builds and runs again

This commit is contained in:
Jeff Carr 2025-01-09 15:51:45 -06:00
parent 455377e30a
commit 65aa8e85b1
4 changed files with 38 additions and 19 deletions

View File

@ -6,7 +6,6 @@ full: clean auto goimports vet build
vet:
@GO111MODULE=off go vet
@echo this go binary package should build okay
build:
rm -f fruit.newsort.pb.go

View File

@ -1,26 +1,26 @@
package main
import (
"fmt"
"os"
"strings"
"go.wit.com/log"
)
func (pb *Files) makeNewSortfile(pf *File) {
func (pb *Files) makeNewSortfile(pf *File) error {
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.Bases == nil {
return fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
}
if pf.Base != nil {
log.Info("THIS IS WHAT BASE?", pf.Base.Name, pf.Base)
if pf.Base == nil {
return fmt.Errorf("Base was nil. 'message %s {` did not exist", pf.Filebase)
}
pf.Base.iterTop(f)
pf.Base.iterNext(f)
}
/*
for _, msg := range pf.MsgNames {
@ -35,8 +35,8 @@ func (pb *Files) makeNewSortfile(pf *File) {
}
*/
// pf.appendUnique(f, msg, sortmap) // Append() enforce no unique keys
return
pf.appendUnique(f, nil, sortmap) // Append() enforce no unique keys
return nil
// iterSortAll(f, sortmap)
if argv.Append != "" {
@ -74,4 +74,5 @@ func (pb *Files) makeNewSortfile(pf *File) {
iterFind(f, sortmap)
}
iterEnd(f, sortmap)
return nil
}

View File

@ -122,7 +122,7 @@ func (f *File) parseForMessage(line string) *MsgName {
log.Info("found messge:", msgName)
msg := new(MsgName)
msg.Name = msgName
msg.Lockname = msgName + "Mu"
msg.Lockname = f.Filebase + "Mu" // this should be lowercase. do not export the Mutex
if strings.Contains(line, "`autogenpb:mutex`") {
msg.DoMutex = true

31
sort.go
View File

@ -185,14 +185,15 @@ func iterEnd(w io.Writer, names map[string]string) {
func iterAppend(w io.Writer, names map[string]string) {
}
func (pf *File) appendUnique(w io.Writer, msg *MsgName, names map[string]string) {
var MSG string = msg.Name // msg.Name
func (pf *File) appendUnique(w io.Writer, blah *MsgName, names map[string]string) {
var MSG string = pf.Bases.Name
var BASE string = names["Base"]
var LOCK string = names["lock"]
var LOCK string = pf.Bases.Lockname
if argv.Mutex {
LOCK = "Lock"
LOCK = pf.Bases.Name + ".Lock"
} else {
LOCK = names["lock"] + ".Lock"
LOCK = "all.Lock"
}
fmt.Fprintln(w, "// enforces "+BASE+" is unique")
@ -201,7 +202,7 @@ func (pf *File) appendUnique(w io.Writer, msg *MsgName, names map[string]string)
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " for _, p := range all."+MSG+" {")
for _, KEY := range msg.Unique {
for _, KEY := range pf.Base.Unique {
fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {")
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, " }")
@ -212,6 +213,24 @@ func (pf *File) appendUnique(w io.Writer, msg *MsgName, names map[string]string)
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
for _, KEY := range pf.Base.Unique {
fmt.Fprintln(w, "// enforces "+BASE+" is unique")
fmt.Fprintln(w, "func (all *"+MSG+") AppendUnique"+KEY+"(newP *"+BASE+") bool {")
fmt.Fprintln(w, " "+LOCK+".RLock()")
fmt.Fprintln(w, " defer "+LOCK+".RUnlock()")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " for _, p := range all."+MSG+" {")
fmt.Fprintln(w, " if p."+KEY+" == newP."+KEY+" {")
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
fmt.Fprintln(w, " all."+MSG+" = append(all."+MSG+", newP)")
fmt.Fprintln(w, " return true")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
}
}
func iterReplace(w io.Writer, names map[string]string) {