45 #include <sys/types.h>
52 typedef void DFL(
char *);
66 #define MAXLINESZ 2048
68 #define KERNELDOCPATH "scripts/"
69 #define KERNELDOC "kernel-doc"
70 #define DOCBOOK "-docbook"
72 #define FUNCTION "-function"
73 #define NOFUNCTION "-nofunction"
74 #define NODOCSECTIONS "-no-doc-sections"
76 static char *srctree, *kernsrctree;
78 static char **all_list =
NULL;
79 static int all_list_len = 0;
81 static void consume_symbol(
const char *sym)
85 for (i = 0; i < all_list_len; i++) {
88 if (
strcmp(sym, all_list[i]))
95 static void usage (
void)
97 fprintf(stderr,
"Usage: docproc {doc|depend} file\n");
98 fprintf(stderr,
"Input is read from file.tmpl. Output is sent to stdout\n");
99 fprintf(stderr,
"doc: frontend when generating kernel documentation\n");
100 fprintf(stderr,
"depend: generate list of files referenced within file\n");
101 fprintf(stderr,
"Environment variable SRCTREE: absolute path to sources.\n");
102 fprintf(stderr,
" KBUILD_SRC: absolute path to kernel source tree.\n");
108 static void exec_kernel_doc(
char **svec)
115 switch (pid=fork()) {
120 memset(real_filename, 0,
sizeof(real_filename));
124 execvp(real_filename, svec);
126 perror(real_filename);
129 waitpid(pid, &ret ,0);
153 static void add_new_symbol(
struct symfile *sym,
char * symname)
163 symfilelist[symfilecnt++].filename = strdup(filename);
181 static void adddep(
char *
file) {
printf(
"\t%s", file); }
182 static void adddep2(
char *
file,
char *
line) { line = line; adddep(file); }
183 static void noaction(
char *
line) { line = line; }
184 static void noaction2(
char *
file,
char *
line) { file =
file; line = line; }
187 static void printline(
char *
line) {
printf(
"%s", line); }
194 static void find_export_symbols(
char * filename)
199 if (filename_exist(filename) ==
NULL) {
201 memset(real_filename, 0,
sizeof(real_filename));
204 strncat(real_filename, filename,
206 sym = add_new_file(filename);
207 fp = fopen(real_filename,
"r");
210 perror(real_filename);
216 if (((p =
strstr(line,
"EXPORT_SYMBOL_GPL")) !=
NULL) ||
217 ((p =
strstr(line,
"EXPORT_SYMBOL")) !=
NULL)) {
219 while (
isalnum(*p) || *p ==
'_')
231 while (
isalnum(*e) || *e ==
'_')
234 add_new_symbol(sym, p);
250 static void docfunctions(
char * filename,
char *
type)
259 vec =
malloc((2 + 2 * symcnt + 3) *
sizeof(
char *));
277 printf(
"<!-- %s -->\n", filename);
278 exec_kernel_doc(vec);
282 static void intfunc(
char * filename) { docfunctions(filename,
NOFUNCTION); }
283 static void extfunc(
char * filename) { docfunctions(filename,
FUNCTION); }
290 static void singfunc(
char * filename,
char * line)
299 for (i=0; line[
i]; i++) {
308 vec[idx++] = &line[
i];
311 for (i = 0; i <
idx; i++) {
314 consume_symbol(vec[i + 1]);
318 exec_kernel_doc(vec);
326 static void docsect(
char *filename,
char *line)
331 for (s = line; *
s; s++)
335 if (asprintf(&s,
"DOC: %s", line) < 0) {
348 exec_kernel_doc(vec);
351 static void find_all_symbols(
char *filename)
371 switch (pid=fork()) {
378 memset(real_filename, 0,
sizeof(real_filename));
382 execvp(real_filename, vec);
384 perror(real_filename);
390 while ((ret =
read(pipefd[0],
394 data = realloc(data, data_len + 4096);
401 waitpid(pid, &ret ,0);
411 if (data[i] ==
'\n') {
416 start = all_list_len;
417 all_list_len +=
count;
418 all_list = realloc(all_list,
sizeof(
char *) * all_list_len);
420 for (i = 0; i < data_len && start != all_list_len; i++) {
421 if (data[i] ==
'\0') {
439 static void parse_file(FILE *infile)
444 if (line[0] ==
'!') {
448 while (*s && !
isspace(*s)) s++;
453 while (*s && !
isspace(*s)) s++;
458 while (*s && !
isspace(*s)) s++;
464 while (*s && !
isspace(*s)) s++;
473 while (*s && !
isspace(*s)) s++;
481 while (*s && !
isspace(*s)) s++;
502 srctree = getenv(
"SRCTREE");
504 srctree = getcwd(
NULL, 0);
505 kernsrctree = getenv(
"KBUILD_SRC");
506 if (!kernsrctree || !*kernsrctree)
507 kernsrctree = srctree;
513 infile = fopen(argv[2],
"r");
514 if (infile ==
NULL) {
520 if (
strcmp(
"doc", argv[1]) == 0) {
550 for (i = 0; i < all_list_len; i++) {
553 fprintf(stderr,
"Warning: didn't use docs for %s\n",
556 }
else if (
strcmp(
"depend", argv[1]) == 0) {
570 fprintf(stderr,
"Unknown option: %s\n", argv[1]);