示例#1
0
文件: main.go 项目: bjarneh/cmd
func slurp(strpath string) (b []byte) {
	b, err := ioutil.ReadFile(strpath)
	if err != nil {
		handy.Check(err)
	}
	return b
}
示例#2
0
文件: guess.go 项目: bjarneh/cmd
func NorwayFile(fname string) int {

	var (
		ascii  byte = 1
		utf8   byte
		latin1 byte
		prev   byte
		b      []byte
		e      error
	)

	b, e = ioutil.ReadFile(fname)
	handy.Check(e)

	for i := 0; i < len(b); i++ {
		if b[i] > 127 {
			ascii = 0
		}
		if looksUnicode(prev, b[i]) {
			utf8 = 1
		}
		if looksLatin(b[i]) {
			latin1 = 1
		}
		prev = b[i]

		if !conflict(ascii, utf8, latin1) && ascii == 0 {
			i = len(b) // breaks
		}
	}

	if !conflict(ascii, utf8, latin1) {
		switch {
		case latin1 == 1:
			return LATIN1
		case utf8 == 1:
			return UTF8
		case ascii == 1:
			return ASCII
		}
	}

	return UNSURE
}
示例#3
0
文件: dag.go 项目: bjarneh/godag
// gorun like stuff
func ParseSingle(pathname string) (pkgs []*Package, name string) {

	tree := getSyntaxTreeOrDie(pathname, parser.ImportsOnly)
	shortname := tree.Name.String()

	if shortname != "main" {
		log.Fatalf("[ERROR] running a single file requires 'main' package\n")
	}

	p := newPackage()
	p.ShortName = shortname
	absPath, e := filepath.Abs(pathname)
	handy.Check(e)
	stub := filepath.Join(os.TempDir(), "godag")
	handy.DirOrMkdir(stub)
	name = filepath.Join(stub, handy.Sha1(absPath))
	p.Name = name
	p.Files = append(p.Files, pathname)

	pkgs = append(pkgs, p)

	return
}