diff options
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 103 |
1 files changed, 53 insertions, 50 deletions
@@ -607,8 +607,8 @@ void Parser_main (char *raw_in, int interactive_terminal, void(*cbfunc)(gpointer /* end of a regular command word - use it */ commands[command_depth]=Parser_id_word( current_word->str, - &channel, - &with_id_code); + &channel, + &with_id_code); /* get ready for the next token */ g_string_free (current_word, 1); @@ -819,79 +819,82 @@ static int Go_freq_32_33(gchar** response, int channel, char *parameter,char *un static int Handle_Units(float *mult,char *units, char *in_base) { int len_base, len_all, pos; - char prefix[max_input_word_length]; - char base[max_input_word_length]; - - strcpy (base, in_base); + int errornum = OK; *mult=1.0; - if (!strcmp(units,base)) { + if (!strcmp(units,in_base)) { return OK; } - // match base len_all = strlen (units); if (len_all == 0) { return OK; } + gchar *prefix = g_strdup (units); + gchar *base = g_strdup (in_base); + len_base = strlen (base); pos = len_all - len_base; - strcpy (prefix, units); - if (!strcmp(base,"%") && (len_all >= 3) && !strcmp(prefix + len_all - 3,"pct")) { - strcpy(base, "pct"); + g_free (base); + base = g_strdup ("pct"); prefix[len_all - 3] = 0; } else if (!strcmp(base,"pct") && !strcmp(prefix + len_all - 1,"%")) { - strcpy(base, "%"); + g_free (base); + base = g_strdup ("%"); prefix[len_all - 1] = 0; } else if (strcmp(prefix+pos,base)) { - return UnknownUnits; + g_free (base); + g_free (prefix); + errornum = UnknownUnits; } else { prefix[pos]=0; } - if (strlen(prefix) == 0) { - return OK; - } + if (strlen(prefix) && !errornum) { - // special exceptions - if (!strcmp(prefix,"m") && !strcmp(base,"ohm")) { - *mult=1.0e6; - } else if (!strcmp(prefix,"m") && !strcmp(base,"hz")) { - *mult=1.0e6; - } - // normal rules - else if (!strcmp(prefix,"ex")) { - *mult=1.0e18; - } else if (!strcmp(prefix,"pe")) { - *mult=1.0e15; - } else if (!strcmp(prefix,"t")) { - *mult=1.0e12; - } else if (!strcmp(prefix,"g")) { - *mult=1.0e9; - } else if (!strcmp(prefix,"ma")) { - *mult=1.0e6; - } else if (!strcmp(prefix,"k")) { - *mult=1.0e3; - } else if (!strcmp(prefix,"m")) { - *mult=1.0e-3; - } else if (!strcmp(prefix,"u")) { - *mult=1.0e-6; - } else if (!strcmp(prefix,"n")) { - *mult=1.0e-9; - } else if (!strcmp(prefix,"p")) { - *mult=1.0e-12; - } else if (!strcmp(prefix,"f")) { - *mult=1.0e-15; - } else if (!strcmp(prefix,"a")) { - *mult=1.0e-18; - } else { - return UnknownUnits; + // special exceptions + if (!strcmp(prefix,"m") && !strcmp(base,"ohm")) { + *mult=1.0e6; + } else if (!strcmp(prefix,"m") && !strcmp(base,"hz")) { + *mult=1.0e6; + } + // normal rules + else if (!strcmp(prefix,"ex")) { + *mult=1.0e18; + } else if (!strcmp(prefix,"pe")) { + *mult=1.0e15; + } else if (!strcmp(prefix,"t")) { + *mult=1.0e12; + } else if (!strcmp(prefix,"g")) { + *mult=1.0e9; + } else if (!strcmp(prefix,"ma")) { + *mult=1.0e6; + } else if (!strcmp(prefix,"k")) { + *mult=1.0e3; + } else if (!strcmp(prefix,"m")) { + *mult=1.0e-3; + } else if (!strcmp(prefix,"u")) { + *mult=1.0e-6; + } else if (!strcmp(prefix,"n")) { + *mult=1.0e-9; + } else if (!strcmp(prefix,"p")) { + *mult=1.0e-12; + } else if (!strcmp(prefix,"f")) { + *mult=1.0e-15; + } else if (!strcmp(prefix,"a")) { + *mult=1.0e-18; + } else { + errornum = UnknownUnits; + } } - return OK; + g_free (base); + g_free (prefix); + + return errornum; } |