Break cgen's generated data into chapters

This will hopefully lessen the diff of subsequent changes.
This commit is contained in:
Nigel Tao committed 2018-04-17 10:57:08 +10:00
1 parent 6656b6e5e9
commit 9c2330e6fd
8 files changed
+119 -56

No files matched your search

+27 -8
View File
@@ -98,19 +98,38 @@ func genBase(out *bytes.Buffer) error {
}
fmt.Fprintf(out, "const %s = \"\" +\n", f.varname)
for len(in) > 0 {
s := in
if len(s) > columns {
s = s[:columns]
}
in = in[len(s):]
fmt.Fprintf(out, "%q +\n", s)
}
writeStringConst(out, in)
out.WriteString("\"\"\n\n")
}
return nil
}
var dashDashDashDash = []byte("// ----")
func writeStringConst(out *bytes.Buffer, s []byte) {
for len(s) > 0 {
remaining := []byte(nil)
if i := bytes.Index(s[1:], dashDashDashDash); i >= 0 {
s, remaining = s[:i+1], s[i+1:]
}
for len(s) > 0 {
t := s
if len(t) > columns {
t = t[:columns]
}
s = s[len(t):]
fmt.Fprintf(out, "%q +\n", t)
}
s = remaining
if len(s) > 0 {
out.WriteString("\"\" +\n")
}
}
}
type template struct {
name string
args [][2]string