]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge adjacent identical ifdefs in genmod
authork9er <k9wolf@pm.me>
Mon, 13 Jan 2025 20:50:05 +0000 (20:50 +0000)
committerterencehill <piuntn@gmail.com>
Mon, 13 Jan 2025 20:50:05 +0000 (20:50 +0000)
qcsrc/common/monsters/_mod.inc
qcsrc/common/monsters/_mod.qh
qcsrc/common/mutators/mutator/overkill/_mod.inc
qcsrc/tools/genmod.sh

index 31ff90be61ecab90969ac581b2b3b2a67f886b4f..f2315fc6c2db4d400c8b66aa5cf47146954391ea 100644 (file)
@@ -2,11 +2,7 @@
 #include <common/monsters/all.qc>
 #ifdef SVQC
        #include <common/monsters/sv_monsters.qc>
-#endif
-#ifdef SVQC
        #include <common/monsters/sv_spawn.qc>
-#endif
-#ifdef SVQC
        #include <common/monsters/sv_spawner.qc>
 #endif
 
index 890edfcedee9b680206caf181b20f2df09e70210..73167f84f6d4f65ded968cc6c9167668837b4071 100644 (file)
@@ -2,11 +2,7 @@
 #include <common/monsters/all.qh>
 #ifdef SVQC
        #include <common/monsters/sv_monsters.qh>
-#endif
-#ifdef SVQC
        #include <common/monsters/sv_spawn.qh>
-#endif
-#ifdef SVQC
        #include <common/monsters/sv_spawner.qh>
 #endif
 
index 36dba038598e0a3e1d91ec34663d839795279e38..c42e2054d28eb2e965b20a94b051467dc1cff9df 100644 (file)
@@ -10,7 +10,5 @@
 #endif
 #ifdef SVQC
        #include <common/mutators/mutator/overkill/sv_overkill.qc>
-#endif
-#ifdef SVQC
        #include <common/mutators/mutator/overkill/sv_weapons.qc>
 #endif
index 2c6c3226f8fbba038dfc8d2a0a19eb99f31af6f6..fa2fc438fc031cec38f2da0972fed5318ae18c6f 100755 (executable)
@@ -17,6 +17,44 @@ function hash() {
        git hash-object "$1"
 }
 
+function print_ifdef() {
+       local filename="$1"
+       local pathtofile="$2"
+       local filetype="$3"
+       local outputfile="${MOD}.$filetype"
+       local currentqc="$4"  # Current ifdef QC VM type
+       local nextqc="${5-NONE}" # Next ifdef QC VM type
+
+       # End previous ifdef if required
+       if [ "$currentqc" != "$nextqc" ] \
+       && [ "$currentqc" != "NONE" ]
+       then
+               printf "#endif\n" >> "$outputfile"
+       fi
+
+       # Start new ifdef if required
+       if [ "${nextqc-}" != "NONE" ] \
+       && [ "$currentqc" != "$nextqc" ]
+       then
+               printf "#ifdef %s\n" "$nextqc" >> "$outputfile"
+       fi
+
+       # Update
+       currentqc="$nextqc"
+
+       # Include the file
+       if [ "$currentqc" != "NONE" ]
+       then
+               # Indent if inside an ifdef block
+               printf "\t#include <%s>\n" "$pathtofile$filename" >> "$outputfile"
+       else
+               printf   "#include <%s>\n" "$pathtofile$filename" >> "$outputfile"
+       fi
+
+       # "Return" the current (potentially changed) ifdef QC VM type
+       echo "$currentqc"
+}
+
 function genmod() {
        # use context to work around cmake issue #12619
        CTX="${PWD#"$ROOT"}/"
@@ -35,6 +73,9 @@ function genmod() {
        echo "// $(basename "$0") autogenerated file; do not modify" > "${MOD}.inc"
        echo "// $(basename "$0") autogenerated file; do not modify" > "${MOD}.qh"
 
+       ifdef_inc="NONE" # Can be either CSQC, SVQC, MENUQC, or NONE
+       ifdef_qh="NONE"
+
        # Dr. Jaska: TODO: replace ls with something else
        # LSP note: "Use find instead of ls to better handle non-alphanumeric filenames."
        # Dr. Jaska: find without some configuration would prefix everything with ./ which is likely unwanted
@@ -49,8 +90,8 @@ function genmod() {
                #
                # file.qc into _mod.inc
                # file.qh into _mod.qh
-               if [[ -f "$f"          ]]; then printf "#include <%s>\n" "${CTX}$f"          >> ${MOD}.inc; fi
-               if [[ -f "${f%.qc}.qh" ]]; then printf "#include <%s>\n" "${CTX}${f%.qc}.qh" >> ${MOD}.qh;  fi
+               if [[ -f "$f"          ]]; then ifdef_inc=$(print_ifdef "$f"          "$CTX" "inc" "$ifdef_inc"); fi
+               if [[ -f "${f%.qc}.qh" ]]; then ifdef_qh=$( print_ifdef "${f%.qc}.qh" "$CTX" "qh"  "$ifdef_qh" ); fi
 
                # Print the following template:
                #
@@ -61,19 +102,21 @@ function genmod() {
                # CSQC
                # cl_file.qc into _mod.inc
                # cl_file.qh into _mod.qh
-               if [[ -f "cl_$f"          ]]; then printf "#ifdef %s\n\t#include <%s>\n#endif\n"   CSQC "${CTX}cl_$f"          >> ${MOD}.inc; fi
-               if [[ -f "cl_${f%.qc}.qh" ]]; then printf "#ifdef %s\n\t#include <%s>\n#endif\n"   CSQC "${CTX}cl_${f%.qc}.qh" >> ${MOD}.qh;  fi
+               if [[ -f "cl_$f"          ]]; then ifdef_inc=$(print_ifdef "cl_$f"          "$CTX" "inc" "$ifdef_inc" "CSQC"); fi
+               if [[ -f "cl_${f%.qc}.qh" ]]; then ifdef_qh=$( print_ifdef "cl_${f%.qc}.qh" "$CTX" "qh"  "$ifdef_qh"  "CSQC");  fi
                # SVQC
                # sv_file.qc into _mod.inc
                # sv_file.qh into _mod.qh
-               if [[ -f "sv_$f"          ]]; then printf "#ifdef %s\n\t#include <%s>\n#endif\n"   SVQC "${CTX}sv_$f"          >> ${MOD}.inc; fi
-               if [[ -f "sv_${f%.qc}.qh" ]]; then printf "#ifdef %s\n\t#include <%s>\n#endif\n"   SVQC "${CTX}sv_${f%.qc}.qh" >> ${MOD}.qh;  fi
+               if [[ -f "sv_$f"          ]]; then ifdef_inc=$(print_ifdef "sv_$f"          "$CTX" "inc" "$ifdef_inc" "SVQC"); fi
+               if [[ -f "sv_${f%.qc}.qh" ]]; then ifdef_qh=$( print_ifdef "sv_${f%.qc}.qh" "$CTX" "qh"  "$ifdef_qh"  "SVQC");  fi
                # MENUQC
                # ui_file.qc into _mod.inc
                # ui_file.qh into _mod.qh
-               if [[ -f "ui_$f"          ]]; then printf "#ifdef %s\n\t#include <%s>\n#endif\n" MENUQC "${CTX}ui_$f"          >> ${MOD}.inc; fi
-               if [[ -f "ui_${f%.qc}.qh" ]]; then printf "#ifdef %s\n\t#include <%s>\n#endif\n" MENUQC "${CTX}ui_${f%.qc}.qh" >> ${MOD}.qh;  fi
+               if [[ -f "ui_$f"          ]]; then ifdef_inc=$(print_ifdef "ui_$f"          "$CTX" "inc" "$ifdef_inc" "MENUQC"); fi
+               if [[ -f "ui_${f%.qc}.qh" ]]; then ifdef_qh=$( print_ifdef "ui_${f%.qc}.qh" "$CTX" "qh"  "$ifdef_qh"  "MENUQC");  fi
        done
+       if [ "$ifdef_inc" != "NONE" ]; then printf "#endif\n" >> "${MOD}.inc"; fi
+       if [ "$ifdef_qh"  != "NONE" ]; then printf "#endif\n" >> "${MOD}.qh";  fi
 
        declare -l rec=1