9749a67
--- nedit-5.5/source/nedit.c.utf8	2004-09-02 10:49:56.000000000 +0200
9749a67
+++ nedit-5.5/source/nedit.c	2004-12-27 09:59:40.997208056 +0100
9749a67
@@ -90,6 +90,7 @@ static int checkDoMacroArg(const char *m
9749a67
 static String neditLanguageProc(Display *dpy, String xnl, XtPointer closure);
9749a67
 static void maskArgvKeywords(int argc, char **argv, const char **maskArgs);
9749a67
 static void unmaskArgvKeywords(int argc, char **argv, const char **maskArgs);
9749a67
+static void changeLocaleIfUTF8(void);
9749a67
 static void patchResourcesForVisual(void);
9749a67
 static void patchResourcesForKDEbug(void);
9749a67
 static void patchLocaleForMotif(void);
9749a67
@@ -392,6 +393,8 @@ int main(int argc, char **argv)
9749a67
     /* Save the command which was used to invoke nedit for restart command */
9749a67
     ArgV0 = argv[0];
9749a67
 
9749a67
+    changeLocaleIfUTF8();
9749a67
+
9749a67
     /* Set locale for C library, X, and Motif input functions. 
9749a67
        Reverts to "C" if requested locale not available. */
9749a67
     XtSetLanguageProc(NULL, neditLanguageProc, NULL);
9749a67
@@ -1035,6 +1038,32 @@ static String neditLanguageProc(Display 
9749a67
     return setlocale(LC_ALL, NULL); /* re-query in case overwritten */
9749a67
 }
9749a67
 
9749a67
+static void changeLocaleIfUTF8(void)
9749a67
+{
9749a67
+    char *locale;
9749a67
+
9749a67
+    locale = getenv("LANG");
9749a67
+    if (!locale) {
9749a67
+        locale = setlocale(LC_ALL, NULL);
9749a67
+    }
9749a67
+
9749a67
+    if (locale) {
9749a67
+        char *ptr;
9749a67
+
9749a67
+        ptr = strstr(locale, ".UTF-8");
9749a67
+        if (ptr) {
9749a67
+            fprintf(stderr, "nedit: the current locale is utf8 (%s)\n", locale);
9749a67
+
9749a67
+            ptr[0] = '\0';
9749a67
+
9749a67
+            setenv("LC_ALL", locale, 1);
9749a67
+            locale = setlocale(LC_ALL, locale);
9749a67
+
9749a67
+            fprintf(stderr, "nedit: changed locale to non-utf8 (%s)\n", locale);
9749a67
+        }
9749a67
+    }
9749a67
+}
9749a67
+
9749a67
 static int sortAlphabetical(const void* k1, const void* k2)
9749a67
 {
9749a67
     const char* key1 = *(const char**)k1;