home *** CD-ROM | disk | FTP | other *** search
- # include <stdio.h>
- # include <bench.h>
- # include <proc.io>
- # include "field.h"
- # include "screen.h"
- # include "iodef.h"
- # include "sup.h"
- # include "passwd.h"
-
- extern int tot_size;
- extern int pending;
-
- /*
- * Change Mode !! Revelation
- */
- int change_mode(tab, head, lptr, table, mode)
- struct _table *tab;
- struct a_line **head, **lptr;
- int table, mode;
- {
- int stat, try = 0;
- int cc;
-
- if (!(tab->perms & PERM_CHANGE))
- {
- errmsg(ERR_NOCHG);
- return (IOPERM);
- }
-
- if (*lptr == ANULL)
- return (IOGOOD);
-
- if ((*lptr)->deleted == TRUE)
- {
- errmsg(ERR_DELETE);
- return (IOGOOD);
- }
-
- /*
- * Save current Record
- */
- (*lptr)->curr = (struct a_line *) alloc(tot_size);
- bytecpy((*lptr)->curr->rec, tab->rec, tab->size);
-
- /*
- * Lock the required record
- */
- no_msg = !(tab->messages);
-
- stat = lock_rec(tab->fd, tab->rec);
-
- while (stat != IOGOOD && ++try <= tab->retry)
- {
- if (stat != IOGOOD && stat != IOLOCKED)
- {
- free ((*lptr)->curr);
- (*lptr)->curr = ANULL;
- return (do_error(stat));
- }
-
- stat = lock_rec(tab->fd, tab->rec);
- }
-
- if (stat != IOGOOD)
- {
- free ((*lptr)->curr);
- (*lptr)->curr = ANULL;
- return (do_error(stat));
- }
-
- /*
- * Switch on Transaction Processing for the duration
- */
- if (tab->tp)
- tran_p(tab);
-
- /*
- * Enter Details here
- * and update current record
- */
- do
- {
- ichar = K_CR;
-
- cc = (*tab->inp_fn)(CHG, tab, head, lptr, table);
-
- if (cc == FALSE && bytecmp(tab->rec, (*lptr)->curr->rec, tab->size))
- if (tab->query_box && !warning(99, UPD_ABANDON))
- cc = TRUE;
- }
- while (cc != FALSE);
-
- /*
- * If the user hits ESC, then we unlock the record
- * but if he has hit CHG, then it will be unlocked
- * anyway. Problem - NIG
- */
- no_msg = !(tab->messages);
-
- if (tab->retry != 0)
- ulock_rec(tab->fd, tab->rec);
-
- /*
- * Ok, if the user gets here then he has hit ESC or
- * dropped throught normally. If there are transactions
- * pending, then we need to commit them.
- */
- if (tab->tp)
- comm_p(tab);
-
- /*
- * Restore Previous values if ESC hit.
- * If ESC was not hit, then curr contains
- * the current record anyway.
- */
- bytecpy((*lptr)->rec, (*lptr)->curr->rec, tab->size);
- bytecpy(tab->rec, (*lptr)->rec, tab->size);
-
- /*
- * Re-display the Current Record in 'Selected' attribute
- */
- if (tab->dsp_fn != (void (*)())0)
- (*tab->dsp_fn)(UNDERLINED, mode);
-
- free ((*lptr)->curr);
- (*lptr)->curr = ANULL;
-
- return (IOGOOD);
- }
-
- /*
- * Re-write the record if it's value has changed
- */
- int rewrite_mode(tab, head, lptr)
- struct _table *tab;
- struct a_line **head, **lptr;
- {
- int stat;
-
- /*
- * No change, No update
- *
- * OK, because of the scan_table routine, makes tab->rec &
- * lptr->rec the same, we also need to check against the
- * curr->rec value, which is the value of the record before
- * any changes are made.
- */
- if ((*lptr)->curr == ANULL)
- {
- errmsg(ERR_NOREC);
- return (FALSE);
- }
-
- if (!bytecmp(tab->rec, (*lptr)->curr->rec, tab->size))
- {
- /*
- * Not a query, but the same sort of message
- */
- if (tab->query_box)
- errmsg(UPD_NOCHG);
- return (FALSE);
- }
-
- if (tab->query_box && !warning(99, UPD_SAVE))
- return (FALSE);
-
- /*
- * Record is Already Locked at this stage.
- */
- no_msg = !(tab->messages);
-
- stat = updrec(tab->fd, tab->rec);
-
- /*
- * Commit or Rollback the pending operations
- */
- pending = TRUE;
-
- if (tab->tp)
- {
- if (stat == IOGOOD)
- comm_p(tab);
- else
- roll_p(tab);
- }
-
- if (do_error(stat) != IOGOOD)
- return (FALSE);
-
- bytecpy((*lptr)->curr->rec, tab->rec, tab->size);
- bytecpy((*lptr)->rec, tab->rec, tab->size);
-
- return (TRUE);
- }
-
-
-