Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[linux-2.6-block.git] / scripts / basic / docproc.c
index 0e4bd5459df4e08e90770516e942ba9236da3a22..4c9523ef9c00d0a795862cc12e23b1eda80931d2 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,8 +67,9 @@ FILELINE * entity_system;
 #define DOCBOOK       "-docbook"
 #define FUNCTION      "-function"
 #define NOFUNCTION    "-nofunction"
+#define NODOCSECTIONS "-no-doc-sections"
 
-char *srctree;
+static char *srctree, *kernsrctree;
 
 void usage (void)
 {
@@ -74,7 +77,8 @@ 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");
+       fprintf(stderr, "Environment variable SRCTREE: absolute path to sources.\n");
+       fprintf(stderr, "                     KBUILD_SRC: absolute path to kernel source tree.\n");
 }
 
 /*
@@ -93,8 +97,8 @@ void exec_kernel_doc(char **svec)
                        exit(1);
                case  0:
                        memset(real_filename, 0, sizeof(real_filename));
-                       strncat(real_filename, srctree, PATH_MAX);
-                       strncat(real_filename, KERNELDOCPATH KERNELDOC,
+                       strncat(real_filename, kernsrctree, PATH_MAX);
+                       strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
                                        PATH_MAX - strlen(real_filename));
                        execvp(real_filename, svec);
                        fprintf(stderr, "exec ");
@@ -175,6 +179,7 @@ void find_export_symbols(char * filename)
                char real_filename[PATH_MAX + 1];
                memset(real_filename, 0, sizeof(real_filename));
                strncat(real_filename, srctree, PATH_MAX);
+               strncat(real_filename, "/", PATH_MAX - strlen(real_filename));
                strncat(real_filename, filename,
                                PATH_MAX - strlen(real_filename));
                sym = add_new_file(filename);
@@ -231,13 +236,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++) {
@@ -286,13 +292,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)
 {
@@ -326,6 +356,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);
                        }
@@ -345,6 +384,9 @@ int main(int argc, char *argv[])
        srctree = getenv("SRCTREE");
        if (!srctree)
                srctree = getcwd(NULL, 0);
+       kernsrctree = getenv("KBUILD_SRC");
+       if (!kernsrctree)
+               kernsrctree = srctree;
        if (argc != 3) {
                usage();
                exit(1);
@@ -372,6 +414,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 */
@@ -381,6 +424,7 @@ int main(int argc, char *argv[])
                externalfunctions = extfunc;
                symbolsonly       = printline;
                singlefunctions   = singfunc;
+               docsection        = docsect;
 
                parse_file(infile);
        }
@@ -394,6 +438,7 @@ int main(int argc, char *argv[])
                externalfunctions = adddep;
                symbolsonly       = adddep;
                singlefunctions   = adddep2;
+               docsection        = adddep2;
                parse_file(infile);
                printf("\n");
        }