@@ -56,6 +56,8 @@ static void substallpatterns(unsigned char *line,int buffersize);
56
56
static int match (char * st ,int end );
57
57
static int alpha (char c );
58
58
59
+ static void rectok (char * tokptr ,int whitespace );
60
+
59
61
#define SKIPMODE 1 /* bit field in "#if" stack */
60
62
#define PARSEMODE 2 /* bit field in "#if" stack */
61
63
#define HANDLED_ELSE 4 /* bit field in "#if" stack */
@@ -68,6 +70,7 @@ static short iflevel; /* nesting level if #if/#else/#endif */
68
70
static short skiplevel ; /* level at which we started skipping (including nested #if .. #endif) */
69
71
static unsigned char term_expr [] = "" ;
70
72
static int listline = -1 ; /* "current line" for the list file */
73
+ static short iskipwspace = FALSE; /* skipped whitespace(s) before the last read token? */
71
74
72
75
73
76
/* pushstk & popstk
@@ -2310,11 +2313,13 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
2310
2313
* lexvalue = _lexval ;
2311
2314
* lexsym = _lexstr ;
2312
2315
_lexnewline = FALSE;
2316
+ iskipwspace = FALSE;
2313
2317
if (!freading )
2314
2318
return 0 ;
2315
2319
2316
2320
newline = (lptr == pline ); /* does lptr point to start of line buffer */
2317
2321
while (* lptr <=' ' ) { /* delete leading white space */
2322
+ iskipwspace = TRUE;
2318
2323
if (* lptr == '\0' ) {
2319
2324
preprocess (); /* preprocess resets "lptr" */
2320
2325
if (!freading )
@@ -2344,6 +2349,8 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
2344
2349
_lextok = i ;
2345
2350
if (pc_docexpr ) /* optionally concatenate to documentation string */
2346
2351
insert_autolist (* tokptr );
2352
+ if (pc_isrecording )
2353
+ rectok (* tokptr ,iskipwspace );
2347
2354
return _lextok ;
2348
2355
} /* if */
2349
2356
i += 1 ;
@@ -2355,6 +2362,8 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
2355
2362
errorset (sRESET ,0 ); /* reset error flag (clear the "panic mode")*/
2356
2363
if (pc_docexpr ) /* optionally concatenate to documentation string */
2357
2364
insert_autolist (* tokptr );
2365
+ if (pc_isrecording )
2366
+ rectok (* tokptr ,iskipwspace );
2358
2367
return _lextok ;
2359
2368
} /* if */
2360
2369
i += 1 ;
@@ -2472,6 +2481,28 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
2472
2481
free (docstr );
2473
2482
} /* if */
2474
2483
} /* if */
2484
+ if (pc_isrecording ) {
2485
+ switch (_lextok ) {
2486
+ case tNUMBER :
2487
+ case tRATIONAL :
2488
+ _lexstr [0 ]= '\0' ,strncat (_lexstr ,(char * )starttoken ,lptr - starttoken );
2489
+ /* fallthrough */
2490
+ case tSYMBOL :
2491
+ case tLABEL :
2492
+ rectok (_lexstr ,iskipwspace );
2493
+ if (_lextok == tLABEL )
2494
+ rectok (":" ,FALSE);
2495
+ break ;
2496
+ default :
2497
+ if (_lextok < tFIRST ) {
2498
+ char tmp [2 ];
2499
+ sprintf (tmp ,"%c" ,_lextok );
2500
+ rectok (tmp ,iskipwspace );
2501
+ } else {
2502
+ rectok (sc_tokens [tSTRING - tFIRST ],iskipwspace );
2503
+ } /* if */
2504
+ } /* if */
2505
+ } /* if */
2475
2506
return _lextok ;
2476
2507
}
2477
2508
@@ -2508,6 +2539,86 @@ SC_FUNC void lexclr(int clreol)
2508
2539
} /* if */
2509
2540
}
2510
2541
2542
+ static void rectok (char * tokptr ,int whitespace )
2543
+ {
2544
+ int toklen = strlen (tokptr );
2545
+
2546
+ if (pc_recstr == NULL ) {
2547
+ pc_recstr = (char * )malloc ((toklen + 1 )* sizeof (char ));
2548
+ if (pc_recstr == NULL )
2549
+ error (103 ); /* insufficient memory */
2550
+ memcpy (pc_recstr ,tokptr ,toklen * sizeof (char ));
2551
+ pc_recstr [toklen ]= '\0' ;
2552
+ } else {
2553
+ int oldlen = strlen (pc_recstr );
2554
+ char * newresctr = realloc (pc_recstr ,(oldlen + (whitespace ? 1 : 0 )+ toklen + 1 )* sizeof (char ));
2555
+ if (newresctr == NULL )
2556
+ error (103 ); /* insufficient memory */
2557
+ pc_recstr = newresctr ;
2558
+ if (whitespace )
2559
+ pc_recstr [oldlen ]= ' ' ;
2560
+ memcpy (pc_recstr + (whitespace ? 1 : 0 )+ oldlen ,tokptr ,(toklen + 1 )* sizeof (char ));
2561
+ } /* if */
2562
+ }
2563
+
2564
+ /* recstart
2565
+ *
2566
+ * (Re-)starts recording all tokens that lex() reads.
2567
+ */
2568
+ SC_FUNC void recstart (void )
2569
+ {
2570
+ pc_isrecording = TRUE;
2571
+ if (_pushed ) {
2572
+ /* record the pushed token */
2573
+ char tmp [2 ];
2574
+ char * tokstr ;
2575
+ if (_lextok < tFIRST ) {
2576
+ sprintf (tmp ,"%c" ,_lextok );
2577
+ tokstr = tmp ;
2578
+ } else {
2579
+ tokstr = sc_tokens [_lextok - tFIRST ];
2580
+ } /* if */
2581
+ rectok (tokstr ,iskipwspace );
2582
+ } /* if */
2583
+ }
2584
+
2585
+ /* recstop
2586
+ *
2587
+ * Stops recording tokens.
2588
+ */
2589
+ SC_FUNC void recstop (void )
2590
+ {
2591
+ if (sc_status != statWRITE )
2592
+ return ;
2593
+
2594
+ assert (pc_recstr != NULL );
2595
+ pc_isrecording = FALSE;
2596
+
2597
+ /* if nothing was recorded, then we have a quick exit */
2598
+ if (strempty (pc_recstr ))
2599
+ return ;
2600
+
2601
+ /* if the last token was pushed, remove it from the recorded string */
2602
+ if (_pushed && pc_recstr [0 ]!= '\0' ) {
2603
+ char tmp [2 ];
2604
+ char * tokstr ;
2605
+ int pos ;
2606
+ if (_lextok < tFIRST ) {
2607
+ sprintf (tmp ,"%c" ,_lextok );
2608
+ tokstr = tmp ;
2609
+ } else {
2610
+ tokstr = sc_tokens [_lextok - tFIRST ];
2611
+ } /* if */
2612
+ pos = strlen (pc_recstr )- strlen (tokstr );
2613
+ if (strcmp (& pc_recstr [pos ],tokstr )== 0 ) {
2614
+ /* remove trailing whitespaces */
2615
+ while (pc_recstr [-- pos ]<=' ' )
2616
+ ; /* nothing */
2617
+ pc_recstr [pos + 1 ]= '\0' ;
2618
+ } /* if */
2619
+ } /* if */
2620
+ }
2621
+
2511
2622
/* matchtoken
2512
2623
*
2513
2624
* This routine is useful if only a simple check is needed. If the token
0 commit comments