@@ -37,20 +37,22 @@ for f in $(git ls-files 'src/**/*.c'); do
3737 # Stop scanning early after first 60 lines (header region)
3838 (( line_no > 60 )) && break
3939 [[ $line == \# * include* ]] || continue
40- # Normalize whitespace
41- norm=${${line##* include } // [[:space:]]/ }
40+ # Normalize whitespace after the word 'include' using tr (portable)
41+ norm=$( print -r -- " ${line#* include} " | tr -d ' \t' )
42+ # Track first two include lines as they appear (before any early continues)
43+ if [[ -z $first_include ]]; then
44+ first_include=${norm}
45+ elif [[ -z $second_include ]]; then
46+ second_include=${norm}
47+ fi
4248 if [[ $norm == " \" zpmod.mdh\" " ]]; then
4349 if (( have_gateway & 1 )) ; then duplicate_gateway=1; fi
4450 (( have_gateway |= 1 ))
45- if [[ -z $first_include ]]; then first_include=" zpmod.mdh" ;
46- elif [[ -z $second_include ]]; then second_include=" zpmod.mdh" ; fi
4751 continue
4852 fi
4953 if [[ $norm == " \" zpmod.pro\" " ]]; then
5054 if (( have_gateway & 2 )) ; then duplicate_gateway=1; fi
5155 (( have_gateway |= 2 ))
52- if [[ -z $first_include ]]; then second_include=" zpmod.pro" ; first_include=${first_include:- } ;
53- elif [[ -z $second_include ]]; then second_include=" zpmod.pro" ; fi
5456 continue
5557 fi
5658 # If a system include (#include <...>) or quoted include (#include "...")
@@ -67,29 +69,18 @@ for f in $(git ls-files 'src/**/*.c'); do
6769 break
6870 fi
6971 fi
70-
71- # Enforce first-two-include rule: first include must be zpmod.mdh, second must be zpmod.pro
72- if [[ -z $first_include ]]; then
73- first_include=${norm}
74- if [[ $first_include != ' "zpmod.mdh"' ]]; then
75- print -u2 " [include-order] $f : first include must be \" zpmod.mdh\" (found $first_include )"
76- err=1
77- break
78- fi
79- continue
80- elif [[ -z $second_include ]]; then
81- second_include=${norm}
82- if [[ $second_include != ' "zpmod.pro"' ]]; then
83- print -u2 " [include-order] $f : second include must be \" zpmod.pro\" (found $second_include )"
84- err=1
85- break
86- fi
87- continue
88- fi
8972 done < $f
73+ # Validate gateway presence within first 60 lines
9074 if (( have_gateway != 3 )) ; then
9175 print -u2 " [include-order] $f : missing gateway pair (zpmod.mdh + zpmod.pro) in first 60 lines" ; err=1
9276 fi
77+ # Enforce the first-two-include policy after scanning
78+ if [[ -n $first_include && $first_include != ' "zpmod.mdh"' ]]; then
79+ print -u2 " [include-order] $f : first include must be \" zpmod.mdh\" (found $first_include )" ; err=1
80+ fi
81+ if [[ -n $second_include && $second_include != ' "zpmod.pro"' ]]; then
82+ print -u2 " [include-order] $f : second include must be \" zpmod.pro\" (found $second_include )" ; err=1
83+ fi
9384 if (( duplicate_gateway )) ; then
9485 print -u2 " [include-order] $f : duplicate gateway include lines" ; err=1
9586 fi
0 commit comments