2024-12-27 14:43:21 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2025-01-09 15:51:45 -06:00
|
|
|
func (pb *Files) makeNewSortfile(pf *File) error {
|
2025-01-09 05:20:00 -06:00
|
|
|
f, _ := os.OpenFile(pf.Filebase+".newsort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 05:20:00 -06:00
|
|
|
header(f, pf)
|
2025-01-09 15:29:27 -06:00
|
|
|
pf.syncLock(f)
|
2025-01-09 17:15:53 -06:00
|
|
|
|
|
|
|
if argv.Mutex {
|
|
|
|
// use the mutex lock from the modified protoc.pb.go file
|
|
|
|
pf.Bases.Lockname = "all.Lock"
|
2025-01-09 15:29:27 -06:00
|
|
|
}
|
|
|
|
|
2025-01-09 15:51:45 -06:00
|
|
|
pf.Base.iterTop(f)
|
|
|
|
pf.Base.iterNext(f)
|
2025-01-09 17:15:53 -06:00
|
|
|
pf.iterSelect(f)
|
2025-01-09 16:18:06 -06:00
|
|
|
pf.appendUnique(f) // Append() enforce no unique keys
|
2025-01-09 17:15:53 -06:00
|
|
|
pf.iterSortBy(f)
|
|
|
|
pf.iterAll(f)
|
|
|
|
// pf.iterSortAll(f, sortmap)
|
2025-01-09 15:51:45 -06:00
|
|
|
|
|
|
|
return nil
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
/*
|
|
|
|
for _, s := range uniqueKeys {
|
|
|
|
// log.Info("found unique key in .proto", s)
|
|
|
|
sortmap["sortBy"] = s
|
|
|
|
sortmap["sortKey"] = s
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
sortmap["append"] = sortmap["sortKey"]
|
|
|
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
iterDelete(f, sortmap)
|
|
|
|
iterReplace(f, sortmap)
|
|
|
|
iterFind(f, sortmap)
|
|
|
|
}
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
for _, s := range argv.Sort {
|
|
|
|
sortparts := strings.Split(s, ",")
|
|
|
|
sortmap["sortBy"] = sortparts[0]
|
|
|
|
sortmap["sortKey"] = sortparts[1]
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
iterSortBy(f, sortmap)
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
sortmap["append"] = sortmap["sortKey"]
|
|
|
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
2024-12-27 14:43:21 -06:00
|
|
|
|
2025-01-09 17:15:53 -06:00
|
|
|
iterDelete(f, sortmap)
|
|
|
|
iterReplace(f, sortmap)
|
|
|
|
iterFind(f, sortmap)
|
|
|
|
}
|
|
|
|
*/
|
2025-01-09 15:51:45 -06:00
|
|
|
return nil
|
2024-12-27 14:43:21 -06:00
|
|
|
}
|