]> git.proxmox.com Git - spiceterm.git/blame - test_display_base.c
Makefile: add clean/distclean targets
[spiceterm.git] / test_display_base.c
CommitLineData
cc04455b
DM
1#include <stdlib.h>
2#include <math.h>
3#include <string.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <signal.h>
7#include <wait.h>
8#include <sys/select.h>
9#include <sys/types.h>
10#include <getopt.h>
11
4219b121 12#include "glyphs.h"
cc04455b 13#include <spice.h>
474762d8 14#include <spice/enums.h>
cc04455b
DM
15#include <spice/macros.h>
16#include <spice/qxl_dev.h>
17
18#include "test_display_base.h"
cc04455b
DM
19
20#define MEM_SLOT_GROUP_ID 0
21
22#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
23#define NOTIFY_CURSOR_BATCH 10
24
25/* Parts cribbed from spice-display.h/.c/qxl.c */
26
27typedef struct SimpleSpiceUpdate {
28 QXLCommandExt ext; // first
29 QXLDrawable drawable;
30 QXLImage image;
31 uint8_t *bitmap;
32} SimpleSpiceUpdate;
33
cc04455b
DM
34static void test_spice_destroy_update(SimpleSpiceUpdate *update)
35{
36 if (!update) {
37 return;
38 }
39 if (update->drawable.clip.type != SPICE_CLIP_TYPE_NONE) {
40 uint8_t *ptr = (uint8_t*)update->drawable.clip.data;
41 free(ptr);
42 }
9f9c8d83
DM
43 g_free(update->bitmap);
44 g_free(update);
cc04455b
DM
45}
46
47#define DEFAULT_WIDTH 640
48#define DEFAULT_HEIGHT 320
49
50#define SINGLE_PART 4
51static const int angle_parts = 64 / SINGLE_PART;
52static int unique = 1;
53static int color = -1;
54static int c_i = 0;
55
cc04455b
DM
56__attribute__((noreturn))
57static void sigchld_handler(int signal_num) // wait for the child process and exit
58{
59 int status;
60 wait(&status);
61 exit(0);
62}
63
cc04455b
DM
64static void set_cmd(QXLCommandExt *ext, uint32_t type, QXLPHYSICAL data)
65{
66 ext->cmd.type = type;
67 ext->cmd.data = data;
68 ext->cmd.padding = 0;
69 ext->group_id = MEM_SLOT_GROUP_ID;
70 ext->flags = 0;
71}
72
73static void simple_set_release_info(QXLReleaseInfo *info, intptr_t ptr)
74{
75 info->id = ptr;
76 //info->group_id = MEM_SLOT_GROUP_ID;
77}
78
9f9c8d83 79/* bitmap are freed, so they must be allocated with g_malloc */
cc04455b
DM
80SimpleSpiceUpdate *test_spice_create_update_from_bitmap(uint32_t surface_id,
81 QXLRect bbox,
4219b121 82 uint8_t *bitmap)
cc04455b
DM
83{
84 SimpleSpiceUpdate *update;
85 QXLDrawable *drawable;
86 QXLImage *image;
87 uint32_t bw, bh;
88
89 bh = bbox.bottom - bbox.top;
90 bw = bbox.right - bbox.left;
91
9f9c8d83 92 update = g_new0(SimpleSpiceUpdate, 1);
cc04455b
DM
93 update->bitmap = bitmap;
94 drawable = &update->drawable;
95 image = &update->image;
96
97 drawable->surface_id = surface_id;
98
99 drawable->bbox = bbox;
4219b121 100 drawable->clip.type = SPICE_CLIP_TYPE_NONE;
cc04455b
DM
101 drawable->effect = QXL_EFFECT_OPAQUE;
102 simple_set_release_info(&drawable->release_info, (intptr_t)update);
103 drawable->type = QXL_DRAW_COPY;
104 drawable->surfaces_dest[0] = -1;
105 drawable->surfaces_dest[1] = -1;
106 drawable->surfaces_dest[2] = -1;
107
108 drawable->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
109 drawable->u.copy.src_bitmap = (intptr_t)image;
110 drawable->u.copy.src_area.right = bw;
111 drawable->u.copy.src_area.bottom = bh;
112
113 QXL_SET_IMAGE_ID(image, QXL_IMAGE_GROUP_DEVICE, unique);
114 image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
115 image->bitmap.flags = QXL_BITMAP_DIRECT | QXL_BITMAP_TOP_DOWN;
116 image->bitmap.stride = bw * 4;
117 image->descriptor.width = image->bitmap.x = bw;
118 image->descriptor.height = image->bitmap.y = bh;
119 image->bitmap.data = (intptr_t)bitmap;
120 image->bitmap.palette = 0;
121 image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
122
123 set_cmd(&update->ext, QXL_CMD_DRAW, (intptr_t)drawable);
124
125 return update;
126}
127
8a22eb4f 128static SimpleSpiceUpdate *test_draw_char(Test *test, int x, int y, int c)
cc04455b
DM
129{
130 int top, left;
131 uint8_t *dst;
132 uint8_t *bitmap;
133 int bw, bh;
9462ba15 134 int i, j;
cc04455b
DM
135 QXLRect bbox;
136
8a22eb4f
DM
137 left = x*8;
138 top = y*16;
26c64941 139
9f9c8d83 140 printf("DRAWCHAR %d %d %d\n", left, top, c);
8a22eb4f 141
cc04455b
DM
142 unique++;
143
26c64941
DM
144 bw = 8;
145 bh = 16;
cc04455b 146
9f9c8d83 147 bitmap = dst = g_malloc(bw * bh * 4);
cc04455b 148
9462ba15
DM
149 unsigned char *data = vt_font_data + c*16;
150 unsigned char d = *data;
151
9f9c8d83
DM
152 unsigned char fgc_red = 255;
153 unsigned char fgc_blue = 255;
154 unsigned char fgc_green = 255;
155 unsigned char bgc_red = 0;
156 unsigned char bgc_blue = 0;
157 unsigned char bgc_green = 0;
158
9462ba15
DM
159 for (j = 0; j < 16; j++) {
160 for (i = 0; i < 8; i++) {
161 if ((i&7) == 0) {
162 d=*data;
163 data++;
164 }
165 if (d&0x80) {
9f9c8d83
DM
166 *(dst) = fgc_blue;
167 *(dst+1) = fgc_green;
168 *(dst+2) = fgc_red;
169 *(dst+3) = 0;
170 } else {
171 *(dst) = bgc_blue;
172 *(dst+1) = bgc_green;
173 *(dst+2) = bgc_red;
9462ba15
DM
174 *(dst+3) = 0;
175 }
176 d<<=1;
177 dst += 4;
178 }
cc04455b
DM
179 }
180
181 bbox.left = left; bbox.top = top;
182 bbox.right = left + bw; bbox.bottom = top + bh;
9462ba15 183
8a22eb4f 184 return test_spice_create_update_from_bitmap(0, bbox, bitmap);
cc04455b
DM
185}
186
cc04455b
DM
187static void create_primary_surface(Test *test, uint32_t width,
188 uint32_t height)
189{
190 QXLWorker *qxl_worker = test->qxl_worker;
191 QXLDevSurfaceCreate surface = { 0, };
192
193 g_assert(height <= MAX_HEIGHT);
194 g_assert(width <= MAX_WIDTH);
195 g_assert(height > 0);
196 g_assert(width > 0);
197
198 surface.format = SPICE_SURFACE_FMT_32_xRGB;
199 surface.width = test->primary_width = width;
200 surface.height = test->primary_height = height;
201 surface.stride = -width * 4; /* negative? */
202 surface.mouse_mode = TRUE; /* unused by red_worker */
203 surface.flags = 0;
204 surface.type = 0; /* unused by red_worker */
205 surface.position = 0; /* unused by red_worker */
206 surface.mem = (uint64_t)&test->primary_surface;
207 surface.group_id = MEM_SLOT_GROUP_ID;
208
209 test->width = width;
210 test->height = height;
211
212 qxl_worker->create_primary_surface(qxl_worker, 0, &surface);
213}
214
215QXLDevMemSlot slot = {
216.slot_group_id = MEM_SLOT_GROUP_ID,
217.slot_id = 0,
218.generation = 0,
219.virt_start = 0,
220.virt_end = ~0,
221.addr_delta = 0,
222.qxl_ram_size = ~0,
223};
224
225static void attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker)
226{
227 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
228
229 if (test->qxl_worker) {
230 if (test->qxl_worker != _qxl_worker)
231 printf("%s ignored, %p is set, ignoring new %p\n", __func__,
232 test->qxl_worker, _qxl_worker);
233 else
234 printf("%s ignored, redundant\n", __func__);
235 return;
236 }
237 printf("%s\n", __func__);
238 test->qxl_worker = _qxl_worker;
239 test->qxl_worker->add_memslot(test->qxl_worker, &slot);
240 create_primary_surface(test, DEFAULT_WIDTH, DEFAULT_HEIGHT);
241 test->qxl_worker->start(test->qxl_worker);
242}
243
244static void set_compression_level(QXLInstance *qin, int level)
245{
246 printf("%s\n", __func__);
247}
248
249static void set_mm_time(QXLInstance *qin, uint32_t mm_time)
250{
251}
cc04455b
DM
252static void get_init_info(QXLInstance *qin, QXLDevInitInfo *info)
253{
254 memset(info, 0, sizeof(*info));
255 info->num_memslots = 1;
256 info->num_memslots_groups = 1;
257 info->memslot_id_bits = 1;
258 info->memslot_gen_bits = 1;
aae93060 259 info->n_surfaces = 1;
cc04455b
DM
260}
261
aae93060 262
cc04455b
DM
263// We shall now have a ring of commands, so that we can update
264// it from a separate thread - since get_command is called from
265// the worker thread, and we need to sometimes do an update_area,
266// which cannot be done from red_worker context (not via dispatcher,
267// since you get a deadlock, and it isn't designed to be done
268// any other way, so no point testing that).
269int commands_end = 0;
270int commands_start = 0;
271struct QXLCommandExt* commands[1024];
272
273#define COMMANDS_SIZE COUNT(commands)
274
275static void push_command(QXLCommandExt *ext)
276{
277 g_assert(commands_end - commands_start < COMMANDS_SIZE);
278 commands[commands_end % COMMANDS_SIZE] = ext;
279 commands_end++;
280}
281
282static struct QXLCommandExt *get_simple_command(void)
283{
284 struct QXLCommandExt *ret = commands[commands_start % COMMANDS_SIZE];
285 g_assert(commands_start < commands_end);
286 commands_start++;
287 return ret;
288}
289
290static int get_num_commands(void)
291{
292 return commands_end - commands_start;
293}
294
295// called from spice_server thread (i.e. red_worker thread)
296static int get_command(QXLInstance *qin, struct QXLCommandExt *ext)
297{
298 if (get_num_commands() == 0) {
299 return FALSE;
300 }
301 *ext = *get_simple_command();
302 return TRUE;
303}
304
cc04455b
DM
305static int req_cmd_notification(QXLInstance *qin)
306{
307 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
308
8a22eb4f 309 //test->core->timer_start(test->wakeup_timer, test->wakeup_ms);
cc04455b
DM
310 return TRUE;
311}
f6cb554c 312
cc04455b
DM
313static void release_resource(QXLInstance *qin, struct QXLReleaseInfoExt release_info)
314{
315 QXLCommandExt *ext = (QXLCommandExt*)(unsigned long)release_info.info->id;
316 //printf("%s\n", __func__);
317 g_assert(release_info.group_id == MEM_SLOT_GROUP_ID);
318 switch (ext->cmd.type) {
319 case QXL_CMD_DRAW:
320 test_spice_destroy_update((void*)ext);
321 break;
322 case QXL_CMD_SURFACE:
323 free(ext);
324 break;
325 case QXL_CMD_CURSOR: {
326 QXLCursorCmd *cmd = (QXLCursorCmd *)(unsigned long)ext->cmd.data;
327 if (cmd->type == QXL_CURSOR_SET) {
328 free(cmd);
329 }
330 free(ext);
331 break;
332 }
333 default:
334 abort();
335 }
336}
337
338#define CURSOR_WIDTH 32
339#define CURSOR_HEIGHT 32
340
341static struct {
342 QXLCursor cursor;
343 uint8_t data[CURSOR_WIDTH * CURSOR_HEIGHT * 4]; // 32bit per pixel
344} cursor;
345
346static void cursor_init()
347{
348 cursor.cursor.header.unique = 0;
349 cursor.cursor.header.type = SPICE_CURSOR_TYPE_COLOR32;
350 cursor.cursor.header.width = CURSOR_WIDTH;
351 cursor.cursor.header.height = CURSOR_HEIGHT;
352 cursor.cursor.header.hot_spot_x = 0;
353 cursor.cursor.header.hot_spot_y = 0;
354 cursor.cursor.data_size = CURSOR_WIDTH * CURSOR_HEIGHT * 4;
355
356 // X drivers addes it to the cursor size because it could be
357 // cursor data information or another cursor related stuffs.
358 // Otherwise, the code will break in client/cursor.cpp side,
359 // that expect the data_size plus cursor information.
360 // Blame cursor protocol for this. :-)
361 cursor.cursor.data_size += 128;
362 cursor.cursor.chunk.data_size = cursor.cursor.data_size;
363 cursor.cursor.chunk.prev_chunk = cursor.cursor.chunk.next_chunk = 0;
364}
365
366static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext)
367{
368 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
369 static int color = 0;
370 static int set = 1;
371 static int x = 0, y = 0;
372 QXLCursorCmd *cursor_cmd;
373 QXLCommandExt *cmd;
374
375 if (!test->cursor_notify) {
376 return FALSE;
377 }
378
379 test->cursor_notify--;
380 cmd = calloc(sizeof(QXLCommandExt), 1);
381 cursor_cmd = calloc(sizeof(QXLCursorCmd), 1);
382
383 cursor_cmd->release_info.id = (unsigned long)cmd;
384
385 if (set) {
386 cursor_cmd->type = QXL_CURSOR_SET;
387 cursor_cmd->u.set.position.x = 0;
388 cursor_cmd->u.set.position.y = 0;
389 cursor_cmd->u.set.visible = TRUE;
390 cursor_cmd->u.set.shape = (unsigned long)&cursor;
391 // Only a white rect (32x32) as cursor
392 memset(cursor.data, 255, sizeof(cursor.data));
393 set = 0;
394 } else {
395 cursor_cmd->type = QXL_CURSOR_MOVE;
396 cursor_cmd->u.position.x = x++ % test->primary_width;
397 cursor_cmd->u.position.y = y++ % test->primary_height;
398 }
399
400 cmd->cmd.data = (unsigned long)cursor_cmd;
401 cmd->cmd.type = QXL_CMD_CURSOR;
402 cmd->group_id = MEM_SLOT_GROUP_ID;
403 cmd->flags = 0;
404 *ext = *cmd;
405 //printf("%s\n", __func__);
406 return TRUE;
407}
408
409static int req_cursor_notification(QXLInstance *qin)
410{
411 printf("%s\n", __func__);
412 return TRUE;
413}
414
415static void notify_update(QXLInstance *qin, uint32_t update_id)
416{
417 printf("%s\n", __func__);
418}
419
420static int flush_resources(QXLInstance *qin)
421{
422 printf("%s\n", __func__);
423 return TRUE;
424}
425
426static int client_monitors_config(QXLInstance *qin,
427 VDAgentMonitorsConfig *monitors_config)
428{
429 if (!monitors_config) {
430 printf("%s: NULL monitors_config\n", __func__);
431 } else {
432 printf("%s: %d\n", __func__, monitors_config->num_of_monitors);
433 }
434 return 0;
435}
436
437static void set_client_capabilities(QXLInstance *qin,
438 uint8_t client_present,
439 uint8_t caps[58])
440{
441 Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance);
442
443 printf("%s: present %d caps %d\n", __func__, client_present, caps[0]);
444 if (test->on_client_connected && client_present) {
445 test->on_client_connected(test);
446 }
447 if (test->on_client_disconnected && !client_present) {
448 test->on_client_disconnected(test);
449 }
450}
451
6faab5d5
DM
452static int client_count = 0;
453
454static void client_connected(Test *test)
455{
456 printf("Client connected\n");
457 client_count++;
458}
459
460static void client_disconnected(Test *test)
461{
462
463 if (client_count > 0) {
464 client_count--;
465 printf("Client disconnected\n");
466 exit(0); // fixme: cleanup?
467 }
468}
469
f6cb554c
DM
470static void do_conn_timeout(void *opaque)
471{
472 Test *test = opaque;
473
474 if (client_count <= 0) {
475 printf("do_conn_timeout\n");
476 exit (0); // fixme: cleanup?
477 }
478}
479
480
cc04455b
DM
481QXLInterface display_sif = {
482 .base = {
483 .type = SPICE_INTERFACE_QXL,
484 .description = "test",
485 .major_version = SPICE_INTERFACE_QXL_MAJOR,
486 .minor_version = SPICE_INTERFACE_QXL_MINOR
487 },
488 .attache_worker = attache_worker,
489 .set_compression_level = set_compression_level,
490 .set_mm_time = set_mm_time,
491 .get_init_info = get_init_info,
492
493 /* the callbacks below are called from spice server thread context */
494 .get_command = get_command,
495 .req_cmd_notification = req_cmd_notification,
496 .release_resource = release_resource,
497 .get_cursor_command = get_cursor_command,
498 .req_cursor_notification = req_cursor_notification,
499 .notify_update = notify_update,
500 .flush_resources = flush_resources,
501 .client_monitors_config = client_monitors_config,
502 .set_client_capabilities = set_client_capabilities,
503};
504
505/* interface for tests */
506void test_add_display_interface(Test* test)
507{
508 spice_server_add_interface(test->server, &test->qxl_instance.base);
509}
510
511static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
512{
6faab5d5 513// printf("%s: %d\n", __func__, len);
cc04455b
DM
514 return len;
515}
516
517static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
518{
6faab5d5 519// printf("%s: %d\n", __func__, len);
cc04455b
DM
520 return 0;
521}
522
523static void vmc_state(SpiceCharDeviceInstance *sin, int connected)
524{
6faab5d5 525// printf("%s: %d\n", __func__, connected);
cc04455b
DM
526}
527
528static SpiceCharDeviceInterface vdagent_sif = {
529 .base.type = SPICE_INTERFACE_CHAR_DEVICE,
530 .base.description = "test spice virtual channel char device",
531 .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
532 .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
533 .state = vmc_state,
534 .write = vmc_write,
535 .read = vmc_read,
536};
537
538SpiceCharDeviceInstance vdagent_sin = {
539 .base = {
540 .sif = &vdagent_sif.base,
541 },
542 .subtype = "vdagent",
543};
544
545void test_add_agent_interface(SpiceServer *server)
546{
547 spice_server_add_interface(server, &vdagent_sin.base);
548}
549
8a22eb4f
DM
550static int my_charcode = 65;
551static int my_posx = 0;
474762d8
DM
552static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag)
553{
8a22eb4f
DM
554 Test *test = SPICE_CONTAINEROF(sin, Test, keyboard_sin);
555
556 printf("KEYCODE %u %p\n", frag, test);
557
558 SimpleSpiceUpdate *update;
559 update = test_draw_char(test, my_posx, 10, my_charcode);
560 my_posx++;
561 my_charcode++;
562 push_command(&update->ext);
563
564 test->qxl_worker->wakeup(test->qxl_worker);
474762d8
DM
565}
566
22e5ba02
DM
567void test_draw_update_char(Test *test, int x, int y, int c, TextAttributes attrib)
568{
569 int fg, bg;
570
571 if (attrib.invers) {
572 bg = attrib.fgcol;
573 fg = attrib.bgcol;
574 } else {
575 bg = attrib.bgcol;
576 fg = attrib.fgcol;
577 }
578
579 if (attrib.bold) {
580 fg += 8;
581 }
582
583 // unsuported attributes = (attrib.blink || attrib.unvisible)
584
585 //if (attrib.uline) {
586 //rfbDrawLine (vt->screen, rx, ry + 14, rxe, ry + 14, fg);
587 //}
588
589 SimpleSpiceUpdate *update;
590 update = test_draw_char(test, x, y, c);
591 push_command(&update->ext);
592
593 test->qxl_worker->wakeup(test->qxl_worker);
594}
595
474762d8
DM
596static uint8_t kbd_get_leds(SpiceKbdInstance *sin)
597{
598 return 0;
599}
600
601static SpiceKbdInterface keyboard_sif = {
602 .base.type = SPICE_INTERFACE_KEYBOARD ,
603 .base.description = "spiceterm keyboard device",
604 .base.major_version = SPICE_INTERFACE_KEYBOARD_MAJOR,
605 .base.minor_version = SPICE_INTERFACE_KEYBOARD_MINOR,
606 .push_scan_freg = kbd_push_key,
607 .get_leds = kbd_get_leds,
608};
609
8a22eb4f 610void test_add_keyboard_interface(Test* test)
474762d8 611{
22e5ba02 612 g_error("teste");
8a22eb4f 613 spice_server_add_interface(test->server, &test->keyboard_sin.base);
474762d8
DM
614}
615
cc04455b
DM
616void test_set_simple_command_list(Test *test, int *simple_commands, int num_commands)
617{
618 int i;
619
620 /* FIXME: leaks */
621 test->commands = malloc(sizeof(*test->commands) * num_commands);
622 memset(test->commands, 0, sizeof(*test->commands) * num_commands);
623 test->num_commands = num_commands;
624 for (i = 0 ; i < num_commands; ++i) {
625 test->commands[i].command = simple_commands[i];
626 }
627}
628
629void test_set_command_list(Test *test, Command *commands, int num_commands)
630{
631 test->commands = commands;
632 test->num_commands = num_commands;
633}
634
635
636Test *test_new(SpiceCoreInterface *core)
637{
638 int port = 5912;
639 Test *test = g_new0(Test, 1);
640 SpiceServer* server = spice_server_new();
641
6faab5d5
DM
642 test->on_client_connected = client_connected,
643 test->on_client_disconnected = client_disconnected,
644
cc04455b
DM
645 test->qxl_instance.base.sif = &display_sif.base;
646 test->qxl_instance.id = 0;
647
8a22eb4f
DM
648 test->keyboard_sin.base.sif = &keyboard_sif.base;
649
cc04455b
DM
650 test->core = core;
651 test->server = server;
8a22eb4f 652
cc04455b
DM
653 test->cursor_notify = NOTIFY_CURSOR_BATCH;
654 // some common initialization for all display tests
655 printf("TESTER: listening on port %d (unsecure)\n", port);
656 spice_server_set_port(server, port);
657 spice_server_set_noauth(server);
1d7f2da4
DM
658 int res = spice_server_init(server, core);
659 if (res != 0) {
660 g_error("spice_server_init failed, res = %d\n", res);
661 }
cc04455b
DM
662
663 cursor_init();
cc04455b 664 test->has_secondary = 0;
f6cb554c
DM
665
666 int timeout = 10; // max time to wait for client connection
667 test->conn_timeout_timer = core->timer_add(do_conn_timeout, test);
668 test->core->timer_start(test->conn_timeout_timer, timeout*1000);
669
cc04455b
DM
670 return test;
671}
672
cc04455b
DM
673
674__attribute__((noreturn))
675void usage(const char *argv0, const int exitcode)
676{
cc04455b 677
7f30e760 678 printf("usage: %s\n", argv0);
cc04455b
DM
679 exit(exitcode);
680}
681
682void spice_test_config_parse_args(int argc, char **argv)
683{
684 struct option options[] = {
7f30e760 685// {"automated-tests", no_argument, &has_automated_tests, 1},
cc04455b
DM
686 {NULL, 0, NULL, 0},
687 };
688 int option_index;
689 int val;
690
691 while ((val = getopt_long(argc, argv, "", options, &option_index)) != -1) {
692 switch (val) {
693 case '?':
694 printf("unrecognized option '%s'\n", argv[optind - 1]);
695 usage(argv[0], EXIT_FAILURE);
696 case 0:
697 break;
698 }
699 }
700
701 if (argc > optind) {
702 printf("unknown argument '%s'\n", argv[optind]);
703 usage(argv[0], EXIT_FAILURE);
704 }
cc04455b
DM
705 return;
706}