summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-15 09:11:03 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2012-08-15 09:11:03 -0400
commita5e307c120a7950f4e469d0c8ca696890adb40a2 (patch)
treed922a481a40ab53cc0d6902341c1ea566722ac52 /parser.c
parentc8657d70a81f1b1526c37ce3805a9bbd74bdf628 (diff)
remove max_input_word_length limit
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c103
1 files changed, 53 insertions, 50 deletions
diff --git a/parser.c b/parser.c
index 9428a23..fe71449 100644
--- a/parser.c
+++ b/parser.c
@@ -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;
}