Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (47 sloc) 1.239 kb
9ca02ae @dchenbecker Fixed some quotes and started a script that will automate it.
dchenbecker authored
1 import scala.io.Source
2
3 sealed abstract class State
4 case object Normal extends State
5 case object InListing extends State
34b6bf8 @dchenbecker Minor fix to quote handling in the script.
dchenbecker authored
6 case object InQuotes extends State
9ca02ae @dchenbecker Fixed some quotes and started a script that will automate it.
dchenbecker authored
7
8 var state: State = Normal
9 var insetDepth = 0
10 for (file <- args) {
11 val outputFile = new java.io.FileWriter(file + "-fixed")
12
13 for ((line,index) <- Source.fromFile(file).getLines.zipWithIndex) {
14 //print (file,index,line)
15 var output = line
16 state match {
17 case Normal if line.matches("""(?s)^\\begin_inset listings.*""") => {
18 //printf("Found listing at %s : %d\n", file, index + 1)
19 state = InListing
20 insetDepth = 1
21 }
22 case InListing => {
23
24 if (line.matches("""(?s)\\begin_inset Quotes e[lr]d.*""")) {
25 printf("Bad quotes at %s : %d\n", file, index + 1)
34b6bf8 @dchenbecker Minor fix to quote handling in the script.
dchenbecker authored
26 output = "\"\n"
27 state = InQuotes
28 } else {
29 if (line.matches("""(?s)\\begin_inset.*""")) {
30 insetDepth += 1
31 }
32 if (line.matches("""(?s)\\end_inset.*""")) {
33 insetDepth -= 1
34 }
35 if (insetDepth == 0) {
9ca02ae @dchenbecker Fixed some quotes and started a script that will automate it.
dchenbecker authored
36 state = Normal
34b6bf8 @dchenbecker Minor fix to quote handling in the script.
dchenbecker authored
37 }
9ca02ae @dchenbecker Fixed some quotes and started a script that will automate it.
dchenbecker authored
38 }
39 }
34b6bf8 @dchenbecker Minor fix to quote handling in the script.
dchenbecker authored
40 case InQuotes if line.matches("""(?s)\\end_inset.*""") => {
41 output = ""
42 state = InListing
43 }
44 case InQuotes => output = ""
9ca02ae @dchenbecker Fixed some quotes and started a script that will automate it.
dchenbecker authored
45 case Normal =>
46 // ok
47 }
48 outputFile.write(output)
49 }
50
51 outputFile.close()
52 }
Something went wrong with that request. Please try again.