create msg.h from preferred language include
authorMischa POSLAWSKY <netris@shiar.org>
Sun, 4 Mar 2007 09:12:44 +0000 (10:12 +0100)
committerMischa POSLAWSKY <netris@shiar.org>
Sun, 4 Mar 2007 09:12:44 +0000 (10:12 +0100)
Specified with configure --lang.
Adds missing defines from english master file.

Makefile
client.c
configure
curses.c
msg_diff.sh [new file with mode: 0755]

index 0baead23e60beef2b58d5a8cd1ed4d5238a24a20..389503bef1781e37d62ee64cea47ab39a1d44bf9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,10 +20,22 @@ DISTFILES = README FAQ INSTALL COPYING TODO CHANGES \
 
 all: Makefile config.h $(PROG) $(SPROG)
 
-$(PROG): $(OBJS)
+msg.h: msg.en.h $(MSG_FILE)
+       @echo "Linking $(MSG_FILE) to msg.h"
+       @echo '// WARNING! This is a generated file. Do NOT edit.' > msg.h
+       @echo '// See msg.*.h for the editable files.' >> msg.h
+       @echo '#include "$(MSG_FILE)"' >> msg.h
+
+ifneq ($(MSG_FILE),msg.en.h)
+       @echo "Adding untranslated messages to msg.h"
+       @echo '// untranslated messages from the English master file:' >> msg.h
+       @./msg_diff.sh $(MSG_FILE) < msg.en.h >> msg.h
+endif
+
+$(PROG): msg.h $(OBJS)
        $(CC) -o $(PROG) $(OBJS) $(LFLAGS) $(CFLAGS)
 
-$(SPROG): $(SOBJS)
+$(SPROG): msg.h $(SOBJS)
        $(CC) -o $(SPROG) $(SOBJS) $(LFLAGS) $(CFLAGS)
 
 .c.o:
@@ -47,7 +59,7 @@ dist: $(DISTFILES)
        tar -cvzof $$dir.tar.gz $$dir
 
 clean:
-       rm -f $(PROG) $(OBJS) $(SPROG) $(SOBJS) a.out
+       rm -f $(PROG) $(OBJS) $(SPROG) $(SOBJS) msg.h a.out
 
 cleandir: clean
        rm -f config.mak config.h
index 64acecc6928b6afae51fd8bdd642570a6d013216..67d6f8df9faa51f2a5d3ca55b4bc29a0f76b980f 100644 (file)
--- a/client.c
+++ b/client.c
@@ -31,7 +31,7 @@
 #include "board.h"
 #include "curses.h"
 #include "inet.h"
-#include "msg.en.h"
+#include "msg.h"
 
 static struct option options[] = {
        { "ascii",              2, 0, 'a' },
index c3a63dcaf5f40e162fbc7f52895a696982ef3539..6ae80bb75c3829df49988e5c08078e0c0a1b9c2f 100755 (executable)
--- a/configure
+++ b/configure
@@ -55,6 +55,10 @@ while [ $# -ge 1 ]; do
                --curses-hack)
                        CURSES_HACK=true
                        ;;
+               --lang)
+                       lang="$1"
+                       shift
+                       ;;
                *)
                        cat << "END"
 Usage: ./configure [options...]
@@ -65,6 +69,7 @@ Usage: ./configure [options...]
     --cextra <opt>: Set extra C flags
     --lextra <opt>: Set extra linker flags
     --curses-hack: Disable scroll-optimization for broken curses
+    --lang <code>: Preferred interface language (default "en")
 END
                        exit 1
                        ;;
@@ -135,6 +140,13 @@ fi
 
 rm -f test.c test.o a.out
 
+test -z "$lang" && lang=en
+MSG_FILE=msg.$lang.h
+if [ ! -f $MSG_FILE ]; then
+       echo "Error: $MSG_FILE not found"
+       exit
+fi
+
 echo "Creating config.mak"
 cat > config.mak << END
 ### Automatically generated by ./configure ###
@@ -145,6 +157,7 @@ CEXTRA = $CEXTRA
 LEXTRA = $LEXTRA
 LFLAGS = $LEXTRA $LFLAGS
 CFLAGS = \$(CEXTRA) \$(COPT)
+MSG_FILE = $MSG_FILE
 END
 
 echo "Creating config.h"
index 637e8971721f97836f6cfcd826a9baa23de2921f..7b5a26d0f3c524a205dd253ab7c79de4f75a1f60 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -29,7 +29,7 @@
 #include "curses.h"
 #include "util.h"
 #include "board.h"
-#include "msg.en.h"
+#include "msg.h"
 
 #ifdef NCURSES_VERSION
 # define HAVE_NCURSES
diff --git a/msg_diff.sh b/msg_diff.sh
new file mode 100755 (executable)
index 0000000..7f246b1
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Copied help_diff.sh from the MPlayer project <http://www.mplayerhq.hu>
+# copyright MPlayer team
+
+# This script walks through the master (stdin) help/message file, and
+# prints (stdout) only those messages which are missing from the help
+# file given as parameter ($1).
+#
+# Example: msg_diff.sh msg.eo.h < msg.en.h > missing.h
+
+curr=""
+
+while read -r line; do
+       if echo "$line" | grep '^#define' > /dev/null 2>&1; then
+               curr=`printf "%s\n" "$line" | cut -d ' ' -f 2`
+               if grep "^#define $curr[         ]" $1 > /dev/null 2>&1; then
+                       curr=""
+               fi
+       else
+               if [ -z "$line" ]; then
+                       curr=""
+               fi
+       fi
+
+       if [ -n "$curr" ]; then
+               printf "%s\n" "$line"
+       fi
+done