aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/enums/generate.go
diff options
context:
space:
mode:
authorBernd Fix <brf@hoi-polloi.org>2022-11-11 09:43:03 +0100
committerBernd Fix <brf@hoi-polloi.org>2022-11-11 09:43:03 +0100
commit30f8a148ff551129b3ccc8f52e5dda1ec2104ee3 (patch)
tree18f30b4fa4bb4ecaf81d67551fafc77bcf1ad8a1 /src/gnunet/enums/generate.go
parentbcc6ce0be0d9c240dce80c42af5b56e8ee805aff (diff)
downloadgnunet-go-30f8a148ff551129b3ccc8f52e5dda1ec2104ee3.tar.gz
gnunet-go-30f8a148ff551129b3ccc8f52e5dda1ec2104ee3.zip
Namestore and identity service integrated.v0.1.38
Diffstat (limited to 'src/gnunet/enums/generate.go')
-rw-r--r--src/gnunet/enums/generate.go134
1 files changed, 0 insertions, 134 deletions
diff --git a/src/gnunet/enums/generate.go b/src/gnunet/enums/generate.go
deleted file mode 100644
index 0e02850..0000000
--- a/src/gnunet/enums/generate.go
+++ /dev/null
@@ -1,134 +0,0 @@
1// This file is part of gnunet-go, a GNUnet-implementation in Golang.
2// Copyright (C) 2019-2022 Bernd Fix >Y<
3//
4// gnunet-go is free software: you can redistribute it and/or modify it
5// under the terms of the GNU Affero General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// gnunet-go is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Affero General Public License for more details.
13//
14// You should have received a copy of the GNU Affero General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17// SPDX-License-Identifier: AGPL3.0-or-later
18
19//go:build ignore
20
21package main
22
23import (
24 "bufio"
25 "flag"
26 "fmt"
27 "io"
28 "log"
29 "os"
30 "strings"
31 "text/template"
32)
33
34// Record in the GANA registry (for a given type)
35type Record struct {
36 Number string
37 Name string
38 Comment string
39 References string
40}
41
42// String returns a readable record string
43func (rec *Record) String() string {
44 return fmt.Sprintf("[%s:%s]\n", rec.Number, rec.Name)
45}
46
47// go:generate generator to read recfiles and fill templates (not exactly
48// build on recutils but on recfiles).
49func main() {
50 // handle command-line arguments
51 flag.Parse()
52 args := flag.Args()
53 if len(args) != 3 {
54 log.Fatal("not enough arguments")
55 }
56
57 // read template
58 tpl, err := template.ParseFiles(args[1])
59 if err != nil {
60 log.Fatal(err)
61 }
62
63 // parse recfile
64 in, err := os.Open(args[0])
65 if err != nil {
66 log.Fatal(err)
67 }
68 defer in.Close()
69
70 rdr := bufio.NewReader(in)
71 state := 0
72 var recs []*Record
73 var rec *Record
74 for {
75 // read next line from recfile
76 buf, _, err := rdr.ReadLine()
77 if err != nil {
78 if err == io.EOF {
79 break
80 }
81 }
82 line := strings.TrimSpace(string(buf))
83 log.Printf("[%d] %s\n", state, line)
84
85 // perform state machine:
86 switch state {
87
88 // wait for record to start
89 case 0:
90 if len(line) == 0 || strings.Index("%#", string(line[0])) != -1 {
91 continue
92 }
93 // new record starts here
94 rec = new(Record)
95 state = 1
96 fallthrough
97
98 // read record data
99 case 1:
100 if len(line) == 0 {
101 // record done; add to list
102 log.Println("Record: " + rec.String())
103 recs = append(recs, rec)
104 rec = nil
105 state = 0
106 continue
107 }
108 // set attribute
109 kv := strings.SplitN(line, ":", 2)
110 switch kv[0] {
111 case "Number":
112 rec.Number = strings.TrimSpace(kv[1])
113 case "Name":
114 rec.Name = strings.TrimSpace(kv[1])
115 case "Comment":
116 rec.Comment = strings.TrimSpace(kv[1])
117 case "References":
118 rec.References = strings.TrimSpace(kv[1])
119 }
120 }
121 }
122
123 // open output file
124 out, err := os.Create(args[2])
125 if err != nil {
126 log.Fatal(err)
127 }
128 defer out.Close()
129
130 // Exeute template on data
131 if err := tpl.Execute(out, recs); err != nil {
132 log.Fatal(err)
133 }
134}