-
Notifications
You must be signed in to change notification settings - Fork 0
/
prettify_commandgen.awk
executable file
·60 lines (57 loc) · 2.52 KB
/
prettify_commandgen.awk
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
#!/usr/bin/awk -f
#
# Retrieves script names from flow.txt to compile the runfile
#
# pass flow.txt as argument:
# awk -f prettify_commandgen.awk flow.txt
BEGIN {
FS = "\t"
while (getline < "metadata.txt"){
if ($1 == "Title"){title = $2}
if ($1 == "Title file as"){titlefa = $2}
if ($1 == "Author"){author = $2}
if ($1 == "Author file as"){authorfa = $2}
if ($1 == "Modified"){modified = $2}
if ($1 == "Unique ID"){uniqueid = $2}
if ($1 == "Ebook filename"){ebookname = $2}
if ($1 == "Censorship level"){censor_level = $2}
}
runfile = "prettify_run.sh"
ORS = " "
print "awk -f prettify.awk censor_level=" censor_level " " > runfile
FS = "\""
}
/\<CallScript\>/{
print $2 ".txt" > runfile
}
# skip over bad ending files
/\<GChoiceMode\>/{
do{
hangingOpenBrackets = 0
hangingOpenBrackets += gsub("{","")
hangingOpenBrackets -= gsub("}","")
getline
} while (hangingOpenBrackets)
}
END {
print "*tips*txt" > runfile
ORS = "\n"
print "" > runfile
print "sed -i -e 's/TITLE HERE/" title "/g' book-template/item/standard.opf book-template/item/xhtml/*" > runfile
print "sed -i -e 's/TITLE FILEAS HERE/" titlefa "/g' book-template/item/standard.opf" > runfile
print "sed -i -e 's/AUTHOR HERE/" author "/g' book-template/item/standard.opf book-template/item/xhtml/*" > runfile
print "sed -i -e 's/AUTHOR FILEAS HERE/" authorfa "/g' book-template/item/standard.opf" > runfile
print "sed -i -e 's/UNIQUE ID HERE/" uniqueid "/g' book-template/item/standard.opf" > runfile
print "sed -i -e 's/MODIFIED HERE/" modified "/g' book-template/item/standard.opf" > runfile
print "sed -i -e '/INSERT HERE/r book-template/item/navigation-documents.txt' -e '/INSERT HERE/d' book-template/item/navigation-documents.xhtml" > runfile
print "rm book-template/item/navigation-documents.txt" > runfile
print "sed -i -e '/INSERT HERE/r book-template/item/xhtml/p-toc.txt' -e '/INSERT HERE/d' book-template/item/xhtml/p-toc.xhtml" > runfile
print "rm book-template/item/xhtml/p-toc.txt" > runfile
print "sed -i -e '/INSERT HERE/r book-template/item/xhtml/p-001.txt' -e '/INSERT HERE/d' book-template/item/xhtml/p-001.xhtml" > runfile
print "rm book-template/item/xhtml/p-001.txt" > runfile
print "sed -i -e '/INSERT HERE/r book-template/item/xhtml/tips.txt' -e '/INSERT HERE/d' book-template/item/xhtml/tips.xhtml" > runfile
print "rm book-template/item/xhtml/tips.txt" > runfile
print "cd book-template\nzip -X0 ../" ebookname " mimetype\nzip -Xr ../" ebookname " *" > runfile
print "cd ..\nrm book-template -rf" > runfile
system("chmod +x " runfile)
}