home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / PLST_133.SZH / STDIO.C < prev    next >
Text File  |  1991-09-20  |  6KB  |  229 lines

  1. /*
  2.  
  3.                           The Conference Mail System
  4.  
  5.               This module was originally written by Bob Hartman
  6.                        Sysop of FidoNet node 1:104/501
  7.  
  8.  The Conference Mail System  is a  complete Echomail processing package.  It
  9.  is a superset of the original  Echomail utilities created by Jeff Rush, and
  10.  also contains ideas gleaned from the  ARCmail,  Renum,  oMMM, MGM, and Opus
  11.  programs that were created by various software authors.
  12.  
  13.  This program source code is being released with the following provisions:
  14.  
  15.  1.  You are  free to make  changes to this source  code for use on your own
  16.  machine,  however,  altered source files may not be distributed without the
  17.  consent of Spark Software.
  18.  
  19.  2.  You may distribute "patches"  or  "diff" files for any changes that you
  20.  have made, provided that the "patch" or "diff" files are also sent to Spark
  21.  Software for inclusion in future releases of the entire package.   A "diff"
  22.  file for the source archives may also contain a compiled version,  provided
  23.  it is  clearly marked as not  being created  from the original source code.
  24.  No other  executable  versions may be  distributed without  the  consent of
  25.  Spark Software.
  26.  
  27.  3.  You are free to include portions of this source code in any program you
  28.  develop, providing:  a) Credit is given to Spark Software for any code that
  29.  may is used, and  b) The resulting program is free to anyone wanting to use
  30.  it, including commercial and government users.
  31.  
  32.  4.  There is  NO  technical support  available for dealing with this source
  33.  code, or the accompanying executable files.  This source  code  is provided
  34.  as is, with no warranty expressed or implied (I hate legalease).   In other
  35.  words, if you don't know what to do with it,  don't use it,  and if you are
  36.  brave enough to use it, you're on your own.
  37.  
  38. */
  39.  
  40. /*
  41.    $Log:    stdio.c $
  42.  * Revision 3.3  87/12/12  00:45:26  Bob
  43.  * Source code release
  44.  *
  45. */
  46.  
  47. #include <stdio.h>
  48. #include <ctype.h>
  49. #include <malloc.h>
  50. #include "types.h"
  51. #include "externs.h"
  52.  
  53. #define BIGSIZE 8192
  54.  
  55. WBUFFER wbuffs[50] = {
  56.    { NULL, NULL, -1 },
  57.    { NULL, NULL, -1 },
  58.    { NULL, NULL, -1 },
  59.    { NULL, NULL, -1 },
  60.    { NULL, NULL, -1 },
  61.    { NULL, NULL, -1 },
  62.    { NULL, NULL, -1 },
  63.    { NULL, NULL, -1 },
  64.    { NULL, NULL, -1 },
  65.    { NULL, NULL, -1 },
  66.    { NULL, NULL, -1 },
  67.    { NULL, NULL, -1 },
  68.    { NULL, NULL, -1 },
  69.    { NULL, NULL, -1 },
  70.    { NULL, NULL, -1 },
  71.    { NULL, NULL, -1 },
  72.    { NULL, NULL, -1 },
  73.    { NULL, NULL, -1 },
  74.    { NULL, NULL, -1 },
  75.    { NULL, NULL, -1 },
  76.    { NULL, NULL, -1 },
  77.    { NULL, NULL, -1 },
  78.    { NULL, NULL, -1 },
  79.    { NULL, NULL, -1 },
  80.    { NULL, NULL, -1 },
  81.    { NULL, NULL, -1 },
  82.    { NULL, NULL, -1 },
  83.    { NULL, NULL, -1 },
  84.    { NULL, NULL, -1 },
  85.    { NULL, NULL, -1 },
  86.    { NULL, NULL, -1 },
  87.    { NULL, NULL, -1 },
  88.    { NULL, NULL, -1 },
  89.    { NULL, NULL, -1 },
  90.    { NULL, NULL, -1 },
  91.    { NULL, NULL, -1 },
  92.    { NULL, NULL, -1 },
  93.    { NULL, NULL, -1 },
  94.    { NULL, NULL, -1 },
  95.    { NULL, NULL, -1 },
  96.    { NULL, NULL, -1 },
  97.    { NULL, NULL, -1 },
  98.    { NULL, NULL, -1 },
  99.    { NULL, NULL, -1 },
  100.    { NULL, NULL, -1 },
  101.    { NULL, NULL, -1 },
  102.    { NULL, NULL, -1 },
  103.    { NULL, NULL, -1 },
  104.    { NULL, NULL, -1 },
  105.    { NULL, NULL, -1 }
  106. };
  107.  
  108. fast_open (char *name,int mode,int pmode)
  109. {
  110.    int f;
  111. /* extern char far *_FMALLOC1(); */
  112.  
  113.    pmode = pmode; /* Shut up 6.0 */
  114.    if ((f = OFAST_OPEN (name, mode)) != -1)
  115.       {
  116.       if (wbuffs[f].wbuff == NULL)
  117.          {
  118.          wbuffs[f].wbuff = wbuffs[f].wptr = _FMALLOC1 (BIGSIZE);
  119.          if (wbuffs[f].wbuff != NULL)
  120.             wbuffs[f].wsize = 0;
  121.          }
  122.       }
  123.  
  124.    return (f);
  125.  
  126.  
  127. }
  128.  
  129. fast_close (int f)
  130. {
  131.    if (wbuffs[f].wsize > 0)
  132.       {
  133.       O1FAST_WRITE (f, wbuffs[f].wbuff, wbuffs[f].wsize);
  134.       wbuffs[f].wsize = -1;
  135.       _FFREE1 (wbuffs[f].wbuff);
  136.       wbuffs[f].wptr = wbuffs[f].wbuff = NULL;
  137.       }
  138.    return (OFAST_CLOSE (f));
  139. }
  140.  
  141. fast_write (int f,char *st,unsigned int l)
  142. {
  143.    unsigned int ctr, savel;
  144.    WBUFFER *w;
  145.  
  146.    w = &wbuffs[f];
  147.    if ((int)(w->wsize) < 0)
  148.    {
  149.       return (OFAST_WRITE (f, st, l));
  150.    }
  151.  
  152.    savel = l;
  153.    ctr = 0;
  154.    do {
  155.       if (w->wsize + l > BIGSIZE)
  156.       {
  157.          MEM1CPY (w->wptr, &st[ctr], BIGSIZE - w->wsize);
  158.          l -= (BIGSIZE - w->wsize);
  159.          ctr += (BIGSIZE - w->wsize);
  160.          w->wsize = 0;
  161.          w->wptr = w->wbuff;
  162.          if (O1FAST_WRITE (f, w->wbuff, BIGSIZE) != BIGSIZE)
  163.          {
  164.             w->wsize = 0;
  165.             return (-1);
  166.          }
  167.       }
  168.       else
  169.       {
  170.          MEM1CPY (w->wptr, &st[ctr], l);
  171.          w->wsize += l;
  172.          w->wptr += l;
  173.          l = 0;
  174.       }
  175.    } while (l != 0);
  176.  
  177.    return (savel);
  178. }
  179.  
  180. fast_read (int f,char *st,unsigned int l)
  181. {
  182.    unsigned int ctr, savel;
  183.    WBUFFER *w;
  184.  
  185.    w = &wbuffs[f];
  186.    if ((int)(w->wsize) < 0)
  187.    {
  188.       return (OFAST_READ (f, st, l));
  189.    }
  190.  
  191.    savel = l;
  192.    ctr = 0;
  193.    do {
  194.       if (w->wsize == 0)
  195.       {
  196.          w->wptr = w->wbuff;
  197.          w->wsize = O1FAST_READ (f, w->wbuff, BIGSIZE);
  198.          if ((int)(w->wsize) <= 0)
  199.          {
  200.             w->wsize = 0;
  201.             return (savel - l);
  202.          }
  203.       }
  204.  
  205.       if (((int)(w->wsize) - (int) l) < 0)
  206.       {
  207.          MEM2CPY (&st[ctr], w->wptr, w->wsize);
  208.          l -= w->wsize;
  209.          ctr += w->wsize;
  210.          w->wptr = w->wbuff;
  211.          w->wsize = O1FAST_READ (f, w->wbuff, BIGSIZE);
  212.          if ((int)(w->wsize) <= 0)
  213.          {
  214.             w->wsize = 0;
  215.             return (savel - l);
  216.          }
  217.       }
  218.       else
  219.       {
  220.          MEM2CPY (&st[ctr], w->wptr, l);
  221.          w->wsize -= l;
  222.          w->wptr += l;
  223.          l = 0;
  224.       }
  225.    } while (l != 0);
  226.  
  227.    return (savel);
  228. }
  229.