[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 3/3] getterm lernt notduerftig englisch



+ getterm: Meldungen auf englisch, wenn LANG=en gesetzt ist
! getterm: Rechtschreibfehler und Umlaute in Meldungen

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/c/getterm/lang.h |   62 ++++++++++++++++++++++++++++++++++++++++++
 src/modules/c/getterm/main.c |   29 ++++++++++++++++---
 2 files changed, 86 insertions(+), 5 deletions(-)
 create mode 100644 src/modules/c/getterm/lang.h

diff --git a/src/modules/c/getterm/lang.h b/src/modules/c/getterm/lang.h
new file mode 100644
index 0000000..299a8d5
--- /dev/null
+++ b/src/modules/c/getterm/lang.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LANG_H
+#define LANG_H
+
+struct messages {
+    const char* rsUsage;
+    const char* rsPressEnter;
+    const char* rsConsSetError;
+    const char* rsExecError;
+};
+
+static struct messages msg = {
+    .rsUsage        = "Aufruf: getterm [--once] [--auto] "
+                      "<stdin> <stdout> <stderr> <Programm>",
+    .rsPressEnter   = "\n\nEingabetaste drücken, um %s zu starten...\n",
+    .rsConsSetError = "Fehler beim Setzen des Pfades für die I/O-Handles.",
+    .rsExecError    = "Fehler beim Ausführen von '%s'\n",
+};
+
+static struct messages msg_en = {
+    .rsUsage        = "Usage: getterm [--once] [--auto] "
+                      "<stdin> <stdout> <stderr> <program>",
+    .rsPressEnter   = "\n\nPress the enter key to start %s...\n",
+    .rsConsSetError = "Failed to set the path for I/O handles.",
+    .rsExecError    = "Failed to execute '%s'\n",
+};
+
+#endif
diff --git a/src/modules/c/getterm/main.c b/src/modules/c/getterm/main.c
index aa210e6..e536177 100644
--- a/src/modules/c/getterm/main.c
+++ b/src/modules/c/getterm/main.c
@@ -42,6 +42,8 @@
 #include <sys/wait.h>
 #include <init.h>
 
+#include "lang.h"
+
 
 // Aufruf an Console zum aendern der Terminal-Optionen
 typedef enum {STDIN, STDOUT, STDERR} console_handle_t;
@@ -52,6 +54,22 @@ typedef struct {
 } __attribute__((packed)) console_ctrl_t;
 
 /**
+ * Sprache anhand der Umgebungsvariablen LANG setzen
+ */
+static void set_language(void)
+{
+    const char* lang = getenv("LANG");
+
+    if (!lang) {
+        return;
+    }
+
+    if (!strcmp(lang, "en")) {
+        msg = msg_en;
+    }
+}
+
+/**
  * Pfad fuer Terminal aendern
  */
 static void console_set_handle(console_handle_t handle, const char* path)
@@ -73,7 +91,7 @@ static void console_set_handle(console_handle_t handle, const char* path)
     dword result = rpc_get_dword(console_pid, "CONS_SET",
         size, (char*) buffer);
     if (result == 0) {
-        printf("Fehler beim setzen des Pfades fuer die I/O-Handles.");
+        puts(msg.rsConsSetError);
         exit(-1);
     }
 }
@@ -87,6 +105,8 @@ int main(int argc, char* argv[])
     int respawn = 1;
     int wait_for_key = 1;
 
+    set_language();
+
     // Mit --once wird das Programm nicht neugestartet
     // Mit --auto wird nicht auf einen Tastendruck gewartet
     while (argc > 2) {
@@ -103,8 +123,7 @@ int main(int argc, char* argv[])
 
     // Wenn die Anzahl der Argumente nicht stimmt wird abgebrochen
     if (argc != 5) {
-        puts("Aufruf: getterm [--once] [--auto] "
-            "<stdin> <stdout> <stderr> <Programm>");
+        puts(msg.rsUsage);
         return -1;
     }
     program = argv[4];
@@ -120,7 +139,7 @@ int main(int argc, char* argv[])
     do {
         if (wait_for_key) {
             char input = 0;
-            printf("\n\nEingabetaste druecken um %s zu starten...\n", program);
+            printf(msg.rsPressEnter, program);
             // Auf Druecken der Eingabetaste warten
             while((fread(&input, 1, 1, stdin) != 1) || (input != '\n')) {
                 yield();
@@ -131,7 +150,7 @@ int main(int argc, char* argv[])
             
         // Fehler ist aufgetreten
         if (pid == 0) {
-            printf("Fehler beim ausfuehren von '%s'\n", program);
+            printf(msg.rsExecError, program);
             return -1;
         }
 
-- 
1.6.0.2