jdk/src/solaris/native/java/lang/java_props_md.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 5168 41e46b5d9b15
child 6489 9e7015635425
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     2
 * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5168
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <pwd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#ifndef ARCHPROPNAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#error "The macro ARCHPROPNAME has not been defined"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <sys/utsname.h>        /* For os_name and os_version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include <langinfo.h>           /* For nl_langinfo */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <sys/param.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "locale_str.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "java_props.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define CODESET _NL_CTYPE_CODESET_NAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#ifdef ALT_CODESET_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#define CODESET ALT_CODESET_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/* Take an array of string pairs (map of key->value) and a string (key).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Examine each pair in the map to see if the first string (key) matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * string.  If so, store the second string of the pair (value) in the value and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * return 1.  Otherwise do nothing and return 0.  The end of the map is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * indicated by an empty string at the start of a pair (key of "").
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
mapLookup(char* map[], const char* key, char** value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    for (i = 0; strcmp(map[i], ""); i += 2){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if (!strcmp(key, map[i])){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            *value = map[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/* This function sets an environment variable using envstring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * The format of envstring is "name=value".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * If the name has already existed, it will append value to the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
setPathEnvironment(char *envstring)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    char name[20], *value, *current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    value = strchr(envstring, '='); /* locate name and value separator */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    if (! value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return; /* not a valid environment setting */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /* copy first part as environment name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    strncpy(name, envstring, value - envstring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    name[value-envstring] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    value++; /* set value point to value of the envstring */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    current = getenv(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    if (current) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (! strstr(current, value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            /* value is not found in current environment, append it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            char *temp = malloc(strlen(envstring) + strlen(current) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        strcpy(temp, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        strcat(temp, "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        strcat(temp, current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        strcat(temp, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        strcat(temp, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        putenv(temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        /* else the value has already been set, do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        /* environment variable is not found */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        putenv(envstring);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#ifndef P_tmpdir
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#define P_tmpdir "/var/tmp"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/* This function gets called very early, before VM_CALLS are setup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * Do not use any of the VM_CALLS entries!!!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
java_props_t *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
GetJavaProperties(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    static java_props_t sprops = {0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    char *v; /* tmp var */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    if (sprops.user_dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /* tmp dir */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    sprops.tmp_dir = P_tmpdir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /* Printing properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    sprops.printerJob = "sun.print.PSPrinterJob";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /* patches/service packs installed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    sprops.patch_level = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /* Java 2D properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    sprops.graphics_env = "sun.awt.X11GraphicsEnvironment";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    sprops.awt_toolkit = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /* This is used only for debugging of font problems. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    v = getenv("JAVA2D_FONTPATH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    sprops.font_dir = v ? v : NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
#ifdef SI_ISALIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /* supported instruction sets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        char list[258];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        sysinfo(SI_ISALIST, list, sizeof(list));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        sprops.cpu_isalist = strdup(list);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    sprops.cpu_isalist = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /* endianness of platform */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        unsigned int endianTest = 0xff000000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        if (((char*)(&endianTest))[0] != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            sprops.cpu_endian = "big";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            sprops.cpu_endian = "little";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /* os properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        struct utsname name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        uname(&name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        sprops.os_name = strdup(name.sysname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        sprops.os_version = strdup(name.release);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        sprops.os_arch = ARCHPROPNAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            sprops.desktop = "gnome";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            sprops.desktop = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /* Determine the language, country, variant, and encoding from the host,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * and store these in the user.language, user.country, user.variant and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * file.encoding system properties. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        char *lc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        lc = setlocale(LC_CTYPE, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
#ifndef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (lc == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
             * 'lc == null' means system doesn't support user's environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
             * variable's locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
          setlocale(LC_ALL, "C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
          sprops.language = "en";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
          sprops.encoding = "ISO8859-1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
          sprops.sun_jnu_encoding = sprops.encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            lc = "en_US";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
             * locale string format in Solaris is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
             * <language name>_<country name>.<encoding name>@<variant name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
             * <country name>, <encoding name>, and <variant name> are optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            char temp[64];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            char *language = NULL, *country = NULL, *variant = NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                 *encoding = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            char *std_language = NULL, *std_country = NULL, *std_variant = NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                 *std_encoding = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            char *p, encoding_variant[64];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            int i, found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#ifndef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
             * Workaround for Solaris bug 4201684: Xlib doesn't like @euro
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
             * locales. Since we don't depend on the libc @euro behavior,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
             * we just remove the qualifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
             * On Linux, the bug doesn't occur; on the other hand, @euro
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
             * is needed there because it's a shortcut that also determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
             * the encoding - without it, we wouldn't get ISO-8859-15.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
             * Therefore, this code section is Solaris-specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            lc = strdup(lc);    /* keep a copy, setlocale trashes original. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            strcpy(temp, lc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            p = strstr(temp, "@euro");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (p != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            setlocale(LC_ALL, temp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            strcpy(temp, lc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            /* Parse the language, country, encoding, and variant from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
             * locale.  Any of the elements may be missing, but they must occur
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
             * in the order language_country.encoding@variant, and must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
             * preceded by their delimiter (except for language).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
             * If the locale name (without .encoding@variant, if any) matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
             * any of the names in the locale_aliases list, map it to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
             * corresponding full locale name.  Most of the entries in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
             * locale_aliases list are locales that include a language name but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
             * no country name, and this facility is used to map each language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
             * to a default country if that's possible.  It's also used to map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             * the Solaris locale aliases to their proper Java locale IDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if ((p = strchr(temp, '.')) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                strcpy(encoding_variant, p); /* Copy the leading '.' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            } else if ((p = strchr(temp, '@')) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                 strcpy(encoding_variant, p); /* Copy the leading '@' */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                 *p = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                *encoding_variant = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (mapLookup(locale_aliases, temp, &p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                strcpy(temp, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            language = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if ((country = strchr(temp, '_')) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                *country++ = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            p = encoding_variant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if ((encoding = strchr(p, '.')) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                p[encoding++ - p] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                p = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if ((variant = strchr(p, '@')) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                p[variant++ - p] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            /* Normalize the language name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            std_language = "en";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (language != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                mapLookup(language_names, language, &std_language);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            sprops.language = std_language;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            /* Normalize the country name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (country != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                std_country = country;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                mapLookup(country_names, country, &std_country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                sprops.country = strdup(std_country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            /* Normalize the variant name.  Note that we only use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
             * variants listed in the mapping array; others are ignored. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            if (variant != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                mapLookup(variant_names, variant, &std_variant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                sprops.variant = std_variant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            /* Normalize the encoding name.  Note that we IGNORE the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
             * 'encoding' extracted from the locale name above.  Instead, we use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
             * more reliable method of calling nl_langinfo(CODESET).  This function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
             * returns an empty string if no encoding is set for the given locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
             * (e.g., the C or POSIX locales); we use the default ISO 8859-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
             * converter for such locales.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            /* OK, not so reliable - nl_langinfo() gives wrong answers on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             * Euro locales, in particular. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if (strcmp(p, "ISO8859-15") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                p = "ISO8859-15";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                p = nl_langinfo(CODESET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            /* Convert the bare "646" used on Solaris to a proper IANA name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (strcmp(p, "646") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                p = "ISO646-US";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            /* return same result nl_langinfo would return for en_UK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
             * in order to use optimizations. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            std_encoding = (*p != '\0') ? p : "ISO8859-1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
             * Remap the encoding string to a different value for japanese
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
             * locales on linux so that customized converters are used instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
             * of the default converter for "EUC-JP". The customized converters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
             * omit support for the JIS0212 encoding which is not supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
             * the variant of "EUC-JP" encoding used on linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            if (strcmp(p, "EUC-JP") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                std_encoding = "EUC-JP-LINUX";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (strcmp(p,"eucJP") == 0) {
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   341
                /* For Solaris use customized vendor defined character
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   342
                 * customized EUC-JP converter
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   343
                 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                std_encoding = "eucJP-open";
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   345
            } else if (strcmp(p, "Big5") == 0 || strcmp(p, "BIG5") == 0) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   346
                /*
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   347
                 * Remap the encoding string to Big5_Solaris which augments
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   348
                 * the default converter for Solaris Big5 locales to include
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   349
                 * seven additional ideographic characters beyond those included
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   350
                 * in the Java "Big5" converter.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   351
                 */
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   352
                std_encoding = "Big5_Solaris";
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   353
            } else if (strcmp(p, "Big5-HKSCS") == 0) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   354
                /*
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   355
                 * Solaris uses HKSCS2001
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   356
                 */
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents: 2
diff changeset
   357
                std_encoding = "Big5-HKSCS-2001";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            sprops.encoding = std_encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            sprops.sun_jnu_encoding = sprops.encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
#if __BYTE_ORDER == __LITTLE_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    sprops.unicode_encoding = "UnicodeLittle";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    sprops.unicode_encoding = "UnicodeBig";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    sprops.unicode_encoding = "UnicodeBig";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /* user properties */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        struct passwd *pwent = getpwuid(getuid());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        sprops.user_name = pwent ? strdup(pwent->pw_name) : "?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /* User TIMEZONE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         * We defer setting up timezone until it's actually necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         * Refer to TimeZone.getDefault(). However, the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * property is necessary to be able to be set by the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         * line interface -D. Here temporarily set a null string to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * timezone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        tzset();        /* for compatibility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        sprops.timezone = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    /* Current directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        char buf[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        errno = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (getcwd(buf, sizeof(buf))  == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            JNU_ThrowByName(env, "java/lang/Error",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
             "Properties init: Could not determine current working directory.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            sprops.user_dir = strdup(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    sprops.file_separator = "/";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    sprops.path_separator = ":";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    sprops.line_separator = "\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /* Append CDE message and resource search path to NLSPATH and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * XFILESEARCHPATH, in order to pick localized message for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * FileSelectionDialog window (Bug 4173641).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    setPathEnvironment("NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    setPathEnvironment("XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    return &sprops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
}
5168
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   419
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   420
jstring
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   421
GetStringPlatform(JNIEnv *env, nchar* cstr)
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   422
{
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   423
    return JNU_NewStringPlatform(env, cstr);
41e46b5d9b15 4947220: (process)Runtime.exec() cannot invoke applications with unicode parameters(win)
sherman
parents: 5167
diff changeset
   424
}