diff --git a/Makefile b/Makefile index 1b5e8b4b..d4e78e01 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ tests-zsh: clean ./"game shell (1).sh" -Zdq -c 'gsh systemconfig; for _ in $$(seq 42); do gsh goal|cat; gsh test --abort; gsh auto --abort; done; gsh stat' clean: - rm -rf i18n/*~ locale gameshell.tgz gameshell.sh gameshell-save.sh scripts/boxes-data.awk + rm -rf i18n/*~ locale gameshell.tgz gameshell.sh gameshell-save*.sh scripts/boxes-data.awk rm -rf .bin .config .sbin .var World rm -rf "game shell"* diff --git a/doc/gameshell.md b/doc/gameshell.md index e4bc2c2e..5be9dfa8 100644 --- a/doc/gameshell.md +++ b/doc/gameshell.md @@ -139,9 +139,9 @@ You can customize the archive with the following options GameShell will ask for the player's name and email. This is useful in the classroom as it makes it easier to link a game to the corresponding student. (The player can run the archive in anonymous mode with the `-A` option.) -* `-p PASSWORD`: you can choose the admin password for the archive. This is - also useful in the classroom as we might not want the students to learn of - this password. :) +* `--password PASSWORD`: you can choose the admin password for the archive. + This is also useful in the classroom as we might not want the students to + learn of this password. :) * `-a`: keep the automatic scripts. Some missions come with a script that automagically completes the missions. By default, those scripts are **not** included in the archive. Use `-a` if you want to keep them. diff --git a/i18n/start-help/en.txt b/i18n/start-help/en.txt index 8f2c93fe..0904d250 100644 --- a/i18n/start-help/en.txt +++ b/i18n/start-help/en.txt @@ -9,12 +9,22 @@ options: -C continue current game (if relevant) -R reset game + -F do not check for more recent savefiles, force using the given archive -G do not use gettext for translation (everything will be in English) -L ... set LANGUAGE variable (ex: -L fr:it:en) On non GNU systems, set the variable LC_MESSAGES to a valid locale. + --simple-savefiles + the savefile is obtained by adding a "-save" suffix, + each savefile overwrites the previous one + --index-savefiles + savefiles are numbered so that all savefiles are kept + --overwrite-savefiles + the savefile overwrite the initial GameShell file + (you can use option -R to start a new game from the start) + -B use bash -Z use zsh diff --git a/i18n/start-help/fr.txt b/i18n/start-help/fr.txt index 56f59335..98cfa676 100644 --- a/i18n/start-help/fr.txt +++ b/i18n/start-help/fr.txt @@ -9,12 +9,24 @@ options : -C continue la partie en cours (si pertinent) -R recommence une partie du début + -F ne vérifie pas l'existence de fichiers de sauvegarde plus récents, + force l'utilisation de l'archive donnée -G désactive gettext pour les traductions (tout sera en Anglais) -L initialise la variable LANGUAGE (ex : -L fr:it:en) Pour les systèmes non GNU, initialisez la variable LC_MESSAGES avec une locale valide. + --simple-savefiles + le fichier de sauvegarde est obtenu en ajoutant un suffix "-save", + chaque fichier de sauvegarde remplace le précédent + --index-savefiles + les fichiers de sauvegarde sont numérotés pour que toutes les + sauvegardes soient conservées + --overwrite-savefiles + le fichier de sauvegarde remplace l'instance initial de GameShell + (on peut utiliser l'option -R pour lancer une partie à partir du début) + -q mode silencieux : n'affiche pas les messages d'information -n mode noir et blanc : n'utilise pas les séquences ANSI -c CMD donne cette commande à GameShell (pour faire des tests) diff --git a/lib/gsh.sh b/lib/gsh.sh index 8e177207..5f8e1fc5 100644 --- a/lib/gsh.sh +++ b/lib/gsh.sh @@ -517,9 +517,10 @@ __save() { GSH_SAVEFILE="$GSH_SAVEFILE-save.$EXT" ;; - "same") + "overwrite") GSH_SAVEFILE=$GSH_EXEC_DIR/$GSH_EXEC_FILE ;; + esac fi _gsh_save "$GSH_SAVEFILE" diff --git a/lib/header.sh b/lib/header.sh index 4597b673..023371ee 100644 --- a/lib/header.sh +++ b/lib/header.sh @@ -81,6 +81,9 @@ do elif [ "$arg" = "-K" ] then KEEP_DIR="true" + elif [ "$arg" = "-F" ] + then + GSH_FORCE="true" elif [ "$arg" = "-h" ] then # used to avoid checking for more recent files @@ -98,7 +101,7 @@ GSH_NAME=${GSH_NAME%-save*} GSH_NAME=$(basename "$GSH_NAME") -if [ "$GSH_HELP" != "true" ] +if [ "$GSH_HELP" != "true" ] && [ "$GSH_FORCE" != "true" ] then LAST_SAVEFILE=$(ls "$GSH_EXEC_DIR/$GSH_NAME-save"*".$EXT" 2>/dev/null | sort | tail -n 1) diff --git a/start.sh b/start.sh index 194c3b41..4f001e22 100755 --- a/start.sh +++ b/start.sh @@ -29,15 +29,37 @@ display_help() { } -# possible values: index, simple, same -export GSH_SAVEFILE_MODE=simple +# possible values: index, simple (default), overwrite +export GSH_SAVEFILE_MODE="simple" export GSH_AUTOSAVE=1 export GSH_COLOR="OK" GSH_MODE="ANONYMOUS" +# if GSH_NO_GETTEXT is non-empty, gettext won't be used anywhere, the only language will thus be English +# export GSH_NO_GETTEXT=1 # DO NOT CHANGE OR REMOVE THIS LINE, it is used by utils/archive.sh RESET="" -while getopts ":hnPdDACRXUVqGL:KBZc:" opt +# hack to parse long options --index-savefiles --overwrite-savefiles --simple-savefiles +# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options +_long_option=0 +while getopts ":hnPdDACRXUVqGL:KBZc:F-:" opt do + if [ "$opt" = "-" ] + then + opt="${OPTARG%%=*}" # extract long option name + OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty) + OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + _long_option=1 + fi + case $opt in + index-savefiles) + GSH_SAVEFILE_MODE=index + ;; + simple-savefiles) + GSH_SAVEFILE_MODE=simple + ;; + overwrite-savefiles) + GSH_SAVEFILE_MODE=overwrite + ;; h) display_help exit 0 @@ -98,10 +120,14 @@ do c) GSH_COMMAND=$OPTARG ;; - K) + K|F) : # used by the self-extracting archive ;; *) + if [ "$_long_option" = "1" ] + then + OPTARG="-$opt" + fi echo "$(eval_gettext "Error: invalid option: '-\$OPTARG'")" >&2 exit 1 ;; diff --git a/utils/archive.sh b/utils/archive.sh index 775c7baa..e2ff4a92 100755 --- a/utils/archive.sh +++ b/utils/archive.sh @@ -9,22 +9,27 @@ $(basename "$0") [OPTIONS] [MISSIONS] create a GameShell standalone archive options: - -h this message + -h this message - -p ... choose password for admin commands - -P use the "passport mode" by default when running GameShell - -A use the "anonymous mode" by default when running GameShell - -L LANGS only keep the given languages (ex: -L 'en*,fr') - -E only keep english as a language, not generating any ".mo" file - and not using gettext + --password ... choose password for admin commands + -P use the "passport mode" by default when running GameShell + -A use the "anonymous mode" by default when running GameShell + -L LANGS only keep the given languages (ex: -L 'en*,fr') + -E only keep english as a language, not generating any ".mo" file + and not using gettext - -N ... name of the archive / top directory (default: "gameshell") + -N ... name of the archive / top directory (default: "gameshell") - -a keep 'auto.sh' scripts for missions that have one - -t keep 'test.sh' scripts for missions that have one - -z keep tgz archive + --simple-savefiles + --index-savefiles + --overwrite-savefiles + choose default savefile mode - -v show the list of mission directories as they are being processed + -a keep 'auto.sh' scripts for missions that have one + -t keep 'test.sh' scripts for missions that have one + -z keep tgz archive + + -v show the list of mission directories as they are being processed EOH } @@ -57,19 +62,39 @@ KEEP_PO=0 # this is set to 1 if we generate .mo files. Setting it to 1 here LANGUAGES="" VERBOSE= -while getopts ":hp:N:atPzL:Ev" opt +# hack to parse long option --password +# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options +_long_option=0 +while getopts ":hp:N:atPzL:Ev-:" opt do + if [ "$opt" = "-" ] + then + opt="${OPTARG%%=*}" # extract long option name + OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty) + OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + _long_option=1 + fi + case $opt in h) display_help exit 0; ;; - p) + password) ADMIN_PASSWD=$OPTARG ;; N) NAME=$OPTARG ;; + index-savefiles) + GSH_SAVEFILE_MODE=index + ;; + simple-savefiles) + GSH_SAVEFILE_MODE=simple + ;; + overwrite-savefiles) + GSH_SAVEFILE_MODE=overwrite + ;; a) KEEP_AUTO=1 ;; @@ -95,6 +120,10 @@ do VERBOSE=1 ;; *) + if [ "$_long_option" = "1" ] + then + OPTARG="-$opt" + fi echo "invalid option: '-$OPTARG'" >&2 exit 1 ;; @@ -295,6 +324,12 @@ case $DEFAULT_MODE in ;; esac +# choose default savefile mode +if [ -n "$GSH_SAVEFILE_MODE" ] +then + sed-i "s/^export GSH_SAVEFILE_MODE=.*$/export GSH_SAVEFILE_MODE='$GSH_SAVEFILE_MODE'/" "$GSH_ROOT/start.sh" +fi + # record version if git rev-parse --is-inside-work-tree >/dev/null 2>&1 then