func slurp(strpath string) (b []byte) { b, err := ioutil.ReadFile(strpath) if err != nil { handy.Check(err) } return b }
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 }
// 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 }