home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2_409E.SZH / HW.C < prev    next >
Text File  |  1991-06-27  |  6KB  |  213 lines

  1. /*
  2.   $Header: hw.c 3.3 87/12/12 00:42:46 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:    hw.c $
  51.  * Revision 3.3  87/12/12  00:42:46  Bob
  52.  * Source code release
  53.  *
  54. */
  55.  
  56. #include <stdio.h>
  57. #include <ctype.h>
  58. #include <fcntl.h>
  59. #include <io.h>
  60. #include <string.h>
  61. #include <time.h>
  62. #include <sys\types.h>
  63. #include <sys\stat.h>
  64. #include "fastecho.h"
  65.  
  66. #define DEBUG 0
  67.  
  68. extern int high_one;
  69. extern char tearline[];
  70. extern int ctrla;
  71. extern int hwptr;
  72.  
  73. extern struct tm *t2;
  74. extern struct _stamp cur_stamp;
  75. extern struct _stamp zero_stamp;
  76.  
  77. extern char *_months[];
  78. extern char *weekday[];
  79.  
  80. void get_hw (AREAS_PTR which)
  81. {
  82.     int f;
  83.     char fname1[80];
  84.     MSG m;
  85.     int *hptr;
  86.  
  87.     /* Open message 1 */
  88.     /* Create the message file name */
  89.     sprintf (fname1, "%s\\1.MSG", which->msg_path);
  90.  
  91.     if (hwptr)
  92.         hptr = &(m.up);
  93.     else
  94.         hptr = &(m.reply);
  95.  
  96.     /* Set up a default */
  97.     *hptr = 1;
  98.  
  99. #if DEBUG
  100.     printf ("getting high water from '%s'\n", fname1);
  101. #endif
  102.  
  103.     /* Open up new message file */
  104.     if((f = open (fname1, O_RDONLY|O_BINARY)) == -1)
  105.     {
  106. #if DEBUG
  107.         printf ("high water mark does not exist\n");
  108. #endif
  109.         /* It does not exist, so just return first message */
  110.         /* By returning 0 find_msg() will give the first real message */
  111.         high_one = 0;
  112.         return;
  113.     }
  114.  
  115.     (void) fast_read (f, (char *) &m, sizeof (MSG));
  116.  
  117. #if DEBUG
  118.     printf ("reply = %d, up = %d, from = '%s'\n", m.reply, m.up, m.from);
  119. #endif
  120.     (void) fast_close (f);
  121.     high_one = *hptr;
  122. #if DEBUG
  123.     printf ("returning %d as the high water mark\n", high_one);
  124. #endif
  125. }
  126.  
  127. void set_hw (int mnum,AREAS_PTR which)
  128. {
  129.     int f, foo;
  130.     char fname1[80];
  131.     char mess[100];
  132.     MSG m;
  133.     int *hptr;
  134.  
  135.     /* Open message 1 */
  136.     /* Create the message file name */
  137.     sprintf (fname1, "%s\\1.MSG", which->msg_path);
  138.  
  139. #if DEBUG
  140.     printf ("getting high water from '%s'\n", fname1);
  141. #endif
  142.  
  143.     if (hwptr)
  144.         hptr = &(m.up);
  145.     else
  146.         hptr = &(m.reply);
  147.  
  148.     memset ((char *) &m, 0, sizeof (MSG));
  149.     foo = 0;
  150.     /* Open up new message file */
  151.     if((f = open (fname1, O_RDONLY|O_BINARY)) == -1)
  152.     {
  153.         foo = 1;
  154.  
  155.         /* It does not exist, so create it */
  156.         if ((f = open (fname1, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1)
  157.         {
  158.             /* Could not even create it */
  159.             printf ("\nCould not store High Water Mark for area '%s'", which->area_name);
  160.             return;
  161.         }
  162.  
  163.         strcpy (m.from, &tearline[6]);
  164.         m.from[strlen(m.from)-1] = '\0';
  165.         m.from[strlen(m.from)-1] = '\0';
  166.         strcpy (m.to, m.from);
  167.         strcpy (m.subj, "ConfMail High Water Mark Stored Here");
  168.         m.times = 0;
  169.         m.dest = -1;
  170.         m.orig = -1;
  171.         m.cost = 0;
  172.         m.orig_net = -1;
  173.         m.dest_net = -1;
  174.         m.attr = MSGSENT|MSGPRIVATE;
  175.         m.up = 0;
  176.         m.reply = 0;
  177. #if DEBUG
  178.         printf ("High water message being created\n");
  179. #endif
  180.     }
  181.     else
  182.     {
  183. #if DEBUG
  184.         printf ("Found high water message\n");
  185. #endif
  186.         (void) fast_read (f, (char *) &m, sizeof (MSG));
  187.         (void) fast_close (f);
  188.         f = open (fname1, O_RDWR|O_BINARY);
  189.     }
  190.  
  191.     /* Save the high water mark */
  192.     *hptr = mnum;
  193.     /* Alway stick in the date arrived */
  194.     m._date_arrived = zero_stamp;
  195.  
  196.     /* Stick in a valid date */
  197.     sprintf (m.date, "%3.3s %2d %3.3s %02d %02d:%02d",
  198.       weekday[t2->tm_wday], t2->tm_mday, _months[t2->tm_mon],
  199.       t2->tm_year, t2->tm_hour, t2->tm_min);
  200.     m.date[8] = (char) tolower (m.date[8]);
  201.     m.date[9] = (char) tolower (m.date[9]);
  202.     m._date_written = m._date_arrived = zero_stamp;
  203.  
  204.     (void) fast_write (f, (char *) &m, sizeof (MSG));
  205.     if (foo)
  206.     {
  207.         sprintf (mess, "NOECHO\r\n\r\nIgnore this message!\r\rIt is only used by the Conference Mail System.\r\r");
  208.         (void) fast_write (f, mess, strlen(mess));
  209.     }
  210.     (void) fast_close (f);
  211. }
  212.  
  213.