Diff of /src/win32/winlang.c [000000] .. [3736ff]  Maximize  Restore

Switch to unified view

a b/src/win32/winlang.c
1
/* Copyright (C) 2008
2
 *   Written by Keith Marshall (keithmarshall@users.sourceforge.net)
3
 *
4
 * Provides:
5
 *   void win32_iso639_default( const char *varname );
6
 *
7
 *     This function may be used to establish the ISO-639 language
8
 *     code corresponding to the user's default locale, placing the
9
 *     returned value into the environment as an assignment for the
10
 *     variable specified by `varname'; the function performs no
11
 *     action, if `varname' has previously been assigned.
12
 *
13
 * This is free software; you can redistribute it and/or modify it
14
 * under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2, or (at your option)
16
 * any later version.
17
 *
18
 * This software is distributed in the hope that it will be useful, but
19
 * WITHOUT ANY WARRANTY of any kind; without even the implied warranty
20
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Please refer
21
 * to the GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this software; see the file COPYING.  If not, write to
25
 * the Free Software Foundation, 51 Franklin St - Fifth Floor, Boston,
26
 * MA 02110-1301, USA.
27
 */
28
#define WIN32_LEAN_AND_MEAN
29
#include <windows.h>
30
31
#include "compat.h"
32
33
#include <stdio.h>
34
#include <stdlib.h>
35
#include <string.h>
36
37
void win32_iso639_default( const char *varname )
38
{
39
  /* Assign the ISO-639 language identifier code, representing the
40
   * user's default locale, to the environment variable specified by
41
   * `varname', provided that variable has no prior assignment.
42
   */
43
  if( getenv( varname ) == NULL )
44
  {
45
    /* The specified environment variable hasn't been defined...
46
     * Allocate a buffer, sufficiently large to assemble an assignment
47
     * for it, with the appropriate ISO-639 language code in place.
48
     */
49
    size_t bufreq = strlen( varname ) + 10;
50
    char buf[ bufreq ], *value = buf + bufreq - 9;
51
52
    /* Use the Win32 API to retrieve the ISO-639 language code for the
53
     * user's default locale...
54
     */
55
    if( GetLocaleInfo( GetUserDefaultLCID(), LOCALE_SISO639LANGNAME, value, 9 )
56
    /*
57
     * and assemble it into the required format for assignment to the
58
     * specified environment variable...
59
     */
60
    &&  sprintf( buf, "%s=%s", varname, value )  )
61
      /*
62
       * if successfully assembled, add it to the environment.
63
       */
64
      putenv( buf );
65
  }
66
}
67
68
/* $RCSfile$: end of file */

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks