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
101
102
103
104
|
function do_if(proc,sym, direct ) {
if( (sym in defined) && (defined[sym]!=0 ) ) {
while( direct!="else" && direct!="endif" ) direct=proc_line(proc)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(0)
} else {
while( direct!="else" && direct!="endif" ) direct=proc_line(0)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(proc)
}
}
function do_if_not(proc,sym, direct ) {
if( (!(sym in defined)) || (defined[sym]==0 ) ) {
while( direct!="else" && direct!="endif" ) direct=proc_line(proc)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(0)
} else {
while( direct!="else" && direct!="endif" ) direct=proc_line(0)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(proc)
}
}
function do_ifdef(proc,sym, direct ) {
if( sym in defined ) {
while( direct!="else" && direct!="endif" ) direct=proc_line(proc)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(0)
} else {
while( direct!="else" && direct!="endif" ) direct=proc_line(0)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(proc)
}
}
function do_ifndef(proc,sym, direct) {
if( !(sym in defined) ) {
while( direct!="else" && direct!="endif" ) direct=proc_line(proc)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(0)
} else {
while( direct!="else" && direct!="endif" ) direct=proc_line(0)
if(direct=="else")
while( direct!="endif" ) direct=proc_line(proc)
}
}
function proc_line(proc, direct) {
if( (getline<"jbtxbst.doc") <1 ) {
exit
}
lno++;
if( $0 ~ /^#/ ) {
if( $1=="#" ) {
direct=$2; arg1=$3; arg2=$4
}else {
direct=substr($1,2,16); arg1=$2; arg2=$3
}
if(direct=="define") {
if(proc) defined[arg1]=arg2+0
} else if(direct=="ifdef" ){
do_ifdef(proc,arg1)
}else if(direct=="ifndef") {
do_ifndef(proc,arg1)
}else if(direct=="if") {
if( substr(arg1,1,1)=="!" ) do_if_not(proc,substr(arg1,2,32))
else do_if(proc,arg1)
}else if( (direct!="else") && (direct!="endif") ){
print "% Error **undefined **",direct,"** in line",lno >"/dev/tty"
exit
}
return direct;
}else if($0 ~ /^%/ ) {
return "" # コメントは基本的には削除する
}else if($0 ~ /^ %/ ) {
sub(/ /,"") # この形式のコメントは出力する
print $0
return ""
}else {
if(proc) print $0
return ""
}
}
BEGIN{
if(ARGC<2) {
print "usage: gawk -f cpp.awk <style-type> [<option>]"
print "<style-type> = JPLAIN | JALPHA | JABBRV | JUNSRT | JIPSJ"
print " TIPSJ | TIEICE | JNAME | JORSJ"
print "<option> = ASCII"
exit
}
opt=ARGV[1]
name["JPLAIN"]="jplain"; name["JALPHA"]="jalpha"; name["JABBRV"]="jabbrv"
name["JUNSRT"]="junsrt"; name["JIPSJ" ]="jipsj" ; name["TIPSJ" ]="tipsj"
name["TIEICE"]="tieice"; name["JNAME" ]="jname" ; name["JORSJ" ]="jorsj"
if( opt in name )
printf("%% JBibTeX standard bibliography style `%s'\n",name[opt])
for(i=1;i<ARGC;i++) {
defined[ARGV[i]]=1
ARGV[i]=""
}
while(1) proc_line(1)
}
|