summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-10 13:52:04 -0500
committerJeff Carr <[email protected]>2025-03-10 13:52:04 -0500
commit63a3d0dc2439802ca3bf8db92d095733db6b7b7e (patch)
tree9d85dd98eeb7175ff06bb55e5743ad2ea0408f94
parenta496b7abf77f4975962488eb0adb28b23b61a305 (diff)
adding more table pb optionsv0.0.65
-rw-r--r--example/fruit.proto4
-rw-r--r--file.proto2
-rw-r--r--generateGui.go81
-rw-r--r--protoParse.go24
4 files changed, 93 insertions, 18 deletions
diff --git a/example/fruit.proto b/example/fruit.proto
index 4545e03..362c59b 100644
--- a/example/fruit.proto
+++ b/example/fruit.proto
@@ -21,8 +21,8 @@ message Apple {
google.protobuf.Timestamp ctime = 3; // when the apple was born
}
-message Apples {
- string name = 1; // `autogenpb:unique` // generates SortByxxx() and AppendUnique() functions
+message Apples { // `autogenpb:gui:Apple`
+ string name = 1; // `autogenpb:unique`
string genus = 2; // `autogenpb:unique` // generates same thing here but SortByGenus()
repeated Apple apples = 3;
}
diff --git a/file.proto b/file.proto
index 01c9d39..a947826 100644
--- a/file.proto
+++ b/file.proto
@@ -46,6 +46,8 @@ message MsgName {
bool needIter = 10; // true if the sort iterator has not been generated yet
bool needAll = 11; // true if the sort iterator has not been generated yet
bool noMutex = 12; // only use the global mutex
+ bool doGui = 13; // if a gui.pb.go file should be created
+ string guiVarName = 14; // the name of the variable to use
}
message Sort {
diff --git a/generateGui.go b/generateGui.go
index 4f12a67..86d6179 100644
--- a/generateGui.go
+++ b/generateGui.go
@@ -32,22 +32,82 @@ func (pb *Files) makeGuiFile(pf *File) error {
fmt.Fprintf(newf, "// START GUI\n")
fmt.Fprintf(newf, "\n")
- guiMain(newf, pf.Bases.Name, pf.Base.Name)
- guiStringFuncs(newf, pf.Package, pf.Bases.Name, pf.Base.Name)
+ /*
+ FRUITS := pf.Bases.Name
+ FRUIT := pf.Base.Name
+ fruitVars := pf.Base.Vars
+ pf.generateAutoTablePB(newf, FRUITS, FRUIT, fruitVars)
+ */
+
+ for _, msg := range pf.allMsg() {
+ if msg.DoGui {
+ color := pf.findMsg(msg.GuiVarName)
+ if color == nil {
+ return fmt.Errorf("failed to find struct %s", msg.GuiVarName)
+ }
+ FRUITS := msg.Name
+ FRUIT := msg.GuiVarName
+ fruitVars := color.Vars
+ pf.generateAutoTablePB(newf, FRUITS, FRUIT, fruitVars)
+ log.Printf("NEED TO ADD GUI FOR %s with var %s and found msg struct %s\n", msg.Name, msg.GuiVarName, color.Lockname)
+ }
+ }
+ // os.Exit(-1)
+
+ /*
+ guiMain(newf, pf.Bases.Name, pf.Base.Name)
+ guiStringFuncs(newf, pf.Package, pf.Bases.Name, pf.Base.Name)
- for _, v := range pf.Base.Vars {
+ for _, v := range pf.Base.Vars {
+ if v.IsRepeated {
+ // can't work against slices
+ continue
+ }
+ if v.VarType == "string" {
+ log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
+ guiAddStringFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
+ continue
+ }
+ if v.VarType == "int64" {
+ log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
+ guiAddIntFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
+ continue
+ }
+ }
+ FRUITS := pf.Bases.Name
+ FRUIT := pf.Base.Name
+ fRUITS := untitle(pf.Bases.Name)
+ fRUIT := untitle(pf.Base.Name)
+ guiUpdate(newf, FRUITS, FRUIT)
+ guiTableDelete(newf, FRUITS, FRUIT)
+ guiTableCustom(newf, FRUITS, fRUITS, FRUIT, fRUIT)
+ */
+
+ fmt.Fprintf(newf, "\n")
+ fmt.Fprintf(newf, "// END GUI\n")
+ return nil
+}
+
+func (pf *File) generateAutoTablePB(newf *os.File, FRUITS string, FRUIT string, fruitVars []*MsgVar) {
+ fRUITS := untitle(FRUITS)
+ fRUIT := untitle(FRUIT)
+
+ guiMain(newf, FRUITS, FRUIT)
+ guiStringFuncs(newf, pf.Package, FRUITS, FRUIT)
+
+ for _, v := range fruitVars {
if v.IsRepeated {
// can't work against slices
continue
}
if v.VarType == "string" {
- log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
- guiAddStringFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
+ log.Printf("make Add function here %s %s %s\n", FRUITS, FRUIT, v.VarName)
+ guiAddStringFunc(newf, FRUITS, FRUIT, v.VarName)
continue
}
if v.VarType == "int64" {
- log.Printf("make Add function here %s %s %s\n", pf.Bases.Name, pf.Base.Name, v.VarName)
- guiAddIntFunc(newf, pf.Bases.Name, pf.Base.Name, v.VarName)
+ log.Printf("make Add function here %s %s %s\n", FRUITS, FRUIT, v.VarName)
+ guiAddIntFunc(newf, FRUITS, FRUIT, v.VarName)
continue
}
/*
@@ -63,17 +123,10 @@ func (pb *Files) makeGuiFile(pf *File) error {
log.Printf("Adding %s\n", funcdef)
*/
}
- FRUITS := pf.Bases.Name
- FRUIT := pf.Base.Name
- fRUITS := untitle(pf.Bases.Name)
- fRUIT := untitle(pf.Base.Name)
guiUpdate(newf, FRUITS, FRUIT)
guiTableDelete(newf, FRUITS, FRUIT)
guiTableCustom(newf, FRUITS, fRUITS, FRUIT, fRUIT)
- fmt.Fprintf(newf, "\n")
- fmt.Fprintf(newf, "// END GUI\n")
- return nil
}
func headerGui(w io.Writer, pf *File) {
diff --git a/protoParse.go b/protoParse.go
index ba1ff4c..79f36df 100644
--- a/protoParse.go
+++ b/protoParse.go
@@ -54,6 +54,7 @@ func (pf *File) protoParse() error {
if curmsg == nil {
// log.Info("curmsg == nil", line)
// can't contiue on nil below here
+ // TODO: look for and format enum structs here
continue
}
// log.Info("curmsg != nil", line)
@@ -153,6 +154,7 @@ func parseMsgVar(line string) *MsgVar {
func (pf *File) parseForMessage(line string) *MsgName {
fields := strings.Fields(line)
if len(fields) == 0 || fields[0] != "message" {
+ // this line doesn't start with message
return nil
}
var msg *MsgName
@@ -189,10 +191,28 @@ func (pf *File) parseForMessage(line string) *MsgName {
msg.DoMarshal = true
// log.Info("Added Marshal=true:", msg.Name)
}
- if strings.Contains(line, "autogenpb:gui") {
+ if strings.Contains(line, "`autogenpb:gui") {
log.Info("got autogenpb:gui")
pf.DoGui = true
- // os.Exit(-1)
+ msg.DoGui = true
+ parts := strings.Split(line, "autogenpb:gu")
+ if len(parts) != 2 {
+ log.Info("len(parts) != 2", line)
+ os.Exit(-1)
+ }
+ log.Info("line =", line)
+ log.Info("end =", parts[1])
+ end := strings.Split(parts[1], "`")
+ if end[0] != "i" {
+ varname := strings.TrimPrefix(end[0], "i:")
+ msg.GuiVarName = varname
+ log.Info("varname =", varname)
+ } else {
+ if strings.HasSuffix(msgName, "s") {
+ varname := strings.TrimSuffix(msgName, "s")
+ msg.GuiVarName = varname
+ }
+ }
}
return msg
}