Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / ptx / examples / include.pl
1 #!/usr/bin/perl --                                              # -*-Perl-*-
2 eval "exec /usr/bin/perl -S $0 $*"
3     if $running_under_some_shell;
4
5 # Construct a permuted index for all system include files.
6 # Copyright (C) 1991 Free Software Foundation, Inc.
7 # Francois Pinard <pinard@iro.umontreal.ca>, June 1991.
8
9 # NOTE: about removing asm statements?
10 # NOTE: about removing strings?
11 # NOTE: about ignoring 0xHEXDIGITS, unchar/ushort/etc.
12
13 # Construct a sorted list of system include files.
14
15 opendir (DIR, "/usr/include");
16 @includes = sort grep (-f "/usr/include/$_", readdir (DIR));
17 opendir (DIR, "/usr/include/sys");
18 foreach (sort grep (-f "/usr/include/sys/$_", readdir (DIR))) {
19     push (@includes, "sys/$_");
20 }
21 closedir (DIR);
22
23 # Launch the permuted indexer, with a list of ignore words. 
24
25 $ignore = "/tmp/incptx.$$";
26 open (IGNORE, "> $ignore");
27 print IGNORE join ("\n", split (' ', <<IGNORE)), "\n";
28 asm at at386 break bss case ch char continue copyright corporation
29 default define defined do double dst else endif enum extern file flag
30 float for goto i286 i386 ident if ifdef ifndef int interactive len
31 lint long m32 mpat num pdp11 printf ptr register return sco5 short siz
32 sizeof src static str struct sun switch sys systems type typedef u370
33 u3b u3b15 u3b2 u3b5 undef union unsigned vax void while win
34 IGNORE
35 close IGNORE;
36 exit 0;
37
38 open (OUTPUT, "| ptx -r -f -W '[a-zA-Z_][a-zA-Z_0-9]+' -F ... -i $ignore")
39     || die "ptx did not start\n";
40 select (OUTPUT);
41
42 # Reformat all files, removing C comments and adding a reference field.
43
44 foreach $include (@includes)
45 {
46     warn "Reading /usr/include/$include\n";
47     open (INPUT, "/usr/include/$include");
48     while (<INPUT>)
49     {
50
51         # Get rid of comments.
52
53         $comment = $next_comment;
54         if ($comment)
55         {
56             $next_comment = !s,^.*\*/,,;
57         }
58         else
59         {
60             s,/\*.*\*/,,g;
61             $next_comment = s,/\*.*,,;
62         }
63         next if $comment && $next_comment;
64
65         # Remove extraneous white space.
66
67         s/[ \t]+/ /g;
68         s/ $//;
69         next if /^$/;
70
71         # Print the line with its reference.
72
73         print "$include($.): ", $_;
74     }
75 }
76
77 warn "All read, now ptx' game!\n";
78 close OUTPUT || die "ptx failed...\n";
79 unlink $ignore;