diff options
author | Audrius Butkevicius <audrius.butkevicius@gmail.com> | 2020-08-25 07:11:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-25 08:11:14 +0200 |
commit | d507d932b8975a0c6efeef326d69bac1cab059d1 (patch) | |
tree | b844cdc4254cdc51d817484f0334cf4d35aec826 /script | |
parent | 5b953033c752f4908804f723442c5c97cef712db (diff) | |
download | syncthing-d507d932b8975a0c6efeef326d69bac1cab059d1.tar.gz syncthing-d507d932b8975a0c6efeef326d69bac1cab059d1.zip |
all: Use protobuf to generate config structs (fixes #6734) (#6900)
Diffstat (limited to 'script')
-rw-r--r-- | script/protofmt.go | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/script/protofmt.go b/script/protofmt.go deleted file mode 100644 index 5a203d20e..000000000 --- a/script/protofmt.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2016 The Syncthing Authors. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at https://mozilla.org/MPL/2.0/. - -// +build ignore - -package main - -import ( - "bufio" - "flag" - "fmt" - "io" - "log" - "os" - "regexp" - "strings" - "text/tabwriter" -) - -func main() { - flag.Parse() - file := flag.Arg(0) - in, err := os.Open(file) - if err != nil { - log.Fatal(err) - } - out, err := os.Create(file + ".tmp") - if err != nil { - log.Fatal(err) - } - - if err := formatProto(in, out); err != nil { - log.Fatal(err) - } - in.Close() - out.Close() - if err := os.Rename(file+".tmp", file); err != nil { - log.Fatal(err) - } -} - -func formatProto(in io.Reader, out io.Writer) error { - sc := bufio.NewScanner(in) - lineExp := regexp.MustCompile(`([^=]+)\s+([^=\s]+?)\s*=(.+)`) - var tw *tabwriter.Writer - for sc.Scan() { - line := sc.Text() - if strings.HasPrefix(line, "//") { - if _, err := fmt.Fprintln(out, line); err != nil { - return err - } - continue - } - - ms := lineExp.FindStringSubmatch(line) - for i := range ms { - ms[i] = strings.TrimSpace(ms[i]) - } - if len(ms) == 4 && ms[1] != "option" { - typ := strings.Join(strings.Fields(ms[1]), " ") - name := ms[2] - id := ms[3] - if tw == nil { - tw = tabwriter.NewWriter(out, 4, 4, 1, ' ', 0) - } - if typ == "" { - // We're in an enum - fmt.Fprintf(tw, "\t%s\t= %s\n", name, id) - } else { - // Message - fmt.Fprintf(tw, "\t%s\t%s\t= %s\n", typ, name, id) - } - } else { - if tw != nil { - if err := tw.Flush(); err != nil { - return err - } - tw = nil - } - if _, err := fmt.Fprintln(out, line); err != nil { - return err - } - } - } - - return nil -} |