File: scanerr.pl

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (100 lines) | stat: -rw-r--r-- 2,116 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!perl

# Scan the err*.c files and create the ERROR.H include file.

$src = shift;

for (@ARGV) {
	push(@h, glob($_));
}
@ARGV = @h;

while(<>) {
	next unless /^void\s+[a-z]/;
	chomp;
	if(/^([^\(]+\([^\)]+\))\s*$/) {
		# simple case
		print "$1;\n";
	} else {
		$line = $_ . "\n";
		$cnt = 1;
		die "Syntax error in function definition"
			unless ($i = index($line, '(')) >= 0;
		$fnam = $ARGV;
		while($cnt) {
			if(++$i >= length($line)) {
				$_ = <>;
				die "Missing right parenthesis in file $fnam\n"
					if !$_ || $ARGV != $fnam;
				$line .= $_;
			}
			++$cnt if substr($line, $i, 1) eq '(';
			--$cnt if substr($line, $i, 1) eq ')';
		}
		print substr($line, 0, $i) . ";\n";
	}
}

if($src) {
	die "Cannot open file $src: $!\n"
		unless open(SRC, $src);
	$i = rindex($src, "\\");
	$j = rindex($src, '/');
	if($i < 0 && $j < 0) {
		$dir = '.';
	} else {
		$dir = substr($src, 0, $i > $j? $i: $j);
	}
	$cnt = 0;
	die "Cannot create Makefile include file: $dir/err_fcts.mk: $!\n"
		unless open(MK, ">$dir/err_fcts.mk");
	while(<SRC>) {
		chop;
		die "Syntax error"
			unless /:=/;
		$header = $`;
		$body = "displayError($');";
		if($header =~ /\(/) {
			$fctname = $`;
		} else {
			$fctname = $header;
			$header .= '(void)';
		}
		$fnam = "$dir/err" . ++$cnt . '.c';
		die "Cannot create $fnam: $!\n"
			unless open(OUT, ">$fnam");
		print "void $header;\n";
		print OUT "/*	This is an automatic generated file

	DO NOT EDIT! SEE ERR_FCTS.SRC and SCANERR.PL.

	Error printing function providing a wrapper for STRINGS
 */

#include \"../config.h\"

#include \"../include/misc.h\"
#include \"../err_fcts.h\"
#include \"../strings.h\"

#undef $fctname
void $header
{	$body
}
";
		close OUT;
	}
	print MK "SRC_ERR = ";
	foreach $i (1..$cnt) {
		print MK " \\\n\terr$i.c"
	}
	print MK "\n\nOBJ_ERR = ";
	foreach $i (1..$cnt) {
		print MK " \\\n\terr$i.obj"
	}
	print MK "\n\n";
	foreach $i (1..$cnt) {
		print MK "err$i.obj : err$i.c ../config.h ../strings.h ../err_fcts.h ../include/misc.h\n"
	}
	close MK;
}