]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
i18n: Change NLS interface a bit - libhylafax *is* a C++ library
authorAidan Van Dyk <aidan@ifax.com>
Thu, 28 Feb 2008 20:49:25 +0000 (20:49 +0000)
committerAidan Van Dyk <aidan@ifax.com>
Thu, 28 Feb 2008 20:49:25 +0000 (20:49 +0000)
We also want libhylafax to be able to use it's own domain, so
it needs to have a way to get it's gettext strings with dgettext.

31 files changed:
config.h.in
faxalter/faxalter.c++
faxcover/faxcover.c++
faxd/choptest.c++
faxd/cqtest.c++
faxd/faxQCleanApp.c++
faxd/tagtest.c++
faxd/tsitest.c++
faxmail/faxmail.c++
faxrm/faxrm.c++
faxstat/faxstat.c++
libhylafax/AtSyntax.c++
libhylafax/DialRules.c++
libhylafax/FaxClient.c++
libhylafax/FaxConfig.c++
libhylafax/FaxDB.c++
libhylafax/InetTransport.c++
libhylafax/NLS.c++
libhylafax/NLS.h
libhylafax/Obj.c++
libhylafax/PageSize.c++
libhylafax/SNPPClient.c++
libhylafax/SendFaxClient.c++
libhylafax/SendFaxJob.c++
libhylafax/Sequence.c++
libhylafax/TextFormat.c++
libhylafax/TypeRules.c++
libhylafax/Types.h
libhylafax/UnixTransport.c++
sendfax/sendfax.c++
sendpage/sendpage.c++

index 062a8d0876a06a7826deb6535a16bd64e9f5247f..6931c15a4fcb9fb2fc55e516491241d8cee46aae 100644 (file)
 @ENABLE_NLS@
 #define LOCALEDIR "@LOCALEDIR@"
 #define LOCALE_DOMAIN "@LOCALE_DOMAIN@"
-#include "NLS.h"
 
 #endif
index 17c395bf795478f889634ae2f3aef16c7c1b5772..3c00a8269edc27d2579522b85b684548cba2a459 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include "FaxClient.h"
 #include "Sys.h"
+#include "NLS.h"
 #include "config.h"
 
 extern int
@@ -327,7 +328,7 @@ faxAlterApp::usage()
 int
 main(int argc, char** argv)
 {
-    setupNLS();
+    NLS::Setup("hylafax-clients");
     faxAlterApp app;
     return (app.run(argc, argv));
 }
index 5c5f2225c3b07e6ad7a35c0440b60f77bb147ad1..2aeedf7d8536eb8d1b02302b71d6bbb55ba895ac 100644 (file)
@@ -29,6 +29,8 @@
 #include "PageSize.h"
 #include "Sys.h"
 
+#include "NLS.h"
+
 #include <stdarg.h>
 #include <ctype.h>
 #include <pwd.h>
@@ -474,7 +476,7 @@ faxCoverApp::printError(const char* va_alist ...)
 int
 main(int argc, char** argv)
 {
-    setupNLS();
+    NLS::Setup("hylafax-client");
     faxCoverApp app;
     app.initialize(argc, argv);
     app.open();
index 21ff63be9cd2ec75144bd088e4bc9013d5af933b..b1786cee28e031f73ee7635afc56a65a707a9250 100644 (file)
@@ -33,6 +33,7 @@
 #include "MemoryDecoder.h"
 #include "tiffio.h"
 #include "Sys.h"
+#include "NLS.h"
 
 const char* appName;
 
@@ -65,7 +66,7 @@ main(int argc, char* argv[])
     bool doAll = false;
     int c;
 
-    setupNLS();
+    NLS::Setup("hylafax-server");
     appName = argv[0];
     while ((c = Sys::getopt(argc, argv, "t:a")) != -1)
        switch (c) {
index 4e9997dfe8d4a5a1967b2b32ebf4ab0e5ab0a13b..9757a3801a12b872da54c248313434f528e3c35f 100644 (file)
@@ -36,6 +36,7 @@
 #include "Class2Params.h"
 #include "Str.h"
 #include "FaxTrace.h"
+#include "NLS.h"
 #include "tiffio.h"
 
 struct CQDecoder : public G3Decoder {
@@ -507,7 +508,7 @@ main(int argc, char* argv[])
     extern char* optarg;
     int c;
 
-    setupNLS();
+    NLS::Setup("hylafax-server");
     CQDecoder cq;
     appName = argv[0];
     while ((c = Sys::getopt(argc, argv, "m:o:p:")) != -1)
index 0aae039db8fcb9bef2e5ab8a537837c4342ef510..14bfc8372f6bab301461ac6760b9c42c3eb090f5 100644 (file)
@@ -28,6 +28,7 @@
 #include "faxApp.h"
 #include "Dictionary.h"
 #include "FaxRequest.h"
+#include "NLS.h"
 #include "config.h"
 
 #include <sys/file.h>
@@ -436,7 +437,7 @@ usage(const char* appName)
 int
 main(int argc, char** argv)
 {
-    setupNLS();
+    NLS::Setup("hylafax-server");
     faxApp::setupLogging("FaxQCleaner");
 
     fxStr appName = argv[0];
index 9cee8d40ada149002012bfc718b4a1526ad3e722..bd1a0216916b01ba782e28bc8566f9445ba5ea16 100644 (file)
@@ -29,7 +29,7 @@
  * Usage: tagtest [-f fontfile] [-m format] [-o output.tif] input.tif
  */
 #include "Sys.h"
-
+#include "NLS.h"
 #include "PCFFont.h"
 #include "StackBuffer.h"
 #include "FaxFont.h"
@@ -406,13 +406,15 @@ main(int argc, char* argv[])
     int c;
     const char* output = "t.tif";
 
+    NLS::Setup("hylafax-server");
+
 #ifdef LC_CTYPE
     setlocale(LC_CTYPE, "");                   // for <ctype.h> calls
 #endif
 #ifdef LC_TIME
     setlocale(LC_TIME, "");                    // for strftime calls
 #endif
-    setupNLS();
+
     appName = argv[0];
     while ((c = Sys::getopt(argc, argv, "f:m:o:")) != -1)
        switch (c) {
index 1c5c51f5504c3050ccb394b0216e003843aa96e0..0d5ceb356776eaa41d17f491b57b07a7c6bc575b 100644 (file)
@@ -40,6 +40,7 @@
 #include "BoolArray.h"
 #include "Str.h"
 #include "Sys.h"
+#include "NLS.h"
 
 fxStr          qualifyTSI;
 REArray*       tsiPats = NULL;         // recv tsi patterns
@@ -143,7 +144,7 @@ main(int argc, char* argv[])
     extern int optind;
     int c;
 
-    setupNLS();
+    NLS::Setup("hylafax-server");
     appName = argv[0];
     while ((c = Sys::getopt(argc, argv, ":q")) != -1)
        switch (c) {
index 5dd6da3570d9b2e6ae1947d1f04e6818a5d77a30..716578944071ba20a4df741995361b5c990a37fd 100644 (file)
@@ -29,6 +29,7 @@
 #include "StrArray.h"
 #include "Sys.h"
 #include "SendFaxClient.h"
+#include "NLS.h"
 #include "config.h"
 
 #include <ctype.h>
@@ -916,7 +917,7 @@ main(int argc, char** argv)
 #ifdef LC_CTYPE
     setlocale(LC_CTYPE, "");                   // for <ctype.h> calls
 #endif
-    setupNLS();
+    NLS::Setup("hylafax-client");
 
     app = new faxMailApp;
 
index bc0cb9337c7561bf043c484b2b8f1a7e26606e95..b9bb971ab86a2d58bbc70c5db575708ac75736ce 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include "FaxClient.h"
 #include "Sys.h"
+#include "NLS.h"
 #include "config.h"
 
 class faxRmApp : public FaxClient {
@@ -138,7 +139,7 @@ faxRmApp::usage()
 int
 main(int argc, char** argv)
 {
-    setupNLS();
+    NLS::Setup("hylafax-client");
     faxRmApp app;
     app.run(argc, argv);
     return 0;
index 9bef0917aa83ba60a1e7a549c39af9dbf784cf15..0acf82964d20404a16e4efdfab67ee67b917227a 100644 (file)
@@ -26,6 +26,7 @@
 #include "FaxClient.h"
 #include "StrArray.h"
 #include "Sys.h"
+#include "NLS.h"
 #include "config.h"
 
 #include <errno.h>
@@ -159,7 +160,7 @@ bad:
 int
 main(int argc, char** argv)
 {
-    setupNLS();
+    NLS::Setup("hylafax-client");
     faxStatApp app;
     app.run(argc, argv);
     return 0;
index 743c0bb3c69bc958dd4162e12ea4fe8539a7005e..97de0bf4524d5d53d4a724d0c344f09995146677 100644 (file)
@@ -29,6 +29,8 @@
 #include <time.h>
 #include <ctype.h>
 
+#include "NLS.h"
+
 #define        TM_YEAR_BASE    1900            // tm times all start here...
 #define        EPOCH_YEAR      1970
 #define        EPOCH_WDAY      4               // January 1, 1970 was a Thursday
@@ -101,20 +103,20 @@ parseAtSyntax(const char* s, const struct tm& ref, struct tm& at0, fxStr& emsg)
            if (isdigit(cp[1]) && isdigit(cp[2])) {
                int min = 10*(cp[1]-'0') + (cp[2]-'0');
                if (min >= 60) {
-                   _atError(emsg, _("Illegal minutes value %u"), min);
+                   _atError(emsg, NLS::TEXT("Illegal minutes value %u"), min);
                    return (false);
                }
                v += min;
                cp += 3;
            } else {
-               _atSyntax(emsg, _("expecting HH:MM"));
+               _atSyntax(emsg, NLS::TEXT("expecting HH:MM"));
                return (false);
            }
        }
        cp = whitespace(cp);
        if (streq(cp, "am", 2)) {
            if (v >= HALFDAY+HOUR) {
-               _atError(emsg, _("%u:%02u is not an AM value"), v/HOUR, v%HOUR);
+               _atError(emsg, NLS::TEXT("%u:%02u is not an AM value"), v/HOUR, v%HOUR);
                return (false);
            }
            if (HALFDAY <= v && v < HALFDAY+HOUR)
@@ -122,7 +124,7 @@ parseAtSyntax(const char* s, const struct tm& ref, struct tm& at0, fxStr& emsg)
            cp += 2;
        } else if (streq(cp, "pm", 2)) {
            if (v >= HALFDAY+HOUR) {
-               _atError(emsg, _("%u:%02u is not a PM value"), v/HOUR, v%HOUR);
+               _atError(emsg, NLS::TEXT("%u:%02u is not a PM value"), v/HOUR, v%HOUR);
                return (false);
            }
            if (v < HALFDAY)
@@ -143,12 +145,12 @@ parseAtSyntax(const char* s, const struct tm& ref, struct tm& at0, fxStr& emsg)
            v = at.tm_hour*HOUR + at.tm_min;
            cp += 4;
        } else {
-           _atSyntax(emsg, _("unrecognized symbolic time \"%s\""), cp);
+           _atSyntax(emsg, NLS::TEXT("unrecognized symbolic time \"%s\""), cp);
            return (false);
        }
     }
     if ((unsigned) v >= FULLDAY) {
-       _atError(emsg, _("Illegal time value; out of range"));
+       _atError(emsg, NLS::TEXT("Illegal time value; out of range"));
        return (false);
     }
     at.tm_hour = v/HOUR;
@@ -172,7 +174,7 @@ parseAtSyntax(const char* s, const struct tm& ref, struct tm& at0, fxStr& emsg)
            at.tm_yday++;
            cp += 8;
        } else if (cp[0] != '\0' && cp[0] != '+') {
-           _atSyntax(emsg, _("expecting \"+\" after time"));
+           _atSyntax(emsg, NLS::TEXT("expecting \"+\" after time"));
            return (false);
        }
        /*
@@ -188,7 +190,7 @@ parseAtSyntax(const char* s, const struct tm& ref, struct tm& at0, fxStr& emsg)
        return (false);
     fixup(at);
     if (at < ref) {
-       _atError(emsg, _("Invalid date/time; time must be in the future"));
+       _atError(emsg, NLS::TEXT("Invalid date/time; time must be in the future"));
        return (false);
     }
     at0 = at;
@@ -314,7 +316,7 @@ parseMonthAndYear(const char*& cp, const struct tm& ref, struct tm& at, fxStr& e
     char* tp;
     at.tm_mday = (u_int) strtoul(cp, &tp, 10);
     if (tp == cp) {
-       _atSyntax(emsg, _("missing or invalid day of month"));
+       _atSyntax(emsg, NLS::TEXT("missing or invalid day of month"));
        return (false);
     }
     at.tm_mday--;                      // tm_mday is [0..31]
@@ -323,11 +325,11 @@ parseMonthAndYear(const char*& cp, const struct tm& ref, struct tm& at, fxStr& e
        char* xp;
        u_int year = (u_int) strtoul(++tp, &xp, 10);
        if (tp == xp) {
-           _atSyntax(emsg, _("missing year"));
+           _atSyntax(emsg, NLS::TEXT("missing year"));
            return (false);
        }
        if (year < TM_YEAR_BASE) {
-           _atError(emsg, _("Sorry, cannot handle dates before %u"),
+           _atError(emsg, NLS::TEXT("Sorry, cannot handle dates before %u"),
                TM_YEAR_BASE);
            return (false);
        }
@@ -350,7 +352,7 @@ parseMonthAndYear(const char*& cp, const struct tm& ref, struct tm& at, fxStr& e
     }
     const int* days = daysInMonth[isLeapYear(at)];
     if (at.tm_mday > days[at.tm_mon]) {
-       _atError(emsg, _("Invalid day of month, %s has only %u days"),
+       _atError(emsg, NLS::TEXT("Invalid day of month, %s has only %u days"),
            months[at.tm_mon], days[at.tm_mon]);
        return (false);
     }
@@ -366,7 +368,7 @@ parseMultiplier(const char* cp, struct tm& at, fxStr& emsg)
 {
     cp = whitespace(cp);
     if (!isdigit(cp[0])) {
-       _atSyntax(emsg, _("expecting number after \"+\""));
+       _atSyntax(emsg, NLS::TEXT("expecting number after \"+\""));
        return (false);
     }
     int v = 0;
@@ -374,7 +376,7 @@ parseMultiplier(const char* cp, struct tm& at, fxStr& emsg)
        v = v*10 + (*cp - '0');
     cp = whitespace(cp);
     if (*cp == '\0') {
-       _atSyntax(emsg, _("\"+%u\" without unit"), v);
+       _atSyntax(emsg, NLS::TEXT("\"+%u\" without unit"), v);
        return (false);
     }
     if (streq(cp, "minute", 6))
@@ -393,7 +395,7 @@ parseMultiplier(const char* cp, struct tm& at, fxStr& emsg)
     } else if (streq(cp, "year", 4))
        at.tm_year += v;
     else {
-       _atError(emsg, _("Unknown increment unit \"%s\""), cp);
+       _atError(emsg, NLS::TEXT("Unknown increment unit \"%s\""), cp);
        return (false);
     }
     return (true);
@@ -447,7 +449,7 @@ _atSyntax(fxStr& emsg, const char* fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    emsg = _("Syntax error, ") | fxStr::vformat(fmt, ap);
+    emsg = NLS::TEXT("Syntax error, ") | fxStr::vformat(fmt, ap);
     va_end(ap);
 }
 
index 0ad6f8ef2a822dea110cd71f2d806d970735a172..99fbfb10b2035c8d0e49792d488d9c2e380df86b 100644 (file)
@@ -33,6 +33,8 @@
 
 #include <ctype.h>
 
+#include "NLS.h"
+
 /*
  * Interpolation points in replacement strings have
  * the META bit or'd together with their match identifier.
@@ -93,7 +95,7 @@ DialStringRules::parse(bool shouldExist)
        ok = parseRules();
        fclose(fp);
     } else if (shouldExist)
-       parseError(_("Cannot open file \"%s\" for reading"),
+       parseError(NLS::TEXT("Cannot open file \"%s\" for reading"),
                (const char*) filename);
     return (ok);
 }
@@ -102,7 +104,7 @@ void
 DialStringRules::def(const fxStr& var, const fxStr& value)
 {
     if (verbose)
-       traceParse(_("Define %s = \"%s\""),
+       traceParse(NLS::TEXT("Define %s = \"%s\""),
            (const char*) var, (const char*) value);
     (*vars)[var] = value;
 }
@@ -111,7 +113,7 @@ void
 DialStringRules::undef(const fxStr& var)
 {
     if (verbose)
-       traceParse(_("Undefine %s"), (const char*) var);
+       traceParse(NLS::TEXT("Undefine %s"), (const char*) var);
     vars->remove(var);
 }
 
@@ -123,7 +125,7 @@ DialStringRules::parseRules()
     while ((cp = nextLine(line, sizeof (line)))) {
        // collect token
        if (!isalpha(*cp)) {
-           parseError(_("Syntax error, expecting identifier"));
+           parseError(NLS::TEXT("Syntax error, expecting identifier"));
            return (false);
        }
        const char* tp = cp;
@@ -135,7 +137,7 @@ DialStringRules::parseRules()
        if (*cp == ':' && cp[1] == '=') {       // rule set definition
            for (cp += 2; *cp != '['; cp++)
                if (*cp == '\0') {
-                   parseError(_("Missing '[' while parsing rule set"));
+                   parseError(NLS::TEXT("Missing '[' while parsing rule set"));
                    return (false);
                }
            if (verbose)
@@ -154,17 +156,17 @@ DialStringRules::parseRules()
                return (false);
            def(var, value);
        } else {                                // an error
-           parseError(_("Missing '=' or ':=' after \"%s\""), (const char*) var);
+           parseError(NLS::TEXT("Missing '=' or ':=' after \"%s\""), (const char*) var);
            return (false);
        }
     }
     if (verbose) {
        RuleArray* ra = (*rules)["CanonicalNumber"];
        if (ra == 0)
-           traceParse(_("Warning, no \"CanonicalNumber\" rules."));
+           traceParse(NLS::TEXT("Warning, no \"CanonicalNumber\" rules."));
        ra = (*rules)["DialString"];
        if (ra == 0)
-           traceParse(_("Warning, no \"DialString\" rules."));
+           traceParse(NLS::TEXT("Warning, no \"DialString\" rules."));
     }
     return (true);
 }
@@ -212,11 +214,11 @@ DialStringRules::parseToken(const char* cp, fxStr& v)
        tp = ++cp;
        for (;;) {
            if (*cp == '\0') {
-               parseError(_("String with unmatched '\"'"));
+               parseError(NLS::TEXT("String with unmatched '\"'"));
                return (NULL);
            }
            if (*cp == '\\' && cp[1] == '\0') {
-               parseError(_("Bad '\\' escape sequence"));
+               parseError(NLS::TEXT("Bad '\\' escape sequence"));
                return (NULL);
            }
            if (*cp == '"' && (cp == tp || cp[-1] != '\\'))
@@ -228,7 +230,7 @@ DialStringRules::parseToken(const char* cp, fxStr& v)
     } else {                           // token terminated by white space
        for (tp = cp; *cp != '\0'; cp++) {
            if (*cp == '\\' && cp[1] == '\0') {
-               parseError(_("Bad '\\' escape sequence"));
+               parseError(NLS::TEXT("Bad '\\' escape sequence"));
                return (NULL);
            }
            if (isspace(*cp) && (cp == tp || cp[-1] != '\\'))
@@ -243,7 +245,7 @@ DialStringRules::parseToken(const char* cp, fxStr& v)
             */
            u_int l = v.next(i, '}');
            if (l >= v.length()) {
-               parseError(_("Missing '}' for variable reference"));
+               parseError(NLS::TEXT("Missing '}' for variable reference"));
                return (NULL);
            }
            fxStr var = v.cut(i+2,l-(i+2));// variable name
@@ -290,7 +292,7 @@ DialStringRules::parseRuleSet(RuleArray& rules)
        char line[1024];
        const char* cp = nextLine(line, sizeof (line));
        if (!cp) {
-           parseError(_("Missing ']' while parsing rule set"));
+           parseError(NLS::TEXT("Missing ']' while parsing rule set"));
            return (false);
        }
        if (*cp == ']')
@@ -302,7 +304,7 @@ DialStringRules::parseRuleSet(RuleArray& rules)
        while (isspace(*cp))
            cp++;
        if (*cp != '=') {
-           parseError(_("Rule pattern without '='"));
+           parseError(NLS::TEXT("Rule pattern without '='"));
            return (false);
        }
        DialRule r;
@@ -338,7 +340,7 @@ fxStr
 DialStringRules::applyRules(const fxStr& name, const fxStr& s)
 {
     if (verbose)
-       traceRules(_("Apply %s rules to \"%s\""),
+       traceRules(NLS::TEXT("Apply %s rules to \"%s\""),
            (const char*) name, (const char*) s);
     fxStr result(s);
     RuleArray* ra = (*rules)[name];
@@ -376,13 +378,13 @@ DialStringRules::applyRules(const fxStr& name, const fxStr& s)
                result.insert(replace, ix);
                off = ix + replace.length();    // skip replace when searching
                if (verbose)
-                   traceRules(_("--> match rule \"%s\", result now \"%s\""),
+                   traceRules(NLS::TEXT("--> match rule \"%s\", result now \"%s\""),
                        rule.pat->pattern(), (const char*) result);
            }
        }
     }
     if (verbose)
-       traceRules(_("--> return result \"%s\""), (const char*) result);
+       traceRules(NLS::TEXT("--> return result \"%s\""), (const char*) result);
     return result;
 }
 
@@ -393,7 +395,7 @@ DialStringRules::parseError(const char* fmt ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    fprintf(stderr, _("%s: line %u: "), (const char*) filename, lineno);
+    fprintf(stderr, NLS::TEXT("%s: line %u: "), (const char*) filename, lineno);
     vfprintf(stderr, fmt, ap);
     va_end(ap);
     putc('\n', stderr);
@@ -404,7 +406,7 @@ DialStringRules::traceParse(const char* fmt ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    fprintf(stdout, _("%s: line %u: "), (const char*) filename, lineno);
+    fprintf(stdout, NLS::TEXT("%s: line %u: "), (const char*) filename, lineno);
     vfprintf(stdout, fmt, ap);
     va_end(ap);
     putc('\n', stdout);
index f79ea9842bbef9f1715c2f74b298a908abcfd7c6..9681c12da8e0f6933fc351eb7204fb21d86f8e53 100644 (file)
@@ -37,6 +37,8 @@
 #include <sys/mman.h>
 #endif
 
+#include "NLS.h"
+
 #define        N(a)    (sizeof (a) / sizeof (a[0]))
 
 FaxClient::FaxClient()
@@ -114,7 +116,7 @@ FaxClient::printWarning(const char* fmt ...)
 void
 FaxClient::vprintWarning(const char* fmt, va_list ap)
 {
-    fprintf(stderr, _("Warning, "));
+    fprintf(stderr, NLS::TEXT("Warning, "));
     vfprintf(stderr, fmt, ap);
     fputs("\n", stderr);
 }
@@ -189,7 +191,7 @@ FaxClient::setupUserIdentity(fxStr& emsg)
        if (name)
            userName = name;
        else {
-           emsg = fxStr::format(_("Can not locate your password entry "
+           emsg = fxStr::format(NLS::TEXT("Can not locate your password entry "
                "(uid %lu): %s"), (u_long) getuid(), strerror(errno));
            return (false);
        }
@@ -215,7 +217,7 @@ FaxClient::setupUserIdentity(fxStr& emsg)
     } else
        senderName = userName;
     if (senderName.length() == 0) {
-       emsg = _("Bad (null) user name; your password file entry"
+       emsg = NLS::TEXT("Bad (null) user name; your password file entry"
            " probably has bogus GECOS field information.");
        return (false);
     } else
@@ -384,7 +386,7 @@ FaxClient::login(const char* user, fxStr& emsg)
        user = userName;
     }
     if (*user == '\0') {
-       emsg = _("Malformed (null) username");
+       emsg = NLS::TEXT("Malformed (null) username");
        return (false);
     }
     int n = command("USER %s", user);
@@ -405,7 +407,7 @@ FaxClient::login(const char* user, fxStr& emsg)
        }
        return (true);
     } else {
-       emsg = _("Login failed: ") | lastResponse;
+       emsg = NLS::TEXT("Login failed: ") | lastResponse;
        return (false);
     }
 }
@@ -426,7 +428,7 @@ bool
 FaxClient::admin(const char* pass, fxStr& emsg)
 {
     if (command("ADMIN %s", pass ? pass : getpass("Password:")) != COMPLETE) {
-       emsg = _("Admin failed: ") | lastResponse;
+       emsg = NLS::TEXT("Admin failed: ") | lastResponse;
        return (false);
     } else
        return (true);
@@ -442,7 +444,7 @@ FaxClient::setCommon(FaxParam& parm, u_int v)
                return (false);
            }
        } else {
-           printError(_("Bad %s parameter value %u."), parm.cmd, v);
+           printError(NLS::TEXT("Bad %s parameter value %u."), parm.cmd, v);
            return (false);
        }
        this->*parm.pv = v;
@@ -482,7 +484,7 @@ FaxClient::setTimeZone(u_int v)
             if (v == TZ_GMT) state &= ~FS_TZPEND;
             else state |= FS_TZPEND;
         } else {
-            printError(_("Bad time zone parameter value %u."), v);
+            printError(NLS::TEXT("Bad time zone parameter value %u."), v);
             return (false);
         }
         return (true);
@@ -521,7 +523,7 @@ FaxClient::initDataConn(fxStr& emsg)
     if (transport) {
         if (!transport->initDataConn(emsg)) {
             if (emsg == "") {
-                emsg = _("Unable to initialize data connection to server");
+                emsg = NLS::TEXT("Unable to initialize data connection to server");
             }
             return (false);
         }
@@ -535,7 +537,7 @@ FaxClient::openDataConn(fxStr& emsg)
     if (transport) {
         if (!transport->openDataConn(emsg)) {
             if (emsg == "") {
-               emsg = _("Unable to open data connection to server");
+               emsg = NLS::TEXT("Unable to open data connection to server");
             }
                return (false);
         }
@@ -559,7 +561,7 @@ FaxClient::abortDataConn(fxStr& emsg)
         fflush(fdOut);
         if (!transport->abortCmd(emsg)) {
             if (emsg == "") {
-               emsg = _("Unable to abort data connection to server");
+               emsg = NLS::TEXT("Unable to abort data connection to server");
             }
                return (false);
         }
@@ -589,14 +591,14 @@ FaxClient::abortDataConn(fxStr& emsg)
 void
 FaxClient::lostServer(void)
 {
-    printError(_("Service not available, remote server closed connection"));
+    printError(NLS::TEXT("Service not available, remote server closed connection"));
     hangupServer();
 }
 
 void
 FaxClient::unexpectedResponse(fxStr& emsg)
 {
-    emsg = _("Unexpected server response: ") | lastResponse;
+    emsg = NLS::TEXT("Unexpected server response: ") | lastResponse;
 }
 
 void
@@ -604,7 +606,7 @@ FaxClient::protocolBotch(fxStr& emsg, const char* fmt ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    emsg = _("Protocol botch") | fxStr::vformat(fmt, ap);
+    emsg = NLS::TEXT("Protocol botch") | fxStr::vformat(fmt, ap);
     va_end(ap);
 }
 
@@ -639,7 +641,7 @@ FaxClient::vcommand(const char* fmt, va_list ap)
         } else {
            line = (char *)malloc(100);
            if (line == NULL)
-               printError(_("Memory allocation failed"));
+               printError(NLS::TEXT("Memory allocation failed"));
            else {
                vsnprintf(line, 100, fmt, ap);
                traceServer("-> %s", line);
@@ -647,7 +649,7 @@ FaxClient::vcommand(const char* fmt, va_list ap)
         }
     }
     if (fdOut == NULL) {
-        printError(_("No control connection for command"));
+        printError(NLS::TEXT("No control connection for command"));
         code = -1;
         return (0);
     }
@@ -782,14 +784,14 @@ FaxClient::extract(u_int& pos, const char* pattern, fxStr& result,
         l = lastResponse.find(pos, pat);
     }
     if (l == lastResponse.length()) {
-        protocolBotch(emsg, _(": No \"%s\" in %s response: %s"),
+        protocolBotch(emsg, NLS::TEXT(": No \"%s\" in %s response: %s"),
             pattern, cmd, (const char*) lastResponse);
         return false;
     }
     l = lastResponse.skip(l+pat.length(), ' ');// skip white space
     result = lastResponse.extract(l, lastResponse.next(l, ' ')-l);
     if (result == "") {
-        protocolBotch(emsg, _(": Null %s in %s response: %s"),
+        protocolBotch(emsg, NLS::TEXT(": Null %s in %s response: %s"),
             pattern, cmd, (const char*) lastResponse);
         return false;
     }
@@ -972,7 +974,7 @@ FaxClient::runScript(const char* filename, fxStr& emsg)
        ok = runScript(fd, filename, emsg);
        fclose(fd);
     } else
-       emsg = fxStr::format(_("Unable to open script file \"%s\"."), filename);
+       emsg = fxStr::format(NLS::TEXT("Unable to open script file \"%s\"."), filename);
     return (ok);
 }
 
@@ -991,7 +993,7 @@ FaxClient::runScript(FILE* fp, const char* filename, fxStr& emsg)
        if (Sys::read(fileno(fp), addr, (u_int) sb.st_size) == sb.st_size)
            ok = runScript(addr, sb.st_size, filename, emsg);
        else
-           emsg = fxStr::format(_("%s: Read error: %s"),
+           emsg = fxStr::format(NLS::TEXT("%s: Read error: %s"),
                filename, strerror(errno));
        delete [] addr;
 #if HAS_MMAP
@@ -1016,7 +1018,7 @@ FaxClient::runScript(const char* script, u_long scriptLen,
        u_int cmdLen = ep-script;
        if (cmdLen > 1) {
            if (command("%.*s", cmdLen, script) != COMPLETE) {
-               emsg = fxStr::format(_("%s: line %u: %s"),
+               emsg = fxStr::format(NLS::TEXT("%s: line %u: %s"),
                    filename, lineno, (const char*) lastResponse);
                return (false);
            }
@@ -1106,14 +1108,14 @@ FaxClient::sendRawData(void* buf, int cc, fxStr& emsg)
     for (int cnt, sent = 0; cc; sent += cnt, cc -= cnt)
        if ((cnt = write(fdData, bp + sent, cc)) <= 0) {
            protocolBotch(emsg, errno == EPIPE ?
-               _(" (server closed connection)") : _(" (server write error: %s)."),
+               NLS::TEXT(" (server closed connection)") : _(" (server write error: %s)."),
                strerror(errno));
            return (false);
        }
 #else
     if (write(fdData, buf, cc) != cc) {
        protocolBotch(emsg, errno == EPIPE ?
-           _(" (server closed connection)") : _(" (server write error: %s)."),
+           NLS::TEXT(" (server closed connection)") : _(" (server write error: %s)."),
            strerror(errno));
        return (false);
     }
@@ -1135,7 +1137,7 @@ FaxClient::sendData(int fd,
     size_t cc;
     (void) Sys::fstat(fd, sb);
     if (getVerbose())
-       traceServer(_("SEND data, %lu bytes"), (u_long) sb.st_size);
+       traceServer(NLS::TEXT("SEND data, %lu bytes"), (u_long) sb.st_size);
     if (!initDataConn(emsg))
        goto bad;
     if (!setMode(MODE_S))
@@ -1153,7 +1155,7 @@ FaxClient::sendData(int fd,
            char buf[32*1024];                  // XXX better if page-aligned
            size_t n = fxmin(cc, sizeof (buf));
            if (read(fd, buf, n) != (ssize_t)n) {
-               protocolBotch(emsg, _(" (data read: %s)."), strerror(errno));
+               protocolBotch(emsg, NLS::TEXT(" (data read: %s)."), strerror(errno));
                goto bad;
            }
            if (!sendRawData(buf, n, emsg))
@@ -1204,7 +1206,7 @@ FaxClient::sendZData(int fd,
        size_t cc;
        Sys::fstat(fd, sb);
        if (getVerbose())
-           traceServer(_("SEND compressed data, %lu bytes"), (u_long) sb.st_size);
+           traceServer(NLS::TEXT("SEND compressed data, %lu bytes"), (u_long) sb.st_size);
        if (!initDataConn(emsg))
            goto bad;
        if (!setMode(MODE_Z))
@@ -1222,14 +1224,14 @@ FaxClient::sendZData(int fd,
                char buf[32*1024];
                int n = fxmin((size_t) cc, sizeof (buf));
                if (read(fd, buf, n) != n) {
-                   protocolBotch(emsg, _(" (data read: %s)"), strerror(errno));
+                   protocolBotch(emsg, NLS::TEXT(" (data read: %s)"), strerror(errno));
                    goto bad;
                }
                zstream.next_in = (Bytef*) buf;
                zstream.avail_in = n;
                do {
                    if (deflate(&zstream, Z_NO_FLUSH) != Z_OK) {
-                       emsg = fxStr::format(_("zlib compressor error: %s"),
+                       emsg = fxStr::format(NLS::TEXT("zlib compressor error: %s"),
                            zstream.msg);
                        goto bad;
                    }
@@ -1249,7 +1251,7 @@ FaxClient::sendZData(int fd,
            zstream.avail_in = (u_int) sb.st_size;
            do {
                if (deflate(&zstream, Z_NO_FLUSH) != Z_OK) {
-                   emsg = fxStr::format(_("zlib compressor error: %s"),
+                   emsg = fxStr::format(NLS::TEXT("zlib compressor error: %s"),
                        zstream.msg);
                    goto bad;
                }
@@ -1275,13 +1277,13 @@ FaxClient::sendZData(int fd,
                }
                break;
            default:
-               emsg = fxStr::format(_("zlib compressor error: %s"),
+               emsg = fxStr::format(NLS::TEXT("zlib compressor error: %s"),
                    zstream.msg);
                goto bad;
            }
        } while (dstate != Z_STREAM_END);
        if (getVerbose())
-           traceServer(_("SEND %lu bytes transmitted (%.1fx compression)"),
+           traceServer(NLS::TEXT("SEND %lu bytes transmitted (%.1fx compression)"),
 #define        NZ(x)   ((x)?(x):1)
                zstream.total_out, float(sb.st_size) / NZ(zstream.total_out));
        closeDataConn();
@@ -1302,7 +1304,7 @@ bad:
 #endif
        deflateEnd(&zstream);
     } else
-       emsg = fxStr::format(_("Can not initialize compression library: %s"),
+       emsg = fxStr::format(NLS::TEXT("Can not initialize compression library: %s"),
            zstream.msg);
     return (false);
 }
@@ -1344,7 +1346,7 @@ FaxClient::recvData(bool (*f)(int, const char*, int, fxStr&),
            return (getReply(false) == COMPLETE);
        }
        if (cc < 0) {
-           emsg = fxStr::format(_("Data Connection: %s"), strerror(errno));
+           emsg = fxStr::format(NLS::TEXT("Data Connection: %s"), strerror(errno));
            (void) getReply(false);
            break;
        }
@@ -1407,7 +1409,7 @@ FaxClient::recvZData(bool (*f)(void*, const char*, int, fxStr&),
                return (getReply(false) == COMPLETE);
            }
            if (cc < 0) {
-               emsg = fxStr::format(_("Data Connection: %s"), strerror(errno));
+               emsg = fxStr::format(NLS::TEXT("Data Connection: %s"), strerror(errno));
                (void) getReply(false);
                goto bad;
            }
@@ -1418,7 +1420,7 @@ FaxClient::recvZData(bool (*f)(void*, const char*, int, fxStr&),
                if (dstate == Z_STREAM_END)
                    break;
                if (dstate != Z_OK) {
-                   emsg = fxStr::format(_("Decoding error: %s"), zstream.msg);
+                   emsg = fxStr::format(NLS::TEXT("Decoding error: %s"), zstream.msg);
                    goto bad;
                }
                size_t occ = sizeof (obuf) - zstream.avail_out;
@@ -1432,7 +1434,7 @@ bad:
        closeDataConn();
        inflateEnd(&zstream);
     } else
-       emsg = fxStr::format(_("Can not initialize decoder: %s"), zstream.msg);
+       emsg = fxStr::format(NLS::TEXT("Can not initialize decoder: %s"), zstream.msg);
     return (false);
 }
 
@@ -1611,9 +1613,9 @@ FaxClient::makeHeader(const char* fmt, const FaxFmtHeader fmts[], fxStr& header)
                if (fspec[1] == '-')    // left justify
                    width = -width;
                if (width == 0 && prec == 0)
-                   header.append(_(hp->title));
+                   header.append(NLS::TEXT(hp->title));
                else
-                   header.append(fxStr::format("%*.*s", width, prec, _(hp->title)));
+                   header.append(fxStr::format("%*.*s", width, prec, NLS::TEXT(hp->title)));
            } else {
                *fp++ = c;
                header.append(fxStr(fspec, fp-fspec));
index 3e304a55cfdd74b8e2aca6621221c5d6dec285cb..956f1b4a6863f0ab5dd3e659275ac98781529fff 100644 (file)
@@ -34,6 +34,8 @@
 #include <pwd.h>
 
 #include "Sys.h"
+#include "NLS.h"
+
 
 FaxConfig::FaxConfig()
 {
@@ -52,7 +54,7 @@ FaxConfig::readConfig(const fxStr& filename)
 {
     FILE* fd = Sys::fopen(tildeExpand(filename), "r");
     if (fd) {
-       configTrace(_("Read config file %s"), (const char*) filename);
+       configTrace(NLS::TEXT("Read config file %s"), (const char*) filename);
        char line[1024];
        while (fgets(line, sizeof (line)-1, fd)){
            line[strlen(line)-1]='\0';          // Nuke \r at end of line
@@ -90,7 +92,7 @@ FaxConfig::tildeExpand(const fxStr& filename)
        if (!cp || *cp == '\0') {
            struct passwd* pwd = getpwuid(getuid());
            if (!pwd) {
-               configError(_("No passwd file entry for uid %u,"
+               configError(NLS::TEXT("No passwd file entry for uid %u,"
                    " cannot expand ~ in \"%s\""),
                    getuid(), (const char*) filename);
                cp = "";                // NB: XXX maybe this should be fatal?
@@ -163,7 +165,7 @@ FaxConfig::readConfigItem(const char* b)
        cp++;
     }
     if (*cp != ':') {
-       configError(_("Syntax error at line %u, missing ':' in \"%s\""),
+       configError(NLS::TEXT("Syntax error at line %u, missing ':' in \"%s\""),
            lineno, b);
        return (false);
     }
@@ -178,7 +180,7 @@ FaxConfig::readConfigItem(const char* b)
        char* dp = ++cp;
        for (value = dp; (c = *cp) != '"'; cp++) {
            if (c == '\0') {                    // unmatched quote mark
-               configError(_("Syntax error at line %u, missing quote mark in \"%s\""),
+               configError(NLS::TEXT("Syntax error at line %u, missing quote mark in \"%s\""),
                    lineno, b);
                return (false);
            }
@@ -211,18 +213,18 @@ FaxConfig::readConfigItem(const char* b)
 
     if (streq(tag, "include") ) {
         u_int old_lineno = lineno;
-       configTrace(_("%s = %s (line %u)"), tag, value, lineno);
+       configTrace(NLS::TEXT("%s = %s (line %u)"), tag, value, lineno);
        lineno = 0;
        readConfig(value);
        lineno = old_lineno;
        return (true);
     }
     if (!setConfigItem(tag, value)) {
-       configTrace(_("Unknown configuration parameter \"%s\" ignored at line %u"),
+       configTrace(NLS::TEXT("Unknown configuration parameter \"%s\" ignored at line %u"),
             tag, lineno);
        return (false);
     } else {
-       configTrace(_("%s = %s (line %u)"), tag, value, lineno);
+       configTrace(NLS::TEXT("%s = %s (line %u)"), tag, value, lineno);
        return (true);
     }
 }
index 49814953413504782772728e0bae766f9485c1e8..edeeff323842b8d52174fad7000bd714557f4998 100644 (file)
@@ -25,6 +25,8 @@
  */
 #include "FaxDB.h"
 #include "RE.h"
+#include "NLS.h"
+
 
 FaxDBRecord::FaxDBRecord()
 {
@@ -119,7 +121,7 @@ FaxDB::parseDatabase(FILE* fd, FaxDBRecord* parent)
     while (getToken(fd, key)) {
        if (key == "]") {
            if (parent == 0)
-               fprintf(stderr, _("%s: line %d: Unmatched \"]\".\n"),
+               fprintf(stderr, NLS::TEXT("%s: line %d: Unmatched \"]\".\n"),
                    (const char*) filename, lineno);
            break;
        }
@@ -131,7 +133,7 @@ FaxDB::parseDatabase(FILE* fd, FaxDBRecord* parent)
        if (!getToken(fd, value))
            break;
        if (value != ":") {
-           fprintf(stderr, _("%s: line %d: Missing \":\" separator.\n"),
+           fprintf(stderr, NLS::TEXT("%s: line %d: Missing \":\" separator.\n"),
                (const char*) filename, lineno);
            continue;
        }
@@ -179,7 +181,7 @@ top:
            if (c == '\\') {
                c = getc(fd);
                if (c == EOF) {
-                   fprintf(stderr, _("%s: Premature EOF.\n"), (const char*) filename);
+                   fprintf(stderr, NLS::TEXT("%s: Premature EOF.\n"), (const char*) filename);
                    return (false);
                }
                // XXX handle standard escapes
index da2c9493763aaee897e844be551bc4a638225e84..888724937b1d29f2721877da02f6a6e994f7f587 100644 (file)
@@ -27,6 +27,8 @@
 #include "FaxClient.h"
 #include "InetTransport.h"
 #include "Sys.h"
+#include "NLS.h"
+
 
 InetTransport::InetTransport(FaxClient& c) : Transport(c) {}
 InetTransport::~InetTransport(){}
@@ -70,7 +72,7 @@ InetTransport::callServer(fxStr& emsg)
     const char* cproto = proto;                        // XXX for busted include files
     struct protoent* pp = getprotobyname(cproto);
     if (!pp) {
-       client.printWarning(_("%s: No protocol definition, using default."),
+       client.printWarning(NLS::TEXT("%s: No protocol definition, using default."),
            cproto);
        protocol = 0;
     } else
@@ -78,13 +80,13 @@ InetTransport::callServer(fxStr& emsg)
 
     struct hostent* hp = Socket::gethostbyname(client.getHost());
     if (!hp) {
-       emsg = client.getHost() | _(": Unknown host");
+       emsg = client.getHost() | NLS::TEXT(": Unknown host");
        return (false);
     }
 
     int fd = socket(hp->h_addrtype, SOCK_STREAM, protocol);
     if (fd < 0) {
-       emsg = _("Can not create socket to connect to server.");
+       emsg = NLS::TEXT("Can not create socket to connect to server.");
        return (false);
     }
     struct sockaddr_in sin;
@@ -95,7 +97,7 @@ InetTransport::callServer(fxStr& emsg)
        if (!sp) {
            if (!isdigit(cproto[0])) {
                client.printWarning(
-                   _("No \"%s\" service definition, using default %u/%s."),
+                   NLS::TEXT("No \"%s\" service definition, using default %u/%s."),
                    FAX_SERVICE, FAX_DEFPORT, cproto);
                sin.sin_port = htons(FAX_DEFPORT);
            } else
@@ -107,23 +109,23 @@ InetTransport::callServer(fxStr& emsg)
     for (char** cpp = hp->h_addr_list; *cpp; cpp++) {
        memcpy(&sin.sin_addr, *cpp, hp->h_length);
        if (client.getVerbose())
-           client.traceServer(_("Trying %s (%s) at port %u..."),
+           client.traceServer(NLS::TEXT("Trying %s (%s) at port %u..."),
                (const char*) client.getHost(),
                inet_ntoa(sin.sin_addr),
                ntohs(sin.sin_port));
        if (Socket::connect(fd, &sin, sizeof (sin)) >= 0) {
            if (client.getVerbose())
-               client.traceServer(_("Connected to %s."), hp->h_name);
+               client.traceServer(NLS::TEXT("Connected to %s."), hp->h_name);
 #if defined(IP_TOS) && defined(IPTOS_LOWDELAY)
            int tos = IPTOS_LOWDELAY;
            if (Socket::setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0)
-               client.printWarning(_("setsockopt(TOS): %s (ignored)"),
+               client.printWarning(NLS::TEXT("setsockopt(TOS): %s (ignored)"),
                    strerror(errno));
 #endif
 #ifdef SO_OOBINLINE
            int on = 1;
            if (Socket::setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &on, sizeof (on)) < 0)
-               client.printWarning(_("setsockopt(OOBLINE): %s (ignored)"),
+               client.printWarning(NLS::TEXT("setsockopt(OOBLINE): %s (ignored)"),
                    strerror(errno));
 #endif
            /*
@@ -136,7 +138,7 @@ InetTransport::callServer(fxStr& emsg)
            return (true);
        }
     }
-    emsg = fxStr::format(_("Can not reach server at host \"%s\", port %u."),
+    emsg = fxStr::format(NLS::TEXT("Can not reach server at host \"%s\", port %u."),
        (const char*) client.getHost(), ntohs(sin.sin_port));
     Sys::close(fd), fd = -1;
     return (false);
@@ -264,7 +266,7 @@ InetTransport::abortCmd(fxStr& emsg)
 void
 Transport::notConfigured(fxStr& emsg)
 {
-    emsg = _("Sorry, no TCP/IP communication support was configured.");
+    emsg = NLS::TEXT("Sorry, no TCP/IP communication support was configured.");
 }
 
 bool InetTransport::callServer(fxStr& emsg)
index 4e480e0faea180c5e680fdf0208aaec47e9f3b5e..f8bd93a9d1088a95dbafacc8cd556ad4e5aa42bb 100644 (file)
  * OF THIS SOFTWARE.
  */
 #include "NLS.h"
+#include "Types.h"
+#include "Sys.h"
 
-void
-setupNLS()
+#include <errno.h>
+
+void do_bind (const char* domain, const char* ldir)
+{
+    /* bindtextdomain() doesn't preserver errno */
+    int save_errno = errno;
+
+    if (!ldir)
+       ldir = getenv("HFLOCALEDIR");
+    if (!ldir)
+       ldir = LOCALEDIR;
+    bindtextdomain(domain, ldir);
+    errno = save_errno;
+}
+
+const char* NLS::TEXT (const char* msgid)
+{
+    if (! bound)
+    {
+       bound = true;
+       do_bind(domain, NULL);
+    }
+    return dgettext(domain, msgid);
+}
+
+void NLS::Setup (const char* d, const char* ldir)
 {
-#ifdef ENABLE_NLS
     setlocale(LC_CTYPE, "");
     setlocale(LC_MESSAGES, "");
-    bindtextdomain(LOCALE_DOMAIN, LOCALEDIR);
-    textdomain(LOCALE_DOMAIN);
-#endif
+
+    /*
+     * We'll take the hit of setting up libhylafax NLS here
+     */
+    do_bind(domain, NULL);
+    bound = true;
+
+    do_bind(d, ldir);
+    textdomain(d);
 }
+
+const char* NLS::domain = "libhylafax";
+bool NLS::bound = false;
index 4f982d092b9f3104c0d7bc2080e3883276730ce7..5a280d4075be98946f76db511ff8c007e821319e 100644 (file)
 #ifndef _NLS_
 #define        _NLS_
 
-#include "config.h"
-
-extern void setupNLS();
+#include "Types.h"
 
-#define _(String) gettext(String)
-#define N_(String) gettext_noop(String)
-#define gettext_noop(String) String
-
-#ifdef ENABLE_NLS
+#include "config.h"
 
-#include <locale.h>
-#include <libintl.h>
+class NLS
+{
+    public:
+       static const char* TEXT (const char*);
 
-#ifdef NEED_NGETTEXT
-#define ngettext(s1,s2,n) (n ==1 ? gettext(s1) : gettext(s2))
-#endif
+       static void Setup (const char* domain, const char* local_dir = NULL);
 
-#else /* ENABLE_NLS */
 
-#define gettext(String) (String)
-#define textdomain(Domain) do {} while()
-#define bindtextdomain(Package, Directory) do {} while()
-#define ngettext(s1, s2, n) (n==1?s1:s2)
+       static const char* domain;
 
-#endif /* ENABLE_NLS */
+    private:
+       static bool bound;
+};
 
 #endif /* _NLS_ */
index 78f363750e2e5741502d2d9995845a7aea2fdd4a..e4571ebd30f5b887ffc3e5beb5238f38b3e08528 100644 (file)
@@ -24,6 +24,7 @@
  * OF THIS SOFTWARE.
  */
 #include "Obj.h"
+#include "NLS.h"
 
 extern "C" void abort();
 
@@ -35,7 +36,7 @@ const char* fxObj::className() const { return "fxObj"; }
 
 void fxObj::subClassMustDefine(const char* method) const
 {
-    fprintf(stderr, _("%s: Sub class must define method \"%s\".\n"),
+    fprintf(stderr, NLS::TEXT("%s: Sub class must define method \"%s\".\n"),
        className(), method);
     abort();
 }
index 07421e1ec15df594f2f08ea0ec31ffab3cebac65..3962f27de64c9fdd4b623c828a5ed076dfcd4db6 100644 (file)
@@ -35,6 +35,8 @@
 #include <ctype.h>
 #include <stdlib.h>
 
+#include "NLS.h"
+
 fxDECLARE_StructArray(PageInfoArray, PageInfo)
 fxIMPLEMENT_StructArray(PageInfoArray, PageInfo)
 
@@ -47,7 +49,7 @@ parseError(const char* file, u_int lineno, const char* fmt ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    fprintf(stderr, _("%s: line %u: "), file, lineno);
+    fprintf(stderr, NLS::TEXT("%s: line %u: "), file, lineno);
     vfprintf(stderr, fmt, ap);
     va_end(ap);
 }
@@ -62,7 +64,7 @@ PageSizeInfo::skipws(char*& cp,
        cp++;
     if (*cp == '\0') {
        parseError(file, lineno,
-           _("Unexpected end of line after \"%s\".\n"), item);
+           NLS::TEXT("Unexpected end of line after \"%s\".\n"), item);
        return (false);
     } else
        return (true);
@@ -95,27 +97,27 @@ PageSizeInfo::readPageInfoFile()
            pi.name = cp;
            while (*cp != '\t')
                cp++;
-           if (!skipws(cp, file, _("page size name"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("page size name"), lineno))
                continue;
            pi.abbr = cp;
            while (*cp != '\t')
                cp++;
-           if (!skipws(cp, file, _("page size abbreviation"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("page size abbreviation"), lineno))
                continue;
            pi.w = (BMU) strtoul(cp, &cp, 10);
-           if (!skipws(cp, file, _("page width"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("page width"), lineno))
                continue;
            pi.h = (BMU) strtoul(cp, &cp, 10);
-           if (!skipws(cp, file, _("page height"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("page height"), lineno))
                continue;
            pi.grw = (BMU) strtoul(cp, &cp, 10);
-           if (!skipws(cp, file, _("guaranteed page width"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("guaranteed page width"), lineno))
                continue;
            pi.grh = (BMU) strtoul(cp, &cp, 10);
-           if (!skipws(cp, file, _("guaranteed page height"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("guaranteed page height"), lineno))
                continue;
            pi.top = (BMU) strtoul(cp, &cp, 10);
-           if (!skipws(cp, file, _("top margin"), lineno))
+           if (!skipws(cp, file, NLS::TEXT("top margin"), lineno))
                continue;
            pi.left = (BMU) strtoul(cp, &cp, 10);
            pi.name = strdup(pi.name);
@@ -125,7 +127,7 @@ PageSizeInfo::readPageInfoFile()
        fclose(fp);
     } else {
        fprintf(stderr,
-    _("Warning, no page size database file \"%s\", using builtin default.\n"),
+    NLS::TEXT("Warning, no page size database file \"%s\", using builtin default.\n"),
            (const char*)file);
        PageInfo pi;
        pi.name = strdup("default");
index 2ee1aeeae7b9e0e97c316a83ad1ef7bd550dec7d..1326d4ae068b0886390d77ffc8d9d1db88145275 100644 (file)
@@ -33,6 +33,8 @@
 
 #define        N(a)    (sizeof (a) / sizeof (a[0]))
 
+#include "NLS.h"
+
 SNPPClient::SNPPClient()
 {
     init();
@@ -101,7 +103,7 @@ SNPPClient::printWarning(const char* fmt ...)
 void
 SNPPClient::vprintWarning(const char* fmt, va_list ap)
 {
-    fprintf(stderr, _("Warning, "));
+    fprintf(stderr, NLS::TEXT("Warning, "));
     vfprintf(stderr, fmt, ap);
     fputs("\n", stderr);
 }
@@ -206,7 +208,7 @@ SNPPClient::setupSenderIdentity(fxStr& emsg)
     }
     fxStr mbox;
     if (senderName == "" || !getNonBlankMailbox(mbox)) {
-       emsg = _("Malformed (null) sender name or mail address");
+       emsg = NLS::TEXT("Malformed (null) sender name or mail address");
        return (false);
     } else
        return (true);
@@ -252,7 +254,7 @@ SNPPClient::setupUserIdentity(fxStr& emsg)
     pwd = getpwuid(getuid());
     if (!pwd) {
        emsg = fxStr::format(
-           _("Can not locate your password entry (uid %lu): %s."),
+           NLS::TEXT("Can not locate your password entry (uid %lu): %s."),
                (u_long) getuid(), strerror(errno));
        return (false);
     }
@@ -276,7 +278,7 @@ SNPPClient::setupUserIdentity(fxStr& emsg)
     } else
        senderName = userName;
     if (senderName.length() == 0) {
-       emsg = _("Bad (null) user name; your password file entry"
+       emsg = NLS::TEXT("Bad (null) user name; your password file entry"
            " probably has bogus GECOS field information.");
        return (false);
     } else
@@ -383,7 +385,7 @@ SNPPClient::setConfigItem(const char* tag, const char* value)
     } else if (streq(tag, "holdtime")) {
        fxStr emsg;
        if (!jproto.setHoldTime(tag, emsg))
-           configError(_("Invalid hold time \"%s\": %s"),
+           configError(NLS::TEXT("Invalid hold time \"%s\": %s"),
                value, (const char*) emsg);
     } else if (streq(tag, "retrytime")) {
        jproto.setRetryTime(value);
@@ -454,20 +456,20 @@ SNPPClient::callInetServer(fxStr& emsg)
     }
     struct hostent* hp = Socket::gethostbyname(getHost());
     if (!hp) {
-       emsg = getHost() | _(": Unknown host");
+       emsg = getHost() | NLS::TEXT(": Unknown host");
        return (false);
     }
     int protocol;
     const char* cproto = proto;                        // XXX for busted include files
     struct protoent* pp = getprotobyname(cproto);
     if (!pp) {
-       printWarning(_("%s: No protocol definition, using default."), cproto);
+       printWarning(NLS::TEXT("%s: No protocol definition, using default."), cproto);
        protocol = 0;
     } else
        protocol = pp->p_proto;
     int fd = socket(hp->h_addrtype, SOCK_STREAM, protocol);
     if (fd < 0) {
-       emsg = _("Can not create socket to connect to server.");
+       emsg = NLS::TEXT("Can not create socket to connect to server.");
        return (false);
     }
     struct sockaddr_in sin;
@@ -478,7 +480,7 @@ SNPPClient::callInetServer(fxStr& emsg)
        if (!sp) {
            if (!isdigit(cproto[0])) {
                printWarning(
-                   _("No \"%s\" service definition, using default %u/%s."),
+                   NLS::TEXT("No \"%s\" service definition, using default %u/%s."),
                    SNPP_SERVICE, SNPP_DEFPORT, cproto);
                sin.sin_port = htons(SNPP_DEFPORT);
            } else
@@ -490,30 +492,30 @@ SNPPClient::callInetServer(fxStr& emsg)
     for (char** cpp = hp->h_addr_list; *cpp; cpp++) {
        memcpy(&sin.sin_addr, *cpp, hp->h_length);
        if (getVerbose())
-           traceServer(_("Trying %s (%s) at port %u..."),
+           traceServer(NLS::TEXT("Trying %s (%s) at port %u..."),
                (const char*) getHost(),
                inet_ntoa(sin.sin_addr),
                ntohs(sin.sin_port));
        if (Socket::connect(fd, &sin, sizeof (sin)) >= 0) {
            if (getVerbose())
-               traceServer(_("Connected to %s."), hp->h_name);
+               traceServer(NLS::TEXT("Connected to %s."), hp->h_name);
 #if defined(IP_TOS) && defined(IPTOS_LOWDELAY)
            int tos = IPTOS_LOWDELAY;
            if (Socket::setsockopt(fd, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0)
-               printWarning(_("setsockopt(TOS): %s (ignored)"),
+               printWarning(NLS::TEXT("setsockopt(TOS): %s (ignored)"),
                    strerror(errno));
 #endif
 #ifdef SO_OOBINLINE
            int on = 1;
            if (Socket::setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &on, sizeof (on)) < 0)
-               printWarning(_("setsockopt(OOBLINE): %s (ignored)"),
+               printWarning(NLS::TEXT("setsockopt(OOBLINE): %s (ignored)"),
                    strerror(errno));
 #endif
            setCtrlFds(fd, fd);
            return (true);
        }
     }
-    emsg = fxStr::format(_("Can not reach server at host \"%s\", port %u."),
+    emsg = fxStr::format(NLS::TEXT("Can not reach server at host \"%s\", port %u."),
        (const char*) getHost(), ntohs(sin.sin_port));
     close(fd), fd = -1;
     return (false);
@@ -522,7 +524,7 @@ SNPPClient::callInetServer(fxStr& emsg)
 bool
 SNPPServer::callInetServer(fxStr& emsg)
 {
-    emsg = _("Sorry, no TCP/IP communication support was configured.");
+    emsg = NLS::TEXT("Sorry, no TCP/IP communication support was configured.");
     return (false);
 }
 #endif
@@ -573,7 +575,7 @@ SNPPClient::login(const char* user, fxStr& emsg)
            state &= ~SS_HASSITE;
        return (true);
     } else {
-       emsg = _("Login failed: ") | lastResponse;
+       emsg = NLS::TEXT("Login failed: ") | lastResponse;
        return (false);
     }
 }
@@ -590,14 +592,14 @@ SNPPClient::getPasswd(const char* prompt)
 void
 SNPPClient::lostServer(void)
 {
-    printError(_("Service not available, remote server closed connection"));
+    printError(NLS::TEXT("Service not available, remote server closed connection"));
     hangupServer();
 }
 
 void
 SNPPClient::unexpectedResponse(fxStr& emsg)
 {
-    emsg = _("Unexpected server response: ") | lastResponse;
+    emsg = NLS::TEXT("Unexpected server response: ") | lastResponse;
 }
 
 void
@@ -605,7 +607,7 @@ SNPPClient::protocolBotch(fxStr& emsg, const char* fmt ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    emsg = _("Protocol botch") | fxStr::vformat(fmt, ap);
+    emsg = NLS::TEXT("Protocol botch") | fxStr::vformat(fmt, ap);
     va_end(ap);
 }
 
@@ -640,7 +642,7 @@ SNPPClient::vcommand(const char* fmt, va_list ap)
        }
     }
     if (fdOut == NULL) {
-       printError(_("No control connection for command"));
+       printError(NLS::TEXT("No control connection for command"));
        code = -1;
        return (0);
     }
@@ -855,7 +857,7 @@ bool
 SNPPClient::submitJobs(fxStr& emsg)
 {
     if (!isLoggedIn()) {
-       emsg = _("Not logged in to server");
+       emsg = NLS::TEXT("Not logged in to server");
        return (false);
     }
     /*
@@ -887,7 +889,7 @@ SNPPClient::submitJobs(fxStr& emsg)
 void
 SNPPClient::notifyNewJob(const SNPPJob& job)
 {
-    printf(_("destination pin %s: request id is %s for host %s\n")
+    printf(NLS::TEXT("destination pin %s: request id is %s for host %s\n")
        , (const char*) job.getPIN()
        , (const char*) job.getJobID()
        , (const char*) getHost()
@@ -910,14 +912,14 @@ SNPPClient::sendRawData(void* buf, int cc, fxStr& emsg)
     for (int cnt, sent = 0; cc; sent += cnt, cc -= cnt)
        if ((cnt = write(fileno(fdOut), bp + sent, cc)) <= 0) {
            protocolBotch(emsg, errno == EPIPE ?
-               _(" (server closed connection)") : _(" (server write error: %s)."),
+               NLS::TEXT(" (server closed connection)") : _(" (server write error: %s)."),
                strerror(errno));
            return (false);
        }
 #else
     if (write(fileno(fdOut), buf, cc) != cc) {
        protocolBotch(emsg, errno == EPIPE ?
-           _(" (server closed connection)") : _(" (server write error: %s)."),
+           NLS::TEXT(" (server closed connection)") : _(" (server write error: %s)."),
            strerror(errno));
        return (false);
     }
@@ -931,14 +933,14 @@ SNPPClient::sendData(int fd, fxStr& emsg)
     struct stat sb;
     (void) Sys::fstat(fd, sb);
     if (getVerbose())
-       traceServer(_("SEND message data, %lu bytes"), (u_long) sb.st_size);
+       traceServer(NLS::TEXT("SEND message data, %lu bytes"), (u_long) sb.st_size);
     if (command("DATA") == CONTINUE) {
        size_t cc = (size_t) sb.st_size;
        while (cc > 0) {
            char buf[32*1024];
            size_t n = fxmin(cc, sizeof (buf));
            if (read(fd, buf, n) != (ssize_t) n) {
-               protocolBotch(emsg, _(" (data read: %s)."), strerror(errno));
+               protocolBotch(emsg, NLS::TEXT(" (data read: %s)."), strerror(errno));
                return (false);
            }
            if (!sendRawData(buf, n, emsg))
@@ -961,7 +963,7 @@ SNPPClient::sendData(const fxStr& filename, fxStr& emsg)
        ok = sendData(fd, emsg);
        Sys::close(fd);
     } else
-       emsg = fxStr::format(_("Unable to open message file \"%s\"."),
+       emsg = fxStr::format(NLS::TEXT("Unable to open message file \"%s\"."),
            (const char*) filename);
     return (ok);
 }
@@ -980,7 +982,7 @@ bool
 SNPPClient::siteParm(const char* name, const fxStr& value)
 {
     if (!hasSiteCmd()) {
-       printWarning(_("no SITE %s support; ignoring set request."), name);
+       printWarning(NLS::TEXT("no SITE %s support; ignoring set request."), name);
        return (true);
     } else
        return (command("SITE %s %s", name, (const char*) value) == COMPLETE);
@@ -990,7 +992,7 @@ bool
 SNPPClient::siteParm(const char* name, u_int value)
 {
     if (!hasSiteCmd()) {
-       printWarning(_("no SITE %s support; ignoring set request."), name);
+       printWarning(NLS::TEXT("no SITE %s support; ignoring set request."), name);
        return (true);
     } else
        return (command("SITE %s %u", name, value) == COMPLETE);
index aae9f63505c3c51a7b92a600f58f899958b89f43..397c4f79f057757cd014920644cacbb300abd537 100644 (file)
@@ -34,6 +34,8 @@
 #include "TypeRules.h"
 #include "DialRules.h"
 #include "Array.h"
+#include "NLS.h"
+
 
 struct FileInfo : public fxObj {
     fxStr      name;                   // user-specified document file
@@ -98,7 +100,7 @@ SendFaxClient::prepareForJobSubmissions(fxStr& emsg)
     if (typeRules == NULL) {
        typeRules = TypeRules::read(typeRulesFile);
        if (!typeRules) {
-           emsg = _("Unable to setup file typing and conversion rules");
+           emsg = NLS::TEXT("Unable to setup file typing and conversion rules");
            return (false);
        }
     }
@@ -124,7 +126,7 @@ SendFaxClient::prepareForJobSubmissions(fxStr& emsg)
        if (job.getPageWidth() != 0 && job.getPageLength() != 0)
            continue;
        if (!job.setPageSize(job.getPageSize())) {
-           emsg = _("Unknown page size ") | job.getPageSize();
+           emsg = NLS::TEXT("Unknown page size ") | job.getPageSize();
            return (false);
        }
     }
@@ -233,7 +235,7 @@ SendFaxClient::makeCoverPage(const SendFaxJob& job, fxStr& file, fxStr& emsg)
            pid_t pid = fork();
            switch (pid) {
            case -1:                    // error
-               emsg = fxStr::format(_("Error creating cover sheet; "
+               emsg = fxStr::format(NLS::TEXT("Error creating cover sheet; "
                    "could not fork subprocess: %s"), strerror(errno));
                Sys::close(pfd[1]);
                break;
@@ -259,7 +261,7 @@ SendFaxClient::makeCoverPage(const SendFaxJob& job, fxStr& file, fxStr& emsg)
                    file = tmpFile;
                    return (true);
                }
-               emsg = fxStr::format(_("Error creating cover sheet; "
+               emsg = fxStr::format(NLS::TEXT("Error creating cover sheet; "
                    "command was \"%s\"; exit status %x")
                    , (const char*) joinargs(coverCmd, av)
                    , status
@@ -268,12 +270,12 @@ SendFaxClient::makeCoverPage(const SendFaxJob& job, fxStr& file, fxStr& emsg)
            }
            Sys::close(pfd[0]);
        } else {
-           emsg = fxStr::format(_("Error creating cover sheet; "
+           emsg = fxStr::format(NLS::TEXT("Error creating cover sheet; "
                "unable to create pipe to subprocess: %s"), strerror(errno));
        }
 #undef MAXARGS
     } else
-       emsg = fxStr::format(_("%s: Can not create temporary file for cover page"),
+       emsg = fxStr::format(NLS::TEXT("%s: Can not create temporary file for cover page"),
            (const char*) tmpFile);
     Sys::unlink(tmpFile);
     return (false);
@@ -416,11 +418,11 @@ bool
 SendFaxClient::submitJobs(fxStr& emsg)
 {
     if (!setup) {
-       emsg = _("Documents not prepared");
+       emsg = NLS::TEXT("Documents not prepared");
        return (false);
     }
     if (!isLoggedIn()) {
-       emsg = _("Not logged in to server");
+       emsg = NLS::TEXT("Not logged in to server");
        return (false);
     }
     /*
@@ -456,7 +458,7 @@ SendFaxClient::sendDocuments(fxStr& emsg)
        FileInfo& info = (*files)[i];
        int fd = Sys::open(info.temp, O_RDONLY);
        if (fd < 0) {
-           emsg = fxStr::format(info.temp | _(": Can not open: %s"),
+           emsg = fxStr::format(info.temp | NLS::TEXT(": Can not open: %s"),
                strerror(errno));
            return (false);                     // XXX
        }
@@ -477,7 +479,7 @@ SendFaxClient::sendDocuments(fxStr& emsg)
        Sys::close(fd);
        if (!fileSent) {
            if (emsg == "")
-               emsg = _("Document transfer failed: ") | getLastResponse();
+               emsg = NLS::TEXT("Document transfer failed: ") | getLastResponse();
            return (false);
        }
     }
@@ -603,7 +605,7 @@ SendFaxClient::setupSenderIdentity(const fxStr& from, fxStr& emsg)
     }
     fxStr mbox;
     if (senderName == "" || !getNonBlankMailbox(mbox)) {
-       emsg = _("Malformed (null) sender name or mail address");
+       emsg = NLS::TEXT("Malformed (null) sender name or mail address");
        return (false);
     } else
        return (true);
@@ -676,7 +678,7 @@ SendFaxClient::prepareFile(FileInfo& info, fxStr& emsg)
            printf("CONVERT \"%s\"\n", (const char*) sysCmd);
        if (system(sysCmd) != 0) {
            Sys::unlink(tmpFile);
-           emsg = fxStr::format(_("Error converting document; command was \"%s\""),
+           emsg = fxStr::format(NLS::TEXT("Error converting document; command was \"%s\""),
                (const char*) sysCmd);
            return (false);
        }
@@ -704,16 +706,16 @@ SendFaxClient::fileType(const char* filename, fxStr& emsg)
     struct stat sb;
     int fd = Sys::open(filename, O_RDONLY);
     if (fd < 0) {
-       emsg = fxStr::format(_("%s: Can not open file"), filename);
+       emsg = fxStr::format(NLS::TEXT("%s: Can not open file"), filename);
        return (NULL);
     }
     if (Sys::fstat(fd, sb) < 0) {
-       emsg = fxStr::format(_("%s: Can not stat file"), filename);
+       emsg = fxStr::format(NLS::TEXT("%s: Can not stat file"), filename);
        Sys::close(fd);
        return (NULL);
     }
     if ((sb.st_mode & S_IFMT) != S_IFREG) {
-       emsg = fxStr::format(_("%s: Not a regular file"), filename);
+       emsg = fxStr::format(NLS::TEXT("%s: Not a regular file"), filename);
        Sys::close(fd);
        return (NULL);
     }
@@ -721,12 +723,12 @@ SendFaxClient::fileType(const char* filename, fxStr& emsg)
     int cc = Sys::read(fd, buf, sizeof (buf));
     Sys::close(fd);
     if (cc == 0) {
-       emsg = fxStr::format(_("%s: Empty file"), filename);
+       emsg = fxStr::format(NLS::TEXT("%s: Empty file"), filename);
        return (NULL);
     }
     const TypeRule* tr = typeRules->match(buf, cc);
     if (!tr) {
-       emsg = fxStr::format(_("%s: Can not determine file type"), filename);
+       emsg = fxStr::format(NLS::TEXT("%s: Can not determine file type"), filename);
        return (NULL);
     }
     if (tr->getResult() == TypeRule::ERROR) {
index 334368d4764308d77c2a3497de96e2aab80c4f1c..ae45c3518e3cd9c9ad5c90c158df00ee3c346df0 100644 (file)
@@ -42,6 +42,8 @@ extern "C" {
 #include "PageSize.h"
 #include "FaxConfig.h"
 
+#include "NLS.h"
+
 SendFaxJob::SendFaxJob()
 {
 }
@@ -530,7 +532,7 @@ SendFaxJob::createJob(SendFaxClient& client, fxStr& emsg)
     if (coverFile != "") {
        int fd = Sys::open(coverFile, O_RDONLY);
        if (fd < 0) {
-           emsg = fxStr::format(_("%s: Can not open: %s"),
+           emsg = fxStr::format(NLS::TEXT("%s: Can not open: %s"),
                (const char*) coverFile, strerror(errno));
            return (false);                     // XXX
        }
@@ -542,7 +544,7 @@ SendFaxJob::createJob(SendFaxClient& client, fxStr& emsg)
        Sys::close(fd);
        if (!fileSent) {
            if (emsg == "")
-               emsg = _("Document transfer failed: ") | client.getLastResponse();
+               emsg = NLS::TEXT("Document transfer failed: ") | client.getLastResponse();
            return (false);
        }
        CHECK(client.jobCover(coverDoc))
index ccfe3a4ac2a2587f42f0f00e267e46dbd52dfce0..e7bc819625107c1c4c3be988a37ad680beb6db98 100644 (file)
@@ -35,6 +35,8 @@
 #include <sys/file.h>
 #include <errno.h>
 
+#include "NLS.h"
+
 
 const fxStr Sequence::format("%09u");
 
@@ -60,7 +62,7 @@ u_long Sequence::getNext(const char* name, fxStr& emsg)
         fd = -1;
     }
     if (fd < 0) {
-        emsg = fxStr::format(_("Unable to open sequence number file %s; %s."),
+        emsg = fxStr::format(NLS::TEXT("Unable to open sequence number file %s; %s."),
             name, strerror(errno));
         logError("%s: open: %s", name, strerror(errno));
         return ((u_long) -1);
@@ -74,7 +76,7 @@ u_long Sequence::getNext(const char* name, fxStr& emsg)
         seqnum = atol(line);
     }
     if (seqnum < 1 || seqnum >= MAXSEQNUM) {
-        logWarning(_("%s: Invalid sequence number \"%s\", resetting to 1"),
+        logWarning(NLS::TEXT("%s: Invalid sequence number \"%s\", resetting to 1"),
             name, line);
         seqnum = 1;
     }
@@ -84,7 +86,7 @@ u_long Sequence::getNext(const char* name, fxStr& emsg)
     if (Sys::write(fd, (const char*)line2, len) != len ||
             ftruncate(fd, len)) {
         emsg = fxStr::format(
-            _("Unable update sequence number file %s; write failed."), name);
+            NLS::TEXT("Unable update sequence number file %s; write failed."), name);
         logError("%s: Problem updating sequence number file", name);
         return ((u_long) -1);
     }
index 9ff2619328ceac4bdefe5a617ccbd1aedac941cb..dad03789a91008ec373eb8047cd9b5fca013584e 100644 (file)
@@ -48,6 +48,8 @@
 #include <sys/mman.h>
 #endif
 
+#include "NLS.h"
+
 #define LUNIT  (72*20)         // local coord system is .05 scale
 #define        ICVT(x) ((TextCoord)((x)*LUNIT))        // scale inches to local coordinates
 #define        CVTI(x) (float(x)/LUNIT)        // convert coords to inches
@@ -92,7 +94,7 @@ TextFormat::~TextFormat()
 void
 TextFormat::warning(const char* fmt ...) const
 {
-    fputs(_("Warning, "), stderr);
+    fputs(NLS::TEXT("Warning, "), stderr);
     va_list ap;
     va_start(ap, fmt);
     vfprintf(stderr, fmt, ap);
@@ -129,7 +131,7 @@ TextFormat::addFont(const char* name, const char* family)
     if (workStarted) {
        fxStr emsg;
        if (!f->readMetrics(pointSize, useISO8859, emsg))
-           error(_("Font %s: %s"), f->getFamily(), (const char*) emsg);
+           error(NLS::TEXT("Font %s: %s"), f->getFamily(), (const char*) emsg);
     }
     return (f);
 }
@@ -248,7 +250,7 @@ TextFormat::beginFormatting(FILE* o)
      */
     tf = Sys::tmpfile();
     if (tf == NULL)
-       fatal(_("Cannot open temporary file: %s"), strerror(errno));
+       fatal(NLS::TEXT("Cannot open temporary file: %s"), strerror(errno));
 
     numcol = fxmax(1,numcol);
     if (pointSize == -1)
@@ -256,13 +258,13 @@ TextFormat::beginFormatting(FILE* o)
     else
        pointSize = fxmax(inch("3bp"), pointSize);
     if (pointSize > inch("18bp"))
-       warning(_("point size is unusually large (>18pt)"));
+       warning(NLS::TEXT("point size is unusually large (>18pt)"));
     // read font metrics
     for (FontDictIter iter(*fonts); iter.notDone(); iter++) {
        fxStr emsg;
        TextFont* f = iter.value();
        if (!f->readMetrics(pointSize, useISO8859, emsg))
-           error(_("Font %s: %s"), f->getFamily(), (const char*) emsg);
+           error(NLS::TEXT("Font %s: %s"), f->getFamily(), (const char*) emsg);
     }
     outline = fxmax(0L,outline);
     curFont = (*fonts)["Roman"];
@@ -274,10 +276,10 @@ TextFormat::beginFormatting(FILE* o)
        pageHeight = t;
     }
     if (lm+rm >= pageWidth)
-       fatal(_("Margin values too large for page; lm %lu rm %lu page width %lu"),
+       fatal(NLS::TEXT("Margin values too large for page; lm %lu rm %lu page width %lu"),
            lm, rm, pageWidth);
     if (tm+bm >= pageHeight)
-       fatal(_("Margin values too large for page; tm %lu bm %lu page height %lu"),
+       fatal(NLS::TEXT("Margin values too large for page; tm %lu bm %lu page height %lu"),
            tm, bm, pageHeight);
 
     col_width = (pageWidth - (lm + rm))/numcol;
@@ -318,7 +320,7 @@ TextFormat::endFormatting(void)
        Copy_Block(0L, last-1);
     }
     if (fclose(tf))
-       fatal(_("Close failure on temporary file: %s"), strerror(errno));
+       fatal(NLS::TEXT("Close failure on temporary file: %s"), strerror(errno));
     tf = NULL;
     emitTrailer();
     fflush(output);
@@ -334,9 +336,9 @@ TextFormat::Copy_Block(off_t b1, off_t b2)
        size_t cc = (size_t) fxmin(sizeof (buf), (size_t) (b2-k+1));
        fseek(tf, (long) k, SEEK_SET);          // position to desired block
        if (fread(buf, 1, (size_t) cc, tf) != cc)
-           fatal(_("Read error during reverse collation: %s"), strerror(errno));
+           fatal(NLS::TEXT("Read error during reverse collation: %s"), strerror(errno));
        if (fwrite(buf, 1, (size_t) cc, output) != cc)
-           fatal(_("Output write error: %s"), strerror(errno));
+           fatal(NLS::TEXT("Output write error: %s"), strerror(errno));
     }
 }
 
@@ -716,7 +718,7 @@ TextFormat::formatFile(const char* name)
        formatFile(fp);
        fclose(fp);
     } else
-       error(_("%s: Cannot open file: %s"), name, strerror(errno));
+       error(NLS::TEXT("%s: Cannot open file: %s"), name, strerror(errno));
 }
 
 void
@@ -1001,7 +1003,7 @@ TextFormat::flush(void)
 {
     fflush(tf);
     if (ferror(tf) && errno == ENOSPC)
-       fatal(_("Output write error: %s"), strerror(errno));
+       fatal(NLS::TEXT("Output write error: %s"), strerror(errno));
 }
 
 /*
@@ -1173,7 +1175,7 @@ TextFont::decodeFontName(const char* name, fxStr& filename, fxStr& emsg)
                 size_t len = strcspn(buf, "%\n");
                 if (len == strlen(buf)) {
                    emsg = fxStr::format(
-                       _("Warning: %s - line too long."), (const char*)fontMapFile);
+                       NLS::TEXT("Warning: %s - line too long."), (const char*)fontMapFile);
                        break;
                 }
                if (len == 0) continue;
@@ -1191,7 +1193,7 @@ TextFont::decodeFontName(const char* name, fxStr& filename, fxStr& emsg)
                         *(buf + len) = '\0';
                         if (len == strlen(buf)) {
                            emsg = fxStr::format(
-                               _("Warning: %s - line too long."), (const char*) fontMapFile);
+                               NLS::TEXT("Warning: %s - line too long."), (const char*) fontMapFile);
                            break;
                         }
                        if (len == 0) continue;
@@ -1231,7 +1233,7 @@ TextFont::decodeFontName(const char* name, fxStr& filename, fxStr& emsg)
                        bool result = stat(filename, &junk) ? false : true;
                        if (!result)
                            emsg = fxStr::format(
-                               _("Warning: %s invalid Fontmap entry - no filename present"), (const char*)val);
+                               NLS::TEXT("Warning: %s invalid Fontmap entry - no filename present"), (const char*)val);
                         return result;
                     }
                 }
@@ -1371,7 +1373,7 @@ TextFont::readMetrics(TextCoord ps, bool useISO8859, fxStr& emsg)
     FILE *fp = openAFMFile(file);
     if (fp == NULL) {
        emsg = fxStr::format(
-           _("%s: Can not open font metrics file; using fixed widths"),
+           NLS::TEXT("%s: Can not open font metrics file; using fixed widths"),
            (const char*) file);
        loadFixedMetrics(625*ps/1000L);         // NB: use fixed width metrics
        return (false);
@@ -1388,7 +1390,7 @@ TextFont::readMetrics(TextCoord ps, bool useISO8859, fxStr& emsg)
     do {
        if (!getAFMLine(fp, buf, sizeof (buf))) {
            emsg = fxStr::format(
-               _("%s: No glyph metric table located; using fixed widths"),
+               NLS::TEXT("%s: No glyph metric table located; using fixed widths"),
                (const char*) file);
            fclose(fp);
            /*
@@ -1407,7 +1409,7 @@ TextFont::readMetrics(TextCoord ps, bool useISO8859, fxStr& emsg)
        int ix, w;
        /* read the glyph position and width */
        if (sscanf(buf, "C %d ; WX %d ;", &ix, &w) != 2) {
-           emsg = fxStr::format(_("%s, line %u: format error"),
+           emsg = fxStr::format(NLS::TEXT("%s, line %u: format error"),
                (const char*) file, lineno);
            fclose(fp);
            return (false);
index dd41bd3f99fb7b360f2de6954458d9aef323ef3c..dd6915f4345e099653f30f66fd0615f5076edd87 100644 (file)
@@ -41,6 +41,8 @@ extern "C" {
 }
 #endif
 
+#include "NLS.h"
+
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -88,7 +90,7 @@ bool
 TypeRule::match(const void* data, size_t size, bool verbose) const
 {
     if (verbose) {
-       printf(_("rule: %soffset %#lx %s %s"),
+       printf(NLS::TEXT("rule: %soffset %#lx %s %s"),
            cont ? ">" : "",
            (u_long) off,
            typeNames[type],
@@ -98,7 +100,7 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
            printf(" \"%s\"", value.s);
        else if (type != ASCII && type != ASCIIESC) {
            if (op == ANY)
-               printf(_(" <any value>"));
+               printf(NLS::TEXT(" <any value>"));
            else
                printf(" %#llx", (long long) value.v);
        }
@@ -106,7 +108,7 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
     }
     if (off > (off_t)size) {
        if (verbose)
-           printf(_("failed (offset past data)\n"));
+           printf(NLS::TEXT("failed (offset past data)\n"));
        return (false);
     }
     bool ok = false;
@@ -119,7 +121,7 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
        for (i = 0; i < size; i++)
            if (!isprint(cp[i]) && !isspace(cp[i])) {
                if (verbose)
-                   printf(_("failed (unprintable char %#x)\n"), cp[i]);
+                   printf(NLS::TEXT("failed (unprintable char %#x)\n"), cp[i]);
                return (false);
            }
        ok = true;
@@ -131,7 +133,7 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
        for (i = 0; i < size; i++)
            if (!isprint(cp[i]) && !isspace(cp[i]) && cp[i] != '\033') {
                if (verbose)
-                   printf(_("failed (unprintable char %#x)\n"), cp[i]);
+                   printf(NLS::TEXT("failed (unprintable char %#x)\n"), cp[i]);
                return (FALSE);
            }
        ok = TRUE;
@@ -159,7 +161,7 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
            break;
        }
        if (verbose)
-           printf(_("failed (insufficient data)\n"));
+           printf(NLS::TEXT("failed (insufficient data)\n"));
        return (false);
     case LONG:
        if (off + 4 < (off_t)size) {
@@ -168,7 +170,7 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
            break;
        }
        if (verbose)
-           printf(_("failed (insufficient data)\n"));
+           printf(NLS::TEXT("failed (insufficient data)\n"));
        return (false);
     }
     /*
@@ -189,10 +191,10 @@ TypeRule::match(const void* data, size_t size, bool verbose) const
 done:
     if (verbose) {
        if (ok)
-           printf(_("success (result %s, rule \"%s\")\n"),
+           printf(NLS::TEXT("success (result %s, rule \"%s\")\n"),
                resultNames[result], (const char*) cmd);
        else
-           printf(_("failed (comparison)\n"));
+           printf(NLS::TEXT("failed (comparison)\n"));
     }
     return (ok);
 }
@@ -306,7 +308,7 @@ parseError(const char* file, u_int lineno, const char* fmt ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    fprintf(stderr, _("%s: line %u: "), file, lineno);
+    fprintf(stderr, NLS::TEXT("%s: line %u: "), file, lineno);
     vfprintf(stderr, fmt, ap);
     va_end(ap);
 }
@@ -318,7 +320,7 @@ TypeRules::read(const fxStr& file)
 
     fp = fopen(file, "r");
     if (fp == NULL) {
-       fprintf(stderr, _("%s: Can not open type rules file.\n"),
+       fprintf(stderr, NLS::TEXT("%s: Can not open type rules file.\n"),
            (const char*) file);
        return NULL;
     }
@@ -339,7 +341,7 @@ TypeRules::read(const fxStr& file)
        const char *op = cp;
        rule.off = strtoul(op, &cp, 0); // file offset
        if (cp == op) {
-           parseError(file, lineno, _("Missing file offset"));
+           parseError(file, lineno, NLS::TEXT("Missing file offset"));
            continue;
        }
        while (isspace(*cp))
@@ -364,7 +366,7 @@ TypeRules::read(const fxStr& file)
        else if (strncasecmp(tp, "addr", cp-tp) == 0)
            rule.type = TypeRule::ADDR;
        else {
-           parseError(file, lineno, _("Unknown datatype \"%.*s\""), cp-tp, tp);
+           parseError(file, lineno, NLS::TEXT("Unknown datatype \"%.*s\""), cp-tp, tp);
            continue;                   // bad type
        }
        while (isspace(*cp))
@@ -405,7 +407,7 @@ TypeRules::read(const fxStr& file)
                const char* vp = cp;
                rule.value.v = strtol(vp, &cp, 0);
                if (vp == cp) {
-                   parseError(file, lineno, _("Missing match value"));
+                   parseError(file, lineno, NLS::TEXT("Missing match value"));
                    continue;
                }
            }
@@ -433,7 +435,7 @@ TypeRules::read(const fxStr& file)
        else if (strncasecmp(rp, "error", cp-rp) == 0)
            rule.result = TypeRule::ERROR;
        else {
-           parseError(file, lineno, _("Unknown result \"%.*s\""), cp-rp, rp);
+           parseError(file, lineno, NLS::TEXT("Unknown result \"%.*s\""), cp-rp, rp);
            continue;
        }
        while (isspace(*cp))
@@ -483,13 +485,13 @@ const TypeRule*
 TypeRules::match(const void* data, u_int size) const
 {
     if (verbose)
-       printf(_("match against (..., %u)\n"), size);
+       printf(NLS::TEXT("match against (..., %u)\n"), size);
     for (u_int i = 0, n = (*rules).length(); i < n; i++) {
        TypeRule& rule = (*rules)[i];
        if (!rule.isContinuation() && rule.match(data, size, verbose))
            return (&(*rules)[i + match2(i, data, size, verbose)]);
     }
     if (verbose)
-       printf(_("no match\n"));
+       printf(NLS::TEXT("no match\n"));
     return (NULL);
 }
index a459149ae3009569bd99576aa105f66cfc8445d3..b08b02c0e8a81cc9578935b13c0823124f757bf8 100644 (file)
@@ -111,4 +111,31 @@ extern "C" void _fxassert(const char*, const char*, int);
 #define        fxSIGACTIONHANDLER
 #endif
 
+// --------------------------------------------------------------------
+//
+// Support for NLS
+
+#define _(String) gettext(String)
+#define N_(String) gettext_noop(String)
+#define gettext_noop(String) String
+
+#ifdef ENABLE_NLS
+
+#include <locale.h>
+#include <libintl.h>
+
+#ifdef NEED_NGETTEXT
+#define ngettext(s1,s2,n) (n ==1 ? gettext(s1) : gettext(s2))
+#endif
+
+#else /* ENABLE_NLS */
+
+#define gettext(String) (String)
+#define textdomain(Domain) do {} while()
+#define bindtextdomain(Package, Directory) do {} while()
+#define ngettext(s1, s2, n) (n==1?s1:s2)
+
+#endif /* ENABLE_NLS */
+
+
 #endif /* _Types_ */
index b8618002e8ceae48015b86e248c6ac0e205fc156..3c6c2fbf8ad8b1e10ae601adab9f71ae1a0336c9 100644 (file)
@@ -28,6 +28,8 @@
 #include "UnixTransport.h"
 #include "Sys.h"
 
+#include "NLS.h"
+
 UnixTransport::UnixTransport(FaxClient& c) : Transport(c) {}
 UnixTransport::~UnixTransport() {}
 
@@ -49,7 +51,7 @@ UnixTransport::callServer(fxStr& emsg)
 {
     int fd = socket(AF_UNIX, SOCK_STREAM, 0);
     if (fd < 0) {
-       emsg = _("Can not create socket to connect to server.");
+       emsg = NLS::TEXT("Can not create socket to connect to server.");
        return (false);
     }
     struct sockaddr_un Sun;
@@ -57,13 +59,13 @@ UnixTransport::callServer(fxStr& emsg)
     Sun.sun_family = AF_UNIX;
     strncpy(Sun.sun_path, client.getHost(), sizeof (Sun.sun_path));
     if (client.getVerbose())
-       client.traceServer(_("connect to server at %s"),
+       client.traceServer(NLS::TEXT("connect to server at %s"),
            (const char*) client.getHost());
     if (Socket::connect(fd, &Sun, sizeof (Sun)) >= 0) {
        client.setCtrlFds(fd, dup(fd));
        return (true);
     } else {
-       emsg = fxStr::format(_("Can not reach server at Unix domain socket \"%s\"."),
+       emsg = fxStr::format(NLS::TEXT("Can not reach server at Unix domain socket \"%s\"."),
            (const char*) client.getHost());
        Sys::close(fd), fd = -1;
        return (false);
@@ -135,7 +137,7 @@ UnixTransport::openDataConn(fxStr&)
 void
 Transport::notConfigured(fxStr& emsg)
 {
-    emsg = _("Sorry, no Unix domain communication support was configured.");
+    emsg = NLS::TEXT("Sorry, no Unix domain communication support was configured.");
 }
 
 bool UnixTransport::callServer(fxStr& emsg)
index b9c1be01595ef62509c4c4d95812b2bd7f4c7e3b..7ba86eb7614f5cf42e866816ee708fbb0ca8c1e5 100644 (file)
@@ -28,6 +28,7 @@
 #include "SendFaxClient.h"
 #include "FaxDB.h"
 #include "Sys.h"
+#include "NLS.h"
 #include "config.h"
 #include <ctype.h>             // isspace()
 
@@ -408,7 +409,7 @@ main(int argc, char** argv)
 #ifdef LC_TIME
     setlocale(LC_TIME, "");                    // for strftime calls
 #endif
-    setupNLS();
+    NLS::Setup("hylafax-client");
     signal(SIGHUP, fxSIGHANDLER(sigDone));
     signal(SIGINT, fxSIGHANDLER(sigDone));
     signal(SIGTERM, fxSIGHANDLER(sigDone));
index 16b5d54c60ccc55217986a29eed45cb806350119..11dbdec5a517fa47c0ed2529e557ec4986e99574 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include "SNPPClient.h"
 #include "Sys.h"
+#include "NLS.h"
 #include "config.h"
 
 #if HAS_LOCALE
@@ -257,7 +258,7 @@ main(int argc, char** argv)
 #ifdef LC_TIME
     setlocale(LC_TIME, "");                    // for strftime calls
 #endif
-    setupNLS();
+    NLS::Setup("hylafax-client");
     signal(SIGHUP, fxSIGHANDLER(sigDone));
     signal(SIGINT, fxSIGHANDLER(sigDone));
     signal(SIGTERM, fxSIGHANDLER(sigDone));