-
Notifications
You must be signed in to change notification settings - Fork 11
/
numberScripts.groovy
46 lines (42 loc) · 1.4 KB
/
numberScripts.groovy
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
// Copyright (c) 2018-2022 Egon Willighagen <[email protected]>
//
// GPL v3
import groovy.xml.XmlSlurper
chapters = "order.txt"
chapterCounters = new HashMap<String,String>();
chapterCounter = 0
def chapterLines = new File(chapters).readLines()
chapterLines.each { String line ->
chapterCounter++
chapterCounters.put(line, "" + chapterCounter)
}
scriptCounter = 0;
tags = [ "code" ]
new File(chapters).eachLine { chapter ->
chapterCounter++
scriptsNames = new HashSet<String>();
currentChapterCounter = chapterCounters.get(chapter)
file = "${chapter}.i.md"
scriptCounter = 0
lines = new File(file).readLines()
scriptInstructionText = ""
inScript = false
lines.each { String line ->
for (tag in tags) {
while (line.contains("<${tag}")) {
xmlStart = line.indexOf("<${tag}")
xmlEnd = line.indexOf("</${tag}>")
fullXML = line.substring(xmlStart, xmlEnd+tag.length()+3)
def scriptInstruction = new XmlSlurper().parseText(fullXML)
scriptname = scriptInstruction.text()
if (!scriptname.isEmpty() && !scriptsNames.contains(scriptname)) {
scriptsNames.add(scriptname)
scriptCounter++
scriptNumber = "${currentChapterCounter}.${scriptCounter}"
println "${scriptname}\t${chapter}\t${scriptNumber}"
}
line = line.substring(0, xmlStart) + line.substring(xmlEnd+tag.length()+3)
}
}
}
}