RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 17-Sep-2014 15:49:29 Branch: rpm-5_4 Handle: 2014091713492800 Added files: (Branch: rpm-5_4) rpm/tools date.c Modified files: (Branch: rpm-5_4) rpm/tools Makefile.am Log: - date: swipe a date(1) implementation from FreeBSD. Summary: Revision Changes Path 2.170.2.11 +5 -1 rpm/tools/Makefile.am 1.1.2.1 +195 -0 rpm/tools/date.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/tools/Makefile.am ============================================================================ $ cvs diff -u -r2.170.2.10 -r2.170.2.11 Makefile.am --- rpm/tools/Makefile.am 27 Aug 2014 20:56:23 -0000 2.170.2.10 +++ rpm/tools/Makefile.am 17 Sep 2014 13:49:28 -0000 2.170.2.11 @@ -29,7 +29,7 @@ xiu-instantiate xiu-store noinst_PROGRAMS = -EXTRA_PROGRAMS += augtool cudftool dbconvert debugedit \ +EXTRA_PROGRAMS += augtool cudftool date dbconvert debugedit \ nix-build nix-channel nix-collect-garbage \ nix-log2xml nix-prefetch-url nix-pull nix-push \ xiu-echo xiu-hash \ @@ -95,6 +95,10 @@ cudftool_LDFLAGS = @LDFLAGS_STATIC@ $(LDFLAGS) $(shell pkg-config --libs glib-2.0) cudftool_LDADD = $(RPMIO_LDADD_COMMON) +date_SOURCES = date.c +date_LDFLAGS = @LDFLAGS_STATIC@ $(LDFLAGS) +date_LDADD = $(RPM_LDADD_COMMON) + dbconvert_SOURCES = dbconvert.c dbconvert_LDFLAGS = @LDFLAGS_STATIC@ $(LDFLAGS) dbconvert_LDADD = $(RPM_LDADD_COMMON) @@ . patch -p0 <<'@@ .' Index: rpm/tools/date.c ============================================================================ $ cvs diff -u -r0 -r1.1.2.1 date.c --- /dev/null 2014-09-17 15:45:52.000000000 +0200 +++ date.c 2014-09-17 15:49:29.228968868 +0200 @@ -0,0 +1,195 @@ +/* date - print or set the system date and time + Copyright (C) 1989, 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +/* Options: + -d DATESTR Display the date DATESTR. + -s DATESTR Set the date to DATESTR. + -u Display or set the date in universal instead of local time. + +FORMAT Specify custom date output format, described below. + MMDDhhmm[[CC]YY][.ss] Set the date in the format described below. + + If one non-option argument is given, it is used as the date to which + to set the system clock, and must have the format: + MM month (01..12) + DD day in month (01..31) + hh hour (00..23) + mm minute (00..59) + CC first 2 digits of year (optional, defaults to current) (00..99) + YY last 2 digits of year (optional, defaults to current) (00..99) + ss second (00..61) + + If a non-option argument that starts with a `+' is specified, it + is used to control the format in which the date is printed; it + can contain any of the `%' substitutions allowed by the strftime + function. A newline is always added at the end of the output. + + David MacKenzie <d...@gnu.ai.mit.edu> */ + +#include <stdio.h> +#include <getopt.h> +#include <sys/types.h> +#include "system.h" + +/* This is portable and avoids bringing in all of the ctype stuff. */ +#undef isdigit +#define isdigit(c) ((c) >= '0' && (c) <= '9') + +#ifdef TM_IN_SYS_TIME +#include <sys/time.h> +#else +#include <time.h> +#endif + +#ifndef STDC_HEADERS +time_t mktime (); +size_t strftime (); +time_t time (); +#endif + +int putenv (); +int stime (); + +#ifdef DYING +char *xrealloc (); +void error (); +time_t posixtime (); +#endif +time_t get_date (); +void show_date (); +void usage (); + +/* putenv string to use Universal Coordinated Time. + POSIX.2 says it should be "TZ=UCT0" or "TZ=GMT0". */ +#ifndef TZ_UCT +#if defined(hpux) || defined(__hpux__) || defined(ultrix) || defined(__ultrix__) || defined(USG) +#define TZ_UCT "TZ=GMT0" +#else +#define TZ_UCT "TZ=" +#endif +#endif + +/* The name this program was run with, for error messages. */ +char *program_name; + +int +main (argc, argv) + int argc; + char **argv; +{ + int optc; + char *datestr = NULL; + time_t when; + int set_date = 0; + int universal_time = 0; + + program_name = argv[0]; + + while ((optc = getopt (argc, argv, "d:s:u")) != EOF) + switch (optc) + { + case 'd': + datestr = optarg; + break; + case 's': + datestr = optarg; + set_date = 1; + break; + case 'u': + universal_time = 1; + break; + default: + usage (); + } + + if (argc - optind > 1) + usage (); + + if (universal_time && putenv (TZ_UCT) != 0) + error (1, 0, "virtual memory exhausted"); + + time (&when); + + if (datestr) + when = get_date (datestr, NULL); + +#ifdef NOTYET + if (argc - optind == 1 && argv[optind][0] != '+') + { + when = posixtime (argv[optind]); + set_date = 1; + } +#endif + + if (when == -1) + error (1, 0, "invalid date"); + + if (set_date && stime (&when) == -1) + error (0, errno, "cannot set date"); + + if (argc - optind == 1 && argv[optind][0] == '+') + show_date (argv[optind] + 1, when); + else + show_date ((char *) NULL, when); + + exit (0); +} + +/* Display the date and/or time in WHEN according to the format specified + in FORMAT, followed by a newline. If FORMAT is NULL, use the + standard output format (ctime style but with a timezone inserted). */ + +void +show_date (format, when) + char *format; + time_t when; +{ + struct tm *tm; + char *out = NULL; + size_t out_length = 0; + + tm = localtime (&when); + + if (format == NULL) + /* Print the date in the default format. Vanilla ANSI C strftime + doesn't support %e, but POSIX requires it. If you don't use + a GNU strftime, make sure yours supports %e. */ + format = "%a %b %e %H:%M:%S %Z %Y"; + else if (*format == '\0') + { + printf ("\n"); + return; + } + + do + { + out_length += 200; + out = (char *) xrealloc (out, out_length); + } + while (strftime (out, out_length, format, tm) == 0); + + printf ("%s\n", out); + free (out); +} + +void +usage () +{ + fprintf (stderr, "\ +Usage: %s [-u] [-d datestr] [-s datestr] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]\n", + program_name); + exit (1); +} @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org