summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rwxr-xr-xsrc/gen_message.sh11
-rw-r--r--src/gen_messages.sed25
3 files changed, 27 insertions, 13 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index be35cd2..c9b4b50 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,8 +10,8 @@ AM_CFLAGS = $(GCC_FLAGS)
$(cmumble_SOURCES): messages.h mumble.pb-c.h
-messages.h: messages.txt gen_message.sh
- $(AM_V_GEN) ./gen_message.sh < $< > $@
+messages.h: messages.txt gen_messages.sed
+ $(AM_V_GEN) $(SED) -f gen_messages.sed $< > $@
mumble.pb-c.c mumble.pb-c.h: mumble.proto
$(AM_V_GEN) $(PROTOBUF_EXECUTABLE) --c_out=. $<
diff --git a/src/gen_message.sh b/src/gen_message.sh
deleted file mode 100755
index 47b81e6..0000000
--- a/src/gen_message.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-echo "#ifndef _MESSAGES_H_"
-echo "#define _MESSAGES_H_"
-echo "#define MUMBLE_MSGS \\"
-while read message
-do
- underscore_name=$(echo "$message" | sed -e "s/\([a-z]\)\([A-Z]\)/\1_\L\2/g" -e "s/[A-Z]*/\L\0/g")
- echo -e "\tMUMBLE_MSG(${message}, ${underscore_name}) \\"
-done
-echo
-echo "#endif"
diff --git a/src/gen_messages.sed b/src/gen_messages.sed
new file mode 100644
index 0000000..0bc51f1
--- /dev/null
+++ b/src/gen_messages.sed
@@ -0,0 +1,25 @@
+1 {
+i\
+#ifndef _MESSAGES_H_ \
+#define _MESSAGES_H_ \
+\
+#define MUMBLE_MSGS \\
+}
+
+# Duplicate & Seperate with ","
+s/^.*$/\0, \0/
+
+# Lowercase and prefix uppercase characters that follow a lowercase one
+:a; s/^\([^,]*, .*[a-z]\)\([A-Z]\)/\1_\L\2\E/g; ta
+
+# Lowercase remaining uppercase characters
+s/\([^,]*, [a-z_]*\)\([A-Z]*\)/\1\L\2\E/g
+
+# Put template macro around
+s/^.*$/\tMUMBLE_MSG(\0) \\/
+
+$ {
+a\
+\
+#endif /* _MESSAGES_H_ */
+}