Debian Codegraph @

awklib/extract.awk

raw
1 # extract.awk --- extract files and run programs from Texinfo files
2 #
3 # Arnold Robbins, [email protected], Public Domain
4 # May 1993
5 # Revised September 2000
6
7 BEGIN { IGNORECASE = 1 }
8
9 /^@c(omment)?[ \t]+system/ {
10 if (NF < 3) {
11 e = ("extract: " FILENAME ":" FNR)
12 e = (e ": badly formed `system' line")
13 print e > "/dev/stderr"
14 next
15 }
16 $1 = ""
17 $2 = ""
18 stat = system($0)
19 if (stat != 0) {
20 e = ("extract: " FILENAME ":" FNR)
21 e = (e ": warning: system returned " stat)
22 print e > "/dev/stderr"
23 }
24 }
25 /^@c(omment)?[ \t]+file/ {
26 if (NF != 3) {
27 e = ("extract: " FILENAME ":" FNR ": badly formed `file' line")
28 print e > "/dev/stderr"
29 next
30 }
31 if ($3 != curfile) {
32 if (curfile != "")
33 filelist[curfile] = 1 # save to close later
34 curfile = $3
35 }
36
37 for (;;) {
38 if ((getline line) <= 0)
39 unexpected_eof()
40 if (line ~ /^@c(omment)?[ \t]+endfile/)
41 break
42 else if (line ~ /^@(end[ \t]+)?group/)
43 continue
44 else if (line ~ /^@c(omment+)?[ \t]+/)
45 continue
46 if (index(line, "@") == 0) {
47 print line > curfile
48 continue
49 }
50 n = split(line, a, "@")
51 # if a[1] == "", means leading @,
52 # don't add one back in.
53 for (i = 2; i <= n; i++) {
54 if (a[i] == "") { # was an @@
55 a[i] = "@"
56 if (a[i+1] == "")
57 i++
58 }
59 }
60 print join(a, 1, n, SUBSEP) > curfile
61 }
62 }
63 END {
64 close(curfile) # close the last one
65 for (f in filelist) # close all the rest
66 close(f)
67 }
68 function unexpected_eof()
69 {
70 printf("extract: %s:%d: unexpected EOF or error\n",
71 FILENAME, FNR) > "/dev/stderr"
72 exit 1
73 }
74
75 # join.awk --- join an array into a string
76 #
77 # Arnold Robbins, [email protected], Public Domain
78 # May 1993
79
80 function join(array, start, end, sep, result, i)
81 {
82 if (sep == "")
83 sep = " "
84 else if (sep == SUBSEP) # magic value
85 sep = ""
86 result = array[start]
87 for (i = start + 1; i <= end; i++)
88 result = result sep array[i]
89 return result
90 }