comparison src/name/blackcap/osdep/Osdep.kt @ 1:5ea54efa8e45

Commit un-checked-in stuff.
author David Barts <n5jrn@me.com>
date Tue, 14 Apr 2020 11:46:23 -0700
parents 895aa9a8d628
children
comparison
equal deleted inserted replaced
0:895aa9a8d628 1:5ea54efa8e45
45 val options = Options().apply { 45 val options = Options().apply {
46 addOption("?", "help", false, "Print this help message.") 46 addOption("?", "help", false, "Print this help message.")
47 addOption("c", "clean", false, "Clean instead of copying.") 47 addOption("c", "clean", false, "Clean instead of copying.")
48 addOption("t", "type", true, "Specify OS type (default ${ostype}).") 48 addOption("t", "type", true, "Specify OS type (default ${ostype}).")
49 } 49 }
50 var cmdLine: CommandLine? = null 50 val cmdLine: CommandLine? = try {
51 try { 51 DefaultParser().parse(options, args)
52 cmdLine = DefaultParser().parse(options, args)
53 } catch (e: ParseException) { 52 } catch (e: ParseException) {
54 System.err.format("%s: %s%n", MYNAME, e.message) 53 System.err.format("%s: %s%n", MYNAME, e.message)
55 System.exit(2) 54 System.exit(2)
55 null
56 } 56 }
57 57
58 if (cmdLine!!.hasOption("help")) { 58 if (cmdLine!!.hasOption("help")) {
59 val usage = MYNAME + " [--help] [--clean] [--type=type] directory [...]" 59 val usage = MYNAME + " [--help] [--clean] [--type=type] directory [...]"
60 HelpFormatter().printHelp(usage, options, false); 60 HelpFormatter().printHelp(usage, options, false);
61 System.exit(0); 61 System.exit(0);
62 } 62 }
63 63
64 val clOstype = cmdLine!!.getOptionValue("type") 64 val clOstype = cmdLine.getOptionValue("type")
65 if (clOstype != null) { 65 if (clOstype != null) {
66 ostype = clOstype 66 ostype = clOstype
67 } 67 }
68 68
69 for (arg in cmdLine.args) { 69 for (arg in cmdLine.args) {
72 } catch (e: Exception) { 72 } catch (e: Exception) {
73 handle(e, "cannot walk '${arg}'") 73 handle(e, "cannot walk '${arg}'")
74 } 74 }
75 } 75 }
76 76
77 val process = if (cmdLine!!.hasOption("clean")) ::clean else ::copy 77 val process = if (cmdLine.hasOption("clean")) ::clean else ::copy
78 files.forEach { 78 files.forEach {
79 process(it.key, it.value) 79 process(it.key, it.value)
80 } 80 }
81 System.exit(if (errors == 0) 0 else 1) 81 System.exit(if (errors == 0) 0 else 1)
82 } 82 }
97 if (dot1 <= 0) { 97 if (dot1 <= 0) {
98 return 98 return
99 } 99 }
100 val base = path.substring(0 .. (dot1 - 1)) 100 val base = path.substring(0 .. (dot1 - 1))
101 val type = path.substring((dot1 + 1) .. (dot2 - 1)) 101 val type = path.substring((dot1 + 1) .. (dot2 - 1))
102 println("base=${base}, type=${type}") /* debug */
103 val fset = files[base] 102 val fset = files[base]
104 if (fset != null) { 103 if (fset != null) {
105 fset.add(type) 104 fset.add(type)
106 } else { 105 } else {
107 files[base] = HashSet<String>().apply { add(type) } 106 files[base] = HashSet<String>().apply { add(type) }