// This generator reads from a file and generates a Go file with the
// file's content assigned to a go constant.
498297
func main() {
	if len(os.Args) < 4 {
		fmt.Println("Usage: winuserdata <copyrightyear> <gofile> <pkgname>")
	}

	addJujuUser, err := compoundJujuUser()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	winpowershell, err := compoundWinPowershellFuncs()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	var buf bytes.Buffer
	type content struct {
		AddJujuUser             string
		WindowsPowershellHelper string
		CopyrightYear           string
		Pkgname                 string
	}

	t, err := template.New("").Parse(fileTemplate)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	addJujuUser = fmt.Sprintf("\n%s", addJujuUser)
	winpowershell = fmt.Sprintf("\n%s", winpowershell)

	// Quote any ` in the data.
	addJujuUser = strings.Replace(addJujuUser, "`", "` + \"`\" + `", -1)
	winpowershell = strings.Replace(winpowershell, "`", "` + \"`\" + `", -1)

	t.Execute(&buf, content{
		AddJujuUser:             fmt.Sprintf("`%s`", addJujuUser),
		WindowsPowershellHelper: fmt.Sprintf("`%s`", winpowershell),
		Pkgname:                 os.Args[3],
		CopyrightYear:           os.Args[1],
	})

	err = ioutil.WriteFile(os.Args[2], buf.Bytes(), 0644)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
205193
func format(f *os.File) {
	// Run go fmt on the file.
	cmd := exec.Command("go", "fmt")
	cmd.Stdin = f
	_ = cmd.Run()
}
765735
func main() {
	var (
		settings         []Option
		settingsTemplate = createTemplate("templates/query_params.go.tmpl")
		filepath         = "../../search/query_params.go"
	)

	for _, opt := range options {
		if isSearch(opt.Kind) {
			settings = append(settings, opt)
		}
	}

	generateFile(settingsTemplate, settings, filepath)
}
1216586
func (t *transformer) transformGoFile(filename string) error {
	t.fset = token.NewFileSet()
	file, err := parser.ParseFile(t.fset, filename, nil, parser.ParseComments)
	if err != nil {
		return err
	}

	t.PackageName = file.Name.Name
	t.services, err = getServices(file)
	if err != nil {
		return err
	}
	if len(t.services) == 0 {
		return nil
	}

	t.inPRPCPackage, err = isInPackage(filename, prpcPackagePath)
	if err != nil {
		return err
	}

	if err := t.transformFile(file); err != nil {
		return err
	}

	var buf bytes.Buffer
	if err := printer.Fprint(&buf, t.fset, file); err != nil {
		return err
	}
	formatted, err := gofmt(buf.Bytes())
	if err != nil {
		return err
	}

	return ioutil.WriteFile(filename, formatted, 0666)
}
1261153
func (e *Error) Gen(format string, args ...interface{}) *Error {
	err := *e
	err.message = format
	err.args = args
	_, err.file, err.line, _ = runtime.Caller(1)
	return &err
}
97391
func Generator(reader io.Reader, sNgram int) chan Ngram {
	if sNgram <= 0 {
		panic(ErrBadNgramSize)
	}
	yield := make(chan Ngram)

	go func() {
		feed(yield, reader, sNgram)
	}()

	return yield
}
450465
func (g *Generator) Generate() (_ []string, err error) {
	if g.API == nil {
		return nil, fmt.Errorf("missing API definition, make sure design is properly initialized")
	}

	go utils.Catch(nil, func() { g.Cleanup() })

	defer func() {
		if err != nil {
			g.Cleanup()
		}
	}()

	if g.Target == "" {
		g.Target = "app"
	}

	codegen.Reserved[g.Target] = true

	mainFile := filepath.Join(g.OutDir, "main.go")
	if g.Force {
		os.Remove(mainFile)
	}
	_, err = os.Stat(mainFile)
	if err != nil {
		// ensure that the output directory exists before creating a new main
		if err = os.MkdirAll(g.OutDir, 0755); err != nil {
			return nil, err
		}
		if err = g.createMainFile(mainFile, funcMap(g.Target, nil)); err != nil {
			return nil, err
		}
	}

	err = g.API.IterateResources(func(r *design.ResourceDefinition) error {
		filename, err := GenerateController(g.Force, g.Regen, g.Target, g.OutDir, "main", r.Name, r)
		if err != nil {
			return err
		}

		g.genfiles = append(g.genfiles, filename)
		return nil
	})
	if err != nil {
		return
	}

	return g.genfiles, nil
}
51120
func NewReadFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
	rule := &readfile{
		pathJoin: gosec.NewCallList(),
		CallList: gosec.NewCallList(),
		MetaData: gosec.MetaData{
			ID:         id,
			What:       "Potential file inclusion via variable",
			Severity:   gosec.Medium,
			Confidence: gosec.High,
		},
	}
	rule.pathJoin.Add("path/filepath", "Join")
	rule.pathJoin.Add("path", "Join")
	rule.Add("io/ioutil", "ReadFile")
	rule.Add("os", "Open")
	return rule, []ast.Node{(*ast.CallExpr)(nil)}
}
58156
func main() {
	rules := filepath.Join(strings.Split(os.Getenv("GOPATH"), ":")[0], "src/github.com/vube/i18n/data/rules")
	err := filepath.Walk(rules, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			panic(err)
		}
		if info.IsDir() {
			return nil
		}
		in, err := ioutil.ReadFile(path)
		if err != nil {
			panic(err)
		}
		var out yaml.MapSlice
		if err = yaml.Unmarshal(in, &out); err != nil {
			panic(err)
		}
		var plural string
		for _, item := range out {
			if item.Key == "plural" {
				plural = item.Value.(string)
			}
		}
		if plural == "" {
			fmt.Println("can't find plurals in", path)
			return nil
		}
		locale := strings.Replace(info.Name(), filepath.Ext(info.Name()), "", 1)
		locale = strings.Replace(locale, "-", "_", -1)
		dir := "resources/locales/" + locale
		if _, err := os.Stat(dir); err != nil {
			fmt.Println(dir, "doesn't exist")
			return nil
		}
		file, err := os.Create(dir + "/plural.go")
		if err != nil {
			panic(err)
		}
		rawcodes := fmt.Sprintf(`package %s

		var pluralRule = %q
		`, locale, plural)
		var codes []byte
		if codes, err = format.Source([]byte(rawcodes)); err != nil {
			panic(err)
		}
		if _, err := file.Write(codes); err != nil {
			panic(err)
		}
		return nil
	})
	if err != nil {
		panic(err)
	}
}
839024
func (g *Generator) Format() ([]byte, error) {
	src, err := format.Source(g.Buf.Bytes())
	if err != nil {
		return g.Buf.Bytes(), err
	}

	return src, nil
}
399391
func Generate() (files []string, err error) {
	var (
		outDir, designPkg, appPkg, ver, res, pkg string
		force, regen                             bool
	)

	set := flag.NewFlagSet("controller", flag.PanicOnError)
	set.StringVar(&outDir, "out", "", "")
	set.StringVar(&designPkg, "design", "", "")
	set.StringVar(&appPkg, "app-pkg", "app", "")
	set.StringVar(&pkg, "pkg", "main", "")
	set.StringVar(&res, "res", "", "")
	set.StringVar(&ver, "version", "", "")
	set.BoolVar(&force, "force", false, "")
	set.BoolVar(&regen, "regen", false, "")
	set.Bool("notest", false, "")
	set.Parse(os.Args[1:])

	if err := codegen.CheckVersion(ver); err != nil {
		return nil, err
	}

	g := &Generator{OutDir: outDir, DesignPkg: designPkg, AppPkg: appPkg, Force: force, Regen: regen, API: design.Design, Pkg: pkg, Resource: res}

	return g.Generate()
}
930515
func File(t TestReporter, path string, content string) afero.File {
	file, err := appFs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
	if err != nil {
		t.Error("Failed to create the file: "+path, err)
		return nil
	}

	file.WriteString(content)
	Files = append(Files, file.Name())

	return file
}
849496
func Readlines(reader io.Reader) (generator chan []byte) {
	generator = make(chan []byte)
	go func() {
		defer close(generator)
		lreader := bufio.NewReader(reader)
		for line, isPrefix, err := lreader.ReadLine(); err != io.EOF; {
			fullLine := make([]byte, len(line))
			copy(fullLine, line)
			for isPrefix == true {
				line, isPrefix, err = lreader.ReadLine()
				fullLine = append(fullLine, line...)
			}
			generator <- fullLine
			line, isPrefix, err = lreader.ReadLine()
		}
	}()
	return generator
}
1048263
func Generate(input http.FileSystem, opt Options) error {
	opt.fillMissing()

	// Use an in-memory buffer to generate the entire output.
	buf := new(bytes.Buffer)

	err := t.ExecuteTemplate(buf, "Header", opt)
	if err != nil {
		return err
	}

	var toc toc
	err = findAndWriteFiles(buf, input, &toc)
	if err != nil {
		return err
	}

	err = t.ExecuteTemplate(buf, "DirEntries", toc.dirs)
	if err != nil {
		return err
	}

	err = t.ExecuteTemplate(buf, "Trailer", toc)
	if err != nil {
		return err
	}

	// Write output file (all at once).
	fmt.Println("writing", opt.Filename)
	err = ioutil.WriteFile(opt.Filename, buf.Bytes(), 0644)
	return err
}
948864
func (g *Group) File(path, file string) {
	g.echo.File(g.prefix+path, file)
}
1149731
func (g *Generator) generateImports() {
	// We almost always need a proto import.  Rather than computing when we
	// do, which is tricky when there's a plugin, just import it and
	// reference it later. The same argument applies to the fmt and math packages.
	if gogoproto.ImportsGoGoProto(g.file.FileDescriptorProto) {
		g.PrintImport(g.Pkg["proto"], g.ImportPrefix+"github.com/gogo/protobuf/proto")
		if gogoproto.RegistersGolangProto(g.file.FileDescriptorProto) {
			g.PrintImport(g.Pkg["golang_proto"], g.ImportPrefix+"github.com/golang/protobuf/proto")
		}
	} else {
		g.PrintImport(g.Pkg["proto"], g.ImportPrefix+"github.com/golang/protobuf/proto")
	}
	g.PrintImport(g.Pkg["fmt"], "fmt")
	g.PrintImport(g.Pkg["math"], "math")

	for i, s := range g.file.Dependency {
		fd := g.fileByName(s)
		// Do not import our own package.
		if fd.PackageName() == g.packageName {
			continue
		}
		filename := fd.goFileName()
		// By default, import path is the dirname of the Go filename.
		importPath := path.Dir(filename)
		if substitution, ok := g.ImportMap[s]; ok {
			importPath = substitution
		}
		importPath = g.ImportPrefix + importPath
		// Skip weak imports.
		if g.weak(int32(i)) {
			g.P("// skipping weak import ", fd.PackageName(), " ", strconv.Quote(importPath))
			continue
		}
		// We need to import all the dependencies, even if we don't reference them,
		// because other code and tools depend on having the full transitive closure
		// of protocol buffer types in the binary.
		if _, ok := g.usedPackages[fd.PackageName()]; ok {
			g.PrintImport(fd.PackageName(), importPath)
		} else {
			g.P("import _ ", strconv.Quote(importPath))
		}
	}
	g.P()
	for _, s := range g.customImports {
		s1 := strings.Map(badToUnderscore, s)
		g.PrintImport(s1, s)
	}
	g.P()
	g.P("// Reference imports to suppress errors if they are not otherwise used.")
	g.P("var _ = ", g.Pkg["proto"], ".Marshal")
	if gogoproto.ImportsGoGoProto(g.file.FileDescriptorProto) && gogoproto.RegistersGolangProto(g.file.FileDescriptorProto) {
		g.P("var _ = ", g.Pkg["golang_proto"], ".Marshal")
	}
	g.P("var _ = ", g.Pkg["fmt"], ".Errorf")
	g.P("var _ = ", g.Pkg["math"], ".Inf")
	for _, cimport := range g.customImports {
		if cimport == "time" {
			g.P("var _ = time.Kitchen")
			break
		}
	}
	g.P()
}
844659
func Generate() (files []string, err error) {
	var (
		outDir, ver  string
		timeout      time.Duration
		scheme, host string
		noexample    bool
	)

	set := flag.NewFlagSet("client", flag.PanicOnError)
	set.StringVar(&outDir, "out", "", "")
	set.String("design", "", "")
	set.DurationVar(&timeout, "timeout", time.Duration(20)*time.Second, "")
	set.StringVar(&scheme, "scheme", "", "")
	set.StringVar(&host, "host", "", "")
	set.StringVar(&ver, "version", "", "")
	set.BoolVar(&noexample, "noexample", false, "")
	set.Parse(os.Args[1:])

	// First check compatibility
	if err := codegen.CheckVersion(ver); err != nil {
		return nil, err
	}

	// Now proceed
	g := &Generator{OutDir: outDir, Timeout: timeout, Scheme: scheme, Host: host, NoExample: noexample, API: design.Design}

	return g.Generate()
}