autogenpb/newsort.go

78 lines
1.6 KiB
Go

package main
import (
"os"
"strings"
"go.wit.com/log"
)
func (pb *Files) makeNewSortfile(pf *File) {
f, _ := os.OpenFile(pf.Filebase+".newsort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
header(f, pf)
pf.syncLock(f)
if pf.Bases != nil {
log.Info("THIS IS WHAT BASES?", pf.Bases.Name, pf.Bases)
}
if pf.Base != nil {
log.Info("THIS IS WHAT BASE?", pf.Base.Name, pf.Base)
pf.Base.iterTop(f)
pf.Base.iterNext(f)
}
/*
for _, msg := range pf.MsgNames {
if msg.DoMutex {
for _, key := range msg.Sort {
pf.iterTop(f, key)
pf.iterNext(f, key)
}
} else {
log.Info("Skipping syncLock() for", msg.Name, "DoMutex = false")
}
}
*/
// pf.appendUnique(f, msg, sortmap) // Append() enforce no unique keys
return
// iterSortAll(f, sortmap)
if argv.Append != "" {
sortmap["append"] = string(argv.Append)
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
}
for _, s := range uniqueKeys {
// log.Info("found unique key in .proto", s)
sortmap["sortBy"] = s
sortmap["sortKey"] = s
iterSortBy(f, sortmap)
sortmap["append"] = sortmap["sortKey"]
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
iterDelete(f, sortmap)
iterReplace(f, sortmap)
iterFind(f, sortmap)
}
for _, s := range argv.Sort {
sortparts := strings.Split(s, ",")
sortmap["sortBy"] = sortparts[0]
sortmap["sortKey"] = sortparts[1]
iterSortBy(f, sortmap)
sortmap["append"] = sortmap["sortKey"]
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
iterDelete(f, sortmap)
iterReplace(f, sortmap)
iterFind(f, sortmap)
}
iterEnd(f, sortmap)
}