Expect reStructuredText input and have kernel-doc produce reStructuredText output with the new --rst option. Also add --docbook option for completeness. If no option is given, default to reStructuredText if the input file has ".rst" extension, DocBook otherwise. Directives for reStructuredText use .. ! instead of just !, to make them reStructuredText comments.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -42,6 +42,7 @@ · 41 unmodified lines | ||
| 42 | 42 | #include <unistd.h> |
| 43 | 43 | #include <limits.h> |
| 44 | 44 | #include <errno.h> |
| 45 | +#include <getopt.h> | |
| 45 | 46 | #include <sys/types.h> |
| 46 | 47 | #include <sys/wait.h> |
| 47 | 48 | |
| @@ -68,12 +69,23 @@ FILELINE * docsection; · 20 unmodified lines | ||
| 68 | 69 | #define KERNELDOCPATH "scripts/" |
| 69 | 70 | #define KERNELDOC "kernel-doc" |
| 70 | 71 | #define DOCBOOK "-docbook" |
| 72 | +#define RST "-rst" | |
| 71 | 73 | #define LIST "-list" |
| 72 | 74 | #define FUNCTION "-function" |
| 73 | 75 | #define NOFUNCTION "-nofunction" |
| 74 | 76 | #define NODOCSECTIONS "-no-doc-sections" |
| 75 | 77 | #define SHOWNOTFOUND "-show-not-found" |
| 76 | 78 | |
| 79 | +enum file_format { | |
| 80 | + FORMAT_AUTO, | |
| 81 | + FORMAT_DOCBOOK, | |
| 82 | + FORMAT_RST, | |
| 83 | +}; | |
| 84 | + | |
| 85 | +static enum file_format file_format = FORMAT_AUTO; | |
| 86 | + | |
| 87 | +#define KERNELDOC_FORMAT (file_format == FORMAT_RST ? RST : DOCBOOK) | |
| 88 | + | |
| 77 | 89 | static char *srctree, *kernsrctree; |
| 78 | 90 | |
| 79 | 91 | static char **all_list = NULL; |
| @@ -95,7 +107,7 @@ static void consume_symbol(const char *sym) · 15 unmodified lines | ||
| 95 | 107 | |
| 96 | 108 | static void usage (void) |
| 97 | 109 | { |
| 98 | − fprintf(stderr, "Usage: docproc {doc|depend} file\n"); | |
| 110 | + fprintf(stderr, "Usage: docproc [{--docbook|--rst}] {doc|depend} file\n"); | |
| 99 | 111 | fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n"); |
| 100 | 112 | fprintf(stderr, "doc: frontend when generating kernel documentation\n"); |
| 101 | 113 | fprintf(stderr, "depend: generate list of files referenced within file\n"); |
| @@ -242,7 +254,7 @@ static void find_export_symbols(char * filename) · 140 unmodified lines | ||
| 242 | 254 | /* |
| 243 | 255 | * Document all external or internal functions in a file. |
| 244 | 256 | * Call kernel-doc with following parameters: |
| 245 | − * kernel-doc -docbook -nofunction function_name1 filename | |
| 257 | + * kernel-doc [-docbook|-rst] -nofunction function_name1 filename | |
| 246 | 258 | * Function names are obtained from all the src files |
| 247 | 259 | * by find_export_symbols. |
| 248 | 260 | * intfunc uses -nofunction |
| @@ -263,7 +275,7 @@ static void docfunctions(char * filename, char * type) · 14 unmodified lines | ||
| 263 | 275 | exit(1); |
| 264 | 276 | } |
| 265 | 277 | vec[idx++] = KERNELDOC; |
| 266 | − vec[idx++] = DOCBOOK; | |
| 278 | + vec[idx++] = KERNELDOC_FORMAT; | |
| 267 | 279 | vec[idx++] = NODOCSECTIONS; |
| 268 | 280 | for (i=0; i < symfilecnt; i++) { |
| 269 | 281 | struct symfile * sym = &symfilelist[i]; |
| @@ -275,7 +287,10 @@ static void docfunctions(char * filename, char * type) · 5 unmodified lines | ||
| 275 | 287 | } |
| 276 | 288 | vec[idx++] = filename; |
| 277 | 289 | vec[idx] = NULL; |
| 278 | − printf("<!-- %s -->\n", filename); | |
| 290 | + if (file_format == FORMAT_RST) | |
| 291 | + printf(".. %s\n", filename); | |
| 292 | + else | |
| 293 | + printf("<!-- %s -->\n", filename); | |
| 279 | 294 | exec_kernel_doc(vec); |
| 280 | 295 | fflush(stdout); |
| 281 | 296 | free(vec); |
| @@ -294,7 +309,7 @@ static void singfunc(char * filename, char * line) · 12 unmodified lines | ||
| 294 | 309 | int i, idx = 0; |
| 295 | 310 | int startofsym = 1; |
| 296 | 311 | vec[idx++] = KERNELDOC; |
| 297 | − vec[idx++] = DOCBOOK; | |
| 312 | + vec[idx++] = KERNELDOC_FORMAT; | |
| 298 | 313 | vec[idx++] = SHOWNOTFOUND; |
| 299 | 314 | |
| 300 | 315 | /* Split line up in individual parameters preceded by FUNCTION */ |
| @@ -343,7 +358,7 @@ static void docsect(char *filename, char *line) · 42 unmodified lines | ||
| 343 | 358 | free(s); |
| 344 | 359 | |
| 345 | 360 | vec[0] = KERNELDOC; |
| 346 | − vec[1] = DOCBOOK; | |
| 361 | + vec[1] = KERNELDOC_FORMAT; | |
| 347 | 362 | vec[2] = SHOWNOTFOUND; |
| 348 | 363 | vec[3] = FUNCTION; |
| 349 | 364 | vec[4] = line; |
| @@ -448,8 +463,10 @@ static char *chomp(char *s) · 98 unmodified lines | ||
| 448 | 463 | /* Return pointer to directive content, or NULL if not a directive. */ |
| 449 | 464 | static char *is_directive(char *line) |
| 450 | 465 | { |
| 451 | − if (line[0] == '!') | |
| 466 | + if (file_format == FORMAT_DOCBOOK && line[0] == '!') | |
| 452 | 467 | return line + 1; |
| 468 | + else if (file_format == FORMAT_RST && !strncmp(line, ".. !", 4)) | |
| 469 | + return line + 4; | |
| 453 | 470 | |
| 454 | 471 | return NULL; |
| 455 | 472 | } |
| @@ -516,6 +533,22 @@ static void parse_file(FILE *infile) · 60 unmodified lines | ||
| 516 | 533 | fflush(stdout); |
| 517 | 534 | } |
| 518 | 535 | |
| 536 | +/* | |
| 537 | + * Is this a RestructuredText template? Answer the question by seeing if its | |
| 538 | + * name ends in ".rst". | |
| 539 | + */ | |
| 540 | +static int is_rst(const char *file) | |
| 541 | +{ | |
| 542 | + char *dot = strrchr(file, '.'); | |
| 543 | + | |
| 544 | + return dot && !strcmp(dot + 1, "rst"); | |
| 545 | +} | |
| 546 | + | |
| 547 | +enum opts { | |
| 548 | + OPT_DOCBOOK, | |
| 549 | + OPT_RST, | |
| 550 | + OPT_HELP, | |
| 551 | +}; | |
| 519 | 552 | |
| 520 | 553 | int main(int argc, char *argv[]) |
| 521 | 554 | { |
| @@ -529,13 +562,50 @@ int main(int argc, char *argv[]) · 7 unmodified lines | ||
| 529 | 562 | kernsrctree = getenv("KBUILD_SRC"); |
| 530 | 563 | if (!kernsrctree || !*kernsrctree) |
| 531 | 564 | kernsrctree = srctree; |
| 532 | − if (argc != 3) { | |
| 565 | + | |
| 566 | + for (;;) { | |
| 567 | + int c; | |
| 568 | + struct option opts[] = { | |
| 569 | + { "docbook", no_argument, NULL, OPT_DOCBOOK }, | |
| 570 | + { "rst", no_argument, NULL, OPT_RST }, | |
| 571 | + { "help", no_argument, NULL, OPT_HELP }, | |
| 572 | + {} | |
| 573 | + }; | |
| 574 | + | |
| 575 | + c = getopt_long_only(argc, argv, "", opts, NULL); | |
| 576 | + if (c == -1) | |
| 577 | + break; | |
| 578 | + | |
| 579 | + switch (c) { | |
| 580 | + case OPT_DOCBOOK: | |
| 581 | + file_format = FORMAT_DOCBOOK; | |
| 582 | + break; | |
| 583 | + case OPT_RST: | |
| 584 | + file_format = FORMAT_RST; | |
| 585 | + break; | |
| 586 | + case OPT_HELP: | |
| 587 | + usage(); | |
| 588 | + return 0; | |
| 589 | + default: | |
| 590 | + case '?': | |
| 591 | + usage(); | |
| 592 | + return 1; | |
| 593 | + } | |
| 594 | + } | |
| 595 | + | |
| 596 | + argc -= optind; | |
| 597 | + argv += optind; | |
| 598 | + | |
| 599 | + if (argc != 2) { | |
| 533 | 600 | usage(); |
| 534 | 601 | exit(1); |
| 535 | 602 | } |
| 536 | 603 | |
| 537 | − subcommand = argv[1]; | |
| 538 | − filename = argv[2]; | |
| 604 | + subcommand = argv[0]; | |
| 605 | + filename = argv[1]; | |
| 606 | + | |
| 607 | + if (file_format == FORMAT_AUTO) | |
| 608 | + file_format = is_rst(filename) ? FORMAT_RST : FORMAT_DOCBOOK; | |
| 539 | 609 | |
| 540 | 610 | /* Open file, exit on error */ |
| 541 | 611 | infile = fopen(filename, "r"); |