#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # README # Makefile # date_calc.c # This archive created: Mon May 14 22:26:17 2001 # By: Daniel E. Singer (des@cs.duke.edu) # Duke University CS Dept. export PATH; PATH=/bin:$PATH echo shar: extracting "'README'" '(3897 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else sed 's/^ X//' << \SHAR_EOF > 'README' X Xdate_calc: calculate date1 from date0 + number of days X (ie, given a date and an offset in days, compute the second date) Xdays_calc: calculate number of days from date0 to date1 X (ie, compute the number of days between two dates) X XThis should be installed with links for both of these names. X XThis has been tested and used most recently with SunOS 4.1.3 and Solaris 2.5. X XFiles included with this distribution: X X.. README - this file X.. Makefile - the compile makefile X.. date_calc.c - the source X X=============================================================================== X% date_calc -h X Xdate_calc: reports the date of a given number of days from today or from a Xspecified date. X XUsage: date_calc [-ht] [-f fmt] [-s m d y] [+|-]num_days X Options: X -f 'fmt' - use 'fmt' as the output format, where X 'fmt' is a string of characters in which X "%n" is replaced by number of days, X "%y" is replaced by starting year, X "%m" is replaced by starting month, X "%d" is replaced by starting day, X "%Y" is replaced by ending year, X "%M" is replaced by ending month, X "%D" is replaced by ending day, X and "%N" is replaced by newline; X -h - help, print this message and exit. X -s m d y - use as the starting date (month, day, year), X the default is the current date; X -t - print only the number; X Arguments: X num_days - a number of days, with optional sign. X Where the year is specified: X if (year >= 0 and year <= 49, 2000 is added; X if (year >= 50 and year <= 99, 1900 is added. X Examples: X % date_calc 500 X 07/04/1998 and 500 days arrives at 11/16/1999. X % date_calc -s 7 4 50 -f "You will be %n days old on %M/%D/%Y.%N" 20000 X You will be 20000 days old on 4/6/2005. X XSee also: days_calc X=============================================================================== X% days_calc -h X Xdays_calc: reports the number of days between two dates, starting from today Xor a specified date. X XUsage: days_calc [-ht] [-f fmt] [-s m d y] m d y X days_calc [-ht] [-f fmt] -s m d y X Options: X -f 'fmt' - use 'fmt' as the output format, where X 'fmt' is a string of characters in which X "%n" is replaced by number of days, X "%y" is replaced by starting year, X "%m" is replaced by starting month, X "%d" is replaced by starting day, X "%Y" is replaced by ending year, X "%M" is replaced by ending month, X "%D" is replaced by ending day, X and "%N" is replaced by newline; X -h - help, print this message and exit. X -s m d y - use as the starting date (month, day, year), X the default is the current date; X -t - print only the number; X Arguments: X m d y - the ending date (month, day, year); if -s is, X given, this will default to the current date; X ( 1 <= m <= 12, 1 <= d <= (days in month), y >= 0). X Where the year is specified: X if (year >= 0 and year <= 49, 2000 is added; X if (year >= 50 and year <= 99, 1900 is added. X Examples: X % days_calc 1 1 2000 X From 07/04/1998 to 01/01/2000 is 546 days. X % days_calc -s 7 4 50 -f "You are %n days old.%N" X You are 17532 days old. X XSee also: date_calc X=============================================================================== X X-Daniel E. Singer, des@cs.duke.edu, 7/98 SHAR_EOF if test 3897 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 3897 characters)' fi fi # end of overwriting check echo shar: extracting "'Makefile'" '(786 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^ X//' << \SHAR_EOF > 'Makefile' X## X## Makefile for 'date_calc' X## D.Singer, 9/91 X## X## NOTE: This code is tested on SunOS 4.1.3 and SunOS 5.x X## X XPROG = date_calc XHDRS = XSRCS = ${PROG}.c XOBJS = ${PROG}.o X#LIBS = -lc XFILES = Makefile ${HDRS} ${SRCS} X#DEST = /us1/des/bin XDEST = /usr/local/bin X#CFLAGS = -g X XSHARE_FILE_NAME = ${PROG}.share XSHARE_FILE_NAME_ZIPPED = ${SHARE_FILE_NAME}.gz XSHARE_FILES = README Makefile ${PROG}.c X X${PROG} : ${OBJS} X cc -o ${PROG} ${OBJS} ${LIBS} X X${OBJS} : ${HDRS} X Xinstall : X /usr/bin/cp ${PROG} ${DEST} X Xclean : X rm -f ${PROG} ${OBJS} a.out core X Xshare: ${SHARE_FILE_NAME_ZIPPED} X X${SHARE_FILE_NAME_ZIPPED}: ${SHARE_FILES} X /usr/bin/rm -f ${SHARE_FILE_NAME} ${SHARE_FILE_NAME_ZIPPED} X /usr/local/bin/shar -a ${SHARE_FILES} > ${SHARE_FILE_NAME} X /usr/local/bin/gzip ${SHARE_FILE_NAME} SHAR_EOF if test 786 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 786 characters)' fi fi # end of overwriting check echo shar: extracting "'date_calc.c'" '(18961 characters)' if test -f 'date_calc.c' then echo shar: will not over-write existing file "'date_calc.c'" else sed 's/^ X//' << \SHAR_EOF > 'date_calc.c' X/* X * @(#) /u/des/src/date_calc/date_calc.c 1.6 01/05/14 22:26:01 X * X * date_calc: calculate date1 from date0 + number of days X * days_calc: calculate number of days from date0 to date1 X * (should install with links for both of these names) X * X * Copyright (c) 1989-2001 by Daniel E. Singer. All rights reserved. X * Permission is granted to reproduce and distribute this program X * with the following conditions: X * 1) This copyright notice and the author identification below X * must be left intact in the program and in any copies. X * 2) Any modifications to the program must be clearly identified X * in the source file. X * X * written by Daniel E. Singer X * June 1989 X * X * Note: Modified 10/91 for 4.3BSD (original was on PRIMOS) X * X * Note: until 7/98, this was called "days_old", and was tailored X * to calculate number of days from a past date to today. X * X * Usage: X * date_calc [options] [+|-]num_days X * days_calc [options] m d y X * days_calc [options] -s m d y X * X * Options: X * -h : Help -- print help message and exit X * -f format : Format -- output format string X * -s m d y : Start -- use as the starting date X * -t : Terse -- just print the number X */ X X#include X#include X#include X X X/* X * names (links) for this program X */ X#define DATE_CALC_NAME "date_calc" X#define DAYS_CALC_NAME "days_calc" X X#define LeapYear(yy) ((yy)%4==0 && ((yy)%100!=0 || (yy)%400==0)) X#define DaysPerYear(yy) (365 + LeapYear((yy))) X#define DaysPerMonth(yy,mm) ( (mm)==2 ? 28 + LeapYear((yy)) \ X : 30 + ((mm)+((mm)>=8))%2 ) X#define CheckDate(yy,mm,dd) ( (yy)>=0 && (mm)>=1 && (mm)<=12 && \ X (dd)>=1 && (dd)<=DaysPerMonth((yy),(mm)) ) X X#define DAYS_MODE 1 /* program called for days calc */ X#define DATE_MODE 2 /* program called for date calc */ X X#define OPT_CHAR '-' /* option indicator */ X#define PATH_SEP '/' /* pathname component separater */ X#define FMT_CHAR '%' /* format indicator */ X#define DAYS_CHAR 'n' /* day format */ X#define NL_CHAR 'N' /* newline format */ X#define YEAR0_CHAR 'y' /* year0 format */ X#define MONTH0_CHAR 'm' /* month0 format */ X#define DAY0_CHAR 'd' /* day0 format */ X#define YEAR1_CHAR 'Y' /* year1 format */ X#define MONTH1_CHAR 'M' /* month1 format */ X#define DAY1_CHAR 'D' /* day1 format */ X#define BELL_CHAR '\007' /* terminal bell */ X#define SPACES " \t" /* space chars in environment variable */ X X /* errors */ X#define E_NONE 0 /* no error */ X#define E_ARGS 1 /* arg syntax */ X#define E_UNKNOWN 2 /* unknown arg */ X#define E_RANGE 3 /* arg out of range */ X#define E_ENVIRON 4 /* environ var bad format */ X Xstatic char X id[] = "by Daniel E. Singer, des@cs.duke.edu"; Xchar X *progname, /* name of this program */ X *fmt_str = (char*)0; /* the output format string */ Xint X year0, month0, day0, /* starting date */ X year1, month1, day1, /* ending date */ X terse = 0, /* terse options given */ X start_date = 0, /* start_date option given */ X format = 0, /* format options given */ X help = 0, /* help options given */ X mode = 0, /* which program invocation */ X num_days = 0; /* command line num-days argument X * or calculated num-days */ X Xchar X *file_name(), X *skip_space(), X *find_space(), X *getenv(), X *malloc(); Xint X is_integer(), X get_cnum(), X parse_date_str(), X adjust_year(), X get_environment(), X strcmp(); Xtime_t X time(); Xvoid X do_args(), X do_format(), X get_todays_date(), X calc_date(); X X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X progname = file_name(argv[0]); X --argc; ++argv; X X if (strcmp(progname,DAYS_CALC_NAME) == 0) X mode = DAYS_MODE; X else if (strcmp(progname,DATE_CALC_NAME) == 0) X mode = DATE_MODE; X else { X fprintf(stderr,"%s%c: who am I?\n",progname,BELL_CHAR); X pr_usage(); X exit(1); X } X X /* check for options, and get date args */ X do_args(&argc,&argv); X X if (mode == DAYS_MODE) { X num_days = date_diff(year0,month0,day0,year1,month1,day1); X X if (terse) X fprintf(stdout,"%d",num_days); X else if (format) X do_format(stdout,fmt_str,num_days,year0,month0,day0,year1,month1,day1); X else { X char *tstr = num_days == 1 || num_days == -1 ? "" : "s"; X X fprintf(stdout,"From %02d/%02d/%04d to %02d/%02d/%04d is %d day%s.\n", X month0,day0,year0,month1,day1,year1, X num_days,tstr); X } X } X else { X calc_date(year0,month0,day0,num_days,&year1,&month1,&day1); X X if (terse) X fprintf(stdout,"%02d %02d %04d\n",month1,day1,year1); X else if (format) X do_format(stdout,fmt_str,num_days,year0,month0,day0,year1,month1,day1); X else { X char *tstr = num_days == 1 || num_days == -1 ? "" : "s"; X X fprintf(stdout,"%02d/%02d/%04d and %d day%s arrives at %02d/%02d/%04d.\n", X month0,day0,year0, X num_days,tstr, X month1,day1,year1); X } X } X X exit(0); X} X Xvoid Xdo_args(ac,av) Xregister int *ac; Xregister char *(*av[]); X{ X register char *argp; X register int error = E_NONE; X char *evar; X int year, X month, X day; X X /* check for options */ X for ( ; *ac > 0 && (**av)[0] == OPT_CHAR; --*ac, ++*av) { X argp = &((**av)[0]); X X if (mode == DATE_MODE) X /* check for a negative num-days argument */ X if (*(argp+1) >= '0' && *(argp+1) <= '9') X break; X X /* just "-" by itself is an error */ X if (*(argp+1) == '\0') { X error = E_ARGS; X break; X } X X /* undocumented feature: "--" means stop processing opts */ X if (strcmp(argp,"--") == 0) { X --*ac, ++*av; X break; X } X X while (*++argp != '\0') { X switch (*argp) { X /* help option */ X case 'h': X help = 1; X break; X /* terse option */ X case 't': X terse = 1; X continue; X /* format option */ X case 'f': X --*ac, ++*av; X if (*ac < 1) { X error = E_ARGS; X break; X } X fmt_str = (*av)[0]; X format = 1; X continue; X /* start_date (or, date math) option */ X case 's': X --*ac, ++*av; X if (*ac < 1) { X error = E_ARGS; X break; X } X else if (parse_date_str((*av)[0],&month,&day,&year) == 1) { X start_date = 1; X continue; X } X else if (*ac >= 3 && is_integer((*av)[0]) && X is_integer((*av)[1]) && X is_integer((*av)[2])) { X month = atoi((*av)[0]); X day = atoi((*av)[1]); X year = atoi((*av)[2]); X year = adjust_year(year); X *ac -= 2, *av +=2; X start_date = 1; X continue; X } X error = E_ARGS; X break; X default: X error = E_UNKNOWN; X break; X } X break; X } X if (error != E_NONE) X break; X } X X if (help) { X pr_help(); X exit(0); X } X X /* check for remaining DOB or NUM-DAYS arguments */ X if (error == E_NONE) { X if (mode == DAYS_MODE) { X if (start_date) { X year0 = year; X month0 = month; X day0 = day; X } X else X get_todays_date(&year0,&month0,&day0); X switch (*ac) { X case 0: X if (!start_date) { X error = E_ARGS; X break; X } X get_todays_date(&year1,&month1,&day1); X break; X case 1: X /* get the month day year args from single arg */ X if (parse_date_str((*av)[0],&month0,&day0,&year0) == 0) X error = E_ARGS; X break; X case 3: X /* get the month day year args */ X if ( !is_integer((*av)[0]) X || !is_integer((*av)[1]) X || !is_integer((*av)[2]) ) X error = E_ARGS; X else { X /* get date args */ X month1 = atoi((*av)[0]); X day1 = atoi((*av)[1]); X year1 = atoi((*av)[2]); X year1 = adjust_year(year1); X } X break; X default: X error = E_ARGS; X } X } X else { X if (start_date) { X year0 = year; X month0 = month; X day0 = day; X } X else X get_todays_date(&year0,&month0,&day0); X X switch (*ac) { X case 1: X /* get the number of days */ X if (!get_cnum((*av)[0],&num_days)) X error = E_ARGS; X break; X default: X error = E_ARGS; X break; X } X } X } X X if (error == E_NONE) { X /* check date ranges */ X if (mode == DAYS_MODE) { X if ( (start_date && !CheckDate(year0,month0,day0)) || X !CheckDate(year1,month1,day1) ) X error = E_RANGE; X } X else { X if (start_date && !CheckDate(year0,month0,day0)) X error = E_RANGE; X } X } X X if (error != E_NONE) { X fprintf(stderr,"%s: ",progname); X switch (error) { X case E_ARGS: X fprintf(stderr,"syntax error.\n"); X break; X case E_UNKNOWN: X fprintf(stderr,"unknown option '%c'.\n",*argp); X break; X case E_RANGE: X fprintf(stderr,"an argument is out of range.\n"); X break; X case E_ENVIRON: X fprintf(stderr,"environment variable bad format.\n"); X break; X } X putc(BELL_CHAR,stderr); X pr_usage(); X exit(error); X } X} X Xpr_usage() X{ X if (mode == DAYS_MODE) { X fprintf(stderr,"\ XUsage: %s [-ht] [-f fmt] [-s m d y] m d y\n\ X %s [-ht] [-f fmt] -s m d y\n",progname,progname); X } X else { X fprintf(stderr,"\ XUsage: %s [-ht] [-f fmt] [-s m d y] [+|-]num_days\n",progname); X } X} X Xpr_help() X{ X if (mode == DAYS_MODE) { X fprintf(stdout,"\ X\n\ X%s: reports the number of days between two dates, starting from today\n\ Xor a specified date.\n\ X\n\ XUsage: %s [-ht] [-f fmt] [-s m d y] m d y\n\ X %s [-ht] [-f fmt] -s m d y\n\ X Options:\n\ X -f 'fmt' - use 'fmt' as the output format, where\n\ X 'fmt' is a string of characters in which\n\ X \"%%%c\" is replaced by number of days,\n\ X \"%%%c\" is replaced by starting year,\n\ X \"%%%c\" is replaced by starting month,\n\ X \"%%%c\" is replaced by starting day,\n\ X \"%%%c\" is replaced by ending year,\n\ X \"%%%c\" is replaced by ending month,\n\ X \"%%%c\" is replaced by ending day,\n\ X and \"%%%c\" is replaced by newline;\n\ X -h - help, print this message and exit.\n\ X -s m d y - use as the starting date (month, day, year),\n\ X the default is the current date;\n\ X -t - print only the number;\n\ X Arguments:\n\ X m d y - the ending date (month, day, year); if -s is,\n\ X given, this will default to the current date;\n\ X ( 1 <= m <= 12, 1 <= d <= (days in month), y >= 0).\n\ X Where the year is specified:\n\ X if (year >= 0 and year <= 49, 2000 is added;\n\ X if (year >= 50 and year <= 99, 1900 is added.\n\ X Examples:\n\ X %% %s 1 1 2000\n\ X From 07/04/1998 to 01/01/2000 is 546 days.\n\ X %% %s -s 7 4 50 -f \"You are %%n days old.%%N\"\n\ X You are 17532 days old.\n\ X\n\ XSee also: %s\n\ X", X progname,progname,progname,DAYS_CHAR, X YEAR0_CHAR,MONTH0_CHAR,DAY0_CHAR, X YEAR1_CHAR,MONTH1_CHAR,DAY1_CHAR, X NL_CHAR,progname,progname,DATE_CALC_NAME); X } X else { X fprintf(stdout,"\ X\n\ X%s: reports the date of a given number of days from today or from a\n\ Xspecified date.\n\ X\n\ XUsage: %s [-ht] [-f fmt] [-s m d y] [+|-]num_days\n\ X Options:\n\ X -f 'fmt' - use 'fmt' as the output format, where\n\ X 'fmt' is a string of characters in which\n\ X \"%%%c\" is replaced by number of days,\n\ X \"%%%c\" is replaced by starting year,\n\ X \"%%%c\" is replaced by starting month,\n\ X \"%%%c\" is replaced by starting day,\n\ X \"%%%c\" is replaced by ending year,\n\ X \"%%%c\" is replaced by ending month,\n\ X \"%%%c\" is replaced by ending day,\n\ X and \"%%%c\" is replaced by newline;\n\ X -h - help, print this message and exit.\n\ X -s m d y - use as the starting date (month, day, year),\n\ X the default is the current date;\n\ X -t - print only the number;\n\ X Arguments:\n\ X num_days - a number of days, with optional sign.\n\ X Where the year is specified:\n\ X if (year >= 0 and year <= 49, 2000 is added;\n\ X if (year >= 50 and year <= 99, 1900 is added.\n\ X Examples:\n\ X %% %s 500\n\ X 07/04/1998 and 500 days arrives at 11/16/1999.\n\ X %% %s -s 7 4 50 -f \"You will be %%n days old on %%M/%%D/%%Y.%%N\" 20000\n\ X You will be 20000 days old on 4/6/2005.\n\ X\n\ XSee also: %s\n\ X", X progname,progname,DAYS_CHAR, X YEAR0_CHAR,MONTH0_CHAR,DAY0_CHAR, X YEAR1_CHAR,MONTH1_CHAR,DAY1_CHAR, X NL_CHAR,progname,progname,DAYS_CALC_NAME); X } X} X Xparse_date_str(date_str,month,day,year) X/* X * parse a numeric date string into month, day, year X */ Xchar X *date_str; /* format: "mm dd yy" */ Xint X *month, X *day, X *year; X{ X char *m, X *d, X *y, X *junk, X *tstr; X X if ((tstr = malloc(strlen(date_str)+1)) == (char*)0) { X putc(BELL_CHAR,stderr); X fprintf(stderr,"%s: problem with malloc().\n",progname); X exit(1); X } X strcpy(tstr,date_str); X m = skip_space(tstr); X d = skip_space(find_space(m)); X y = skip_space(find_space(d)); X junk = skip_space(find_space(y)); X X *find_space(m) = '\0'; X *find_space(d) = '\0'; X *find_space(y) = '\0'; X X if ( *junk != '\0' X || !is_integer(m) X || !is_integer(d) X || !is_integer(y) ) { X return(0); X } X X *month = atoi(m); X *day = atoi(d); X *year = atoi(y); X *year = adjust_year(*year); X free(tstr); X return(1); X} X Xint Xadjust_year(year) X/* X * do the Y2K thang X */ Xregister int X year; X{ X if (year >= 0 && year <= 49) X return(year + 2000); X if (year >= 50 && year <= 99) X return(year + 1900); X return(year); X} X Xvoid Xget_todays_date(year,month,day) X/* X * get the current date X */ Xregister int X *year, X *month, X *day; X{ X register struct tm X *tmp; X int X the_time; X X the_time = time((int*)0); X tmp = localtime(&the_time); X X *year = tmp->tm_year; /* 0-???: years since 1900 */ X *month = tmp->tm_mon; /* 0-11 */ X *day = tmp->tm_mday; /* 1-31 */ X X *year += 1900; X *month += 1; X} X Xint Xdate_diff(year0,month0,day0,year1,month1,day1) X/* X * compute the difference in days between two dates; X * y1, etc, are the later date (otherwise, return negative); X * dates are assumed to already be checked for valid range; X */ Xint year0, month0, day0, /* earlier date */ X year1, month1, day1; /* later date */ X{ X register int X yy, X mm, X num_days = 0, X reverse, X t; X X if (reverse = year0 > year1 X || (year0 == year1 X && (month0 > month1 X || (month0 == month1 X && day0 > day1)))) { X t = year0; year0 = year1; year1 = t; X t = month0; month0 = month1; month1 = t; X t = day0; day0 = day1; day1 = t; X } X X /* do a gross total of the span of years, then adjust */ X for (yy=year0; yy <= year1; ++yy) X num_days += DaysPerYear(yy); X X /* adjust first year */ X for (mm=1; mm < month0; ++mm) X num_days -= DaysPerMonth(year0,mm); X X /* adjust last year */ X for (mm=month1; mm <= 12; ++mm) X num_days -= DaysPerMonth(year1,mm); X X num_days += day1 - day0; X X return( reverse ? -num_days : num_days ); X} X Xvoid Xcalc_date(year0,month0,day0,num_days,year1,month1,day1) X/* X * compute a new date, based on a starting date and an offset in days; X * y0, etc, are the base date; y1, etc, are the calculated date; X * num_days is the offset X */ Xint year0, month0, day0, /* base date */ X num_days, /* date offset */ X *year1, *month1, *day1; /* calculated date */ X{ X register int X nd = num_days, X yy, X mm, X neg = 0, X t; X X if (nd == 0) { X *year1 = year0; X *month1 = month0; X *day1 = day0; X return; X } X if (nd < 0) { X nd = -nd; X X /* go to the end of the year, and work backward */ X nd += DaysPerMonth(year0,month0) - day0; X while (month0 < 12) { X ++month0; X nd += DaysPerMonth(year0,month0); X } X X for ( ; ; --year0) { X yy = DaysPerYear(year0); X if (yy > nd) X break; X nd -= yy; X } X X for ( ; ; --month0) { X mm = DaysPerMonth(year0,month0); X if (mm > nd) X break; X nd -= mm; X } X X day0 = mm - nd; X } X else { X /* go to the beginning of the year, and work forward */ X nd += day0 - 1; X while (month0 > 1) { X --month0; X nd += DaysPerMonth(year0,month0); X } X X for ( ; ; ++year0) { X yy = DaysPerYear(year0); X if (yy > nd) X break; X nd -= yy; X } X X for ( ; ; ++month0) { X mm = DaysPerMonth(year0,month0); X if (mm > nd) X break; X nd -= mm; X } X X day0 = nd + 1; X } X X *year1 = year0; X *month1 = month0; X *day1 = day0; X} X Xvoid Xdo_format(fp,fmt,num) X/* X * process command line format option, similar to printf(); X */ Xregister FILE X *fp; Xregister char X *fmt; Xint X num; X{ X register char X *p = fmt; X X for ( ; *p != '\0'; ++p) { X if (*p == FMT_CHAR) { X switch (*(p+1)) { X case FMT_CHAR: X putc(FMT_CHAR,fp); X ++p; X continue; X case DAYS_CHAR: X fprintf(fp,"%d",num); X ++p; X continue; X case NL_CHAR: X putc('\n',fp); X ++p; X continue; X case YEAR0_CHAR: X fprintf(fp,"%d",year0); X ++p; X continue; X case MONTH0_CHAR: X fprintf(fp,"%d",month0); X ++p; X continue; X case DAY0_CHAR: X fprintf(fp,"%d",day0); X ++p; X continue; X case YEAR1_CHAR: X fprintf(fp,"%d",year1); X ++p; X continue; X case MONTH1_CHAR: X fprintf(fp,"%d",month1); X ++p; X continue; X case DAY1_CHAR: X fprintf(fp,"%d",day1); X ++p; X continue; X } X } X putc(*p,fp); X } X} X X#if 0 Xvoid Xdo_cformat(fp,fmt,num,year0,month0,day0,year1,month1,day1); X/* X * process command line format option, similar to printf(); X */ Xregister FILE X *fp; Xregister char X *fmt; Xint X num, X year0, X month0, X day0, X year1, X month1, X day1; X{ X register char X *p = fmt; X X for ( ; *p != '\0'; ++p) { X if (*p == FMT_CHAR) { X switch (*(p+1)) { X case FMT_CHAR: X putc(FMT_CHAR,fp); X ++p; X continue; X case DAYS_CHAR: X fprintf(fp,"%d",num); X ++p; X continue; X case NL_CHAR: X putc('\n',fp); X ++p; X continue; X } X } X putc(*p,fp); X } X} X#endif X Xchar* Xfile_name(path) X/* X * return a ptr to the filename part of a pathname; X */ Xregister char X *path; X{ X register char X *p = path, X *hold = p; X X for ( ; *p != '\0'; ++p) X if (*p == PATH_SEP) X hold = p + 1; X X return(hold); X} X Xchar* Xskip_space(str) X/* X * return a ptr to the character after space; X */ Xregister char X *str; X{ X register char X *space = SPACES, X *p; X X for ( ; *str != '\0'; ++str) { X for (p=space; *p != '\0' && *p != *str; ++p) ; X if (*p == '\0') X break; X } X return(str); X} X Xchar* Xfind_space(str) X/* X * return a ptr to the first space character, or end of string; X */ Xregister char X *str; X{ X register char X *space = SPACES, X *p; X X for ( ; *str != '\0'; ++str) { X for (p=space; *p != '\0' && *p != *str; ++p) ; X if (*p != '\0') X break; X } X return(str); X} X Xint Xget_cnum(str,num) Xchar *str; Xint *num; X{ X register X char *p = str; X register X int sign = 1; X X if (*p == '+') X ++p; X else if (*p == '-') { X sign = -1; X ++p; X } X if (!is_integer(p)) X return(0); X X *num = sign * atoi(p); X return(1); X} X Xint Xis_integer(str) X/* X * see if this string is exactly an integer; X */ Xregister char *str; X{ X char int_buf[21]; X X int len = strlen(str); X X if (len > 20) X len = 20; X X sprintf(int_buf,"%0*d",len,atoi(str)); X /*printf("is_integer: %s -> %s\n", str, int_buf);*/ X X return( strcmp(int_buf,str) == 0 ); X} SHAR_EOF if test 18961 -ne "`wc -c < 'date_calc.c'`" then echo shar: error transmitting "'date_calc.c'" '(should have been 18961 characters)' fi fi # end of overwriting check # End of shell archive exit 0