Subject: v08i081: Phase of the moon, date routines Newsgroups: mod.sources Approved: mirror!rs Submitted by: Jef Poskanzer Mod.sources: Volume 8, Issue 81 Archive-name: phoon #! /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 deltime.c deltime.man dtime.c dtimep.lex lexedit.sed # lexstring.c libtws.man parsetime.c phoon.c phoon.man tws.h # This archive created by # Jef Poskanzer (Paratheo-Anametamystikhood Of Eris Esoteric, Ada Lovelace Cabal) export PATH; PATH=/bin:$PATH echo shar: extracting "'README'" '(2571 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else sed 's/^X//' << \SHAR_EOF > 'README' XSecond distribution of phoon, deltime, and libtws - 24feb87. X X XThis package contains two programs and a library: X X phoon - program to display the PHase of the mOON. Unlike other X such programs, which just tell you how long since first quarter X or something like that, phoon *shows* you the phase with a little X picture. I've put an example at the end of this file. I first X wrote this program in Pascal / TOPS-20 at CMU in 1979; I translated X it to Ratfor / Software Tools in 1981; and now it's in C / Unix*. X X deltime - program to subtract date/times. Tells you the difference X between two date/times, or between now and a specified date/time. X I once used this to help a friend quit smoking - every time she X logged in, the computer told her how many days since her last X cigarette. I also use it in my .login, to tell me how old I am. X X libtws - date/time library. Unlike the standard Unix* X date/time routines, libtws lets you parse a date/time string X into internal form. Most of this library came from version X 6.5 of the MH message handling system, courtesy of Marshall Rose. X I extended it somewhat and added the manual entry. X X XFiles in this distribution: X X README this X Makefile guess X deltime.c source for time subtraction tool X deltime.man manual for time subtraction tool X dtime.c source for most of the time routines X dtimep.lex source for time-parsing routine X lexedit.sed script to modify output of lex X lexstring.c front end for time-parsing routine X libtws.man manual for time library X parsetime.c source for test program X phoon.c source for phase of moon program X phoon.man manual for phase of moon program X tws.h include file for time library X X XUnpack the files, edit Makefile and change the options to suit, Xmake, and enjoy! I've tested this stuff under 4.2 BSD, 4.3 BSD, Xand System V rel 2. Nevertheless, I'm sure bugs remain. Feedback Xis welcome - send bug reports, enhancements, checks, money orders, Xetc. to the addresses below. X X X Jef Poskanzer, UniSoft Systems, Berkeley X unisoft!jef@ucbvax.Berkeley.Edu X ...ucbvax!unisoft!jef X (415)644-1230 X X X* Unix is a virus from outer space. X X X .-- X .-- X .-' X .-'@ X /@@@ X ./ X /@@ o X /@@@@ X |@@@@@ X /@@@@@ Last Quarter + X | @@@@ 4 1:36:10 X |@ @@@ New Moon - X | 3 7:34:53 X \ . @ X | X \ @ X \ o X `\ X \ X `-. X `-. X `-- X `-- SHAR_EOF if test 2571 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 2571 characters)' fi fi # end of overwriting check echo shar: extracting "'Makefile'" '(2137 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' X# Makefile for phoon, deltime, parsetime, and libtws (stolen from mh). X X X# Valid options: X# BSD42 Set this if your system is BSD 4.2 or later. X# SYS5 Set this if your system is System V. X# EUROPE Makes nn/nn/nn mean dd/mm/yy instead of mm/dd/yy. X# ATZ This has something to do with alpha-numeric time zones. X# DSTXXX This has something to do with daylight savings time. X# HUJI I don't X# INETONLY know what X# LEXDEBUG the rest of these X# ONECASE do. XOPTIONS = -DBSD42 -DATZ -DDSTXXX -DONECASE X X XCC = cc XCFLAGS = -O $(OPTIONS) XLDFLAGS = -ns X X.SUFFIXES: .man .cat X.man.cat: X nroff -h -man $< > $@ X X Xall: phoon phoon.cat deltime deltime.cat libtws.cat X X Xphoon: phoon.o libtws.a X $(CC) $(LDFLAGS) -o phoon phoon.o -lm libtws.a X Xphoon.o: phoon.c tws.h X X Xdeltime: deltime.o libtws.a X $(CC) $(LDFLAGS) -o deltime deltime.o libtws.a X Xdeltime.o: deltime.c tws.h X X Xparsetime: parsetime.o libtws.a X $(CC) $(LDFLAGS) -o parsetime parsetime.o libtws.a X Xparsetime.o: parsetime.c tws.h X X Xlibtws.a: dtime.o dtimep.o lexstring.o X ar r libtws.a dtime.o dtimep.o lexstring.o X# The following amusing bullshit makes sure that ranlib X# gets executed if it is present, no matter which shell X# make uses. If there's a better way to do this, someone X# please tell me! X -if test -r /usr/bin/ranlib ; then ranlib libtws.a ; fi X -if ( -r /usr/bin/ranlib ) ranlib libtws.a X X Xdtime.o: dtime.c tws.h X X Xdtimep.o: dtimep.c tws.h X Xdtimep.c: dtimep.lex X lex -nt dtimep.lex | sed -f lexedit.sed > dtimep.c X X Xlexstring.o: lexstring.c X $(CC) $(CFLAGS) -c lexstring.c X X Xclean: X -rm -f dtimep.c *.o libtws.a phoon deltime parsetime *.cat phoon.shar* core X Xphoon.shar: phoon.shar1 phoon.shar2 X Xphoon.shar1: README Makefile deltime.c deltime.man dtime.c dtimep.lex X shar -v -c -p X README Makefile deltime.c deltime.man dtime.c dtimep.lex > phoon.shar1 X Xphoon.shar2: lexedit.sed lexstring.c libtws.man parsetime.c phoon.c phoon.man tws.h X shar -v -c -p X lexedit.sed lexstring.c libtws.man parsetime.c phoon.c phoon.man tws.h > phoon.shar2 SHAR_EOF if test 2137 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 2137 characters)' fi fi # end of overwriting check echo shar: extracting "'deltime.c'" '(2156 characters)' if test -f 'deltime.c' then echo shar: will not over-write existing file "'deltime.c'" else sed 's/^X//' << \SHAR_EOF > 'deltime.c' X/* deltime.c - subtract date/times X Xver date who remarks X--- ------- --- ------------------------------------------------------------- X01B 15nov86 JP Modified to use twsubtract(). X01A 08nov86 JP Written. X XCopyright (C) 1986 by Jef Poskanzer. Permission to use, copy, Xmodify, and distribute this software and its documentation for any Xpurpose and without fee is hereby granted, provided that this copyright Xnotice appear in all copies and in all supporting documentation. No Xrepresentation is made about the suitability of this software for any Xpurpose. It is provided "as is" without express or implied warranty. X X*/ X Xstatic char copyright[] = "\nCopyright (C) 1986 by Jef Poskanzer.\n"; X X X#include "tws.h" X#include X X#define SECSPERMINUTE 60 X#define SECSPERHOUR (60 * SECSPERMINUTE) X#define SECSPERDAY (24 * SECSPERHOUR) X Xmain( argc, argv ) Xint argc; Xchar *argv[]; X { X struct tws tws1, tws2, *twp; X long delta, days, hours, minutes, secs; X char *illdt = "illegal date/time: %s\n"; X X if ( argc == 2 ) X { X twp = dparsetime( argv[1] ); X if ( twp == NULL || twp -> tw_flags & TW_JUNK ) X { X fprintf( stderr, illdt, argv[1] ); X exit( 1 ); X } X twscopy( &tws1, twp ); X twscopy( &tws2, dtwstime( ) ); X } X else if ( argc == 3 ) X { X twp = dparsetime( argv[1] ); X if ( twp == NULL || twp -> tw_flags & TW_JUNK ) X { X fprintf( stderr, illdt, argv[1] ); X exit( 1 ); X } X twscopy( &tws1, twp ); X twp = dparsetime( argv[2] ); X if ( twp == NULL || twp -> tw_flags & TW_JUNK ) X { X fprintf( stderr, illdt, argv[2] ); X exit( 1 ); X } X twscopy( &tws2, twp ); X } X else X { X fprintf( stderr, "usage: %s