diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 13:09:56 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2010-07-16 13:09:56 +0300 |
commit | bc70de7b3302d5a81515b901cae376b8b51d2004 (patch) | |
tree | d36d6743e65697f6923b79d0ea8f9f9bf4ef7398 /missing | |
parent | b9e4a1fd4c8c8753ab8a9887bab55f03efe1e3e2 (diff) | |
download | egawk-bc70de7b3302d5a81515b901cae376b8b51d2004.tar.gz egawk-bc70de7b3302d5a81515b901cae376b8b51d2004.tar.bz2 egawk-bc70de7b3302d5a81515b901cae376b8b51d2004.zip |
Move to gawk-3.1.0.
Diffstat (limited to 'missing')
-rwxr-xr-x | missing | 265 | ||||
-rw-r--r-- | missing/memcmp.c | 18 | ||||
-rw-r--r-- | missing/memcpy.c | 18 | ||||
-rw-r--r-- | missing/memset.c | 20 | ||||
-rw-r--r-- | missing/strchr.c | 47 | ||||
-rw-r--r-- | missing/strerror.c | 37 | ||||
-rw-r--r-- | missing/strftime.3 | 395 | ||||
-rw-r--r-- | missing/strftime.c | 923 | ||||
-rw-r--r-- | missing/strncasecmp.c | 102 | ||||
-rw-r--r-- | missing/strtod.c | 123 | ||||
-rw-r--r-- | missing/system.c | 27 | ||||
-rw-r--r-- | missing/tzset.c | 39 |
12 files changed, 265 insertions, 1749 deletions
diff --git a/missing b/missing new file mode 100755 index 00000000..5f9da906 --- /dev/null +++ b/missing @@ -0,0 +1,265 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. +# Copyright 1996, 1997, 1999, 2000 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. + +# 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. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing 0.3 - GNU automake" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acinclude.m4' or \`configure.in'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`configure.in'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acconfig.h' or \`configure.in'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' configure.in` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`configure.in'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar ${1+"$@"} && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar ${1+"$@"} && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" ${1+"$@"} && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" ${1+"$@"} && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequirements for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 diff --git a/missing/memcmp.c b/missing/memcmp.c deleted file mode 100644 index 63cb5f8f..00000000 --- a/missing/memcmp.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * memcmp --- compare strings. - * - * We use our own routine since it has to act like strcmp() for return - * value, and the BSD manual says bcmp() only returns zero/non-zero. - */ - -int -memcmp (s1, s2, l) -register char *s1, *s2; -register int l; -{ - for (; l-- > 0; s1++, s2++) { - if (*s1 != *s2) - return (*s1 - *s2); - } - return (0); -} diff --git a/missing/memcpy.c b/missing/memcpy.c deleted file mode 100644 index 3c4accdf..00000000 --- a/missing/memcpy.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * memcpy --- copy strings. - * - * We supply this routine for those systems that aren't standard yet. - */ - -char * -memcpy (dest, src, l) -register char *dest, *src; -register int l; -{ - register char *ret = dest; - - while (l--) - *dest++ = *src++; - - return ret; -} diff --git a/missing/memset.c b/missing/memset.c deleted file mode 100644 index 1ff4458b..00000000 --- a/missing/memset.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * memset --- initialize memory - * - * We supply this routine for those systems that aren't standard yet. - */ - -void * -memset(dest, val, l) -void *dest; -register int val; -register size_t l; -{ - register char *ret = dest; - register char *d = dest; - - while (l--) - *d++ = val; - - return ((void *) ret); -} diff --git a/missing/strchr.c b/missing/strchr.c deleted file mode 100644 index 7da479fc..00000000 --- a/missing/strchr.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * strchr --- search a string for a character - * - * We supply this routine for those systems that aren't standard yet. - */ - -#if 0 -#include <stdio.h> -#endif - -char * -strchr(str, c) -register const char *str, c; -{ - 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; -} - -/* - * strrchr --- find the last occurrence of a character in a string - * - * We supply this routine for those systems that aren't standard yet. - */ - -char * -strrchr(str, c) -register const char *str, c; -{ - register const char *save = NULL; - - for (; *str; str++) - if (*str == c) - save = str; - - return (char *) save; -} diff --git a/missing/strerror.c b/missing/strerror.c deleted file mode 100644 index 6a725995..00000000 --- a/missing/strerror.c +++ /dev/null @@ -1,37 +0,0 @@ -/* strerror.c --- ANSI C compatible system error routine - - Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc. - - 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. */ - -#if 0 -#include <stdio.h> -#endif - -extern int sys_nerr; -extern char *sys_errlist[]; - -char * -strerror(n) -int n; -{ - static char mesg[30]; - - 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 deleted file mode 100644 index 0ccd7d33..00000000 --- a/missing/strftime.3 +++ /dev/null @@ -1,395 +0,0 @@ -.TH STRFTIME 3 -.SH NAME -strftime \- generate formatted time information -.SH SYNOPSIS -.ft B -.nf -#include <sys/types.h> -#include <time.h> -.sp -size_t strftime(char *s, size_t maxsize, const char *format, - const struct tm *timeptr); -.SH DESCRIPTION -The following description is transcribed verbatim from the December 7, 1988 -draft standard for ANSI C. -This draft is essentially identical in technical content -to the final version of the standard. -.LP -The -.B strftime -function places characters into the array pointed to by -.B s -as controlled by the string pointed to by -.BR format . -The format shall be a multibyte character sequence, beginning and ending in -its initial shift state. -The -.B format -string consists of zero or more conversion specifiers and ordinary -multibyte characters. A conversion specifier consists of a -.B % -character followed by a character that determines the behavior of the -conversion specifier. -All ordinary multibyte characters (including the terminating null -character) are copied unchanged into the array. -If copying takes place between objects that overlap the behavior is undefined. -No more than -.B maxsize -characters are placed into the array. -Each conversion specifier is replaced by appropriate characters as described -in the following list. -The appropriate characters are determined by the -.B LC_TIME -category of the current locale and by the values contained in the -structure pointed to by -.BR timeptr . -.TP -.B %a -is replaced by the locale's abbreviated weekday name. -.TP -.B %A -is replaced by the locale's full weekday name. -.TP -.B %b -is replaced by the locale's abbreviated month name. -.TP -.B %B -is replaced by the locale's full month name. -.TP -.B %c -is replaced by the locale's appropriate date and time representation. -.TP -.B %d -is replaced by the day of the month as a decimal number -.RB ( 01 - 31 ). -.TP -.B %H -is replaced by the hour (24-hour clock) as a decimal number -.RB ( 00 - 23 ). -.TP -.B %I -is replaced by the hour (12-hour clock) as a decimal number -.RB ( 01 - 12 ). -.TP -.B %j -is replaced by the day of the year as a decimal number -.RB ( 001 - 366 ). -.TP -.B %m -is replaced by the month as a decimal number -.RB ( 01 - 12 ). -.TP -.B %M -is replaced by the minute as a decimal number -.RB ( 00 - 59 ). -.TP -.B %p -is replaced by the locale's equivalent of the AM/PM designations associated -with a 12-hour clock. -.TP -.B %S -is replaced by the second as a decimal number -.RB ( 00 - 60 ). -.TP -.B %U -is replaced by the week number of the year (the first Sunday as the first -day of week 1) as a decimal number -.RB ( 00 - 53 ). -.TP -.B %w -is replaced by the weekday as a decimal number -.RB [ "0 " (Sunday)- 6 ]. -.TP -.B %W -is replaced by the week number of the year (the first Monday as the first -day of week 1) as a decimal number -.RB ( 00 - 53 ). -.TP -.B %x -is replaced by the locale's appropriate date representation. -.TP -.B %X -is replaced by the locale's appropriate time representation. -.TP -.B %y -is replaced by the year without century as a decimal number -.RB ( 00 - 99 ). -.TP -.B %Y -is replaced by the year with century as a decimal number. -.TP -.B %Z -is replaced by the time zone name or abbreviation, or by no characters if -no time zone is determinable. -.TP -.B %% -is replaced by -.BR % . -.LP -If a conversion specifier is not one of the above, the behavior is -undefined. -.SH RETURNS -If the total number of resulting characters including the terminating null -character is not more than -.BR maxsize , -the -.B strftime -function returns the number of characters placed into the array pointed to -by -.B s -not including the terminating null character. -Otherwise, zero is returned and the contents of the array are indeterminate. -.SH NON-ANSI EXTENSIONS -If -.B SYSV_EXT -is defined when the routine is compiled, then the following additional -conversions will be available. -These are borrowed from the System V -.IR cftime (3) -and -.IR ascftime (3) -routines. -.TP -.B %D -is equivalent to specifying -.BR %m/%d/%y . -.TP -.B %e -is replaced by the day of the month, -padded with a blank if it is only one digit. -.TP -.B %h -is equivalent to -.BR %b , -above. -.TP -.B %n -is replaced with a newline character (\s-1ASCII LF\s+1). -.TP -.B %r -is equivalent to specifying -.BR "%I:%M:%S %p" . -.TP -.B %R -is equivalent to specifying -.BR %H:%M . -.TP -.B %T -is equivalent to specifying -.BR %H:%M:%S . -.TP -.B %t -is replaced with a \s-1TAB\s+1 character. -.PP -If -.B SUNOS_EXT -is defined when the routine is compiled, then the following additional -conversions will be available. -These are borrowed from the SunOS version of -.IR strftime . -.TP -.B %k -is replaced by the hour (24-hour clock) as a decimal number -.RB ( 0 - 23 ). -Single digit numbers are padded with a blank. -.TP -.B %l -is replaced by the hour (12-hour clock) as a decimal number -.RB ( 1 - 12 ). -Single digit numbers are padded with a blank. -.PP -If -.B HPUX_EXT -is defined when the routine is compiled, then the following additional -conversions will be available. -These are borrowed from the HP-UX version of -.IR date . -.TP -.B %E -The combined ``Emporer/Era'' name and year -(same as -.B %Y ). -This is only available if -.B POSIX2_DATE -is -.I not -defined. -.TP -.B %F -Same as -.BR %B . -(Marked as obsolescent in the HP-UX documentation.) -.TP -.B %N -The ``Emporer/Era'' name. -Typically, this is equivalent to the century -(same as -.B %C ). -.TP -.B %o -The ``Emporer/Era'' year. -Typically, this is equivalent to the year -(same as -.B %y ). -.TP -.B %z -The timezone name or abbreviation. -This is only available if -.B MAILHEADER_EXT -is -.I not -defined. -.SH POSIX 1003.2 EXTENSIONS -If -.B POSIX2_DATE -is defined, then all of the conversions available with -.B SYSV_EXT -and -.B SUNOS_EXT -are available, as well as the -following additional conversions: -.TP -.B %C -The century, as a number between 00 and 99. -.TP -.B %u -is replaced by the weekday as a decimal number -.RB [ "1 " (Monday)- 7 ]. -.TP -.B %V -is replaced by the week number of the year (the first Monday as the first -day of week 1) as a decimal number -.RB ( 01 - 53 ). -The method for determining the week number is as specified by ISO 8601 -(to wit: if the week 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 year (52 or 53) -and the next week is week 1). -.LP -The text of the POSIX standard for the -.I date -utility describes -.B %U -and -.B %W -this way: -.TP -.B %U -is replaced by the week number of the year (the first Sunday as the first -day of week 1) as a decimal number -.RB ( 00 - 53 ). -All days in a new year preceding the first Sunday are considered to be -in week 0. -.TP -.B %W -is replaced by the week number of the year (the first Monday as the first -day of week 1) as a decimal number -.RB ( 00 - 53 ). -All days in a new year preceding the first Monday are considered to be -in week 0. -.LP -In addition, the alternate representations -.BR %Ec , -.BR %EC , -.BR %Ex , -.BR %Ey , -.BR %EY , -.BR %Od , -.BR %Oe , -.BR %OH , -.BR %OI , -.BR %Om , -.BR %OM , -.BR %OS , -.BR %Ou , -.BR %OU , -.BR %OV , -.BR %Ow , -.BR %OW , -and -.B %Oy -are recognized, but their normal representations are used. -.SH VMS EXTENSIONS -If -.B VMS_EXT -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), -.IR localtime (3), -.IR tzset (3) -.SH BUGS -This version does not handle multibyte characters or pay attention to the -setting of the -.B LC_TIME -environment variable. -.LP -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 -is automatically defined, which forces the code to call -.IR tzset (3) -whenever the -.B TZ -environment variable has changed. -If this routine will be used in an application that will not be changing -.BR TZ , -then there may be some performance improvements by not defining -.BR POSIX_SEMANTICS . -.SH AUTHOR -.nf -Arnold Robbins -.sp -INTERNET: arnold@skeeve.com -.fi -.SH ACKNOWLEDGEMENTS -Thanks to Geoff Clare <gwc@root.co.uk> for helping debug earlier -versions of this routine, and for advice about POSIX semantics. -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 deleted file mode 100644 index 56412d21..00000000 --- a/missing/strftime.c +++ /dev/null @@ -1,923 +0,0 @@ -/* - * strftime.c - * - * Public-domain implementation of ANSI C library routine. - * - * It's written in old-style C for maximal portability. - * However, since I'm used to prototypes, I've included them too. - * - * If you want stuff in the System V ascftime routine, add the SYSV_EXT define. - * 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 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 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. - * - * This file is also shipped with GAWK (GNU Awk), gawk specific bits of - * code are included if GAWK is defined. - * - * Arnold Robbins - * January, February, March, 1991 - * Updated March, April 1992 - * Updated April, 1993 - * Updated February, 1994 - * Updated May, 1994 - * Updated January, 1995 - * Updated September, 1995 - * Updated January, 1996 - * Updated July, 1997 - * Updated October, 1999 - * - * Fixes from ado@elsie.nci.nih.gov - * February 1991, May 1992 - * Fixes from Tor Lillqvist tml@tik.vtt.fi - * 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 - * %v code fixed, better configuration - * July 1997 - */ - -#ifndef GAWK -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <time.h> -#endif -#if defined(TM_IN_SYS_TIME) || ! defined(GAWK) -#include <sys/types.h> -#include <sys/time.h> -#endif - -/* defaults: season to taste */ -#define SYSV_EXT 1 /* stuff in System V ascftime routine */ -#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 */ -#define HPUX_EXT 1 /* stuff in HP-UX date command */ -#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 -#endif -#if ! defined(SUNOS_EXT) -#define SUNOS_EXT 1 -#endif -#endif - -#if defined(POSIX2_DATE) -#define adddecl(stuff) stuff -#else -#define adddecl(stuff) -#endif - -#undef strchr /* avoid AIX weirdness */ - -#ifndef __STDC__ -#define const /**/ -extern void tzset(); -static int weeknumber(); -adddecl(static int iso8601wknum();) -#else -extern void tzset(void); -static int weeknumber(const struct tm *timeptr, int firstweekday); -adddecl(static int iso8601wknum(const struct tm *timeptr);) -#endif - -#ifdef STDC_HEADERS -#include <stdlib.h> -#include <string.h> -#else -extern void *malloc(); -extern void *realloc(); -extern char *getenv(); -extern char *strchr(); -#endif - -#ifdef __GNUC__ -#define inline __inline__ -#else -#define inline /**/ -#endif - -#define range(low, item, hi) max(low, min(item, hi)) - -#if !defined(OS2) && !defined(MSDOS) && defined(HAVE_TZNAME) -extern char *tzname[2]; -extern int daylight; -#if defined(SOLARIS) || defined(mips) -extern long int timezone, altzone; -#else -extern int timezone, altzone; -#endif -#endif - -#undef min /* just in case */ - -/* min --- return minimum of two numbers */ - -#ifndef __STDC__ -static inline int -min(a, b) -int a, b; -#else -static inline int -min(int a, int b) -#endif -{ - return (a < b ? a : b); -} - -#undef max /* also, just in case */ - -/* max --- return maximum of two numbers */ - -#ifndef __STDC__ -static inline int -max(a, b) -int a, b; -#else -static inline int -max(int a, int b) -#endif -{ - return (a > b ? a : b); -} - -/* strftime --- produce formatted time */ - -#ifndef __STDC__ -size_t -strftime(s, maxsize, format, timeptr) -char *s; -size_t maxsize; -const char *format; -const struct tm *timeptr; -#else -size_t -strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr) -#endif -{ - char *endp = s + maxsize; - char *start = s; - auto char tbuf[100]; - long off; - int i, w, y; - static short first = 1; -#ifdef POSIX_SEMANTICS - static char *savetz = NULL; - static int savetzlen = 0; - 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 */ - static const char *days_a[] = { - "Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat", - }; - static const char *days_l[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday", - }; - static const char *months_a[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - }; - static const char *months_l[] = { - "January", "February", "March", "April", - "May", "June", "July", "August", "September", - "October", "November", "December", - }; - static const char *ampm[] = { "AM", "PM", }; - - if (s == NULL || format == NULL || timeptr == NULL || maxsize == 0) - return 0; - - /* quick check if we even need to bother */ - if (strchr(format, '%') == NULL && strlen(format) + 1 >= maxsize) - return 0; - -#ifndef POSIX_SEMANTICS - if (first) { - tzset(); - first = 0; - } -#else /* POSIX_SEMANTICS */ - tz = getenv("TZ"); - if (first) { - if (tz != NULL) { - int tzlen = strlen(tz); - - savetz = (char *) malloc(tzlen + 1); - if (savetz != NULL) { - savetzlen = tzlen + 1; - strcpy(savetz, tz); - } - } - tzset(); - first = 0; - } - /* if we have a saved TZ, and it is different, recapture and reset */ - if (tz && savetz && (tz[0] != savetz[0] || strcmp(tz, savetz) != 0)) { - i = strlen(tz) + 1; - if (i > savetzlen) { - savetz = (char *) realloc(savetz, i); - if (savetz) { - savetzlen = i; - strcpy(savetz, tz); - } - } else - strcpy(savetz, tz); - tzset(); - } -#endif /* POSIX_SEMANTICS */ - - for (; *format && s < endp - 1; format++) { - tbuf[0] = '\0'; - if (*format != '%') { - *s++ = *format; - continue; - } - again: - switch (*++format) { - case '\0': - *s++ = '%'; - goto out; - - case '%': - *s++ = '%'; - continue; - - case 'a': /* abbreviated weekday name */ - if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6) - strcpy(tbuf, "?"); - else - strcpy(tbuf, days_a[timeptr->tm_wday]); - break; - - case 'A': /* full weekday name */ - if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6) - strcpy(tbuf, "?"); - else - strcpy(tbuf, days_l[timeptr->tm_wday]); - break; - -#ifdef SYSV_EXT - case 'h': /* abbreviated month name */ -#endif - case 'b': /* abbreviated month name */ - if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11) - strcpy(tbuf, "?"); - else - strcpy(tbuf, months_a[timeptr->tm_mon]); - break; - -#ifdef HPUX_EXT - case 'F': -#endif - case 'B': /* full month name */ - if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11) - strcpy(tbuf, "?"); - else - strcpy(tbuf, months_l[timeptr->tm_mon]); - break; - - case 'c': /* appropriate date and time representation */ - strftime(tbuf, sizeof tbuf, "%a %b %e %H:%M:%S %Y", timeptr); - break; - - case 'd': /* day of the month, 01 - 31 */ - i = range(1, timeptr->tm_mday, 31); - sprintf(tbuf, "%02d", i); - break; - - case 'H': /* hour, 24-hour clock, 00 - 23 */ - i = range(0, timeptr->tm_hour, 23); - sprintf(tbuf, "%02d", i); - break; - - case 'I': /* hour, 12-hour clock, 01 - 12 */ - i = range(0, timeptr->tm_hour, 23); - if (i == 0) - i = 12; - else if (i > 12) - i -= 12; - sprintf(tbuf, "%02d", i); - break; - - case 'j': /* day of the year, 001 - 366 */ - sprintf(tbuf, "%03d", timeptr->tm_yday + 1); - break; - - case 'm': /* month, 01 - 12 */ - i = range(0, timeptr->tm_mon, 11); - sprintf(tbuf, "%02d", i + 1); - break; - - case 'M': /* minute, 00 - 59 */ - i = range(0, timeptr->tm_min, 59); - sprintf(tbuf, "%02d", i); - break; - -#ifdef HPUX_EXT - case 'N': /* Emperor/Era name */ - /* this is essentially the same as the century */ - goto century; /* %C */ - - case 'o': /* Emperor/Era year */ - goto year; /* %y */ - -#ifndef POSIX2_DATE - case 'E': /* Combined Emporer/Era name and year */ - goto fullyear; /* %Y */ - -#endif /* POSIX2_DATE */ -#endif /* HPUX_EXT */ - - case 'p': /* am or pm based on 12-hour clock */ - i = range(0, timeptr->tm_hour, 23); - if (i < 12) - strcpy(tbuf, ampm[0]); - else - strcpy(tbuf, ampm[1]); - break; - - case 'S': /* second, 00 - 60 */ - i = range(0, timeptr->tm_sec, 60); - sprintf(tbuf, "%02d", i); - break; - - case 'U': /* week of year, Sunday is first day of week */ - sprintf(tbuf, "%02d", weeknumber(timeptr, 0)); - break; - - case 'w': /* weekday, Sunday == 0, 0 - 6 */ - i = range(0, timeptr->tm_wday, 6); - sprintf(tbuf, "%d", i); - break; - - case 'W': /* week of year, Monday is first day of week */ - sprintf(tbuf, "%02d", weeknumber(timeptr, 1)); - break; - - case 'x': /* appropriate date representation */ - strftime(tbuf, sizeof tbuf, "%m/%d/%y", timeptr); - break; - - case 'X': /* appropriate time representation */ - strftime(tbuf, sizeof tbuf, "%H:%M:%S", timeptr); - break; - - case 'y': /* year without a century, 00 - 99 */ - year: - i = timeptr->tm_year % 100; - sprintf(tbuf, "%02d", i); - break; - - case 'Y': /* year with century */ - fullyear: - 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 */ - -#if defined(HPUX_EXT) && ! defined(MAILHEADER_EXT) - case 'z': -#endif - case 'Z': /* time zone name or abbrevation */ -#ifdef HAVE_TZNAME - 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 > 0)); -#endif /* HAVE_TM_NAME */ -#endif /* HAVE_TM_ZONE */ -#endif /* HAVE_TZNAME */ - break; - -#ifdef SYSV_EXT - case 'n': /* same as \n */ - tbuf[0] = '\n'; - tbuf[1] = '\0'; - break; - - case 't': /* same as \t */ - tbuf[0] = '\t'; - tbuf[1] = '\0'; - break; - - case 'D': /* date as %m/%d/%y */ - strftime(tbuf, sizeof tbuf, "%m/%d/%y", timeptr); - break; - - case 'e': /* day of month, blank padded */ - sprintf(tbuf, "%2d", range(1, timeptr->tm_mday, 31)); - break; - - case 'r': /* time as %I:%M:%S %p */ - strftime(tbuf, sizeof tbuf, "%I:%M:%S %p", timeptr); - break; - - case 'R': /* time as %H:%M */ - strftime(tbuf, sizeof tbuf, "%H:%M", timeptr); - break; - - case 'T': /* time as %H:%M:%S */ - strftime(tbuf, sizeof tbuf, "%H:%M:%S", timeptr); - break; -#endif - -#ifdef SUNOS_EXT - case 'k': /* hour, 24-hour clock, blank pad */ - sprintf(tbuf, "%2d", range(0, timeptr->tm_hour, 23)); - break; - - case 'l': /* hour, 12-hour clock, 1 - 12, blank pad */ - i = range(0, timeptr->tm_hour, 23); - if (i == 0) - i = 12; - else if (i > 12) - i -= 12; - sprintf(tbuf, "%2d", i); - break; -#endif - - -#ifdef VMS_EXT - case 'v': /* date as dd-bbb-YYYY */ - sprintf(tbuf, "%2d-%3.3s-%4d", - range(1, timeptr->tm_mday, 31), - months_a[range(0, timeptr->tm_mon, 11)], - timeptr->tm_year + 1900); - for (i = 3; i < 6; i++) - if (islower(tbuf[i])) - tbuf[i] = toupper(tbuf[i]); - break; -#endif - - -#ifdef POSIX2_DATE - case 'C': - century: - sprintf(tbuf, "%02d", (timeptr->tm_year + 1900) / 100); - break; - - - case 'E': - case 'O': - /* POSIX locale extensions, ignored for now */ - goto again; - - case 'V': /* week of year according ISO 8601 */ - sprintf(tbuf, "%02d", iso8601wknum(timeptr)); - break; - - case 'u': - /* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */ - sprintf(tbuf, "%d", timeptr->tm_wday == 0 ? 7 : - 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; - tbuf[2] = '\0'; - break; - } - i = strlen(tbuf); - if (i) { - if (s + i < endp - 1) { - strcpy(s, tbuf); - s += i; - } else - return 0; - } - } -out: - if (s < endp && *format == '\0') { - *s = '\0'; - return (s - start); - } else - return 0; -} - -/* isleap --- is a year a leap year? */ - -#ifndef __STDC__ -static int -isleap(year) -int year; -#else -static int -isleap(int year) -#endif -{ - return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); -} - - -#ifdef POSIX2_DATE -/* iso8601wknum --- compute week number according to ISO 8601 */ - -#ifndef __STDC__ -static int -iso8601wknum(timeptr) -const struct tm *timeptr; -#else -static int -iso8601wknum(const struct tm *timeptr) -#endif -{ - /* - * From 1003.2: - * 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 - * 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. - * - * XPG4 erroneously included POSIX.2 rationale text in the - * main body of the standard. Thus it requires week 53. - */ - - int weeknum, jan1day, diff; - - /* get week number, Monday as first day of the week */ - weeknum = weeknumber(timeptr, 1); - - /* - * With thanks and tip of the hatlo to tml@tik.vtt.fi - * - * What day of the week does January 1 fall on? - * We know that - * (timeptr->tm_yday - jan1.tm_yday) MOD 7 == - * (timeptr->tm_wday - jan1.tm_wday) MOD 7 - * and that - * jan1.tm_yday == 0 - * and that - * timeptr->tm_wday MOD 7 == timeptr->tm_wday - * from which it follows that. . . - */ - jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7); - if (jan1day < 0) - jan1day += 7; - - /* - * If Jan 1 was a Monday through Thursday, it was in - * week 1. Otherwise it was last year's highest week, which is - * this year's week 0. - * - * What does that mean? - * If Jan 1 was Monday, the week number is exactly right, it can - * never be 0. - * If it was Tuesday through Thursday, the weeknumber is one - * less than it should be, so we add one. - * Otherwise, Friday, Saturday or Sunday, the week number is - * OK, but if it is 0, it needs to be 52 or 53. - */ - switch (jan1day) { - case 1: /* Monday */ - break; - case 2: /* Tuesday */ - case 3: /* Wednesday */ - case 4: /* Thursday */ - weeknum++; - break; - case 5: /* Friday */ - case 6: /* Saturday */ - case 0: /* Sunday */ - if (weeknum == 0) { -#ifdef USE_BROKEN_XPG4 - /* XPG4 (as of March 1994) says 53 unconditionally */ - weeknum = 53; -#else - /* get week number of last week of last year */ - struct tm dec31ly; /* 12/31 last year */ - dec31ly = *timeptr; - dec31ly.tm_year--; - dec31ly.tm_mon = 11; - dec31ly.tm_mday = 31; - dec31ly.tm_wday = (jan1day == 0) ? 6 : jan1day - 1; - dec31ly.tm_yday = 364 + isleap(dec31ly.tm_year + 1900); - weeknum = iso8601wknum(& dec31ly); -#endif - } - 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 - -/* weeknumber --- figure how many weeks into the year */ - -/* With thanks and tip of the hatlo to ado@elsie.nci.nih.gov */ - -#ifndef __STDC__ -static int -weeknumber(timeptr, firstweekday) -const struct tm *timeptr; -int firstweekday; -#else -static int -weeknumber(const struct tm *timeptr, int firstweekday) -#endif -{ - int wday = timeptr->tm_wday; - int ret; - - if (firstweekday == 1) { - if (wday == 0) /* sunday */ - wday = 6; - else - wday--; - } - ret = ((timeptr->tm_yday + 7 - wday) / 7); - if (ret < 0) - ret = 0; - return ret; -} - -#if 0 -/* ADR --- I'm loathe to mess with ado's code ... */ - -Date: Wed, 24 Apr 91 20:54:08 MDT -From: Michal Jaegermann <audfax!emory!vm.ucs.UAlberta.CA!NTOMCZAK> -To: arnold@audiofax.com - -Hi Arnold, -in a process of fixing of strftime() in libraries on Atari ST I grabbed -some pieces of code from your own strftime. When doing that it came -to mind that your weeknumber() function compiles a little bit nicer -in the following form: -/* - * firstweekday is 0 if starting in Sunday, non-zero if in Monday - */ -{ - return (timeptr->tm_yday - timeptr->tm_wday + - (firstweekday ? (timeptr->tm_wday ? 8 : 1) : 7)) / 7; -} -How nicer it depends on a compiler, of course, but always a tiny bit. - - Cheers, - Michal - ntomczak@vm.ucs.ualberta.ca -#endif - -#ifdef TEST_STRFTIME - -/* - * NAME: - * tst - * - * SYNOPSIS: - * tst - * - * DESCRIPTION: - * "tst" is a test driver for the function "strftime". - * - * OPTIONS: - * None. - * - * AUTHOR: - * Karl Vogel - * Control Data Systems, Inc. - * vogelke@c-17igp.wpafb.af.mil - * - * BUGS: - * None noticed yet. - * - * COMPILE: - * cc -o tst -DTEST_STRFTIME strftime.c - */ - -/* ADR: I reformatted this to my liking, and deleted some unneeded code. */ - -#ifndef NULL -#include <stdio.h> -#endif -#include <sys/time.h> -#include <string.h> - -#define MAXTIME 132 - -/* - * Array of time formats. - */ - -static char *array[] = -{ - "(%%A) full weekday name, var length (Sunday..Saturday) %A", - "(%%B) full month name, var length (January..December) %B", - "(%%C) Century %C", - "(%%D) date (%%m/%%d/%%y) %D", - "(%%E) Locale extensions (ignored) %E", - "(%%F) full month name, var length (January..December) %F", - "(%%H) hour (24-hour clock, 00..23) %H", - "(%%I) hour (12-hour clock, 01..12) %I", - "(%%M) minute (00..59) %M", - "(%%N) Emporer/Era Name %N", - "(%%O) Locale extensions (ignored) %O", - "(%%R) time, 24-hour (%%H:%%M) %R", - "(%%S) second (00..60) %S", - "(%%T) time, 24-hour (%%H:%%M:%%S) %T", - "(%%U) week of year, Sunday as first day of week (00..53) %U", - "(%%V) week of year according to ISO 8601 %V", - "(%%W) week of year, Monday as first day of week (00..53) %W", - "(%%X) appropriate locale time representation (%H:%M:%S) %X", - "(%%Y) year with century (1970...) %Y", - "(%%Z) timezone (EDT), or blank if timezone not determinable %Z", - "(%%a) locale's abbreviated weekday name (Sun..Sat) %a", - "(%%b) locale's abbreviated month name (Jan..Dec) %b", - "(%%c) full date (Sat Nov 4 12:02:33 1989)%n%t%t%t %c", - "(%%d) day of the month (01..31) %d", - "(%%e) day of the month, blank-padded ( 1..31) %e", - "(%%h) should be same as (%%b) %h", - "(%%j) day of the year (001..366) %j", - "(%%k) hour, 24-hour clock, blank pad ( 0..23) %k", - "(%%l) hour, 12-hour clock, blank pad ( 0..12) %l", - "(%%m) month (01..12) %m", - "(%%o) Emporer/Era Year %o", - "(%%p) locale's AM or PM based on 12-hour clock %p", - "(%%r) time, 12-hour (same as %%I:%%M:%%S %%p) %r", - "(%%u) ISO 8601: Weekday as decimal number [1 (Monday) - 7] %u", - "(%%v) VMS date (dd-bbb-YYYY) %v", - "(%%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 -}; - -/* main routine. */ - -int -main(argc, argv) -int argc; -char **argv; -{ - long time(); - - char *next; - char string[MAXTIME]; - - int k; - int length; - - struct tm *tm; - - long clock; - - /* Call the function. */ - - clock = time((long *) 0); - tm = localtime(&clock); - - for (k = 0; next = array[k]; k++) { - length = strftime(string, MAXTIME, next, tm); - printf("%s\n", string); - } - - exit(0); -} -#endif /* TEST_STRFTIME */ diff --git a/missing/strncasecmp.c b/missing/strncasecmp.c deleted file mode 100644 index 9d17c648..00000000 --- a/missing/strncasecmp.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 1987 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)strcasecmp.c 5.6 (Berkeley) 6/27/88"; -#endif /* LIBC_SCCS and not lint */ - -#ifdef atarist -#include <sys/types.h> -#else -#define u_char unsigned char -#endif - -/* This rather ugly macro is for VMS C */ -#ifdef C -#undef C -#endif -#define C(c) ((u_char)c) -/* - * This array is designed for mapping upper and lower case letter - * together for a case independent comparison. The mappings are - * based upon ascii character sequences. - */ -static u_char charmap[] = { - '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', - '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', - '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', - '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', - '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', - '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', - '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', - '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', - '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', - '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', - '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', - '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', - C('\200'), C('\201'), C('\202'), C('\203'), C('\204'), C('\205'), C('\206'), C('\207'), - C('\210'), C('\211'), C('\212'), C('\213'), C('\214'), C('\215'), C('\216'), C('\217'), - C('\220'), C('\221'), C('\222'), C('\223'), C('\224'), C('\225'), C('\226'), C('\227'), - C('\230'), C('\231'), C('\232'), C('\233'), C('\234'), C('\235'), C('\236'), C('\237'), - C('\240'), C('\241'), C('\242'), C('\243'), C('\244'), C('\245'), C('\246'), C('\247'), - C('\250'), C('\251'), C('\252'), C('\253'), C('\254'), C('\255'), C('\256'), C('\257'), - C('\260'), C('\261'), C('\262'), C('\263'), C('\264'), C('\265'), C('\266'), C('\267'), - C('\270'), C('\271'), C('\272'), C('\273'), C('\274'), C('\275'), C('\276'), C('\277'), - C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'), - C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'), - C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\327'), - C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\337'), - C('\340'), C('\341'), C('\342'), C('\343'), C('\344'), C('\345'), C('\346'), C('\347'), - C('\350'), C('\351'), C('\352'), C('\353'), C('\354'), C('\355'), C('\356'), C('\357'), - C('\360'), C('\361'), C('\362'), C('\363'), C('\364'), C('\365'), C('\366'), C('\367'), - C('\370'), C('\371'), C('\372'), C('\373'), C('\374'), C('\375'), C('\376'), C('\377'), -}; - -#undef C - -int -strcasecmp(s1, s2) - const char *s1, *s2; -{ - register u_char *cm = charmap, - *us1 = (u_char *)s1, - *us2 = (u_char *)s2; - - while (cm[*us1] == cm[*us2++]) - if (*us1++ == '\0') - return(0); - return(cm[*us1] - cm[*--us2]); -} - -int -strncasecmp(s1, s2, n) - const char *s1, *s2; - register size_t n; -{ - register u_char *cm = charmap, - *us1 = (u_char *)s1, - *us2 = (u_char *)s2; - - while ((long)(--n) >= 0 && cm[*us1] == cm[*us2++]) - if (*us1++ == '\0') - return(0); - return((long)n < 0 ? 0 : cm[*us1] - cm[*--us2]); -} diff --git a/missing/strtod.c b/missing/strtod.c deleted file mode 100644 index 7e6cc0c4..00000000 --- a/missing/strtod.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * strtod.c - * - * Stupid version of System V strtod(3) library routine. - * Does no overflow/underflow checking. - * - * A real number is defined to be - * optional leading white space - * optional sign - * string of digits with optional decimal point - * optional 'e' or 'E' - * followed by optional sign or space - * followed by an integer - * - * if ptr is not NULL a pointer to the character terminating the - * scan is returned in *ptr. If no number formed, *ptr is set to str - * and 0 is returned. - * - * For speed, we don't do the conversion ourselves. Instead, we find - * the end of the number and then call atof() to do the dirty work. - * This bought us a 10% speedup on a sample program at uunet.uu.net. - */ - -#if 0 -#include <ctype.h> -#endif - -extern double atof(); - -double -strtod(s, ptr) -register char *s; -register char **ptr; -{ - double ret = 0.0; - char *start = s; - char *begin = NULL; - int success = 0; - - /* optional white space */ - while (isspace(*s)) - s++; - - /* optional sign */ - if (*s == '+' || *s == '-') { - s++; - if (*(s-1) == '-') - begin = s - 1; - else - begin = s; - } - - /* string of digits with optional decimal point */ - if (isdigit(*s) && ! begin) - begin = s; - - while (isdigit(*s)) { - s++; - success++; - } - - if (*s == '.') { - if (! begin) - begin = s; - s++; - while (isdigit(*s)) - s++; - success++; - } - - if (s == start || success == 0) /* nothing there */ - goto out; - - /* - * optional 'e' or 'E' - * followed by optional sign or space - * followed by an integer - */ - - if (*s == 'e' || *s == 'E') { - s++; - - /* XXX - atof probably doesn't allow spaces here */ - while (isspace(*s)) - s++; - - if (*s == '+' || *s == '-') - s++; - - while (isdigit(*s)) - s++; - } - - /* go for it */ - ret = atof(begin); - -out: - if (! success) - s = start; /* in case all we did was skip whitespace */ - - if (ptr) - *ptr = s; - - return ret; -} - -#ifdef TEST -int -main(argc, argv) -int argc; -char **argv; -{ - double d; - char *p; - - for (argc--, argv++; argc; argc--, argv++) { - d = strtod (*argv, & p); - printf ("%lf [%s]\n", d, p); - } - - return 0; -} -#endif diff --git a/missing/system.c b/missing/system.c deleted file mode 100644 index 11db9925..00000000 --- a/missing/system.c +++ /dev/null @@ -1,27 +0,0 @@ -/* system.c --- replacement system() for systems missing one - - Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc. - - 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. */ - -extern void fatal(); - -int -system(s) -char *s; -{ - fatal("system() not supported on this system"); - return 0; -} diff --git a/missing/tzset.c b/missing/tzset.c deleted file mode 100644 index 678ec66d..00000000 --- a/missing/tzset.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * tzset.c - * - * Quick and dirty emulation of tzset(), tzname[], and daylight - * for old BSD systems without it. - * - * Thanks to Rick Adams, rick@uunet.uu.net, for the basics. - * - * BUGS: - * Totally ignores the value of the TZ environment variable. - */ - -#if 0 -#include <time.h> -#endif -#include <sys/time.h> - -static char tz1[1024]; -static char tz2[1024]; - -/* external variables */ -char *tzname[2] = { - tz1, tz2 -}; -int daylight; - -extern char *timezone(); - -void -tzset() -{ - struct timeval tp; - struct timezone tz; - - (void) gettimeofday(&tp, &tz); - (void) strcpy(tz1, timezone(tz.tz_minuteswest, 0)); - (void) strcpy(tz2, timezone(tz.tz_minuteswest, 1)); - daylight = tz.tz_dsttime; -} |