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 / STDSUP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  6.8 KB  |  317 lines

  1. /* ==( gensup/stdsup.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 "iodef.h"
  19. # include "sup.h"
  20. # include "screen.h"
  21.  
  22. /*
  23.  * Get back to beginning of list
  24. */
  25. void head_list(tab, head, lptr, mode)
  26. struct _table *tab;
  27. struct a_line **head, **lptr;
  28. int mode;
  29. {
  30.     if (*lptr != ANULL)
  31.         while ((*lptr)->prev != ANULL)
  32.           (*lptr) = (*lptr)->prev;
  33.  
  34.    *head = *lptr;
  35.  
  36.     if (*lptr != ANULL)
  37.        bytecpy(tab->rec, (*lptr)->rec, tab->size);
  38.  
  39.     /*
  40.      * Display the records
  41.     */
  42.    do_page_mode(tab, head, lptr, mode);
  43. }
  44.  
  45. /*
  46.  * Get to end of list, then look back to top of page
  47. */
  48. void tail_list(tab, head, lptr, mode)
  49. struct _table *tab;
  50. struct a_line **head, **lptr;
  51. int mode;
  52. {
  53.     if (*lptr != ANULL)
  54.         while ((*lptr)->next != ANULL)
  55.           (*lptr) = (*lptr)->next;
  56.  
  57.     /*
  58.      * Really the tail at this stage !!
  59.     */
  60.    *head = *lptr;
  61.  
  62.     if ((*head)->index < tab->maximum)
  63.     {
  64.         while ((*head)->prev != ANULL)
  65.             *head = (*head)->prev;
  66.     }
  67.     else
  68.     {
  69.         int i = tab->maximum;
  70.  
  71.         while (--i > 0)
  72.             (*head) = (*head)->prev;
  73.  
  74.         *(tab->index) = tab->maximum - 1;
  75.     }
  76.  
  77.     if (*lptr != ANULL)
  78.        bytecpy(tab->rec, (*lptr)->rec, tab->size);
  79.  
  80.     /*
  81.      * Display the records
  82.     */
  83.    do_page_mode(tab, head, lptr, mode);
  84. }
  85.  
  86.  
  87. /*
  88.  * Display full page of records
  89. */
  90. void do_page_mode(tab, head, lptr, mode)
  91. struct _table *tab;
  92. struct a_line **head, **lptr;
  93. int mode;
  94. {
  95.     int idx, ln, curidx, depth;
  96.     struct a_line *tmp, *cur = ANULL;
  97.  
  98.     /*
  99.      * Clear away any previous excess
  100.     */
  101.     tmp = *head;
  102.  
  103.     ln = 0;
  104.  
  105.     idx = *(tab->index);
  106.     *(tab->index) = 0;
  107.  
  108.    if (tab->tabno == 1)
  109.         depth = tab->maximum;
  110.     else
  111.         depth = tab->fn;
  112.  
  113.    while (ln < depth)
  114.     {
  115.         if (tmp == ANULL && ln >= tab->maximum)
  116.         {
  117.             ln++;
  118.             continue;
  119.         }
  120.         /*
  121.          * Set current Record.  Doesn't matter if it's NULL
  122.         */
  123.         *lptr = tmp;
  124.         if (tmp != ANULL)
  125.            bytecpy(tab->rec, (*lptr)->rec, tab->size);
  126.  
  127.       if (tab->dsp_fn != (void (*)())0) 
  128.             (*tab->dsp_fn)((*(tab->index) == idx) ? UNDERLINED : -1, (*lptr != ANULL && (*lptr)->deleted == FALSE) ? mode : CLR);
  129.  
  130.         if (tmp != ANULL)
  131.         {
  132.             /*
  133.               * Save Ptr to Current Record
  134.             */
  135.             if (*(tab->index) == idx)
  136.             {
  137.                 curidx = *(tab->index);
  138.                 cur = tmp;
  139.             }
  140.  
  141.           tmp = tmp->next;
  142.         }
  143.         ln++;
  144.         (*(tab->index))++;
  145.     }
  146.  
  147.     /*
  148.      * Don't continue if we are clearing the display
  149.     */
  150.     if (mode == CLR)
  151.         return;
  152.  
  153.     *lptr = cur;
  154.     if (*lptr != ANULL)
  155.           bytecpy(tab->rec, (*lptr)->rec, tab->size);
  156.     *(tab->index) = idx;
  157. }
  158.  
  159.  
  160. void before_input(dummy, tab, fld)
  161. FIELD *dummy;
  162. struct _table *tab;
  163. struct fldinfx *fld;
  164. {
  165.     short tmpi;
  166.     long tmpl;
  167.     unsigned long tmpy;
  168.     float tmpf;
  169.     double tmpd;
  170.  
  171.     /*
  172.     * If there is no mask then the user has selected the field but
  173.     * does not want it displayed. Therefore, we must still copy the
  174.    * value back into dummy->fbuff
  175.     * BOB Aug 9, 1990
  176.     */
  177.     int mask_len = length_mask(dummy);
  178.     int dec_len = decmasklen(dummy->fmask);
  179.     mask_len = (mask_len == 0) ? 80 : mask_len; 
  180.     dec_len = (dec_len == 0) ? 5 : dec_len; 
  181.  
  182.     switch (fld->fldtype)
  183.     {
  184.    case CHRTYP :  /* Don't copy - Use the buffer directly */
  185.     case MEMTYP :
  186.         dummy->fbuff = tab->rec + fld->fldstart;
  187.         break;
  188.    case INTTYP :
  189.         bytecpy((char *)&tmpi, tab->rec + fld->fldstart, sizeof(short));
  190.           sprintf(dummy->fbuff, "%d", tmpi);
  191.         break;
  192.    case LNGTYP :
  193.         bytecpy((char *)&tmpl, tab->rec + fld->fldstart, sizeof(long));
  194.           sprintf(dummy->fbuff, "%ld", tmpl);
  195.         break;
  196.    case FLTTYP :
  197.         bytecpy((char *)&tmpf, tab->rec + fld->fldstart, sizeof(float));
  198.         f_to_a(dummy->fbuff, tmpf, mask_len, dec_len);
  199.         break;
  200.    case DBLTYP :
  201.         bytecpy((char *)&tmpd, tab->rec + fld->fldstart, sizeof(double));
  202.         f_to_a(dummy->fbuff, tmpd, mask_len, dec_len);
  203.         break;
  204.    case DATTYP :
  205.    case TIMTYP :
  206.         switch (fld->fldlen)
  207.         {
  208.         case  6 :
  209.               strcpy(dummy->fbuff, ltocon(dstrtol(tab->rec + fld->fldstart, "YYMMDD"), dummy->fmask, 1));
  210.             break;
  211.         default :
  212.             bytecpy((char *)&tmpy, tab->rec + fld->fldstart, sizeof(long));
  213.               strcpy(dummy->fbuff, ltocon(tmpy, dummy->fmask, 1));
  214.         }
  215.         break;
  216.     }
  217. }
  218.  
  219.  
  220. void after_input(dummy, tab, fld)
  221. FIELD *dummy;
  222. struct _table *tab;
  223. struct fldinfx *fld;
  224. {
  225.     short tmpi;
  226.     unsigned long tmpy;
  227.     long tmpl;
  228.     float tmpf;
  229.     double tmpd;
  230.  
  231.     switch (fld->fldtype)
  232.     {
  233.    case CHRTYP :   /* No Need to Copy - Buffer used directly */
  234.     case MEMTYP :
  235.         break;
  236.    case INTTYP :
  237.         tmpi = atoi(dummy->fbuff);
  238.         bytecpy(tab->rec + fld->fldstart, (char *)&tmpi, sizeof(short));
  239.         break;
  240.    case LNGTYP :
  241.         tmpl = atol(dummy->fbuff);
  242.         bytecpy(tab->rec + fld->fldstart, (char *)&tmpl, sizeof(long));
  243.         break;
  244.    case FLTTYP :
  245.         tmpf = (float) atof(dummy->fbuff);
  246.         bytecpy(tab->rec + fld->fldstart, (char *)&tmpf, sizeof(float));
  247.         break;
  248.    case DBLTYP :
  249.         tmpd = atof(dummy->fbuff);
  250.         bytecpy(tab->rec + fld->fldstart, (char *)&tmpd, sizeof(double));
  251.         break;
  252.    case DATTYP :
  253.    case TIMTYP :
  254.         switch (fld->fldlen)
  255.         {
  256.         case  6 :
  257.             bytecpy(tab->rec + fld->fldstart, ltocon(dstrtol(dummy->fbuff, dummy->fmask), "YYMMDD", 1), 6);
  258.             break;
  259.         default :
  260.             tmpy = dstrtol(dummy->fbuff, dummy->fmask);
  261.             bytecpy(tab->rec + fld->fldstart, (char *)&tmpy, sizeof(long));
  262.         }
  263.         break;
  264.     }
  265. }
  266.  
  267.  
  268. void table_defaults(tab)
  269. struct _table *tab;
  270. {
  271.    tab->inp_fn    = (int (*)())0;
  272.    tab->add_fn    = (int (*)())0;
  273.    tab->chg_fn    = (int (*)())0;
  274.    tab->dsp_fn    = VNULL;
  275.    tab->key_fn    = VNULL;
  276.    tab->sel_fn    = VNULL;
  277.    tab->extra_fn  = VNULL;
  278.    tab->goto_fn   = (int (*)())0;
  279.     tab->query_box = TRUE;
  280.     tab->messages  = TRUE;
  281.     tab->auto_exit = FALSE;
  282.     tab->no_menus  = FALSE;
  283.     tab->tp        = FALSE;
  284.     tab->fn        = 50;      /* Maximum to read into 1 list */
  285. }
  286.  
  287. /*
  288.  * Compare 2 records field for field 
  289. */
  290. int cmp_rec(tab, lptr)
  291. struct _table *tab;
  292. struct a_line *lptr;
  293. {
  294.     struct fldinfx *fld = &tab->fld_off[0];
  295.  
  296.     while (fld->fldname != NULL)
  297.     {
  298.         switch (fld->fldtype)
  299.         {
  300.        case CHRTYP :    /* Char Types */
  301.         case MEMTYP :
  302.         case DATTYP :
  303.             if (strncmp(tab->rec + fld->fldstart, lptr->rec + fld->fldstart, fld->fldlen))
  304.                 return (TRUE);
  305.             break;
  306.         default :        /* Numeric Types */
  307.             if (bytecmp(tab->rec + fld->fldstart, lptr->rec + fld->fldstart, fld->fldlen))
  308.                 return (TRUE);
  309.         }
  310.  
  311.         fld++;
  312.     }
  313.  
  314.     return (FALSE);
  315. }
  316.  
  317.