-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhtml_include.awk
More file actions
executable file
·43 lines (38 loc) · 951 Bytes
/
html_include.awk
File metadata and controls
executable file
·43 lines (38 loc) · 951 Bytes
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
#!/usr/bin/awk -f
# this file preprocesses HTML files to put in includes
BEGIN {
# Need to set these variables in ENV
template_path = ENVIRON["TEMPLATE_DIR"]
quiz_path = ENVIRON["QUIZ_DIR"]
}
/<html>/ {
print "<html>"
print "<!-- THIS FILE WAS GENERATED BY A SCRIPT: DO NOT EDIT IT! -->"
next
}
/<!-- *include/ {
file = $2
# file has a forward slash in it, leave it alone:
if(!match($2, /\//)) {
# if file starts with 'quiz' use quiz_path not template_path
if (quiz_path != "" && match($2, /quiz/)) {
file = quiz_path "/" $2
}
else if (template_path != "") {
file = template_path "/" $2
}
}
i = 0
while((getline < file ) > 0 ) {
print $0
i++
}
close(file)
if (i == 0) {
s = "<p>We attempted to read from " file " but failed.</p>"
print s > "/dev/stderr"
print s
}
next
}
{ print }