summaryrefslogtreecommitdiff
path: root/protoReformat.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-26 14:02:25 -0500
committerJeff Carr <[email protected]>2025-03-26 20:44:06 -0500
commit81b4b453e7aea2b40674dd40977c1385c559a72b (patch)
tree6130b2698b90b92840947fb973ca790d1f0c40f7 /protoReformat.go
parent2269ac2c275a9f38cde2c55a39bccf4c011659d0 (diff)
more attempts to work on the signal-server proto files
Diffstat (limited to 'protoReformat.go')
-rw-r--r--protoReformat.go74
1 files changed, 70 insertions, 4 deletions
diff --git a/protoReformat.go b/protoReformat.go
index 093a666..00d9352 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -7,6 +7,7 @@ import (
"fmt"
"iter"
"os"
+ "regexp"
"strings"
sync "sync"
@@ -26,6 +27,20 @@ func protoReformat(filename string) error {
}
var newfile string
+
+ /*
+ _, junk := filepath.Split(filename)
+ if junk != "SignalService.proto" {
+ var allLinesIter iter.Seq[string]
+ allLinesIter = makeLineIter(data)
+ // gets the max vartype and varname
+ for line := range allLinesIter {
+ newfile += fmt.Sprintln(commentPreprocessor(line))
+ }
+ return saveFile(filename, newfile)
+ }
+ */
+
var fmtmsg *FormatMsg
fmtmsg = new(FormatMsg)
@@ -162,13 +177,17 @@ func protoReformat(filename string) error {
newfile += fmt.Sprintln(line)
}
+ return saveFile(filename, newfile)
+}
+
+func saveFile(filename string, data string) error {
pf, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Info("file open error. permissions?", filename, err)
return err
}
- newfile = strings.TrimSpace(newfile)
- fmt.Fprintln(pf, newfile)
+ data = strings.TrimSpace(data)
+ fmt.Fprintln(pf, data)
pf.Close()
// for i, s := range slices.Backward(pf.ToSort) {
@@ -185,7 +204,7 @@ func getInceptionMsg(fmtmsg *FormatMsg) {
newmsg.MaxVartype = fmtmsg.MaxVartype
newmsg.Header = line
getInceptionEnum(newmsg)
- fmtmsg.Enums = append(fmtmsg.Oneofs, newmsg)
+ fmtmsg.Oneofs = append(fmtmsg.Oneofs, newmsg)
continue
}
if strings.HasPrefix(line, "enum ") {
@@ -329,6 +348,24 @@ func formatMessage(curmsg *FormatMsg) []string {
}
*/
+ for _, msg := range curmsg.Enums {
+ for _, newline := range formatEnum(msg) {
+ newmsg = append(newmsg, newline)
+ }
+ }
+
+ for _, msg := range curmsg.Oneofs {
+ for _, newline := range formatEnum(msg) {
+ newmsg = append(newmsg, newline)
+ }
+ }
+
+ for _, msg := range curmsg.InceptionMsgs {
+ for _, newline := range formatMessage(msg) {
+ newmsg = append(newmsg, newline)
+ }
+ }
+
for _, line := range curmsg.Lines {
line = strings.TrimSpace(line)
if line == "" {
@@ -387,7 +424,36 @@ func (it *LinesScanner) Next() string {
if it.index-1 == len(it.things) {
fmt.Println("Next() error in LinesScanner", it.index)
}
- return strings.TrimSpace(it.things[it.index-1])
+ // out := commentPreprocessor(it.things[it.index-1])
+ out := it.things[it.index-1]
+ // return strings.TrimSpace(out)
+ return out
}
// END DEFINE THE ITERATOR
+
+// turns: "/* test */ reserved /* linkPreviews */ 4;"
+// into:
+func commentPreprocessor(line string) string {
+
+ // Match all /* comment */ blocks
+ re := regexp.MustCompile(`/\*([^*]+)\*/`)
+ matches := re.FindAllStringSubmatch(line, -1)
+
+ // Extract just the comment texts
+ var comments []string
+ for _, match := range matches {
+ comments = append(comments, strings.TrimSpace(match[1]))
+ }
+
+ // Remove the block comments from the original line
+ line = re.ReplaceAllString(line, "")
+ line = strings.TrimSpace(line)
+
+ // Append comments at the end with //
+ for _, comment := range comments {
+ line += " // " + comment
+ }
+
+ return line
+}