]> ocean-lang.org Git - ocean/commitdiff
scanner: allow a section to be specified.
authorNeilBrown <neil@brown.name>
Sat, 8 Jun 2019 10:27:15 +0000 (20:27 +1000)
committerNeilBrown <neil@brown.name>
Sat, 8 Jun 2019 10:27:15 +0000 (20:27 +1000)
If --section arg is given, only report on that section.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/scanner.mdc

index 80adb2a3ad1f7b1684af3ee7fb1f77006492c7a0..9a040e1c39e97e1205dcccb5208919eb6b4203ad 100644 (file)
@@ -2030,12 +2030,15 @@ the tokens one per line.
                        { "ignore-block-comment", 0, NULL, 'C'},
                        { "ignore-indent",      0, NULL, 'i'},
                        { "file",               1, NULL, 'f'},
                        { "ignore-block-comment", 0, NULL, 'C'},
                        { "ignore-indent",      0, NULL, 'i'},
                        { "file",               1, NULL, 'f'},
+                       { "section",            1, NULL, 's'},
                        { NULL,                 0, NULL, 0},
                };
                        { NULL,                 0, NULL, 0},
                };
-               static const char options[] = "W:w:n:NIMSzclCif:";
+               static const char options[] = "W:w:n:NIMSzclCif:s:";
 
                struct section *table, *s, *prev;
                int opt;
 
                struct section *table, *s, *prev;
                int opt;
+               char *section_name = NULL;
+               int section_found = 0;
 
                setlocale(LC_ALL,"");
                while ((opt = getopt_long(argc, argv, options, long_options, NULL))
 
                setlocale(LC_ALL,"");
                while ((opt = getopt_long(argc, argv, options, long_options, NULL))
@@ -2054,6 +2057,7 @@ the tokens one per line.
                        case 'l': conf.ignored |= 1 << TK_newline; break;
                        case 'i': conf.ignored |= 1 << TK_in; break;
                        case 'f': filename = optarg; break;
                        case 'l': conf.ignored |= 1 << TK_newline; break;
                        case 'i': conf.ignored |= 1 << TK_in; break;
                        case 'f': filename = optarg; break;
+                       case 's': section_name = optarg; break;
                        default: fprintf(stderr, "scanner: unknown option '%c'.\n",
                                         opt);
                                exit(1);
                        default: fprintf(stderr, "scanner: unknown option '%c'.\n",
                                         opt);
                                exit(1);
@@ -2090,6 +2094,12 @@ the tokens one per line.
 
                for (s = table; s;
                        (code_free(s->code), prev = s, s = s->next, free(prev))) {
 
                for (s = table; s;
                        (code_free(s->code), prev = s, s = s->next, free(prev))) {
+                       if (section_name &&
+                           (s->section.len != strlen(section_name) ||
+                            strncmp(s->section.txt, section_name, s->section.len) != 0))
+                               continue;
+                       if (section_name)
+                               section_found = 1;
                        printf("Tokenizing: %.*s\n", s->section.len,
                                s->section.txt);
                        state = token_open(s->code, &conf);
                        printf("Tokenizing: %.*s\n", s->section.len,
                                s->section.txt);
                        state = token_open(s->code, &conf);
@@ -2132,6 +2142,10 @@ the tokens one per line.
                }
                if (conf.words_marks != known)
                        free(conf.words_marks);
                }
                if (conf.words_marks != known)
                        free(conf.words_marks);
+               if (section_name && !section_found) {
+                       fprintf(stderr, "scanner: section %s not found\n", section_name);
+                       errs = 1;
+               }
                exit(!!errs);
        }
 ###### File: scanner.mk
                exit(!!errs);
        }
 ###### File: scanner.mk