summaryrefslogtreecommitdiff
path: root/protoReformat.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-26 03:36:05 -0500
committerJeff Carr <[email protected]>2025-03-26 20:44:06 -0500
commit7a68c6247ae72ef4a22fb3b1e767c9f15fc67b82 (patch)
treeebecc0963bfb8190067447223c91706da3d87b48 /protoReformat.go
parent2775e36aa4e981a4a052b6f15148b61b0f13a2f7 (diff)
first part done
Diffstat (limited to 'protoReformat.go')
-rw-r--r--protoReformat.go35
1 files changed, 23 insertions, 12 deletions
diff --git a/protoReformat.go b/protoReformat.go
index 1739288..44426aa 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -27,13 +27,15 @@ func protoReformat(filename string) error {
}
var inMessage bool
- var curmsg []string
var newfile string
var fmtmsg *FormatMsg
fmtmsg = new(FormatMsg)
linesIter = makeLineIter(data)
+ var bigName int64
+ var bigType int64
+
// gets the max vartype and varname
for line := range linesIter {
if strings.HasPrefix(line, "message ") {
@@ -44,9 +46,14 @@ func protoReformat(filename string) error {
// find the end of the message
if strings.HasPrefix(line, "}") {
inMessage = false
- formatMessage(curmsg)
+ // formatMessage(curmsg)
formatMessage2(fmtmsg)
- curmsg = nil
+ if bigName < fmtmsg.MaxVarname {
+ bigName = fmtmsg.MaxVarname
+ }
+ if bigType < fmtmsg.MaxVartype {
+ bigType = fmtmsg.MaxVartype
+ }
fmtmsg = new(FormatMsg)
continue
}
@@ -55,10 +62,14 @@ func protoReformat(filename string) error {
if !inMessage {
continue
}
- curmsg = append(curmsg, line)
fmtmsg.Lines = append(fmtmsg.Lines, line)
}
+ maxVarname = int(bigName)
+ maxVartype = int(bigType)
+
+ var curmsg []string
+
// gets the max vartype and varname
for line := range linesIter {
if strings.HasPrefix(line, "message ") {
@@ -71,7 +82,7 @@ func protoReformat(filename string) error {
// hack to actually indent comments on the message line itself. you're welcome
start := parts[0] + " " + parts[1] + " " + parts[2]
end := strings.Join(parts[3:], " ")
- offset := maxVarname + maxVartype + 16 - len(start)
+ offset := int(bigName) + int(bigType) + 16 - len(start)
pad := fmt.Sprintf("%d", offset)
hmm := "%s %" + pad + "s %s"
line = fmt.Sprintf(hmm, start, " ", end)
@@ -218,11 +229,11 @@ func formatMessage2(curmsg *FormatMsg) []string {
}
vartype, varname, _, _ := tokenMsgVar(line)
- if len(vartype) > maxVartype {
- maxVartype = len(vartype)
+ if len(vartype) > int(curmsg.MaxVartype) {
+ curmsg.MaxVartype = int64(len(vartype))
}
- if len(varname) > maxVarname {
- maxVarname = len(varname)
+ if len(varname) > int(curmsg.MaxVarname) {
+ curmsg.MaxVarname = int64(len(varname))
}
}
@@ -233,14 +244,14 @@ func formatMessage2(curmsg *FormatMsg) []string {
continue
}
if strings.HasPrefix(line, "//") {
- pad := fmt.Sprintf("%d", maxVartype+maxVarname+21)
+ pad := fmt.Sprintf("%d", curmsg.MaxVartype+curmsg.MaxVarname+21)
hmm := "%" + pad + "s %s"
line = fmt.Sprintf(hmm, " ", line) // todo: compute 50
newmsg = append(newmsg, line)
continue
}
- mt := fmt.Sprintf("%d", maxVartype)
- mv := fmt.Sprintf("%d", maxVarname)
+ mt := fmt.Sprintf("%d", curmsg.MaxVartype)
+ mv := fmt.Sprintf("%d", curmsg.MaxVarname)
hmm := " %-" + mt + "s %-" + mv + "s = %-3s %s"