home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / GENSUP / NEXT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-21  |  3.0 KB  |  134 lines

  1. /* ==( gensup/next.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   Nig   1-Jan-90                        */
  9. /* Modified  Nig   1-Jan-90                        */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13.  
  14. # include <stdio.h>
  15. # include <bench.h>
  16. # include <proc.io>
  17. # include "field.h"
  18. # include "sup.h"
  19. # include "screen.h"
  20. # include "iodef.h"
  21. # include "passwd.h"
  22.  
  23.  
  24. /*
  25.  * Read the next record forward or backward, using the
  26.  * next on the list, or from the file if at end of list
  27. */
  28. int next_mode(tab, head, lptr, table, mode)
  29. struct _table *tab;
  30. struct a_line **head, **lptr;
  31. int table, mode;
  32. {
  33.     int stat, try = 0;
  34.     struct a_line *tmp;
  35.  
  36.     /*
  37.      * Cannot read next if no 
  38.      * records to start from
  39.     */
  40.     if (*head == ANULL)
  41.         return (IOGOOD);
  42.  
  43.     if (!(tab->perms & PERM_INQUIRE))
  44.     {
  45.         errmsg(ErrNoInq);
  46.         return (IOPERM);
  47.     }
  48.  
  49.     /*
  50.      * Display current record in normal attributes
  51.      * if list is > 1 deep
  52.     */
  53.     if (tab->maximum > 1)
  54.         if (tab->dsp_fn != (void (*)())0) 
  55.             (*tab->dsp_fn)(REVVID, mode);
  56.  
  57.     /*
  58.      * Make sure we are searching on the right key
  59.     */
  60.    selectinx(tab->fd, *(tab->keynum), *(tab->keymatch), tab->retry);
  61.  
  62.     tab->mode = K_DOWN;
  63.  
  64.     no_msg = !(tab->messages);
  65.  
  66.     stat = nextrec(tab->fd, tab->rec);
  67.  
  68.     /*
  69.      * Try & Lock retry times before failing
  70.      * If No locking is specified, the lock
  71.      * will just re-establish the current record
  72.     */
  73.     if (stat != IOEOF && stat != IOGOOD && stat != IOLOCKED)
  74.     {
  75.         if (tab->dsp_fn != (void (*)())0) 
  76.             (*tab->dsp_fn)(UNDERLINED, mode);
  77.         return (do_error(stat));
  78.     }
  79.  
  80.     ulock_rec(tab->fd, tab->rec);
  81.  
  82.     if (stat != IOGOOD)
  83.     {
  84.         /*
  85.          * Restore current value in case the I/O manager
  86.          * updates it inadvertently.
  87.         */
  88.         bytecpy(tab->rec, (*lptr)->rec, tab->size);
  89.         if (tab->dsp_fn != (void (*)())0) 
  90.             (*tab->dsp_fn)(UNDERLINED, mode);
  91.         return (do_error(stat));
  92.     }
  93.  
  94.     if ((*lptr)->next == ANULL)
  95.     {
  96.         *(tab->seq) = ASCENDING;
  97.         tmp = *head;
  98.          new_record(tab, head, lptr);
  99.         *head = tmp;
  100.     }
  101.     else
  102.     {
  103.         *lptr = (*lptr)->next;
  104.  
  105.         /*
  106.          * Old Way !!
  107.         bytecmp(tab->rec, (*lptr)->rec, tab->size))
  108.         */
  109.         if (cmp_rec(tab, *lptr))
  110.         {
  111.             if (tab->messages)
  112.                 errmsg(FetchErr);
  113.  
  114.             /*
  115.              * Update the list with the current record.
  116.              *
  117.              * It would be nice if we could retain the 
  118.              * order which appears on the screen
  119.              * until the user scrolls out of sequence
  120.              * records off the screen, or re-seeks for
  121.              * a new block of records, but this is not
  122.              * possible in case we are working with a 
  123.              * block of duplicate keys.
  124.             */
  125.             bytecpy((*lptr)->rec, tab->rec, tab->size);
  126.         }
  127.     }
  128.  
  129.     reorder_mode(tab, head, lptr, FORWARD);
  130.  
  131.     return (stat);
  132. }
  133.  
  134.