changeset 930:39ac9e0ad6ad

Generate FLAG_longopt macros for --longopts with no corresponding short option.
author Rob Landley <rob@landley.net>
date Sat, 22 Jun 2013 14:23:06 -0500
parents 9e00446064fa
children 011df43e35d5
files scripts/make.sh
diffstat 1 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/make.sh	Tue Jun 18 18:13:06 2013 -0500
+++ b/scripts/make.sh	Sat Jun 22 14:23:06 2013 -0500
@@ -43,9 +43,9 @@
 
 echo "Generate headers from toys/*/*.c..."
 
-# Create a list of all the applets toybox can provide.  Note that the first
-# entry is out of order on purpose (the toybox multiplexer applet must be the
-# first element of the array).  The rest must be sorted in alphabetical order
+# Create a list of all the commands toybox can provide. Note that the first
+# entry is out of order on purpose (the toybox multiplexer command must be the
+# first element of the array). The rest must be sorted in alphabetical order
 # for fast binary search.
 
 echo "generated/newtoys.h"
@@ -59,10 +59,12 @@
 
 function getflags()
 {
-  sed -n -e "s/.*TOY($1"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \
+  FLX="$1"
+  shift
+  sed -n -e "s/.*TOY($FLX"',[ \t]*"\([^"]*\)"[ \t]*,.*)/\1/' \
          -e 't keep;d;:keep' -e 's/^[<>=][0-9]//' -e 's/[?&^]//' \
          -e 't keep' -e 's/[><=][0-9][0-9]*//g' -e 's/+.//g' \
-         -e 's/([^)]*)//g' -e 's/\[[^]]*\]//g' -e 's/[-?^:&#|@*]//g' -e 'p'
+         -e 's/\[[^]]*\]//g' -e 's/[-?^:&#|@*]//g' "$@" -e 'p'
 }
 
 # Extract global structure definitions and flag definitions from toys/*/*.c
@@ -85,17 +87,30 @@
         -e 's/^GLOBALS(/struct '"$NAME"'_data {/' \
         -e 's/^)/};/' -e 'p' $i
 
-    FLAGS="$(echo "$NEWTOYS" | getflags "$NAME")"
-    ZFLAGS="$(echo "$ALLTOYS" | getflags "$NAME" | sed 's/[-'"$FLAGS"']//g')"
+    LONGFLAGS="$(echo "$NEWTOYS" | getflags "$NAME" -e 's/\(\(([^)]*)\)*\).*/\1/' -e 's/(//g' -e 's/)/ /g')"
+    FLAGS="$(echo "$NEWTOYS" | getflags "$NAME" -e 's/([^)]*)//g')"
+    ZFLAGS="$(echo "$ALLTOYS" | getflags "$NAME" -e 's/([^)]*)//g' -e 's/[-'"$FLAGS"']//g')"
+    LONGFLAGLEN="$(echo "$LONGFLAGS" | wc -w)"
 
     echo "#ifdef FOR_${NAME}"
     X=0
+    # Provide values for --longopts with no corresponding short flags
+    for i in $LONGFLAGS
+    do
+      X=$(($X+1))
+      echo -e "#define FLAG_$i\t(1<<$(($LONGFLAGLEN+${#FLAGS}-$X)))"
+    done
+
+    # Provide values for active flags
+    X=0
     while [ $X -lt ${#FLAGS} ]
     do
       echo -ne "#define FLAG_${FLAGS:$X:1}\t"
       X=$(($X+1))
       echo "(1<<$((${#FLAGS}-$X)))"
     done
+
+    # Provide zeroes for inactive flags
     X=0
     while [ $X -lt ${#ZFLAGS} ]
     do