autogenpb/sort.go

38 lines
694 B
Go
Raw Normal View History

package main
import (
2025-01-10 04:22:53 -06:00
"fmt"
"os"
)
2025-01-10 04:22:53 -06:00
// this file is named poorly. It has more than Sort()
2025-01-09 15:51:45 -06:00
func (pb *Files) makeNewSortfile(pf *File) error {
2025-01-10 04:22:53 -06:00
w, _ := os.OpenFile(pf.Filebase+".sort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
2025-01-10 04:22:53 -06:00
header(w, pf)
pf.syncLock(w)
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-10 04:22:53 -06:00
pf.Base.iterTop(w)
pf.Base.iterNext(w)
pf.selectAllFunc(w)
pf.iterSelect(w)
fmt.Fprintln(w, "// maybe seperate files here?")
pf.appendUnique(w) // Append() enforce no unique keys
pf.sortByFunc(w)
if argv.Delete {
pf.deleteWithCopyFunc(w)
} else {
pf.deleteFunc(w)
}
pf.findFunc(w)
2025-01-09 15:51:45 -06:00
return nil
}