autogenpb/sort.go

38 lines
694 B
Go

package main
import (
"fmt"
"os"
)
// this file is named poorly. It has more than Sort()
func (pb *Files) makeNewSortfile(pf *File) error {
w, _ := os.OpenFile(pf.Filebase+".sort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
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"
}
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)
return nil
}