From b9b313538c278357171d547bdac751832916c029 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Tue, 12 Apr 2016 06:45:35 +0000 Subject: [PATCH] Reorganize the implementations of the virtual member function Fl_System_Driver::getenv() git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11585 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_System_Driver.H | 4 ++-- src/Fl_System_Driver.cxx | 18 ------------------ src/drivers/Posix/Fl_Posix_System_Driver.H | 1 + src/drivers/X11/Fl_X11_System_Driver.H | 1 + src/drivers/X11/Fl_X11_System_Driver.cxx | 9 +++++++++ 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/FL/Fl_System_Driver.H b/FL/Fl_System_Driver.H index 66e421f24..82b206401 100644 --- a/FL/Fl_System_Driver.H +++ b/FL/Fl_System_Driver.H @@ -79,7 +79,7 @@ public: // implement these to support cross-platform file operations virtual char *utf2mbcs(const char *s) {return (char*)s;} - virtual char *getenv(const char* v); + virtual char *getenv(const char* v) {return NULL;} virtual int putenv(char* v) {return -1;} virtual int open(const char* f, int oflags, int pmode) {return -1;} virtual FILE *fopen(const char* f, const char *mode) {return NULL;} @@ -97,7 +97,7 @@ public: // the default implementation of these utf8... functions should be enough virtual unsigned utf8towc(const char* src, unsigned srclen, wchar_t* dst, unsigned dstlen); virtual unsigned utf8fromwc(char* dst, unsigned dstlen, const wchar_t* src, unsigned srclen); - virtual int utf8locale(); + virtual int utf8locale() {return 1;} virtual unsigned utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstlen); virtual unsigned utf8from_mb(char* dst, unsigned dstlen, const char* src, unsigned srclen); // implement to shield fprintf() from locale changes in decimal point diff --git a/src/Fl_System_Driver.cxx b/src/Fl_System_Driver.cxx index eacc9fbf3..9c34194fe 100644 --- a/src/Fl_System_Driver.cxx +++ b/src/Fl_System_Driver.cxx @@ -219,10 +219,6 @@ int Fl_System_Driver::XParseGeometry(const char* string, int* x, int* y, return (mask); } -char *Fl_System_Driver::getenv(const char *v) { - return ::getenv(v); -} - unsigned Fl_System_Driver::utf8towc(const char* src, unsigned srclen, wchar_t* dst, unsigned dstlen) { const char* p = src; const char* e = src+srclen; @@ -303,20 +299,6 @@ J1: return count; } -int Fl_System_Driver::utf8locale() { - static int ret = 2; - if (ret == 2) { - char* s; - ret = 1; // assume UTF-8 if no locale - if (((s = getenv("LC_CTYPE")) && *s) || - ((s = getenv("LC_ALL")) && *s) || - ((s = getenv("LANG")) && *s)) { - ret = (strstr(s,"utf") || strstr(s,"UTF")); - } - } - return ret; -} - unsigned Fl_System_Driver::utf8to_mb(const char* src, unsigned srclen, char* dst, unsigned dstlen) { wchar_t lbuf[1024]; wchar_t* buf = lbuf; diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index ad41d5f83..79d4c3562 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -52,6 +52,7 @@ public: virtual int open(const char* f, int oflags, int pmode) { return pmode == -1 ? ::open(f, oflags) : ::open(f, oflags, pmode); } + virtual char *getenv(const char *v) { return ::getenv(v); } virtual int putenv(char* v) {return ::putenv(v);} virtual FILE *fopen(const char* f, const char *mode) {return ::fopen(f, mode);} virtual int system(const char* cmd) {return ::system(cmd);} diff --git a/src/drivers/X11/Fl_X11_System_Driver.H b/src/drivers/X11/Fl_X11_System_Driver.H index a36c3214c..0b309dc34 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.H +++ b/src/drivers/X11/Fl_X11_System_Driver.H @@ -42,6 +42,7 @@ public: virtual char *preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root, const char *vendor, const char *application); virtual int preferences_need_protection_check() {return 1;} + virtual int utf8locale(); }; #endif /* FL_X11_SYSTEM_DRIVER_H */ diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index 11ed6488f..08f3f1e14 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -499,6 +499,15 @@ int Fl_X11_System_Driver::filename_list(const char *d, dirent ***list, int (*sor return n; } +int Fl_X11_System_Driver::utf8locale() { + char *s; + static int ret = ((s = ::getenv("LC_CTYPE")) && *s) || + ((s = ::getenv("LC_ALL")) && *s) || + ((s = ::getenv("LANG")) && *s) + ? 1 : 0; + return ret; +} + // // End of "$Id: quartz.H 11017 2016-01-20 21:40:12Z matt $". //