home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / GENSUP / BATCH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-15  |  3.3 KB  |  162 lines

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