diff options
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 193 |
1 files changed, 108 insertions, 85 deletions
@@ -85,20 +85,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); @@ -369,7 +369,8 @@ typedef short int yytype_int16; #ifndef lint # define YYID(N) (N) #else -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static int YYID (int yyi) #else @@ -453,7 +454,9 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ -#if (! defined yyoverflow && (! defined __cplusplus || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -999,7 +1002,8 @@ do { \ `--------------------------------*/ /*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else @@ -1032,7 +1036,8 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) | Print this symbol on YYOUTPUT. | `--------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else @@ -1057,7 +1062,8 @@ yy_symbol_print (yyoutput, yytype, yyvaluep) | TOP (included). | `------------------------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) #else @@ -1087,7 +1093,8 @@ do { \ | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void yy_reduce_print (YYSTYPE *yyvsp, int yyrule) #else @@ -1154,7 +1161,8 @@ int yydebug; # define yystrlen strlen # else /* Return the length of YYSTR. */ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) #else @@ -1177,7 +1185,8 @@ yystrlen (yystr) # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) #else @@ -1391,7 +1400,8 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ /*ARGSUSED*/ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else @@ -1443,7 +1453,8 @@ int yynerrs; `----------*/ #ifdef YYPARSE_PARAM -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) int yyparse (void *YYPARSE_PARAM) #else @@ -1452,7 +1463,8 @@ yyparse (YYPARSE_PARAM) void *YYPARSE_PARAM; #endif #else /* ! YYPARSE_PARAM */ -#if (defined __STDC__ || defined __C99__FUNC__ || defined __cplusplus || defined _MSC_VER) +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) int yyparse (void) #else @@ -1699,7 +1711,7 @@ yyreduce: #line 109 "command.y" { 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); @@ -1719,7 +1731,7 @@ yyreduce: { if (errcount == 0 && cmd_idx >= 0) { Func_cmd cmdfunc; - int terminate = FALSE; + bool terminate = false; CMDARG *args; int ctype = 0; @@ -1753,7 +1765,7 @@ yyreduce: if (in_commands) cmdfunc = do_commands; cmd_idx = -1; - want_nodeval = FALSE; + want_nodeval = false; args = arg_list; arg_list = NULL; @@ -1778,7 +1790,7 @@ yyreduce: case 22: /* Line 1792 of yacc.c */ #line 212 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 23: @@ -1796,7 +1808,7 @@ yyreduce: rl_inhibit_completion = 1; } cmd_idx = -1; - in_eval = TRUE; + in_eval = true; } } break; @@ -1843,7 +1855,7 @@ yyreduce: rl_inhibit_completion = 0; } cmd_idx = find_command("eval", 4); - in_eval = FALSE; + in_eval = false; } break; @@ -1891,37 +1903,37 @@ yyreduce: case 38: /* Line 1792 of yacc.c */ #line 305 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 40: /* Line 1792 of yacc.c */ #line 306 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 46: /* Line 1792 of yacc.c */ #line 311 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 49: /* Line 1792 of yacc.c */ #line 313 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 51: /* Line 1792 of yacc.c */ #line 314 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 53: /* Line 1792 of yacc.c */ #line 315 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 57: @@ -1956,12 +1968,12 @@ yyreduce: ; else if (in_commands) yyerror(_("Can't use command `commands' for breakpoint/watchpoint commands")); - else if ((yyvsp[(2) - (2)]) == NULL && ! (type = has_break_or_watch_point(&num, TRUE))) + else if ((yyvsp[(2) - (2)]) == NULL && ! (type = has_break_or_watch_point(&num, true))) yyerror(_("no breakpoint/watchpoint has been set yet")); - else if ((yyvsp[(2) - (2)]) != NULL && ! (type = has_break_or_watch_point(&num, FALSE))) + else if ((yyvsp[(2) - (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"), @@ -1981,7 +1993,7 @@ yyreduce: else { if (input_from_tty) dbg_prompt = dgawk_prompt; - in_commands = FALSE; + in_commands = false; } } break; @@ -2014,7 +2026,7 @@ yyreduce: case 63: /* Line 1792 of yacc.c */ #line 381 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 64: @@ -2023,7 +2035,7 @@ yyreduce: { int type; int num = (yyvsp[(2) - (4)])->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")); } @@ -2155,13 +2167,13 @@ yyreduce: case 89: /* Line 1792 of yacc.c */ #line 496 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 92: /* Line 1792 of yacc.c */ #line 498 "command.y" - { want_nodeval = TRUE; } + { want_nodeval = true; } break; case 95: @@ -2350,7 +2362,7 @@ yyreduce: if ((n->flags & NUMBER) == 0) yyerror(_("non-numeric value found, numeric expected")); else - (yyvsp[(2) - (2)])->a_node->numbr = - n->numbr; + negate_num(n); (yyval) = (yyvsp[(2) - (2)]); } break; @@ -2674,7 +2686,7 @@ yyreturn: /* 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; @@ -2684,7 +2696,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; @@ -2696,7 +2708,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; @@ -2710,14 +2722,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; @@ -2727,8 +2739,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 } @@ -3089,7 +3101,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"); @@ -3104,7 +3116,7 @@ err: } if (c == '\\') { c = *++lexptr; - esc_seen = TRUE; + esc_seen = true; if (want_nodeval || c != '"') *p++ = '\\'; } @@ -3117,7 +3129,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 */ @@ -3163,22 +3175,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; } @@ -3286,7 +3313,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; @@ -3308,8 +3335,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]) { @@ -3362,7 +3391,7 @@ do_help(CMDARG *arg, int cmd) fprintf(out_fp, _("undefined command: %s\n"), name); } - return FALSE; + return false; } @@ -3411,7 +3440,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; @@ -3449,6 +3478,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; @@ -3509,7 +3539,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); @@ -3517,12 +3547,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) @@ -3539,45 +3569,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; } @@ -3602,4 +3626,3 @@ history_expand_line(char **line) } #endif - |