compiles example and it runs

This commit is contained in:
Jeff Carr 2025-01-09 15:29:27 -06:00
parent ff1721c250
commit 455377e30a
4 changed files with 43 additions and 23 deletions

View File

@ -1,8 +1,8 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
full: clean goimports auto vet build
./testfiles
full: clean auto goimports vet build
./example
vet:
@GO111MODULE=off go vet
@ -11,7 +11,6 @@ vet:
build:
rm -f fruit.newsort.pb.go
GO111MODULE=off go build
./testfiles
auto:
../autogenpb --proto fruit.proto --package main

View File

@ -12,19 +12,30 @@ func (pb *Files) makeNewSortfile(pf *File) {
header(f, pf)
for _, msg := range pf.MsgNames {
if msg.DoMutex {
msg.syncLock(f, msg.Lockname)
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
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)

View File

@ -27,14 +27,14 @@ func (pb *Files) hasPluralMessage(f *File) error {
line := scanner.Text()
base := cases.Title(language.English, cases.NoLower).String(f.Filebase)
prefix := "message " + base + "s" // to conform, it must have an added 's'
prefix := "message " + base + "s {" // to conform, it must have an added 's'
if !strings.HasPrefix(line, prefix) {
// log.Info("nope", prefix, "line", line)
// nope, not this line
continue
}
// found the matching message
// f.Bases = f.parseForMessage(line)
f.Bases = f.parseForMessage(line)
line = scanner.Text()
fields := strings.Fields(line)
@ -78,9 +78,9 @@ func (pb *Files) protoParse(f *File) error {
base := cases.Title(language.English, cases.NoLower).String(f.Filebase)
if strings.HasPrefix(line, "message ") {
curmsg = f.parseForMessage(line)
prefix := "message " + base // only look for this for now
prefix := "message " + base + " {" // only look for this for now
if strings.HasPrefix(line, prefix) {
// f.Base = curmsg
f.Base = curmsg
} else {
f.MsgNames = append(f.MsgNames, curmsg)
}
@ -118,7 +118,7 @@ func (f *File) parseForMessage(line string) *MsgName {
if fields[0] != "message" {
return nil
}
msgName := fields[1]
msgName := cases.Title(language.English, cases.NoLower).String(fields[1])
log.Info("found messge:", msgName)
msg := new(MsgName)
msg.Name = msgName

18
sort.go
View File

@ -5,6 +5,8 @@ import (
"io"
"os"
"strings"
"go.wit.com/log"
)
// passes in the protobuf file protobuf
@ -55,8 +57,12 @@ func (pb *Files) makeSortfile(pf *File) {
iterEnd(f, sortmap)
}
func (msg *MsgName) syncLock(w io.Writer, s string) {
var LOCK string = msg.Name
func (pf *File) syncLock(w io.Writer) {
if pf.Bases == nil {
log.Info("BASES == nil in syncLock")
return
}
var LOCK string = pf.Bases.Lockname
fmt.Fprintln(w, "// bad global lock until modifying the .pb.go file is tested")
fmt.Fprintln(w, "// sync.RWMutex or sync.Mutex?")
@ -64,7 +70,9 @@ func (msg *MsgName) syncLock(w io.Writer, s string) {
fmt.Fprintln(w, "")
}
func (pf *File) iterTop(w io.Writer, BASE string) {
func (msg *MsgName) iterTop(w io.Writer) {
var BASE string = msg.Name
fmt.Fprintln(w, "type "+BASE+"Iterator struct {")
fmt.Fprintln(w, " sync.RWMutex")
fmt.Fprintln(w, "")
@ -94,7 +102,9 @@ func (pf *File) iterTop(w io.Writer, BASE string) {
fmt.Fprintln(w, "")
}
func (pf *File) iterNext(w io.Writer, BASE string) {
func (msg *MsgName) iterNext(w io.Writer) {
var BASE string = msg.Name
fmt.Fprintln(w, "// Next() returns the next thing in the array")
fmt.Fprintln(w, "func (it *"+BASE+"Iterator) Next() *"+BASE+" {")
fmt.Fprintln(w, " if it.things[it.index-1] == nil {")