| 1 | #include <locale.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <wchar.h>
|
|---|
| 5 |
|
|---|
| 6 | /* This is the relevant piece from the charmap:
|
|---|
| 7 | <UFF61> /x8e/xa1 HALFWIDTH IDEOGRAPHIC FULL STOP
|
|---|
| 8 | <UFF62> /x8e/xa2 HALFWIDTH LEFT CORNER BRACKET
|
|---|
| 9 | <UFF63> /x8e/xa3 HALFWIDTH RIGHT CORNER BRACKET
|
|---|
| 10 | <UFF64> /x8e/xa4 HALFWIDTH IDEOGRAPHIC COMMA
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 | const char input[] = "\x8e\xa1g\x8e\xa2h\x8e\xa3i\x8e\xa4j";
|
|---|
| 14 |
|
|---|
| 15 | int
|
|---|
| 16 | main (void)
|
|---|
| 17 | {
|
|---|
| 18 | wchar_t buf[1000];
|
|---|
| 19 | #define nbuf (sizeof (buf) / sizeof (buf[0]))
|
|---|
| 20 | int result = 0;
|
|---|
| 21 | ssize_t n;
|
|---|
| 22 |
|
|---|
| 23 | if (setlocale (LC_ALL, "ja_JP.EUC-JP") == NULL)
|
|---|
| 24 | {
|
|---|
| 25 | puts ("cannot set locale");
|
|---|
| 26 | exit (1);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | #define CHECK(fmt, nexp, exp) \
|
|---|
| 30 | n = swprintf (buf, nbuf, fmt, input); \
|
|---|
| 31 | if (n != nexp) \
|
|---|
| 32 | { \
|
|---|
| 33 | printf ("swprintf (.., .., L\"%ls\", \"%ls\") return %d, not %d\n", \
|
|---|
| 34 | fmt, (wchar_t*) input, (int) n, (int) nexp); \
|
|---|
| 35 | result = 1; \
|
|---|
| 36 | } \
|
|---|
| 37 | else if (wcscmp (buf, exp) != 0) \
|
|---|
| 38 | { \
|
|---|
| 39 | printf ("\
|
|---|
| 40 | swprintf (.., .., L\"%ls\", \"%ls\") produced \"%ls\", not \"%ls\"\n", \
|
|---|
| 41 | fmt, (wchar_t *) input, buf, exp ); \
|
|---|
| 42 | result = 1; \
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | CHECK (L"[%-6.0s]", 8, L"[ ]");
|
|---|
| 46 | CHECK (L"[%-6.1s]", 8, L"[\xff61 ]");
|
|---|
| 47 | CHECK (L"[%-6.2s]", 8, L"[\xff61g ]");
|
|---|
| 48 | CHECK (L"[%-6.3s]", 8, L"[\xff61g\xff62 ]");
|
|---|
| 49 | CHECK (L"[%-6.4s]", 8, L"[\xff61g\xff62h ]");
|
|---|
| 50 | CHECK (L"[%-6.5s]", 8, L"[\xff61g\xff62h\xff63 ]");
|
|---|
| 51 | CHECK (L"[%-6.6s]", 8, L"[\xff61g\xff62h\xff63i]");
|
|---|
| 52 | CHECK (L"[%-6.7s]", 9, L"[\xff61g\xff62h\xff63i\xff64]");
|
|---|
| 53 | CHECK (L"[%-6.8s]", 10, L"[\xff61g\xff62h\xff63i\xff64j]");
|
|---|
| 54 |
|
|---|
| 55 | return result;
|
|---|
| 56 | }
|
|---|