enum footer fix
This commit is contained in:
parent
81b4b453e7
commit
5876518571
3
Makefile
3
Makefile
|
@ -91,3 +91,6 @@ clean:
|
||||||
clean-more:
|
clean-more:
|
||||||
ls -l autogenpb autogenpb.last
|
ls -l autogenpb autogenpb.last
|
||||||
-rm -f autogenpb.2*
|
-rm -f autogenpb.2*
|
||||||
|
|
||||||
|
Signal-Desktop:
|
||||||
|
autogenpb --proto SignalService.proto --format
|
||||||
|
|
|
@ -18,6 +18,12 @@ import (
|
||||||
|
|
||||||
var allTheLines *LinesScanner
|
var allTheLines *LinesScanner
|
||||||
|
|
||||||
|
type Messages interface {
|
||||||
|
format() []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var allMessages []Messages
|
||||||
|
|
||||||
func protoReformat(filename string) error {
|
func protoReformat(filename string) error {
|
||||||
// read in the .proto file
|
// read in the .proto file
|
||||||
data, err := os.ReadFile(filename)
|
data, err := os.ReadFile(filename)
|
||||||
|
@ -78,34 +84,17 @@ func protoReformat(filename string) error {
|
||||||
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
fmtmsg.Lines = append(fmtmsg.Lines, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmtmsg = new(FormatMsg)
|
|
||||||
fmtmsg.MaxVarname = bigName
|
|
||||||
fmtmsg.MaxVartype = bigType
|
|
||||||
|
|
||||||
// getMessage(fmtmsg)
|
|
||||||
|
|
||||||
// write out the messages
|
// write out the messages
|
||||||
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
|
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
/*
|
|
||||||
if inMessage {
|
|
||||||
// message inception. search for the architect. don't forget your totem
|
|
||||||
newmsg := new(FormatMsg)
|
newmsg := new(FormatMsg)
|
||||||
newmsg.MaxVarname = bigName
|
newmsg.MaxVarname = bigName
|
||||||
newmsg.MaxVartype = bigType
|
newmsg.MaxVartype = bigType
|
||||||
newmsg.Lines = append(newmsg.Lines, line)
|
newmsg.Header = line
|
||||||
getInceptionEnum(newmsg)
|
loadEnumDefinition(newmsg)
|
||||||
fmtmsg.Enums = append(fmtmsg.Oneofs, newmsg)
|
allMessages = append(allMessages, newmsg)
|
||||||
continue
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
newmsg := new(FormatMsg)
|
|
||||||
newmsg.MaxVarname = bigName
|
|
||||||
newmsg.MaxVartype = bigType
|
|
||||||
newmsg.Lines = append(newmsg.Lines, line)
|
|
||||||
getInceptionEnum(newmsg)
|
|
||||||
for _, newline := range formatMessage(newmsg) {
|
for _, newline := range formatMessage(newmsg) {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
|
@ -113,23 +102,11 @@ func protoReformat(filename string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
/*
|
|
||||||
if inMessage {
|
|
||||||
// message inception. search for the architect. don't forget your totem
|
|
||||||
newmsg := new(FormatMsg)
|
|
||||||
newmsg.MaxVarname = bigName
|
|
||||||
newmsg.MaxVartype = bigType
|
|
||||||
newmsg.Lines = append(newmsg.Lines, line)
|
|
||||||
getInceptionEnum(newmsg)
|
|
||||||
fmtmsg.Enums = append(fmtmsg.Enums, newmsg)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
newmsg := new(FormatMsg)
|
newmsg := new(FormatMsg)
|
||||||
newmsg.MaxVarname = bigName
|
newmsg.MaxVarname = bigName
|
||||||
newmsg.MaxVartype = bigType
|
newmsg.MaxVartype = bigType
|
||||||
newmsg.Header = line
|
newmsg.Header = line
|
||||||
getInceptionEnum(newmsg)
|
loadEnumDefinition(newmsg)
|
||||||
for _, newline := range formatEnum(newmsg) {
|
for _, newline := range formatEnum(newmsg) {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
|
@ -142,23 +119,11 @@ func protoReformat(filename string) error {
|
||||||
newmsg.MaxVartype = bigType
|
newmsg.MaxVartype = bigType
|
||||||
newmsg.Header = line
|
newmsg.Header = line
|
||||||
|
|
||||||
getInceptionMsg(newmsg)
|
loadMsgDefinition(newmsg)
|
||||||
for _, newline := range formatMessage(newmsg) {
|
for _, newline := range formatMessage(newmsg) {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if inMessage {
|
|
||||||
// message inception. search for the architect. don't forget your totem
|
|
||||||
newmsg := new(FormatMsg)
|
|
||||||
newmsg.MaxVarname = bigName
|
|
||||||
newmsg.MaxVartype = bigType
|
|
||||||
newmsg.Lines = append(newmsg.Lines, line)
|
|
||||||
getInceptionMsg(newmsg)
|
|
||||||
fmtmsg.InceptionMsgs = append(fmtmsg.InceptionMsgs, newmsg)
|
|
||||||
continue
|
|
||||||
|
|
||||||
}
|
|
||||||
inMessage = true
|
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
if len(parts) > 3 {
|
if len(parts) > 3 {
|
||||||
// hack to actually indent comments on the message line itself. you're welcome
|
// hack to actually indent comments on the message line itself. you're welcome
|
||||||
|
@ -194,26 +159,24 @@ func saveFile(filename string, data string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInceptionMsg(fmtmsg *FormatMsg) {
|
func loadMsgDefinition(fmtmsg *FormatMsg) {
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
// message inception. search for the architect. don't forget your totem
|
|
||||||
newmsg := new(FormatMsg)
|
newmsg := new(FormatMsg)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
newmsg.MaxVarname = fmtmsg.MaxVarname
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||||
newmsg.Header = line
|
newmsg.Header = line
|
||||||
getInceptionEnum(newmsg)
|
loadEnumDefinition(newmsg)
|
||||||
fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
|
fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
// message inception. search for the architect. don't forget your totem
|
|
||||||
newmsg := new(FormatMsg)
|
newmsg := new(FormatMsg)
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
newmsg.MaxVarname = fmtmsg.MaxVarname
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||||
newmsg.Header = line
|
newmsg.Header = line
|
||||||
getInceptionEnum(newmsg)
|
loadEnumDefinition(newmsg)
|
||||||
fmtmsg.Enums = append(fmtmsg.Enums, newmsg)
|
fmtmsg.Enums = append(fmtmsg.Enums, newmsg)
|
||||||
// log.Info("got here:", line)
|
// log.Info("got here:", line)
|
||||||
// os.Exit(-1)
|
// os.Exit(-1)
|
||||||
|
@ -225,7 +188,7 @@ func getInceptionMsg(fmtmsg *FormatMsg) {
|
||||||
newmsg.MaxVarname = fmtmsg.MaxVarname
|
newmsg.MaxVarname = fmtmsg.MaxVarname
|
||||||
newmsg.MaxVartype = fmtmsg.MaxVartype
|
newmsg.MaxVartype = fmtmsg.MaxVartype
|
||||||
newmsg.Header = line
|
newmsg.Header = line
|
||||||
getInceptionMsg(newmsg)
|
loadMsgDefinition(newmsg)
|
||||||
fmtmsg.InceptionMsgs = append(fmtmsg.InceptionMsgs, newmsg)
|
fmtmsg.InceptionMsgs = append(fmtmsg.InceptionMsgs, newmsg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -281,11 +244,11 @@ func makeLineIter(data []byte) iter.Seq[string] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInceptionEnum(curmsg *FormatMsg) {
|
func loadEnumDefinition(curmsg *FormatMsg) {
|
||||||
for allTheLines.Scan() {
|
for allTheLines.Scan() {
|
||||||
line := allTheLines.Next()
|
line := allTheLines.Next()
|
||||||
if strings.HasPrefix(line, "}") {
|
if strings.HasPrefix(line, "}") {
|
||||||
curmsg.Lines = append(curmsg.Lines, line)
|
curmsg.Footer = line
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
curmsg.Lines = append(curmsg.Lines, line)
|
curmsg.Lines = append(curmsg.Lines, line)
|
||||||
|
@ -311,12 +274,16 @@ func setMaxSizes(curmsg *FormatMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (curmsg *FormatMsg) format() []string {
|
||||||
|
return formatEnum(curmsg)
|
||||||
|
}
|
||||||
|
|
||||||
func formatEnum(curmsg *FormatMsg) []string {
|
func formatEnum(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
||||||
|
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
line = strings.TrimSpace(line)
|
line = " " + strings.TrimSpace(line)
|
||||||
newmsg = append(newmsg, line)
|
newmsg = append(newmsg, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +293,21 @@ func formatEnum(curmsg *FormatMsg) []string {
|
||||||
|
|
||||||
func formatMessage(curmsg *FormatMsg) []string {
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
|
||||||
|
if curmsg.Header != "" {
|
||||||
|
line := curmsg.Header
|
||||||
|
parts := strings.Fields(line)
|
||||||
|
if len(parts) > 3 {
|
||||||
|
// 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 := int(curmsg.MaxVarname) + int(curmsg.MaxVartype) + 16 - len(start)
|
||||||
|
pad := fmt.Sprintf("%d", offset)
|
||||||
|
hmm := "%s %" + pad + "s %s"
|
||||||
|
line = fmt.Sprintf(hmm, start, " ", end)
|
||||||
|
}
|
||||||
|
newmsg = append(newmsg, line) // +" //header")
|
||||||
|
}
|
||||||
|
|
||||||
// find the max length of varname and vartype
|
// find the max length of varname and vartype
|
||||||
setMaxSizes(curmsg)
|
setMaxSizes(curmsg)
|
||||||
|
|
Loading…
Reference in New Issue