summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-29 11:55:54 -0500
committerJeff Carr <[email protected]>2025-03-29 11:55:54 -0500
commit79e59bef1164b0c6ebeea9f040438d1b9caa1aaf (patch)
treebbb6414d924a2b3e520da6d2b43331b3362cd1db
parent0a97886cd2e942070ac478b2802f49dca8249f36 (diff)
used autogenpb to reformat file.proto
-rw-r--r--Makefile8
-rw-r--r--file.proto21
-rw-r--r--protoReformat.go47
3 files changed, 45 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index b15cd9a..67794f9 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ build:
cp -f autogenpb autogenpb.${BUILDTIME}
bak:
- cp -f autogenpb autogenpb.last
+ -cp -f autogenpb autogenpb.last
redo-protobuf:
rm -f *.pb.go
@@ -63,9 +63,13 @@ proto:
#
# use the current autogenpb
-proto-local: bak clean
+proto-local-noformat: bak clean
./autogenpb.last --proto file.proto --package main --no-format
+# use the current autogenpb
+proto-local-format: bak clean
+ ./autogenpb.last --proto file.proto --package main
+
junk:
cd example; rm -f go.* *.pb.go
cd example; ../autogenpb --proto file.proto --package yellow
diff --git a/file.proto b/file.proto
index a8313de..a13a94e 100644
--- a/file.proto
+++ b/file.proto
@@ -25,6 +25,7 @@ package main;
// it needs in these protobuf files, then it processes the
// protobuf files to write out *.sort.pb.go and *.marshal.pb.go files
//
+
message MsgVar {
string varName = 1; // the variable name
string varType = 2; // the variable type
@@ -58,15 +59,14 @@ message Sort {
string lockname = 4; //
bool needAll = 5; //
}
-
// used to auto-format protobuf files
message FormatMsg {
- enum Type {
- MESSAGE = 0;
- ENUM = 1;
- ONEOF = 2;
- VAR = 3;
- }
+ enum Type {
+ MESSAGE = 0;
+ ENUM = 1;
+ ONEOF = 2;
+ VAR = 3;
+ }
int64 depth = 1; // used to indent output
int64 maxVarname = 2; // max string length of var names
@@ -76,7 +76,7 @@ message FormatMsg {
repeated FormatMsg msgs = 6; // locally defined messages and enums
repeated string lines = 7; // the variables
string footer = 8; // the '}' line
- Type type = 9; // yep. type. yep. that's what this is for
+ Type type = 9; // yep. type. yep. that's what this is for
}
message Find {
@@ -86,7 +86,7 @@ message Find {
bool needAll = 4; //
}
-message File { // `autogenpb:var:w io.Writer`
+message File { // `autogenpb:var:w io.Writer`
string Package = 1; // whatever the package name is at the top of the .go file
string filename = 2; // yellow.proto
string pbfilename = 3; // yellow.pb.go
@@ -104,7 +104,6 @@ message File { // `autogenpb:var:w io.Writer`
string goPath = 13; // the version to use in a func NewMsgName()
bool doGui = 14; // if a gui.pb.go file should be created
}
-
// I know, I know, the whole point of using protobuf
// is so you don't need a uuid or versions because it's
// inherently forward compatable. nonetheless, a simple stubbed out
@@ -116,10 +115,10 @@ message Files { // `autogenpb:marshal`
string version = 2; // `autogenpb:version:v0.0.38`
repeated File Files = 3; // an array of each .proto file in the working directory
}
-
// this generic message is used by autogen to identify and
// then dump the uuid and version from any arbitrary .pb file
message Identify { // `autogenpb:marshal`
string uuid = 1; //
string version = 2; //
}
+// footer was empty
diff --git a/protoReformat.go b/protoReformat.go
index efd568b..af64f87 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -29,17 +29,6 @@ type StdMessage struct {
all []Message
}
-func (msg *EnumMessage) name() string {
- return "fuckit enum"
-}
-
-func (msg *StdMessage) name() string {
- if msg.msgPB != nil {
- return msg.msgPB.Header
- }
- return "fuckit std"
-}
-
type Message interface {
name() string
load()
@@ -197,7 +186,7 @@ func newDepth(fmtmsg *FormatMsg, header string) *FormatMsg {
newmsg := new(FormatMsg)
newmsg.MaxVarname = fmtmsg.MaxVarname
newmsg.MaxVartype = fmtmsg.MaxVartype
- newmsg.Header = header
+ newmsg.Header = strings.TrimSpace(header)
newmsg.Depth = fmtmsg.Depth + 1
return newmsg
@@ -364,18 +353,40 @@ func (msg *FormatMsg) pad() string {
return pad
}
+func (msg *FormatMsg) padding(offset int) string {
+ var pad string
+ for i := offset; i < int(msg.Depth); i += 1 {
+ pad += fmt.Sprintf("%8s", " ")
+ }
+ return pad
+}
+
func formatEnum(curmsg *FormatMsg) []string {
var newmsg []string
- header := fmt.Sprintf("%s%s // enum depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
- newmsg = append(newmsg, header)
+ if argv.Debug {
+ header := fmt.Sprintf("%s%s // enum2 depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
+ newmsg = append(newmsg, header)
+ header = fmt.Sprintf("//%s//%s// enum2 depth=%d", curmsg.padding(2), curmsg.Header, curmsg.Depth)
+ newmsg = append(newmsg, header)
+ header = fmt.Sprintf("// %s", curmsg.Header)
+ newmsg = append(newmsg, header)
+ } else {
+ header := fmt.Sprintf("%s%s", curmsg.padBase(), curmsg.Header)
+ newmsg = append(newmsg, header)
+ }
for _, line := range curmsg.Lines {
line = fmt.Sprintf("%s%s", curmsg.pad(), line)
newmsg = append(newmsg, line)
}
- footer := fmt.Sprintf("%s%s // enum footer depth=%d", curmsg.padBase(), curmsg.Footer, curmsg.Depth)
- newmsg = append(newmsg, footer)
+ if argv.Debug {
+ footer := fmt.Sprintf("%s%s // enum2 footer depth=%d", curmsg.padBase(), curmsg.Footer, curmsg.Depth)
+ newmsg = append(newmsg, footer)
+ } else {
+ footer := fmt.Sprintf("%s%s", curmsg.padBase(), curmsg.Footer)
+ newmsg = append(newmsg, footer)
+ }
return newmsg
}
@@ -465,12 +476,12 @@ func formatMessage(curmsg *FormatMsg) []string {
switch msg.Type {
case FormatMsg_ENUM:
for _, line := range formatEnum(msg) {
- line = fmt.Sprintf("%s%s", curmsg.pad(), line)
+ // line = fmt.Sprintf("%s%s", curmsg.pad(), line)
newmsg = append(newmsg, line)
}
case FormatMsg_MESSAGE:
for _, line := range msg.format() {
- line = fmt.Sprintf("%s%s", curmsg.pad(), line)
+ // line = fmt.Sprintf("%s%s", curmsg.pad(), line)
newmsg = append(newmsg, line)
}
default: