Sun, 30 Nov 2025 10:14:33 +0100
run compiler detection before trying to correct libdir + check TOOLCHAIN_WSIZE before setting 64bit libdir
| 162 | 1 | package de.unixwork.uwproj; |
| 2 | ||
| 3 | public abstract class AbstractOption { | |
|
165
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
4 | protected String arg = ""; |
| 162 | 5 | protected String desc = ""; |
| 6 | ||
|
165
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
7 | public AbstractOption() { |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
8 | } |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
9 | |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
10 | /** |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
11 | * Indicates whether the option can be overridden by command line arguments. |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
12 | * |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
13 | * @return {@code true} if the option can be overridden, {@code false} otherwise |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
14 | */ |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
15 | public final boolean isOverridable() { |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
16 | return !arg.isEmpty(); |
| 162 | 17 | } |
| 18 | ||
| 19 | /** | |
| 20 | * The name of the argument. | |
| 21 | * | |
| 22 | * @return the argument name | |
| 23 | * @see #getHelpTextArg() | |
| 24 | */ | |
|
165
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
25 | public final String getArg() { |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
26 | return arg; |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
27 | } |
| 162 | 28 | |
| 29 | /** | |
| 30 | * The display text for the argument. | |
| 31 | * <p> | |
| 32 | * This is not necessarily the same as {@link #getArg()}, | |
| 33 | * e.g. for options that have --enable-opt / --disable-opt variants. | |
| 34 | * Also, the help text may show a set of selecatable values or other info. | |
| 35 | * | |
| 36 | * @return the text for the argument to include in the help text | |
| 37 | * @see #getArg() | |
| 38 | */ | |
| 39 | public abstract String getHelpTextArg(); | |
| 40 | ||
| 41 | /** | |
| 42 | * The description of the option. | |
| 43 | * Rarely used, better use {@link #getHelpText()} instead. | |
| 44 | * @return the description without any formatting | |
| 45 | * @see #getHelpText() | |
| 46 | */ | |
|
165
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
47 | public final String getDesc() { |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
48 | return desc; |
|
f4f11f755ee7
add full spectrum config var configurations
Mike Becker <universe@uap-core.de>
parents:
162
diff
changeset
|
49 | } |
| 162 | 50 | |
| 51 | /** | |
| 52 | * The internal variable name for the option. | |
| 53 | * @return the variable name where the option's value will be stored | |
| 54 | */ | |
| 55 | public abstract String getVarName(); | |
| 56 | ||
| 57 | /** | |
| 58 | * Generates help text for the feature option. | |
| 59 | * <p> | |
| 60 | * If no description is available via {@link #getDesc()}, only the option name is generated | |
| 61 | * via {@link #getHelpTextArg()}. Otherwise, the description is added according to the following rules: | |
| 62 | * <p> | |
| 63 | * When the option name does not consume more than 25 characters, the description starts in the same line. | |
| 64 | * Otherwise, a line break is added, first. The description will be placed in a block starting from column | |
| 65 | * 27 to 80 and automatically break when necessary. The description must not contain a single word | |
| 66 | * that is longer than 54 characters, or it will break the layout. | |
| 67 | * | |
| 68 | * @return a help text for terminal output | |
| 69 | */ | |
| 70 | public String getHelpText() { | |
| 71 | final var builder = new StringBuilder(); | |
| 72 | ||
| 73 | // Get the option name and prepend it with indentation | |
| 74 | final var opt = " "+getHelpTextArg(); | |
| 75 | ||
| 76 | // Add option name | |
| 77 | builder.append(opt); | |
| 78 | ||
| 79 | // Stop, if there is no description | |
| 80 | if (desc.isBlank()) return builder.toString(); | |
| 81 | ||
| 82 | // Prepare the description by replacing some unwanted spaces | |
| 83 | final var hdesc = desc.trim() | |
| 84 | .replaceAll("\\r", "") | |
| 85 | .replaceAll("\\t", " "); | |
| 86 | ||
| 87 | // Declare our frame where the description shall be placed | |
| 88 | final int startx = 26; | |
| 89 | final int endx = 80; | |
| 90 | ||
| 91 | // Move to startx (break, if we already past that) | |
| 92 | if (opt.length() >= startx) { | |
| 93 | builder.append("\n"); | |
| 94 | builder.append(" ".repeat(startx)); | |
| 95 | } else { | |
| 96 | builder.append(" ".repeat(startx-opt.length())); | |
| 97 | } | |
| 98 | ||
| 99 | // Append the description keeping the layout intact | |
| 100 | int x = startx; | |
| 101 | for (int i = 0 ; i < hdesc.length() ;) { | |
| 102 | // get the next word and see where we would end | |
| 103 | int s = hdesc.indexOf(' ', i); | |
| 104 | if (s < 0) s = hdesc.length(); | |
| 105 | int n = hdesc.indexOf('\n', i); | |
| 106 | if (n < 0) n = hdesc.length(); | |
| 107 | s = Math.min(s, n); | |
| 108 | int l = s-i; | |
| 109 | if (x + l > endx) { | |
| 110 | // does not fit, break into next line | |
| 111 | builder.append('\n'); | |
| 112 | builder.append(" ".repeat(startx)); | |
| 113 | x = startx; | |
| 114 | } | |
| 115 | // append the word | |
| 116 | builder.append(hdesc, i, s); | |
| 117 | x += l; | |
| 118 | i += l; | |
| 119 | // append the next spaces | |
| 120 | while (i < hdesc.length()) { | |
| 121 | int c = hdesc.charAt(i); | |
| 122 | if (c == ' ') { | |
| 123 | // as long as we don't need to break, add the spaces | |
| 124 | i++; | |
| 125 | x++; | |
| 126 | if (x < endx) builder.append(' '); | |
| 127 | } else if (c == '\n') { | |
| 128 | // if user wants us to break, comply | |
| 129 | i++; | |
| 130 | // if we have still space, just move to the end of the line | |
| 131 | if (x < endx) { | |
| 132 | x = endx; | |
| 133 | } else { | |
| 134 | // otherwise, we need to add an extra blank line | |
| 135 | builder.append('\n'); | |
| 136 | } | |
| 137 | } else { | |
| 138 | // we have found the next word, so continue with the outer loop | |
| 139 | break; | |
| 140 | } | |
| 141 | } | |
| 142 | // break to new line, when spaces moved us outside the frame | |
| 143 | if (x > endx) { | |
| 144 | builder.append('\n'); | |
| 145 | builder.append(" ".repeat(startx)); | |
| 146 | x = startx; | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 150 | return builder.toString(); | |
| 151 | } | |
| 152 | } |