home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2SRC.ZIP / DATE.C < prev    next >
Text File  |  1991-04-20  |  5KB  |  185 lines

  1. /*
  2.   $Header: date.c 3.3 87/12/12 00:40:50 Bob Exp $
  3.  
  4.                           The Conference Mail System
  5.  
  6.               This module was originally written by Bob Hartman
  7.                        Sysop of FidoNet node 1:132/101
  8.  
  9.    Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061
  10.  
  11.  The Conference Mail System  is a  complete Echomail processing package.  It
  12.  is a superset of the original  Echomail utilities created by Jeff Rush, and
  13.  also contains ideas gleaned from the  ARCmail,  Renum,  oMMM, MGM, and Opus
  14.  programs that were created by various software authors.
  15.  
  16.  This program source code is being released with the following provisions:
  17.  
  18.  1.  You are  free to make  changes to this source  code for use on your own
  19.  machine,  however,  altered source files may not be distributed without the
  20.  consent of Spark Software.
  21.  
  22.  2.  You may distribute "patches"  or  "diff" files for any changes that you
  23.  have made, provided that the "patch" or "diff" files are also sent to Spark
  24.  Software for inclusion in future releases of the entire package.   A "diff"
  25.  file for the source archives may also contain a compiled version,  provided
  26.  it is  clearly marked as not  being created  from the original source code.
  27.  No other  executable  versions may be  distributed without  the  consent of
  28.  Spark Software.
  29.  
  30.  3.  You are free to include portions of this source code in any program you
  31.  develop, providing:  a) Credit is given to Spark Software for any code that
  32.  may is used, and  b) The resulting program is free to anyone wanting to use
  33.  it, including commercial and government users.
  34.  
  35.  4.  There is  NO  technical support  available for dealing with this source
  36.  code, or the accompanying executable files.  This source  code  is provided
  37.  as is, with no warranty expressed or implied (I hate legalease).   In other
  38.  words, if you don't know what to do with it,  don't use it,  and if you are
  39.  brave enough to use it, you're on your own.
  40.  
  41.  Spark Software may be contacted by modem at (603) 888-8179 (node 1:132/101)
  42.  on the public FidoNet network, or at the address given above.
  43.  
  44.  To use this code you will need Microsoft C version 4.0, and also Microsoft
  45.  Macro Assembler version 4.0.
  46.  
  47. */
  48.  
  49. /*
  50.    $Log:    date.c $
  51.  * Revision 3.3  87/12/12  00:40:50  Bob
  52.  * Source code release
  53.  *
  54. */
  55.  
  56. #include <stdio.h>
  57. #include <fcntl.h>
  58. #include <setjmp.h>
  59. #include <ctype.h>
  60. #include <dos.h>
  61. #include <string.h>
  62. #include <signal.h>
  63. #include "fastecho.h"
  64.  
  65. #define DEBUG 0
  66.  
  67. #define YEAR(x)   ((((x)->date>>9)&0x7f))
  68. #define MONTH(x)  (((x)->date>>5)&0x0f)
  69. #define DAY(x)    ((x)->date&0x1f)
  70. #define HOUR(x)   (((x)->time>>11)&0x1f)
  71. #define MINUTE(x) (((x)->time>>5)&0x3f)
  72. #define SECOND(x) (((x)->time&0x1f)*2)
  73.  
  74.  
  75. extern int seadog;
  76. extern int quiet;
  77. extern char home[];
  78. extern char home1[];
  79. extern int *msg_nums;
  80.  
  81.  
  82. #define ESCAPE_CHAR     '%'
  83. #define DOSINT   0x21
  84.  
  85. static char *_days[7] = {
  86.    "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
  87. };
  88.  
  89. long days_to_month[12] = {
  90.    0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L
  91. };
  92.  
  93. extern char *_months[];
  94.  
  95. long secs_from_1980 (MSG *str)
  96. {
  97.     long ret_val, y, d, h, m, s;
  98.     int i;
  99.     char m1[100], junk[100];
  100.  
  101.     s = 0L;
  102.     if ((str->date[19]&0xff) != 0xff)
  103.     {
  104.         if ((i = sscanf (str->date, "%ld %s %ld %ld:%ld:%ld", &d, m1, &y, &h, &m, &s)) != 6)
  105.         {
  106.             if ((i = sscanf (str->date, "%s %ld %s %ld %ld:%ld", junk, &d, m1, &y, &h, &m)) < 5)
  107.             {
  108.                 return (1000000000L);
  109.             }
  110.         }
  111.         m1[0] = (char) toupper (m1[0]);
  112.         m1[1] = (char) toupper (m1[1]);
  113.         m1[2] = (char) toupper (m1[2]);
  114. /*      i = 0;
  115.         while ((strncmp (_months[i], m1, 3) != 0) && (i != 12))
  116.             ++i;
  117.  */
  118.         for (i=0;i<12;i++)
  119.         {
  120.             if (strncmp (_months[i], m1, 3) == 0)
  121.                 break;
  122.         }
  123.     }
  124.     else
  125.     {
  126.         y = (long) (YEAR (&(str->_date_written)));
  127.         d = (long) (DAY (&(str->_date_written)));
  128.         i = MONTH (&(str->_date_written)) - 1;
  129.         h = (long) (HOUR (&(str->_date_written)));
  130.         m = (long) (MINUTE (&(str->_date_written)));
  131.  
  132.     }
  133.  
  134.     ret_val = y - 80;
  135.     ret_val *= 365;
  136.     ret_val += d;
  137.  
  138.     if (i != 12)
  139.     {
  140.         ret_val += days_to_month[i];
  141.     }
  142.     else
  143.     {
  144.         if (strncmp("MEI",m1,3) != 0)
  145.             return (1000000000L);
  146.         else
  147.             ret_val += days_to_month[4];
  148.     }
  149.     ret_val *= 86400L;
  150.  
  151.     /* Now we have number of seconds for the full days add in h:m:s */
  152.  
  153.     /* Can't add in seconds because TBBS systems do not save that value */
  154. /*  ret_val += s; */
  155.     ret_val += (m * 60L);
  156.     ret_val += (h * 3600L);
  157.  
  158.     return (ret_val);
  159. }
  160.  
  161. unsigned int calcrc(char *ptr)
  162. {
  163.     unsigned int crc;
  164.     int i, j;
  165.     unsigned char r;
  166.  
  167.     crc = 0;
  168.     j = 0;
  169.     while ((*ptr) && (j++ <= 40))
  170.     {
  171.         r = (char) toupper (*ptr);
  172.         ++ptr;
  173.         crc = crc ^ (int)r << 8;
  174.         for (i = 0; i < 8; ++i)
  175.         {
  176.             if (crc & 0x8000)
  177.                 crc = crc << 1 ^ 0x1021;
  178.             else
  179.                 crc = crc << 1;
  180.         }
  181.     }
  182.     return (crc & 0xFFFF);
  183. }
  184.  
  185.