home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / GENSUP / REORDER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  1.1 KB  |  65 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.  
  9. /*
  10.  * Re-order the list of records, depending on the
  11.  * direction we are adding additional records from
  12. */
  13. void reorder_mode(tab, head, lptr, direction)
  14. struct _table *tab;
  15. struct a_line **head, **lptr;
  16. int direction;
  17. {
  18.     struct a_line *top, *bot, *tmp;
  19.  
  20.     /*
  21.      * Find the End of the list
  22.     */
  23.     for (bot = *head;  bot != ANULL;  bot = bot->next)
  24.         if (bot->next == ANULL)
  25.             break;
  26.  
  27.     top = *head;
  28.  
  29.     if (direction == FORWARD)
  30.         tmp = *head;
  31.     else
  32.         tmp = bot;
  33.  
  34.     /*
  35.      * If there are > 1 on the list
  36.      * then let's shuffle up
  37.     */
  38.     if (bot != *head)
  39.     {
  40.         bot->next = top;
  41.         top->prev = bot;
  42.  
  43.         if (direction == BACKWARD)
  44.         {
  45.             bot->prev->next = ANULL;
  46.             bot->prev       = ANULL;
  47.             *head = tmp = bot;
  48.         }
  49.         else  /* forward */
  50.         {
  51.             *head = (*head)->next;
  52.             top->next->prev = ANULL;
  53.             top->next       = ANULL;
  54.         }
  55.     }
  56.  
  57.     /*
  58.      * Add the new one on to the freed up slot in the list
  59.     */
  60.    bytecpy(tmp->rec, tab->rec, tab->size);
  61.  
  62.    *lptr = tmp;
  63. }
  64.  
  65.