]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Simplify cvar-standardize.sh a bit k9er/standardize-cvar-descs 1393/head
authorotta8634 <k9wolf@pm.me>
Fri, 13 Dec 2024 15:54:40 +0000 (23:54 +0800)
committerotta8634 <k9wolf@pm.me>
Fri, 13 Dec 2024 15:54:40 +0000 (23:54 +0800)
Merged lowercase_after_notes into lowercase_after_sentences.
Removed unnecessary \b selector.
Also improved some comments.

qcsrc/tools/cvar-standardize.sh

index 3ac00824463a236d072e90ec6cd1513d281cd5b5..af3717605ef8f467dbaaf5a98fac8cb5292e0af2 100644 (file)
@@ -7,19 +7,19 @@ cd ../..
 CONFIG_EXT=".cfg"
 SCRIPT_IGNORE='\/\/[^\/"]*\bscript-ignore\b[^\/"]*$'
 # can add `// script-ignore` to the end of lines to ignore
-# e.g. g_ca 0 "Clan Arena: played in rounds, once you're dead you're out! The team with survivors wins the round" // script-ignore
+# e.g. set g_ca 0 "Clan Arena: played in rounds, once you're dead you're out! The team with survivors wins the round" // script-ignore
 # the script would otherwise change "Clan" -> "clan", and other changes
-START='^(([[:space:]]*\/\/)?[[:space:]]*\bseta?[[:space:]]+(\w+|"\w+")[[:space:]]+([^"[:space:]]+|"[^"]*")[[:space:]]+")'
+START='^(([[:space:]]*\/\/)?[[:space:]]*seta?[[:space:]]+(\w+|"\w+")[[:space:]]+([^"[:space:]]+|"[^"]*")[[:space:]]+")'
 END='("[[:space:]]*(\/\/.*)?)$'
 # selects all properly formatted set/seta lines, including commented out ones, excluding the script-ignore ones
 LINE_SELECTOR="/$SCRIPT_IGNORE/!"
-# combined regex: /^((\s*\/\/)?\s*\bseta?\s+(\w+|"\w+")\s+([^"\s]+|"[^"]*")\s+").*("\s*(\/\/.*)?)$/, ignoring /\/\/[^\/"]*\bscript-ignore\b[^\/"]*$/
-#                   +~~~~~~~~~--------------~~~~~~~~~~~---~~~~~~~~~~~~~~~~~----+  +-------------+
-#                    +-------+              +--  \1  -+   +---------------+           \digit
-#                       \2                      \4               \3
+# combined regex: /^((\s*\/\/)?\s*seta?\s+(\w+|"\w+")\s+([^"\s]+|"[^"]*")\s+").*("\s*(\/\/.*)?)$/, ignoring /\/\/[^\/"]*\bscript-ignore\b[^\/"]*$/
+#                   +~~~~~~~~~------------~~~~~~~~~~~---~~~~~~~~~~~~~~~~~----+  +-------------+
+#                    +-------+            +---- \1 -+   +---------------+           \digit
+#                       \2                    \4               \3
 # replacements should start with \1, skip \2, \3, and \4, and end with \digit
 
-# this script shouldn't be run on the user's .cfgs, or else it can alter cvars like _cl_name
+# this script shouldn't be run on the user's .cfg files
 
 function hash() {
        git hash-object "$1"
@@ -58,14 +58,6 @@ function uppercase_notes() {
        #         +----+ +------------------------------+   +---------+
        #     \1    \5                  \6                      \7       \8
 }
-function lowercase_after_notes() {
-       #- seta cl_test_cvar "1" "some test cvar (WARNING: Does nothing)"
-       #+ seta cl_test_cvar "1" "some test cvar (WARNING: does nothing)"
-       sed -i -E ":a; ${LINE_SELECTOR}s/$START"'(.*[[:space:]])?(\([A-Z][A-Z\-]*:)[[:space:]]+([A-Z][a-z\-]*[a-z]\b[^)]*\).*)'"$END"'/\1\5\6 \l\7\8/; ta' "$1"
-       # regex: /(.*\s)?(\([A-Z][A-Z\-]*:)\s+([A-Z][a-z\-]*[a-z]\b[^)]*\).*)/
-       #         +----+ +----------------+   +-----------------------------+
-       #     \1    \5           \6                         \7                 \8
-}
 function lowercase_option_first_letter() {
        #- seta cl_test_cvar "1" "some test cvar; \"0\" = Do nothing, \"1\" = Do something"
        #+ seta cl_test_cvar "1" "some test cvar; \"0\" = do nothing, \"1\" = do something"
@@ -89,10 +81,10 @@ function lowercase_after_sentences() {
        #- seta cl_test_cvar "1" "some test cvar; Does nothing"
        #+ seta cl_test_cvar "1" "some test cvar; does nothing"
        # same condition as in lowercase_first_letter()
-       sed -i -E ":a; ${LINE_SELECTOR}s/$START"'(.+[;.?!])[[:space:]]+([A-Z][a-z\-]*[a-z]\b.*)'"$END"'/\1\5 \l\6\7/; ta' "$1"
-       # regex: /(.+[;.?!])\s+([A-Z][a-z\-]*[a-z]\b.*)/
-       #         +--------+   +----------------------+
-       #     \1      \5                  \6             \7
+       sed -i -E ":a; ${LINE_SELECTOR}s/$START"'(.+[:;.?!])[[:space:]]+([A-Z][a-z\-]*[a-z]\b.*)'"$END"'/\1\5 \l\6\7/; ta' "$1"
+       # regex: /(.+[:;.?!])\s+([A-Z][a-z\-]*[a-z]\b.*)/
+       #         +---------+   +----------------------+
+       #     \1      \5                   \6             \7
 }
 
 function check() {
@@ -115,7 +107,6 @@ function check() {
                change_colons_to_equals "$file"
                quote_options "$file"
                uppercase_notes "$file"
-               lowercase_after_notes "$file"
                lowercase_option_first_letter "$file"
                lowercase_first_letter "$file"
                lowercase_after_sentences "$file"