summaryrefslogtreecommitdiff
path: root/def
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-28 21:32:18 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-28 21:32:18 +0000
commitf3fd330cddade1c66d0f101d5cc6f657c4cd1bb6 (patch)
tree87ccd4ed6ca757709164615b8cbce92932a96f21 /def
downloadplan9-f3fd330cddade1c66d0f101d5cc6f657c4cd1bb6.tar.gz
Add various tools
Diffstat (limited to 'def')
-rwxr-xr-xdef45
1 files changed, 45 insertions, 0 deletions
diff --git a/def b/def
new file mode 100755
index 0000000..09a3f0c
--- /dev/null
+++ b/def
@@ -0,0 +1,45 @@
+#!/bin/rc -e
+
+# def -- find function definition
+
+flagfmt=a
+args='name [dir]'
+if(! ifs=() eval `{aux/getflags $*} || ! ~ $#* 1 2 3){
+ echo usage: $0 name [dir] >[1=2]
+ exit usage
+}
+
+name=$1
+if(~ $#* 2) wdir=$2
+if not wdir=`{pwd}
+
+files=$wdir^/*.[ch]
+if(~ $files $wdir^/'*.[ch]'){
+ echo error: no c/h files found >[1=2]
+ exit 'not found'
+}
+
+# ansi definition
+if(~ $flaga 1){
+ r=`{
+ echo 'X ,x/[\n ]\**'^$name^'\(.*\)([ ]*\/\*.*\*\/)?\n{/-+=' |
+ sam -d $files >[2=1] |
+ awk -F'[ ;]' '
+ /^ -\. / { file = $3; next }
+ /^ - / { file = $4; next }
+ { print file ":" $1; exit }
+ '}
+}
+
+# style(1) definition
+if not{
+ r=`{grep -n '^'^$name^'\(' $files | awk -F: '{print $1 ":" $2; exit}'}
+}
+
+# success
+if(! ~ $r '')
+ echo $r
+
+# try to find macro instead
+if not
+ grep -n '^#define[ ]'^$name^'\(' $files | awk -F: '{print $1 ":" $2; exit}'