home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / private / _addwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  2.1 KB  |  104 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4. #define    CURSES_LIBRARY    1
  5. #include <curses.h>
  6.  
  7. #ifdef    REGISTERWINDOWS
  8. #ifdef PDCDEBUG
  9. char *rcsid__addwin = "$Header: C:\CURSES\private\RCS\_addwin.c 2.1 1993/06/18 20:23:06 MH Rel MH $";
  10. #endif
  11.  
  12.  
  13.  
  14.  
  15. /*man-start*********************************************************************
  16.  
  17.   PDC_addwin()    - adds window
  18.  
  19.   PDCurses Description:
  20.      This routine adds the passed window pointer after the specified
  21.      window.     If the specified window is NULL, then the passed
  22.      window pointer is inserted first in the list.
  23.  
  24.      If the 'after' window is not on the visible list, then 'win'
  25.      will be added to the end of the list.
  26.  
  27.   PDCurses Return Value:
  28.      This routine will return OK upon success and otherwise ERR will be
  29.      returned.
  30.  
  31.   PDCurses Errors:
  32.      An error will occur if we are unable to allocate a new WINDS
  33.      structure.
  34.  
  35.   Portability:
  36.      PDCurses    int    PDC_addwin( WINDOW* win, WINDOW* after );
  37.  
  38. **man-end**********************************************************************/
  39.  
  40. int    _addwin(WINDOW *win, WINDOW *after)
  41. {
  42. extern    void*    (*mallc)( size_t );
  43. extern    void*    (*callc)( size_t, size_t );
  44. extern    void    (*fre)( void* );
  45.  
  46.     WINDS  *root = _cursvar.visible;
  47.     WINDS  *wlst = PDC_findwin(after);
  48.     WINDS  *new  = (*mallc)(sizeof(WINDS));
  49.  
  50. #ifdef PDCDEBUG
  51.     if (trace_on) PDC_debug("PDC_addwin() - called\n");
  52. #endif
  53.  
  54.     if (new == (WINDOW *)NULL)
  55.         return( ERR );
  56.  
  57.     PDC_rmwin(win);
  58.     memset(new, 0, sizeof(WINDS));
  59.     new->w = win;
  60.     if (wlst == (WINDS *)NULL)
  61.     {
  62.         if (root == (WINDS *)NULL)
  63.             _cursvar.visible = new;
  64.         else
  65.         {
  66.             root->tail->next = new;
  67.             new->prev = root->tail;
  68.             root->tail = new;
  69.         }
  70.     }
  71.     else
  72.     {
  73.         if (root->next == NULL)
  74.         {
  75.             root->next = new;
  76.             new->prev = root;
  77.         }
  78.         else
  79.         if (wlst == root->tail)
  80.         {
  81.             root->tail->next = new;
  82.             new->prev = root->tail;
  83.             root->tail = new;
  84.         }
  85.         else
  86.         {
  87.             new->prev = wlst;
  88.             new->next = wlst->next;
  89.             if (wlst->next == NULL)
  90.             {
  91.                 wlst->next = new;
  92.                 root->tail = new;
  93.             }
  94.             else
  95.             {
  96.                 wlst->next->prev = new;
  97.                 wlst->next = new;
  98.             }
  99.         }
  100.     }
  101.     return( OK );
  102. }
  103. #endif
  104.