home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / SQDEV200.ZIP / SRC / DATE2BIN.C < prev    next >
C/C++ Source or Header  |  1994-05-23  |  4KB  |  113 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Squish Developers Kit Source, Version 2.00                             *
  4.  *  Copyright 1989-1994 by SCI Communications.  All rights reserved.       *
  5.  *                                                                         *
  6.  *  USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE       *
  7.  *  SQUISH DEVELOPERS KIT LICENSING AGREEMENT IN SQDEV.PRN.  IF YOU DO NOT *
  8.  *  FIND THE TEXT OF THIS AGREEMENT IN THE AFOREMENTIONED FILE, OR IF YOU  *
  9.  *  DO NOT HAVE THIS FILE, YOU SHOULD IMMEDIATELY CONTACT THE AUTHOR AT    *
  10.  *  ONE OF THE ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO  *
  11.  *  USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE SQUISH          *
  12.  *  DEVELOPERS KIT LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE *
  13.  *  ABLE TO REACH WITH THE AUTHOR.                                         *
  14.  *                                                                         *
  15.  *  You can contact the author at one of the address listed below:         *
  16.  *                                                                         *
  17.  *  Scott Dudley       FidoNet     1:249/106                               *
  18.  *  777 Downing St.    Internet    sjd@f106.n249.z1.fidonet.org            *
  19.  *  Kingston, Ont.     CompuServe  >INTERNET:sjd@f106.n249.z1.fidonet.org  *
  20.  *  Canada  K7M 5N3    BBS         1-613-634-3058, V.32bis                 *
  21.  *                                                                         *
  22.  ***************************************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <time.h>
  27. #include "prog.h"
  28.  
  29. static void near StandardDate(union stamp_combo *d_written);
  30.  
  31. void _fast ASCII_Date_To_Binary(char *msgdate,union stamp_combo *d_written)
  32. {
  33.   char temp[80];
  34.  
  35.   int dd,yy,mo,
  36.       hh,mm,ss,
  37.       x;
  38.  
  39.   time_t timeval;
  40.   struct tm *tim;
  41.  
  42.   timeval=time(NULL);
  43.   tim=localtime(&timeval);
  44.  
  45.   if (*msgdate=='\0') /* If no date... */
  46.   {
  47.     /* Insert today's date */
  48.     strftime(msgdate,19,"%d %b %y %H:%M:%S",tim);
  49.  
  50.     StandardDate(d_written);
  51.     return;
  52.   }
  53.  
  54.   if (sscanf(msgdate,"%d %s %d %d:%d:%d",&dd,temp,&yy,&hh,&mm,&ss)==6)
  55.     x=1;
  56.   else if (sscanf(msgdate,"%d %s %d %d:%d",&dd,temp,&yy,&hh,&mm)==5)
  57.   {
  58.     ss=0;
  59.     x=1;
  60.   }
  61.   else if (sscanf(msgdate, "%*s %d %s %d %d:%d",&dd,temp,&yy,&hh,&mm)==5)
  62.     x=2;
  63.   else if (sscanf(msgdate,"%d/%d/%d %d:%d:%d",&mo,&dd,&yy,&hh,&mm,&ss)==6)
  64.     x=3;
  65.   else x=0;
  66.  
  67.   if (x==0)
  68.   {
  69.     StandardDate(d_written);
  70.     return;
  71.   }
  72.  
  73.   if (x==1 || x==2) /* Formats one and two have ASCII date, so compare to list */
  74.   {
  75.     for (x=0;x < 12;x++)
  76.     {
  77.       if (eqstri(temp,months_ab[x]))
  78.       {
  79.         d_written->msg_st.date.mo=x+1;
  80.         break;
  81.       }
  82.     }
  83.  
  84.     if (x==12)    /* Invalid month, use January instead. */
  85.       d_written->msg_st.date.mo=1;
  86.   }
  87.   else d_written->msg_st.date.mo=mo; /* Format 3 don't need no ASCII month */
  88.  
  89.   d_written->msg_st.date.yr=yy-80;
  90.   d_written->msg_st.date.da=dd;
  91.  
  92.   d_written->msg_st.time.hh=hh;
  93.   d_written->msg_st.time.mm=mm;
  94.   d_written->msg_st.time.ss=ss >> 1;
  95. }
  96.  
  97.  
  98.  
  99. /* Date couldn't be determined, so set it to Jan 1st, 1980 */
  100.  
  101. static void near StandardDate(union stamp_combo *d_written)
  102. {
  103.   d_written->msg_st.date.yr=0;
  104.   d_written->msg_st.date.mo=1;
  105.   d_written->msg_st.date.da=1;
  106.  
  107.   d_written->msg_st.time.hh=0;
  108.   d_written->msg_st.time.mm=0;
  109.   d_written->msg_st.time.ss=0;
  110. }
  111.  
  112.  
  113.