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"
-
-
- /*
- * 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)
- {
- free ((*lptr)->curr);
- (*lptr)->curr = ANULL;
- free ((*lptr));
- (*lptr) = ANULL;
- stat = updrec(tab->fd, tab->rec);
- }
- }
- 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);
-
- /*
- * No change, No update
- */
- if (!bytecmp(tab->rec, (*lptr)->rec, tab->size))
- return (FALSE);
-
- no_msg = !(tab->messages);
-
- /*
- * Lock the record before update.
- */
- stat = lock_rec(tab->fd, tab->rec);
-
- while (stat != IOGOOD && ++try <= tab->retry)
- {
- if (stat != IOGOOD && stat != IOLOCKED)
- return (do_error(stat));
-
- stat = lock_rec(tab->fd, tab->rec);
- }
-
- if (stat != IOGOOD)
- return (do_error(stat));
-
- bytecpy((*lptr)->rec, tab->rec, tab->size);
-
- stat = updrec(tab->fd, (*lptr)->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);
-
- while (stat != IOGOOD && ++try <= tab->retry)
- {
- if (stat != IOGOOD && stat != IOLOCKED)
- return (do_error(stat));
-
- 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);
- }
- }
-
-