parseConfig
1.38 KB
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
#!/usr/local/bin/perl5
#
# Copyright (C) 1996-1998 by the Board of Trustees
# of Leland Stanford Junior University.
#
# This file is part of the SimOS distribution.
# See LICENSE file for terms of the license.
#
if ($ARGV[0]) {
open (CONFIG, $ARGV[0]);
} else {
open (CONFIG, "./simconfig.c");
}
$beginconfig = 0;
while (<CONFIG>) {
if(/SimConfigDefaults\(void\)/) {
$beginconfig = 1;
}
if(/^#define\s+(\S+)\s+(\S+)/) {
$defarr{$1} = $2;
}
if($beginconfig == 0) {
next;
}
if(/\/\* ENDCONFIG \*\//) {
last;
}
if(/^\s*SimConfigSet(\w+)\s*\(\s*"(\w+)"\s*,\s*(\S+)\s*\)\s*;(\s*\/\*([^*]+)(\*\/)?)?/) {
$tag = join('', $2, ":");
$comment = $5;
$cont = $6;
$token = $1;
if(($1 eq "String") || ($1 eq "Line") || ($1 eq "Bool")) {
$3 =~ /"(\S*)"/;
if($defarr{$1}) {
$defarr{$1} =~ /"(\S*)"/;
}
$val = $1;
} else {
if($defarr{$3}) {
$val = $defarr{$3};
} else {
$val = $3;
}
}
printf "%-25s %-25s#%-6s", $tag, $val, $token;
if($comment) {
if(!$cont) {
chop $comment;
}
printf ": %s\n", $comment;
while(!($cont) && ($cline = <CONFIG>)) {
if($cline =~ /^\s*(\* )?([^*]*)(\*\/)?/) {
$cont = $3;
if($2) {
printf "%51s# %s", "", $2;
}
}
}
} else {
print "\n";
}
next;
}
if(/\/\*\s*(.+)\s*\*\//) {
print "\n# $1\n";
}
}