2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* docproc is a simple preprocessor for the template files
|
|
|
|
* used as placeholders for the kernel internal documentation.
|
|
|
|
* docproc is used for documentation-frontend and
|
|
|
|
* dependency-generator.
|
|
|
|
* The two usages have in common that they require
|
|
|
|
* some knowledge of the .tmpl syntax, therefore they
|
|
|
|
* are kept together.
|
|
|
|
*
|
|
|
|
* documentation-frontend
|
|
|
|
* Scans the template file and call kernel-doc for
|
|
|
|
* all occurrences of ![EIF]file
|
2007-09-05 12:23:22 +08:00
|
|
|
* Beforehand each referenced file is scanned for
|
|
|
|
* any symbols that are exported via these macros:
|
|
|
|
* EXPORT_SYMBOL(), EXPORT_SYMBOL_GPL(), &
|
|
|
|
* EXPORT_SYMBOL_GPL_FUTURE()
|
2005-04-17 06:20:36 +08:00
|
|
|
* This is used to create proper -function and
|
|
|
|
* -nofunction arguments in calls to kernel-doc.
|
|
|
|
* Usage: docproc doc file.tmpl
|
|
|
|
*
|
|
|
|
* dependency-generator:
|
|
|
|
* Scans the template file and list all files
|
|
|
|
* referenced in a format recognized by make.
|
|
|
|
* Usage: docproc depend file.tmpl
|
|
|
|
* Writes dependency information to stdout
|
|
|
|
* in the following format:
|
|
|
|
* file.tmpl src.c src2.c
|
|
|
|
* The filenames are obtained from the following constructs:
|
|
|
|
* !Efilename
|
|
|
|
* !Ifilename
|
|
|
|
* !Dfilename
|
|
|
|
* !Ffilename
|
2007-10-25 06:08:48 +08:00
|
|
|
* !Pfilename
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-09-12 06:55:22 +08:00
|
|
|
#define _GNU_SOURCE
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
2010-09-12 06:55:22 +08:00
|
|
|
#include <errno.h>
|
2016-05-12 21:15:43 +08:00
|
|
|
#include <getopt.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2016-05-12 21:15:44 +08:00
|
|
|
#include <time.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* exitstatus is used to keep track of any failing calls to kernel-doc,
|
|
|
|
* but execution continues. */
|
|
|
|
int exitstatus = 0;
|
|
|
|
|
|
|
|
typedef void DFL(char *);
|
|
|
|
DFL *defaultline;
|
|
|
|
|
|
|
|
typedef void FILEONLY(char * file);
|
|
|
|
FILEONLY *internalfunctions;
|
|
|
|
FILEONLY *externalfunctions;
|
|
|
|
FILEONLY *symbolsonly;
|
2010-09-12 06:55:22 +08:00
|
|
|
FILEONLY *findall;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-26 05:59:22 +08:00
|
|
|
typedef void FILELINE(char * file, char * line);
|
2005-04-17 06:20:36 +08:00
|
|
|
FILELINE * singlefunctions;
|
|
|
|
FILELINE * entity_system;
|
2007-10-25 06:08:48 +08:00
|
|
|
FILELINE * docsection;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define MAXLINESZ 2048
|
|
|
|
#define MAXFILES 250
|
|
|
|
#define KERNELDOCPATH "scripts/"
|
|
|
|
#define KERNELDOC "kernel-doc"
|
|
|
|
#define DOCBOOK "-docbook"
|
2016-05-12 21:15:43 +08:00
|
|
|
#define RST "-rst"
|
2010-09-12 06:55:22 +08:00
|
|
|
#define LIST "-list"
|
2005-04-17 06:20:36 +08:00
|
|
|
#define FUNCTION "-function"
|
|
|
|
#define NOFUNCTION "-nofunction"
|
2007-10-25 06:08:48 +08:00
|
|
|
#define NODOCSECTIONS "-no-doc-sections"
|
2013-11-13 07:11:12 +08:00
|
|
|
#define SHOWNOTFOUND "-show-not-found"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-05-12 21:15:43 +08:00
|
|
|
enum file_format {
|
|
|
|
FORMAT_AUTO,
|
|
|
|
FORMAT_DOCBOOK,
|
|
|
|
FORMAT_RST,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum file_format file_format = FORMAT_AUTO;
|
|
|
|
|
|
|
|
#define KERNELDOC_FORMAT (file_format == FORMAT_RST ? RST : DOCBOOK)
|
|
|
|
|
2009-06-01 00:05:34 +08:00
|
|
|
static char *srctree, *kernsrctree;
|
2007-10-09 14:25:18 +08:00
|
|
|
|
2010-09-12 06:55:22 +08:00
|
|
|
static char **all_list = NULL;
|
|
|
|
static int all_list_len = 0;
|
|
|
|
|
|
|
|
static void consume_symbol(const char *sym)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < all_list_len; i++) {
|
|
|
|
if (!all_list[i])
|
|
|
|
continue;
|
|
|
|
if (strcmp(sym, all_list[i]))
|
|
|
|
continue;
|
|
|
|
all_list[i] = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-19 03:49:23 +08:00
|
|
|
static void usage (void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-05-12 21:15:43 +08:00
|
|
|
fprintf(stderr, "Usage: docproc [{--docbook|--rst}] {doc|depend} file\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
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");
|
2009-06-01 00:05:34 +08:00
|
|
|
fprintf(stderr, "Environment variable SRCTREE: absolute path to sources.\n");
|
|
|
|
fprintf(stderr, " KBUILD_SRC: absolute path to kernel source tree.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-09-05 12:23:22 +08:00
|
|
|
* Execute kernel-doc with parameters given in svec
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
static void exec_kernel_doc(char **svec)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
int ret;
|
|
|
|
char real_filename[PATH_MAX + 1];
|
|
|
|
/* Make sure output generated so far are flushed */
|
|
|
|
fflush(stdout);
|
2007-09-05 12:23:22 +08:00
|
|
|
switch (pid=fork()) {
|
2005-04-17 06:20:36 +08:00
|
|
|
case -1:
|
|
|
|
perror("fork");
|
|
|
|
exit(1);
|
|
|
|
case 0:
|
|
|
|
memset(real_filename, 0, sizeof(real_filename));
|
2009-06-01 00:05:34 +08:00
|
|
|
strncat(real_filename, kernsrctree, PATH_MAX);
|
|
|
|
strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
|
2005-04-17 06:20:36 +08:00
|
|
|
PATH_MAX - strlen(real_filename));
|
|
|
|
execvp(real_filename, svec);
|
|
|
|
fprintf(stderr, "exec ");
|
|
|
|
perror(real_filename);
|
|
|
|
exit(1);
|
|
|
|
default:
|
|
|
|
waitpid(pid, &ret ,0);
|
|
|
|
}
|
|
|
|
if (WIFEXITED(ret))
|
|
|
|
exitstatus |= WEXITSTATUS(ret);
|
|
|
|
else
|
|
|
|
exitstatus = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Types used to create list of all exported symbols in a number of files */
|
|
|
|
struct symbols
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct symfile
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
struct symbols *symbollist;
|
|
|
|
int symbolcnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct symfile symfilelist[MAXFILES];
|
|
|
|
int symfilecnt = 0;
|
|
|
|
|
2009-09-19 03:49:23 +08:00
|
|
|
static void add_new_symbol(struct symfile *sym, char * symname)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
sym->symbollist =
|
2014-06-10 18:08:13 +08:00
|
|
|
realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *));
|
2005-04-17 06:20:36 +08:00
|
|
|
sym->symbollist[sym->symbolcnt++].name = strdup(symname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a filename to the list */
|
2009-09-19 03:49:23 +08:00
|
|
|
static struct symfile * add_new_file(char * filename)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
symfilelist[symfilecnt++].filename = strdup(filename);
|
|
|
|
return &symfilelist[symfilecnt - 1];
|
|
|
|
}
|
2007-09-05 12:23:22 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Check if file already are present in the list */
|
2009-09-19 03:49:23 +08:00
|
|
|
static struct symfile * filename_exist(char * filename)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i < symfilecnt; i++)
|
|
|
|
if (strcmp(symfilelist[i].filename, filename) == 0)
|
|
|
|
return &symfilelist[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List all files referenced within the template file.
|
|
|
|
* Files are separated by tabs.
|
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
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; }
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Echo the line without further action */
|
2009-09-19 03:49:23 +08:00
|
|
|
static void printline(char * line) { printf("%s", line); }
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2007-09-05 12:23:22 +08:00
|
|
|
* Find all symbols in filename that are exported with EXPORT_SYMBOL &
|
|
|
|
* EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly).
|
2005-04-17 06:20:36 +08:00
|
|
|
* All symbols located are stored in symfilelist.
|
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
static void find_export_symbols(char * filename)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
FILE * fp;
|
|
|
|
struct symfile *sym;
|
|
|
|
char line[MAXLINESZ];
|
|
|
|
if (filename_exist(filename) == NULL) {
|
|
|
|
char real_filename[PATH_MAX + 1];
|
|
|
|
memset(real_filename, 0, sizeof(real_filename));
|
2007-10-09 14:25:18 +08:00
|
|
|
strncat(real_filename, srctree, PATH_MAX);
|
2009-06-01 00:05:34 +08:00
|
|
|
strncat(real_filename, "/", PATH_MAX - strlen(real_filename));
|
2005-04-17 06:20:36 +08:00
|
|
|
strncat(real_filename, filename,
|
|
|
|
PATH_MAX - strlen(real_filename));
|
|
|
|
sym = add_new_file(filename);
|
|
|
|
fp = fopen(real_filename, "r");
|
2011-06-15 17:53:13 +08:00
|
|
|
if (fp == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
fprintf(stderr, "docproc: ");
|
|
|
|
perror(real_filename);
|
2006-09-29 17:00:56 +08:00
|
|
|
exit(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-09-05 12:23:22 +08:00
|
|
|
while (fgets(line, MAXLINESZ, fp)) {
|
2005-06-26 05:59:22 +08:00
|
|
|
char *p;
|
|
|
|
char *e;
|
2007-09-05 12:23:22 +08:00
|
|
|
if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != NULL) ||
|
2014-06-10 18:08:13 +08:00
|
|
|
((p = strstr(line, "EXPORT_SYMBOL")) != NULL)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Skip EXPORT_SYMBOL{_GPL} */
|
|
|
|
while (isalnum(*p) || *p == '_')
|
|
|
|
p++;
|
2007-09-05 12:23:22 +08:00
|
|
|
/* Remove parentheses & additional whitespace */
|
2005-04-17 06:20:36 +08:00
|
|
|
while (isspace(*p))
|
|
|
|
p++;
|
|
|
|
if (*p != '(')
|
|
|
|
continue; /* Syntax error? */
|
|
|
|
else
|
|
|
|
p++;
|
|
|
|
while (isspace(*p))
|
|
|
|
p++;
|
|
|
|
e = p;
|
|
|
|
while (isalnum(*e) || *e == '_')
|
|
|
|
e++;
|
|
|
|
*e = '\0';
|
|
|
|
add_new_symbol(sym, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Document all external or internal functions in a file.
|
|
|
|
* Call kernel-doc with following parameters:
|
2016-05-12 21:15:43 +08:00
|
|
|
* kernel-doc [-docbook|-rst] -nofunction function_name1 filename
|
2007-09-05 12:23:22 +08:00
|
|
|
* Function names are obtained from all the src files
|
2005-04-17 06:20:36 +08:00
|
|
|
* by find_export_symbols.
|
|
|
|
* intfunc uses -nofunction
|
|
|
|
* extfunc uses -function
|
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
static void docfunctions(char * filename, char * type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
int symcnt = 0;
|
|
|
|
int idx = 0;
|
|
|
|
char **vec;
|
|
|
|
|
|
|
|
for (i=0; i <= symfilecnt; i++)
|
|
|
|
symcnt += symfilelist[i].symbolcnt;
|
2007-10-25 06:08:48 +08:00
|
|
|
vec = malloc((2 + 2 * symcnt + 3) * sizeof(char *));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (vec == NULL) {
|
|
|
|
perror("docproc: ");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
vec[idx++] = KERNELDOC;
|
2016-05-12 21:15:43 +08:00
|
|
|
vec[idx++] = KERNELDOC_FORMAT;
|
2007-10-25 06:08:48 +08:00
|
|
|
vec[idx++] = NODOCSECTIONS;
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i=0; i < symfilecnt; i++) {
|
|
|
|
struct symfile * sym = &symfilelist[i];
|
|
|
|
for (j=0; j < sym->symbolcnt; j++) {
|
|
|
|
vec[idx++] = type;
|
2010-09-12 06:55:22 +08:00
|
|
|
consume_symbol(sym->symbollist[j].name);
|
2005-04-17 06:20:36 +08:00
|
|
|
vec[idx++] = sym->symbollist[j].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vec[idx++] = filename;
|
|
|
|
vec[idx] = NULL;
|
2016-05-12 21:15:43 +08:00
|
|
|
if (file_format == FORMAT_RST)
|
|
|
|
printf(".. %s\n", filename);
|
|
|
|
else
|
|
|
|
printf("<!-- %s -->\n", filename);
|
2005-04-17 06:20:36 +08:00
|
|
|
exec_kernel_doc(vec);
|
|
|
|
fflush(stdout);
|
|
|
|
free(vec);
|
|
|
|
}
|
2009-09-19 03:49:23 +08:00
|
|
|
static void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); }
|
|
|
|
static void extfunc(char * filename) { docfunctions(filename, FUNCTION); }
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2006-11-03 14:07:01 +08:00
|
|
|
* Document specific function(s) in a file.
|
2005-04-17 06:20:36 +08:00
|
|
|
* Call kernel-doc with the following parameters:
|
|
|
|
* kernel-doc -docbook -function function1 [-function function2]
|
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
static void singfunc(char * filename, char * line)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char *vec[200]; /* Enough for specific functions */
|
2014-06-10 18:08:13 +08:00
|
|
|
int i, idx = 0;
|
|
|
|
int startofsym = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
vec[idx++] = KERNELDOC;
|
2016-05-12 21:15:43 +08:00
|
|
|
vec[idx++] = KERNELDOC_FORMAT;
|
2013-11-13 07:11:12 +08:00
|
|
|
vec[idx++] = SHOWNOTFOUND;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-10 18:08:13 +08:00
|
|
|
/* Split line up in individual parameters preceded by FUNCTION */
|
|
|
|
for (i=0; line[i]; i++) {
|
|
|
|
if (isspace(line[i])) {
|
|
|
|
line[i] = '\0';
|
|
|
|
startofsym = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (startofsym) {
|
|
|
|
startofsym = 0;
|
|
|
|
vec[idx++] = FUNCTION;
|
|
|
|
vec[idx++] = &line[i];
|
|
|
|
}
|
|
|
|
}
|
2010-09-12 06:55:22 +08:00
|
|
|
for (i = 0; i < idx; i++) {
|
2014-06-10 18:08:13 +08:00
|
|
|
if (strcmp(vec[i], FUNCTION))
|
|
|
|
continue;
|
2010-09-12 06:55:22 +08:00
|
|
|
consume_symbol(vec[i + 1]);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
vec[idx++] = filename;
|
|
|
|
vec[idx] = NULL;
|
|
|
|
exec_kernel_doc(vec);
|
|
|
|
}
|
|
|
|
|
2007-10-25 06:08:48 +08:00
|
|
|
/*
|
|
|
|
* Insert specific documentation section from a file.
|
|
|
|
* Call kernel-doc with the following parameters:
|
|
|
|
* kernel-doc -docbook -function "doc section" filename
|
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
static void docsect(char *filename, char *line)
|
2007-10-25 06:08:48 +08:00
|
|
|
{
|
2013-11-13 07:11:12 +08:00
|
|
|
/* kerneldoc -docbook -show-not-found -function "section" file NULL */
|
|
|
|
char *vec[7];
|
2007-10-25 06:08:48 +08:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
for (s = line; *s; s++)
|
|
|
|
if (*s == '\n')
|
|
|
|
*s = '\0';
|
|
|
|
|
2010-10-22 22:32:10 +08:00
|
|
|
if (asprintf(&s, "DOC: %s", line) < 0) {
|
|
|
|
perror("asprintf");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-09-12 06:55:22 +08:00
|
|
|
consume_symbol(s);
|
|
|
|
free(s);
|
|
|
|
|
2007-10-25 06:08:48 +08:00
|
|
|
vec[0] = KERNELDOC;
|
2016-05-12 21:15:43 +08:00
|
|
|
vec[1] = KERNELDOC_FORMAT;
|
2013-11-13 07:11:12 +08:00
|
|
|
vec[2] = SHOWNOTFOUND;
|
|
|
|
vec[3] = FUNCTION;
|
|
|
|
vec[4] = line;
|
|
|
|
vec[5] = filename;
|
|
|
|
vec[6] = NULL;
|
2007-10-25 06:08:48 +08:00
|
|
|
exec_kernel_doc(vec);
|
|
|
|
}
|
|
|
|
|
2010-09-12 06:55:22 +08:00
|
|
|
static void find_all_symbols(char *filename)
|
|
|
|
{
|
|
|
|
char *vec[4]; /* kerneldoc -list file NULL */
|
|
|
|
pid_t pid;
|
|
|
|
int ret, i, count, start;
|
|
|
|
char real_filename[PATH_MAX + 1];
|
|
|
|
int pipefd[2];
|
|
|
|
char *data, *str;
|
|
|
|
size_t data_len = 0;
|
|
|
|
|
|
|
|
vec[0] = KERNELDOC;
|
|
|
|
vec[1] = LIST;
|
|
|
|
vec[2] = filename;
|
|
|
|
vec[3] = NULL;
|
|
|
|
|
|
|
|
if (pipe(pipefd)) {
|
|
|
|
perror("pipe");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pid=fork()) {
|
|
|
|
case -1:
|
|
|
|
perror("fork");
|
|
|
|
exit(1);
|
|
|
|
case 0:
|
|
|
|
close(pipefd[0]);
|
|
|
|
dup2(pipefd[1], 1);
|
|
|
|
memset(real_filename, 0, sizeof(real_filename));
|
|
|
|
strncat(real_filename, kernsrctree, PATH_MAX);
|
|
|
|
strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
|
|
|
|
PATH_MAX - strlen(real_filename));
|
|
|
|
execvp(real_filename, vec);
|
|
|
|
fprintf(stderr, "exec ");
|
|
|
|
perror(real_filename);
|
|
|
|
exit(1);
|
|
|
|
default:
|
|
|
|
close(pipefd[1]);
|
|
|
|
data = malloc(4096);
|
|
|
|
do {
|
|
|
|
while ((ret = read(pipefd[0],
|
|
|
|
data + data_len,
|
|
|
|
4096)) > 0) {
|
|
|
|
data_len += ret;
|
|
|
|
data = realloc(data, data_len + 4096);
|
|
|
|
}
|
|
|
|
} while (ret == -EAGAIN);
|
|
|
|
if (ret != 0) {
|
|
|
|
perror("read");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
waitpid(pid, &ret ,0);
|
|
|
|
}
|
|
|
|
if (WIFEXITED(ret))
|
|
|
|
exitstatus |= WEXITSTATUS(ret);
|
|
|
|
else
|
|
|
|
exitstatus = 0xff;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
/* poor man's strtok, but with counting */
|
|
|
|
for (i = 0; i < data_len; i++) {
|
|
|
|
if (data[i] == '\n') {
|
|
|
|
count++;
|
|
|
|
data[i] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
start = all_list_len;
|
|
|
|
all_list_len += count;
|
|
|
|
all_list = realloc(all_list, sizeof(char *) * all_list_len);
|
|
|
|
str = data;
|
|
|
|
for (i = 0; i < data_len && start != all_list_len; i++) {
|
|
|
|
if (data[i] == '\0') {
|
|
|
|
all_list[start] = str;
|
|
|
|
str = data + i + 1;
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:15:42 +08:00
|
|
|
/*
|
|
|
|
* Terminate s at first space, if any. If there was a space, return pointer to
|
|
|
|
* the character after that. Otherwise, return pointer to the terminating NUL.
|
|
|
|
*/
|
|
|
|
static char *chomp(char *s)
|
|
|
|
{
|
|
|
|
while (*s && !isspace(*s))
|
|
|
|
s++;
|
|
|
|
|
|
|
|
if (*s)
|
|
|
|
*s++ = '\0';
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:15:41 +08:00
|
|
|
/* Return pointer to directive content, or NULL if not a directive. */
|
|
|
|
static char *is_directive(char *line)
|
|
|
|
{
|
2016-05-12 21:15:43 +08:00
|
|
|
if (file_format == FORMAT_DOCBOOK && line[0] == '!')
|
2016-05-12 21:15:41 +08:00
|
|
|
return line + 1;
|
2016-05-12 21:15:43 +08:00
|
|
|
else if (file_format == FORMAT_RST && !strncmp(line, ".. !", 4))
|
|
|
|
return line + 4;
|
2016-05-12 21:15:41 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Parse file, calling action specific functions for:
|
|
|
|
* 1) Lines containing !E
|
|
|
|
* 2) Lines containing !I
|
|
|
|
* 3) Lines containing !D
|
|
|
|
* 4) Lines containing !F
|
2007-10-25 06:08:48 +08:00
|
|
|
* 5) Lines containing !P
|
2010-09-12 06:55:22 +08:00
|
|
|
* 6) Lines containing !C
|
|
|
|
* 7) Default lines - lines not matching the above
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-09-19 03:49:23 +08:00
|
|
|
static void parse_file(FILE *infile)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char line[MAXLINESZ];
|
2016-05-12 21:15:41 +08:00
|
|
|
char *p, *s;
|
2007-09-05 12:23:22 +08:00
|
|
|
while (fgets(line, MAXLINESZ, infile)) {
|
2016-05-12 21:15:41 +08:00
|
|
|
p = is_directive(line);
|
|
|
|
if (!p) {
|
2016-05-12 21:15:40 +08:00
|
|
|
defaultline(line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:15:41 +08:00
|
|
|
switch (*p++) {
|
2016-05-12 21:15:40 +08:00
|
|
|
case 'E':
|
2016-05-12 21:15:42 +08:00
|
|
|
chomp(p);
|
2016-05-12 21:15:41 +08:00
|
|
|
externalfunctions(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
break;
|
|
|
|
case 'I':
|
2016-05-12 21:15:42 +08:00
|
|
|
chomp(p);
|
2016-05-12 21:15:41 +08:00
|
|
|
internalfunctions(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
break;
|
|
|
|
case 'D':
|
2016-05-12 21:15:42 +08:00
|
|
|
chomp(p);
|
2016-05-12 21:15:41 +08:00
|
|
|
symbolsonly(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
/* filename */
|
2016-05-12 21:15:42 +08:00
|
|
|
s = chomp(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
/* function names */
|
|
|
|
while (isspace(*s))
|
|
|
|
s++;
|
2016-05-12 21:15:41 +08:00
|
|
|
singlefunctions(p, s);
|
2016-05-12 21:15:40 +08:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
/* filename */
|
2016-05-12 21:15:42 +08:00
|
|
|
s = chomp(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
/* DOC: section name */
|
|
|
|
while (isspace(*s))
|
|
|
|
s++;
|
2016-05-12 21:15:41 +08:00
|
|
|
docsection(p, s);
|
2016-05-12 21:15:40 +08:00
|
|
|
break;
|
|
|
|
case 'C':
|
2016-05-12 21:15:42 +08:00
|
|
|
chomp(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
if (findall)
|
2016-05-12 21:15:41 +08:00
|
|
|
findall(p);
|
2016-05-12 21:15:40 +08:00
|
|
|
break;
|
|
|
|
default:
|
2005-04-17 06:20:36 +08:00
|
|
|
defaultline(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2016-05-12 21:15:43 +08:00
|
|
|
/*
|
|
|
|
* Is this a RestructuredText template? Answer the question by seeing if its
|
|
|
|
* name ends in ".rst".
|
|
|
|
*/
|
|
|
|
static int is_rst(const char *file)
|
|
|
|
{
|
|
|
|
char *dot = strrchr(file, '.');
|
|
|
|
|
|
|
|
return dot && !strcmp(dot + 1, "rst");
|
|
|
|
}
|
|
|
|
|
|
|
|
enum opts {
|
|
|
|
OPT_DOCBOOK,
|
|
|
|
OPT_RST,
|
|
|
|
OPT_HELP,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-05-12 21:15:39 +08:00
|
|
|
const char *subcommand, *filename;
|
2005-04-17 06:20:36 +08:00
|
|
|
FILE * infile;
|
2010-09-12 06:55:22 +08:00
|
|
|
int i;
|
2007-10-09 14:25:18 +08:00
|
|
|
|
|
|
|
srctree = getenv("SRCTREE");
|
|
|
|
if (!srctree)
|
|
|
|
srctree = getcwd(NULL, 0);
|
2009-06-01 00:05:34 +08:00
|
|
|
kernsrctree = getenv("KBUILD_SRC");
|
2009-06-19 15:06:54 +08:00
|
|
|
if (!kernsrctree || !*kernsrctree)
|
2009-06-01 00:05:34 +08:00
|
|
|
kernsrctree = srctree;
|
2016-05-12 21:15:43 +08:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c;
|
|
|
|
struct option opts[] = {
|
|
|
|
{ "docbook", no_argument, NULL, OPT_DOCBOOK },
|
|
|
|
{ "rst", no_argument, NULL, OPT_RST },
|
|
|
|
{ "help", no_argument, NULL, OPT_HELP },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
c = getopt_long_only(argc, argv, "", opts, NULL);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case OPT_DOCBOOK:
|
|
|
|
file_format = FORMAT_DOCBOOK;
|
|
|
|
break;
|
|
|
|
case OPT_RST:
|
|
|
|
file_format = FORMAT_RST;
|
|
|
|
break;
|
|
|
|
case OPT_HELP:
|
|
|
|
usage();
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
2005-04-17 06:20:36 +08:00
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-05-12 21:15:39 +08:00
|
|
|
|
2016-05-12 21:15:43 +08:00
|
|
|
subcommand = argv[0];
|
|
|
|
filename = argv[1];
|
|
|
|
|
|
|
|
if (file_format == FORMAT_AUTO)
|
|
|
|
file_format = is_rst(filename) ? FORMAT_RST : FORMAT_DOCBOOK;
|
2016-05-12 21:15:39 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Open file, exit on error */
|
2016-05-12 21:15:39 +08:00
|
|
|
infile = fopen(filename, "r");
|
2014-06-10 18:08:13 +08:00
|
|
|
if (infile == NULL) {
|
|
|
|
fprintf(stderr, "docproc: ");
|
2016-05-12 21:15:39 +08:00
|
|
|
perror(filename);
|
2014-06-10 18:08:13 +08:00
|
|
|
exit(2);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-05-12 21:15:39 +08:00
|
|
|
if (strcmp("doc", subcommand) == 0) {
|
2016-05-12 21:15:44 +08:00
|
|
|
if (file_format == FORMAT_RST) {
|
|
|
|
time_t t = time(NULL);
|
|
|
|
printf(".. generated from %s by docproc %s\n",
|
|
|
|
filename, ctime(&t));
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Need to do this in two passes.
|
|
|
|
* First pass is used to collect all symbols exported
|
2007-09-05 12:23:22 +08:00
|
|
|
* in the various files;
|
2005-04-17 06:20:36 +08:00
|
|
|
* Second pass generate the documentation.
|
2007-09-05 12:23:22 +08:00
|
|
|
* This is required because some functions are declared
|
2005-04-17 06:20:36 +08:00
|
|
|
* and exported in different files :-((
|
|
|
|
*/
|
|
|
|
/* Collect symbols */
|
|
|
|
defaultline = noaction;
|
|
|
|
internalfunctions = find_export_symbols;
|
|
|
|
externalfunctions = find_export_symbols;
|
|
|
|
symbolsonly = find_export_symbols;
|
|
|
|
singlefunctions = noaction2;
|
2007-10-25 06:08:48 +08:00
|
|
|
docsection = noaction2;
|
2010-09-12 06:55:22 +08:00
|
|
|
findall = find_all_symbols;
|
2005-04-17 06:20:36 +08:00
|
|
|
parse_file(infile);
|
|
|
|
|
|
|
|
/* Rewind to start from beginning of file again */
|
|
|
|
fseek(infile, 0, SEEK_SET);
|
|
|
|
defaultline = printline;
|
|
|
|
internalfunctions = intfunc;
|
|
|
|
externalfunctions = extfunc;
|
|
|
|
symbolsonly = printline;
|
|
|
|
singlefunctions = singfunc;
|
2007-10-25 06:08:48 +08:00
|
|
|
docsection = docsect;
|
2010-09-12 06:55:22 +08:00
|
|
|
findall = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
parse_file(infile);
|
2010-09-12 06:55:22 +08:00
|
|
|
|
|
|
|
for (i = 0; i < all_list_len; i++) {
|
|
|
|
if (!all_list[i])
|
|
|
|
continue;
|
|
|
|
fprintf(stderr, "Warning: didn't use docs for %s\n",
|
|
|
|
all_list[i]);
|
|
|
|
}
|
2016-05-12 21:15:39 +08:00
|
|
|
} else if (strcmp("depend", subcommand) == 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Create first part of dependency chain
|
|
|
|
* file.tmpl */
|
2016-05-12 21:15:39 +08:00
|
|
|
printf("%s\t", filename);
|
2005-04-17 06:20:36 +08:00
|
|
|
defaultline = noaction;
|
|
|
|
internalfunctions = adddep;
|
|
|
|
externalfunctions = adddep;
|
|
|
|
symbolsonly = adddep;
|
|
|
|
singlefunctions = adddep2;
|
2007-10-25 06:08:48 +08:00
|
|
|
docsection = adddep2;
|
2010-09-12 06:55:22 +08:00
|
|
|
findall = adddep;
|
2005-04-17 06:20:36 +08:00
|
|
|
parse_file(infile);
|
|
|
|
printf("\n");
|
2011-06-15 17:53:13 +08:00
|
|
|
} else {
|
2016-05-12 21:15:39 +08:00
|
|
|
fprintf(stderr, "Unknown option: %s\n", subcommand);
|
2005-04-17 06:20:36 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fclose(infile);
|
|
|
|
fflush(stdout);
|
|
|
|
return exitstatus;
|
|
|
|
}
|