예제 #1
0
// runs here
func runExit(x *xEnv, argv ...string) error {
	app.Dprintf("exit %v\n", argv)
	s := ""
	if len(argv) > 1 {
		s = argv[1]
	}
	app.Exits(s)
	return nil
}
예제 #2
0
func TestBib2ref(t *testing.T) {
	c := app.New()
	defer app.Exiting()
	c.Debug = testing.Verbose()
	lnc := nsutil.GetLines("/zx/lib/bib/zx.bib")
	rc := bib2ref(lnc)
	for ln := range rc {
		app.Dprintf("%s", ln)
	}
}
예제 #3
0
func (b *Bib) loadBib(fn string) error {
	lnc := nsutil.GetLines(fn)
	ln := <-lnc
	if !strings.Contains(ln, "bib2ref ok") {
		close(lnc, "not for me")
		return nil
	}
	app.Dprintf("add file %s\n", fn)
	return b.loadLines(bib2ref(lnc))
}
예제 #4
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
}
예제 #5
0
func TestBibLoad(t *testing.T) {
	BibTexOk = true
	c := app.New()
	defer app.Exiting()
	c.Debug = testing.Verbose()
	b, err := Load("/zx/lib/bib")
	if err != nil {
		t.Fatalf("load: %s", err)
	}
	if testing.Verbose() {
		b.WriteTo(os.Stdout)
	}

	app.Dprintf("cite plan 9 networks:\n")
	refs := b.Cites("VisageFS")
	for _, r := range refs {
		app.Dprintf("got:\n%s\n", strings.Join(r.Reference(), "\n"))
	}
	if len(refs) == 0 {
		t.Fatalf("did not find visage in bib")
	}
}
예제 #6
0
func TestLoad(t *testing.T) {
	BibTexOk = false
	c := app.New()
	defer app.Exiting()
	c.Debug = testing.Verbose()
	b, err := Load("/zx/lib/bib")
	if err != nil {
		t.Fatalf("load: %s", err)
	}
	if testing.Verbose() {
		b.WriteTo(os.Stdout)
	}

	app.Dprintf("cite plan 9 networks:\n")
	refs := b.Cites("plan", "9", "networks")
	for _, r := range refs {
		app.Dprintf("got:\n%s\n", strings.Join(r.Reference(), "\n"))
	}
	if len(refs) != 2 {
		t.Fatalf("wrong count for plan 9 networks at lsub bib")
	}
}
예제 #7
0
func (ek *eKeys) setKeys() {
	e := ek.el
	ks := keys(e.Tag)
	if e.Caption != nil {
		ks = append(ks, keys(e.Caption.Data)...)
	}
	if e.Kind == Khdr1 || e.Kind == Khdr2 || e.Kind == Khdr3 {
		ks = append(ks, keys(e.Data)...)
	}
	for _, w := range ks {
		ek.keys[w] = true
	}
	app.Dprintf("label %s %s -> %v\n", ek.el.Kind, ek.el.Nb, ks)
}
예제 #8
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
}
예제 #9
0
func (b *Bib) add(r *Ref) {
	app.Dprintf("add %v\n", r.Keys['T'])
	b.All = append(b.All, r)
	for _, v := range r.Keys {
		for _, k := range v {
			for _, tok := range strings.Fields(k) {
				tok = strings.ToLower(tok)
				tok = strings.TrimFunc(tok, unicode.IsPunct)
				if b.refs[tok] == nil {
					b.refs[tok] = map[*Ref]bool{}
				}
				b.refs[tok][r] = true
			}
		}
	}
}
예제 #10
0
// runs here
func runWait(x *xEnv, argv ...string) error {
	opts := opt.New("wait")
	app.Dprintf("wait %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	if len(args) == 0 {
		args = []string{"&"}
	}
	if len(args) != 1 {
		opts.Usage()
		return dbg.ErrUsage
	}
	x.wait(args[0])
	return nil
}
예제 #11
0
func (e *Elem) setRef(refs []*eKeys) {
	ks := keys(e.Data)
	var match *eKeys
	for _, r := range refs {
		if r.matches(ks) {
			if match != nil {
				e.Warn("multiple matches for ref %v; using %s", ks, e.Data)
				return
			}
			match = r
			app.Dprintf("ref %s -> %s\n", e.Data, r.el.Nb)
			e.Data = r.el.Nb
		}
	}
	if match == nil {
		e.Warn("no match for ref '%s'", e.Data)
	}
}
예제 #12
0
// runs here
func runCd(x *xEnv, argv ...string) error {
	opts := opt.New("")
	app.Dprintf("cd %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	if len(args) != 0 {
		opts.Usage()
		return dbg.ErrUsage
	}
	m, ok := <-app.In()
	if !ok {
		err = cerror(app.In())
		app.Warn("%s", err)
		return err
	}
	d, ok := m.(zx.Dir)
	if !ok {
		b, ok := m.([]byte)
		if !ok {
			app.Warn("%s", dbg.ErrNotDir)
			return dbg.ErrNotDir
		}
		s := string(b)
		d, err = nsutil.Stat(s)
		if err != nil {
			app.Warn("%s: %s", s, err)
			return err
		}
	}
	if d["type"] != "d" {
		app.Warn("%s: %s", d["path"], dbg.ErrNotDir)
		return dbg.ErrNotDir
	}
	app.Cd(d["path"])
	out := app.Out()
	if out != nil {
		out <- d
	}
	return nil
}
예제 #13
0
// runs here
func runNew(x *xEnv, argv ...string) error {
	opts := opt.New("dup")
	app.Dprintf("dup %v\n", argv)
	args, err := opts.Parse(argv)
	if err != nil {
		opts.Usage()
		return dbg.ErrUsage
	}
	for _, arg := range args {
		switch arg {
		case "ns":
			app.NewNS(nil)
		case "io":
			app.NewIO(nil)
		case "env":
			app.NewEnv(nil)
		case "dot":
			app.NewDot("")
		default:
			app.Warn("unknown resource '%s'", arg)
		}
	}
	return nil
}
예제 #14
0
func (b *Bib) load(fn string) error {
	app.Dprintf("add file %s\n", fn)
	lnc := nsutil.GetLines(fn)
	return b.loadLines(lnc)
}
예제 #15
0
//line parse.y:605
func yprintf(l interface{}, fmts string, args ...interface{}) {
	app.Dprintf(fmts, args...)
}
예제 #16
0
func main() {
	defer app.Exiting()
	os.Args[0] = "Q"
	c := app.New()
	opts.NewFlag("c", "ignored for compatibility", &dummy)
	opts.NewFlag("D", "debug", &c.Debug)
	edir := dbg.Usr
	opts.NewFlag("e", "env: qlfs environment name (defaults to uid)", &edir)
	opts.NewFlag("q", "qldir: qlfs root dir (defaults to /n/ql)", &ql)
	args, err := opts.Parse(os.Args)
	if err != nil {
		app.Warn("%s", err)
		opts.Usage()
		app.Exits(err)
	}
	cmd := ""
	if len(args) == 0 {
		app.Warn("no command given")
		opts.Usage()
		app.Exits(err)
	}
	cmd = strings.Join(args, " ")
	app.Dprintf("run %s\n", cmd)
	_, err = os.Stat(path.Join(ql, "Ctl"))
	if err != nil {
		app.Fatal("qlfs: %s", err)
	}
	env := path.Join(ql, edir)
	_, err = os.Stat(env)
	if err != nil {
		err = os.Mkdir(env, 0775)
	}
	if err != nil {
		app.Fatal("%s", err)
	}

	cdir := fmt.Sprintf("%s/%d", env, os.Getpid())
	if err := os.Mkdir(cdir, 0755); err != nil {
		app.Fatal("%s", err)
	}
	var b bytes.Buffer
	io.Copy(&b, os.Stdin)
	if err := ioutil.WriteFile(path.Join(cdir, "in"), b.Bytes(), 0644); err != nil {
		os.RemoveAll(cdir)
		app.Fatal("writing in: %s", err)
	}
	if err := ioutil.WriteFile(path.Join(cdir, "cmd"), []byte(cmd), 0644); err != nil {
		os.RemoveAll(cdir)
		app.Fatal("writing cmd: %s", err)
	}
	oc := make(chan bool, 2)
	pfd, err := os.Open(path.Join(cdir, "pout"))
	if err != nil {
		app.Warn("out: %s", err)
		oc <- true
	} else {
		go func() {
			io.Copy(os.Stdout, pfd)
			pfd.Close()
			oc <- true
		}()
	}
	efd, err := os.Open(path.Join(cdir, "perr"))
	if err != nil {
		app.Warn("err: %s", err)
		oc <- true
	} else {
		go func() {
			io.Copy(os.Stderr, efd)
			efd.Close()
			oc <- true
		}()
	}
	<-oc
	<-oc
	sts, err := ioutil.ReadFile(path.Join(cdir, "wait"))
	os.RemoveAll(cdir)
	if err != nil {
		app.Exits(err)
	}
	s := string(sts)
	if s == "success" {
		s = ""
	}
	app.Exits(s)
}