diff options
Diffstat (limited to 'missing')
-rw-r--r-- | missing/memset.c | 14 | ||||
-rw-r--r-- | missing/strchr.c | 22 | ||||
-rw-r--r-- | missing/strerror.c | 14 | ||||
-rw-r--r-- | missing/strftime.3 | 47 | ||||
-rw-r--r-- | missing/strftime.c | 197 | ||||
-rw-r--r-- | missing/system.c | 6 | ||||
-rw-r--r-- | missing/tzset.c | 3 |
7 files changed, 231 insertions, 72 deletions
diff --git a/missing/memset.c b/missing/memset.c index 120bdcb4..1ff4458b 100644 --- a/missing/memset.c +++ b/missing/memset.c @@ -4,15 +4,17 @@ * We supply this routine for those systems that aren't standard yet. */ -char * -memset (dest, val, l) -register char *dest, val; -register int l; +void * +memset(dest, val, l) +void *dest; +register int val; +register size_t l; { register char *ret = dest; + register char *d = dest; while (l--) - *dest++ = val; + *d++ = val; - return ret; + return ((void *) ret); } diff --git a/missing/strchr.c b/missing/strchr.c index 76016d89..7da479fc 100644 --- a/missing/strchr.c +++ b/missing/strchr.c @@ -4,13 +4,25 @@ * We supply this routine for those systems that aren't standard yet. */ +#if 0 +#include <stdio.h> +#endif + char * -strchr (str, c) +strchr(str, c) register const char *str, c; { - for (; *str; str++) - if (*str == c) - return (char *) str; + if (c == '\0') { + /* thanks to Mike Brennan ... */ + do { + if (*str == c) + return (char *) str; + } while (*str++); + } else { + for (; *str; str++) + if (*str == c) + return (char *) str; + } return NULL; } @@ -22,7 +34,7 @@ register const char *str, c; */ char * -strrchr (str, c) +strrchr(str, c) register const char *str, c; { register const char *save = NULL; diff --git a/missing/strerror.c b/missing/strerror.c index badaf5dd..e49fdb65 100644 --- a/missing/strerror.c +++ b/missing/strerror.c @@ -6,7 +6,7 @@ * Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the - * AWK Progamming Language. + * AWK Programming Language. * * GAWK is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +19,14 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GAWK; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#if 0 +#include <stdio.h> +#endif + extern int sys_nerr; extern char *sys_errlist[]; @@ -32,8 +36,8 @@ int n; { static char mesg[30]; - if (n < 0 || n > sys_nerr) { - sprintf (mesg, "Unknown error (%d)", n); + if (n < 0 || n >= sys_nerr) { + sprintf(mesg, "Unknown error (%d)", n); return mesg; } else return sys_errlist[n]; diff --git a/missing/strftime.3 b/missing/strftime.3 index 9efe8408..76fc02a0 100644 --- a/missing/strftime.3 +++ b/missing/strftime.3 @@ -274,6 +274,39 @@ is defined, then the following additional conversion is available: .TP .B %v The date in VMS format (e.g. 20-JUN-1991). +.SH MAIL HEADER EXTENSIONS +If +.B MAILHEADER_EXT +is defined, then the following additional conversion is available: +.TP +.B %z +The timezone offset in a +HHMM format (e.g. the format necessary to +produce RFC-822/RFC-1036 date headers). +.SH ISO DATE FORMAT EXTENSIONS +If +.B ISO_DATE_EXT +is defined, then all of the conversions available with +.BR POSIX2_DATE, +.BR SYSV_EXT, +and +.B SUNOS_EXT +are available, as well as the +following additional conversions: +.TP +.B %G +is replaced by the year with century of the ISO week number (see +.BR %V , +above) as a decimal number. +.TP +.B %g +is replaced by the year without century of the ISO week number, +as a decimal number +.RB ( 00 - 99 ). +.PP +For example, January 1, 1993, is in week 53 of 1992. Thus, the year +of its ISO week number is 1992, even though its year is 1993. +Similarly, December 31, 1973, is in week 1 of 1974. Thus, the year +of its ISO week number is 1974, even though its year is 1973. .SH SEE ALSO .IR time (2), .IR ctime (3), @@ -285,8 +318,12 @@ setting of the .B LC_TIME environment variable. .LP -It is not clear what is ``appropriate'' for the C locale; the values -returned are a best guess on the author's part. +The ``appropriate'' values used for +.BR %c , +.BR %x , +are +.B %X +are those specified by the 1003.2 standard for the POSIX locale. .SH CAVEATS The pre-processor symbol .B POSIX_SEMANTICS @@ -303,9 +340,7 @@ then there may be some performance improvements by not defining .nf Arnold Robbins .sp -INTERNET: arnold@skeeve.atl.ga.us -UUCP: emory!skeeve!arnold -Phone: +1 404 248 9324 +INTERNET: arnold@gnu.ai.mit.edu .fi .SH ACKNOWLEDGEMENTS Thanks to Geoff Clare <gwc@root.co.uk> for helping debug earlier @@ -314,3 +349,5 @@ Additional thanks to Arthur David Olsen <ado@elsie.nci.nih.gov> for some code improvements. Thanks also to Tor Lillqvist <tml@tik.vtt.fi> for code fixes to the ISO 8601 code. +Thanks to Hume Smith for pointing out a problem with the ISO 8601 code +and to Arthur David Olsen for further discussions. diff --git a/missing/strftime.c b/missing/strftime.c index 629eb5f2..478471c3 100644 --- a/missing/strftime.c +++ b/missing/strftime.c @@ -10,9 +10,12 @@ * For extensions from SunOS, add SUNOS_EXT. * For stuff needed to implement the P1003.2 date command, add POSIX2_DATE. * For VMS dates, add VMS_EXT. + * For a an RFC822 time format, add MAILHEADER_EXT. + * For ISO week years, add ISO_DATE_EXT. * For complete POSIX semantics, add POSIX_SEMANTICS. * - * The code for %c, %x, and %X is my best guess as to what's "appropriate". + * The code for %c, %x, and %X now follows the 1003.2 specification for + * the POSIX locale. * This version ignores LOCALE information. * It also doesn't worry about multi-byte characters. * So there. @@ -26,6 +29,9 @@ * Updated April, 1993 * Updated February, 1994 * Updated May, 1994 + * Updated January, 1995 + * Updated September, 1995 + * Updated January, 1996 * * Fixes from ado@elsie.nci.nih.gov * February 1991, May 1992 @@ -33,17 +39,12 @@ * May, 1993 * Further fixes from ado@elsie.nci.nih.gov * February 1994 + * %z code from chip@chinacat.unicom.com + * Applied September 1995 + * %V code fixed (again) and %G, %g added, + * January 1996 */ -/************ for gawk 2.15.5 ***************/ -#ifndef TZNAME_MISSING -#define HAVE_TZNAME -#endif -#ifndef TM_ZONE_MISSING -#define HAVE_TM_ZONE -#endif -/*********** end of for gawk 2.15.5 *********/ - #ifndef GAWK #include <stdio.h> #include <ctype.h> @@ -60,10 +61,18 @@ #define SUNOS_EXT 1 /* stuff in SunOS strftime routine */ #define POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */ #define VMS_EXT 1 /* include %v for VMS date format */ +#define MAILHEADER_EXT 1 /* add %z for HHMM format */ +#define ISO_DATE_EXT 1 /* %G and %g for year of ISO week */ #ifndef GAWK #define POSIX_SEMANTICS 1 /* call tzset() if TZ changes */ #endif +#if defined(ISO_DATE_EXT) +#if ! defined(POSIX2_DATE) +#define POSIX2_DATE 1 +#endif +#endif + #if defined(POSIX2_DATE) #if ! defined(SYSV_EXT) #define SYSV_EXT 1 @@ -111,8 +120,15 @@ adddecl(static int iso8601wknum(const struct tm *timeptr);) #if !defined(OS2) && !defined(MSDOS) && defined(HAVE_TZNAME) extern char *tzname[2]; extern int daylight; +#ifdef SOLARIS +extern long timezone, altzone; +#else +extern int timezone, altzone; +#endif #endif +#undef min /* just in case */ + /* min --- return minimum of two numbers */ #ifndef __STDC__ @@ -127,6 +143,8 @@ min(int a, int b) return (a < b ? a : b); } +#undef max /* also, just in case */ + /* max --- return maximum of two numbers */ #ifndef __STDC__ @@ -158,7 +176,8 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) char *endp = s + maxsize; char *start = s; auto char tbuf[100]; - int i; + long off; + int i, w, y; static short first = 1; #ifdef POSIX_SEMANTICS static char *savetz = NULL; @@ -166,9 +185,13 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) char *tz; #endif /* POSIX_SEMANTICS */ #ifndef HAVE_TM_ZONE +#ifndef HAVE_TM_NAME +#ifndef HAVE_TZNAME extern char *timezone(); struct timeval tv; struct timezone zone; +#endif /* HAVE_TZNAME */ +#endif /* HAVE_TM_NAME */ #endif /* HAVE_TM_ZONE */ /* various tables, useful in North America */ @@ -281,14 +304,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) break; case 'c': /* appropriate date and time representation */ - sprintf(tbuf, "%s %s %2d %02d:%02d:%02d %d", - days_a[range(0, timeptr->tm_wday, 6)], - months_a[range(0, timeptr->tm_mon, 11)], - range(1, timeptr->tm_mday, 31), - range(0, timeptr->tm_hour, 23), - range(0, timeptr->tm_min, 59), - range(0, timeptr->tm_sec, 61), - timeptr->tm_year + 1900); + strftime(tbuf, sizeof tbuf, "%a %b %e %H:%M:%S %Y", timeptr); break; case 'd': /* day of the month, 01 - 31 */ @@ -351,18 +367,11 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) break; case 'x': /* appropriate date representation */ - sprintf(tbuf, "%s %s %2d %d", - days_a[range(0, timeptr->tm_wday, 6)], - months_a[range(0, timeptr->tm_mon, 11)], - range(1, timeptr->tm_mday, 31), - timeptr->tm_year + 1900); + strftime(tbuf, sizeof tbuf, "%m/%d/%y", timeptr); break; case 'X': /* appropriate time representation */ - sprintf(tbuf, "%02d:%02d:%02d", - range(0, timeptr->tm_hour, 23), - range(0, timeptr->tm_min, 59), - range(0, timeptr->tm_sec, 61)); + strftime(tbuf, sizeof tbuf, "%H:%M:%S", timeptr); break; case 'y': /* year without a century, 00 - 99 */ @@ -374,19 +383,75 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) sprintf(tbuf, "%d", 1900 + timeptr->tm_year); break; +#ifdef MAILHEADER_EXT + /* + * From: Chip Rosenthal <chip@chinacat.unicom.com> + * Date: Sun, 19 Mar 1995 00:33:29 -0600 (CST) + * + * Warning: the %z [code] is implemented by inspecting the + * timezone name conditional compile settings, and + * inferring a method to get timezone offsets. I've tried + * this code on a couple of machines, but I don't doubt + * there is some system out there that won't like it. + * Maybe the easiest thing to do would be to bracket this + * with an #ifdef that can turn it off. The %z feature + * would be an admittedly obscure one that most folks can + * live without, but it would be a great help to those of + * us that muck around with various message processors. + */ + case 'z': /* time zone offset east of GMT e.g. -0600 */ +#ifdef HAVE_TM_NAME + /* + * Systems with tm_name probably have tm_tzadj as + * secs west of GMT. Convert to mins east of GMT. + */ + off = -timeptr->tm_tzadj / 60; +#else /* !HAVE_TM_NAME */ +#ifdef HAVE_TM_ZONE + /* + * Systems with tm_zone probably have tm_gmtoff as + * secs east of GMT. Convert to mins east of GMT. + */ + off = timeptr->tm_gmtoff / 60; +#else /* !HAVE_TM_ZONE */ +#if HAVE_TZNAME + /* + * Systems with tzname[] probably have timezone as + * secs west of GMT. Convert to mins east of GMT. + */ + off = -(daylight ? timezone : altzone) / 60; +#else /* !HAVE_TZNAME */ + off = -zone.tz_minuteswest; +#endif /* !HAVE_TZNAME */ +#endif /* !HAVE_TM_ZONE */ +#endif /* !HAVE_TM_NAME */ + if (off < 0) { + tbuf[0] = '-'; + off = -off; + } else { + tbuf[0] = '+'; + } + sprintf(tbuf+1, "%02d%02d", off/60, off%60); + break; +#endif /* MAILHEADER_EXT */ + case 'Z': /* time zone name or abbrevation */ #ifdef HAVE_TZNAME - i = (daylight && timeptr->tm_isdst); /* 0 or 1 */ + i = (daylight && timeptr->tm_isdst > 0); /* 0 or 1 */ strcpy(tbuf, tzname[i]); #else #ifdef HAVE_TM_ZONE strcpy(tbuf, timeptr->tm_zone); #else +#ifdef HAVE_TM_NAME + strcpy(tbuf, timeptr->tm_name); +#else gettimeofday(& tv, & zone); strcpy(tbuf, timezone(zone.tz_minuteswest, - timeptr->tm_isdst)); -#endif -#endif + timeptr->tm_isdst > 0)); +#endif /* HAVE_TM_NAME */ +#endif /* HAVE_TM_ZONE */ +#endif /* HAVE_TZNAME */ break; #ifdef SYSV_EXT @@ -462,19 +527,6 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) goto again; case 'V': /* week of year according ISO 8601 */ -#if defined(GAWK) && defined(VMS_EXT) - { - extern int do_lint; - extern void warning(); - static int warned = 0; - - if (! warned && do_lint) { - warned = 1; - warning( - "conversion %%V added in P1003.2; for VMS style date, use %%v"); - } - } -#endif sprintf(tbuf, "%02d", iso8601wknum(timeptr)); break; @@ -484,6 +536,33 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) timeptr->tm_wday); break; #endif /* POSIX2_DATE */ + +#ifdef ISO_DATE_EXT + case 'G': + case 'g': + /* + * Year of ISO week. + * + * If it's December but the ISO week number is one, + * that week is in next year. + * If it's January but the ISO week number is 52 or + * 53, that week is in last year. + * Otherwise, it's this year. + */ + w = iso8601wknum(timeptr); + if (timeptr->tm_mon == 11 && w == 1) + y = 1900 + timeptr->tm_year + 1; + else if (timeptr->tm_mon == 0 && w >= 52) + y = 1900 + timeptr->tm_year - 1; + else + y = 1900 + timeptr->tm_year; + + if (*format == 'G') + sprintf(tbuf, "%d", y); + else + sprintf(tbuf, "%02d", y % 100); + break; +#endif ISO_DATE_EXT default: tbuf[0] = '%'; tbuf[1] = *format; @@ -539,7 +618,7 @@ iso8601wknum(const struct tm *timeptr) * If the week (Monday to Sunday) containing January 1 * has four or more days in the new year, then it is week 1; * otherwise it is the highest numbered week of the previous - * (52 or 53) year, and the next week is week 1. + * year (52 or 53), and the next week is week 1. * * ADR: This means if Jan 1 was Monday through Thursday, * it was week 1, otherwise week 52 or 53. @@ -587,7 +666,7 @@ iso8601wknum(const struct tm *timeptr) case 1: /* Monday */ break; case 2: /* Tuesday */ - case 3: /* Wednedsday */ + case 3: /* Wednesday */ case 4: /* Thursday */ weeknum++; break; @@ -612,6 +691,29 @@ iso8601wknum(const struct tm *timeptr) } break; } + + if (timeptr->tm_mon == 11) { + /* + * The last week of the year + * can be in week 1 of next year. + * Sigh. + * + * This can only happen if + * M T W + * 29 30 31 + * 30 31 + * 31 + */ + int wday, mday; + + wday = timeptr->tm_wday; + mday = timeptr->tm_mday; + if ( (wday == 1 && (mday >= 29 && mday <= 31)) + || (wday == 2 && (mday == 30 || mday == 31)) + || (wday == 3 && mday == 31)) + weeknum = 1; + } + return weeknum; } #endif @@ -749,6 +851,7 @@ static char *array[] = "(%%w) day of week (0..6, Sunday == 0) %w", "(%%x) appropriate locale date representation %x", "(%%y) last two digits of year (00..99) %y", + "(%%z) timezone offset east of GMT as HHMM (e.g. -0500) %z", (char *) NULL }; diff --git a/missing/system.c b/missing/system.c index fffb39c1..8e613a3a 100644 --- a/missing/system.c +++ b/missing/system.c @@ -6,7 +6,7 @@ * Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc. * * This file is part of GAWK, the GNU implementation of the - * AWK Progamming Language. + * AWK Programming Language. * * GAWK is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,8 +19,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with GAWK; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ extern void fatal(); diff --git a/missing/tzset.c b/missing/tzset.c index 7e0af48a..678ec66d 100644 --- a/missing/tzset.c +++ b/missing/tzset.c @@ -11,8 +11,9 @@ */ #if 0 -#include <sys/time.h> +#include <time.h> #endif +#include <sys/time.h> static char tz1[1024]; static char tz2[1024]; |