home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / WNPGADD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.6 KB  |  96 lines

  1. /**
  2. *
  3. * Name        wnpgadd -- Add window to linked list of windows
  4. *               displayed on a device & display page.
  5. *
  6. * Synopsis    presult = wnpgadd(pwindow,dev,page);
  7. *
  8. *        WIN_NODE *presult Pointer to newly-created WIN_NODE
  9. *                  structure, or NIL if failure.
  10. *        BWINDOW  *pwindow Window to add to list
  11. *        int     dev      Video display device (COLOR or MONO)
  12. *        int     page      Video display page
  13. *
  14. * Description    This function adds a window to the linked list which
  15. *        governs the windows displayed on a given device and
  16. *        video page.  The window is stored as the topmost (i.e.,
  17. *        most recently displayed).
  18. *
  19. *        An error occurs if the window structure is invalid, if
  20. *        the device or page are illegal, or if insufficient
  21. *        memory is available for the window node.
  22. *
  23. * Returns    presult       Pointer to newly-created WIN_NODE
  24. *                  structure, or NIL if failure.
  25. *        b_wnlist[][]      Altered linked list if success.
  26. *        pwindow->pnode      Pointer to newly-created WIN_NODE
  27. *                  structure, or NIL if failure.
  28. *        b_wnerr       Possible values:
  29. *                  (No change)      Success.
  30. *                  WN_BAD_WIN      *pwin is invalid.
  31. *                  WN_BAD_DEV      Unknown device.
  32. *                  WN_NO_MEMORY      Insufficient memory.
  33. *                  WN_BAD_PAGE      Internal error.
  34. *
  35. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  36. *
  37. **/
  38.  
  39. #include <string.h>
  40.  
  41. #include <bwindow.h>
  42.  
  43. #if MSC300
  44. #include <malloc.h>
  45. #else
  46. #include <stdlib.h>
  47. #endif
  48.  
  49.                       /* List of windows displayed on */
  50.                       /* each page (NIL if none).     */
  51. WIN_NODE *(b_wnlist[MAX_DEVICES][MAX_PAGES]) = {0};
  52.  
  53. WIN_NODE *wnpgadd(pwindow,dev,page)
  54. BWINDOW *pwindow;
  55. int dev,page;
  56. {
  57.     WIN_NODE *pnew_node;
  58.  
  59.     if (wnvalwin(pwindow) == NIL)     /* Validate window structure.   */
  60.     {
  61.     wnerror(WN_BAD_WIN);
  62.     return NIL;
  63.     }
  64.  
  65.     if (dev != MONO && dev != COLOR)  /* Make sure dev & page are     */
  66.     {                      /* within range of array          */
  67.     wnerror(WN_BAD_DEV);          /* subscripts.              */
  68.     return NIL;
  69.     }
  70.     if (page < 0 || page >= MAX_PAGES)
  71.     {
  72.     wnerror(WN_BAD_PAGE);
  73.     return NIL;
  74.     }
  75.  
  76.                       /* Create new node.          */
  77.     if ((pnew_node = utalloc(WIN_NODE)) == NIL)
  78.     {
  79.     wnerror(WN_NO_MEMORY);
  80.     return NIL;
  81.     }
  82.  
  83.     strcpy(pnew_node->signature,BNODE_SIGN); /* Distinctive signature */
  84.  
  85.     pnew_node->pwin  = pwindow;          /* Attach to window.     */
  86.  
  87.     pnew_node->below = b_wnlist[dev][page];  /* Attach to former      */
  88.                          /* topmost window.       */
  89.  
  90.     if (pnew_node->below != NIL)
  91.     pnew_node->below->above = pnew_node; /* Attach former topmost */
  92.                          /* to this window.       */
  93.  
  94.     return b_wnlist[dev][page] = pnew_node;  /* New head of list.     */
  95. }
  96.