@@ -311,6 +311,9 @@ struct token {
311311
312312static struct token * token_list ;
313313static unsigned nr_tokens ;
314+ static _Bool verbose ;
315+
316+ #define debug (fmt , ...) do { if (verbose) printf(fmt, ## __VA_ARGS__); } while (0)
314317
315318static int directive_compare (const void * _key , const void * _pdir )
316319{
@@ -322,21 +325,21 @@ static int directive_compare(const void *_key, const void *_pdir)
322325 dlen = strlen (dir );
323326 clen = (dlen < token -> size ) ? dlen : token -> size ;
324327
325- //printf ("cmp(%*.*s,%s) = ",
328+ //debug ("cmp(%*.*s,%s) = ",
326329 // (int)token->size, (int)token->size, token->value,
327330 // dir);
328331
329332 val = memcmp (token -> value , dir , clen );
330333 if (val != 0 ) {
331- //printf ("%d [cmp]\n", val);
334+ //debug ("%d [cmp]\n", val);
332335 return val ;
333336 }
334337
335338 if (dlen == token -> size ) {
336- //printf ("0\n");
339+ //debug ("0\n");
337340 return 0 ;
338341 }
339- //printf ("%d\n", (int)dlen - (int)token->size);
342+ //debug ("%d\n", (int)dlen - (int)token->size);
340343 return dlen - token -> size ; /* shorter -> negative */
341344}
342345
@@ -515,13 +518,13 @@ static void tokenise(char *buffer, char *end)
515518 }
516519
517520 nr_tokens = tix ;
518- printf ("Extracted %u tokens\n" , nr_tokens );
521+ debug ("Extracted %u tokens\n" , nr_tokens );
519522
520523#if 0
521524 {
522525 int n ;
523526 for (n = 0 ; n < nr_tokens ; n ++ )
524- printf ("Token %3u: '%*.*s'\n" ,
527+ debug ("Token %3u: '%*.*s'\n" ,
525528 n ,
526529 (int )token_list [n ].size , (int )token_list [n ].size ,
527530 token_list [n ].value );
@@ -542,6 +545,7 @@ int main(int argc, char **argv)
542545 ssize_t readlen ;
543546 FILE * out , * hdr ;
544547 char * buffer , * p ;
548+ char * kbuild_verbose ;
545549 int fd ;
546550
547551 if (argc != 4 ) {
@@ -550,6 +554,10 @@ int main(int argc, char **argv)
550554 exit (2 );
551555 }
552556
557+ kbuild_verbose = getenv ("KBUILD_VERBOSE" );
558+ if (kbuild_verbose )
559+ verbose = atoi (kbuild_verbose );
560+
553561 filename = argv [1 ];
554562 outputname = argv [2 ];
555563 headername = argv [3 ];
@@ -748,11 +756,11 @@ static void build_type_list(void)
748756
749757 qsort (type_index , nr , sizeof (type_index [0 ]), type_index_compare );
750758
751- printf ("Extracted %u types\n" , nr_types );
759+ debug ("Extracted %u types\n" , nr_types );
752760#if 0
753761 for (n = 0 ; n < nr_types ; n ++ ) {
754762 struct type * type = type_index [n ];
755- printf ("- %*.*s\n" ,
763+ debug ("- %*.*s\n" ,
756764 (int )type -> name -> size ,
757765 (int )type -> name -> size ,
758766 type -> name -> value );
@@ -793,7 +801,7 @@ static void parse(void)
793801
794802 } while (type ++ , !(type -> flags & TYPE_STOP_MARKER ));
795803
796- printf ("Extracted %u actions\n" , nr_actions );
804+ debug ("Extracted %u actions\n" , nr_actions );
797805}
798806
799807static struct element * element_list ;
@@ -1284,7 +1292,7 @@ static void render(FILE *out, FILE *hdr)
12841292 }
12851293
12861294 /* We do two passes - the first one calculates all the offsets */
1287- printf ("Pass 1\n" );
1295+ debug ("Pass 1\n" );
12881296 nr_entries = 0 ;
12891297 root = & type_list [0 ];
12901298 render_element (NULL , root -> element , NULL );
@@ -1295,7 +1303,7 @@ static void render(FILE *out, FILE *hdr)
12951303 e -> flags &= ~ELEMENT_RENDERED ;
12961304
12971305 /* And then we actually render */
1298- printf ("Pass 2\n" );
1306+ debug ("Pass 2\n" );
12991307 fprintf (out , "\n" );
13001308 fprintf (out , "static const unsigned char %s_machine[] = {\n" ,
13011309 grammar_name );
0 commit comments