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