diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-11 11:49:38 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-11 11:49:38 +0200 |
| commit | a75c732b88bd27e351368b1a7b0c111df5488be1 (patch) | |
| tree | 27ca78e051bef68f074a1780de6f437a9226e29a /alg | |
| parent | 500da620557e19c334882e50ffbd92d6e53a4b76 (diff) | |
| parent | 8734897667bdf68307fc2f57bf0db4c10e3dec8d (diff) | |
| download | scripts-a75c732b88bd27e351368b1a7b0c111df5488be1.tar.gz scripts-a75c732b88bd27e351368b1a7b0c111df5488be1.zip | |
Merge branch 'master' of tronto.net:scripts
Diffstat (limited to '')
| -rwxr-xr-x | alg | 126 |
1 files changed, 122 insertions, 4 deletions
| @@ -6,7 +6,10 @@ | |||
| 6 | # Example: alg c UBL E - prints out all first algs for UBL-FDR-* | 6 | # Example: alg c UBL E - prints out all first algs for UBL-FDR-* |
| 7 | 7 | ||
| 8 | usage() { | 8 | usage() { |
| 9 | echo "Usage: alg [[edit] (c|e|w|x) [buffer] (1 letter|2 letters)]" | 9 | echo "Usage:" |
| 10 | echo "alg" | ||
| 11 | echo "alg edit (c|e|w|x) [buffer] (1 letter|2 letters)" | ||
| 12 | echo "alg export (c|e|w|x|all)" | ||
| 10 | } | 13 | } |
| 11 | 14 | ||
| 12 | default_editor=vi | 15 | default_editor=vi |
| @@ -178,13 +181,128 @@ showall_x() { | |||
| 178 | done | 181 | done |
| 179 | } | 182 | } |
| 180 | 183 | ||
| 184 | export_csv_c() { | ||
| 185 | sorted_letters="d b c l n p m k z f j v w g a o e s r u t" | ||
| 186 | buffer="$cbuffer" | ||
| 187 | f="$basedir/corners/$buffer" | ||
| 188 | printf '"",' | ||
| 189 | for first in $sorted_letters; do | ||
| 190 | printf '"%s",' "$(corner $first)" | ||
| 191 | done | ||
| 192 | printf '\n' | ||
| 193 | for first in $sorted_letters; do | ||
| 194 | firstpiece="$(corner $first)" | ||
| 195 | printf '"%s",' "$firstpiece" | ||
| 196 | for second in $sorted_letters; do | ||
| 197 | g="$f/$firstpiece/$(corner $second)" | ||
| 198 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 199 | printf '"",' | ||
| 200 | else | ||
| 201 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 202 | fi | ||
| 203 | done | ||
| 204 | printf '\n' | ||
| 205 | done | ||
| 206 | } | ||
| 207 | |||
| 208 | export_csv_e() { | ||
| 209 | sorted_letters="d c b n l p m k z f v j w g i a o e t r u s" | ||
| 210 | buffer="$ebuffer" | ||
| 211 | f="$basedir/edges/$buffer" | ||
| 212 | printf '"",' | ||
| 213 | for first in $sorted_letters; do | ||
| 214 | printf '"%s",' "$(edge $first)" | ||
| 215 | done | ||
| 216 | printf '\n' | ||
| 217 | for first in $sorted_letters; do | ||
| 218 | firstpiece="$(edge $first)" | ||
| 219 | printf '"%s",' "$firstpiece" | ||
| 220 | for second in $sorted_letters; do | ||
| 221 | g="$f/$firstpiece/$(edge $second)" | ||
| 222 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 223 | printf '"",' | ||
| 224 | else | ||
| 225 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 226 | fi | ||
| 227 | done | ||
| 228 | printf '\n' | ||
| 229 | done | ||
| 230 | } | ||
| 231 | |||
| 232 | export_csv_w() { | ||
| 233 | sorted_letters="b d c n l p m k x z f v j w g i a o e t r u s" | ||
| 234 | buffer="$wbuffer" | ||
| 235 | f="$basedir/wings/$buffer" | ||
| 236 | printf '"",' | ||
| 237 | for first in $sorted_letters; do | ||
| 238 | printf '"%s",' "$(wing $first)" | ||
| 239 | done | ||
| 240 | printf '\n' | ||
| 241 | for first in $sorted_letters; do | ||
| 242 | firstpiece="$(wing $first)" | ||
| 243 | printf '"%s",' "$firstpiece" | ||
| 244 | for second in $sorted_letters; do | ||
| 245 | g="$f/$firstpiece/$(wing $second)" | ||
| 246 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 247 | printf '"",' | ||
| 248 | else | ||
| 249 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 250 | fi | ||
| 251 | done | ||
| 252 | printf '\n' | ||
| 253 | done | ||
| 254 | } | ||
| 255 | |||
| 256 | export_csv_x() { | ||
| 257 | sorted_letters="d c b l n p m k x z f j v w g i a o e s r u t" | ||
| 258 | buffer="$xbuffer" | ||
| 259 | f="$basedir/xcenters/$buffer" | ||
| 260 | printf '"",' | ||
| 261 | for first in $sorted_letters; do | ||
| 262 | printf '"%s",' "$(xcenter $first)" | ||
| 263 | done | ||
| 264 | printf '\n' | ||
| 265 | for first in $sorted_letters; do | ||
| 266 | firstpiece="$(xcenter $first)" | ||
| 267 | printf '"%s",' "$firstpiece" | ||
| 268 | for second in $sorted_letters; do | ||
| 269 | g="$f/$firstpiece/$(xcenter $second)" | ||
| 270 | if [ "$first" = "$second" ] || [ ! -f "$g" ]; then | ||
| 271 | printf '"",' | ||
| 272 | else | ||
| 273 | printf '"%s",' "$(head -n 1 "$g")" | ||
| 274 | fi | ||
| 275 | done | ||
| 276 | printf '\n' | ||
| 277 | done | ||
| 278 | } | ||
| 279 | |||
| 181 | run() { | 280 | run() { |
| 182 | if [ "$1" = "edit" ]; then | 281 | case "$1" in |
| 282 | edit) | ||
| 183 | editor="$default_editor" | 283 | editor="$default_editor" |
| 184 | shift | 284 | shift |
| 185 | else | 285 | ;; |
| 286 | export) | ||
| 287 | if [ "$2" = "all" ]; then | ||
| 288 | mkdir -p bldsheets | ||
| 289 | export_csv_c > bldsheets/corners.csv | ||
| 290 | export_csv_e > bldsheets/edges.csv | ||
| 291 | export_csv_w > bldsheets/wings.csv | ||
| 292 | export_csv_x > bldsheets/xcenters.csv | ||
| 293 | echo "Sheets exported to bldsheets" | ||
| 294 | return | ||
| 295 | fi | ||
| 296 | #TODO add option for alternative buffers | ||
| 297 | [ "$2" != "c" ] && [ "$2" != "e" ] && \ | ||
| 298 | [ "$2" != "w" ] && [ "$2" != "x" ] && usage && return | ||
| 299 | export_csv_$2 | ||
| 300 | return | ||
| 301 | ;; | ||
| 302 | *) | ||
| 186 | editor="cat" | 303 | editor="cat" |
| 187 | fi | 304 | ;; |
| 305 | esac | ||
| 188 | 306 | ||
| 189 | type="$1" | 307 | type="$1" |
| 190 | if [ -z "$3" ]; then | 308 | if [ -z "$3" ]; then |
