File: mktd.SH

package info (click to toggle)
trn4 4.0-test77-18
  • links: PTS, VCS
  • area: non-free
  • in suites: sid, trixie
  • size: 4,016 kB
  • sloc: ansic: 48,332; sh: 6,795; tcl: 1,696; yacc: 662; perl: 108; makefile: 26
file content (73 lines) | stat: -rw-r--r-- 1,696 bytes parent folder | download | duplicates (11)
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
case $CONFIG in
    '') . ./config.sh ;;
esac
echo "Extracting mktd (with variable substitutions)"
$spitshell >mktd <<!GROK!THIS!
#!$perlpath
#
# mktd - make typedef.h
#

chdir "$src";
!GROK!THIS!
$spitshell >>mktd <<'!NO!SUBS!'

# We scan the .h and .ih files for definitions of the form:
#
#    struct foo { ... };
# and
#    union bar { ... };
#
# and create typedefs of:
#
#    typedef struct foo FOO;
# and
#    typedef union bar BAR;
#
# in the file typedef.nh.  If it differs from typedef.h, move the
# old version to the directory "sanity" and rename the new one.

open(IN, "<typedef.h") || die "Can't open typedef.h for input\n";
open(OUT, ">typedef.nh") || die "Can't open typedef.nh for output\n";

# Copy everything up to the DON'T EDIT line.
while (<IN>) {
    print OUT $_;
    last if /DON'T EDIT BELOW/;
}

close IN;

# Scan through all the .h and .ih files
foreach $file (sort(<*.h>, <*.ih>)) {
    open(IN, $file) || die "Can't open $file for input\n";
    # The first typedef from this file needs a preceding comment.
    $need_comment = 1;
    while (<IN>) {
	next unless /^(struct|union)\s+([a-z][a-z0-9_]*)\s+{/;
	if ($need_comment) {
	    print OUT "\n/* $file */\n\n";
	    $need_comment = 0;
	}
	$upper = $2;
	$upper =~ tr/a-z/A-Z/;
	print OUT "typedef $1 $2 $upper;\n";
    }
    close IN;
}

close OUT;

# Check for any differences and update if changed.
if (system "diff -q typedef.h typedef.nh >/dev/null") {
	print "Updating typedef.h\n";
	mkdir("sanity",0755) unless -d "sanity";
	rename("typedef.h","sanity/typedef.h");
	rename("typedef.nh","typedef.h");
} else {
	print "No change to typedef.h\n";
	unlink "typedef.nh";
}
!NO!SUBS!
$eunicefix mktd
chmod 755 mktd