| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *	docproc is a simple preprocessor for the template files | 
|  | 3 | *      used as placeholders for the kernel internal documentation. | 
|  | 4 | *	docproc is used for documentation-frontend and | 
|  | 5 | *      dependency-generator. | 
|  | 6 | *	The two usages have in common that they require | 
|  | 7 | *	some knowledge of the .tmpl syntax, therefore they | 
|  | 8 | *	are kept together. | 
|  | 9 | * | 
|  | 10 | *	documentation-frontend | 
|  | 11 | *		Scans the template file and call kernel-doc for | 
|  | 12 | *		all occurrences of ![EIF]file | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 13 | *		Beforehand each referenced file is scanned for | 
|  | 14 | *		any symbols that are exported via these macros: | 
|  | 15 | *			EXPORT_SYMBOL(), EXPORT_SYMBOL_GPL(), & | 
|  | 16 | *			EXPORT_SYMBOL_GPL_FUTURE() | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | *		This is used to create proper -function and | 
|  | 18 | *		-nofunction arguments in calls to kernel-doc. | 
|  | 19 | *		Usage: docproc doc file.tmpl | 
|  | 20 | * | 
|  | 21 | *	dependency-generator: | 
|  | 22 | *		Scans the template file and list all files | 
|  | 23 | *		referenced in a format recognized by make. | 
|  | 24 | *		Usage:	docproc depend file.tmpl | 
|  | 25 | *		Writes dependency information to stdout | 
|  | 26 | *		in the following format: | 
|  | 27 | *		file.tmpl src.c	src2.c | 
|  | 28 | *		The filenames are obtained from the following constructs: | 
|  | 29 | *		!Efilename | 
|  | 30 | *		!Ifilename | 
|  | 31 | *		!Dfilename | 
|  | 32 | *		!Ffilename | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 33 | *		!Pfilename | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * | 
|  | 35 | */ | 
|  | 36 |  | 
|  | 37 | #include <stdio.h> | 
|  | 38 | #include <stdlib.h> | 
|  | 39 | #include <string.h> | 
|  | 40 | #include <ctype.h> | 
|  | 41 | #include <unistd.h> | 
|  | 42 | #include <limits.h> | 
|  | 43 | #include <sys/types.h> | 
|  | 44 | #include <sys/wait.h> | 
|  | 45 |  | 
|  | 46 | /* exitstatus is used to keep track of any failing calls to kernel-doc, | 
|  | 47 | * but execution continues. */ | 
|  | 48 | int exitstatus = 0; | 
|  | 49 |  | 
|  | 50 | typedef void DFL(char *); | 
|  | 51 | DFL *defaultline; | 
|  | 52 |  | 
|  | 53 | typedef void FILEONLY(char * file); | 
|  | 54 | FILEONLY *internalfunctions; | 
|  | 55 | FILEONLY *externalfunctions; | 
|  | 56 | FILEONLY *symbolsonly; | 
|  | 57 |  | 
| J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 58 | typedef void FILELINE(char * file, char * line); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | FILELINE * singlefunctions; | 
|  | 60 | FILELINE * entity_system; | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 61 | FILELINE * docsection; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 |  | 
|  | 63 | #define MAXLINESZ     2048 | 
|  | 64 | #define MAXFILES      250 | 
|  | 65 | #define KERNELDOCPATH "scripts/" | 
|  | 66 | #define KERNELDOC     "kernel-doc" | 
|  | 67 | #define DOCBOOK       "-docbook" | 
|  | 68 | #define FUNCTION      "-function" | 
|  | 69 | #define NOFUNCTION    "-nofunction" | 
| Johannes Berg | 2e95972 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 70 | #define NODOCSECTIONS "-no-doc-sections" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 |  | 
| Jiri Slaby | 2d51005 | 2009-05-31 18:05:34 +0200 | [diff] [blame] | 72 | static char *srctree, *kernsrctree; | 
| Rob Landley | bb13be5 | 2007-10-09 01:25:18 -0500 | [diff] [blame] | 73 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | void usage (void) | 
|  | 75 | { | 
|  | 76 | fprintf(stderr, "Usage: docproc {doc|depend} file\n"); | 
|  | 77 | fprintf(stderr, "Input is read from file.tmpl. Output is sent to stdout\n"); | 
|  | 78 | fprintf(stderr, "doc: frontend when generating kernel documentation\n"); | 
|  | 79 | fprintf(stderr, "depend: generate list of files referenced within file\n"); | 
| Jiri Slaby | 2d51005 | 2009-05-31 18:05:34 +0200 | [diff] [blame] | 80 | fprintf(stderr, "Environment variable SRCTREE: absolute path to sources.\n"); | 
|  | 81 | fprintf(stderr, "                     KBUILD_SRC: absolute path to kernel source tree.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } | 
|  | 83 |  | 
|  | 84 | /* | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 85 | * Execute kernel-doc with parameters given in svec | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ | 
|  | 87 | void exec_kernel_doc(char **svec) | 
|  | 88 | { | 
|  | 89 | pid_t pid; | 
|  | 90 | int ret; | 
|  | 91 | char real_filename[PATH_MAX + 1]; | 
|  | 92 | /* Make sure output generated so far are flushed */ | 
|  | 93 | fflush(stdout); | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 94 | switch (pid=fork()) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | case -1: | 
|  | 96 | perror("fork"); | 
|  | 97 | exit(1); | 
|  | 98 | case  0: | 
|  | 99 | memset(real_filename, 0, sizeof(real_filename)); | 
| Jiri Slaby | 2d51005 | 2009-05-31 18:05:34 +0200 | [diff] [blame] | 100 | strncat(real_filename, kernsrctree, PATH_MAX); | 
|  | 101 | strncat(real_filename, "/" KERNELDOCPATH KERNELDOC, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | PATH_MAX - strlen(real_filename)); | 
|  | 103 | execvp(real_filename, svec); | 
|  | 104 | fprintf(stderr, "exec "); | 
|  | 105 | perror(real_filename); | 
|  | 106 | exit(1); | 
|  | 107 | default: | 
|  | 108 | waitpid(pid, &ret ,0); | 
|  | 109 | } | 
|  | 110 | if (WIFEXITED(ret)) | 
|  | 111 | exitstatus |= WEXITSTATUS(ret); | 
|  | 112 | else | 
|  | 113 | exitstatus = 0xff; | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | /* Types used to create list of all exported symbols in a number of files */ | 
|  | 117 | struct symbols | 
|  | 118 | { | 
|  | 119 | char *name; | 
|  | 120 | }; | 
|  | 121 |  | 
|  | 122 | struct symfile | 
|  | 123 | { | 
|  | 124 | char *filename; | 
|  | 125 | struct symbols *symbollist; | 
|  | 126 | int symbolcnt; | 
|  | 127 | }; | 
|  | 128 |  | 
|  | 129 | struct symfile symfilelist[MAXFILES]; | 
|  | 130 | int symfilecnt = 0; | 
|  | 131 |  | 
|  | 132 | void add_new_symbol(struct symfile *sym, char * symname) | 
|  | 133 | { | 
|  | 134 | sym->symbollist = | 
|  | 135 | realloc(sym->symbollist, (sym->symbolcnt + 1) * sizeof(char *)); | 
|  | 136 | sym->symbollist[sym->symbolcnt++].name = strdup(symname); | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | /* Add a filename to the list */ | 
|  | 140 | struct symfile * add_new_file(char * filename) | 
|  | 141 | { | 
|  | 142 | symfilelist[symfilecnt++].filename = strdup(filename); | 
|  | 143 | return &symfilelist[symfilecnt - 1]; | 
|  | 144 | } | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 145 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* Check if file already are present in the list */ | 
|  | 147 | struct symfile * filename_exist(char * filename) | 
|  | 148 | { | 
|  | 149 | int i; | 
|  | 150 | for (i=0; i < symfilecnt; i++) | 
|  | 151 | if (strcmp(symfilelist[i].filename, filename) == 0) | 
|  | 152 | return &symfilelist[i]; | 
|  | 153 | return NULL; | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | /* | 
|  | 157 | * List all files referenced within the template file. | 
|  | 158 | * Files are separated by tabs. | 
|  | 159 | */ | 
|  | 160 | void adddep(char * file)		   { printf("\t%s", file); } | 
| J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 161 | void adddep2(char * file, char * line)     { line = line; adddep(file); } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | void noaction(char * line)		   { line = line; } | 
| J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 163 | void noaction2(char * file, char * line)   { file = file; line = line; } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 |  | 
|  | 165 | /* Echo the line without further action */ | 
|  | 166 | void printline(char * line)               { printf("%s", line); } | 
|  | 167 |  | 
|  | 168 | /* | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 169 | * Find all symbols in filename that are exported with EXPORT_SYMBOL & | 
|  | 170 | * EXPORT_SYMBOL_GPL (& EXPORT_SYMBOL_GPL_FUTURE implicitly). | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | * All symbols located are stored in symfilelist. | 
|  | 172 | */ | 
|  | 173 | void find_export_symbols(char * filename) | 
|  | 174 | { | 
|  | 175 | FILE * fp; | 
|  | 176 | struct symfile *sym; | 
|  | 177 | char line[MAXLINESZ]; | 
|  | 178 | if (filename_exist(filename) == NULL) { | 
|  | 179 | char real_filename[PATH_MAX + 1]; | 
|  | 180 | memset(real_filename, 0, sizeof(real_filename)); | 
| Rob Landley | bb13be5 | 2007-10-09 01:25:18 -0500 | [diff] [blame] | 181 | strncat(real_filename, srctree, PATH_MAX); | 
| Jiri Slaby | 2d51005 | 2009-05-31 18:05:34 +0200 | [diff] [blame] | 182 | strncat(real_filename, "/", PATH_MAX - strlen(real_filename)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | strncat(real_filename, filename, | 
|  | 184 | PATH_MAX - strlen(real_filename)); | 
|  | 185 | sym = add_new_file(filename); | 
|  | 186 | fp = fopen(real_filename, "r"); | 
|  | 187 | if (fp == NULL) | 
|  | 188 | { | 
|  | 189 | fprintf(stderr, "docproc: "); | 
|  | 190 | perror(real_filename); | 
| Henrik Kretzschmar | 074a5dd | 2006-09-29 02:00:56 -0700 | [diff] [blame] | 191 | exit(1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 193 | while (fgets(line, MAXLINESZ, fp)) { | 
| J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 194 | char *p; | 
|  | 195 | char *e; | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 196 | if (((p = strstr(line, "EXPORT_SYMBOL_GPL")) != NULL) || | 
|  | 197 | ((p = strstr(line, "EXPORT_SYMBOL")) != NULL)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* Skip EXPORT_SYMBOL{_GPL} */ | 
|  | 199 | while (isalnum(*p) || *p == '_') | 
|  | 200 | p++; | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 201 | /* Remove parentheses & additional whitespace */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | while (isspace(*p)) | 
|  | 203 | p++; | 
|  | 204 | if (*p != '(') | 
|  | 205 | continue; /* Syntax error? */ | 
|  | 206 | else | 
|  | 207 | p++; | 
|  | 208 | while (isspace(*p)) | 
|  | 209 | p++; | 
|  | 210 | e = p; | 
|  | 211 | while (isalnum(*e) || *e == '_') | 
|  | 212 | e++; | 
|  | 213 | *e = '\0'; | 
|  | 214 | add_new_symbol(sym, p); | 
|  | 215 | } | 
|  | 216 | } | 
|  | 217 | fclose(fp); | 
|  | 218 | } | 
|  | 219 | } | 
|  | 220 |  | 
|  | 221 | /* | 
|  | 222 | * Document all external or internal functions in a file. | 
|  | 223 | * Call kernel-doc with following parameters: | 
|  | 224 | * kernel-doc -docbook -nofunction function_name1 filename | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 225 | * Function names are obtained from all the src files | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | * by find_export_symbols. | 
|  | 227 | * intfunc uses -nofunction | 
|  | 228 | * extfunc uses -function | 
|  | 229 | */ | 
|  | 230 | void docfunctions(char * filename, char * type) | 
|  | 231 | { | 
|  | 232 | int i,j; | 
|  | 233 | int symcnt = 0; | 
|  | 234 | int idx = 0; | 
|  | 235 | char **vec; | 
|  | 236 |  | 
|  | 237 | for (i=0; i <= symfilecnt; i++) | 
|  | 238 | symcnt += symfilelist[i].symbolcnt; | 
| Johannes Berg | 2e95972 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 239 | vec = malloc((2 + 2 * symcnt + 3) * sizeof(char *)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | if (vec == NULL) { | 
|  | 241 | perror("docproc: "); | 
|  | 242 | exit(1); | 
|  | 243 | } | 
|  | 244 | vec[idx++] = KERNELDOC; | 
|  | 245 | vec[idx++] = DOCBOOK; | 
| Johannes Berg | 2e95972 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 246 | vec[idx++] = NODOCSECTIONS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | for (i=0; i < symfilecnt; i++) { | 
|  | 248 | struct symfile * sym = &symfilelist[i]; | 
|  | 249 | for (j=0; j < sym->symbolcnt; j++) { | 
|  | 250 | vec[idx++]     = type; | 
|  | 251 | vec[idx++] = sym->symbollist[j].name; | 
|  | 252 | } | 
|  | 253 | } | 
|  | 254 | vec[idx++]     = filename; | 
|  | 255 | vec[idx] = NULL; | 
|  | 256 | printf("<!-- %s -->\n", filename); | 
|  | 257 | exec_kernel_doc(vec); | 
|  | 258 | fflush(stdout); | 
|  | 259 | free(vec); | 
|  | 260 | } | 
|  | 261 | void intfunc(char * filename) {	docfunctions(filename, NOFUNCTION); } | 
|  | 262 | void extfunc(char * filename) { docfunctions(filename, FUNCTION);   } | 
|  | 263 |  | 
|  | 264 | /* | 
| Randy Dunlap | c612093 | 2006-11-02 22:07:01 -0800 | [diff] [blame] | 265 | * Document specific function(s) in a file. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | * Call kernel-doc with the following parameters: | 
|  | 267 | * kernel-doc -docbook -function function1 [-function function2] | 
|  | 268 | */ | 
| J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 269 | void singfunc(char * filename, char * line) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { | 
|  | 271 | char *vec[200]; /* Enough for specific functions */ | 
|  | 272 | int i, idx = 0; | 
|  | 273 | int startofsym = 1; | 
|  | 274 | vec[idx++] = KERNELDOC; | 
|  | 275 | vec[idx++] = DOCBOOK; | 
|  | 276 |  | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 277 | /* Split line up in individual parameters preceded by FUNCTION */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | for (i=0; line[i]; i++) { | 
|  | 279 | if (isspace(line[i])) { | 
|  | 280 | line[i] = '\0'; | 
|  | 281 | startofsym = 1; | 
|  | 282 | continue; | 
|  | 283 | } | 
|  | 284 | if (startofsym) { | 
|  | 285 | startofsym = 0; | 
|  | 286 | vec[idx++] = FUNCTION; | 
|  | 287 | vec[idx++] = &line[i]; | 
|  | 288 | } | 
|  | 289 | } | 
|  | 290 | vec[idx++] = filename; | 
|  | 291 | vec[idx] = NULL; | 
|  | 292 | exec_kernel_doc(vec); | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | /* | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 296 | * Insert specific documentation section from a file. | 
|  | 297 | * Call kernel-doc with the following parameters: | 
|  | 298 | * kernel-doc -docbook -function "doc section" filename | 
|  | 299 | */ | 
|  | 300 | void docsect(char *filename, char *line) | 
|  | 301 | { | 
|  | 302 | char *vec[6]; /* kerneldoc -docbook -function "section" file NULL */ | 
|  | 303 | char *s; | 
|  | 304 |  | 
|  | 305 | for (s = line; *s; s++) | 
|  | 306 | if (*s == '\n') | 
|  | 307 | *s = '\0'; | 
|  | 308 |  | 
|  | 309 | vec[0] = KERNELDOC; | 
|  | 310 | vec[1] = DOCBOOK; | 
|  | 311 | vec[2] = FUNCTION; | 
|  | 312 | vec[3] = line; | 
|  | 313 | vec[4] = filename; | 
|  | 314 | vec[5] = NULL; | 
|  | 315 | exec_kernel_doc(vec); | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | * Parse file, calling action specific functions for: | 
|  | 320 | * 1) Lines containing !E | 
|  | 321 | * 2) Lines containing !I | 
|  | 322 | * 3) Lines containing !D | 
|  | 323 | * 4) Lines containing !F | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 324 | * 5) Lines containing !P | 
|  | 325 | * 6) Default lines - lines not matching the above | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | */ | 
|  | 327 | void parse_file(FILE *infile) | 
|  | 328 | { | 
|  | 329 | char line[MAXLINESZ]; | 
| J.A. Magallon | 48b9d03 | 2005-06-25 14:59:22 -0700 | [diff] [blame] | 330 | char * s; | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 331 | while (fgets(line, MAXLINESZ, infile)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (line[0] == '!') { | 
|  | 333 | s = line + 2; | 
|  | 334 | switch (line[1]) { | 
|  | 335 | case 'E': | 
|  | 336 | while (*s && !isspace(*s)) s++; | 
|  | 337 | *s = '\0'; | 
|  | 338 | externalfunctions(line+2); | 
|  | 339 | break; | 
|  | 340 | case 'I': | 
|  | 341 | while (*s && !isspace(*s)) s++; | 
|  | 342 | *s = '\0'; | 
|  | 343 | internalfunctions(line+2); | 
|  | 344 | break; | 
|  | 345 | case 'D': | 
|  | 346 | while (*s && !isspace(*s)) s++; | 
|  | 347 | *s = '\0'; | 
|  | 348 | symbolsonly(line+2); | 
|  | 349 | break; | 
|  | 350 | case 'F': | 
|  | 351 | /* filename */ | 
|  | 352 | while (*s && !isspace(*s)) s++; | 
|  | 353 | *s++ = '\0'; | 
|  | 354 | /* function names */ | 
|  | 355 | while (isspace(*s)) | 
|  | 356 | s++; | 
|  | 357 | singlefunctions(line +2, s); | 
|  | 358 | break; | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 359 | case 'P': | 
|  | 360 | /* filename */ | 
|  | 361 | while (*s && !isspace(*s)) s++; | 
|  | 362 | *s++ = '\0'; | 
|  | 363 | /* DOC: section name */ | 
|  | 364 | while (isspace(*s)) | 
|  | 365 | s++; | 
|  | 366 | docsection(line + 2, s); | 
|  | 367 | break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | default: | 
|  | 369 | defaultline(line); | 
|  | 370 | } | 
|  | 371 | } | 
|  | 372 | else { | 
|  | 373 | defaultline(line); | 
|  | 374 | } | 
|  | 375 | } | 
|  | 376 | fflush(stdout); | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 |  | 
|  | 380 | int main(int argc, char *argv[]) | 
|  | 381 | { | 
|  | 382 | FILE * infile; | 
| Rob Landley | bb13be5 | 2007-10-09 01:25:18 -0500 | [diff] [blame] | 383 |  | 
|  | 384 | srctree = getenv("SRCTREE"); | 
|  | 385 | if (!srctree) | 
|  | 386 | srctree = getcwd(NULL, 0); | 
| Jiri Slaby | 2d51005 | 2009-05-31 18:05:34 +0200 | [diff] [blame] | 387 | kernsrctree = getenv("KBUILD_SRC"); | 
| Amerigo Wang | b767b90 | 2009-06-19 03:06:54 -0400 | [diff] [blame] | 388 | if (!kernsrctree || !*kernsrctree) | 
| Jiri Slaby | 2d51005 | 2009-05-31 18:05:34 +0200 | [diff] [blame] | 389 | kernsrctree = srctree; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | if (argc != 3) { | 
|  | 391 | usage(); | 
|  | 392 | exit(1); | 
|  | 393 | } | 
|  | 394 | /* Open file, exit on error */ | 
|  | 395 | infile = fopen(argv[2], "r"); | 
|  | 396 | if (infile == NULL) { | 
|  | 397 | fprintf(stderr, "docproc: "); | 
|  | 398 | perror(argv[2]); | 
|  | 399 | exit(2); | 
|  | 400 | } | 
|  | 401 |  | 
|  | 402 | if (strcmp("doc", argv[1]) == 0) | 
|  | 403 | { | 
|  | 404 | /* Need to do this in two passes. | 
|  | 405 | * First pass is used to collect all symbols exported | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 406 | * in the various files; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | * Second pass generate the documentation. | 
| Randy Dunlap | 6dd16f4 | 2007-09-04 21:23:22 -0700 | [diff] [blame] | 408 | * This is required because some functions are declared | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | * and exported in different files :-(( | 
|  | 410 | */ | 
|  | 411 | /* Collect symbols */ | 
|  | 412 | defaultline       = noaction; | 
|  | 413 | internalfunctions = find_export_symbols; | 
|  | 414 | externalfunctions = find_export_symbols; | 
|  | 415 | symbolsonly       = find_export_symbols; | 
|  | 416 | singlefunctions   = noaction2; | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 417 | docsection        = noaction2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | parse_file(infile); | 
|  | 419 |  | 
|  | 420 | /* Rewind to start from beginning of file again */ | 
|  | 421 | fseek(infile, 0, SEEK_SET); | 
|  | 422 | defaultline       = printline; | 
|  | 423 | internalfunctions = intfunc; | 
|  | 424 | externalfunctions = extfunc; | 
|  | 425 | symbolsonly       = printline; | 
|  | 426 | singlefunctions   = singfunc; | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 427 | docsection        = docsect; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 |  | 
|  | 429 | parse_file(infile); | 
|  | 430 | } | 
|  | 431 | else if (strcmp("depend", argv[1]) == 0) | 
|  | 432 | { | 
|  | 433 | /* Create first part of dependency chain | 
|  | 434 | * file.tmpl */ | 
|  | 435 | printf("%s\t", argv[2]); | 
|  | 436 | defaultline       = noaction; | 
|  | 437 | internalfunctions = adddep; | 
|  | 438 | externalfunctions = adddep; | 
|  | 439 | symbolsonly       = adddep; | 
|  | 440 | singlefunctions   = adddep2; | 
| Johannes Berg | e662af4 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 441 | docsection        = adddep2; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | parse_file(infile); | 
|  | 443 | printf("\n"); | 
|  | 444 | } | 
|  | 445 | else | 
|  | 446 | { | 
|  | 447 | fprintf(stderr, "Unknown option: %s\n", argv[1]); | 
|  | 448 | exit(1); | 
|  | 449 | } | 
|  | 450 | fclose(infile); | 
|  | 451 | fflush(stdout); | 
|  | 452 | return exitstatus; | 
|  | 453 | } |