home *** CD-ROM | disk | FTP | other *** search
- /* ==( gensup/next.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 "sup.h"
- # include "screen.h"
- # include "iodef.h"
- # include "passwd.h"
-
-
- /*
- * Read the next record forward or backward, using the
- * next on the list, or from the file if at end of list
- */
- int next_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;
-
- /*
- * Cannot read next if no
- * records to start from
- */
- if (*head == ANULL)
- return (IOGOOD);
-
- if (!(tab->perms & PERM_INQUIRE))
- {
- errmsg(ErrNoInq);
- return (IOPERM);
- }
-
- /*
- * Display current record in normal attributes
- * if list is > 1 deep
- */
- if (tab->maximum > 1)
- if (tab->dsp_fn != (void (*)())0)
- (*tab->dsp_fn)(REVVID, mode);
-
- /*
- * Make sure we are searching on the right key
- */
- selectinx(tab->fd, *(tab->keynum), *(tab->keymatch), tab->retry);
-
- tab->mode = K_DOWN;
-
- no_msg = !(tab->messages);
-
- stat = nextrec(tab->fd, tab->rec);
-
- /*
- * Try & Lock retry times before failing
- * If No locking is specified, the lock
- * will just re-establish the current record
- */
- if (stat != IOEOF && stat != IOGOOD && stat != IOLOCKED)
- {
- if (tab->dsp_fn != (void (*)())0)
- (*tab->dsp_fn)(UNDERLINED, mode);
- return (do_error(stat));
- }
-
- ulock_rec(tab->fd, tab->rec);
-
- if (stat != IOGOOD)
- {
- /*
- * Restore current value in case the I/O manager
- * updates it inadvertently.
- */
- bytecpy(tab->rec, (*lptr)->rec, tab->size);
- if (tab->dsp_fn != (void (*)())0)
- (*tab->dsp_fn)(UNDERLINED, mode);
- return (do_error(stat));
- }
-
- if ((*lptr)->next == ANULL)
- {
- *(tab->seq) = ASCENDING;
- tmp = *head;
- new_record(tab, head, lptr);
- *head = tmp;
- }
- else
- {
- *lptr = (*lptr)->next;
-
- /*
- * Old Way !!
- bytecmp(tab->rec, (*lptr)->rec, tab->size))
- */
- if (cmp_rec(tab, *lptr))
- {
- if (tab->messages)
- errmsg(FetchErr);
-
- /*
- * Update the list with the current record.
- *
- * It would be nice if we could retain the
- * order which appears on the screen
- * until the user scrolls out of sequence
- * records off the screen, or re-seeks for
- * a new block of records, but this is not
- * possible in case we are working with a
- * block of duplicate keys.
- */
- bytecpy((*lptr)->rec, tab->rec, tab->size);
- }
- }
-
- reorder_mode(tab, head, lptr, FORWARD);
-
- return (stat);
- }
-
-