shithub: bin.rc

Download patch

ref: b35806908757c20012985c8916d48456cd14e720
parent: d400e426eb04cfc4cb78fa82e7bcdc20150f3305
author: kvik <[email protected]>
date: Mon May 4 16:39:55 EDT 2020

c: add enum (-e) search option

--- a/bin/c
+++ b/bin/c
@@ -21,6 +21,23 @@
 	}' | sam -d $files >[2]/dev/null
 }
 
+fn enum {
+	search = $*
+	if(~ $#search 0)
+		search = (.)
+	files = `{walk -f $search | grep '\.[ch]$'}
+	awk '
+	/^enum[ 	]*{/ {
+		matched = 1
+		if(nfound++ > 0) printf "\n"
+		if(ARGC != 1)
+			print FILENAME ":" FNR
+	}
+	matched         {print}
+	matched && /^}/ {matched = 0}
+	' $files
+}
+
 fn function {
 	ignore = ('\.root.s$' 'cmd/python/')
 	search = $*
@@ -46,6 +63,7 @@
 
 flagfmt = 'e,f,s'; args = '[regexp] [searchpath]'
 eval `{aux/getflags $*} || exec aux/usage
+if(~ $flage 1) op = 'enum'
 if(~ $flagf 1) op = 'function'
 if(~ $flags 1) op = 'struct'
 if(! isatty){