summaryrefslogtreecommitdiff
path: root/web/tweb/bin/web2tex
blob: 78b2994b8ccc78487db624800becc31d89223718 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
BEGIN   { code = 0
          codeno = 0
          codechunkno = 1

          definitions = ":def:|:edef:|:xdef:|:gdef:"\
             ":let:|"\
             ":chardef:|:mathchardef:|"\
             ":newcount:|:countdef:|"\
             ":newdimen:|:dimendef:|"\
             ":newskip:|:skipdef:|"\
             ":newtoks:|:toksdef:|"\
             ":muskipdef:|"\
             ":newif:|"\
             ":newbox:|"\
             ":read:"\
             ":font:"

          print "\\input tweb.sty\n\n"\
           "{\\catcode`\\| = 0 |catcode`|\\ = 12 %\n"\
           "|obeylines |gdef|ttfinish#1\\EDOC{|gobblespace#1|endgroup}}\n\n"\
           "\\makeindexes\n"
}

END   { print "\n"\
              "\\printuserleveldefs\n"\
              "\\printdefs\n"\
              "\\printchunks\n"\
              "\\bye"
}


/^@text %%% *version *= *"/ \
{
      gsub(/^@text %%% *version *= *"/, "")
      gsub(/",/, "")
      printf "\\gdef \\RCSversion {%s}\n", $0
      next
}

/^@file /       { printf "\\def\\filename{%s}\n", substr($0,7) ; next }

/^@quote$/      { printf "\|"  ; next }
/^@endquote$/   { printf "\|"  ; next }

/^@begin code/  {
                  print "\\BEGINCODE"
                  code = 1
                  codeno = $3
                  next
                }
/^@end code/    {
                  print "\\ENDCODE"
                  code = 0
                  next
                }

/^@begin docs/  {
                  printf "\\BEGINDOC\n"
                  next
                }
/^@end docs/    { printf "\\ENDDOC\n" ; next }

/^@defn /       {
                  gsub(/\[\[/, "\\CODE "); gsub(/]]/, "\\EDOC")
                  name = substr($0,7)
                  defs[name] += 1
                  printf "\\noindent\\LA %s\\RA", name

                  if (defs[name] > 1)
                     printf "$+\\!\\!\\equiv$"
                  else
                     printf "$\\equiv$"

                  gsub("@", "\"@", name)
                  printf "\%\n\\chk{\\LA %s\\RA}"\
                         "\n\\nobreak\\medskip", name

                  next
                }
/^@use /        {
                  gsub(/\[\[/, "\\CODE "); gsub(/]]/, "\\EDOC")
                  name = substr($0,6)
                  used[name] = codeno
                  printf "\\LA %s\\RA", name
                  gsub("@", "\"@", name)
                  printf "\%\n\\chk{\\LA %s\\RA}", name, name

                  getline
                  next
                }

/^@literal /    { printf "%s", substr($0, 10) ; next }

/^@nl$/         { printf "\n" ; next }

/^@text /       { line = junk = substr($0,7)
                  indexed = ""
                  found = ""

                  if (code)
                  {
                     while (match(junk, /\\[a-zA-Z@]+/)>0\
                         && substr(junk, 1, RSTART) !~ /%/)
                     {
                        prefix = "\\ddx{"

                        found = substr(junk, RSTART+1, RLENGTH-1)
                        junk = substr(junk, RSTART+RLENGTH)

                        if ( ":" found ":" ~ definitions )
                        {
                           prefix = "\\udx{"
                           match(junk, /\\[a-zA-Z@]+|\\[^a-zA-Z@]/)
                           found = substr(junk, RSTART+1, RLENGTH-1)
                           junk = substr(junk, RSTART+RLENGTH)
                        }

                        if (found != "" && found !~ /[^a-zA-Z@]/)
                        {
                           gsub("@", "\"@", found)
                           indexed = "\%\n"\
                              prefix found\
                              "@\\\\" found "\|N{"\
                              codechunkno "}}" indexed
                        }
                     }
                     printf "\\NO{%d}\\CODE %s\\EDOC%s",\
                         codechunkno++, line, indexed
                  }
                  else
                     printf "%s", line
               }