Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7a986b894a
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 180 lines (152 sloc) 5.607 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
/* rgdata.h: JSON data structure header
for RemGlk, remote-procedure-call implementation of the Glk API.
Designed by Andrew Plotkin <erkyrath@eblong.com>
http://eblong.com/zarf/glk/
*/

/* There are two levels of data structures here. The high-level ones
(data_event_t, data_update_t, data_window_t, etc) are built and accepted
by the other parts of the library.

The low-level structure, data_raw_t, is defined and used only inside
rgdata.c. It maps directly to and from JSON objects.

Every data structure has a print() method, which sends it to stdout
as a JSON structure.
*/

typedef enum DTag_enum {
    dtag_Unknown = 0,
    dtag_Init = 1,
    dtag_Refresh = 2,
    dtag_Line = 2,
    dtag_Char = 3,
    dtag_Arrange = 4,
    dtag_Hyperlink = 5,
    dtag_SpecialResponse = 6,
} DTag;

/* gen_list_t: A boring little structure which holds a dynamic list of
void pointers. Several of the high-level data objects use these
to store lists of other high-level data objects. (You embed a
gen_list_t directly, rather than a pointer to it.) */
typedef struct gen_list_struct {
    void **list;
    int count;
    int allocsize;
} gen_list_t;

typedef struct data_event_struct data_event_t;
typedef struct data_update_struct data_update_t;
typedef struct data_window_struct data_window_t;
typedef struct data_input_struct data_input_t;
typedef struct data_line_struct data_line_t;
typedef struct data_span_struct data_span_t;

/* data_metrics_t: Defines the display metrics. */
struct data_metrics_struct {
    glui32 width, height;
    glui32 outspacingx, outspacingy;
    glui32 inspacingx, inspacingy;
    glui32 gridcharwidth, gridcharheight;
    glui32 gridmarginx, gridmarginy;
    glui32 buffercharwidth, buffercharheight;
    glui32 buffermarginx, buffermarginy;
};

/* data_event_t: Represents an input event (either the initial setup event,
or user input). */
struct data_event_struct {
    DTag dtag;
    glsi32 gen;
    glui32 window;
    glui32 charvalue;
    glui32 *linevalue;
    glui32 linelen;
    glui32 terminator;
    data_metrics_t *metrics;
};

/* data_update_t: Represents a complete output update, including what
happened to all the windows this cycle. */
struct data_update_struct {
    glsi32 gen;
    int usewindows;
    gen_list_t windows; /* data_window_t */
    gen_list_t contents; /* data_content_t */
    int useinputs;
    gen_list_t inputs; /* data_event_t */
    data_specialreq_t *specialreq;
    int disable;
};

/* data_window_t: Represents one window, either newly created, resized, or
repositioned. */
struct data_window_struct {
    glui32 window;
    glui32 type;
    glui32 rock;
    grect_t size;
    glui32 gridwidth, gridheight;
};

/* data_input_t: Represents the input request of one window. */
struct data_input_struct {
    glui32 window;
    glsi32 evtype;
    glsi32 gen;
    glui32 *initstr;
    glui32 initlen;
    glui32 maxlen;
};

/* data_content_t: Represents the output changes of one window (text
updates). */
struct data_content_struct {
    glui32 window;
    glui32 type;
    gen_list_t lines; /* data_line_t */
    int clear;
};

/* data_line_t: One line of text in a data_content_t. This is used for
both grid windows and buffer windows. (In a buffer window, a "line"
is a complete paragraph.) */
struct data_line_struct {
    glui32 linenum;
    int append;
    data_span_t *spans;
    int count;
    int allocsize;
};

/* data_span_t: One style-span of text in a data_line_t. */
struct data_span_struct {
    short style;
    glui32 *str; /* This will always be a reference to existing data.
Do not free. */
    long len;
};

/* data_specialreq_t: A special input request. */
struct data_specialreq_struct {
    glui32 filemode;
    glui32 filetype;
    char *gameid; /* may be null */
};

extern void gli_initialize_datainput(void);

extern void print_ustring_json(glui32 *buf, glui32 len, FILE *fl);
extern void print_string_json(char *buf, FILE *fl);

extern void gen_list_init(gen_list_t *list);
extern void gen_list_free(gen_list_t *list);
extern void gen_list_append(gen_list_t *list, void *val);

extern data_metrics_t *data_metrics_alloc(int width, int height);
extern void data_metrics_free(data_metrics_t *metrics);
extern void data_metrics_print(data_metrics_t *metrics);

extern data_event_t *data_event_read(void);
extern void data_event_free(data_event_t *data);
extern void data_event_print(data_event_t *data);

extern data_update_t *data_update_alloc(void);
extern void data_update_free(data_update_t *data);
extern void data_update_print(data_update_t *data);

extern data_window_t *data_window_alloc(glui32 window, glui32 type, glui32 rock);
extern void data_window_free(data_window_t *data);
extern void data_window_print(data_window_t *data);

extern data_input_t *data_input_alloc(glui32 window, glui32 evtype);
extern void data_input_free(data_input_t *data);
extern void data_input_print(data_input_t *data);

extern data_content_t *data_content_alloc(glui32 window, glui32 type);
extern void data_content_free(data_content_t *data);
extern void data_content_print(data_content_t *data);

extern data_line_t *data_line_alloc(void);
extern void data_line_free(data_line_t *data);
extern void data_line_add_span(data_line_t *data, short style, glui32 *str, long len);
extern void data_line_print(data_line_t *data, glui32 wintype);

extern data_specialreq_t *data_specialreq_alloc(glui32 filemode, glui32 filetype);
extern void data_specialreq_free(data_specialreq_t *data);
extern void data_specialreq_print(data_specialreq_t *data);

Something went wrong with that request. Please try again.