|
|
1.1 root 1: # DELAMC
2: #
3: # Delaminate file using tab characters
4: #
5: # Thomas R. Hicks
6: #
7: # Last modified 2/9/86 by Ralph E. Griswold
8: #
9:
10: procedure main(a)
11: local tabset, fylist, nxtarg
12: if match("-t",a[1]) then # tab char given
13: tabset := cset(a[1][3:0])
14: if 0 = *(fylist := doutfyls(a)) then Usage()
15: /tabset := cset(&ascii[10]) # tab is default separator
16: delamrc(tabset,fylist) # call main routine
17: end
18:
19: # Usage - write usage message
20: #
21: procedure Usage()
22: stop("usage: delamc [-tc] {outputfile | -} ...")
23: end
24:
25: # delamrc - do actual division of input file using tab chars
26: #
27: procedure delamrc(tabset,fylist)
28: local i, flen, line
29: while line := read() do
30: {
31: i := 1
32: flen := *fylist
33: line ? while (i <= flen) do
34: {
35: if i = flen then
36: write(fylist[i][2],tab(0) | "")
37: else
38: write(fylist[i][2],tab(upto(tabset)) | tab(0) | "")
39: move(1)
40: i +:= 1
41: }
42: }
43: end
44:
45: # doutfyls - process output file arguments; return list
46: #
47: procedure doutfyls(a)
48: local lst, x, i
49: lst := []
50: i := 2
51: while \a[i] do {
52: if x := llu(a[i],lst) then # already in list
53: lst |||:= [[a[i],lst[x][2]]]
54: else # not in list
55: if a[i] == "-" then # standard out
56: lst |||:= [[a[i],&output]]
57: else # a new file
58: if not (x := open(a[i],"w")) then
59: stop("Cannot open ",a[i]," for output")
60: else lst |||:= [[a[i],x]]
61: i +:= 1
62: }
63: return lst
64: end
65:
66: # llu - lookup file name in output file list
67: #
68: procedure llu(str,lst)
69: local i
70: i := 1
71: while \lst[i] do {
72: if \lst[i][1] == str then return i
73: i +:= 1
74: }
75: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.