home *** CD-ROM | disk | FTP | other *** search
- /* ==( gensup/chg.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Nig 1-Jan-90 */
- /* Modified Nig 1-Jan-90 */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
-
- # include <stdio.h>
- # include <bench.h>
- # include <proc.io>
- # include "field.h"
- # include "iodef.h"
- # include "sup.h"
- # include "screen.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(ErrNoChg);
- return (IOPERM);
- }
-
- if (*lptr == ANULL)
- return (IOGOOD);
-
- if ((*lptr)->deleted == TRUE)
- {
- errmsg(ErrDelete);
- 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);
-
- 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);
-
- /*
- * Old Way !!
- if (cc == FALSE && bytecmp(tab->rec, (*lptr)->curr->rec, tab->size))
- */
- if (cc == FALSE && cmp_rec(tab, (*lptr)->curr))
- if (tab->query_box && !warning(99, UpdAbandon))
- 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);
-
- 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(ErrNoRec);
- return (FALSE);
- }
-
- if (!cmp_rec(tab, (*lptr)->curr))
- {
- /*
- * Not a query, but the same sort of message
- */
- if (tab->query_box)
- errmsg(UpdNoChg);
- return (FALSE);
- }
-
- if (tab->query_box && !warning(99, UpdSave))
- return (FALSE);
-
- /*
- * Record should already be Locked at this stage.
- */
- no_msg = !(tab->messages);
-
- /*
- * If you perform an x-ref to the same table, then the current
- * record pointer will no longer be valid here. If you need the
- * record to be valid, then the table must have a Unique key.
- * Select this key, search on the record, copy in the new values
- * the update.
- * Re-Select the regular current key afterwards though to make sure
- * that the sequencing is correct.
- */
-
- 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 (stat != IOGOOD)
- lock_rec(tab->fd, tab->rec);
-
- if (do_error(stat) != IOGOOD)
- return (FALSE);
-
- bytecpy((*lptr)->curr->rec, tab->rec, tab->size);
- bytecpy((*lptr)->rec, tab->rec, tab->size);
-
- return (TRUE);
- }
-
-
-