closer to working on Signal-Desktop proto files
This commit is contained in:
parent
79e59bef11
commit
3b43eea6a3
5
Makefile
5
Makefile
|
@ -110,6 +110,11 @@ reformat-signal.proto-full: goimports vet build
|
||||||
make -C example proto-reformat-restore
|
make -C example proto-reformat-restore
|
||||||
make -C example proto-reformat-full
|
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
|
reformat-signal.proto-fruit: goimports vet build
|
||||||
git checkout example/*.proto
|
git checkout example/*.proto
|
||||||
make -C example proto-reformat-fruit
|
make -C example proto-reformat-fruit
|
||||||
|
|
|
@ -110,6 +110,9 @@ proto-reformat-comments:
|
||||||
../autogenpb --proto signal.proto --format-comments
|
../autogenpb --proto signal.proto --format-comments
|
||||||
|
|
||||||
proto-reformat-full:
|
proto-reformat-full:
|
||||||
|
../autogenpb --proto signal.proto --format
|
||||||
|
|
||||||
|
proto-reformat-full-debug:
|
||||||
../autogenpb --proto signal.proto --format --debug
|
../autogenpb --proto signal.proto --format --debug
|
||||||
|
|
||||||
proto-reformat-fruit:
|
proto-reformat-fruit:
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
// like 'goimport', but for .proto files
|
// like 'goimport', but for .proto files
|
||||||
|
|
||||||
var allTheLines *LinesScanner
|
var allTheLines *LinesScanner
|
||||||
|
var allTheNewLines []string
|
||||||
|
|
||||||
/*
|
/*
|
||||||
type EnumMessage struct {
|
type EnumMessage struct {
|
||||||
|
@ -67,43 +68,6 @@ func protoReformat(filename string) error {
|
||||||
|
|
||||||
var newfile string
|
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"))
|
basemsg := doParse(strings.Split(string(data), "\n"))
|
||||||
|
|
||||||
for _, newline := range basemsg.format() {
|
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
|
// find the max length of varname and vartype
|
||||||
func setMaxSizes(curmsg *FormatMsg) {
|
func setMaxSizes(curmsg *FormatMsg) {
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
|
@ -504,13 +453,18 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
mt := fmt.Sprintf("%d", curmsg.MaxVartype)
|
mt := fmt.Sprintf("%d", curmsg.MaxVartype)
|
||||||
mv := fmt.Sprintf("%d", curmsg.MaxVarname)
|
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)
|
vartype, varname, id, end := tokenMsgVar(line)
|
||||||
end = strings.TrimSpace(end)
|
end = strings.TrimSpace(end)
|
||||||
id = id + ";"
|
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, " ")
|
newline = strings.TrimRight(newline, " ")
|
||||||
newmsg = append(newmsg, newline)
|
newmsg = append(newmsg, newline)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue