home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / GENSUP / NEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  2.3 KB  |  119 lines

  1. # include <stdio.h>
  2. # include <bench.h>
  3. # include <proc.io>
  4. # include "field.h"
  5. # include "sup.h"
  6. # include "screen.h"
  7. # include "iodef.h"
  8. # include "passwd.h"
  9.  
  10.  
  11. /*
  12.  * Read the next record forward or backward, using the
  13.  * next on the list, or from the file if at end of list
  14. */
  15. int next_mode(tab, head, lptr, table, mode)
  16. struct _table *tab;
  17. struct a_line **head, **lptr;
  18. int table, mode;
  19. {
  20.     int stat, try = 0;
  21.  
  22.     /*
  23.      * Cannot read next if no 
  24.      * records to start from
  25.     */
  26.     if (*head == ANULL)
  27.         return (IOGOOD);
  28.  
  29.     if (!(tab->perms & PERM_INQUIRE))
  30.     {
  31.         errmsg(ERR_NOINQ);
  32.         return (IOPERM);
  33.     }
  34.  
  35.     /*
  36.      * Display current record in normal attributes
  37.      * if list is > 1 deep
  38.     */
  39.     if (tab->maximum > 1)
  40.         if (tab->dsp_fn != (void (*)())0) 
  41.             (*tab->dsp_fn)(REVVID, mode);
  42.  
  43.     /*
  44.      * Make sure we are searching on the right key
  45.     */
  46.    selectinx(tab->fd, *(tab->keynum), *(tab->keymatch), tab->retry);
  47.  
  48.     tab->mode = K_DOWN;
  49.  
  50.     no_msg = !(tab->messages);
  51.  
  52.     stat = nextrec(tab->fd, tab->rec);
  53.  
  54.     /*
  55.      * Try & Lock retry times before failing
  56.      * If No locking is specified, the lock
  57.      * will just re-estgablish the current record
  58.     */
  59.     if (stat != IOEOF)
  60.         while (stat != IOGOOD && ++try <= tab->retry)
  61.         {
  62.             if (stat != IOGOOD && stat != IOLOCKED)
  63.             {
  64.                 if (tab->dsp_fn != (void (*)())0) 
  65.                     (*tab->dsp_fn)(UNDERLINED, mode);
  66.                 return (do_error(stat));
  67.             }
  68.  
  69.             stat = lock_rec(tab->fd, tab->rec); 
  70.         }
  71.     else
  72.         while (lock_rec(tab->fd, tab->rec) != IOGOOD && ++try <= tab->retry);
  73.  
  74.     if (tab->retry != 0)
  75.         ulock_rec(tab->fd, tab->rec);
  76.  
  77.     if (stat != IOGOOD)
  78.     {
  79.         if (tab->dsp_fn != (void (*)())0) 
  80.             (*tab->dsp_fn)(UNDERLINED, mode);
  81.         return (do_error(stat));
  82.     }
  83.  
  84.     if (*(tab->index) == tab->maximum - 1)
  85.     {
  86.         if (tab->maximum > 1)
  87.         {
  88.             reorder_mode(tab, head, lptr, FORWARD);
  89.             do_page_mode(tab, head, lptr, mode);
  90.         }
  91.         /*
  92.          * Display current record hi-lighted
  93.         */
  94.         else if (tab->dsp_fn != (void (*)())0) 
  95.               (*tab->dsp_fn)(UNDERLINED, mode);
  96.     }
  97.     else
  98.     {
  99.         if ((*lptr)->next == ANULL)
  100.           new_line(tab, head, lptr);
  101.         else
  102.         {
  103.             *lptr = (*lptr)->next;
  104.             (*(tab->index))++;
  105.         }
  106.  
  107.         /*
  108.          * Display current record hi-lighted
  109.         */
  110.         if (tab->dsp_fn != (void (*)())0) 
  111.               (*tab->dsp_fn)(UNDERLINED, mode);
  112.     }
  113.  
  114.    bytecpy((*lptr)->rec, tab->rec, tab->size);
  115.  
  116.     return (stat);
  117. }
  118.  
  119.