Author: jilles
Date: Fri May  6 22:31:27 2011
New Revision: 221559
URL: http://svn.freebsd.org/changeset/base/221559

Log:
  sh: Track if the current locale's charset is UTF-8 or not.

Modified:
  head/bin/sh/main.c
  head/bin/sh/var.c
  head/bin/sh/var.h

Modified: head/bin/sh/main.c
==============================================================================
--- head/bin/sh/main.c  Fri May  6 22:26:57 2011        (r221558)
+++ head/bin/sh/main.c  Fri May  6 22:31:27 2011        (r221559)
@@ -76,6 +76,7 @@ __FBSDID("$FreeBSD$");
 int rootpid;
 int rootshell;
 struct jmploc main_handler;
+int localeisutf8;
 
 static void read_profile(const char *);
 static char *find_dot_file(char *);
@@ -96,6 +97,7 @@ main(int argc, char *argv[])
        char *shinit;
 
        (void) setlocale(LC_ALL, "");
+       updatecharset();
        state = 0;
        if (setjmp(main_handler.loc)) {
                switch (exception) {

Modified: head/bin/sh/var.c
==============================================================================
--- head/bin/sh/var.c   Fri May  6 22:26:57 2011        (r221558)
+++ head/bin/sh/var.c   Fri May  6 22:31:27 2011        (r221559)
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <locale.h>
+#include <langinfo.h>
 
 #include "shell.h"
 #include "output.h"
@@ -361,6 +362,7 @@ setvareq(char *s, int flags)
                        if ((vp->flags & VEXPORT) && localevar(s)) {
                                change_env(s, 1);
                                (void) setlocale(LC_ALL, "");
+                               updatecharset();
                        }
                        INTON;
                        return;
@@ -379,6 +381,7 @@ setvareq(char *s, int flags)
        if ((vp->flags & VEXPORT) && localevar(s)) {
                change_env(s, 1);
                (void) setlocale(LC_ALL, "");
+               updatecharset();
        }
        INTON;
 }
@@ -480,6 +483,7 @@ bltinsetlocale(void)
        if (loc != NULL) {
                setlocale(LC_ALL, loc);
                INTON;
+               updatecharset();
                return;
        }
        locdef = bltinlookup("LANG", 0);
@@ -491,6 +495,7 @@ bltinsetlocale(void)
                        setlocale(locale_categories[i], loc);
        }
        INTON;
+       updatecharset();
 }
 
 /*
@@ -505,12 +510,24 @@ bltinunsetlocale(void)
        for (lp = cmdenviron ; lp ; lp = lp->next) {
                if (localevar(lp->text)) {
                        setlocale(LC_ALL, "");
+                       updatecharset();
                        return;
                }
        }
        INTON;
 }
 
+/*
+ * Update the localeisutf8 flag.
+ */
+void
+updatecharset(void)
+{
+       char *charset;
+
+       charset = nl_langinfo(CODESET);
+       localeisutf8 = !strcmp(charset, "UTF-8");
+}
 
 /*
  * Generate a list of exported variables.  This routine is used to construct
@@ -656,6 +673,7 @@ exportcmd(int argc, char **argv)
                                                if ((vp->flags & VEXPORT) && 
localevar(vp->text)) {
                                                        change_env(vp->text, 1);
                                                        (void) 
setlocale(LC_ALL, "");
+                                                       updatecharset();
                                                }
                                                goto found;
                                        }
@@ -850,6 +868,7 @@ unsetvar(const char *s)
                        if ((vp->flags & VEXPORT) && localevar(vp->text)) {
                                change_env(s, 0);
                                setlocale(LC_ALL, "");
+                               updatecharset();
                        }
                        vp->flags &= ~VEXPORT;
                        vp->flags |= VUNSET;

Modified: head/bin/sh/var.h
==============================================================================
--- head/bin/sh/var.h   Fri May  6 22:26:57 2011        (r221558)
+++ head/bin/sh/var.h   Fri May  6 22:31:27 2011        (r221559)
@@ -81,6 +81,8 @@ extern struct var vhistsize;
 extern struct var vterm;
 #endif
 
+extern int localeisutf8;
+
 /*
  * The following macros access the values of the above variables.
  * They have to skip over the name.  They return the null string
@@ -112,6 +114,7 @@ char *lookupvar(const char *);
 char *bltinlookup(const char *, int);
 void bltinsetlocale(void);
 void bltinunsetlocale(void);
+void updatecharset(void);
 char **environment(void);
 int showvarscmd(int, char **);
 int exportcmd(int, char **);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to