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

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