From: Bruno Haible Date: Thu, 25 Oct 2001 09:22:38 +0000 (+0000) Subject: Extract the time formatting code into a separate file po-time.c, to be used by X-Git-Tag: v0.11~415 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cfd5122406d7a7948d151570f59c3f95f4e49ec7;p=thirdparty%2Fgettext.git Extract the time formatting code into a separate file po-time.c, to be used by msginit. --- diff --git a/src/ChangeLog b/src/ChangeLog index 771757429..12e02d22b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2001-10-08 Bruno Haible + + * po-time.h: New file. + * po-time.c: New file, extracted from xgettext.c. + * xgettext.c: Include po-time.h. + (difftm): Move to po-time.c. + (construct_header): Move some code to po-time.c. Call po_strftime. + * Makefile.am (noinst_HEADERS): Add po-time.h. + (xgettext_SOURCES): Add po-time.c. + 2001-09-29 Bruno Haible * user-email.in: New file. diff --git a/src/Makefile.am b/src/Makefile.am index 1b415e9a8..a7f17cc37 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,8 +28,8 @@ noinst_PROGRAMS = hostname noinst_HEADERS = pos.h message.h po-gram.h po-hash.h po-charset.h po-lex.h \ po.h open-po.h read-po.h str-list.h write-po.h dir-list.h file-list.h \ po-gram-gen.h po-hash-gen.h msgl-charset.h msgl-equal.h msgl-iconv.h \ -msgl-ascii.h msgl-cat.h msgfmt.h read-mo.h write-mo.h xgettext.h x-c.h x-po.h \ -x-java.h x-ycp.h x-rst.h +msgl-ascii.h msgl-cat.h msgfmt.h read-mo.h write-mo.h po-time.h xgettext.h \ +x-c.h x-po.h x-java.h x-ycp.h x-rst.h EXTRA_DIST = FILES @@ -71,7 +71,7 @@ msgcmp_SOURCES = msgcmp.c $(COMMON_SOURCE) msgfmt_SOURCES = msgfmt.c $(COMMON_SOURCE) msgl-ascii.c msgl-iconv.c write-mo.c write-java.c plural.c plural-eval.c $(FORMAT_SOURCE) msgmerge_SOURCES = msgmerge.c $(COMMON_SOURCE) msgl-ascii.c write-po.c read-po.c msgl-equal.c msgunfmt_SOURCES = msgunfmt.c $(COMMON_SOURCE) msgl-ascii.c write-po.c read-po.c read-mo.c read-java.c -xgettext_SOURCES = xgettext.c $(COMMON_SOURCE) msgl-ascii.c write-po.c file-list.c x-c.c x-po.c x-java.l x-ycp.c x-rst.c $(FORMAT_SOURCE) +xgettext_SOURCES = xgettext.c $(COMMON_SOURCE) msgl-ascii.c write-po.c file-list.c po-time.c x-c.c x-po.c x-java.l x-ycp.c x-rst.c $(FORMAT_SOURCE) msgattrib_SOURCES = msgattrib.c $(COMMON_SOURCE) msgl-ascii.c write-po.c read-po.c msgcat_SOURCES = msgcat.c $(COMMON_SOURCE) msgl-ascii.c write-po.c read-po.c msgl-iconv.c msgl-cat.c file-list.c msgcomm_SOURCES = msgcomm.c $(COMMON_SOURCE) msgl-ascii.c write-po.c read-po.c msgl-iconv.c msgl-cat.c file-list.c diff --git a/src/po-time.c b/src/po-time.c new file mode 100644 index 000000000..75b680db3 --- /dev/null +++ b/src/po-time.c @@ -0,0 +1,84 @@ +/* PO/POT file timestamps. + Copyright (C) 1995-1998, 2000, 2001 Free Software Foundation, Inc. + Written by Ulrich Drepper , April 1995. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* Specification. */ +#include "po-time.h" + +#include "xerror.h" + + +/* Prototypes for local functions. Needed to ensure compiler checking of + function argument counts despite of K&R C function definition syntax. */ +static long difftm PARAMS ((const struct tm *a, const struct tm *b)); + + +#define TM_YEAR_ORIGIN 1900 + +/* Yield A - B, measured in seconds. */ +static long +difftm (a, b) + const struct tm *a; + const struct tm *b; +{ + int ay = a->tm_year + TM_YEAR_ORIGIN - 1; + int by = b->tm_year + TM_YEAR_ORIGIN - 1; + /* Some compilers cannot handle this as a single return statement. */ + long days = ( + /* difference in day of year */ + a->tm_yday - b->tm_yday + /* + intervening leap days */ + + ((ay >> 2) - (by >> 2)) + - (ay / 100 - by / 100) + + ((ay / 100 >> 2) - (by / 100 >> 2)) + /* + difference in years * 365 */ + + (long) (ay - by) * 365l); + + return 60l * (60l * (24l * days + (a->tm_hour - b->tm_hour)) + + (a->tm_min - b->tm_min)) + + (a->tm_sec - b->tm_sec); +} + + +char * +po_strftime (tp) + const time_t *tp; +{ + struct tm local_time; + char tz_sign; + long tz_min; + + local_time = *localtime (tp); + tz_sign = '+'; + tz_min = difftm (&local_time, gmtime (tp)) / 60; + if (tz_min < 0) + { + tz_min = -tz_min; + tz_sign = '-'; + } + return xasprintf ("%d-%02d-%02d %02d:%02d%c%02ld%02ld", + local_time.tm_year + TM_YEAR_ORIGIN, + local_time.tm_mon + 1, + local_time.tm_mday, + local_time.tm_hour, + local_time.tm_min, + tz_sign, tz_min / 60, tz_min % 60); +} diff --git a/src/po-time.h b/src/po-time.h new file mode 100644 index 000000000..3a81c1e32 --- /dev/null +++ b/src/po-time.h @@ -0,0 +1,28 @@ +/* PO/POT file timestamps. + Copyright (C) 2001 Free Software Foundation, Inc. + Written by Bruno Haible , 2001. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef _PO_TIME_H +#define _PO_TIME_H + +#include + +/* Return a freshly allocated string containing the given time in the + format YYYY-MM-DD HH:MM+TZOFF. */ +extern char *po_strftime PARAMS ((const time_t *tp)); + +#endif /* _PO_TIME_H */ diff --git a/src/xgettext.c b/src/xgettext.c index 5ce99e505..7281fe189 100644 --- a/src/xgettext.c +++ b/src/xgettext.c @@ -50,6 +50,7 @@ #include "system.h" #include "po.h" #include "message.h" +#include "po-time.h" #include "write-po.h" #include "format.h" #include "libgettext.h" @@ -178,7 +179,6 @@ static FILE *xgettext_open PARAMS ((const char *fn, char **logical_file_name_p, static void extract_from_file PARAMS ((const char *file_name, extractor_func extractor, msgdomain_list_ty *mdlp)); -static long difftm PARAMS ((const struct tm *a, const struct tm *b)); static message_ty *construct_header PARAMS ((void)); static extractor_func language_to_extractor PARAMS ((const char *name)); static const char *extension_to_language PARAMS ((const char *extension)); @@ -1022,69 +1022,29 @@ remember_a_message_plural (mp, string, pos) } -#define TM_YEAR_ORIGIN 1900 - -/* Yield A - B, measured in seconds. */ -static long -difftm (a, b) - const struct tm *a; - const struct tm *b; -{ - int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); - int by = b->tm_year + (TM_YEAR_ORIGIN - 1); - /* Some compilers cannot handle this as a single return statement. */ - long days = ( - /* difference in day of year */ - a->tm_yday - b->tm_yday - /* + intervening leap days */ - + ((ay >> 2) - (by >> 2)) - - (ay / 100 - by / 100) - + ((ay / 100 >> 2) - (by / 100 >> 2)) - /* + difference in years * 365 */ - + (long) (ay - by) * 365l); - - return 60l * (60l * (24l * days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec); -} - - static message_ty * construct_header () { time_t now; - struct tm local_time; + char *timestring; message_ty *mp; char *msgstr; static lex_pos_ty pos = { __FILE__, __LINE__, }; - char tz_sign; - long tz_min; time (&now); - local_time = *localtime (&now); - tz_sign = '+'; - tz_min = difftm (&local_time, gmtime (&now)) / 60; - if (tz_min < 0) - { - tz_min = -tz_min; - tz_sign = '-'; - } + timestring = po_strftime (&now); msgstr = xasprintf ("\ Project-Id-Version: PACKAGE VERSION\n\ -POT-Creation-Date: %d-%02d-%02d %02d:%02d%c%02ld%02ld\n\ +POT-Creation-Date: %s\n\ PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n\ Last-Translator: FULL NAME \n\ Language-Team: LANGUAGE \n\ MIME-Version: 1.0\n\ Content-Type: text/plain; charset=CHARSET\n\ Content-Transfer-Encoding: 8bit\n", - local_time.tm_year + TM_YEAR_ORIGIN, - local_time.tm_mon + 1, - local_time.tm_mday, - local_time.tm_hour, - local_time.tm_min, - tz_sign, tz_min / 60, tz_min % 60); + timestring); + free (timestring); mp = message_alloc ("", NULL, msgstr, strlen (msgstr) + 1, &pos);