summaryrefslogtreecommitdiff
path: root/legacy/evil/src/lib/evil_langinfo.c
blob: d478b0d0285a9e1f1063c4f427751c4c57645e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */

#include "Evil.h"


#ifndef __CEGCC__

static char *
replace(char *prev, char *value)
{
   if (value == NULL)
     return prev;

   if (prev)
     free (prev);
   return strdup (value);
}

char *
nl_langinfo(nl_item index)
{
   static char *result = NULL;
   static char *nothing = "";

   switch (index)
     {
      case CODESET:
        {
           char *p;
           result = replace(result, setlocale(LC_CTYPE, NULL));
           if ((p = strrchr(result, '.' )) == NULL)
             return nothing;

           if ((++p - result) > 2)
             strcpy(result, "cp");
           else
             *result = '\0';
           strcat(result, p);

           return result;
        }
     }

   return nothing;
}

#endif /* ! __CEGCC__ */