@@ -60,7 +60,7 @@ extern int optind; /* for getopt() */
60
60
#endif
61
61
62
62
#define EXTRA_UNDOC "(undoc)"
63
- #define EXTRA_DEBUG "debug: "
63
+ #define EXTRA_DEBUG "debug"
64
64
65
65
66
66
@@ -111,7 +111,7 @@ void usage_long(FILE *st)
111
111
fprintf (st , " -t, --tabs <str> Tab stop distance and expansion [default: %de]\n" , DEF_TABSTOP );
112
112
fprintf (st , " -v, --version Print version information\n" );
113
113
/* fprintf(st, " -x, --extra <arg> If <arg> starts with "debug:", activate debug logging for specified log
114
- areas which follow in a comma-separated list [default area: MAIN]. If <arg> is "undoc", trigger
114
+ areas which follow in a comma-separated list [default area: MAIN]. If <arg> is "( undoc) ", trigger
115
115
undocumented behavior of design detail lister."); // undocumented */
116
116
117
117
bxs_free (config_file );
@@ -562,6 +562,48 @@ static int tab_handling(opt_t *result, char *optarg)
562
562
563
563
564
564
565
+ /**
566
+ * Handle undocumented options (-x).
567
+ * @param result the options struct we are building
568
+ * @param optarg the argument to `-x` on the command line
569
+ * @returns 0 on success, anything else on error
570
+ */
571
+ static int undocumented_options (opt_t * result , char * optarg )
572
+ {
573
+ char * s = optarg ;
574
+
575
+ if (strncmp (s , EXTRA_UNDOC , strlen (EXTRA_UNDOC )) == 0 ) {
576
+ result -> qundoc = 1 ;
577
+ s += strlen (EXTRA_UNDOC );
578
+ }
579
+
580
+ if (strncasecmp (s , EXTRA_DEBUG , strlen (EXTRA_DEBUG )) == 0 ) {
581
+ s += strlen (EXTRA_DEBUG );
582
+ if (* s == ':' ) {
583
+ if (debug_areas (result , s + 1 ) != 0 ) {
584
+ return 1 ;
585
+ }
586
+ }
587
+ else if (* s == '\0' ) {
588
+ /* default to MAIN */
589
+ debug_areas (result , NULL );
590
+ }
591
+ else {
592
+ bx_fprintf (stderr , "%s: invalid option -x %s\n" , PROJECT , optarg );
593
+ return 2 ;
594
+ }
595
+ activate_debug_logging (result -> debug );
596
+ }
597
+
598
+ if (!result -> qundoc && !is_debug_activated ()) {
599
+ bx_fprintf (stderr , "%s: invalid option -x %s\n" , PROJECT , optarg );
600
+ return 3 ;
601
+ }
602
+ return 0 ;
603
+ }
604
+
605
+
606
+
565
607
/**
566
608
* Set *stdout* to binary mode, so that we can control the line terminator. This function only ever does anything on
567
609
* Windows, because on Linux, we already do have control over line terminators.
@@ -733,7 +775,6 @@ opt_t *process_commandline(int argc, char *argv[])
733
775
};
734
776
const char * short_options = "a:c:d:e:f:hi:k:lmn:p:q:rs:t:vx:" ;
735
777
736
- char * s ;
737
778
int oc ; /* option character */
738
779
do {
739
780
oc = getopt_long (argc , argv , short_options , long_options , & option_index );
@@ -866,18 +907,9 @@ opt_t *process_commandline(int argc, char *argv[])
866
907
return result ;
867
908
868
909
case 'x' :
869
- s = optarg ;
870
- if (strncmp (s , EXTRA_UNDOC , strlen (EXTRA_UNDOC )) == 0 ) {
871
- result -> qundoc = 1 ;
872
- s += strlen (EXTRA_UNDOC );
873
- }
874
- if (strncasecmp (s , EXTRA_DEBUG , strlen (EXTRA_DEBUG )) == 0 ) {
875
- s += strlen (EXTRA_DEBUG );
876
- if (debug_areas (result , s ) != 0 ) {
877
- BFREE (result );
878
- return NULL ;
879
- }
880
- activate_debug_logging (result -> debug );
910
+ if (undocumented_options (result , optarg ) != 0 ) {
911
+ BFREE (result );
912
+ return NULL ;
881
913
}
882
914
break ;
883
915
0 commit comments