diff options
Diffstat (limited to 'src/nslcd_proto')
-rw-r--r-- | src/nslcd_proto/.gitignore | 2 | ||||
-rw-r--r-- | src/nslcd_proto/Makefile | 10 | ||||
-rw-r--r-- | src/nslcd_proto/enumerator@T.got | 36 | ||||
-rwxr-xr-x | src/nslcd_proto/struct_null_backend.go.sh | 12 | ||||
-rw-r--r-- | src/nslcd_proto/util/enumerator@T.got | 40 | ||||
-rwxr-xr-x | src/nslcd_proto/util/struct_null_backend.go.sh | 14 |
6 files changed, 62 insertions, 52 deletions
diff --git a/src/nslcd_proto/.gitignore b/src/nslcd_proto/.gitignore index c655813..86bd764 100644 --- a/src/nslcd_proto/.gitignore +++ b/src/nslcd_proto/.gitignore @@ -1,5 +1,5 @@ /interface_backend.go -/struct_null_backend.go +/util/struct_null_backend.go /func_handlerequest.go /requests.txt /responses.txt diff --git a/src/nslcd_proto/Makefile b/src/nslcd_proto/Makefile index f45360b..52e58f5 100644 --- a/src/nslcd_proto/Makefile +++ b/src/nslcd_proto/Makefile @@ -1,8 +1,8 @@ _ := $(MAKEFILE_LIST) d := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) -generate := $(generate) $d/interface_backend.go $d/func_handlerequest.go $d/struct_null_backend.go -secondary := $(secondary) $d/enumerator-list.mk $d/requests.txt $d/responses.txt $d/enumerator@*.go +generate := $(generate) $d/interface_backend.go $d/func_handlerequest.go $d/util/struct_null_backend.go +secondary := $(secondary) $d/enumerator-list.mk $d/requests.txt $d/responses.txt $d/*@*.go $d/util/*@*.go ifeq (,$(filter clean,$(MAKECMDGOALS))) -include $d/enumerator-list.mk @@ -27,9 +27,11 @@ endif $d/enumerator@%.go: $d/enumerator@T.got < $< sed 's/<T>/$*/g' > $@ +$d/util/enumerator@%.go: $d/util/enumerator@T.got + < $< sed 's/<T>/$*/g' > $@ $d/enumerator-list.mk: $d/responses.txt $d/Makefile - < $< sed -rn 's|.*|generate += $$d/enumerator@&.go|p' > $@ + < $< sed -rn 's|.*|generate += $$d/enumerator@&.go $$d/util/enumerator@&.go|p' > $@ $d/requests.txt: $d/nslcd_h.go $d/Makefile < $< grep -Eo '\btype Request_([^_ ]+)(_\S+)?' | sed 's/^type Request_//' > $@ @@ -41,4 +43,4 @@ $d/responses.txt: $d/interface_backend.go $d/Makefile $d/interface_backend.go: $d/requests.txt $d/func_handlerequest.go: $d/requests.txt -$d/struct_null_backend.go: $d/interface_backend.go +$d/util/struct_null_backend.go: $d/interface_backend.go diff --git a/src/nslcd_proto/enumerator@T.got b/src/nslcd_proto/enumerator@T.got index 5a540ae..023c774 100644 --- a/src/nslcd_proto/enumerator@T.got +++ b/src/nslcd_proto/enumerator@T.got @@ -1,4 +1,3 @@ -// -*- Mode: Go -*- package nslcd_proto type <T>_Enumerator interface { @@ -6,37 +5,4 @@ type <T>_Enumerator interface { GenericGetNext() (n interface{}, err error) } -type <T>_List struct { - dat []<T> - i int -} - -var _ <T>_Enumerator = &<T>_List{} - -func New_<T>_List(ary []<T>) *<T>_List { - return &<T>_List{ary, 0} -} - -func (o *<T>_List) GetNext() (n *<T>, err error) { - if o.i < len(o.dat) { - n = &o.dat[o.i] - o.i++ - } - err = nil - return -} - -func (o *<T>_List) GenericGetNext() (n interface{}, err error) { - return o.GetNext() -} - -type <T>_Ø struct{} - -var _ <T>_Enumerator = <T>_Ø{} - -func (o <T>_Ø) GetNext() (*<T>, error) { - return nil, nil -} -func (o <T>_Ø) GenericGetNext() (interface{}, error) { - return nil, nil -} +// -*- Mode: Go -*- diff --git a/src/nslcd_proto/struct_null_backend.go.sh b/src/nslcd_proto/struct_null_backend.go.sh deleted file mode 100755 index 99788aa..0000000 --- a/src/nslcd_proto/struct_null_backend.go.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# -*- Mode: Go -*- -interface=$1 -cat <<EOF | gofmt -package nslcd_proto - -type NullBackend struct{} - -$(< "$interface" sed -rn 's/^\t(.*\) (\S+)_Enumerator)$/func (o NullBackend) \1 { return \2_Ø{} }/p') - -var _ Backend = NullBackend{} -EOF diff --git a/src/nslcd_proto/util/enumerator@T.got b/src/nslcd_proto/util/enumerator@T.got new file mode 100644 index 0000000..e1dd2ae --- /dev/null +++ b/src/nslcd_proto/util/enumerator@T.got @@ -0,0 +1,40 @@ +package util + +import "nslcd_proto" + +type <T>_List struct { + dat []nslcd_proto.<T> + i int +} + +var _ nslcd_proto.<T>_Enumerator = &<T>_List{} + +func New_<T>_List(ary []nslcd_proto.<T>) *<T>_List { + return &<T>_List{ary, 0} +} + +func (o *<T>_List) GetNext() (n *nslcd_proto.<T>, err error) { + if o.i < len(o.dat) { + n = &o.dat[o.i] + o.i++ + } + err = nil + return +} + +func (o *<T>_List) GenericGetNext() (n interface{}, err error) { + return o.GetNext() +} + +type <T>_Ø struct{} + +var _ nslcd_proto.<T>_Enumerator = <T>_Ø{} + +func (o <T>_Ø) GetNext() (*nslcd_proto.<T>, error) { + return nil, nil +} +func (o <T>_Ø) GenericGetNext() (interface{}, error) { + return nil, nil +} + +// -*- Mode: Go -*- diff --git a/src/nslcd_proto/util/struct_null_backend.go.sh b/src/nslcd_proto/util/struct_null_backend.go.sh new file mode 100755 index 0000000..7cbdbd0 --- /dev/null +++ b/src/nslcd_proto/util/struct_null_backend.go.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# -*- Mode: Go -*- +interface=$1 +cat <<EOF +package util + +import p "nslcd_proto" + +type NullBackend struct{} + +$(< "$interface" sed -rn 's/^\t([^(]+)\(Ucred, ([^)]+)\) (\S+)_Enumerator$/func (o NullBackend) \1(p.Ucred, p.\2) p.\3_Enumerator { return \3_Ø{} }/p') + +var _ p.Backend = NullBackend{} +EOF |