libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 5431186e5c82220b2db96bf653a1fd91730ba172
parent 0b566b4f7075acfd30b9ebf9635c2edef6c957f1
Author: Nils Durner <durner@gnunet.org>
Date:   Sat, 12 Mar 2005 22:09:39 +0000

nl_langinfo for Windows

Diffstat:
Mconfigure.ac | 2++
Msrc/include/platform.h | 140++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/include/winproc.h | 5+++++
Msrc/main/extract.c | 4----
Msrc/main/extractor.c | 4----
Msrc/main/winproc.c | 194++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/plugins/Makefile.am | 6++++--
Msrc/plugins/filenameextractor.c | 4----
Msrc/plugins/tarextractor.c | 4----
9 files changed, 343 insertions(+), 20 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -101,6 +101,8 @@ AC_CHECK_LIB(stdc++, fclose) # but: only use for the PDF extractor and NOT for everything else! XTRA_CPPLIBS=$LIBS $XTRA_CPPLIBS +AC_CHECK_HEADER(langinfo.h) + LIBS=$LIBSOLD # FIXME: allow --with-oggvorbis=PFX diff --git a/src/include/platform.h b/src/include/platform.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001 - 2005 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other contributing authors) libextractor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -54,6 +54,7 @@ #else #include <winsock2.h> #include <pthread.h> + #include <locale.h> #endif #ifndef MINGW @@ -116,4 +117,141 @@ #define socklen_t unsigned int #endif +#ifndef HAVE_LANGINFO_H +/* Modified version of glibc's langinfo.h */ + +/* Enumeration of locale items that can be queried with `nl_langinfo'. */ +enum +{ + /* LC_TIME category: date and time formatting. */ + + /* Abbreviated days of the week. */ + ABDAY_1, /* Sun */ +#define ABDAY_1 ABDAY_1 + ABDAY_2, +#define ABDAY_2 ABDAY_2 + ABDAY_3, +#define ABDAY_3 ABDAY_3 + ABDAY_4, +#define ABDAY_4 ABDAY_4 + ABDAY_5, +#define ABDAY_5 ABDAY_5 + ABDAY_6, +#define ABDAY_6 ABDAY_6 + ABDAY_7, +#define ABDAY_7 ABDAY_7 + + /* Long-named days of the week. */ + DAY_1, /* Sunday */ +#define DAY_1 DAY_1 + DAY_2, /* Monday */ +#define DAY_2 DAY_2 + DAY_3, /* Tuesday */ +#define DAY_3 DAY_3 + DAY_4, /* Wednesday */ +#define DAY_4 DAY_4 + DAY_5, /* Thursday */ +#define DAY_5 DAY_5 + DAY_6, /* Friday */ +#define DAY_6 DAY_6 + DAY_7, /* Saturday */ +#define DAY_7 DAY_7 + + /* Abbreviated month names. */ + ABMON_1, /* Jan */ +#define ABMON_1 ABMON_1 + ABMON_2, +#define ABMON_2 ABMON_2 + ABMON_3, +#define ABMON_3 ABMON_3 + ABMON_4, +#define ABMON_4 ABMON_4 + ABMON_5, +#define ABMON_5 ABMON_5 + ABMON_6, +#define ABMON_6 ABMON_6 + ABMON_7, +#define ABMON_7 ABMON_7 + ABMON_8, +#define ABMON_8 ABMON_8 + ABMON_9, +#define ABMON_9 ABMON_9 + ABMON_10, +#define ABMON_10 ABMON_10 + ABMON_11, +#define ABMON_11 ABMON_11 + ABMON_12, +#define ABMON_12 ABMON_12 + + /* Long month names. */ + MON_1, /* January */ +#define MON_1 MON_1 + MON_2, +#define MON_2 MON_2 + MON_3, +#define MON_3 MON_3 + MON_4, +#define MON_4 MON_4 + MON_5, +#define MON_5 MON_5 + MON_6, +#define MON_6 MON_6 + MON_7, +#define MON_7 MON_7 + MON_8, +#define MON_8 MON_8 + MON_9, +#define MON_9 MON_9 + MON_10, +#define MON_10 MON_10 + MON_11, +#define MON_11 MON_11 + MON_12, +#define MON_12 MON_12 + + AM_STR, /* Ante meridian string. */ +#define AM_STR AM_STR + PM_STR, /* Post meridian string. */ +#define PM_STR PM_STR + + D_T_FMT, /* Date and time format for strftime. */ +#define D_T_FMT D_T_FMT + D_FMT, /* Date format for strftime. */ +#define D_FMT D_FMT + T_FMT, /* Time format for strftime. */ +#define T_FMT T_FMT + T_FMT_AMPM, /* 12-hour time format for strftime. */ +#define T_FMT_AMPM T_FMT_AMPM + + ERA, /* Alternate era. */ +#define ERA ERA + ERA_D_FMT, /* Date in alternate era format. */ +#define ERA_D_FMT ERA_D_FMT + ALT_DIGITS, /* Alternate symbols for digits. */ +#define ALT_DIGITS ALT_DIGITS + ERA_D_T_FMT, /* Date and time in alternate era format. */ +#define ERA_D_T_FMT ERA_D_T_FMT + ERA_T_FMT, /* Time in alternate era format. */ +#define ERA_T_FMT ERA_T_FMT + _DATE_FMT, /* strftime format for date. */ +#define _DATE_FMT _DATE_FMT + CODESET, +#define CODESET CODESET + CRNCYSTR, +#define CRNCYSTR CRNCYSTR + RADIXCHAR, +#define RADIXCHAR RADIXCHAR + THOUSEP, +#define THOUSEP THOUSEP + YESEXPR, +#define YESEXPR YESEXPR + NOEXPR, /* Regex matching ``no'' input. */ +#define NOEXPR NOEXPR + /* This marks the highest value used. */ + _NL_NUM +}; +#else + #include <langinfo.h> +#endif /* #ifndef HAVE_LANGINFO_H */ + #endif diff --git a/src/include/winproc.h b/src/include/winproc.h @@ -34,11 +34,13 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/timeb.h> +#include <time.h> #include <dirent.h> #include <windows.h> #include <winsock.h> #include <winerror.h> #include <iphlpapi.h> +#include "platform.h" #ifdef __cplusplus extern "C" { @@ -338,6 +340,9 @@ void *_win_mmap(void *start, size_t len, int access, int flags, int fd, unsigned long long offset); int _win_munmap(void *start, size_t length); char *_win_strerror(int errnum); +#ifndef HAVE_LANGINFO_H +char *nl_langinfo(int item); +#endif #if !HAVE_STRNDUP char *strndup (const char *s, size_t n); diff --git a/src/main/extract.c b/src/main/extract.c @@ -189,11 +189,7 @@ printSelectedKeywords(FILE * handle, char * buf; cd = iconv_open( -#ifdef MINGW - "char" -#else nl_langinfo(CODESET) -#endif , "UTF-8"); while (keywords != NULL) { buf = NULL; diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -720,11 +720,7 @@ EXTRACTOR_printKeywords(FILE * handle, char * buf; cd = iconv_open( -#ifdef MINGW - "" -#else nl_langinfo(CODESET) -#endif , "UTF-8"); while (keywords != NULL) { diff --git a/src/main/winproc.c b/src/main/winproc.c @@ -1,6 +1,6 @@ /* This file is part of libextractor. - (C) 2004 - 2005 Christian Grothoff (and other contributing authors) + (C) 2004, 2005 Christian Grothoff (and other contributing authors) libextractor is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -50,6 +50,7 @@ static char szUser[261]; static OSVERSIONINFO theWinVersion; unsigned int uiSockCount = 0; Winsock *pSocks; +static char __langinfo[251]; static HINSTANCE hNTDLL, hIphlpapi; TNtQuerySystemInformation GNNtQuerySystemInformation; @@ -466,6 +467,7 @@ void InitWinEnv() /* Use ANSI codepage for console IO */ SetConsoleCP(CP_ACP); SetConsoleOutputCP(CP_ACP); + setlocale( LC_ALL, ".OCP" ); } /** @@ -2131,6 +2133,196 @@ size_t strnlen (const char *str, size_t maxlen) } #endif +/** + * language information + */ +#ifndef HAVE_LANGINFO_H +char *nl_langinfo(int item) +{ + unsigned int loc; + + loc = GetThreadLocale(); + + switch(item) + { + case CODESET: + { + unsigned int cp = GetACP(); + + if (cp) + sprintf(__langinfo, "CP%u", cp); + else + strcpy(__langinfo, "UTF-8"); /* ? */ + return __langinfo; + } + case D_T_FMT: + case T_FMT_AMPM: + case ERA_D_T_FMT: + strcpy(__langinfo, "%c"); + return __langinfo; + case D_FMT: + case ERA_D_FMT: + strcpy(__langinfo, "%x"); + return __langinfo; + case T_FMT: + case ERA_T_FMT: + strcpy(__langinfo, "%X"); + return __langinfo; + case AM_STR: + GetLocaleInfo(loc, LOCALE_S1159, __langinfo, 251); + return __langinfo; + case PM_STR: + GetLocaleInfo(loc, LOCALE_S2359, __langinfo, 251); + return __langinfo; + case DAY_1: + GetLocaleInfo(loc, LOCALE_SDAYNAME1, __langinfo, 251); + return __langinfo; + case DAY_2: + GetLocaleInfo(loc, LOCALE_SDAYNAME2, __langinfo, 251); + return __langinfo; + case DAY_3: + GetLocaleInfo(loc, LOCALE_SDAYNAME3, __langinfo, 251); + return __langinfo; + case DAY_4: + GetLocaleInfo(loc, LOCALE_SDAYNAME4, __langinfo, 251); + return __langinfo; + case DAY_5: + GetLocaleInfo(loc, LOCALE_SDAYNAME5, __langinfo, 251); + return __langinfo; + case DAY_6: + GetLocaleInfo(loc, LOCALE_SDAYNAME6, __langinfo, 251); + return __langinfo; + case DAY_7: + GetLocaleInfo(loc, LOCALE_SDAYNAME7, __langinfo, 251); + return __langinfo; + case ABDAY_1: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME1, __langinfo, 251); + return __langinfo; + case ABDAY_2: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME2, __langinfo, 251); + return __langinfo; + case ABDAY_3: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME3, __langinfo, 251); + return __langinfo; + case ABDAY_4: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME4, __langinfo, 251); + return __langinfo; + case ABDAY_5: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME5, __langinfo, 251); + return __langinfo; + case ABDAY_6: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME6, __langinfo, 251); + return __langinfo; + case ABDAY_7: + GetLocaleInfo(loc, LOCALE_SABBREVDAYNAME7, __langinfo, 251); + return __langinfo; + case MON_1: + GetLocaleInfo(loc, LOCALE_SMONTHNAME1, __langinfo, 251); + return __langinfo; + case MON_2: + GetLocaleInfo(loc, LOCALE_SMONTHNAME2, __langinfo, 251); + return __langinfo; + case MON_3: + GetLocaleInfo(loc, LOCALE_SMONTHNAME3, __langinfo, 251); + return __langinfo; + case MON_4: + GetLocaleInfo(loc, LOCALE_SMONTHNAME4, __langinfo, 251); + return __langinfo; + case MON_5: + GetLocaleInfo(loc, LOCALE_SMONTHNAME5, __langinfo, 251); + return __langinfo; + case MON_6: + GetLocaleInfo(loc, LOCALE_SMONTHNAME6, __langinfo, 251); + return __langinfo; + case MON_7: + GetLocaleInfo(loc, LOCALE_SMONTHNAME7, __langinfo, 251); + return __langinfo; + case MON_8: + GetLocaleInfo(loc, LOCALE_SMONTHNAME8, __langinfo, 251); + return __langinfo; + case MON_9: + GetLocaleInfo(loc, LOCALE_SMONTHNAME9, __langinfo, 251); + return __langinfo; + case MON_10: + GetLocaleInfo(loc, LOCALE_SMONTHNAME10, __langinfo, 251); + return __langinfo; + case MON_11: + GetLocaleInfo(loc, LOCALE_SMONTHNAME11, __langinfo, 251); + return __langinfo; + case MON_12: + GetLocaleInfo(loc, LOCALE_SMONTHNAME12, __langinfo, 251); + return __langinfo; + case ABMON_1: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME1, __langinfo, 251); + return __langinfo; + case ABMON_2: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME2, __langinfo, 251); + return __langinfo; + case ABMON_3: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME3, __langinfo, 251); + return __langinfo; + case ABMON_4: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME4, __langinfo, 251); + return __langinfo; + case ABMON_5: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME5, __langinfo, 251); + return __langinfo; + case ABMON_6: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME6, __langinfo, 251); + return __langinfo; + case ABMON_7: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME7, __langinfo, 251); + return __langinfo; + case ABMON_8: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME8, __langinfo, 251); + return __langinfo; + case ABMON_9: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME9, __langinfo, 251); + return __langinfo; + case ABMON_10: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME10, __langinfo, 251); + return __langinfo; + case ABMON_11: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME11, __langinfo, 251); + return __langinfo; + case ABMON_12: + GetLocaleInfo(loc, LOCALE_SABBREVMONTHNAME12, __langinfo, 251); + return __langinfo; + case ERA: + /* Not implemented */ + __langinfo[0] = 0; + return __langinfo; + case ALT_DIGITS: + GetLocaleInfo(loc, LOCALE_SNATIVEDIGITS, __langinfo, 251); + return __langinfo; + case RADIXCHAR: + GetLocaleInfo(loc, LOCALE_SDECIMAL, __langinfo, 251); + return __langinfo; + case THOUSEP: + GetLocaleInfo(loc, LOCALE_STHOUSAND, __langinfo, 251); + return __langinfo; + case YESEXPR: + /* Not localized */ + strcpy(__langinfo, "^[yY]"); + return __langinfo; + case NOEXPR: + /* Not localized */ + strcpy(__langinfo, "^[nN]"); + return __langinfo; + case CRNCYSTR: + GetLocaleInfo(loc, LOCALE_STHOUSAND, __langinfo, 251); + if (__langinfo[0] == '0' || __langinfo[0] == '2') + __langinfo[0] = '-'; + else + __langinfo[0] = '+'; + GetLocaleInfo(loc, LOCALE_SCURRENCY, __langinfo + 1, 251); + default: + __langinfo[0] = 0; + return __langinfo; + } +} +#endif + #ifdef __cplusplus } #endif diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -128,7 +128,8 @@ libextractor_asf_la_LDFLAGS = \ libextractor_tar_la_SOURCES = \ tarextractor.c libextractor_tar_la_LDFLAGS = \ - $(PLUGINFLAGS) -lz + $(PLUGINFLAGS) -lz \ + $(top_builddir)/src/main/libextractor.la libextractor_lower_la_SOURCES = \ lowerextractor.c @@ -228,7 +229,8 @@ libextractor_png_la_LIBADD = \ libextractor_filename_la_SOURCES = \ filenameextractor.c libextractor_filename_la_LDFLAGS = \ - $(PLUGINFLAGS) + $(PLUGINFLAGS) \ + $(top_builddir)/src/main/libextractor.la libextractor_filename_la_LIBADD = \ libconvert.la diff --git a/src/plugins/filenameextractor.c b/src/plugins/filenameextractor.c @@ -44,11 +44,7 @@ struct EXTRACTOR_Keywords * libextractor_filename_extract(const char * filename, keyword->next = prev; keyword->keyword = convertToUtf8(filenameRoot, strlen(filenameRoot), -#ifndef MINGW nl_langinfo(CODESET) -#else - "" -#endif ); keyword->keywordType = EXTRACTOR_FILENAME; return keyword; diff --git a/src/plugins/tarextractor.c b/src/plugins/tarextractor.c @@ -166,11 +166,7 @@ struct EXTRACTOR_Keywords * libextractor_tar_extract(const char * filename, ctm = *gmtime(&ctime); if (strftime(tmbuf, sizeof(tmbuf), -#ifndef MINGW nl_langinfo(D_FMT), -#else - "%x", -#endif &ctm)) prev = addKeyword(EXTRACTOR_CREATION_DATE, strdup(tmbuf), prev); }