still not right
This commit is contained in:
parent
f3b9d40dfd
commit
255f08f81f
|
@ -25,7 +25,6 @@ func protoReformat(filename string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var inMessage bool
|
|
||||||
var newfile string
|
var newfile string
|
||||||
var fmtmsg *FormatMsg
|
var fmtmsg *FormatMsg
|
||||||
fmtmsg = new(FormatMsg)
|
fmtmsg = new(FormatMsg)
|
||||||
|
@ -33,6 +32,7 @@ func protoReformat(filename string) error {
|
||||||
var bigName int64
|
var bigName int64
|
||||||
var bigType int64
|
var bigType int64
|
||||||
|
|
||||||
|
var inMessage bool
|
||||||
var allLinesIter iter.Seq[string]
|
var allLinesIter iter.Seq[string]
|
||||||
allLinesIter = makeLineIter(data)
|
allLinesIter = makeLineIter(data)
|
||||||
// gets the max vartype and varname
|
// gets the max vartype and varname
|
||||||
|
@ -45,7 +45,7 @@ func protoReformat(filename string) error {
|
||||||
// find the end of the message
|
// find the end of the message
|
||||||
if strings.HasPrefix(line, "}") {
|
if strings.HasPrefix(line, "}") {
|
||||||
inMessage = false
|
inMessage = false
|
||||||
formatMessage2(fmtmsg)
|
setMaxSizes(fmtmsg)
|
||||||
if bigName < fmtmsg.MaxVarname {
|
if bigName < fmtmsg.MaxVarname {
|
||||||
bigName = fmtmsg.MaxVarname
|
bigName = fmtmsg.MaxVarname
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,9 @@ func protoReformat(filename string) error {
|
||||||
newmsg.MaxVartype = bigType
|
newmsg.MaxVartype = bigType
|
||||||
newmsg.Lines = append(newmsg.Lines, line)
|
newmsg.Lines = append(newmsg.Lines, line)
|
||||||
getInceptionEnum(newmsg)
|
getInceptionEnum(newmsg)
|
||||||
|
for _, newline := range formatMessage(newmsg) {
|
||||||
|
newfile += fmt.Sprintln(newline)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,17 +115,20 @@ func protoReformat(filename string) error {
|
||||||
newmsg.MaxVartype = bigType
|
newmsg.MaxVartype = bigType
|
||||||
newmsg.Header = line
|
newmsg.Header = line
|
||||||
getInceptionEnum(newmsg)
|
getInceptionEnum(newmsg)
|
||||||
|
for _, newline := range formatEnum(newmsg) {
|
||||||
|
newfile += fmt.Sprintln(newline)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, "message ") {
|
if strings.HasPrefix(line, "message ") {
|
||||||
newmsg := FormatMsg{
|
newmsg := new(FormatMsg)
|
||||||
MaxVarname: bigName,
|
newmsg.MaxVarname = bigName
|
||||||
MaxVartype: bigType,
|
newmsg.MaxVartype = bigType
|
||||||
Header: line,
|
newmsg.Header = line
|
||||||
}
|
|
||||||
getInceptionMsg(&newmsg)
|
getInceptionMsg(newmsg)
|
||||||
for _, newline := range formatMessage2(&newmsg) {
|
for _, newline := range formatMessage(newmsg) {
|
||||||
newfile += fmt.Sprintln(newline)
|
newfile += fmt.Sprintln(newline)
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -153,29 +159,7 @@ func protoReformat(filename string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// find the end of the message
|
|
||||||
if strings.HasPrefix(line, "}") {
|
|
||||||
inMessage = false
|
|
||||||
// format and write the last message to the file
|
|
||||||
for _, newline := range formatMessage2(fmtmsg) {
|
|
||||||
newfile += fmt.Sprintln(newline)
|
|
||||||
}
|
|
||||||
newfile += fmt.Sprintln(line)
|
newfile += fmt.Sprintln(line)
|
||||||
fmtmsg = new(FormatMsg)
|
|
||||||
fmtmsg.MaxVarname = bigName
|
|
||||||
fmtmsg.MaxVartype = bigType
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// don't format or change anything when not in a "message {" section
|
|
||||||
if !inMessage {
|
|
||||||
newfile += fmt.Sprintln(line)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmtmsg.Lines = append(fmtmsg.Lines, line)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
@ -285,11 +269,8 @@ func getInceptionEnum(curmsg *FormatMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatMessage2(curmsg *FormatMsg) []string {
|
|
||||||
var newmsg []string
|
|
||||||
|
|
||||||
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
|
||||||
// find the max length of varname and vartype
|
// find the max length of varname and vartype
|
||||||
|
func setMaxSizes(curmsg *FormatMsg) {
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
parts := strings.Split(line, ";")
|
parts := strings.Split(line, ";")
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
|
@ -305,6 +286,44 @@ func formatMessage2(curmsg *FormatMsg) []string {
|
||||||
curmsg.MaxVarname = int64(len(varname))
|
curmsg.MaxVarname = int64(len(varname))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatEnum(curmsg *FormatMsg) []string {
|
||||||
|
var newmsg []string
|
||||||
|
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
||||||
|
|
||||||
|
for _, line := range curmsg.Lines {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
newmsg = append(newmsg, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
newmsg = append(newmsg, curmsg.Footer) // +" //footer")
|
||||||
|
return newmsg
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
|
var newmsg []string
|
||||||
|
newmsg = append(newmsg, curmsg.Header) // +" //header")
|
||||||
|
|
||||||
|
// find the max length of varname and vartype
|
||||||
|
setMaxSizes(curmsg)
|
||||||
|
/*
|
||||||
|
for _, line := range curmsg.Lines {
|
||||||
|
parts := strings.Split(line, ";")
|
||||||
|
if len(parts) < 2 {
|
||||||
|
// line is blank or just a comment
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
vartype, varname, _, _ := tokenMsgVar(line)
|
||||||
|
if len(vartype) > int(curmsg.MaxVartype) {
|
||||||
|
curmsg.MaxVartype = int64(len(vartype))
|
||||||
|
}
|
||||||
|
if len(varname) > int(curmsg.MaxVarname) {
|
||||||
|
curmsg.MaxVarname = int64(len(varname))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
|
|
Loading…
Reference in New Issue