On 22 September 2011 01:52, Chris Morley <chrisinnana...@hotmail.com> wrote:
> Then in the future if we change to dash we would change > everything all at once. Changing all "_" to "-" will break all the existing configs (not only the sample configs, which can be changed by a script). However, I might have a solution: I can't think of any situations where swapping - for _ leads to ambiguity, so why don't we just make HAL not care about the difference? Then we can change everything to suit the canonical definition, but existing configs with _ in pin names will still work. Then we can _know_ that it is always "-" without having to look at the docs (and if we are wrong, or use _ instead, it doesn't matter). The patch below appears to do exactly that. I think that it will save a lot of users a lot of heartache even if we don't change pin names and configs. ( I welcome any efforts to "elegantise" the code, I am _very_ unfamiliar with working with strings in C) --- a/src/hal/hal_lib.c +++ b/src/hal/hal_lib.c @@ -2177,6 +2177,15 @@ int hal_stop_threads(void) * PRIVATE FUNCTION CODE * ************************************************************************/ +// "-" and "_" agnostic strcmp function +int hal_strcmp(char *pin1, const char *pin2){ + char *c; + for (c = strchr(pin1, '_');c != NULL;c = strchr(pin1, '_')){*c = '-';} + for (c = strchr(pin2, '_');c != NULL;c = strchr(pin2, '_')){*c = '-';} + return strcmp(pin1, pin2); +} + + hal_list_t *list_prev(hal_list_t * entry) { /* this function is only needed because of memory mapping */ @@ -2279,13 +2288,13 @@ hal_pin_t *halpr_find_pin_by_name(const char *name) next = hal_data->pin_list_ptr; while (next != 0) { pin = SHMPTR(next); - if (strcmp(pin->name, name) == 0) { + if (hal_strcmp(pin->name, name) == 0) { /* found a match */ return pin; } if (pin->oldname != 0 ) { oldname = SHMPTR(pin->oldname); - if (strcmp(oldname->name, name) == 0) { + if (hal_strcmp(oldname->name, name) == 0) { /* found a match */ return pin; } @@ -2327,13 +2336,13 @@ hal_param_t *halpr_find_param_by_name(const char *name) next = hal_data->param_list_ptr; while (next != 0) { param = SHMPTR(next); - if (strcmp(param->name, name) == 0) { + if (hal_strcmp(param->name, name) == 0) { /* found a match */ return param; } if (param->oldname != 0 ) { oldname = SHMPTR(param->oldname); - if (strcmp(oldname->name, name) == 0) { + if (hal_strcmp(oldname->name, name) == 0) { /* found a match */ return param; } -- atp "Torque wrenches are for the obedience of fools and the guidance of wise men" ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ Emc-developers mailing list Emc-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-developers