diff options
Diffstat (limited to 'command.c')
-rw-r--r-- | command.c | 254 |
1 files changed, 121 insertions, 133 deletions
@@ -1,9 +1,10 @@ -/* A Bison parser, made by GNU Bison 2.4.3. */ + +/* A Bison parser, made by GNU Bison 2.4.1. */ /* Skeleton implementation for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 + Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +46,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.3" +#define YYBISON_VERSION "2.4.1" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -103,7 +104,7 @@ static int num_dim; static int 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); @@ -144,7 +145,7 @@ static int find_argument(CMDARG *arg); /* Line 189 of yacc.c */ -#line 148 "command.c" +#line 149 "command.c" /* Enabling traces. */ #ifndef YYDEBUG @@ -282,7 +283,7 @@ typedef int YYSTYPE; /* Line 264 of yacc.c */ -#line 286 "command.c" +#line 287 "command.c" #ifdef short # undef short @@ -332,7 +333,7 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS +# if YYENABLE_NLS # if ENABLE_NLS # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -893,18 +894,9 @@ static const yytype_uint8 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. However, - YYFAIL appears to be in use. Nevertheless, it is formally deprecated - in Bison 2.4.2's NEWS entry, where a plan to phase it out is - discussed. */ + Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab -#if defined YYFAIL - /* This is here to suppress warnings from the GCC cpp's - -Wunused-macros. Normally we don't worry about that warning, but - some users do, and we want to make it easy for users to remove - YYFAIL uses, which will produce warnings from Bison 2.5. */ -#endif #define YYRECOVERING() (!!yyerrstatus) @@ -961,7 +953,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# if YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ @@ -1691,7 +1683,7 @@ yyreduce: { case 3: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 109 "command.y" { cmd_idx = -1; @@ -1711,7 +1703,7 @@ yyreduce: case 5: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 128 "command.y" { if (errcount == 0 && cmd_idx >= 0) { @@ -1766,7 +1758,7 @@ yyreduce: case 6: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 178 "command.y" { yyerrok; @@ -1775,14 +1767,14 @@ yyreduce: case 22: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 212 "command.y" { want_nodeval = TRUE; } break; case 23: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 217 "command.y" { if (errcount == 0) { @@ -1802,7 +1794,7 @@ yyreduce: case 24: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 235 "command.y" { (yyval) = append_statement(arg_list, (char *) start_EVAL); @@ -1815,14 +1807,14 @@ yyreduce: case 25: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 242 "command.y" { (yyval) = append_statement((yyvsp[(1) - (2)]), lexptr_begin); } break; case 26: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 243 "command.y" { (yyval) = (yyvsp[(3) - (4)]); @@ -1831,7 +1823,7 @@ yyreduce: case 27: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 250 "command.y" { arg_list = append_statement((yyvsp[(2) - (3)]), (char *) end_EVAL); @@ -1852,7 +1844,7 @@ yyreduce: case 28: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 266 "command.y" { NODE *n; @@ -1868,7 +1860,7 @@ yyreduce: case 34: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 285 "command.y" { if (cmdtab[cmd_idx].class == D_FRAME @@ -1879,7 +1871,7 @@ yyreduce: case 35: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 291 "command.y" { int idx = find_argument((yyvsp[(2) - (2)])); @@ -1896,49 +1888,49 @@ yyreduce: case 38: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 304 "command.y" { want_nodeval = TRUE; } break; case 40: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 305 "command.y" { want_nodeval = TRUE; } break; case 46: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 310 "command.y" { want_nodeval = TRUE; } break; case 49: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 312 "command.y" { want_nodeval = TRUE; } break; case 51: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 313 "command.y" { want_nodeval = TRUE; } break; case 53: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 314 "command.y" { want_nodeval = TRUE; } break; case 57: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 318 "command.y" { if (in_cmd_src((yyvsp[(2) - (2)])->a_string)) @@ -1948,7 +1940,7 @@ yyreduce: case 58: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 323 "command.y" { if (! input_from_tty) @@ -1958,7 +1950,7 @@ yyreduce: case 59: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 328 "command.y" { int type = 0; @@ -1989,7 +1981,7 @@ yyreduce: case 60: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 354 "command.y" { if (! in_commands) @@ -2004,7 +1996,7 @@ yyreduce: case 61: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 364 "command.y" { if (! in_commands) @@ -2014,7 +2006,7 @@ yyreduce: case 62: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 369 "command.y" { int idx = find_argument((yyvsp[(2) - (2)])); @@ -2031,14 +2023,14 @@ yyreduce: case 63: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 380 "command.y" { want_nodeval = TRUE; } break; case 64: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 381 "command.y" { int type; @@ -2051,7 +2043,7 @@ yyreduce: case 65: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 389 "command.y" { if (in_commands) { @@ -2067,7 +2059,7 @@ yyreduce: case 66: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 403 "command.y" { if ((yyvsp[(1) - (1)]) != NULL) { @@ -2082,42 +2074,42 @@ yyreduce: case 68: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 417 "command.y" { (yyval) = NULL; } break; case 69: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 422 "command.y" { (yyval) = NULL; } break; case 74: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 431 "command.y" { (yyval) = NULL; } break; case 75: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 436 "command.y" { (yyval) = NULL; } break; case 77: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 439 "command.y" { (yyval) = NULL; } break; case 78: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 444 "command.y" { NODE *n; @@ -2129,14 +2121,14 @@ yyreduce: case 79: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 454 "command.y" { (yyval) = NULL; } break; case 80: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 456 "command.y" { if (find_option((yyvsp[(1) - (1)])->a_string) < 0) @@ -2146,7 +2138,7 @@ yyreduce: case 81: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 461 "command.y" { if (find_option((yyvsp[(1) - (3)])->a_string) < 0) @@ -2156,7 +2148,7 @@ yyreduce: case 82: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 469 "command.y" { NODE *n; @@ -2174,56 +2166,56 @@ yyreduce: case 83: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 485 "command.y" { (yyval) = NULL; } break; case 88: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 494 "command.y" { (yyval) = NULL; } break; case 89: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 495 "command.y" { want_nodeval = TRUE; } break; case 92: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 497 "command.y" { want_nodeval = TRUE; } break; case 95: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 503 "command.y" { (yyval) = NULL; } break; case 97: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 509 "command.y" { (yyval) = NULL; } break; case 99: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 515 "command.y" { (yyval) = NULL; } break; case 104: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 527 "command.y" { int idx = find_argument((yyvsp[(1) - (2)])); @@ -2240,7 +2232,7 @@ yyreduce: case 106: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 543 "command.y" { (yyvsp[(2) - (2)])->type = D_array; /* dump all items */ @@ -2250,7 +2242,7 @@ yyreduce: case 107: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 548 "command.y" { (yyvsp[(2) - (3)])->type = D_array; @@ -2260,21 +2252,21 @@ yyreduce: case 117: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 574 "command.y" { (yyval) = NULL; } break; case 118: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 576 "command.y" { (yyval) = NULL; } break; case 119: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 578 "command.y" { CMDARG *a; @@ -2286,7 +2278,7 @@ yyreduce: case 126: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 594 "command.y" { if ((yyvsp[(1) - (3)])->a_int > (yyvsp[(3) - (3)])->a_int) @@ -2300,28 +2292,28 @@ yyreduce: case 127: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 606 "command.y" { (yyval) = NULL; } break; case 134: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 620 "command.y" { (yyval) = (yyvsp[(1) - (1)]); } break; case 135: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 622 "command.y" { (yyval) = (yyvsp[(1) - (3)]); } break; case 137: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 628 "command.y" { CMDARG *a; @@ -2341,21 +2333,21 @@ yyreduce: case 139: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 647 "command.y" { (yyval) = (yyvsp[(1) - (1)]); num_dim = 1; } break; case 140: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 649 "command.y" { (yyval) = (yyvsp[(1) - (2)]); num_dim++; } break; case 142: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 655 "command.y" { NODE *n = (yyvsp[(2) - (2)])->a_node; @@ -2369,7 +2361,7 @@ yyreduce: case 143: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 664 "command.y" { /* a_string is array name, a_count is dimension count */ @@ -2381,14 +2373,14 @@ yyreduce: case 144: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 674 "command.y" { (yyval) = (yyvsp[(1) - (1)]); } break; case 145: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 676 "command.y" { NODE *n = (yyvsp[(2) - (2)])->a_node; @@ -2400,7 +2392,7 @@ yyreduce: case 146: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 683 "command.y" { NODE *n = (yyvsp[(2) - (2)])->a_node; @@ -2414,35 +2406,35 @@ yyreduce: case 147: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 695 "command.y" { (yyval) = NULL; } break; case 148: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 697 "command.y" { (yyval) = (yyvsp[(1) - (1)]); } break; case 149: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 702 "command.y" { (yyval) = NULL; } break; case 150: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 704 "command.y" { (yyval) = (yyvsp[(1) - (1)]); } break; case 151: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 709 "command.y" { if ((yyvsp[(1) - (1)])->a_int == 0) @@ -2453,7 +2445,7 @@ yyreduce: case 152: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 715 "command.y" { if ((yyvsp[(2) - (2)])->a_int == 0) @@ -2464,21 +2456,21 @@ yyreduce: case 153: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 724 "command.y" { (yyval) = (yyvsp[(1) - (1)]); } break; case 154: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 726 "command.y" { (yyval) = (yyvsp[(2) - (2)]); } break; case 155: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 728 "command.y" { (yyvsp[(2) - (2)])->a_int = - (yyvsp[(2) - (2)])->a_int; @@ -2488,7 +2480,7 @@ yyreduce: case 156: -/* Line 1464 of yacc.c */ +/* Line 1455 of yacc.c */ #line 736 "command.y" { if (lexptr_begin != NULL) { @@ -2502,8 +2494,8 @@ yyreduce: -/* Line 1464 of yacc.c */ -#line 2519 "command.c" +/* Line 1455 of yacc.c */ +#line 2511 "command.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2714,7 +2706,7 @@ yyreturn: -/* Line 1684 of yacc.c */ +/* Line 1675 of yacc.c */ #line 746 "command.y" @@ -2722,7 +2714,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; @@ -2732,7 +2724,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; @@ -2744,7 +2736,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; @@ -2758,14 +2750,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; @@ -2775,8 +2767,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 } @@ -3165,7 +3157,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 */ @@ -3356,8 +3348,10 @@ find_command(const char *token, size_t toklen) && strncmp(name, token, toklen) == 0 ) return i; - if (*name > *token) + + if (*name > *token || i == (k - 1)) try_exact = FALSE; + if (abrv_match < 0) { abrv = cmdtab[i].abbrvn; if (abrv[0] == token[0]) { @@ -3497,6 +3491,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; @@ -3557,7 +3552,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); @@ -3565,12 +3560,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) @@ -3587,45 +3582,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; } @@ -3651,4 +3640,3 @@ history_expand_line(char **line) #endif - |