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"
-
- /*
- * Delete the current record from the file
- */
- int delete_mode(tab, head, lptr, table, mode)
- struct _table *tab;
- struct a_line **head, **lptr;
- int table, mode;
- {
- int stat, try = 0;
- struct a_line *tmp;
-
- if (!(tab->perms & PERM_DELETE))
- {
- errmsg(ERR_NODEL);
- return (IOPERM);
- }
-
- if (*lptr == ANULL)
- return (IOGOOD);
-
- if ((*lptr)->deleted == TRUE)
- {
- errmsg(ERR_DELETE);
- return (IOGOOD);
- }
-
- if (tab->query_box && !warning(99, DEL_CONFIRM))
- return (IOGOOD);
-
- /*
- * 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)
- return (do_error(stat));
-
- stat = lock_rec(tab->fd, tab->rec);
- }
-
- if (stat != IOGOOD)
- return (do_error(stat));
-
- stat = removerec(tab->fd, tab->rec);
-
- if (do_error(stat) == IOGOOD)
- {
- /*
- * Delete from the list if deleted from
- * the file successfully
- */
- delete_list(tab, head, lptr, tab->index);
-
- /*
- * do_page_mode adjusts lptr, so save it and restore
- */
- tmp = *lptr;
-
- do_page_mode(tab, head, lptr, mode);
-
- *lptr = tmp;
-
- # ifdef NOTHERE
- if (*lptr != ANULL)
- {
- bytecpy(tab->rec, (*lptr)->rec, tab->size);
-
- /*
- * Re-find the current record
- */
- stat = findkey(tab->fd, tab->rec);
-
- /*
- * Try & Lock retry times before failing
- */
- 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));
-
- if (tab->retry != 0)
- ulock_rec(tab->fd, tab->rec);
- }
- # endif
- }
-
- return (stat);
- }
-
-
- /*
- * Remove record from the list
- *
- * We need to set the current record pointer to
- * something sensible after a deletion.
- * The current record is retained by all file managers
- * even after a delete, and so the next/prev records
- * can be obtained.
- */
- void delete_list(tab, head, lptr, idx)
- struct _table *tab;
- struct a_line **head, **lptr;
- int *idx;
- {
- struct a_line *tmp, *prv, *nxt;
- int stat = IOERROR;
- int try = 0;
-
- nxt = (*lptr)->next;
- prv = (*lptr)->prev;
- tmp = ANULL;
-
- /*
- * Check forward pointers
- */
- if (nxt != ANULL)
- {
- stat = nextrec(tab->fd, (*lptr)->rec);
-
- while ((stat = lock_rec(tab->fd, tab->rec)) != IOGOOD && ++try <= tab->retry)
- ;
-
- tmp = nxt;
- nxt->prev = prv;
- }
- else
- {
- (*idx)--;
-
- /*
- * Deleting the only record on the list !!
- */
- if (*idx < 0)
- {
- *idx = 0;
- *head = prv;
- }
- }
-
- /*
- * Check backward pointers
- */
- if (prv != ANULL)
- {
- /*
- * Only try to get the previous record
- * if there is no next record.
- * File Managers which have trouble doing
- * a prevrec (eg Oracle) will not like this.
- */
- if (stat != IOGOOD)
- {
- try = 0;
-
- stat = prevrec(tab->fd, (*lptr)->rec);
-
- while ((stat = lock_rec(tab->fd, tab->rec)) != IOGOOD && ++try <= tab->retry)
- ;
-
- tmp = prv;
- }
-
- prv->next = nxt;
- }
- else
- *head = nxt;
-
- free((char *)*lptr);
-
- /*
- * If we cannot establish a current record for
- * any reason, then set all pointers to NULL to
- * avoid any horrible situation that may arise
- * This may occur in managers such as Oracle
- * which cannot do a prevrec.
- */
- if (stat != IOGOOD && stat != IOERROR)
- {
- do_error(stat);
- *lptr = *head = tmp = ANULL;
- }
-
- if (stat == IOGOOD && tab->retry != 0)
- ulock_rec(tab->fd, tab->rec);
-
- *lptr = tmp;
- }
-
-