From: Roland McGrath Date: Tue, 27 Feb 1996 19:19:12 +0000 (+0000) Subject: Tue Feb 27 12:14:59 1996 Roland McGrath X-Git-Tag: upstream/2.30~29647 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7459e56bd36389bab3dbcc06418b94a256e0138;p=external%2Fglibc.git Tue Feb 27 12:14:59 1996 Roland McGrath * time/strftime.c: Support - and _ flags to affect number padding. * sysdeps/unix/common/tcsendbrk.c: New file. --- diff --git a/ChangeLog b/ChangeLog index e6f5808..272ff34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Feb 27 12:14:59 1996 Roland McGrath + + * time/strftime.c: Support - and _ flags to affect number padding. + + * sysdeps/unix/common/tcsendbrk.c: New file. + Mon Feb 26 10:22:30 1996 Roland McGrath * sysdeps/unix/dirstream.h: Rewritten. diff --git a/sysdeps/stub/direct.h b/sysdeps/stub/direct.h deleted file mode 100644 index 7205130..0000000 --- a/sysdeps/stub/direct.h +++ /dev/null @@ -1,5 +0,0 @@ -/* This file should define `struct direct' on Unix systems. - This is the type of actual records in directory files. - See readdir.c. */ - -#error No struct dirent definition. diff --git a/sysdeps/unix/bsd/bsd4.4/direct.h b/sysdeps/unix/bsd/bsd4.4/direct.h deleted file mode 100644 index 06641fc..0000000 --- a/sysdeps/unix/bsd/bsd4.4/direct.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MAXNAMLEN -#define MAXNAMLEN 255 -#endif - -struct direct - { - unsigned long int d_fileno; - unsigned short int d_reclen; - unsigned char d_type; /* File type, possibly unknown. */ - unsigned char d_namlen; /* Length of the file name. */ - char d_name[MAXNAMLEN + 1]; - }; - -#define D_NAMLEN(d) ((d)->d_namlen) - -#define HAVE_D_TYPE diff --git a/sysdeps/unix/bsd/direct.h b/sysdeps/unix/bsd/direct.h deleted file mode 100644 index d663bbb..0000000 --- a/sysdeps/unix/bsd/direct.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef MAXNAMLEN -#define MAXNAMLEN 255 -#endif - -struct direct - { - unsigned int d_fileno; /* 32 bits. */ - unsigned short int d_reclen; /* 16 bits. */ - unsigned short int d_namlen; /* 16 bits. */ - char d_name[MAXNAMLEN + 1]; - }; - -#define D_NAMLEN(d) ((d)->d_namlen) diff --git a/sysdeps/unix/common/direct.h b/sysdeps/unix/common/direct.h deleted file mode 100644 index ef88147..0000000 --- a/sysdeps/unix/common/direct.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (C) 1992, 1993 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifndef _BSDDIR_H -#define _BSDDIR_H 1 - -#include - -/* This is what system V calls a "struct dirent". */ - -struct direct - { - unsigned long int d_fileno; - long int d_off; - unsigned short int d_reclen; - char d_name[NAME_MAX + 1]; - }; - -#include - -/* We calculate the length of the name by taking the length of the whole - `struct direct' record, subtracting the size of everything before the - name, and subtracting one for the terminating null. */ - -#define D_NAMLEN(d) \ - ((d)->d_reclen - offsetof (struct direct, d_name) - 1) - -#endif diff --git a/sysdeps/unix/common/tcsendbrk.c b/sysdeps/unix/common/tcsendbrk.c new file mode 100644 index 0000000..348321a --- /dev/null +++ b/sysdeps/unix/common/tcsendbrk.c @@ -0,0 +1,47 @@ +/* Send break to terminal. +Copyright (C) 1996 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#include +#include +#include +#include + +/* Send zero bits on FD. */ +int +tcsendbreak (int fd, int duration) +{ + /* The break lasts 0.25 to 0.5 seconds if DURATION is zero, + and an implementation-defined period if DURATION is nonzero. + We define a positive DURATION to be number of milliseconds to break. */ + if (duration <= 0) + return __ioctl (fd, TCSBRK, 0); + +#ifdef TCSBRKP + /* Probably Linux-specific: a positive third TCSBRKP ioctl argument is + defined to be the number of 100ms units to break. */ + return __ioctl (fd, TCSBRKP, (duration + 99) / 100); +#else + /* ioctl can't send a break of any other duration for us. + This could be changed to use trickery (e.g. lower speed and + send a '\0') to send the break, but for now just return an error. */ + errno = EINVAL; + return -1; +#endif +} + diff --git a/sysdeps/unix/sysv/irix4/direct.h b/sysdeps/unix/sysv/irix4/direct.h deleted file mode 100644 index 153087f..0000000 --- a/sysdeps/unix/sysv/irix4/direct.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MAXNAMLEN -#define MAXNAMLEN 255 -#endif - -struct direct - { - unsigned long int d_ino; - off_t d_off; - unsigned short int d_reclen; - char d_name[MAXNAMLEN + 1]; - }; - -#define D_NAMLEN(d) (strlen ((d)->d_name)) - -#define D_RECLEN(d) (d->d_reclen) diff --git a/sysdeps/unix/sysv/isc3/direct.h b/sysdeps/unix/sysv/isc3/direct.h deleted file mode 100644 index e6df212..0000000 --- a/sysdeps/unix/sysv/isc3/direct.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/sco3.2.4/direct.h b/sysdeps/unix/sysv/sco3.2.4/direct.h deleted file mode 100644 index b3eaa54..0000000 --- a/sysdeps/unix/sysv/sco3.2.4/direct.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MAXNAMLEN -#define MAXNAMLEN 512 -#endif -#define DIRBUF 1048 /* minimum buffer size for call to getdents */ - -struct direct - { - unsigned short int d_fileno; - short int d_pad; - long int d_off; - unsigned short int d_reclen; - char d_name[1]; /* Actually longer. */ - }; - -#include - -/* We calculate the length of the name by taking the length of the whole - `struct direct' record, subtracting the size of everything before the - name, and subtracting one for the terminating null. */ - -#define D_NAMLEN(d) \ - ((d)->d_reclen - offsetof (struct direct, d_name) - 1) diff --git a/sysdeps/unix/sysv/sysv4/solaris2/direct.h b/sysdeps/unix/sysv/sysv4/solaris2/direct.h deleted file mode 100644 index f9822dc..0000000 --- a/sysdeps/unix/sysv/sysv4/solaris2/direct.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1992, 1993 Free Software Foundation, Inc. -This file is part of the GNU C Library. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library 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 -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifndef _BSDDIR_H -#define _BSDDIR_H 1 - -#include - -/* This is the Solaris direct; it's the same as that in - sysdeps/unix/sysv/sysv4/direct.h, but it uses the length given by d_namlen, - since we can't reliably use tyhe sysv4/direct.h method of computing - the length. */ - -struct direct - { - unsigned long int d_fileno; - long int d_off; - unsigned short int d_reclen; - char d_name[NAME_MAX + 1]; - }; - -#define D_NAMLEN(d) (strlen ((d)->d_name)) - -#endif diff --git a/time/strftime.c b/time/strftime.c index 40a7a74..73f1ac2 100644 --- a/time/strftime.c +++ b/time/strftime.c @@ -1,9 +1,4 @@ -/* Extensions for GNU date that are still missing here: - - - _ -*/ - -/* Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. +/* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -94,6 +89,8 @@ static unsigned int week __P((const struct tm *const, int)); #define fmt(n, args) add((n), sprintf args; if (strlen (p) != (n)) return 0) #endif + + /* Return the week in the year specified by TP, with weeks starting on STARTING_DAY. */ #ifdef __GNUC__ @@ -175,6 +172,10 @@ strftime (s, maxsize, format, tp) register size_t i = 0; register char *p = s; register const char *f; + char number_fmt[5]; + + /* Initialize the buffer we will use for the sprintf format for numbers. */ + number_fmt[0] = '%'; zone = 0; #if HAVE_TM_ZONE @@ -196,6 +197,9 @@ strftime (s, maxsize, format, tp) for (f = format; *f != '\0'; ++f) { + enum { pad_zero, pad_space, pad_none } pad; /* Padding for number. */ + unsigned int maxdigits; /* Max digits for numeric format. */ + unsigned int number_value; /* Numeric value to be printed. */ const char *subfmt; #if HAVE_MBLEN @@ -217,9 +221,26 @@ strftime (s, maxsize, format, tp) continue; } + /* Check for flags that can modify a number format. */ ++f; switch (*f) { + case '_': + pad = pad_space; + ++f; + break; + case '-': + pad = pad_none; + ++f; + break; + default: + pad = pad_zero; + break; + } + + /* Now do the specified format. */ + switch (*f) + { case '\0': case '%': add(1, *p = *f); @@ -257,9 +278,13 @@ strftime (s, maxsize, format, tp) } break; +#define DO_NUMBER(digits, value) \ + maxdigits = digits; number_value = value; goto do_number +#define DO_NUMBER_NOPAD(digits, value) \ + maxdigits = digits; number_value = value; goto do_number_nopad + case 'C': - fmt (2, (p, "%02d", (1900 + tp->tm_year) / 100)); - break; + DO_NUMBER (2, (1900 + tp->tm_year) / 100); case 'x': #ifdef _NL_CURRENT @@ -272,40 +297,67 @@ strftime (s, maxsize, format, tp) goto subformat; case 'd': - fmt(2, (p, "%02d", tp->tm_mday)); - break; + DO_NUMBER (2, tp->tm_mday); case 'e': /* GNU extension: %d, but blank-padded. */ - fmt(2, (p, "%2d", tp->tm_mday)); - break; + DO_NUMBER_NOPAD (2, tp->tm_mday); + + /* All numeric formats set MAXDIGITS and NUMBER_VALUE and then + jump to one of these two labels. */ + + do_number_nopad: + /* Force `-' flag. */ + pad = pad_none; + + do_number: + { + /* Format the number according to the PAD flag. */ + + register char *nf = &number_fmt[1]; + int printed; + + switch (pad) + { + case pad_zero: + *nf++ = '0'; + case pad_space: + *nf++ = '0' + maxdigits; + case pad_none: + *nf++ = 'u'; + *nf = '\0'; + } + +#ifdef _LIBC + add (maxdigits, printed = sprintf (p, number_fmt, number_value)); +#else + add (sprintf (p, number_fmt, number_value); + printed = strlen (p)); +#endif + + break; + } + case 'H': - fmt(2, (p, "%02d", tp->tm_hour)); - break; + DO_NUMBER (2, tp->tm_hour); case 'I': - fmt(2, (p, "%02d", hour12)); - break; + DO_NUMBER (2, hour12); case 'k': /* GNU extension. */ - fmt(2, (p, "%2d", tp->tm_hour)); - break; + DO_NUMBER_NOPAD (2, tp->tm_hour); case 'l': /* GNU extension. */ - fmt(2, (p, "%2d", hour12)); - break; + DO_NUMBER_NOPAD (2, hour12); case 'j': - fmt(3, (p, "%03d", 1 + tp->tm_yday)); - break; + DO_NUMBER (3, 1 + tp->tm_yday); case 'M': - fmt(2, (p, "%02d", tp->tm_min)); - break; + DO_NUMBER (2, tp->tm_min); case 'm': - fmt(2, (p, "%02d", tp->tm_mon + 1)); - break; + DO_NUMBER (2, tp->tm_mon + 1); case 'n': /* GNU extension. */ add (1, *p = '\n'); @@ -324,8 +376,7 @@ strftime (s, maxsize, format, tp) goto subformat; case 'S': - fmt(2, (p, "%02d", tp->tm_sec)); - break; + DO_NUMBER (2, tp->tm_sec); case 'X': #ifdef _NL_CURRENT @@ -342,24 +393,19 @@ strftime (s, maxsize, format, tp) break; case 'U': - fmt(2, (p, "%02u", y_week0)); - break; + DO_NUMBER (2, y_week0); case 'W': - fmt(2, (p, "%02u", y_week1)); - break; + DO_NUMBER (2, y_week1); case 'w': - fmt(2, (p, "%02d", tp->tm_wday)); - break; + DO_NUMBER (2, tp->tm_wday); case 'Y': - fmt(4, (p, "%04d", 1900 + tp->tm_year)); - break; + DO_NUMBER (4, 1900 + tp->tm_year); case 'y': - fmt(2, (p, "%02d", tp->tm_year % 100)); - break; + DO_NUMBER (2, tp->tm_year % 100); case 'Z': cpy(zonelen, zone);