DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T g

⟦4b44d5882⟧ TextFile

    Length: 2210 (0x8a2)
    Types: TextFile
    Names: »gtime.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/psap/gtime.c« 

TextFile

/* gtime.c - inverse gmtime */

#ifndef	lint
static char *rcsid = "$Header: /f/osi/psap/RCS/gtime.c,v 6.0 89/03/18 23:38:20 mrose Rel $";
#endif

/* 
 * $Header: /f/osi/psap/RCS/gtime.c,v 6.0 89/03/18 23:38:20 mrose Rel $
 *
 *
 * $Log:	gtime.c,v $
 * Revision 6.0  89/03/18  23:38:20  mrose
 * Release 5.0
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


/* LINTLIBRARY */

#include <stdio.h>
#include "psap.h"
#ifdef	OSX
#include <sys/time.h>
#endif
#ifdef	notdef
#include <sys/timeb.h>
#endif

/* \f

   DATA */

/* gtime(): the inverse of localtime().
	This routine was supplied by Mike Accetta at CMU many years ago.
 */

int	dmsize[] = {
    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};

#define	dysize(y)	\
	(((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366)))

#define	YEAR(y)		((y) >= 100 ? (y) : (y) + 1900)

/* \f

 */

long	gtime (tm)
register struct tm *tm;
{
    register int    i,
                    sec,
                    mins,
                    hour,
                    mday,
                    mon,
                    year;
    register long   result;
#ifdef	notdef
    long    local;
    struct timeb    tb;
#endif

    if ((sec = tm -> tm_sec) < 0 || sec > 59
	    || (mins = tm -> tm_min) < 0 || mins > 59
	    || (hour = tm -> tm_hour) < 0 || hour > 24
	    || (mday = tm -> tm_mday) < 1 || mday > 31
	    || (mon = tm -> tm_mon + 1) < 1 || mon > 12)
	return ((long) NOTOK);
    if (hour == 24) {
	hour = 0;
	mday++;
    }
    year = YEAR (tm -> tm_year);

    result = 0L;
    for (i = 1970; i < year; i++)
	result += dysize (i);
    if (dysize (year) == 366 && mon >= 3)
	result++;
    while (--mon)
	result += dmsize[mon - 1];
    result += mday - 1;
    result = 24 * result + hour;
    result = 60 * result + mins;
    result = 60 * result + sec;

#ifdef	notdef
    (void) ftime (&tb);
    result += 60 * tb.timezone;
    local = result;
    if ((tm = localtime (&local)) && tm -> tm_isdst)
	result -= 60 * 60;
#endif

    return result;
}