From d4301bdbc057d0fdeb4bceaea693f59490197a74 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Mon, 11 Jul 2011 13:24:47 +0200 Subject: Use a sed script for generating messages.h Drop the prior used shell script. --- configure.ac | 1 + src/Makefile.am | 4 ++-- src/gen_message.sh | 11 ----------- src/gen_messages.sed | 25 +++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 13 deletions(-) delete mode 100755 src/gen_message.sh create mode 100644 src/gen_messages.sed diff --git a/configure.ac b/configure.ac index 0f18774..6aa8568 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) # Check for programs AC_PROG_CC +AC_PROG_SED PKG_PROG_PKG_CONFIG() PKG_CHECK_MODULES(PROTOBUF, [libprotobuf-c],[], [ 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_ */ +} -- cgit