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

  1. /**
  2. *
  3. * Name        wncreate -- Allocate and create a window structure.
  4. *
  5. * Synopsis    presult = wncreate(height,width,attr);
  6. *
  7. *        BWINDOW *presult  Pointer to newly-created BWINDOW
  8. *                  structure, or NIL if failure.
  9. *        int height      Number of rows    in data area
  10. *        int width      Number of columns in data area
  11. *        int attr      Default attribute in data area
  12. *
  13. * Description    This function allocates space for a window structure and
  14. *        fills it with default values.  This includes allocating
  15. *        and initializing the window's data area with blanks
  16. *        (' ') having the specified attribute.
  17. *
  18. *        An error occurs if the window dimensions exceed maximum
  19. *        screen dimensions or if the memory allocation fails.
  20. *
  21. *        Use WNDSTROY to discard the BWINDOW structure and
  22. *        related internal data structures.
  23. *
  24. * Returns    presult       Pointer to newly-created BWINDOW
  25. *                  structure, or NIL if failure.
  26. *        b_wnerr        Possible values:
  27. *                  (No change)      Success.
  28. *                  WN_ILL_DIM      Invalid dimensions.
  29. *                  WN_NO_MEMORY      Insufficient memory.
  30. *
  31. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  32. *
  33. **/
  34.  
  35. #include <string.h>
  36.  
  37. #include <bwindow.h>
  38.  
  39. #if LAT300
  40. #include <stdlib.h>
  41. #endif
  42. #if MSC300
  43. #include <malloc.h>
  44. #endif
  45.  
  46. int b_wnerr = WN_NO_ERROR;          /* Most recent error          */
  47.                       /* (WN_NO_ERROR if none).       */
  48.  
  49. BWINDOW *wncreate(height,width,attr)
  50. int height,width,attr;
  51. {
  52.     BWINDOW *pwin;
  53.     CELL    *ptr;
  54.     int     area,i;
  55.  
  56.     if (   utrange(height,1,PC_BIG_ROWS)   /* Validate dimensions.    */
  57.     || utrange(width, 1,PC_COLS))
  58.     {
  59.     wnerror(WN_ILL_DIM);
  60.     return NIL;
  61.     }
  62.  
  63.     if ((pwin = utalloc(BWINDOW)) == NIL)  /* Allocate space for the  */
  64.     {                       /* structure.          */
  65.     wnerror(WN_NO_MEMORY);
  66.     return NIL;
  67.     }
  68.  
  69.     pwin->img.dim.h = height;
  70.     pwin->img.dim.w = width;
  71.     if (wnmkimg(&pwin->img) == NIL)   /* Allocate space for memory    */
  72.     {                      /* image.               */
  73.  
  74.     free((char *) pwin);          /* Clean up after failure.      */
  75.     return NIL;
  76.     }
  77.  
  78.     area = height * width;
  79.     for (ptr = pwin->img.pdata, i = 0; i < area; i++)
  80.     {
  81.     ptr  ->ch   = ' ';
  82.     ptr++->attr = (char) attr;
  83.     }
  84.  
  85.     /* Initialize fields to default values (except where 0 is an      */
  86.     /* acceptable default value).                      */
  87.  
  88.     pwin->attr            = attr;
  89.     pwin->where_shown.dev   = ABSENT; /* Not currently shown.          */
  90.     pwin->cur_type.high     = 12;     /* Default cursor type.          */
  91.     pwin->cur_type.low        = 13;
  92.     pwin->options.removable = 1;
  93.  
  94.     strcpy(pwin->signature,BWIN_SIGN);/* Distinctive signature.       */
  95.  
  96.     return pwin;              /* Success.              */
  97. }
  98.