summaryrefslogtreecommitdiff
path: root/protoReformat.go
diff options
context:
space:
mode:
Diffstat (limited to 'protoReformat.go')
-rw-r--r--protoReformat.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/protoReformat.go b/protoReformat.go
index 44426aa..98f9c86 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -14,8 +14,8 @@ import (
// like 'goimport' but for .proto files
-var maxVarname int
-var maxVartype int
+// var maxVarname int
+// var maxVartype int
var linesIter iter.Seq[string]
func protoReformat(filename string) error {
@@ -46,7 +46,6 @@ func protoReformat(filename string) error {
// find the end of the message
if strings.HasPrefix(line, "}") {
inMessage = false
- // formatMessage(curmsg)
formatMessage2(fmtmsg)
if bigName < fmtmsg.MaxVarname {
bigName = fmtmsg.MaxVarname
@@ -65,12 +64,11 @@ func protoReformat(filename string) error {
fmtmsg.Lines = append(fmtmsg.Lines, line)
}
- maxVarname = int(bigName)
- maxVartype = int(bigType)
-
- var curmsg []string
+ fmtmsg = new(FormatMsg)
+ fmtmsg.MaxVarname = bigName
+ fmtmsg.MaxVartype = bigType
- // gets the max vartype and varname
+ // write out the messages
for line := range linesIter {
if strings.HasPrefix(line, "message ") {
if inMessage {
@@ -95,11 +93,13 @@ func protoReformat(filename string) error {
if strings.HasPrefix(line, "}") {
inMessage = false
// format and write the last message to the file
- for _, newline := range formatMessage(curmsg) {
+ for _, newline := range formatMessage2(fmtmsg) {
newfile += fmt.Sprintln(newline)
}
newfile += fmt.Sprintln(line)
- curmsg = nil
+ fmtmsg = new(FormatMsg)
+ fmtmsg.MaxVarname = bigName
+ fmtmsg.MaxVartype = bigType
continue
}
@@ -108,7 +108,8 @@ func protoReformat(filename string) error {
newfile += fmt.Sprintln(line)
continue
}
- curmsg = append(curmsg, line)
+
+ fmtmsg.Lines = append(fmtmsg.Lines, line)
}
pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
@@ -124,6 +125,7 @@ func protoReformat(filename string) error {
return nil
}
+/*
func formatMessage(curmsg []string) []string {
var newmsg []string
@@ -172,6 +174,7 @@ func formatMessage(curmsg []string) []string {
}
return newmsg
}
+*/
// returns vartype, varname, id, end
func tokenMsgVar(line string) (string, string, string, string) {