tree-wide: fix assorted typos all over the place
[safe/jmp/linux-2.6] / scripts / basic / docproc.c
index 7eae534..79ab973 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
@@ -67,21 +69,22 @@ FILELINE * entity_system;
 #define NOFUNCTION    "-nofunction"
 #define NODOCSECTIONS "-no-doc-sections"
 
-char *srctree;
+static char *srctree, *kernsrctree;
 
-void usage (void)
+static void usage (void)
 {
        fprintf(stderr, "Usage: docproc {doc|depend} file\n");
        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");
 }
 
 /*
  * Execute kernel-doc with parameters given in svec
  */
-void exec_kernel_doc(char **svec)
+static void exec_kernel_doc(char **svec)
 {
        pid_t pid;
        int ret;
@@ -94,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 ");
@@ -126,7 +129,7 @@ struct symfile
 struct symfile symfilelist[MAXFILES];
 int symfilecnt = 0;
 
-void add_new_symbol(struct symfile *sym, char * symname)
+static void add_new_symbol(struct symfile *sym, char * symname)
 {
        sym->symbollist =
           realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *));
@@ -134,14 +137,14 @@ void add_new_symbol(struct symfile *sym, char * symname)
 }
 
 /* Add a filename to the list */
-struct symfile * add_new_file(char * filename)
+static struct symfile * add_new_file(char * filename)
 {
        symfilelist[symfilecnt++].filename = strdup(filename);
        return &symfilelist[symfilecnt - 1];
 }
 
 /* Check if file already are present in the list */
-struct symfile * filename_exist(char * filename)
+static struct symfile * filename_exist(char * filename)
 {
        int i;
        for (i=0; i < symfilecnt; i++)
@@ -154,20 +157,20 @@ struct symfile * filename_exist(char * filename)
  * List all files referenced within the template file.
  * Files are separated by tabs.
  */
-void adddep(char * file)                  { printf("\t%s", file); }
-void adddep2(char * file, char * line)     { line = line; adddep(file); }
-void noaction(char * line)                { line = line; }
-void noaction2(char * file, char * line)   { file = file; line = line; }
+static void adddep(char * file)                   { printf("\t%s", file); }
+static void adddep2(char * file, char * line)     { line = line; adddep(file); }
+static void noaction(char * line)                 { line = line; }
+static void noaction2(char * file, char * line)   { file = file; line = line; }
 
 /* Echo the line without further action */
-void printline(char * line)               { printf("%s", line); }
+static void printline(char * line)               { printf("%s", line); }
 
 /*
  * Find all symbols in filename that are exported with EXPORT_SYMBOL &
  * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly).
  * All symbols located are stored in symfilelist.
  */
-void find_export_symbols(char * filename)
+static void find_export_symbols(char * filename)
 {
        FILE * fp;
        struct symfile *sym;
@@ -176,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);
@@ -223,7 +227,7 @@ void find_export_symbols(char * filename)
  * intfunc uses -nofunction
  * extfunc uses -function
  */
-void docfunctions(char * filename, char * type)
+static void docfunctions(char * filename, char * type)
 {
        int i,j;
        int symcnt = 0;
@@ -254,15 +258,15 @@ void docfunctions(char * filename, char * type)
        fflush(stdout);
        free(vec);
 }
-void intfunc(char * filename) {        docfunctions(filename, NOFUNCTION); }
-void extfunc(char * filename) { docfunctions(filename, FUNCTION);   }
+static void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); }
+static void extfunc(char * filename) { docfunctions(filename, FUNCTION);   }
 
 /*
  * Document specific function(s) in a file.
  * Call kernel-doc with the following parameters:
  * kernel-doc -docbook -function function1 [-function function2]
  */
-void singfunc(char * filename, char * line)
+static void singfunc(char * filename, char * line)
 {
        char *vec[200]; /* Enough for specific functions */
         int i, idx = 0;
@@ -289,14 +293,38 @@ void singfunc(char * filename, char * line)
 }
 
 /*
+ * Insert specific documentation section from a file.
+ * Call kernel-doc with the following parameters:
+ * kernel-doc -docbook -function "doc section" filename
+ */
+static 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)
+static void parse_file(FILE *infile)
 {
        char line[MAXLINESZ];
        char * s;
@@ -328,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);
                        }
@@ -347,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)
+               kernsrctree = srctree;
        if (argc != 3) {
                usage();
                exit(1);
@@ -374,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 */
@@ -383,6 +424,7 @@ int main(int argc, char *argv[])
                externalfunctions = extfunc;
                symbolsonly       = printline;
                singlefunctions   = singfunc;
+               docsection        = docsect;
 
                parse_file(infile);
        }
@@ -396,6 +438,7 @@ int main(int argc, char *argv[])
                externalfunctions = adddep;
                symbolsonly       = adddep;
                singlefunctions   = adddep2;
+               docsection        = adddep2;
                parse_file(infile);
                printf("\n");
        }