summaryrefslogtreecommitdiff
path: root/web/noweb/src/lib/unmarkup
blob: 761fc148979d2fd99fff8cd27b2e59ab3d506d7c (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
#!/bin/sh
#
# Copyright 1991 by Norman Ramsey.  All rights reserved.
# See file COPYRIGHT for more information.

nawk '
BEGIN {
  rcsid = "$Id: unmarkup,v 1.20 2008/10/06 01:03:05 nr Exp $"
  rcsname = "$Name:  $"
  firstdoc = 1
}
/^@begin docs / { if (!firstdoc) printf "@ "; firstdoc = 0 }
/^@begin code / { code = 1 }
/^@end [cd]o[dc][es] / { 
		code = 0
		if (dangling_text) printf "\n"
		dangling_text = 0
                printf "%s", deflines
                if (defline != "") printf "%s\n", defline
                deflines = "" ; defline = ""
               }
/^@defn / { printf "<<%s>>=", substr($0,7) }
/^@text $/ {next}
/^@text / { 
  gsub("<<", "@<<");
  gsub(">>", "@>>");
  if (!(code || quoting)) {
    gsub(/\[\[/, "@[[");
    gsub(/\]\]/, "@]]");
  }
  printf "%s", substr($0,7) 
  dangling_text = 1
}
/^@quote$/    { printf("[["); dangling_text = 1; quoting = 1 }
/^@endquote$/ { printf("]]"); dangling_text = 1; quoting = 0 }
/^@nl$/       { printf "\n"; dangling_text = 0}

/^@index defn / {
     if (defline == "") defline = "@ %def"
     defline = defline " " substr($0, 13)
}
/^@index nl$/ {
     deflines = deflines defline "\n"
     defline = ""
}
/^@use / { printf "<<%s>>", substr($0,6)
           dangling_text = 1
         }' "$@" | sed 's/^@ $/@/'