d53014f85689f84574d0e4cf6bd7731f487aa71a — Ahmed Alsharif 8 months ago 4f420d9 master
Improve build_table script
Change regex to match more forms of "#define" directives. At one point it would make sense to follow the exact C rules.
1 files changed, 10 insertions(+), 6 deletions(-)

M build_table
M build_table => build_table +10 -6
@@ 9,15 9,19 @@   table=$(echo | gcc -E -Wp,-v - 2>&1 \
  	| grep -E ' /' | xargs find | grep 'syscall.h' \
- 	| xargs cat | grep -E "# define SYS_[a-z]")
+ 	| xargs cat | grep -E "#[[:blank:]]*define SYS_[a-z]")
  
  while read -r line; do
  	splitted_line=($line)
- 	syscall=${splitted_line[2]}
- 	echo
- 	echo "#ifdef $syscall"
- 	echo "	if (strcmp(arg, \"${syscall/"SYS_"/""}\") == 0) return $syscall;"
- 	echo "#endif"
+ 	for word in "${splitted_line[@]}"; do
+ 		if [[ "$word" =~ SYS_ ]]; then
+ 			syscall=$word
+ 			echo
+ 			echo "#ifdef $syscall"
+ 			echo "	if (strcmp(arg, \"${syscall/"SYS_"/""}\") == 0) return $syscall;"
+ 			echo "#endif"
+ 		fi
+ 	done
  done <<< "$table"
  
  echo "	return -1;"