~kris/9p

glenda

4274d7daaea5bc33e171220337848ae9eddbb4f1 — Sean Hinchee 7 years ago a95df9f
add g!sig command
3 files changed, 61 insertions(+), 2 deletions(-)

M mux.go
M x/mux/man.go
A x/mux/man/sig
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