summaryrefslogtreecommitdiff
path: root/web/noweb/src/shell/noweave.nr
blob: ba67721748cdf599559fee31d354bc5afe5c0335 (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
#!/bin/sh
#
# Copyright 1991, 1992, 1993 by Norman Ramsey.  All rights reserved.
# See file COPYRIGHT for more information.
# options: -l == use LaTeX  -x == generate LaTeX cross-reference goo

LIB=|LIBDIR|
latex=0 tex=1 xref=0
args=
markopts=

for i do
	case $i in
	-l) latex=1 ; tex=0 ;;
        -n) latex=0 ; tex=0 ;;
        -x) xref=1 ; if [ $tex -eq 1 ]; then tex=0 ; latex=1; fi ;;
        -t*) markopts="$markopts $i" ;;
        -*) echo "$0: Unrecognized argument '$i'" 1>&2 ; exit ;;
        *)  arg="$arg $i" ;;
	esac
done

if [ $tex -eq 1 ]; then echo -n \\ ; echo input nwmac; fi
if [ $latex -eq 1 ]; then
    echo -n \\; echo "documentstyle[noweb]{article}"; 
    for i in oddsidemargin evensidemargin; do
        echo -n \\; echo -n "advance" ; echo -n \\ ; echo "$i -0.4in"
    done
    echo -n \\ ; echo 'begin{document}'
fi

if [ $xref -eq 0 ]; then
  $LIB/markup $markopts $arg 
else
  $LIB/markup $markopts $arg | $LIB/noxref
fi | nawk '
BEGIN		{ code=0 ; quoting=0 }
/^@begin code/ 	{ code=1 ; printf "\\begincode{%s}\n", substr($0, 13) }
/^@begin docs/ 	{          printf "\\begindocs{%s}\n", substr($0, 13) }
/^@end code/   	{ code=0 ; printf "\\endcode\n" }
/^@end docs/   	{          printf "\\enddocs\n" }
/^@text / 	{ line = substr($0, 7)
    		  if (code || quoting) {
      		    gsub("\\\\", "\\\\", line)
      		    gsub("{", "\\{", line) ; gsub("}", "\\}", line)
    		  }
    		  printf "%s", line
		}
/^@nl$/   	{ printf "\n" }
/^@defn / 	{ name = substr($0, 7)
    		  printf "\\moddef{%s}\\%sendmoddef", convquotes(name), defns[name]
                  defns[name] = "plus"
		}
/^@use / 	{ printf "\\LA{}%s\\RA{}", convquotes(substr($0, 6)) }
/^@quote$/ 	{ quoting = 1 ; printf "\\code{}" }
/^@endquote$/ 	{ quoting = 0 ; printf "\\edoc{}" }
/^@file / 	{ printf "\\filename{%s}\n", substr($0, 7) }
/^@literal / 	{ printf "%s", substr($0, 10) }
function convquotes(s, r, i) {
  r = ""
  while (i = index(s, "[[")) {
    r = r substr(s, 1, i-1) "\\code{}"
    s = substr(s, i+2)
    if (i = match(s, "\\]\\]+")) {
      r = r substr(s, 1, i-1+RLENGTH-2) "\\edoc{}"
      s = substr(s, i+RLENGTH)
    } else {
      r = r s "\\edoc{}"
      s = ""
    }
  }
  return r s
}'
status=$?
if [ $tex -eq 1 ]; then echo -n \\ ; echo bye; fi
if [ $latex -eq 1 ]; then echo -n \\; echo 'end{document}' ; fi
exit $status