aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-07-14 16:58:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-07-14 16:58:05 +0200
commitdabbeeb79356eef78528acd55e1f143ae80372f7 (patch)
tree6cea98d09318303e9a5a54eece9d1ec328e9b931
parent95fffd8a7fd49637d7b6d9f25b69ac6d8c9a2fff (diff)
downloadbusybox-w32-dabbeeb79356eef78528acd55e1f143ae80372f7.tar.gz
busybox-w32-dabbeeb79356eef78528acd55e1f143ae80372f7.tar.bz2
busybox-w32-dabbeeb79356eef78528acd55e1f143ae80372f7.zip
awk: whitespace and debugging tweaks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c133
1 files changed, 66 insertions, 67 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 607d69487..3adbca7aa 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -199,77 +199,78 @@ typedef struct tsplitter_s {
199 199
200/* simple token classes */ 200/* simple token classes */
201/* order and hex values are very important!!! See next_token() */ 201/* order and hex values are very important!!! See next_token() */
202#define TC_LPAREN (1 << 0) /* ( */ 202#define TC_LPAREN (1 << 0) /* ( */
203#define TC_RPAREN (1 << 1) /* ) */ 203#define TC_RPAREN (1 << 1) /* ) */
204#define TC_REGEXP (1 << 2) /* /.../ */ 204#define TC_REGEXP (1 << 2) /* /.../ */
205#define TC_OUTRDR (1 << 3) /* | > >> */ 205#define TC_OUTRDR (1 << 3) /* | > >> */
206#define TC_UOPPOST (1 << 4) /* unary postfix operator ++ -- */ 206#define TC_UOPPOST (1 << 4) /* unary postfix operator ++ -- */
207#define TC_UOPPRE1 (1 << 5) /* unary prefix operator ++ -- $ */ 207#define TC_UOPPRE1 (1 << 5) /* unary prefix operator ++ -- $ */
208#define TC_BINOPX (1 << 6) /* two-opnd operator */ 208#define TC_BINOPX (1 << 6) /* two-opnd operator */
209#define TC_IN (1 << 7) /* 'in' */ 209#define TC_IN (1 << 7) /* 'in' */
210#define TC_COMMA (1 << 8) /* , */ 210#define TC_COMMA (1 << 8) /* , */
211#define TC_PIPE (1 << 9) /* input redirection pipe | */ 211#define TC_PIPE (1 << 9) /* input redirection pipe | */
212#define TC_UOPPRE2 (1 << 10) /* unary prefix operator + - ! */ 212#define TC_UOPPRE2 (1 << 10) /* unary prefix operator + - ! */
213#define TC_ARRTERM (1 << 11) /* ] */ 213#define TC_ARRTERM (1 << 11) /* ] */
214#define TC_LBRACE (1 << 12) /* { */ 214#define TC_LBRACE (1 << 12) /* { */
215#define TC_RBRACE (1 << 13) /* } */ 215#define TC_RBRACE (1 << 13) /* } */
216#define TC_SEMICOL (1 << 14) /* ; */ 216#define TC_SEMICOL (1 << 14) /* ; */
217#define TC_NEWLINE (1 << 15) 217#define TC_NEWLINE (1 << 15)
218#define TC_STATX (1 << 16) /* ctl statement (for, next...) */ 218#define TC_STATX (1 << 16) /* ctl statement (for, next...) */
219#define TC_WHILE (1 << 17) /* 'while' */ 219#define TC_WHILE (1 << 17) /* 'while' */
220#define TC_ELSE (1 << 18) /* 'else' */ 220#define TC_ELSE (1 << 18) /* 'else' */
221#define TC_BUILTIN (1 << 19) 221#define TC_BUILTIN (1 << 19)
222/* This costs ~50 bytes of code. 222/* This costs ~50 bytes of code.
223 * A separate class to support deprecated "length" form. If we don't need that 223 * A separate class to support deprecated "length" form. If we don't need that
224 * (i.e. if we demand that only "length()" with () is valid), then TC_LENGTH 224 * (i.e. if we demand that only "length()" with () is valid), then TC_LENGTH
225 * can be merged with TC_BUILTIN: 225 * can be merged with TC_BUILTIN:
226 */ 226 */
227#define TC_LENGTH (1 << 20) /* 'length' */ 227#define TC_LENGTH (1 << 20) /* 'length' */
228#define TC_GETLINE (1 << 21) /* 'getline' */ 228#define TC_GETLINE (1 << 21) /* 'getline' */
229#define TC_FUNCDECL (1 << 22) /* 'function' 'func' */ 229#define TC_FUNCDECL (1 << 22) /* 'function' 'func' */
230#define TC_BEGIN (1 << 23) /* 'BEGIN' */ 230#define TC_BEGIN (1 << 23) /* 'BEGIN' */
231#define TC_END (1 << 24) /* 'END' */ 231#define TC_END (1 << 24) /* 'END' */
232#define TC_EOF (1 << 25) 232#define TC_EOF (1 << 25)
233#define TC_VARIABLE (1 << 26) /* name */ 233#define TC_VARIABLE (1 << 26) /* name */
234#define TC_ARRAY (1 << 27) /* name[ */ 234#define TC_ARRAY (1 << 27) /* name[ */
235#define TC_FUNCTION (1 << 28) /* name( */ 235#define TC_FUNCTION (1 << 28) /* name( */
236#define TC_STRING (1 << 29) /* "..." */ 236#define TC_STRING (1 << 29) /* "..." */
237#define TC_NUMBER (1 << 30) 237#define TC_NUMBER (1 << 30)
238 238
239#ifndef debug_parse_print_tc 239#ifndef debug_parse_print_tc
240#define debug_parse_print_tc(n) do { \ 240static void debug_parse_print_tc(uint32_t n)
241if ((n) & TC_LPAREN ) debug_printf_parse(" LPAREN" ); \ 241{
242if ((n) & TC_RPAREN ) debug_printf_parse(" RPAREN" ); \ 242 if (n & TC_LPAREN ) debug_printf_parse(" LPAREN" );
243if ((n) & TC_REGEXP ) debug_printf_parse(" REGEXP" ); \ 243 if (n & TC_RPAREN ) debug_printf_parse(" RPAREN" );
244if ((n) & TC_OUTRDR ) debug_printf_parse(" OUTRDR" ); \ 244 if (n & TC_REGEXP ) debug_printf_parse(" REGEXP" );
245if ((n) & TC_UOPPOST ) debug_printf_parse(" UOPPOST" ); \ 245 if (n & TC_OUTRDR ) debug_printf_parse(" OUTRDR" );
246if ((n) & TC_UOPPRE1 ) debug_printf_parse(" UOPPRE1" ); \ 246 if (n & TC_UOPPOST ) debug_printf_parse(" UOPPOST" );
247if ((n) & TC_BINOPX ) debug_printf_parse(" BINOPX" ); \ 247 if (n & TC_UOPPRE1 ) debug_printf_parse(" UOPPRE1" );
248if ((n) & TC_IN ) debug_printf_parse(" IN" ); \ 248 if (n & TC_BINOPX ) debug_printf_parse(" BINOPX" );
249if ((n) & TC_COMMA ) debug_printf_parse(" COMMA" ); \ 249 if (n & TC_IN ) debug_printf_parse(" IN" );
250if ((n) & TC_PIPE ) debug_printf_parse(" PIPE" ); \ 250 if (n & TC_COMMA ) debug_printf_parse(" COMMA" );
251if ((n) & TC_UOPPRE2 ) debug_printf_parse(" UOPPRE2" ); \ 251 if (n & TC_PIPE ) debug_printf_parse(" PIPE" );
252if ((n) & TC_ARRTERM ) debug_printf_parse(" ARRTERM" ); \ 252 if (n & TC_UOPPRE2 ) debug_printf_parse(" UOPPRE2" );
253if ((n) & TC_LBRACE ) debug_printf_parse(" LBRACE" ); \ 253 if (n & TC_ARRTERM ) debug_printf_parse(" ARRTERM" );
254if ((n) & TC_RBRACE ) debug_printf_parse(" RBRACE" ); \ 254 if (n & TC_LBRACE ) debug_printf_parse(" LBRACE" );
255if ((n) & TC_SEMICOL ) debug_printf_parse(" SEMICOL" ); \ 255 if (n & TC_RBRACE ) debug_printf_parse(" RBRACE" );
256if ((n) & TC_NEWLINE ) debug_printf_parse(" NEWLINE" ); \ 256 if (n & TC_SEMICOL ) debug_printf_parse(" SEMICOL" );
257if ((n) & TC_STATX ) debug_printf_parse(" STATX" ); \ 257 if (n & TC_NEWLINE ) debug_printf_parse(" NEWLINE" );
258if ((n) & TC_WHILE ) debug_printf_parse(" WHILE" ); \ 258 if (n & TC_STATX ) debug_printf_parse(" STATX" );
259if ((n) & TC_ELSE ) debug_printf_parse(" ELSE" ); \ 259 if (n & TC_WHILE ) debug_printf_parse(" WHILE" );
260if ((n) & TC_BUILTIN ) debug_printf_parse(" BUILTIN" ); \ 260 if (n & TC_ELSE ) debug_printf_parse(" ELSE" );
261if ((n) & TC_LENGTH ) debug_printf_parse(" LENGTH" ); \ 261 if (n & TC_BUILTIN ) debug_printf_parse(" BUILTIN" );
262if ((n) & TC_GETLINE ) debug_printf_parse(" GETLINE" ); \ 262 if (n & TC_LENGTH ) debug_printf_parse(" LENGTH" );
263if ((n) & TC_FUNCDECL) debug_printf_parse(" FUNCDECL"); \ 263 if (n & TC_GETLINE ) debug_printf_parse(" GETLINE" );
264if ((n) & TC_BEGIN ) debug_printf_parse(" BEGIN" ); \ 264 if (n & TC_FUNCDECL) debug_printf_parse(" FUNCDECL");
265if ((n) & TC_END ) debug_printf_parse(" END" ); \ 265 if (n & TC_BEGIN ) debug_printf_parse(" BEGIN" );
266if ((n) & TC_EOF ) debug_printf_parse(" EOF" ); \ 266 if (n & TC_END ) debug_printf_parse(" END" );
267if ((n) & TC_VARIABLE) debug_printf_parse(" VARIABLE"); \ 267 if (n & TC_EOF ) debug_printf_parse(" EOF" );
268if ((n) & TC_ARRAY ) debug_printf_parse(" ARRAY" ); \ 268 if (n & TC_VARIABLE) debug_printf_parse(" VARIABLE");
269if ((n) & TC_FUNCTION) debug_printf_parse(" FUNCTION"); \ 269 if (n & TC_ARRAY ) debug_printf_parse(" ARRAY" );
270if ((n) & TC_STRING ) debug_printf_parse(" STRING" ); \ 270 if (n & TC_FUNCTION) debug_printf_parse(" FUNCTION");
271if ((n) & TC_NUMBER ) debug_printf_parse(" NUMBER" ); \ 271 if (n & TC_STRING ) debug_printf_parse(" STRING" );
272} while (0) 272 if (n & TC_NUMBER ) debug_printf_parse(" NUMBER" );
273}
273#endif 274#endif
274 275
275/* combined token classes ("token [class] sets") */ 276/* combined token classes ("token [class] sets") */
@@ -417,7 +418,7 @@ static const char tokenlist[] ALIGN1 =
417 "\5close" "\6system" "\6fflush" "\5atan2" 418 "\5close" "\6system" "\6fflush" "\5atan2"
418 "\3cos" "\3exp" "\3int" "\3log" 419 "\3cos" "\3exp" "\3int" "\3log"
419 "\4rand" "\3sin" "\4sqrt" "\5srand" 420 "\4rand" "\3sin" "\4sqrt" "\5srand"
420 "\6gensub" "\4gsub" "\5index" /* "\6length" was here */ 421 "\6gensub" "\4gsub" "\5index" /* "\6length" was here */
421 "\5match" "\5split" "\7sprintf" "\3sub" 422 "\5match" "\5split" "\7sprintf" "\3sub"
422 "\6substr" "\7systime" "\10strftime" "\6mktime" 423 "\6substr" "\7systime" "\10strftime" "\6mktime"
423 "\7tolower" "\7toupper" NTC 424 "\7tolower" "\7toupper" NTC
@@ -1802,7 +1803,6 @@ static void parse_program(char *p)
1802 } /* for (;;) */ 1803 } /* for (;;) */
1803} 1804}
1804 1805
1805
1806/* -------- program execution part -------- */ 1806/* -------- program execution part -------- */
1807 1807
1808/* temporary variables allocator */ 1808/* temporary variables allocator */
@@ -3510,7 +3510,6 @@ static var *evaluate(node *op, var *res)
3510#undef sreg 3510#undef sreg
3511} 3511}
3512 3512
3513
3514/* -------- main & co. -------- */ 3513/* -------- main & co. -------- */
3515 3514
3516static int awk_exit(void) 3515static int awk_exit(void)