-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwt2tex.awk
More file actions
162 lines (147 loc) · 3.13 KB
/
Copy pathwt2tex.awk
File metadata and controls
162 lines (147 loc) · 3.13 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
BEGIN {
print "\\documentclass[11pt]{article}"
print "\\setlength{\\oddsidemargin}{0mm} \\setlength{\\evensidemargin}{0mm}"
print "\\setlength{\\textwidth}{160mm} \\setlength{\\topmargin}{-15mm}"
print "\\setlength{\\parindent}{0in} \\setlength{\\textheight}{240mm}"
print "\\begin{document}"
print "\\title{Webtest Reference}\\author{Volker Dobler}\\date{September 2011}"
print "\\maketitle"
print "\\tableofcontents"
print "\\newpage"
}
function escapelt(t) {
gsub(/\\/, "§", t)
gsub(/\$/, "\\$", t)
gsub(/%/, "\\%", t)
gsub(/#/, "\\#", t)
gsub(/&/, "\\&", t)
gsub(/_/, "\\_", t)
gsub(/~/, "\\~", t)
gsub(/{/, "\\{", t)
gsub(/}/, "\\}", t)
gsub(/</, "$<$", t)
gsub(/>/, "$>$", t)
gsub(/\^/, "\\^", t)
gsub(/§/, "$\\backslash$", t)
return t
}
#
# Normal Text. Empahsis by _underscore_ markup,
# Boldfacing by *star* markup. Verbatim by |pipe| markup.
#
# With paragraphs
# - with bulltes. Not no subitems/nesting.
# - second bullets. No paragraphs in lists. But:
# verbatim code (see below allowed)
# o bullets and * are fine too
#
# Enumerations
# # started by a hash mark
# # looks strange but works
#
# No paragraphs inside itemize
# verbatim code indented by 2 spaces
# more text
#
# Decriptions:
# o Template:: the definition goes here
# o Execution:: decription
#
function enditemize() {
if (initemize) {
print "\\end{itemize}"
initemize = 0
}
}
/^## *[-=]*[ \t]*$/ { # Unerlining of section title
next
}
/^##/ { # a new section
t = substr($0, 3)
# t = sub(/^ .*/, "", t)
enditemize()
printf "\\section{%s}\n", escapelt(t)
section = 1
next
}
/^#[\t ]*$/ { # empty comment lines
enditemize()
print ""
next
}
/^#/ { # unindented comments
t = $0 " "
if (section) {
if (substr(t,1,5) == "# - ") {
if (!initemize) {
print "\\begin{itemize}"
}
initemize = 1
printf "\\item %s\n", escapelt(substr(t,5))
} else if (substr(t,1,4) == "# ") {
if (initemize) {
printf "%s\n", escapelt(substr(t,3))
} else {
t = substr(t, 2)
printf "\\verb§%s§\\\\\n", t
}
} else {
enditemize()
gsub(/^#[ \t]*/, "", t)
print escapelt(t)
}
} else {
enditemize()
printf "\\textit{\\small %s}\\\\\n", escapelt(t)
}
next
}
/^[\t ]*$/ { # empty lines
enditemize()
print ""
next
}
func sprefix(t) {
i = 1
n = 0
while(i<length(t)) {
a = substr(substr(t, i), 1, 1)
if (a == " ") { n++ }
else if (a == "\t") { n += 4 }
else return n
i++
}
return n
}
/^\t[ \t]*#/ { # a indented comment
t = substr($0, 2)
s = " "
n = sprefix(t)
while(n>0) {
s = s " "
n--
}
sub(/^\t[ \t]*#/, "", t)
t = escapelt(t)
enditemize()
printf "\\verb+%s+\\textit{\\small %s}\\\\\n", s, t
next
}
/^\t[ \t]*/ { # indented tests
t = substr($0, 2)
gsub(/\t/, " ", t)
printf "\\verb§ %s§\\\\\n", t
next
}
/^[^ \t]/ { # top level stuff of tests
enditemize()
if (section) {
print ""
section = 0
}
printf "\\verb§%s§\\\\\n", $0
next
}
END {
print "\\end{document}"
}