diff options
Diffstat (limited to 'command.y')
-rw-r--r-- | command.y | 159 |
1 files changed, 85 insertions, 74 deletions
@@ -37,20 +37,20 @@ static void yyerror(const char *mesg, ...); static int find_command(const char *token, size_t toklen); -static int want_nodeval = FALSE; +static bool want_nodeval = false; static int cmd_idx = -1; /* index of current command in cmd table */ static int repeat_idx = -1; /* index of last repeatable command in command table */ static CMDARG *arg_list = NULL; /* list of arguments */ static long errcount = 0; static char *lexptr_begin = NULL; -static int in_commands = FALSE; +static bool in_commands = false; static int num_dim; -static int in_eval = FALSE; +static bool in_eval = false; static const char start_EVAL[] = "function @eval(){"; static const char end_EVAL[] = "}"; -static CMDARG *append_statement(CMDARG *alist, char *stmt); +static CMDARG *append_statement(CMDARG *stmt_list, char *stmt); static char *next_word(char *p, int len, char **endp); static NODE *concat_args(CMDARG *a, int count); @@ -108,7 +108,7 @@ input | input line { cmd_idx = -1; - want_nodeval = FALSE; + want_nodeval = false; if (lexptr_begin != NULL) { if (input_from_tty && lexptr_begin[0] != '\0') add_history(lexptr_begin); @@ -128,7 +128,7 @@ line { if (errcount == 0 && cmd_idx >= 0) { Func_cmd cmdfunc; - int terminate = FALSE; + bool terminate = false; CMDARG *args; int ctype = 0; @@ -162,7 +162,7 @@ line if (in_commands) cmdfunc = do_commands; cmd_idx = -1; - want_nodeval = FALSE; + want_nodeval = false; args = arg_list; arg_list = NULL; @@ -209,7 +209,7 @@ break_cmd /* mid-rule action buried in non-terminal to avoid conflict */ set_want_nodeval - : { want_nodeval = TRUE; } + : { want_nodeval = true; } ; eval_prologue @@ -226,7 +226,7 @@ eval_prologue rl_inhibit_completion = 1; } cmd_idx = -1; - in_eval = TRUE; + in_eval = true; } } ; @@ -261,7 +261,7 @@ eval_cmd rl_inhibit_completion = 0; } cmd_idx = find_command("eval", 4); - in_eval = FALSE; + in_eval = false; } | D_EVAL set_want_nodeval string_node { @@ -302,17 +302,17 @@ command } | D_IGNORE plus_integer D_INT | D_ENABLE enable_args - | D_PRINT { want_nodeval = TRUE; } print_args - | D_PRINTF { want_nodeval = TRUE; } printf_args + | D_PRINT { want_nodeval = true; } print_args + | D_PRINTF { want_nodeval = true; } printf_args | D_LIST list_args | D_UNTIL location | D_CLEAR location | break_cmd break_args - | D_SET { want_nodeval = TRUE; } variable '=' node + | D_SET { want_nodeval = true; } variable '=' node | D_OPTION option_args - | D_RETURN { want_nodeval = TRUE; } opt_node - | D_DISPLAY { want_nodeval = TRUE; } opt_variable - | D_WATCH { want_nodeval = TRUE; } variable condition_exp + | D_RETURN { want_nodeval = true; } opt_node + | D_DISPLAY { want_nodeval = true; } opt_variable + | D_WATCH { want_nodeval = true; } variable condition_exp | d_cmd opt_integer_list | D_DUMP opt_string | D_SOURCE D_STRING @@ -337,12 +337,12 @@ command ; else if (in_commands) yyerror(_("Can't use command `commands' for breakpoint/watchpoint commands")); - else if ($2 == NULL && ! (type = has_break_or_watch_point(&num, TRUE))) + else if ($2 == NULL && ! (type = has_break_or_watch_point(&num, true))) yyerror(_("no breakpoint/watchpoint has been set yet")); - else if ($2 != NULL && ! (type = has_break_or_watch_point(&num, FALSE))) + else if ($2 != NULL && ! (type = has_break_or_watch_point(&num, false))) yyerror(_("invalid breakpoint/watchpoint number")); if (type) { - in_commands = TRUE; + in_commands = true; if (input_from_tty) { dbg_prompt = commands_prompt; fprintf(out_fp, _("Type commands for when %s %d is hit, one per line.\n"), @@ -358,7 +358,7 @@ command else { if (input_from_tty) dbg_prompt = dgawk_prompt; - in_commands = FALSE; + in_commands = false; } } | D_SILENT @@ -378,11 +378,11 @@ command $2->a_argument = argtab[idx].value; } } - | D_CONDITION plus_integer { want_nodeval = TRUE; } condition_exp + | D_CONDITION plus_integer { want_nodeval = true; } condition_exp { int type; int num = $2->a_int; - type = has_break_or_watch_point(&num, FALSE); + type = has_break_or_watch_point(&num, false); if (! type) yyerror(_("condition: invalid breakpoint/watchpoint number")); } @@ -493,9 +493,9 @@ location break_args : /* empty */ { $$ = NULL; } - | plus_integer { want_nodeval = TRUE; } condition_exp + | plus_integer { want_nodeval = true; } condition_exp | func_name - | D_STRING ':' plus_integer { want_nodeval = TRUE; } condition_exp + | D_STRING ':' plus_integer { want_nodeval = true; } condition_exp | D_STRING ':' func_name ; @@ -686,7 +686,7 @@ node if ((n->flags & NUMBER) == 0) yyerror(_("non-numeric value found, numeric expected")); else - $2->a_node->numbr = - n->numbr; + negate_num(n); $$ = $2; } ; @@ -750,7 +750,7 @@ nls /* append_statement --- append 'stmt' to the list of eval awk statements */ static CMDARG * -append_statement(CMDARG *alist, char *stmt) +append_statement(CMDARG *stmt_list, char *stmt) { CMDARG *a, *arg; char *s; @@ -760,7 +760,7 @@ append_statement(CMDARG *alist, char *stmt) if (stmt == start_EVAL) { len = sizeof(start_EVAL); - for (a = alist; a != NULL; a = a->next) + for (a = stmt_list; a != NULL; a = a->next) len += strlen(a->a_string) + 1; /* 1 for ',' */ len += EVALSIZE; @@ -772,7 +772,7 @@ append_statement(CMDARG *alist, char *stmt) slen = sizeof("function @eval(") - 1; memcpy(s, start_EVAL, slen); - for (a = alist; a != NULL; a = a->next) { + for (a = stmt_list; a != NULL; a = a->next) { len = strlen(a->a_string); memcpy(s + slen, a->a_string, len); slen += len; @@ -786,14 +786,14 @@ append_statement(CMDARG *alist, char *stmt) } len = strlen(stmt) + 1; /* 1 for newline */ - s = alist->a_string; + s = stmt_list->a_string; slen = strlen(s); - ssize = alist->a_count; + ssize = stmt_list->a_count; if (len > ssize - slen) { ssize = slen + len + EVALSIZE; erealloc(s, char *, (ssize + 2) * sizeof(char), "append_statement"); - alist->a_string = s; - alist->a_count = ssize; + stmt_list->a_string = s; + stmt_list->a_count = ssize; } memcpy(s + slen, stmt, len); slen += len; @@ -803,8 +803,8 @@ append_statement(CMDARG *alist, char *stmt) } if (stmt == end_EVAL) - erealloc(alist->a_string, char *, slen + 2, "append_statement"); - return alist; + erealloc(stmt_list->a_string, char *, slen + 2, "append_statement"); + return stmt_list; #undef EVALSIZE } @@ -1165,7 +1165,7 @@ again: if (c == '"') { char *str, *p; int flags = ALREADY_MALLOCED; - int esc_seen = FALSE; + bool esc_seen = false; toklen = lexend - lexptr; emalloc(str, char *, toklen + 2, "yylex"); @@ -1180,7 +1180,7 @@ err: } if (c == '\\') { c = *++lexptr; - esc_seen = TRUE; + esc_seen = true; if (want_nodeval || c != '"') *p++ = '\\'; } @@ -1193,7 +1193,7 @@ err: if (! want_nodeval) { yylval = mk_cmdarg(D_string); - yylval->a_string = estrdup(str, p - str); + yylval->a_string = str; append_cmdarg(yylval); return D_STRING; } else { /* awk string */ @@ -1239,22 +1239,37 @@ err: return D_STRING; } - /* assert(want_nodval == TRUE); */ - /* look for awk number */ if (isdigit((unsigned char) tokstart[0])) { - double d; + NODE *r = NULL; errno = 0; - d = strtod(tokstart, &lexptr); +#ifdef HAVE_MPFR + if (do_mpfr) { + int tval; + r = mpg_float(); + tval = mpfr_strtofr(r->mpg_numbr, tokstart, & lexptr, 0, ROUND_MODE); + IEEE_FMT(r->mpg_numbr, tval); + if (mpfr_integer_p(r->mpg_numbr)) { + /* integral value, convert to a GMP type. */ + NODE *tmp = r; + r = mpg_integer(); + mpfr_get_z(r->mpg_i, tmp->mpg_numbr, MPFR_RNDZ); + unref(tmp); + } + } else +#endif + r = make_number(strtod(tokstart, & lexptr)); + if (errno != 0) { yyerror(strerror(errno)); + unref(r); errno = 0; return '\n'; } yylval = mk_cmdarg(D_node); - yylval->a_node = make_number(d); + yylval->a_node = r; append_cmdarg(yylval); return D_NODE; } @@ -1362,7 +1377,7 @@ find_command(const char *token, size_t toklen) { char *name, *abrv; int i, k; - int try_exact = TRUE; + bool try_exact = true; int abrv_match = -1; int partial_match = -1; @@ -1384,8 +1399,10 @@ find_command(const char *token, size_t toklen) && strncmp(name, token, toklen) == 0 ) return i; - if (*name > *token) - try_exact = FALSE; + + if (*name > *token || i == (k - 1)) + try_exact = false; + if (abrv_match < 0) { abrv = cmdtab[i].abbrvn; if (abrv[0] == token[0]) { @@ -1438,7 +1455,7 @@ do_help(CMDARG *arg, int cmd) fprintf(out_fp, _("undefined command: %s\n"), name); } - return FALSE; + return false; } @@ -1487,7 +1504,7 @@ command_completion(const char *text, int start, int end) int idx; int len; - rl_attempted_completion_over = TRUE; /* no default filename completion please */ + rl_attempted_completion_over = true; /* no default filename completion please */ this_cmd = D_illegal; len = start; @@ -1525,6 +1542,7 @@ command_completion(const char *text, int start, int end) return NULL; } } + if (this_cmd == D_print || this_cmd == D_printf) return rl_completion_matches(text, variable_generator); return NULL; @@ -1585,7 +1603,7 @@ argument_generator(const char *text, int state) { static size_t textlen; static int idx; - char *name; + const char *name; if (! state) { /* first time */ textlen = strlen(text); @@ -1593,12 +1611,12 @@ argument_generator(const char *text, int state) } if (this_cmd == D_help) { - while ((name = (char *) cmdtab[idx++].name) != NULL) { + while ((name = cmdtab[idx++].name) != NULL) { if (strncmp(name, text, textlen) == 0) return estrdup(name, strlen(name)); } } else { - while ((name = (char *) argtab[idx].name) != NULL) { + while ((name = argtab[idx].name) != NULL) { if (this_cmd != argtab[idx++].cmd) continue; if (strncmp(name, text, textlen) == 0) @@ -1615,45 +1633,39 @@ variable_generator(const char *text, int state) { static size_t textlen; static int idx = 0; - static char **pnames = NULL; - static NODE **var_table = NULL; - char *name; - NODE *hp; + static NODE *func = NULL; + static NODE **vars = NULL; + const char *name; + NODE *r; if (! state) { /* first time */ textlen = strlen(text); - if (var_table != NULL) - efree(var_table); - var_table = get_varlist(); + if (vars != NULL) + efree(vars); + vars = variable_list(); idx = 0; - pnames = get_parmlist(); /* names of function params in - * current context; the array - * is NULL terminated in - * awkgram.y (func_install). - */ + func = get_function(); /* function in current context */ } /* function params */ - while (pnames != NULL) { - name = pnames[idx]; - if (name == NULL) { - pnames = NULL; /* don't try to match params again */ + while (func != NULL) { + if (idx >= func->param_cnt) { + func = NULL; /* don't try to match params again */ idx = 0; break; } - idx++; + name = func->fparms[idx++].param; if (strncmp(name, text, textlen) == 0) return estrdup(name, strlen(name)); } /* globals */ - while ((hp = var_table[idx]) != NULL) { - idx++; - if (hp->hvalue->type == Node_func) - continue; - if (strncmp(hp->hname, text, textlen) == 0) - return estrdup(hp->hname, hp->hlength); + while ((r = vars[idx++]) != NULL) { + name = r->vname; + if (strncmp(name, text, textlen) == 0) + return estrdup(name, strlen(name)); } + return NULL; } @@ -1678,4 +1690,3 @@ history_expand_line(char **line) } #endif - |