Example #1
0
// parseGroups is used to parse a list of group states.
func parseGroups(lines []string) ([]Group, os.Error) {
	var res vector.Vector
	for _, line := range lines {
		ss := strings.Split(strings.TrimSpace(line), " ", 4)
		if len(ss) < 4 {
			return nil, ProtocolError("short group info line: " + line)
		}
		high, err := strconv.Atoi(ss[1])
		if err != nil {
			return nil, ProtocolError("bad number in line: " + line)
		}
		low, err := strconv.Atoi(ss[2])
		if err != nil {
			return nil, ProtocolError("bad number in line: " + line)
		}
		res.Push(&Group{ss[0], high, low, ss[3]})
	}
	realres := make([]Group, res.Len())
	i := 0
	for v := range res.Iter() {
		realres[i] = *v.(*Group)
		i++
	}
	return realres, nil
}
Example #2
0
func main() {
	/* handle all the flags */
	flag.Parse()
	if flag.NArg() == 0 {
		if !*q {
			println("No files specified")
		}
		os.Exit(1)
	}

	//if neither are set, show both
	if !*d && !*D {
		*d, *D = true, true
	}
	//if none are set, show all
	if !*i && !*f && !*g && !*t {
		*i, *f, *g, *t = true, true, true, true
	}

	var filter int
	if *i {
		filter |= Import
	}
	if *f {
		filter |= Func
	}
	if *g {
		filter |= Global
	}
	if *t {
		filter |= Type
	}

	matcher, err := regexp.Compile(*m)
	check(err)

	files := flag.Args()

	/* process all the files */

	var glob vector.Vector
	for _, file_name := range files {
		info, err := os.Stat(file_name)
		check(err)

		if info.IsDirectory() {
			base := path.Clean(file_name)

			dir, err := os.Open(base, os.O_RDONLY, 0664)
			defer dir.Close()
			check(err)

			dirs, err := dir.Readdirnames(-1)
			check(err)

			none := true
			for _, file_name = range dirs {
				if !*tests && strings.HasSuffix(file_name, "_test.go") {
					continue
				}
				if strings.HasSuffix(file_name, ".go") {
					none = false
					glob.Push(doFile(path.Join(base, file_name)))
				}
			}
			if none {
				if !*q {
					os.Stderr.WriteString("There are no go files in " + base)
				}
				os.Exit(1)
			}
		} else if info.IsRegular() {
			//file.Close()
			glob.Push(doFile(file_name))
		} else {
			msg := "File " + file_name
			msg += " is neither a directory nor a regular file"
			if !*q {
				os.Stderr.WriteString(msg)
			}
			os.Exit(1)
		}
	}

	/* display all requested results */

	var show bool
	for e := range glob.Iter() {
		entry := e.(*Declarations)
		if !*p {
			println(entry.file_name + ":" + entry.package_name)
		}
		for _, decls := range entry.decls {
			show = filter&decls.kind != 0
			if show && decls.kind != Import {
				show = (*D && decls.public) || (*d && !decls.public)
			}
			if show && matcher.MatchString(decls.match) {
				println(decls.full)
			}
		}
	}
}