From d6cb7935fec205aea1fd0ffa6ef651040d2ba7a0 Mon Sep 17 00:00:00 2001 From: Dietrich Epp Date: Wed, 23 Mar 2022 18:04:39 -0400 Subject: [PATCH] Define include path in one place --- gen/filenames.go | 9 +++++---- gen/main.go | 7 +++++-- gen/scriptmap.go | 4 ++-- gen/source.go | 5 +++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gen/filenames.go b/gen/filenames.go index bb8fcca..a3aba0b 100644 --- a/gen/filenames.go +++ b/gen/filenames.go @@ -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') diff --git a/gen/main.go b/gen/main.go index e76bc81..a65ad3b 100644 --- a/gen/main.go +++ b/gen/main.go @@ -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. diff --git a/gen/scriptmap.go b/gen/scriptmap.go index 7c64d36..b9b3496 100644 --- a/gen/scriptmap.go +++ b/gen/scriptmap.go @@ -78,9 +78,9 @@ 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" + + "int GetCharmap(int script, int region) {\n" + "switch (script) {\n") for _, s := range m { fmt.Fprintf(w, "case %d: /* %s */\n", s.script, d.scripts.values[s.script]) diff --git a/gen/source.go b/gen/source.go index fe66eeb..e42f369 100644 --- a/gen/source.go +++ b/gen/source.go @@ -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)) +}