shithub: bin.rc

Download patch

ref: b57d567038f8cf65a8c0ed6e8d55d504801ec306
parent: 825c8db11139dbbb0d2ae87cc43949bcc64feef1
author: kvik <kvik@a-b.xyz>
date: Sat Apr 18 21:41:28 EDT 2020

c: parse flags with aux/getflags(8)

--- a/bin/c
+++ b/bin/c
@@ -1,9 +1,5 @@
 #!/bin/rc
 rfork e
-fn usage {>[2=1] echo 'usage:' $usage && exit 'usage'}
-usage='c [-fs] [regex] [search]
-	-f        find functions
-	-s        find structs'
 
 fn isatty {grep -s '/dev/cons' /fd/0ctl}
 
@@ -44,22 +40,14 @@
 	}' | sam -d $files >[2]/dev/null
 }
 
+
+op = 'struct'
 identifier = '[a-zA-Z_0-9]*'
-op = (struct)
-while(~ $1 -* && ! ~ $1 --){
-	switch($1){
-	case -f -func*
-		op = 'function'
-	case -s -struct
-		op = 'struct'
-	case *
-		usage
-	}
-	shift
-}
-if(~ $1 --)
-	shift
 
+flagfmt = 'f,s'; args = '[regexp] [searchpath]'
+if(! eval `''{aux/getflags $*}) aux/usage
+if(~ $flagf 1) op = 'function'
+if(~ $flags 1) op = 'struct'
 if(! isatty){
 	nl = '
 '