aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/basic
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2010-12-14 16:01:55 -0500
committerMichal Marek <mmarek@suse.cz>2010-12-14 16:01:55 -0500
commit8990c1bc4be46473ad19bf2fa612ca57286f3df4 (patch)
tree3cea60576903a1d26c67e6ec62891b524d390e95 /scripts/basic
parent2979076fbf17a0947d6eba367b0cac19c907c160 (diff)
parentc8ddb2713c624f432fa5fe3c7ecffcdda46ea0d4 (diff)
Merge commit 'v2.6.37-rc1' into kbuild/kbuild
Diffstat (limited to 'scripts/basic')
-rw-r--r--scripts/basic/Makefile2
-rw-r--r--scripts/basic/docproc.c132
-rw-r--r--scripts/basic/hash.c64
3 files changed, 132 insertions, 66 deletions
diff --git a/scripts/basic/Makefile b/scripts/basic/Makefile
index 09559951df12..4c324a1f1e0e 100644
--- a/scripts/basic/Makefile
+++ b/scripts/basic/Makefile
@@ -9,7 +9,7 @@
9# fixdep: Used to generate dependency information during build process 9# fixdep: Used to generate dependency information during build process
10# docproc: Used in Documentation/DocBook 10# docproc: Used in Documentation/DocBook
11 11
12hostprogs-y := fixdep docproc hash 12hostprogs-y := fixdep docproc
13always := $(hostprogs-y) 13always := $(hostprogs-y)
14 14
15# fixdep is needed to compile other host programs 15# fixdep is needed to compile other host programs
diff --git a/scripts/basic/docproc.c b/scripts/basic/docproc.c
index 79ab973fb43a..98dec87974d0 100644
--- a/scripts/basic/docproc.c
+++ b/scripts/basic/docproc.c
@@ -34,12 +34,14 @@
34 * 34 *
35 */ 35 */
36 36
37#define _GNU_SOURCE
37#include <stdio.h> 38#include <stdio.h>
38#include <stdlib.h> 39#include <stdlib.h>
39#include <string.h> 40#include <string.h>
40#include <ctype.h> 41#include <ctype.h>
41#include <unistd.h> 42#include <unistd.h>
42#include <limits.h> 43#include <limits.h>
44#include <errno.h>
43#include <sys/types.h> 45#include <sys/types.h>
44#include <sys/wait.h> 46#include <sys/wait.h>
45 47
@@ -54,6 +56,7 @@ typedef void FILEONLY(char * file);
54FILEONLY *internalfunctions; 56FILEONLY *internalfunctions;
55FILEONLY *externalfunctions; 57FILEONLY *externalfunctions;
56FILEONLY *symbolsonly; 58FILEONLY *symbolsonly;
59FILEONLY *findall;
57 60
58typedef void FILELINE(char * file, char * line); 61typedef void FILELINE(char * file, char * line);
59FILELINE * singlefunctions; 62FILELINE * singlefunctions;
@@ -65,12 +68,30 @@ FILELINE * docsection;
65#define KERNELDOCPATH "scripts/" 68#define KERNELDOCPATH "scripts/"
66#define KERNELDOC "kernel-doc" 69#define KERNELDOC "kernel-doc"
67#define DOCBOOK "-docbook" 70#define DOCBOOK "-docbook"
71#define LIST "-list"
68#define FUNCTION "-function" 72#define FUNCTION "-function"
69#define NOFUNCTION "-nofunction" 73#define NOFUNCTION "-nofunction"
70#define NODOCSECTIONS "-no-doc-sections" 74#define NODOCSECTIONS "-no-doc-sections"
71 75
72static char *srctree, *kernsrctree; 76static char *srctree, *kernsrctree;
73 77
78static char **all_list = NULL;
79static int all_list_len = 0;
80
81static void consume_symbol(const char *sym)
82{
83 int i;
84
85 for (i = 0; i < all_list_len; i++) {
86 if (!all_list[i])
87 continue;
88 if (strcmp(sym, all_list[i]))
89 continue;
90 all_list[i] = NULL;
91 break;
92 }
93}
94
74static void usage (void) 95static void usage (void)
75{ 96{
76 fprintf(stderr, "Usage: docproc {doc|depend} file\n"); 97 fprintf(stderr, "Usage: docproc {doc|depend} file\n");
@@ -248,6 +269,7 @@ static void docfunctions(char * filename, char * type)
248 struct symfile * sym = &symfilelist[i]; 269 struct symfile * sym = &symfilelist[i];
249 for (j=0; j < sym->symbolcnt; j++) { 270 for (j=0; j < sym->symbolcnt; j++) {
250 vec[idx++] = type; 271 vec[idx++] = type;
272 consume_symbol(sym->symbollist[j].name);
251 vec[idx++] = sym->symbollist[j].name; 273 vec[idx++] = sym->symbollist[j].name;
252 } 274 }
253 } 275 }
@@ -287,6 +309,11 @@ static void singfunc(char * filename, char * line)
287 vec[idx++] = &line[i]; 309 vec[idx++] = &line[i];
288 } 310 }
289 } 311 }
312 for (i = 0; i < idx; i++) {
313 if (strcmp(vec[i], FUNCTION))
314 continue;
315 consume_symbol(vec[i + 1]);
316 }
290 vec[idx++] = filename; 317 vec[idx++] = filename;
291 vec[idx] = NULL; 318 vec[idx] = NULL;
292 exec_kernel_doc(vec); 319 exec_kernel_doc(vec);
@@ -306,6 +333,13 @@ static void docsect(char *filename, char *line)
306 if (*s == '\n') 333 if (*s == '\n')
307 *s = '\0'; 334 *s = '\0';
308 335
336 if (asprintf(&s, "DOC: %s", line) < 0) {
337 perror("asprintf");
338 exit(1);
339 }
340 consume_symbol(s);
341 free(s);
342
309 vec[0] = KERNELDOC; 343 vec[0] = KERNELDOC;
310 vec[1] = DOCBOOK; 344 vec[1] = DOCBOOK;
311 vec[2] = FUNCTION; 345 vec[2] = FUNCTION;
@@ -315,6 +349,84 @@ static void docsect(char *filename, char *line)
315 exec_kernel_doc(vec); 349 exec_kernel_doc(vec);
316} 350}
317 351
352static void find_all_symbols(char *filename)
353{
354 char *vec[4]; /* kerneldoc -list file NULL */
355 pid_t pid;
356 int ret, i, count, start;
357 char real_filename[PATH_MAX + 1];
358 int pipefd[2];
359 char *data, *str;
360 size_t data_len = 0;
361
362 vec[0] = KERNELDOC;
363 vec[1] = LIST;
364 vec[2] = filename;
365 vec[3] = NULL;
366
367 if (pipe(pipefd)) {
368 perror("pipe");
369 exit(1);
370 }
371
372 switch (pid=fork()) {
373 case -1:
374 perror("fork");
375 exit(1);
376 case 0:
377 close(pipefd[0]);
378 dup2(pipefd[1], 1);
379 memset(real_filename, 0, sizeof(real_filename));
380 strncat(real_filename, kernsrctree, PATH_MAX);
381 strncat(real_filename, "/" KERNELDOCPATH KERNELDOC,
382 PATH_MAX - strlen(real_filename));
383 execvp(real_filename, vec);
384 fprintf(stderr, "exec ");
385 perror(real_filename);
386 exit(1);
387 default:
388 close(pipefd[1]);
389 data = malloc(4096);
390 do {
391 while ((ret = read(pipefd[0],
392 data + data_len,
393 4096)) > 0) {
394 data_len += ret;
395 data = realloc(data, data_len + 4096);
396 }
397 } while (ret == -EAGAIN);
398 if (ret != 0) {
399 perror("read");
400 exit(1);
401 }
402 waitpid(pid, &ret ,0);
403 }
404 if (WIFEXITED(ret))
405 exitstatus |= WEXITSTATUS(ret);
406 else
407 exitstatus = 0xff;
408
409 count = 0;
410 /* poor man's strtok, but with counting */
411 for (i = 0; i < data_len; i++) {
412 if (data[i] == '\n') {
413 count++;
414 data[i] = '\0';
415 }
416 }
417 start = all_list_len;
418 all_list_len += count;
419 all_list = realloc(all_list, sizeof(char *) * all_list_len);
420 str = data;
421 for (i = 0; i < data_len && start != all_list_len; i++) {
422 if (data[i] == '\0') {
423 all_list[start] = str;
424 str = data + i + 1;
425 start++;
426 }
427 }
428}
429
318/* 430/*
319 * Parse file, calling action specific functions for: 431 * Parse file, calling action specific functions for:
320 * 1) Lines containing !E 432 * 1) Lines containing !E
@@ -322,7 +434,8 @@ static void docsect(char *filename, char *line)
322 * 3) Lines containing !D 434 * 3) Lines containing !D
323 * 4) Lines containing !F 435 * 4) Lines containing !F
324 * 5) Lines containing !P 436 * 5) Lines containing !P
325 * 6) Default lines - lines not matching the above 437 * 6) Lines containing !C
438 * 7) Default lines - lines not matching the above
326 */ 439 */
327static void parse_file(FILE *infile) 440static void parse_file(FILE *infile)
328{ 441{
@@ -365,6 +478,12 @@ static void parse_file(FILE *infile)
365 s++; 478 s++;
366 docsection(line + 2, s); 479 docsection(line + 2, s);
367 break; 480 break;
481 case 'C':
482 while (*s && !isspace(*s)) s++;
483 *s = '\0';
484 if (findall)
485 findall(line+2);
486 break;
368 default: 487 default:
369 defaultline(line); 488 defaultline(line);
370 } 489 }
@@ -380,6 +499,7 @@ static void parse_file(FILE *infile)
380int main(int argc, char *argv[]) 499int main(int argc, char *argv[])
381{ 500{
382 FILE * infile; 501 FILE * infile;
502 int i;
383 503
384 srctree = getenv("SRCTREE"); 504 srctree = getenv("SRCTREE");
385 if (!srctree) 505 if (!srctree)
@@ -415,6 +535,7 @@ int main(int argc, char *argv[])
415 symbolsonly = find_export_symbols; 535 symbolsonly = find_export_symbols;
416 singlefunctions = noaction2; 536 singlefunctions = noaction2;
417 docsection = noaction2; 537 docsection = noaction2;
538 findall = find_all_symbols;
418 parse_file(infile); 539 parse_file(infile);
419 540
420 /* Rewind to start from beginning of file again */ 541 /* Rewind to start from beginning of file again */
@@ -425,8 +546,16 @@ int main(int argc, char *argv[])
425 symbolsonly = printline; 546 symbolsonly = printline;
426 singlefunctions = singfunc; 547 singlefunctions = singfunc;
427 docsection = docsect; 548 docsection = docsect;
549 findall = NULL;
428 550
429 parse_file(infile); 551 parse_file(infile);
552
553 for (i = 0; i < all_list_len; i++) {
554 if (!all_list[i])
555 continue;
556 fprintf(stderr, "Warning: didn't use docs for %s\n",
557 all_list[i]);
558 }
430 } 559 }
431 else if (strcmp("depend", argv[1]) == 0) 560 else if (strcmp("depend", argv[1]) == 0)
432 { 561 {
@@ -439,6 +568,7 @@ int main(int argc, char *argv[])
439 symbolsonly = adddep; 568 symbolsonly = adddep;
440 singlefunctions = adddep2; 569 singlefunctions = adddep2;
441 docsection = adddep2; 570 docsection = adddep2;
571 findall = adddep;
442 parse_file(infile); 572 parse_file(infile);
443 printf("\n"); 573 printf("\n");
444 } 574 }
diff --git a/scripts/basic/hash.c b/scripts/basic/hash.c
deleted file mode 100644
index 2ef5d3f666b8..000000000000
--- a/scripts/basic/hash.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
3 *
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#define DYNAMIC_DEBUG_HASH_BITS 6
11
12static const char *program;
13
14static void usage(void)
15{
16 printf("Usage: %s <djb2|r5> <modname>\n", program);
17 exit(1);
18}
19
20/* djb2 hashing algorithm by Dan Bernstein. From:
21 * http://www.cse.yorku.ca/~oz/hash.html
22 */
23
24static unsigned int djb2_hash(char *str)
25{
26 unsigned long hash = 5381;
27 int c;
28
29 c = *str;
30 while (c) {
31 hash = ((hash << 5) + hash) + c;
32 c = *++str;
33 }
34 return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
35}
36
37static unsigned int r5_hash(char *str)
38{
39 unsigned long hash = 0;
40 int c;
41
42 c = *str;
43 while (c) {
44 hash = (hash + (c << 4) + (c >> 4)) * 11;
45 c = *++str;
46 }
47 return (unsigned int)(hash & ((1 << DYNAMIC_DEBUG_HASH_BITS) - 1));
48}
49
50int main(int argc, char *argv[])
51{
52 program = argv[0];
53
54 if (argc != 3)
55 usage();
56 if (!strcmp(argv[1], "djb2"))
57 printf("%d\n", djb2_hash(argv[2]));
58 else if (!strcmp(argv[1], "r5"))
59 printf("%d\n", r5_hash(argv[2]));
60 else
61 usage();
62 exit(0);
63}
64