Commit d7e46839 authored by Sam Ravnborg's avatar Sam Ravnborg Committed by Linus Torvalds

[PATCH] docbook: scripts/docproc improved [5/9]

This is the first patch in a serie to clean-up the DocBook
Makefile.

docproc is extented to include the functionality previously provided by
gen-all-syms and docgen.  Furthermore the necessity to specify which
files to search for EXPORT_SYMBOL are removed, the information is now
read in the .tmpl files.

docproc is furthermore extended to generate dependency information.
gen-all-syms and docgen are deleted.
parent fa3faf80
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# can't do it # can't do it
CHMOD_FILES := docgen gen-all-syms kernel-doc mkcompile_h makelst CHMOD_FILES := docgen gen-all-syms kernel-doc mkcompile_h makelst
all: fixdep split-include $(CHMOD_FILES) all: fixdep split-include docproc $(CHMOD_FILES)
$(CHMOD_FILES): FORCE $(CHMOD_FILES): FORCE
@chmod a+x $@ @chmod a+x $@
...@@ -37,11 +37,6 @@ kconfig.tk: $(TOPDIR)/arch/$(ARCH)/config.in tkparse $(HEADER) $(TAIL) FORCE ...@@ -37,11 +37,6 @@ kconfig.tk: $(TOPDIR)/arch/$(ARCH)/config.in tkparse $(HEADER) $(TAIL) FORCE
) > $@ ) > $@
chmod 755 $@ chmod 755 $@
# DocBook stuff
# ---------------------------------------------------------------------------
doc-progs: docproc
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
.PHONY: lxdialog .PHONY: lxdialog
......
#!/bin/sh
set -e
if [ -z "$scripts_objtree" ]
then
X=`$TOPDIR/scripts/gen-all-syms "$*"`
$TOPDIR/scripts/docproc $X
else
X=`${scripts_objtree}gen-all-syms "$*"`
TOPDIR=. ${scripts_objtree}docproc $X
fi
/*
* 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
* Beforehand each referenced file are scanned for
* any exported sympols "EXPORT_SYMBOL()" statements.
* 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
*
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
/* 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;
typedef void FILELINE(char * file, char * line);
FILELINE * singlefunctions;
FILELINE * entity_system;
#define MAXLINESZ 2048
#define MAXFILES 250
#define KERNELDOCPATH "scripts/"
#define KERNELDOC "kernel-doc"
#define DOCBOOK "-docbook"
#define FUNCTION "-function"
#define NOFUNCTION "-nofunction"
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");
}
/* /*
* A simple filter for the templates * Execute kernel-doc with parameters givin in svec
*/ */
void exec_kernel_doc(char **svec)
{
pid_t pid;
int ret;
/* Make sure output generated so far are flushed */
fflush(stdout);
switch(pid=fork()) {
case -1:
perror("fork");
exit(1);
case 0:
execvp(KERNELDOCPATH KERNELDOC, svec);
perror("exec " KERNELDOCPATH KERNELDOC);
exit(1);
default:
waitpid(pid, &ret ,0);
}
if (WIFEXITED(ret))
exitstatus = WEXITSTATUS(ret);
else
exitstatus = 0xff;
}
int main(int argc, char *argv[]) /* 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;
void add_new_symbol(struct symfile *sym, char * symname)
{
sym->symbollist =
realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *));
sym->symbollist[sym->symbolcnt++].name = strdup(symname);
}
/* Add a filename to the list */
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)
{ {
char buf[1024];
char *vec[8192];
char *fvec[200];
char **svec;
char type[64];
int i; int i;
int vp=2; for (i=0; i < symfilecnt; i++)
int ret=0; if (strcmp(symfilelist[i].filename, filename) == 0)
pid_t pid; return &symfilelist[i];
return NULL;
}
/*
* 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; }
/* Echo the line without further action */
void printline(char * line) { printf("%s", line); }
if(chdir(getenv("TOPDIR"))) /*
* Find all symbols exported with EXPORT_SYMBOL and EXPORT_SYMBOL_GPL
* in filename.
* All symbols located are stored in symfilelist.
*/
void find_export_symbols(char * filename)
{
FILE * fp;
struct symfile *sym;
char line[MAXLINESZ];
if (filename_exist(filename) == NULL) {
sym = add_new_file(filename);
fp = fopen(filename, "r");
if (fp == NULL)
{ {
perror("chdir"); fprintf(stderr, "docproc: ");
exit(1); perror(filename);
} }
while(fgets(line, MAXLINESZ, fp)) {
char *p;
char *e;
if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != 0) ||
((p = strstr(line, "EXPORT_SYMBOL")) != 0)) {
/* Skip EXPORT_SYMBOL{_GPL} */
while (isalnum(*p) || *p == '_')
p++;
/* Remove paranteses and additional ws */
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);
}
}
/* /*
* Build the exec array ahead of time. * Document all external or internal functions in a file.
* Call kernel-doc with following parameters:
* kernel-doc -docbook -nofunction function_name1 filename
* function names are obtained from all the the src files
* by find_export_symbols.
* intfunc uses -nofunction
* extfunc uses -function
*/ */
vec[0]="kernel-doc"; void docfunctions(char * filename, char * type)
vec[1]="-docbook"; {
for(i=1;vp<8189;i++) int i,j;
{ int symcnt = 0;
if(argv[i]==NULL) int idx = 0;
break; char **vec;
vec[vp++]=type;
vec[vp++]=argv[i]; for (i=0; i <= symfilecnt; i++)
symcnt += symfilelist[i].symbolcnt;
vec = malloc((2 + 2 * symcnt + 2) * sizeof(char*));
if (vec == NULL) {
perror("docproc: ");
exit(1);
} }
vec[vp++]=buf+2; vec[idx++] = KERNELDOC;
vec[vp++]=NULL; vec[idx++] = DOCBOOK;
for (i=0; i < symfilecnt; i++) {
struct symfile * sym = &symfilelist[i];
for (j=0; j < sym->symbolcnt; j++) {
vec[idx++] = type;
vec[idx++] = sym->symbollist[j].name;
}
}
vec[idx++] = filename;
vec[idx] = NULL;
printf("<!-- %s -->\n", filename);
exec_kernel_doc(vec);
fflush(stdout);
free(vec);
}
void intfunc(char * filename) { docfunctions(filename, NOFUNCTION); }
void extfunc(char * filename) { docfunctions(filename, FUNCTION); }
/* /*
* Now process the template * 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)
{
char *vec[200]; /* Enough for specific functions */
int i, idx = 0;
int startofsym = 1;
vec[idx++] = KERNELDOC;
vec[idx++] = DOCBOOK;
while(fgets(buf, 1024, stdin)) /* Split line up in individual parameters preceeded by FUNCTION */
{ for (i=0; line[i]; i++) {
if(*buf!='!') { if (isspace(line[i])) {
printf("%s", buf); line[i] = '\0';
startofsym = 1;
continue; continue;
} }
if (startofsym) {
startofsym = 0;
vec[idx++] = FUNCTION;
vec[idx++] = &line[i];
}
}
vec[idx++] = filename;
vec[idx] = NULL;
exec_kernel_doc(vec);
}
fflush(stdout); /*
svec = vec; * Parse file, calling action specific functions for:
if(buf[1]=='E') * 1) Lines containing !E
strcpy(type, "-function"); * 2) Lines containing !I
else if(buf[1]=='I') * 3) Lines containing !D
strcpy(type, "-nofunction"); * 4) Lines containing !F
else if(buf[1]=='F') { * 5) Default lines - lines not matching the above
int snarf = 0; */
fvec[0] = "kernel-doc"; void parse_file(FILE *infile)
fvec[1] = "-docbook"; {
strcpy (type, "-function"); char line[MAXLINESZ];
vp = 2; char * s;
for (i = 2; buf[i]; i++) { while(fgets(line, MAXLINESZ, infile)) {
if (buf[i] == ' ' || buf[i] == '\n') { if (line[0] == '!') {
buf[i] = '\0'; s = line + 2;
snarf = 1; switch (line[1]) {
continue; case 'E':
while (*s && !isspace(*s)) s++;
*s = '\0';
externalfunctions(line+2);
break;
case 'I':
while (*s && !isspace(*s)) s++;
*s = '\0';
internalfunctions(line+2);
break;
case 'D':
while (*s && !isspace(*s)) s++;
*s = '\0';
symbolsonly(line+2);
break;
case 'F':
/* filename */
while (*s && !isspace(*s)) s++;
*s++ = '\0';
/* function names */
while (isspace(*s))
s++;
singlefunctions(line +2, s);
break;
default:
defaultline(line);
}
} }
else {
defaultline(line);
}
}
fflush(stdout);
}
if (snarf) { int main(int argc, char *argv[])
snarf = 0; {
fvec[vp++] = type; FILE * infile;
fvec[vp++] = &buf[i]; if (argc != 3) {
usage();
exit(1);
} }
/* Open file, exit on error */
infile = fopen(argv[2], "r");
if (infile == NULL) {
fprintf(stderr, "docproc: ");
perror(argv[2]);
exit(2);
} }
fvec[vp++] = &buf[2];
fvec[vp] = NULL; if (strcmp("doc", argv[1]) == 0)
svec = fvec;
} else
{ {
fprintf(stderr, "Unknown ! escape.\n"); /* Need to do this in two passes.
exit(1); * First pass is used to collect all symbols exported
* in the various files.
* Second pass generate the documentation.
* This is required because function are declared
* and exported in different files :-((
*/
/* Collect symbols */
defaultline = noaction;
internalfunctions = find_export_symbols;
externalfunctions = find_export_symbols;
symbolsonly = find_export_symbols;
singlefunctions = noaction2;
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;
parse_file(infile);
} }
switch(pid=fork()) else if (strcmp("depend", argv[1]) == 0)
{ {
case -1: /* Create first part of dependency chain
perror("fork"); * file.tmpl */
exit(1); printf("%s\t", argv[2]);
case 0: defaultline = noaction;
execvp("scripts/kernel-doc", svec); internalfunctions = adddep;
perror("exec scripts/kernel-doc"); externalfunctions = adddep;
exit(1); symbolsonly = adddep;
default: singlefunctions = adddep2;
waitpid(pid, &ret ,0); parse_file(infile);
printf("\n");
} }
else
{
fprintf(stderr, "Unknown option: %s\n", argv[1]);
exit(1);
} }
exit(ret); fclose(infile);
fflush(stdout);
return exitstatus;
} }
#!/bin/sh
for i in $*
do
grep "EXPORT_SYMBOL.*(.*)" "$i" \
| sed -e "s/EXPORT_SYMBOL.*(/ /" \
| sed -e "s/).*$//" | sed -e "s/^ //"
done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment