]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - scripts/basic/docproc.c
Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-omap-h63xx.git] / scripts / basic / docproc.c
index e5c6ac7bde9b5778320ce1f99553c66c79a25826..35bdc68b6e66604fc31f184fff4ad1c0e6c5398e 100644 (file)
@@ -30,6 +30,7 @@
  *             !Ifilename
  *             !Dfilename
  *             !Ffilename
+ *             !Pfilename
  *
  */
 
@@ -57,6 +58,7 @@ FILEONLY *symbolsonly;
 typedef void FILELINE(char * file, char * line);
 FILELINE * singlefunctions;
 FILELINE * entity_system;
+FILELINE * docsection;
 
 #define MAXLINESZ     2048
 #define MAXFILES      250
@@ -65,6 +67,9 @@ FILELINE * entity_system;
 #define DOCBOOK       "-docbook"
 #define FUNCTION      "-function"
 #define NOFUNCTION    "-nofunction"
+#define NODOCSECTIONS "-no-doc-sections"
+
+char *srctree;
 
 void usage (void)
 {
@@ -72,6 +77,7 @@ void usage (void)
        fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n");
        fprintf(stderr, "doc: frontend when generating kernel documentation\n");
        fprintf(stderr, "depend: generate list of files referenced within file\n");
+       fprintf(stderr, "Environment variable SRCTREE: absolute path to kernel source tree.\n");
 }
 
 /*
@@ -90,7 +96,7 @@ void exec_kernel_doc(char **svec)
                        exit(1);
                case  0:
                        memset(real_filename, 0, sizeof(real_filename));
-                       strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
+                       strncat(real_filename, srctree, PATH_MAX);
                        strncat(real_filename, KERNELDOCPATH KERNELDOC,
                                        PATH_MAX - strlen(real_filename));
                        execvp(real_filename, svec);
@@ -171,7 +177,7 @@ void find_export_symbols(char * filename)
        if (filename_exist(filename) == NULL) {
                char real_filename[PATH_MAX + 1];
                memset(real_filename, 0, sizeof(real_filename));
-               strncat(real_filename, getenv("SRCTREE"), PATH_MAX);
+               strncat(real_filename, srctree, PATH_MAX);
                strncat(real_filename, filename,
                                PATH_MAX - strlen(real_filename));
                sym = add_new_file(filename);
@@ -228,13 +234,14 @@ void docfunctions(char * filename, char * type)
 
        for (i=0; i <= symfilecnt; i++)
                symcnt += symfilelist[i].symbolcnt;
-       vec = malloc((2 + 2 * symcnt + 2) * sizeof(char*));
+       vec = malloc((2 + 2 * symcnt + 3) * sizeof(char *));
        if (vec == NULL) {
                perror("docproc: ");
                exit(1);
        }
        vec[idx++] = KERNELDOC;
        vec[idx++] = DOCBOOK;
+       vec[idx++] = NODOCSECTIONS;
        for (i=0; i < symfilecnt; i++) {
                struct symfile * sym = &symfilelist[i];
                for (j=0; j < sym->symbolcnt; j++) {
@@ -283,13 +290,37 @@ void singfunc(char * filename, char * line)
        exec_kernel_doc(vec);
 }
 
+/*
+ * Insert specific documentation section from a file.
+ * Call kernel-doc with the following parameters:
+ * kernel-doc -docbook -function "doc section" filename
+ */
+void docsect(char *filename, char *line)
+{
+       char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */
+       char *s;
+
+       for (s = line; *s; s++)
+               if (*s == '\n')
+                       *s = '\0';
+
+       vec[0] = KERNELDOC;
+       vec[1] = DOCBOOK;
+       vec[2] = FUNCTION;
+       vec[3] = line;
+       vec[4] = filename;
+       vec[5] = NULL;
+       exec_kernel_doc(vec);
+}
+
 /*
  * Parse file, calling action specific functions for:
  * 1) Lines containing !E
  * 2) Lines containing !I
  * 3) Lines containing !D
  * 4) Lines containing !F
- * 5) Default lines - lines not matching the above
+ * 5) Lines containing !P
+ * 6) Default lines - lines not matching the above
  */
 void parse_file(FILE *infile)
 {
@@ -323,6 +354,15 @@ void parse_file(FILE *infile)
                                                s++;
                                        singlefunctions(line +2, s);
                                        break;
+                               case 'P':
+                                       /* filename */
+                                       while (*s && !isspace(*s)) s++;
+                                       *s++ = '\0';
+                                       /* DOC: section name */
+                                       while (isspace(*s))
+                                               s++;
+                                       docsection(line + 2, s);
+                                       break;
                                default:
                                        defaultline(line);
                        }
@@ -338,6 +378,10 @@ void parse_file(FILE *infile)
 int main(int argc, char *argv[])
 {
        FILE * infile;
+
+       srctree = getenv("SRCTREE");
+       if (!srctree)
+               srctree = getcwd(NULL, 0);
        if (argc != 3) {
                usage();
                exit(1);
@@ -365,6 +409,7 @@ int main(int argc, char *argv[])
                externalfunctions = find_export_symbols;
                symbolsonly       = find_export_symbols;
                singlefunctions   = noaction2;
+               docsection        = noaction2;
                parse_file(infile);
 
                /* Rewind to start from beginning of file again */
@@ -374,6 +419,7 @@ int main(int argc, char *argv[])
                externalfunctions = extfunc;
                symbolsonly       = printline;
                singlefunctions   = singfunc;
+               docsection        = docsect;
 
                parse_file(infile);
        }
@@ -387,6 +433,7 @@ int main(int argc, char *argv[])
                externalfunctions = adddep;
                symbolsonly       = adddep;
                singlefunctions   = adddep2;
+               docsection        = adddep2;
                parse_file(infile);
                printf("\n");
        }