예제 #1
0
func checkForUnknownAtts(xn *xmlx.Node, knownAttNames ...string) {
	for _, att := range xn.Attributes {
		if !uslice.StrHas(knownAttNames, att.Name.Local) {
			println("UNKNOWN <" + xn.Name.Local + "> ATT: " + att.Name.Local)
		}
	}
}
예제 #2
0
//	Extracts all "identifiers" (as per `ExtractFirstIdentifier`) in `src` and starting with `prefix` (no duplicates, ordered by occurrence).
func ExtractAllIdentifiers(src, prefix string) (identifiers []string) {
	minPos := 0
	id := ExtractFirstIdentifier(src, prefix, minPos)
	for len(id) > 0 {
		if minPos = strings.Index(src, id) + 1; !uslice.StrHas(identifiers, id) {
			identifiers = append(identifiers, id)
		}
		id = ExtractFirstIdentifier(src, prefix, minPos)
	}
	return
}
예제 #3
0
func (me *ProgramManager) MakeProgramsFromRawSources(defines map[string]interface{}, forceAll bool, forceSome ...string) (dur time.Duration, progsMade []bool, err error) {
	progsMade = make([]bool, len(me.All))
	timeStart := time.Now()
	for i := 0; i < len(me.All); i++ {
		if me.All[i].GlHandle == 0 || forceAll || uslice.StrHas(forceSome, me.All[i].Name) {
			progsMade[i] = true
			me.All[i].Create()
			if err = me.All[i].CompileAndLinkShaders(defines); err != nil {
				me.All[i].Dispose()
				return
			}
		}
	}
	dur = time.Now().Sub(timeStart)
	return
}
예제 #4
0
파일: watcher.go 프로젝트: haruyama/fresh
func watch() {
	root := root()
	filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
		if info.IsDir() && !isTmpDir(path) {
			if len(path) > 1 && strings.HasPrefix(filepath.Base(path), ".") {
				return filepath.SkipDir
			}
			if uslice.StrHas(skipFolders(), filepath.Base(path)) {
				return filepath.SkipDir
			}

			watchFolder(path)
		}

		return err
	})
}
예제 #5
0
//	Extracts a ZIP archive to the local file system.
//	zipFilePath: full file path to the ZIP archive file.
//	targetDirPath: directory path where un-zipped archive contents are extracted to.
//	deleteZipFile: deletes the ZIP archive file upon successful extraction.
func ExtractZipFile(zipFilePath, targetDirPath string, deleteZipFile bool, fileNamesPrefix string, fileNamesToExtract ...string) error {
	var (
		fnames      []string
		fnprefix    string
		efile       *os.File
		zfile       *zip.File
		zfileReader io.ReadCloser
	)
	unzip, err := zip.OpenReader(zipFilePath)
	if unzip != nil {
		if err == nil && unzip.File != nil {
			if fnames = fileNamesToExtract; len(fnames) > 0 {
				for i, fn := range fnames {
					if strings.HasPrefix(fn, fileNamesPrefix) {
						fnames[i] = fn[len(fileNamesPrefix):]
						fnprefix = fileNamesPrefix
					}
				}
			}
			for _, zfile = range unzip.File {
				if len(fnames) == 0 || uslice.StrHas(fnames, zfile.FileHeader.Name) {
					if zfileReader, err = zfile.Open(); zfileReader != nil {
						if err == nil {
							if efile, err = os.Create(filepath.Join(targetDirPath, fnprefix+zfile.FileHeader.Name)); efile != nil {
								if err == nil {
									_, err = io.Copy(efile, zfileReader)
								}
								efile.Close()
							}
						}
						zfileReader.Close()
					}
				}
				if err != nil {
					break
				}
			}
		}
		unzip.Close()
		if deleteZipFile && (err == nil) {
			err = os.Remove(zipFilePath)
		}
	}
	return err
}
예제 #6
0
func isCsrfProtectionMethodForNoXhr(method string) bool {
	return uslice.StrHas(csrfProtectionMethodForNoXhr, strings.ToUpper(method))
}
예제 #7
0
func (me *glPack) makeFuncs() {
	var (
		i       int
		fpgtPtr bool
		src     glPackSrc
		fun     *glFunc
		fp      *glFuncParam
	)
	isBeast := func() bool {
		b := (!strings.HasPrefix(fun.cat, "VERSION_")) && (!strings.HasSuffix(fun.name, fun.cat[:strings.Index(fun.cat, "_")])) && !strings.HasSuffix(fun.name, "EXT")
		return b
	}
	for _, fun = range allFuncs {
		if strings.Contains(fun.cat, " ") {
			println(fun.cat)
		}
		if strings.HasPrefix(fun.cat, "VERSION_") || uslice.StrHas(cfg.genExts, fun.cat) || isBeast() {
			me.funcs[fun.name] = fun
			if uslice.StrHas(cfg.genExts, fun.cat) {
				println("EXT:" + fun.name)
			}
		}
	}

	for _, fun = range me.funcs {
		src.addLn("//\tGLAPI Wiki: http://www.opengl.org/wiki/GLAPI/gl%s", fun.name)
		src.addLn("//\tSDK doc: http://www.opengl.org/sdk/docs/man/xhtml/gl%s.xml", fun.name)
		src.add("func %s(", fun.name)
		for i, fp = range fun.params {
			fpgtPtr = strings.HasSuffix(fp.typeRef.g, "Ptr")
			src.add("%s %s", fp.saneName, strings.Replace(ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference") && !fpgtPtr, "*"+fp.typeRef.g, fp.typeRef.g), "***", "**", -1))
			if i < len(fun.params)-1 {
				src.add(", ")
			}
		}
		src.add(") %s {\n\t", fun.retType.g)
		if len(fun.retType.g) > 0 {
			src.add("return (%s)(", fun.retType.g)
		}
		src.add("C.call%s(", fun.name)
		for i, fp = range fun.params {
			fpgtPtr = fp.typeRef.g == "Ptr"
			if fp.typeRef.c == "GLchar* const" {
				src.add("(**C.GLchar)(unsafe.Pointer(%s))", fp.saneName)
			} else if fp.typeRef.c == "GLDEBUGPROC" {
				src.add("(*[0]byte)(%s)", fp.saneName)
			} else {
				src.add("(%s%s)(%s)", ustr.Ifs(ustr.IsOneOf(fp.kind, "array", "reference") && !fpgtPtr, "*", ""), ustr.Ifs(strings.HasSuffix(fp.typeRef.g, "Ptr"), "unsafe.Pointer", "C."+fp.typeRef.c), fp.saneName)
			}
			if i < len(fun.params)-1 {
				src.add(", ")
			}
		}
		src.add(")")
		if len(fun.retType.g) > 0 {
			src.add(")")
		}
		src.addLn("\n}\n")
		fun.makeCgo()
	}
	me.sources["funcs"] = src
}
예제 #8
0
func saneName(name string) (sane string) {
	if sane = name; uslice.StrHas(cOrGoKeywords, sane) {
		sane += "_"
	}
	return
}