|
|
1.1 ! root 1: # CPPP(1) ! 2: # ! 3: # Expand C conditionals ! 4: # ! 5: # Ralph E. Griswold ! 6: # ! 7: # Last modified 8/14/84 ! 8: # ! 9: ! 10: procedure main(x) ! 11: local s, line, name, alist, dlist, ulist, process, ptype, delete ! 12: dlist := [] # list of things to be defined ! 13: ulist := [] # list of things to be undefined ! 14: delete := string # efficient no-op ! 15: every s := !x do # process options ! 16: if s == "-d" then alist := dlist ! 17: else if s == "-u" then alist := ulist ! 18: else put(\alist,s) | stop("usage: [-d names ] [-u names ]") ! 19: process := write # accept by default ! 20: name := [] # stack of defined names ! 21: ptype := [write] # stack of processes ! 22: while line := read() do ! 23: if line[1] ~== "#" then process(line) ! 24: else if line ? ! 25: (conditional("define" | "undef") == (!dlist | !ulist)) then next ! 26: else if line ? (push(name,conditional("ifdef"))) then { ! 27: push(ptype,process) ! 28: if name[1] == !dlist then process := write ! 29: else if name[1] == !ulist then process := delete ! 30: else process(line) ! 31: } ! 32: else if line ? conditional("endif") then { ! 33: if not(name[1] == (!dlist | !ulist)) then process(line) ! 34: pop(name) ! 35: process := pop(ptype) ! 36: } ! 37: else if line ? (push(name,conditional("ifndef"))) then { ! 38: push(ptype,process) ! 39: if name[1] == !ulist then process := write ! 40: else if name[1] == !dlist then process := delete ! 41: else process(line) ! 42: } ! 43: else if line ? conditional("else") then { ! 44: if name[1] == !dlist then process := delete ! 45: else if name[1] == !ulist then process := write ! 46: else process(line) ! 47: } ! 48: else process(line) ! 49: end ! 50: ! 51: # look for conditional line ! 52: # ! 53: procedure conditional(type) ! 54: static ws ! 55: initial ws := ' \t' ! 56: return { ! 57: ="#" & ! 58: (tab(many(ws)) | "") & ! 59: =type & ! 60: (tab(many(ws)) | "") & ! 61: tab(upto(ws) | 0) ! 62: } ! 63: end ! 64:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.