M mux.go => mux.go +3 -1
@@ 28,7 28,9 @@ func init() {
Router.Route("lookman", "Search for a string in the Plan 9 manual pages (From 9front for now).", Router.Lookman)
- Router.Route("fortune", "Display fortunes. Bonus files are (theo troll rsc terry rob ken).", Router.Fortunes)
+ Router.Route("sig", "Search for function definitions in the Plan 9 manual pages (From 9front for now).", Router.Sig)
+
+ Router.Route("fortune", "Display fortunes. Bonus files are (theo troll rsc terry rob ken henesy).", Router.Fortunes)
Router.Route("bullshit", "Print logical statements with sound grounding.", Router.Bullshit)
M x/mux/man.go => x/mux/man.go +28 -1
@@ 111,8 111,35 @@ func (m *Mux) Man(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
}
// Fetch a summary of a man page
-func (m *Mux) Summary(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
+func (m *Mux) Sig(ds *discordgo.Session, dm *discordgo.Message, ctx *Context) {
+ resp := "\n```"
+ if !(len(ctx.Fields) >= 2) {
+ resp += "Usage: lookman key ...\n"
+ } else {
+ // g!sig vmx
+ args := ctx.Fields[1:]
+
+ // rc or get out
+ out, err := exec.Command("./x/mux/man/sig", args...).Output()
+ if err != nil {
+ resp += "No sig script found."
+ goto END
+ } else {
+ if len(out) < 2 {
+ resp += "No matching definitions found."
+ goto END
+ }
+
+ str := string(out)
+ // lines := strings.Split(str, "\n")
+ resp += str
+ }
+ }
+
+ END:
+ resp += "```\n"
+ ds.ChannelMessageSend(dm.ChannelID, resp)
}
// Call lookman on a given query
A x/mux/man/sig => x/mux/man/sig +30 -0
@@ 0,0 1,30 @@
+#!/usr/bin/env rc
+# Usage: sig key ...
+# prints out function signatures by grepping the manual
+
+MIRROR = /usr/share/mirror/plan9front
+*=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_ \012'} # fold case, delete funny chars
+if(~ $#* 0){
+ echo Usage: sig function ...
+ exit 1
+}
+
+for (i) {
+ files=`{9 grep -il '[ ]\*?'$i'\(' $MIRROR/sys/man/2/*}
+ for(j in $files) {
+ {echo .nr LL 20i; 9 sed -n '/^.SH SYNOPSIS/,/^.SH.*DESCR/p' $j } |
+ 9 nroff -man |
+ sed '
+ :a
+ /,$/ {
+ N
+ s/\n//
+ }
+ ta
+ s/[ ]+/ /g' |
+ 9 grep -i -e '[ *]'$i'\(' | sed 's/^[ +]/ /' | sed 's/ //g'
+ }
+}
+
+exit 0
+