closer to working on Signal-Desktop proto files

This commit is contained in:
Jeff Carr 2025-03-29 13:36:56 -05:00
parent 79e59bef11
commit 3b43eea6a3
3 changed files with 16 additions and 54 deletions

View File

@ -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

View File

@ -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:

View File

@ -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)
}