2018-11-12 18:16:45 +00:00
|
|
|
/*
|
2018-11-13 22:16:49 +00:00
|
|
|
* Copyright (c) 2018 Bevilacqua Joey.
|
2018-11-12 18:16:45 +00:00
|
|
|
*/
|
|
|
|
package ch.usi.inf.atelier.group1
|
|
|
|
|
2018-11-15 15:11:32 +00:00
|
|
|
import ch.usi.inf.atelier.group1.util.Log
|
2018-11-13 22:16:49 +00:00
|
|
|
import java.io.File
|
2018-11-12 18:16:45 +00:00
|
|
|
|
|
|
|
object Main {
|
2018-11-15 15:11:32 +00:00
|
|
|
private lateinit var parser: HtmlParser
|
2018-11-12 18:16:45 +00:00
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun main(args: Array<String>) {
|
|
|
|
|
2018-11-15 15:11:32 +00:00
|
|
|
if (args.isEmpty()) {
|
|
|
|
Log.e("At least one argument is needed")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
parser = HtmlParser(arrayOf("-s", "--singlepage").contains(args[0]))
|
|
|
|
|
2018-11-13 22:16:49 +00:00
|
|
|
args.forEach(this::convert)
|
2018-11-15 15:11:32 +00:00
|
|
|
|
|
|
|
parser.save()
|
2018-11-13 22:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert html files to LaTex files
|
|
|
|
*
|
|
|
|
* @param path of the file (or directory containing files) to be converted
|
|
|
|
*/
|
|
|
|
private fun convert(path: String) {
|
2018-11-15 15:11:32 +00:00
|
|
|
// Ignore the flags
|
|
|
|
if (path.startsWith("-")) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-13 22:16:49 +00:00
|
|
|
val file = File(path)
|
|
|
|
|
|
|
|
if (!file.isDirectory) {
|
2018-11-15 15:11:32 +00:00
|
|
|
parser.parse(file)
|
2018-11-13 22:16:49 +00:00
|
|
|
return
|
2018-11-12 18:16:45 +00:00
|
|
|
}
|
2018-11-13 22:16:49 +00:00
|
|
|
|
|
|
|
// Recursively search for other html files inside a directory
|
|
|
|
file.listFiles().filter { it.name.endsWith(".html") || it.isDirectory }
|
|
|
|
.map { it.path }
|
|
|
|
.forEach(this::convert)
|
2018-11-12 18:16:45 +00:00
|
|
|
}
|
|
|
|
}
|