History

docproc: add support for reStructuredText format via --rst option

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.

Jani Nikula committed 10 years ago

Commit 064669b1 parent 1dcdad01 file · +80 −10Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/docproc.c+80−10
@@ -42,6 +42,7 @@ · 41 unmodified lines
42#include <unistd.h>42#include <unistd.h>
43#include <limits.h>43#include <limits.h>
44#include <errno.h>44#include <errno.h>
45#include <getopt.h>
45#include <sys/types.h>46#include <sys/types.h>
46#include <sys/wait.h>47#include <sys/wait.h>
47 48
@@ -68,12 +69,23 @@ FILELINE * docsection; · 20 unmodified lines
68#define KERNELDOCPATH "scripts/"69#define KERNELDOCPATH "scripts/"
69#define KERNELDOC "kernel-doc"70#define KERNELDOC "kernel-doc"
70#define DOCBOOK "-docbook"71#define DOCBOOK "-docbook"
72#define RST "-rst"
71#define LIST "-list"73#define LIST "-list"
72#define FUNCTION "-function"74#define FUNCTION "-function"
73#define NOFUNCTION "-nofunction"75#define NOFUNCTION "-nofunction"
74#define NODOCSECTIONS "-no-doc-sections"76#define NODOCSECTIONS "-no-doc-sections"
75#define SHOWNOTFOUND "-show-not-found"77#define SHOWNOTFOUND "-show-not-found"
76 78
79enum file_format {
80 FORMAT_AUTO,
81 FORMAT_DOCBOOK,
82 FORMAT_RST,
83};
84
85static enum file_format file_format = FORMAT_AUTO;
86
87#define KERNELDOC_FORMAT (file_format == FORMAT_RST ? RST : DOCBOOK)
88
77static char *srctree, *kernsrctree;89static char *srctree, *kernsrctree;
78 90
79static char **all_list = NULL;91static char **all_list = NULL;
@@ -95,7 +107,7 @@ static void consume_symbol(const char *sym) · 15 unmodified lines
95 107
96static void usage (void)108static 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 fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");111 fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
100 fprintf(stderr, "doc: frontend when generating kernel documentation\n");112 fprintf(stderr, "doc: frontend when generating kernel documentation\n");
101 fprintf(stderr, "depend: generate list of files referenced within file\n");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 * Document all external or internal functions in a file.255 * Document all external or internal functions in a file.
244 * Call kernel-doc with following parameters:256 * Call kernel-doc with following parameters:
245 * kernel-doc -docbook -nofunction function_name1 filename257 * kernel-doc [-docbook|-rst] -nofunction function_name1 filename
246 * Function names are obtained from all the src files258 * Function names are obtained from all the src files
247 * by find_export_symbols.259 * by find_export_symbols.
248 * intfunc uses -nofunction260 * intfunc uses -nofunction
@@ -263,7 +275,7 @@ static void docfunctions(char * filename, char * type) · 14 unmodified lines
263 exit(1);275 exit(1);
264 }276 }
265 vec[idx++] = KERNELDOC;277 vec[idx++] = KERNELDOC;
266 vec[idx++] = DOCBOOK;278 vec[idx++] = KERNELDOC_FORMAT;
267 vec[idx++] = NODOCSECTIONS;279 vec[idx++] = NODOCSECTIONS;
268 for (i=0; i < symfilecnt; i++) {280 for (i=0; i < symfilecnt; i++) {
269 struct symfile * sym = &symfilelist[i];281 struct symfile * sym = &symfilelist[i];
@@ -275,7 +287,10 @@ static void docfunctions(char * filename, char * type) · 5 unmodified lines
275 }287 }
276 vec[idx++] = filename;288 vec[idx++] = filename;
277 vec[idx] = NULL;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 exec_kernel_doc(vec);294 exec_kernel_doc(vec);
280 fflush(stdout);295 fflush(stdout);
281 free(vec);296 free(vec);
@@ -294,7 +309,7 @@ static void singfunc(char * filename, char * line) · 12 unmodified lines
294 int i, idx = 0;309 int i, idx = 0;
295 int startofsym = 1;310 int startofsym = 1;
296 vec[idx++] = KERNELDOC;311 vec[idx++] = KERNELDOC;
297 vec[idx++] = DOCBOOK;312 vec[idx++] = KERNELDOC_FORMAT;
298 vec[idx++] = SHOWNOTFOUND;313 vec[idx++] = SHOWNOTFOUND;
299 314
300 /* Split line up in individual parameters preceded by FUNCTION */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 free(s);358 free(s);
344 359
345 vec[0] = KERNELDOC;360 vec[0] = KERNELDOC;
346 vec[1] = DOCBOOK;361 vec[1] = KERNELDOC_FORMAT;
347 vec[2] = SHOWNOTFOUND;362 vec[2] = SHOWNOTFOUND;
348 vec[3] = FUNCTION;363 vec[3] = FUNCTION;
349 vec[4] = line;364 vec[4] = line;
@@ -448,8 +463,10 @@ static char *chomp(char *s) · 98 unmodified lines
448/* Return pointer to directive content, or NULL if not a directive. */463/* Return pointer to directive content, or NULL if not a directive. */
449static char *is_directive(char *line)464static char *is_directive(char *line)
450{465{
451 if (line[0] == '!')466 if (file_format == FORMAT_DOCBOOK && line[0] == '!')
452 return line + 1;467 return line + 1;
468 else if (file_format == FORMAT_RST && !strncmp(line, ".. !", 4))
469 return line + 4;
453 470
454 return NULL;471 return NULL;
455}472}
@@ -516,6 +533,22 @@ static void parse_file(FILE *infile) · 60 unmodified lines
516 fflush(stdout);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 */
540static int is_rst(const char *file)
541{
542 char *dot = strrchr(file, '.');
543
544 return dot && !strcmp(dot + 1, "rst");
545}
546
547enum opts {
548 OPT_DOCBOOK,
549 OPT_RST,
550 OPT_HELP,
551};
519 552
520int main(int argc, char *argv[])553int main(int argc, char *argv[])
521{554{
@@ -529,13 +562,50 @@ int main(int argc, char *argv[]) · 7 unmodified lines
529 kernsrctree = getenv("KBUILD_SRC");562 kernsrctree = getenv("KBUILD_SRC");
530 if (!kernsrctree || !*kernsrctree)563 if (!kernsrctree || !*kernsrctree)
531 kernsrctree = srctree;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 usage();600 usage();
534 exit(1);601 exit(1);
535 }602 }
536 603
537 subcommand = argv[1];604 subcommand = argv[0];
538 filename = argv[2];605 filename = argv[1];
606
607 if (file_format == FORMAT_AUTO)
608 file_format = is_rst(filename) ? FORMAT_RST : FORMAT_DOCBOOK;
539 609
540 /* Open file, exit on error */610 /* Open file, exit on error */
541 infile = fopen(filename, "r");611 infile = fopen(filename, "r");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t