summaryrefslogtreecommitdiff
path: root/web/noweb/src/icon/texdefs.icn
blob: 13ddd4b12a12d1570cc4cc5ade3b4ea096283031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#line 2 "texdefs.nw"
procedure rcsinfo () 
  return "$Id: texdefs.nw,v 1.18 2008/10/06 01:03:05 nr Exp nr $" ||
         "$Name: v2_12 $"
end
procedure main(args)
  go()
end
#line 10 "texdefs.nw"
procedure postpass(name, arg)
  static kind, idchars, definers, newcommand
  initial { kind := "bogus"; idchars := &letters ++ '@' 
            definers := ["def", "newdimen", "newif", "newcount", "newwrite", 
                         "newbox", "global\\def", "long\\def", "gdef" ]
            newcommand := ["newcommand", "renewcommand"]
          }
  case name of {
    "begin" : arg ? kind := tab(upto(' ')|0)
    "text" : if kind == "code" then arg ? {
        if =("\\" || !definers || "\\") then 
            writedefn("\\" || (tab(many(idchars)) | move(1)))
        else if =("\\" || !newcommand || "{") then 
            writedefn(tab(upto('}')))
       }
  }
  return
end

procedure prepass(name, arg)
  if name == "end" then writedefn(&null) # force newline
end
#line 1 "defns.nw"
procedure go()
  local line
  while line := read() do {
    apply(prepass, line)
    write(line)
    if match("@fatal ", line) then exit(1)
    apply(postpass, line)
  }
end

procedure apply(pass, line)
    line ? (="@" & pass(tab(upto(' ')|0),  if =" " then tab(0) else &null))
end
#line 18 "defns.nw"
procedure writedefn(defn, locl)
  static indextext
  initial indextext := ""
  if /defn then
    *indextext > 0 & 
#line 31 "defns.nw"
{ # write("@index nl")		# don't!
  indextext := ""
}
#line 23 "defns.nw"
  else {
    if *indextext + *defn > 65 then 
#line 31 "defns.nw"
{ # write("@index nl")		# don't!
  indextext := ""
}
#line 25 "defns.nw"
    write(if \locl then "@index localdefn " else "@index defn ", defn)
    indextext ||:= " " || defn
  }
  return
end
#line 35 "defns.nw"
procedure rcsinfo_too () 
  return "$Id: defns.nw,v 1.18 2008/10/06 01:03:05 nr Exp nr $" ||
         "$Name: v2_12 $"
end