Advertisement
Guest User

Untitled

a guest
Nov 18th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5.  
  6. typedef enum
  7. {
  8.     SML_ETYPE_NONE                = (0x000000),
  9.     SML_ETYPE_WINDOW              = (0x000001),
  10.     SML_ETYPE_WIDGET_FOCUSABLE    = (0x000002),
  11.     SML_ETYPE_WIDGET_NONFOCUSABLE = (0x000003),
  12.     SML_ETYPE_TIME                = (0x000004),
  13.     SML_ETYPE_GRAPHICS            = (0x000005),
  14.     SML_ETYPE_TEXTOBJ             = (0x000006),
  15.     SML_ETYPE_GRAPHRULES          = (0x000007),
  16.     SML_ETYPE_SHARED              = (0x000008)
  17. } SmlElemType;
  18.  
  19. #define SML_GENERICDATASIZE  (1024) /* bytes */
  20.  
  21. typedef uint32_t SmlErrors; // simplified.
  22. typedef uint32_t SmlIndex;
  23.  
  24. typedef struct
  25. {
  26.     char            data[SML_GENERICDATASIZE];
  27. } SmlGenericData;
  28.  
  29. #define SML_THEMEBLOCK_SIZE (0x20)
  30.  
  31. typedef struct
  32. {
  33.     SmlIndex     sprite[SML_THEMEBLOCK_SIZE];
  34.     SmlIndex     theme [SML_THEMEBLOCK_SIZE];
  35. } SmlWidgetData;
  36.  
  37. typedef union
  38. {
  39.     SmlGenericData  gen;
  40.     SmlWidgetData   wdg;
  41. } SmlElemData;
  42.  
  43. typedef struct
  44. {
  45.     SmlElemType    type;
  46.     SmlElemData    data;
  47. } SmlElement;
  48.  
  49. typedef struct
  50. {
  51.     SmlElement   * elem;
  52.     uint32_t       elemcount;
  53. } Warehouse;
  54.  
  55. Warehouse warehouse;
  56.  
  57. SmlErrors SmlWhsAdd(SmlElement element, SmlIndex * index)
  58. {
  59.     //SML_CHECKPTR(index); Just checks if null.
  60.  
  61.     SmlElement * ptrold = warehouse.elem;
  62.  
  63.     warehouse.elem      = realloc(warehouse.elem,
  64.                                   (++warehouse.elemcount) * sizeof(SmlElement));
  65.     if (!(warehouse.elem))
  66.     {
  67.         warehouse.elem = ptrold;
  68.         *index         = 0;
  69.         warehouse.elemcount--;
  70.         return 1;//SML_ERR_BADALLOC;
  71.     }
  72.  
  73.     warehouse.elem[warehouse.elemcount - 1] = element;
  74.  
  75.     *index = (warehouse.elemcount - 1);
  76.  
  77.     return 0;//SML_ERR_SUCCESS;
  78. }
  79.  
  80.  
  81.  
  82. int main(void)
  83. {
  84.     // Inits in another module
  85.     warehouse.elemcount = 0;
  86.     warehouse.elem = NULL;
  87.  
  88.     SmlElement dummy;
  89.     dummy.type = SML_ETYPE_WINDOW;
  90.  
  91.     SmlIndex window;
  92.     SmlWhsAdd(dummy, &window);
  93.     SmlElement sprite;
  94.     sprite.type = SML_ETYPE_GRAPHICS;
  95.  
  96.     SmlWhsAdd(sprite, &(warehouse.elem[window].data.wdg.sprite[0]));
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement