home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / GENSUP / BATCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  2.6 KB  |  149 lines

  1. # include <stdio.h>
  2. # include <bench.h>
  3. # include <proc.io>
  4. # include "field.h"
  5. # include "screen.h"
  6. # include "iodef.h"
  7. # include "sup.h"
  8. # include "passwd.h"
  9.  
  10.  
  11. /*
  12.  * Simple Add & Update routines called from a Batch
  13. */
  14.  
  15. /*
  16.  * Add a new record to the file
  17. */
  18. int add_batch(tab, head, lptr)
  19. struct _table *tab;
  20. struct a_line **head, **lptr;
  21. {
  22.     int stat;
  23.  
  24.     if (!(tab->perms & PERM_ADD))
  25.         return (IOPERM);
  26.  
  27.     /*
  28.      * Free up pointers if necessary.
  29.      * Only set on Auto-Add in add mode.
  30.      * If Set, then update the record, as
  31.      * one has been pre-added, else simply
  32.      * add the record.
  33.      * Do we need to do a find before update ??? - NIG
  34.     */
  35.     no_msg = !(tab->messages);
  36.  
  37.     if ((*lptr) != ANULL)
  38.     {
  39.         if ((*lptr)->curr != ANULL)
  40.         {
  41.             free ((*lptr)->curr);
  42.             (*lptr)->curr = ANULL;
  43.             free ((*lptr));
  44.             (*lptr) = ANULL;
  45.             stat = updrec(tab->fd, tab->rec);
  46.         }
  47.     }
  48.     else
  49.         stat = appendrec(tab->fd, tab->rec);
  50.  
  51.     do_error(stat);
  52.  
  53.     return (TRUE);
  54. }
  55.  
  56. /*
  57.  * Re-write the record if it's value has changed
  58. */
  59. int rewrite_batch(tab, head, lptr)
  60. struct _table *tab;
  61. struct a_line **head, **lptr;
  62. {
  63.     int stat, try = 0;
  64.  
  65.     if (!(tab->perms & PERM_CHANGE))
  66.         return (IOPERM);
  67.  
  68.     /*
  69.      * No change, No update
  70.     */
  71.    if (!bytecmp(tab->rec, (*lptr)->rec, tab->size))
  72.         return (FALSE);
  73.  
  74.     no_msg = !(tab->messages);
  75.  
  76.     /*
  77.      * Lock the record before update.
  78.     */
  79.     stat = lock_rec(tab->fd, tab->rec);
  80.  
  81.     while (stat != IOGOOD && ++try <= tab->retry)
  82.     {
  83.         if (stat != IOGOOD && stat != IOLOCKED)
  84.             return (do_error(stat));
  85.  
  86.         stat = lock_rec(tab->fd, tab->rec); 
  87.     }
  88.  
  89.     if (stat != IOGOOD)
  90.         return (do_error(stat));
  91.  
  92.     bytecpy((*lptr)->rec, tab->rec, tab->size);
  93.  
  94.     stat = updrec(tab->fd, (*lptr)->rec);
  95.  
  96.     do_error(stat);
  97.  
  98.     return (TRUE);
  99. }
  100.  
  101.  
  102. int delete_batch(tab, head, lptr)
  103. struct _table *tab;
  104. struct a_line **head, **lptr;
  105. {
  106.     int stat, try = 0;
  107.  
  108.     /*
  109.      * Lock the record before Deleteion.
  110.     */
  111.     stat = lock_rec(tab->fd, tab->rec);
  112.  
  113.     while (stat != IOGOOD && ++try <= tab->retry)
  114.     {
  115.         if (stat != IOGOOD && stat != IOLOCKED)
  116.             return (do_error(stat));
  117.  
  118.         stat = lock_rec(tab->fd, tab->rec); 
  119.     }
  120.  
  121.     if (stat != IOGOOD)
  122.         return (do_error(stat));
  123.  
  124.     stat = removerec(tab->fd, tab->rec);
  125.  
  126.     do_error(stat);
  127.  
  128.     return (TRUE);
  129. }
  130.  
  131.  
  132. int output_list(tab, head, lptr, mode)
  133. struct _table *tab;
  134. struct a_line **head, **lptr;
  135. int mode;
  136. {
  137.     int stat, ln;
  138.  
  139.     if (!(tab->perms & PERM_ADD))
  140.         return (IOPERM);
  141.  
  142.    for (ln = 0; ln < tab->maximum; ln++)
  143.     {
  144.       if (tab->dsp_fn != (void (*)())0) 
  145.             (*tab->dsp_fn)(UNDERLINED, mode);
  146.     }
  147. }
  148.  
  149.