home *** CD-ROM | disk | FTP | other *** search
- /* ==( gensup/batch.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"
-
-
- /*
- * Simple Add & Update routines called from a Batch
- */
-
- /*
- * Add a new record to the file
- */
- int add_batch(tab, head, lptr)
- struct _table *tab;
- struct a_line **head, **lptr;
- {
- int stat;
-
- if (!(tab->perms & PERM_ADD))
- return (IOPERM);
-
- /*
- * Free up pointers if necessary.
- * Only set on Auto-Add in add mode.
- * If Set, then update the record, as
- * one has been pre-added, else simply
- * add the record.
- * Do we need to do a find before update ??? - NIG
- */
- no_msg = !(tab->messages);
-
- if ((*lptr) != ANULL)
- {
- if ((*lptr)->curr != ANULL)
- {
- bytecpy((*lptr)->rec, tab->rec, tab->size);
- bytecpy(tab->rec, (*lptr)->curr->rec, tab->size);
- stat = lock_rec(tab->fd, tab->rec);
- if (stat == IOGOOD)
- {
- bytecpy(tab->rec, (*lptr)->rec, tab->size);
- stat = updrec(tab->fd, tab->rec);
- }
- free ((*lptr)->curr);
- (*lptr)->curr = ANULL;
- free ((*lptr));
- (*lptr) = ANULL;
- }
- }
- else
- stat = appendrec(tab->fd, tab->rec);
-
- do_error(stat);
-
- return (TRUE);
- }
-
- /*
- * Re-write the record if it's value has changed
- */
- int rewrite_batch(tab, head, lptr)
- struct _table *tab;
- struct a_line **head, **lptr;
- {
- int stat, try = 0;
-
- if (!(tab->perms & PERM_CHANGE))
- return (IOPERM);
-
- /*
- * Old Way !!
- if (!bytecmp(tab->rec, (*lptr)->rec, tab->size))
- *
- * No change, No update
- */
- if (!cmp_rec(tab, *lptr))
- return (FALSE);
-
- no_msg = !(tab->messages);
-
- /*
- * Find & Lock the record before update.
- * If there are No Unique Keys, then the same record
- * will get updated N times !!
- */
- if (tab->tabno != 1 && tab->uniquekey != 0)
- {
- selectinx(tab->fd, tab->uniquekey, EXACT, tab->retry);
- stat = findkey(tab->fd, (*lptr)->rec);
- }
- else
- stat = lock_rec(tab->fd, (*lptr)->rec);
-
- if (stat != IOGOOD)
- return (do_error(stat));
-
- stat = updrec(tab->fd, tab->rec);
-
- do_error(stat);
-
- return (TRUE);
- }
-
-
- int delete_batch(tab, head, lptr)
- struct _table *tab;
- struct a_line **head, **lptr;
- {
- int stat, try = 0;
-
- /*
- * Lock the record before Deleteion.
- */
- stat = lock_rec(tab->fd, tab->rec);
-
- if (stat != IOGOOD)
- return (do_error(stat));
-
- stat = removerec(tab->fd, tab->rec);
-
- do_error(stat);
-
- return (TRUE);
- }
-
-
- int output_list(tab, head, lptr, mode)
- struct _table *tab;
- struct a_line **head, **lptr;
- int mode;
- {
- int stat, ln;
-
- if (!(tab->perms & PERM_ADD))
- return (IOPERM);
-
- for (ln = 0; ln < tab->maximum; ln++)
- {
- if (tab->dsp_fn != (void (*)())0)
- (*tab->dsp_fn)(UNDERLINED, mode);
- }
- }
-
-