From: jjj@mits.mdata.fi (Joni Jarvenkyla)
Newsgroups: sfnet.keskustelu.huumeet
Subject: Irti tupakasta, toimiva konsti SysV Unixille
Summary: Toimii mainiosti muissakin kunhan cut:in korvaa jollain.
Date: 11 Apr 92 15:36:28 GMT
Distribution: sfnet
Organization: Microdata Oy, Helsinki, Finland


K{{nn{ softa ja laita se ajettavaksi joka kerta kun loggaat sis{{n ja
loggaat ulos. N{et kuinka monta p{iv{{ olet ollut polttamatta, ja
seuraavan pikku scriptin avulla se laskee paljonko olet s{[st{nyt jos
olisit polttanut 1/2 askia p{iv{ss{. Muuta polttamasi keskim{{r{ kaamean
echo-lauseen lopussa olevan 9:n tilalle (tuo \| 1 \) \* 9), markkoina
siis.

Kaiken lis{ksi konsti toimii, nimim 13 p{iv{{ ja hyv{lt{ tuntuu.
Lis{avuksi suositellaan polkupy|r{ilyn aloittamista, eli fillarin ostoa
tai vanhan kaivamista kellarista yl|s ulos ja lenkille.

Viinanjuontikin voi muuttua yll{tt{v{n mukavaksi puuhaksi kun ei en{{
tupakka p{{se m{ls{st{m{{n mielt{. Ja itse asiassa el{minenkin maistuu
ihan eri lailla.

Iloista lopettamista kaikille. 

shellscrip "rooki":

#!/bin/sh

echo "Olet ollut polttamatta jo `deltime \"29/3/92 11:30\"` vrk h/min/s. S{{st|: "`expr \( "\`deltime \"29/3/92 11:30\" | cut -d\" \" -f1 -\`" \| 1 \) \* 9`" markkaa!"

itse ohjelma "deltime.c":

/* deltime.c - subtract date/times

ver  date   who remarks
--- ------- --- -------------------------------------------------------------
01B 15nov86 JP  Modified to use twsubtract().
01A 08nov86 JP  Written.

Copyright (C) 1986 by Jef Poskanzer.  Permission to use, copy,
modify, and distribute this software and its documentation for any
purpose and without fee is hereby granted, provided that this copyright
notice appear in all copies and in all supporting documentation.  No
representation is made about the suitability of this software for any
purpose.  It is provided "as is" without express or implied warranty.

*/

static char copyright[] = "\nCopyright (C) 1986 by Jef Poskanzer.\n";


#include "tws.h"
#include <stdio.h>

#define SECSPERMINUTE 60
#define SECSPERHOUR (60 * SECSPERMINUTE)
#define SECSPERDAY (24 * SECSPERHOUR)

main( argc, argv )
int argc;
char *argv[];
    {
    struct tws tws1, tws2, *twp;
    long delta, days, hours, minutes, secs;
    char *illdt = "illegal date/time: %s\n";

    if ( argc == 2 )
	{
	twp = dparsetime( argv[1] );
	if ( twp == NULL || twp -> tw_flags & TW_JUNK )
	    {
	    fprintf( stderr, illdt, argv[1] );
	    exit( 1 );
	    }
	twscopy( &tws1, twp );
	twscopy( &tws2, dtwstime( ) );
	}
    else if ( argc == 3 )
	{
	twp = dparsetime( argv[1] );
	if ( twp == NULL || twp -> tw_flags & TW_JUNK )
	    {
	    fprintf( stderr, illdt, argv[1] );
	    exit( 1 );
	    }
	twscopy( &tws1, twp );
	twp = dparsetime( argv[2] );
	if ( twp == NULL || twp -> tw_flags & TW_JUNK )
	    {
	    fprintf( stderr, illdt, argv[2] );
	    exit( 1 );
	    }
	twscopy( &tws2, twp );
	}
    else
	{
	fprintf( stderr, "usage:  %s  <time>  [ <time2> ]\n", argv[0] );
	exit( 1 );
	}
    
    delta = twsubtract( &tws2, &tws1 );
    if ( delta < 0 )
	{
	printf( "-" );
	delta = -delta;
	}

    days = delta / SECSPERDAY;
    delta = delta - days * SECSPERDAY;
    hours = delta / SECSPERHOUR;
    delta = delta - hours * SECSPERHOUR;
    minutes = delta / SECSPERMINUTE;
    delta = delta - minutes * SECSPERMINUTE;
    secs = delta;

    printf( "%ld %2ld:%02ld:%02ld\n", days, hours, minutes, secs );

    exit( 0 );
    }

manuaalisivu deltimelle "deltime.man":

.TH example 1 "08 November 1986"
.SH NAME
deltime \- compute a delta time
.SH SYNOPSIS
.in +.5i
.ti -.5i
deltime  <time>  \%[ <time2> ]
.in -.5i
.SH DESCRIPTION
.PP
.I Deltime
computes the elapsed time between now and a
specified date/time, or between two specified date/times.
The format for specifying date/times is pretty loose - basically
the same as the format for date/times in network mail.
Just be careful to put them in quotes if they contain spaces.
The output format is dddd hh:mm:ss.
.PP
Times earlier than 1970
.I can
be handled, because the internal Unix* time format is not used.
However, time spans greater than 66 years
.I cannot
be handled, because that's 2**31 seconds.
.SH "SEE\ ALSO"
.IR phoon(1),
.IR libtws(3)
.SH AUTHOR
Jef Poskanzer
.SH NOTE
* Unix is a virus from outer space.
-- 
jjj@mits.mdata.fi   Mind         Heart         No      Me
jjj@niksula.hut.fi  Difference   Destruction   Death   You