Define include path in one place

This commit is contained in:
Dietrich Epp 2022-03-23 18:04:39 -04:00
parent bc46e1e982
commit d6cb7935fe
4 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package main
import "strconv"
import (
"strconv"
)
func writeFilenames(charmaps []string, filename string) error {
s, err := createCSource(filename)
@ -10,9 +12,8 @@ func writeFilenames(charmaps []string, filename string) error {
w := s.writer
w.WriteString(header)
w.WriteString(
"#include \"convert/test.h\"\n" +
"const char *const kCharsetFilename[] = {\n")
s.include("test.h")
w.WriteString("const char *const kCharsetFilename[] = {\n")
for _, fn := range charmaps {
if fn != "" {
w.WriteByte('\t')

View File

@ -13,7 +13,10 @@ import (
"moria.us/macscript/table"
)
const header = "/* This file is automatically generated. */\n"
const (
header = "/* This file is automatically generated. */\n"
srcdirname = "convert"
)
var (
flagDest string
@ -44,7 +47,7 @@ func mainE() error {
}
destdir := flagDest
if destdir == "" {
destdir = filepath.Join(srcdir, "convert")
destdir = filepath.Join(srcdir, srcdirname)
}
// Read metadata.

View File

@ -78,8 +78,8 @@ func writeMap(d *scriptdata, m []*scriptmap, filename string) error {
w := s.writer
w.WriteString(header)
s.include("convert.h")
w.WriteString(
"#include \"convert/convert.h\"\n" +
"int GetCharmap(int script, int region) {\n" +
"switch (script) {\n")
for _, s := range m {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path"
)
type csource struct {
@ -62,3 +63,7 @@ func (s *csource) flush() error {
s.filename = ""
return nil
}
func (s *csource) include(name string) {
fmt.Fprintf(s.writer, "#include \"%s\"\n", path.Join(srcdirname, name))
}