mirror of
https://github.com/depp/syncfiles.git
synced 2024-11-26 00:49:17 +00:00
Generate charmap string resources
The string resources contain names of scripts, regions, and character maps.
This commit is contained in:
parent
ca074ce387
commit
f49e81388c
@ -43,6 +43,9 @@ func mainE() error {
|
||||
if err := writeMap(&d, m, "src/getcharmap.c"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := writeRez(&d, "src/charmaps.r"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
63
gen/rez.go
Normal file
63
gen/rez.go
Normal file
@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// writeStrings writes a 'STR#' resource in Rez format.
|
||||
func writeStrings(w *bufio.Writer, rsrc string, strs []string) {
|
||||
fmt.Fprintf(w, "resource 'STR#' (%s) {{\n", rsrc)
|
||||
for i, s := range strs {
|
||||
fmt.Fprintf(w, "\t%q", s)
|
||||
if i < len(strs)-1 {
|
||||
w.WriteByte(',')
|
||||
}
|
||||
w.WriteByte('\n')
|
||||
}
|
||||
w.WriteString("}};\n")
|
||||
}
|
||||
|
||||
func charmapNames(d *scriptdata) []string {
|
||||
r := make([]string, len(d.charmaps))
|
||||
for i, c := range d.charmaps {
|
||||
r[i] = c.name
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func constStrings(c *constmap) []string {
|
||||
var n int
|
||||
for i := range c.values {
|
||||
if i >= n {
|
||||
n = i + 1
|
||||
}
|
||||
}
|
||||
r := make([]string, n)
|
||||
for i, name := range c.values {
|
||||
r[i] = name
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func writeRez(d *scriptdata, filename string) error {
|
||||
fmt.Fprintln(os.Stderr, "Writing:", filename)
|
||||
fp, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fp.Close()
|
||||
w := bufio.NewWriter(fp)
|
||||
|
||||
w.WriteString(header)
|
||||
w.WriteString("#include \"resources.h\"\n")
|
||||
writeStrings(w, "rSTRS_Charmaps", charmapNames(d))
|
||||
writeStrings(w, "rSTRS_Scripts", constStrings(&d.scripts))
|
||||
writeStrings(w, "rSTRS_Regions", constStrings(&d.regions))
|
||||
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
return fp.Close()
|
||||
}
|
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@ -1 +1,2 @@
|
||||
/getcharmap.c
|
||||
/charmaps.r
|
||||
|
3
src/resources.h
Normal file
3
src/resources.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define rSTRS_Charmaps 128
|
||||
#define rSTRS_Scripts 129
|
||||
#define rSTRS_Regions 130
|
Loading…
Reference in New Issue
Block a user