summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-29 13:36:56 -0500
committerJeff Carr <[email protected]>2025-03-29 13:36:56 -0500
commit3b43eea6a39f3b64459ff6f82b28adafbaf26e8d (patch)
treeb692822ea343cd85fe70c38d46bc55ed1069ec26
parent79e59bef1164b0c6ebeea9f040438d1b9caa1aaf (diff)
closer to working on Signal-Desktop proto files
-rw-r--r--Makefile5
-rw-r--r--example/Makefile3
-rw-r--r--protoReformat.go62
3 files changed, 16 insertions, 54 deletions
diff --git a/Makefile b/Makefile
index 67794f9..0a8a695 100644
--- a/Makefile
+++ b/Makefile
@@ -110,6 +110,11 @@ reformat-signal.proto-full: goimports vet build
make -C example proto-reformat-restore
make -C example proto-reformat-full
+reformat-signal.proto-full-debug: goimports vet build
+ git checkout example/*.proto
+ make -C example proto-reformat-restore
+ make -C example proto-reformat-full-debug
+
reformat-signal.proto-fruit: goimports vet build
git checkout example/*.proto
make -C example proto-reformat-fruit
diff --git a/example/Makefile b/example/Makefile
index 1ddb086..0f4afa5 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -110,6 +110,9 @@ proto-reformat-comments:
../autogenpb --proto signal.proto --format-comments
proto-reformat-full:
+ ../autogenpb --proto signal.proto --format
+
+proto-reformat-full-debug:
../autogenpb --proto signal.proto --format --debug
proto-reformat-fruit:
diff --git a/protoReformat.go b/protoReformat.go
index af64f87..1f04680 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -17,6 +17,7 @@ import (
// like 'goimport', but for .proto files
var allTheLines *LinesScanner
+var allTheNewLines []string
/*
type EnumMessage struct {
@@ -67,43 +68,6 @@ func protoReformat(filename string) error {
var newfile string
- // var bigName int64
- // var bigType int64
-
- // var fmtmsg *FormatMsg
- // fmtmsg = new(FormatMsg)
-
- /*
- var allLinesIter iter.Seq[string]
- allLinesIter = makeLineIter(data)
- // gets the max vartype and varname
- for line := range allLinesIter {
- if strings.HasPrefix(line, "message ") {
- inMessage = true
- continue
- }
-
- // find the end of the message
- if strings.HasPrefix(line, "}") {
- inMessage = false
- setMaxSizes(fmtmsg)
- if bigName < fmtmsg.MaxVarname {
- bigName = fmtmsg.MaxVarname
- }
- if bigType < fmtmsg.MaxVartype {
- bigType = fmtmsg.MaxVartype
- }
- fmtmsg = new(FormatMsg)
- continue
- }
-
- // don't format or change anything when not in a "message {" section
- if !inMessage {
- continue
- }
- }
- */
-
basemsg := doParse(strings.Split(string(data), "\n"))
for _, newline := range basemsg.format() {
@@ -301,21 +265,6 @@ func makeLineIter(data []byte) iter.Seq[string] {
}
}
-/*
-// func loadEnumDefinition(newMsg *EnumMessage) *EnumMessage {
-func (newMsg *EnumMessage) load() {
- curPB := newMsg.msgPB
- for allTheLines.Scan() {
- line := allTheLines.Next()
- if strings.HasPrefix(line, "}") {
- curPB.Footer = line
- return
- }
- curPB.Lines = append(curPB.Lines, line)
- }
-}
-*/
-
// find the max length of varname and vartype
func setMaxSizes(curmsg *FormatMsg) {
for _, line := range curmsg.Lines {
@@ -504,13 +453,18 @@ func formatMessage(curmsg *FormatMsg) []string {
mt := fmt.Sprintf("%d", curmsg.MaxVartype)
mv := fmt.Sprintf("%d", curmsg.MaxVarname)
- hmm := " %-" + mt + "s %-" + mv + "s = %-3s %s"
+ hmm := "%s%-" + mt + "s %-" + mv + "s = %-3s %s"
vartype, varname, id, end := tokenMsgVar(line)
end = strings.TrimSpace(end)
id = id + ";"
- newline := fmt.Sprintf(hmm, vartype, varname, id, end)
+ var newline string
+ if argv.Debug {
+ newline = fmt.Sprintf(hmm+" //depth=%d", curmsg.padding(0), vartype, varname, id, end, curmsg.Depth)
+ } else {
+ newline = fmt.Sprintf(hmm, curmsg.padding(0), vartype, varname, id, end)
+ }
newline = strings.TrimRight(newline, " ")
newmsg = append(newmsg, newline)
}