Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
locale_stub.cpp
Go to the documentation of this file.
1
27#include <cstdlib> // for size_t, system()
28#include <cstring> // for strcat(), strlen()
29
30
31int main (int argc, char *argv[])
32{
33 // compute the total length of the command line arguments
34 std::size_t arglen = 0;
35 for (int i = 0; i != argc; ++i)
36 arglen += std::strlen (argv [i]);
37
38 // add the length of space separating adjacent pairs
39 arglen += argc;
40
41 // add the length of the option to invoke localeded in locale mode
42 const char argv_1[] = "--locale-mode";
43 arglen += sizeof argv_1;
44
45 const char localedef[] = "localedef";
46 arglen += sizeof localedef;
47
48 // allocate space for the new command line
49 char* const cmdline = new char [arglen];
50
51 // replace the basename of argv[0] with "localedef" keeping the
52 // directory portion, if it's there, followed by the new option
53 // separated by a space
54 std::strcpy (cmdline, argv [0]);
55 char* slash = std::strrchr (cmdline, '/');
56
57 if (0 == slash) {
58 // look for backslash for Windoze
59 slash = std::strrchr (cmdline, '\\');
60 }
61
62 if (slash)
63 std::strcpy (slash + 1, localedef);
64 else
65 std::strcpy (cmdline, localedef);
66
67 std::strcat (cmdline, " ");
68 std::strcat (cmdline, argv_1);
69
70 // copy arguments to the newly allocated buffer
71 for (int i = 1; i != argc; ++i) {
72 std::strcat (cmdline, " ");
73 std::strcat (cmdline, argv [i]);
74 }
75
76 // invoke the localedef utility instructing it to switch
77 // to locale mode
78 const int status = std::system (cmdline);
79
80 // clean up
81 delete[] cmdline;
82
83 return status;
84}
#define i
Definition 17.names.cpp:126
#define main