Ejemplo n.º 1
0
func loadSchematics(filenames ...string) (schematics map[string]*gosch.File) {
	schematics = make(map[string]*gosch.File)

	for _, filename := range filenames {
		//log.Printf("reading %s", filename)

		f, err := os.Open(filename)
		if err != nil {
			log.Printf("error: failed to open %s: %s", filename, err)
			continue
		}

		d := gosch.NewDecoder(f)
		schematic, err := d.Decode()
		f.Close()
		if err != nil {
			log.Printf("error: failed to parse %s: %s", filename, err)
			continue
		}

		schematics[filename] = schematic
	}

	return schematics
}
Ejemplo n.º 2
0
func (c *Component) loadSymAttrs() {
	symAttrs, ok := loadedSyms[c.sym]
	if ok {
		//log.Printf("used cached copy of %s", c.sym)
		c.symAttrs = symAttrs
		return
	}

	symAttrs = make(map[string]string)
	c.symAttrs = symAttrs
	loadedSyms[c.sym] = symAttrs

	filename := symIndex[c.sym]
	if filename == "" {
		log.Printf("error: could not locate symbol '%s'", c.sym)
		return
	}

	//log.Printf("reading %s", filename)

	f, err := os.Open(filename)
	if err != nil {
		log.Printf("error: failed to open %s: %s", filename, err)
		return
	}

	d := gosch.NewDecoder(f)
	symbol, err := d.Decode()
	f.Close()
	if err != nil {
		log.Printf("error: failed to parse %s: %s", filename, err)
		return
	}

	for _, object := range symbol.Objects {
		text, ok := object.(*gosch.Text)
		if ok {
			parts := strings.SplitN(text.Text, "=", 2)
			if len(parts) == 2 {
				name := parts[0]
				value := parts[1]
				symAttrs[name] = value
			}
		}
	}
}
Ejemplo n.º 3
0
func loadSchematics(filenames ...string) (objects []gosch.Object) {
	for _, filename := range filenames {
		//log.Printf("reading %s", filename)

		f, err := os.Open(filename)
		if err != nil {
			log.Printf("error: failed to open %s: %s", filename, err)
			continue
		}

		d := gosch.NewDecoder(f)
		schematic, err := d.Decode()
		f.Close()
		if err != nil {
			log.Printf("error: failed to parse %s: %s", filename, err)
			continue
		}

		objects = append(objects, schematic.Objects...)
	}

	return objects
}