1: #include "parms.h"
   2: #include "structs.h"
   3: 
   4: #ifdef  RCSIDENT
   5: static char rcsid[] = "$Header: datein.c,v 1.7.0.1 85/07/31 14:12:38 notes Rel $";
   6: #endif	RCSIDENT
   7: 
   8: /*
   9:  *	getdate - parses the date handed as a string. Format is assumed
  10:  *	to be that of CTIME(III).
  11:  *		Ray Essick		Feb 1982
  12:  *
  13:  *	Augmented to understand about lots of different formats -
  14:  *	and make use of the getdate(III) routine to parse an
  15:  *	almost arbitrary date.
  16:  *
  17:  *	If the routine is unable to parse a time, the current time
  18:  *	is returned.  If the parsed time is in the future, the
  19:  *	current time is returned.
  20:  *
  21:  *	Returns:		0	succesfully parsed past date
  22:  *				-1	unsucessful parse
  23:  *					returned current time
  24:  *				-2	unsuccessful parse
  25:  *					returned a future time
  26:  *
  27:  */
  28: 
  29: extern char *mnames[];
  30: 
  31: parsetime (line, date)
  32: char   *line;
  33: struct when_f  *date;
  34: {
  35:     char    month[100];
  36:     char    weekday[100];               /* day of week */
  37:     char    zonename[100];              /* time zone */
  38:     int     day,
  39:             hour,
  40:             min,
  41:             sec,
  42:             year;
  43:     int     count;
  44:     long    timenow;                    /* current time */
  45:     long    xtime;                  /* parsed time */
  46:     struct when_f   now;                /* in structure */
  47: 
  48: 
  49:     gettime (date);                 /* load current */
  50:     gettime (&now);                 /* load current */
  51:     time (&timenow);                    /* seconds GMT */
  52: 
  53: #ifdef  notdef
  54:     /*
  55:      * apparently there are other formats close enough to ctime
  56:      * to fool the sscanf() call into thinking it has succeeded
  57:      * when in fact it hasn't.  So we just fall directly
  58:      * into the getdate() call.
  59:      */
  60: 
  61:     /*
  62:      *	First, let's see if the string is CTIME(III) format.
  63:      */
  64:     if (sscanf (line, "%s %s %hd %hd:%hd:%hd %hd", weekday, month,
  65:         &day, &hour, &min, &sec, &year) == 7)
  66:     {                           /* yay! */
  67: 
  68:     for (count = 12; count > 0; count--)
  69:         if (strcmp (mnames[count], month) == 0)
  70:         break;
  71:     date -> w_month = count;            /* place what we got */
  72:     date -> w_day = day;
  73:     date -> w_hours = hour;
  74:     date -> w_mins = min;
  75:     date -> w_year = year;
  76:     date -> w_gmttime = 0;
  77:     /*
  78: 	 *	We should check that it isn't in the future here
  79: 	 */
  80:     return 0;
  81:     }
  82: 
  83: #endif
  84: 
  85:     /*
  86:      *	Ok, now it's time to call in the big artillery -- GETDATE
  87:      */
  88: 
  89:     xtime = getdate (line, (struct timeb *) NULL);  /* parse */
  90:     if (xtime < 0)                  /* success? */
  91:     return (-1);                    /* failure */
  92:     maketime (date, (long) xtime);          /* encode */
  93:     if (xtime > timenow)                /* future shock */
  94:     return (-2);
  95:     return (0);
  96: 
  97: }

Defined functions

Defined variables

rcsid defined in line 5; never used
Last modified: 1985-10-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 812
Valid CSS Valid XHTML 1.0 Strict