~ubuntu-branches/ubuntu/trusty/wayland/trusty

« back to all changes in this revision

Viewing changes to src/scanner.c

  • Committer: Package Import Robot
  • Author(s): Hector Oron, Timo Aaltonen, Hector Oron
  • Date: 2013-10-11 11:23:38 UTC
  • mfrom: (1.1.15) (0.4.2 sid)
  • Revision ID: package-import@ubuntu.com-20131011112338-2jg0z6ncpm9qnots
Tags: 1.3.0-1
[ Timo Aaltonen ]
* control: Bump the libwayland0 C/R to (<< 1.1.0) so that it covers
  the ubuntu version too, and add it to -cursor.

[ Hector Oron ]
* New upstream stable release (1.3.0).
* Add myself to Uploaders.
* Switch to Debian source format 3.0 quilt.
* d/libwayland-dev.install:
  - install wayland documentation

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
usage(int ret)
35
35
{
36
36
        fprintf(stderr, "usage: ./scanner [client-header|server-header|code]\n");
 
37
        fprintf(stderr, "\n");
 
38
        fprintf(stderr, "Converts XML protocol descriptions supplied on "
 
39
                        "stdin to client headers,\n"
 
40
                        "server headers, or protocol marshalling code.\n");
37
41
        exit(ret);
38
42
}
39
43
 
127
131
        unsigned int character_data_length;
128
132
};
129
133
 
 
134
static void *
 
135
fail_on_null(void *p)
 
136
{
 
137
        if (p == NULL) {
 
138
                fprintf(stderr, "wayland-scanner: out of memory\n");
 
139
                exit(EXIT_FAILURE);
 
140
        }
 
141
 
 
142
        return p;
 
143
}
 
144
 
 
145
static void *
 
146
xmalloc(size_t s)
 
147
{
 
148
        return fail_on_null(malloc(s));
 
149
}
 
150
 
 
151
static char *
 
152
xstrdup(const char *s)
 
153
{
 
154
        return fail_on_null(strdup(s));
 
155
}
 
156
 
130
157
static char *
131
158
uppercase_dup(const char *src)
132
159
{
133
160
        char *u;
134
161
        int i;
135
162
 
136
 
        u = strdup(src);
 
163
        u = xstrdup(src);
137
164
        for (i = 0; u[i]; i++)
138
165
                u[i] = toupper(u[i]);
139
166
        u[i] = '\0';
292
319
                if (name == NULL)
293
320
                        fail(ctx, "no protocol name given");
294
321
 
295
 
                ctx->protocol->name = strdup(name);
 
322
                ctx->protocol->name = xstrdup(name);
296
323
                ctx->protocol->uppercase_name = uppercase_dup(name);
297
324
                ctx->protocol->description = NULL;
298
325
        } else if (strcmp(element_name, "copyright") == 0) {
304
331
                if (version == 0)
305
332
                        fail(ctx, "no interface version given");
306
333
 
307
 
                interface = malloc(sizeof *interface);
308
 
                interface->name = strdup(name);
 
334
                interface = xmalloc(sizeof *interface);
 
335
                interface->name = xstrdup(name);
309
336
                interface->uppercase_name = uppercase_dup(name);
310
337
                interface->version = version;
311
338
                interface->description = NULL;
321
348
                if (name == NULL)
322
349
                        fail(ctx, "no request name given");
323
350
 
324
 
                message = malloc(sizeof *message);
325
 
                message->name = strdup(name);
 
351
                message = xmalloc(sizeof *message);
 
352
                message->name = xstrdup(name);
326
353
                message->uppercase_name = uppercase_dup(name);
327
354
                wl_list_init(&message->arg_list);
328
355
                message->arg_count = 0;
359
386
                if (name == NULL)
360
387
                        fail(ctx, "no argument name given");
361
388
 
362
 
                arg = malloc(sizeof *arg);
363
 
                arg->name = strdup(name);
 
389
                arg = xmalloc(sizeof *arg);
 
390
                arg->name = xstrdup(name);
364
391
 
365
392
                if (strcmp(type, "int") == 0)
366
393
                        arg->type = INT;
386
413
                case NEW_ID:
387
414
                case OBJECT:
388
415
                        if (interface_name)
389
 
                                arg->interface_name = strdup(interface_name);
 
416
                                arg->interface_name = xstrdup(interface_name);
390
417
                        else
391
418
                                arg->interface_name = NULL;
392
419
                        break;
408
435
 
409
436
                arg->summary = NULL;
410
437
                if (summary)
411
 
                        arg->summary = strdup(summary);
 
438
                        arg->summary = xstrdup(summary);
412
439
 
413
440
                wl_list_insert(ctx->message->arg_list.prev, &arg->link);
414
441
                ctx->message->arg_count++;
416
443
                if (name == NULL)
417
444
                        fail(ctx, "no enum name given");
418
445
 
419
 
                enumeration = malloc(sizeof *enumeration);
420
 
                enumeration->name = strdup(name);
 
446
                enumeration = xmalloc(sizeof *enumeration);
 
447
                enumeration->name = xstrdup(name);
421
448
                enumeration->uppercase_name = uppercase_dup(name);
422
449
                enumeration->description = NULL;
423
450
                wl_list_init(&enumeration->entry_list);
430
457
                if (name == NULL)
431
458
                        fail(ctx, "no entry name given");
432
459
 
433
 
                entry = malloc(sizeof *entry);
434
 
                entry->name = strdup(name);
 
460
                entry = xmalloc(sizeof *entry);
 
461
                entry->name = xstrdup(name);
435
462
                entry->uppercase_name = uppercase_dup(name);
436
 
                entry->value = strdup(value);
 
463
                entry->value = xstrdup(value);
437
464
                if (summary)
438
 
                        entry->summary = strdup(summary);
 
465
                        entry->summary = xstrdup(summary);
439
466
                else
440
467
                        entry->summary = NULL;
441
468
                wl_list_insert(ctx->enumeration->entry_list.prev,
444
471
                if (summary == NULL)
445
472
                        fail(ctx, "description without summary");
446
473
 
447
 
                description = malloc(sizeof *description);
448
 
                description->summary = strdup(summary);
 
474
                description = xmalloc(sizeof *description);
 
475
                description->summary = xstrdup(summary);
449
476
 
450
477
                if (ctx->message)
451
478
                        ctx->message->description = description;
579
606
                exit(EXIT_FAILURE);
580
607
        }
581
608
 
582
 
        if (!has_destructor && strcmp(interface->name, "wl_display") != 0)
 
609
        if (!has_destroy && strcmp(interface->name, "wl_display") != 0)
583
610
                printf("static inline void\n"
584
611
                       "%s_destroy(struct %s *%s)\n"
585
612
                       "{\n"
829
856
                        else if (is_interface && a->type == NEW_ID && a->interface_name == NULL)
830
857
                                printf("const char *interface, uint32_t version, uint32_t ");
831
858
                        else if (!is_interface && a->type == OBJECT && a->interface_name == NULL)
832
 
                                printf("struct wl_object *");
 
859
                                printf("void *");
833
860
 
834
861
                        else if (!is_interface && a->type == NEW_ID)
835
862
                                printf("struct %s *", a->interface_name);
1033
1060
 
1034
1061
        wl_list_for_each(m, message_list, link) {
1035
1062
                printf("\t{ \"%s\", \"", m->name);
 
1063
 
 
1064
                if (m->since > 1)
 
1065
                        printf("%d", m->since);
 
1066
 
1036
1067
                wl_list_for_each(a, &m->arg_list, link) {
1037
1068
                        if (is_nullable_type(a) && a->nullable)
1038
1069
                                printf("?");
1131
1162
        struct protocol protocol;
1132
1163
        int len;
1133
1164
        void *buf;
 
1165
        enum {
 
1166
                CLIENT_HEADER,
 
1167
                SERVER_HEADER,
 
1168
                CODE,
 
1169
        } mode;
1134
1170
 
1135
1171
        if (argc != 2)
1136
1172
                usage(EXIT_FAILURE);
 
1173
        else if (strcmp(argv[1], "help") == 0 || strcmp(argv[1], "--help") == 0)
 
1174
                usage(EXIT_SUCCESS);
 
1175
        else if (strcmp(argv[1], "client-header") == 0)
 
1176
                mode = CLIENT_HEADER;
 
1177
        else if (strcmp(argv[1], "server-header") == 0)
 
1178
                mode = SERVER_HEADER;
 
1179
        else if (strcmp(argv[1], "code") == 0)
 
1180
                mode = CODE;
 
1181
        else
 
1182
                usage(EXIT_FAILURE);
1137
1183
 
1138
1184
        wl_list_init(&protocol.interface_list);
1139
1185
        protocol.type_index = 0;
1166
1212
 
1167
1213
        XML_ParserFree(ctx.parser);
1168
1214
 
1169
 
        if (strcmp(argv[1], "client-header") == 0) {
1170
 
                emit_header(&protocol, 0);
1171
 
        } else if (strcmp(argv[1], "server-header") == 0) {
1172
 
                emit_header(&protocol, 1);
1173
 
        } else if (strcmp(argv[1], "code") == 0) {
1174
 
                emit_code(&protocol);
 
1215
        switch (mode) {
 
1216
                case CLIENT_HEADER:
 
1217
                        emit_header(&protocol, 0);
 
1218
                        break;
 
1219
                case SERVER_HEADER:
 
1220
                        emit_header(&protocol, 1);
 
1221
                        break;
 
1222
                case CODE:
 
1223
                        emit_code(&protocol);
 
1224
                        break;
1175
1225
        }
1176
1226
 
1177
1227
        return 0;