summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/ptx/examples/include.pl
blob: cb3c0ffe5263674aa373ad0ab9a13586813d1e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl --						# -*-Perl-*-
eval "exec /usr/bin/perl -S $0 $*"
    if $running_under_some_shell;

# Construct a permuted index for all system include files.
# Copyright (C) 1991 Free Software Foundation, Inc.
# Francois Pinard <pinard@iro.umontreal.ca>, June 1991.

# NOTE: about removing asm statements?
# NOTE: about removing strings?
# NOTE: about ignoring 0xHEXDIGITS, unchar/ushort/etc.

# Construct a sorted list of system include files.

opendir (DIR, "/usr/include");
@includes = sort grep (-f "/usr/include/$_", readdir (DIR));
opendir (DIR, "/usr/include/sys");
foreach (sort grep (-f "/usr/include/sys/$_", readdir (DIR))) {
    push (@includes, "sys/$_");
}
closedir (DIR);

# Launch the permuted indexer, with a list of ignore words. 

$ignore = "/tmp/incptx.$$";
open (IGNORE, "> $ignore");
print IGNORE join ("\n", split (' ', <<IGNORE)), "\n";
asm at at386 break bss case ch char continue copyright corporation
default define defined do double dst else endif enum extern file flag
float for goto i286 i386 ident if ifdef ifndef int interactive len
lint long m32 mpat num pdp11 printf ptr register return sco5 short siz
sizeof src static str struct sun switch sys systems type typedef u370
u3b u3b15 u3b2 u3b5 undef union unsigned vax void while win
IGNORE
close IGNORE;
exit 0;

open (OUTPUT, "| ptx -r -f -W '[a-zA-Z_][a-zA-Z_0-9]+' -F ... -i $ignore")
    || die "ptx did not start\n";
select (OUTPUT);

# Reformat all files, removing C comments and adding a reference field.

foreach $include (@includes)
{
    warn "Reading /usr/include/$include\n";
    open (INPUT, "/usr/include/$include");
    while (<INPUT>)
    {

	# Get rid of comments.

	$comment = $next_comment;
	if ($comment)
	{
	    $next_comment = !s,^.*\*/,,;
	}
	else
	{
	    s,/\*.*\*/,,g;
	    $next_comment = s,/\*.*,,;
	}
	next if $comment && $next_comment;

	# Remove extraneous white space.

	s/[ \t]+/ /g;
	s/ $//;
	next if /^$/;

	# Print the line with its reference.

	print "$include($.): ", $_;
    }
}

warn "All read, now ptx' game!\n";
close OUTPUT || die "ptx failed...\n";
unlink $ignore;
OpenPOWER on IntegriCloud