diff --git a/src/mcsfile/main.c b/src/mcsfile/main.c index f1b32f6..c938723 100644 --- a/src/mcsfile/main.c +++ b/src/mcsfile/main.c @@ -10,6 +10,7 @@ #include "main.h" #include #include +#include #define cry(S, ...) fprintf(stderr, (S), ##__VA_ARGS__) /** @@ -23,6 +24,9 @@ int main(int ac, char **av) { + /* set the locale */ + setlocale(LC_ALL, ""); + /* parse arguments */ const char *path; if (parse_args(ac, av, &path)) diff --git a/src/mcsfile/print.c b/src/mcsfile/print.c index d1a7a4a..e348c8b 100644 --- a/src/mcsfile/print.c +++ b/src/mcsfile/print.c @@ -10,6 +10,7 @@ #include "main.h" #include #include +#include /* ************************************************************************** */ /* Sort */ @@ -64,7 +65,7 @@ static void sort_files(g1m_t *handle) static void put_description(g1m_mcsfile_t *file) { if (!file->head.type) - printf("unknown content (%" PRIuSIZE" octets)\n", file->head.size); + printf("unknown content (%" PRIuSIZE " octets)\n", file->head.size); else if (file->head.type & g1m_mcstype_program) { printf("program ("); if (g1m_has_password(file)) @@ -119,7 +120,7 @@ void put_files(g1m_t *handle) int max_size = 0; for (int i = 0; i < handle->count; i++) { g1m_mcsfile_t *file = handle->files[i]; - int sz = strlen(file->head.name); + int sz = fc_mbstous(NULL, file->head.name, 0); if (file->head._dirname[0]) sz += strlen((char*)file->head._dirname) + 1; if (sz > max_size) max_size = sz; @@ -127,15 +128,17 @@ void put_files(g1m_t *handle) max_size++; /* put the lines */ - char buf[max_size + 1]; + wchar_t buf[max_size + 1], endbuf[max_size + 2]; for (int i = 0; i < handle->count; i++) if (handle->files[i]) { g1m_mcsfile_t *file = handle->files[i]; buf[0] = 0; if (file->head._dirname[0]) - sprintf(buf, "%s/", (char*)file->head._dirname); - sprintf(&buf[strlen(buf)], "%s:", file->head.name); + swprintf(buf, max_size + 1, L"%s/", (char*)file->head._dirname); + fc_mbstous(&buf[wcslen(buf)], file->head.name, 0); + wcscpy(&buf[wcslen(buf)], L":"); + swprintf(endbuf, max_size + 2, L"%-*ls ", max_size, buf); - printf("%-*s ", max_size, buf); + printf("%ls", endbuf); put_description(handle->files[i]); } }