home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / GENSUP / CHG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  3.7 KB  |  197 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. extern int tot_size;
  11. extern int pending;
  12.  
  13. /*
  14.  * Change Mode !! Revelation
  15. */
  16. int change_mode(tab, head, lptr, table, mode)
  17. struct _table *tab;
  18. struct a_line **head, **lptr;
  19. int table, mode;
  20. {
  21.     int stat, try = 0;
  22.     int cc;
  23.  
  24.     if (!(tab->perms & PERM_CHANGE))
  25.     {
  26.         errmsg(ERR_NOCHG);
  27.         return (IOPERM);
  28.     }
  29.  
  30.     if (*lptr == ANULL)
  31.         return (IOGOOD);
  32.  
  33.     if ((*lptr)->deleted == TRUE)
  34.     {
  35.         errmsg(ERR_DELETE);
  36.         return (IOGOOD);
  37.     }
  38.  
  39.     /*
  40.      * Save current Record
  41.     */
  42.    (*lptr)->curr = (struct a_line *) alloc(tot_size);
  43.       bytecpy((*lptr)->curr->rec, tab->rec, tab->size);
  44.  
  45.     /*
  46.      * Lock the required record
  47.     */
  48.     no_msg = !(tab->messages);
  49.  
  50.     stat = lock_rec(tab->fd, tab->rec);
  51.  
  52.     while (stat != IOGOOD && ++try <= tab->retry)
  53.     {
  54.         if (stat != IOGOOD && stat != IOLOCKED)
  55.         {
  56.             free ((*lptr)->curr);
  57.             (*lptr)->curr = ANULL;
  58.             return (do_error(stat));
  59.         }
  60.  
  61.         stat = lock_rec(tab->fd, tab->rec); 
  62.     }
  63.  
  64.     if (stat != IOGOOD)
  65.     {
  66.         free ((*lptr)->curr);
  67.         (*lptr)->curr = ANULL;
  68.         return (do_error(stat));
  69.     }
  70.  
  71.     /*
  72.      * Switch on Transaction Processing for the duration
  73.     */
  74.     if (tab->tp)
  75.         tran_p(tab);
  76.  
  77.     /*
  78.      * Enter Details here
  79.      * and update current record
  80.     */
  81.     do
  82.     {
  83.         ichar = K_CR;
  84.  
  85.         cc = (*tab->inp_fn)(CHG, tab, head, lptr, table);
  86.  
  87.        if (cc == FALSE && bytecmp(tab->rec, (*lptr)->curr->rec, tab->size))
  88.             if (tab->query_box && !warning(99, UPD_ABANDON))
  89.                 cc = TRUE;
  90.     }
  91.     while (cc != FALSE);
  92.  
  93.     /*
  94.      * If the user hits ESC, then we unlock the record
  95.      * but if he has hit CHG, then it will be unlocked 
  96.      * anyway. Problem - NIG
  97.     */
  98.     no_msg = !(tab->messages);
  99.  
  100.     if (tab->retry != 0)
  101.         ulock_rec(tab->fd, tab->rec);
  102.  
  103.     /*
  104.      * Ok, if the user gets here then he has hit ESC or
  105.      * dropped throught normally.  If there are transactions
  106.      * pending, then we need to commit them.
  107.     */
  108.     if (tab->tp)
  109.         comm_p(tab);
  110.  
  111.     /*
  112.      * Restore Previous values if ESC hit.
  113.      * If ESC was not hit, then curr contains
  114.      * the current record anyway.
  115.     */
  116.       bytecpy((*lptr)->rec, (*lptr)->curr->rec, tab->size);
  117.       bytecpy(tab->rec, (*lptr)->rec, tab->size);
  118.  
  119.     /*
  120.      * Re-display the Current Record in 'Selected' attribute
  121.     */
  122.     if (tab->dsp_fn != (void (*)())0) 
  123.           (*tab->dsp_fn)(UNDERLINED, mode);
  124.  
  125.     free ((*lptr)->curr);
  126.     (*lptr)->curr = ANULL;
  127.  
  128.     return (IOGOOD);
  129. }
  130.  
  131. /*
  132.  * Re-write the record if it's value has changed
  133. */
  134. int rewrite_mode(tab, head, lptr)
  135. struct _table *tab;
  136. struct a_line **head, **lptr;
  137. {
  138.     int stat;
  139.  
  140.     /*
  141.      * No change, No update
  142.      *
  143.      * OK, because of the scan_table routine, makes tab->rec & 
  144.      * lptr->rec the same, we also need to check against the 
  145.      * curr->rec value, which is the value of the record before 
  146.      * any changes are made.
  147.     */
  148.     if ((*lptr)->curr == ANULL)
  149.     {
  150.         errmsg(ERR_NOREC);
  151.         return (FALSE);
  152.     }
  153.  
  154.    if (!bytecmp(tab->rec, (*lptr)->curr->rec, tab->size))
  155.     {
  156.         /*
  157.          * Not a query, but the same sort of message
  158.         */
  159.         if (tab->query_box)
  160.             errmsg(UPD_NOCHG);
  161.         return (FALSE);
  162.     }
  163.  
  164.     if (tab->query_box && !warning(99, UPD_SAVE))
  165.         return (FALSE);
  166.  
  167.     /*
  168.      * Record is Already Locked at this stage.
  169.     */
  170.     no_msg = !(tab->messages);
  171.  
  172.     stat = updrec(tab->fd, tab->rec);
  173.  
  174.     /*
  175.      * Commit or Rollback the pending operations
  176.     */
  177.     pending = TRUE;
  178.  
  179.     if (tab->tp)
  180.     {
  181.         if (stat == IOGOOD)
  182.             comm_p(tab);
  183.         else
  184.             roll_p(tab);
  185.     }
  186.  
  187.     if (do_error(stat) != IOGOOD)
  188.         return (FALSE);
  189.  
  190.     bytecpy((*lptr)->curr->rec, tab->rec, tab->size);
  191.     bytecpy((*lptr)->rec, tab->rec, tab->size);
  192.  
  193.     return (TRUE);
  194. }
  195.  
  196.  
  197.