示例#1
0
// runs here
func runFlag(x *xEnv, argv ...string) error {
	c := app.AppCtx()
	app.Dprintf("flag %v\n", argv)
	switch len(argv) {
	case 1:
		flgs := ""
		if c.Debug {
			flgs += "D"
		}
		if x.debugX {
			flgs += "X"
		}
		if x.debugL {
			flgs += "L"
		}
		if x.iflag {
			flgs += "i"
		}
		app.Printf("flags %s\n", flgs)
		return nil
	case 2:
	default:
		app.Eprintf("usage: flags [±]flags\n")
		return dbg.ErrUsage
	}
	flg := argv[1]
	set := flg[0] == '+'
	clear := flg[0] != '-'
	if !set && !clear {
		// clear all flags
		c.Debug = false
		x.debugX = false
		x.debugL = false
		// then set those named
		set = true
	} else {
		flg = flg[1:]
	}
	for _, r := range flg {
		switch r {
		case 'D':
			c.Debug = (c.Debug && !clear) || set
		case 'X':
			x.debugX = (x.debugX && !clear) || set
		case 'L':
			x.debugL = (x.debugL && !clear) || set
		case 'i':
			app.Warn("'-i' cannot be changed")
		default:
			app.Warn("unknown flag '%c'", r)
		}
	}
	return nil
}
示例#2
0
func runType(x *xEnv, argv ...string) error {
	defer app.Exiting()
	opts := opt.New("{name}")
	app.Dprintf("type %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		app.Exits(dbg.ErrUsage)
	}
	for _, n := range args {
		app.Printf("%s: %s\n", n, x.ntype(n))
	}
	app.Exits(nil)
	return nil
}
示例#3
0
func (l *lex) get() rune {
	if l.saved != 0 {
		r := l.saved
		l.saved = 0
		l.val = append(l.val, r)
		return r
	}
	r, _, err := l.in[0].ReadRune()

	// if we are reading ignoring C-c and get a C-c
	// then we must panic so the caller of the parser
	// may recover and re-start the parser with new
	// data from stdin starting now.
	if err == dbg.ErrIntr {
		l.interrupted = true
	}
	if l.interactive && l.interrupted {
		l.interrupted = false
		app.Printf("\n")
		panic(dbg.ErrIntr)
		return 0
	}

	if err != nil {
		r = 0
		if !l.eofmet && !l.interactive {
			r = '\n'
		}
		l.eofmet = err == io.EOF
		if r==0 && len(l.in)>1 {
			l.eofmet = false
			l.in = l.in[1:]
			l.Addr = l.saddr[0]
			l.saddr = l.saddr[1:]
			return l.get()
		}
		return r
	}
	l.val = append(l.val, r)
	return r
}
示例#4
0
// Using channels for the input make it really tricky to issue a prompt
// at the right time.
func (l *lex) lex(lval *yySymType) int {
	l.val = l.val[:0]
	var c rune
	prompted := false
	for {
		if l.interactive && l.wasnl && l.prompt != "" && !prompted{
			app.Printf("%s", l.prompt)
			prompted = true
		}
		c = l.get()
		if c == '#' {
			c = l.skipComment()
			l.wasnl = true
			prompted = false
		}
		if c == 0 {
			l.wasnl = true
			return 0
		}
		if c == '\n' {
			l.val = l.val[:0]
			l.Line++
			l.wasnl = true
			return NL
		}
		if !unicode.IsSpace(c) {
			if l.wasnl && c=='%' {
				l.val = l.val[:0]
				continue
			}
			break
		}
		l.val = l.val[:0]
	}
	l.wasnl = false
	switch c {
	case '\'', '`':
		return l.scanQuote(c, lval)
	case '←':
		return '='
	case '|':
		switch c = l.get(); c {
		case '|':
			return OR
		case '>':
			return GFPIPE
		}
		l.unget()
		return '|'
	case '&':
		if c = l.get(); c == '&' {
			return AND
		}
		l.unget()
		return '&'
	case '{', '}', ';', '[', ']', '^', '=':
		return int(c)
	case '$':
		switch c = l.get(); c {
		case '#':
			return LEN
		}
		l.unget()
		return '$'
	case '<':
		switch c = l.get(); c {
		case '{':
			return INBLK
		case '<', '|':
			switch x := l.get(); x {
			case '{':
				if c == '|' {
					return PIPEBLK
				}
				return RAWINBLK
			case '<':
				if c == '<' && l.get() == '{' {
					return SINGLEINBLK
				}
			}
			// no way out and can't be any other thing as valid syntax.
			l.unget()
			return ERROR
		}
		l.unget()
		return '<'
	case '>':
		switch c = l.get(); c {
		case '>':
			return APP
		case '{':
			return TEEBLK
		}
		l.unget()
		return '>'
	case '-':
		if c = l.get(); c == '|' {
			return INPIPE;
		}
		l.unget()
		// and fall to scanName
	}
	return l.scanName(lval)
}