From abc133121d15617823cceb529a797bbfbf50546d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 10 Sep 2013 13:05:05 +0200 Subject: [PATCH] code cleanup - compile with -Wall --- Makefile | 2 +- basic_event_loop.c | 2 +- glyphs.h | 6 ++-- spiceterm.c | 32 ++++++++----------- test_display_base.c | 22 ++++++------- test_display_base.h | 75 ++------------------------------------------- 6 files changed, 30 insertions(+), 109 deletions(-) diff --git a/Makefile b/Makefile index a7a945d..fb1a12e 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ SOURCES=test_display_base.c basic_event_loop.c all: ${PROGRAMS} spiceterm: ${SOURCES} ${HEADERS} spiceterm.c - gcc ${SOURCES} spiceterm.c -o $@ -lutil $(shell pkg-config --cflags gdk-3.0) $(shell pkg-config --cflags --libs gthread-2.0,spice-protocol,spice-server) + gcc -Werror -Wall -Wtype-limits ${SOURCES} spiceterm.c -o $@ -lutil $(shell pkg-config --cflags gdk-3.0) $(shell pkg-config --cflags --libs gthread-2.0,spice-protocol,spice-server) .PHONY: test test: spiceterm diff --git a/basic_event_loop.c b/basic_event_loop.c index 39e4270..5affa34 100644 --- a/basic_event_loop.c +++ b/basic_event_loop.c @@ -179,7 +179,7 @@ static void watch_remove(SpiceWatch *watch) static void channel_event(int event, SpiceChannelEventInfo *info) { - DPRINTF(0, "channel event con, type, id, event: %ld, %d, %d, %d", + DPRINTF(0, "channel event con, type, id, event: %d, %d, %d, %d", info->connection_id, info->type, info->id, event); } diff --git a/glyphs.h b/glyphs.h index 7203809..7a8253c 100644 --- a/glyphs.h +++ b/glyphs.h @@ -1,6 +1,6 @@ -static int vt_font_size = 850; +int vt_font_size = 850; -static unsigned char vt_font_data[] = { +unsigned char vt_font_data[] = { /* 0 0x00 */ 0x00, /* 00000000 */ 0x00, /* 00000000 */ @@ -15303,7 +15303,7 @@ static unsigned char vt_font_data[] = { }; -static unsigned short vt_fontmap[65536] = { +unsigned short vt_fontmap[65536] = { /* 0x0000 => */ 0, /* 0x0001 => */ 0, /* 0x0002 => */ 0, diff --git a/spiceterm.c b/spiceterm.c index 4113654..2798fa8 100644 --- a/spiceterm.c +++ b/spiceterm.c @@ -22,6 +22,8 @@ */ +#define _GNU_SOURCE + #include #include #include @@ -38,7 +40,7 @@ #include #include "spiceterm.h" -#include "glyphs.h" +//#include "glyphs.h" #include #include @@ -64,8 +66,6 @@ /* these colours are from linux kernel drivers/char/vt.c */ -static int idle_timeout = 1; - unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, 8,12,10,14, 9,13,11,15 }; @@ -78,6 +78,7 @@ print_usage (const char *msg) } /* Convert UCS2 to UTF8 sequence, trailing zero */ +/* static int ucs2_to_utf8 (unicode c, char *out) { @@ -100,7 +101,7 @@ ucs2_to_utf8 (unicode c, char *out) return 0; } - +*/ static void draw_char_at (vncTerm *vt, int x, int y, unicode ch, TextAttributes attrib) @@ -109,10 +110,7 @@ draw_char_at (vncTerm *vt, int x, int y, unicode ch, TextAttributes attrib) return; } - - int ec = vt_fontmap[ch]; - - test_draw_update_char(vt->screen, x, y, ec, attrib); + test_draw_update_char(vt->screen, x, y, ch, attrib); } static void @@ -1269,6 +1267,7 @@ vncterm_set_xcut_text (char* str, int len, struct _rfbClientRec* cl) vt->selection_len = len; } */ +/* static void mouse_report (vncTerm *vt, int butt, int mrx, int mry) { @@ -1279,14 +1278,15 @@ mouse_report (vncTerm *vt, int butt, int mrx, int mry) vncterm_respond_esc (vt, buf); } +*/ void vncterm_toggle_marked_cell (vncTerm *vt, int pos) { - int x= (pos%vt->width)*8; - int y= (pos/vt->width)*16; /* fixme: + int x= (pos%vt->width)*8; + int y= (pos/vt->width)*16; int i,j; rfbScreenInfoPtr s=vt->screen; @@ -1437,14 +1437,9 @@ vncterm_pointer_event (int buttonMask, int x, int y, rfbClientPtr cl) } */ -static int client_count = 0; -static int client_connected = 0; -static int last_client = 1; -static time_t last_time = 0; - static void my_kbd_push_key(SpiceKbdInstance *sin, uint8_t frag) { - vncTerm *vt = SPICE_CONTAINEROF(sin, vncTerm, keyboard_sin); + // vncTerm *vt = SPICE_CONTAINEROF(sin, vncTerm, keyboard_sin); /* we no not need this */ @@ -1741,9 +1736,6 @@ main (int argc, char** argv) int pid; int master; char ptyname[1024]; - fd_set fs, fs1; - struct timeval tv, tv1; - time_t elapsed, cur_time; struct winsize dimensions; g_thread_init(NULL); @@ -1758,6 +1750,8 @@ main (int argc, char** argv) } } + if (0) print_usage(NULL); // fixme: + vncTerm *vt = create_vncterm (argc, argv, 745, 400); setlocale(LC_ALL, ""); // set from environment diff --git a/test_display_base.c b/test_display_base.c index e6c91fe..7551d12 100644 --- a/test_display_base.c +++ b/test_display_base.c @@ -56,11 +56,11 @@ static void test_spice_destroy_update(SimpleSpiceUpdate *update) #define DEFAULT_WIDTH 640 #define DEFAULT_HEIGHT 320 -#define SINGLE_PART 4 -static const int angle_parts = 64 / SINGLE_PART; +//#define SINGLE_PART 4 +//static const int angle_parts = 64 / SINGLE_PART; static int unique = 1; -static int color = -1; -static int c_i = 0; +//static int color = -1; +//static int c_i = 0; __attribute__((noreturn)) static void sigchld_handler(int signal_num) // wait for the child process and exit @@ -388,9 +388,9 @@ ret: static int req_cmd_notification(QXLInstance *qin) { - Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); - + //Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); //test->core->timer_start(test->wakeup_timer, test->wakeup_ms); + return TRUE; } @@ -450,7 +450,6 @@ static void cursor_init() static int get_cursor_command(QXLInstance *qin, struct QXLCommandExt *ext) { Test *test = SPICE_CONTAINEROF(qin, Test, qxl_instance); - static int color = 0; static int set = 1; static int x = 0, y = 0; QXLCursorCmd *cursor_cmd; @@ -553,7 +552,7 @@ static void client_disconnected(Test *test) static void do_conn_timeout(void *opaque) { - Test *test = opaque; + // Test *test = opaque; if (client_count <= 0) { printf("do_conn_timeout\n"); @@ -631,8 +630,6 @@ void test_add_agent_interface(SpiceServer *server) spice_server_add_interface(server, &vdagent_sin.base); } -static int my_charcode = 65; -static int my_posx = 0; static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag) { Test *test = SPICE_CONTAINEROF(sin, Test, keyboard_sin); @@ -641,7 +638,7 @@ static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag) } -void test_draw_update_char(Test *test, int x, int y, int c, TextAttributes attrib) +void test_draw_update_char(Test *test, int x, int y, gunichar ch, TextAttributes attrib) { int fg, bg; @@ -663,6 +660,8 @@ void test_draw_update_char(Test *test, int x, int y, int c, TextAttributes attri //rfbDrawLine (vt->screen, rx, ry + 14, rxe, ry + 14, fg); //} + int c = vt_fontmap[ch]; + SimpleSpiceUpdate *update; update = test_draw_char(test, x, y, c, fg, bg); push_command(test, &update->ext); @@ -718,7 +717,6 @@ Test *test_new(SpiceCoreInterface *core) } cursor_init(); - test->has_secondary = 0; int timeout = 10; // max time to wait for client connection test->conn_timeout_timer = core->timer_add(do_conn_timeout, test); diff --git a/test_display_base.h b/test_display_base.h index a4f8ab1..4dde4d2 100644 --- a/test_display_base.h +++ b/test_display_base.h @@ -3,6 +3,7 @@ #include #include + #include "basic_event_loop.h" @@ -18,82 +19,13 @@ typedef struct TextAttributes { #define COUNT(x) ((sizeof(x)/sizeof(x[0]))) -/* - * simple queue for commands. - * each command can have up to two parameters (grow as needed) - * - * TODO: switch to gtk main loop. Then add gobject-introspection. then - * write tests in python/guile/whatever. - */ -typedef enum { - PATH_PROGRESS, - SIMPLE_CREATE_SURFACE, - SIMPLE_DRAW, - SIMPLE_DRAW_BITMAP, - SIMPLE_DRAW_SOLID, - SIMPLE_COPY_BITS, - SIMPLE_DESTROY_SURFACE, - SIMPLE_UPDATE, - DESTROY_PRIMARY, - CREATE_PRIMARY, - SLEEP -} CommandType; - -typedef struct CommandCreatePrimary { - uint32_t width; - uint32_t height; -} CommandCreatePrimary; - -typedef struct CommandCreateSurface { - uint32_t surface_id; - uint32_t format; - uint32_t width; - uint32_t height; - uint8_t *data; -} CommandCreateSurface; - -typedef struct CommandDrawBitmap { - QXLRect bbox; - uint8_t *bitmap; - uint32_t surface_id; - uint32_t num_clip_rects; - QXLRect *clip_rects; -} CommandDrawBitmap; - -typedef struct CommandDrawSolid { - QXLRect bbox; - uint32_t color; - uint32_t surface_id; -} CommandDrawSolid; - -typedef struct CommandSleep { - uint32_t secs; -} CommandSleep; - -typedef struct Command Command; typedef struct Test Test; -struct Command { - CommandType command; - void (*cb)(Test *test, Command *command); - void *cb_opaque; - union { - CommandCreatePrimary create_primary; - CommandDrawBitmap bitmap; - CommandDrawSolid solid; - CommandSleep sleep; - CommandCreateSurface create_surface; - }; -}; - #define COMMANDS_SIZE 1024 #define MAX_HEIGHT 2048 #define MAX_WIDTH 2048 -#define SURF_WIDTH 320 -#define SURF_HEIGHT 240 - struct Test { SpiceCoreInterface *core; SpiceServer *server; @@ -112,9 +44,6 @@ struct Test { int cursor_notify; - uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4]; - int has_secondary; - // Current mode (set by create_primary) int width; int height; @@ -138,7 +67,7 @@ void test_add_agent_interface(SpiceServer *server); // TODO - Test *test void test_add_keyboard_interface(Test *test); Test* test_new(SpiceCoreInterface* core); -void test_draw_update_char(Test *test, int x, int y, int c, TextAttributes attrib); +void test_draw_update_char(Test *test, int x, int y, gunichar ch, TextAttributes attrib); void test_spice_scroll(Test *test, int x1, int y1, int x2, int y2, int src_x, int src_y); void test_spice_clear(Test *test, int x1, int y1, int x2, int y2); -- 2.39.2