source: trunk/essentials/sys-apps/gawk/awklib/extract.awk

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

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