From 2e5d1ecc383f3862a2b652c2f5a3ec09edd4b5bd Mon Sep 17 00:00:00 2001 From: darkrose Date: Fri, 4 Mar 2016 20:43:08 +1000 Subject: [PATCH] modify logging to simplify i18n --- inc/common.h | 14 +++++++------- src/client/events_x11.c | 4 ++-- src/client/main.c | 5 +---- src/core/command.c | 16 ++++++++-------- src/core/log.c | 14 +++----------- src/graphics/font.c | 2 +- src/graphics/font_ttf.c | 2 +- src/graphics/image.c | 8 ++++---- src/graphics/image_png.c | 2 +- src/graphics/material.c | 2 +- src/graphics/render.c | 13 +++++++------ src/graphics/shader.c | 4 ++-- src/graphics/texture.c | 10 +++++----- src/graphics/wm.c | 4 ++-- src/graphics/wm_x11.c | 6 +++--- src/lib/net_tcp.c | 16 ++++++++-------- src/lib/net_udp.c | 14 +++++++------- src/ui/ui.c | 2 +- 18 files changed, 64 insertions(+), 74 deletions(-) diff --git a/inc/common.h b/inc/common.h index cdb31eb..2482dba 100644 --- a/inc/common.h +++ b/inc/common.h @@ -134,12 +134,12 @@ typedef struct matrix_s { } matrix_t; #endif -#define CN_ERROR "\1" -#define CN_WARN "\2" -#define CN_ACTION "\3" -#define CN_CHAT "\4" -#define CN_INFO "" -#define CN_DEBUG "\6" +#define CN_ERROR 0x01 +#define CN_WARN 0x02 +#define CN_ACTION 0x03 +#define CN_CHAT 0x04 +#define CN_INFO 0x05 +#define CN_DEBUG 0x06 #define VLSTATE_EXIT 0x00 #define VLSTATE_GET 0x01 @@ -236,7 +236,7 @@ int log_smaxlevel_setter(char* v); int log_cminlevel_setter(char* v); int log_cmaxlevel_setter(char* v); int log_file_setter(char* v); -void vlprintf(char* fmt,...); +void vlprintf(uint8_t type, char* fmt,...); /* defined in utf8.c */ int utf8_seqlen(char* str); diff --git a/src/client/events_x11.c b/src/client/events_x11.c index 5dd2799..a32dfe1 100644 --- a/src/client/events_x11.c +++ b/src/client/events_x11.c @@ -380,7 +380,7 @@ void events_main() char buffc[6]; utf8_fromutf32(buffs,6,e.sym.sym); utf8_fromutf32(buffc,6,e.sym.ch); - vlprintf("P %u %u '%s' '%s'\n",e.sym.sym,e.sym.ch,buffs,buffc); + vlprintf(CN_INFO,"P %u %u '%s' '%s'\n",e.sym.sym,e.sym.ch,buffs,buffc); } if (e.sym.sym) events_handle(&e); @@ -404,7 +404,7 @@ void events_main() char buffc[6]; utf8_fromutf32(buffs,6,e.sym.sym); utf8_fromutf32(buffc,6,e.sym.ch); - vlprintf("R %u %u '%s' '%s'\n",e.sym.sym,e.sym.ch,buffs,buffc); + vlprintf(CN_INFO,"R %u %u '%s' '%s'\n",e.sym.sym,e.sym.ch,buffs,buffc); } if (e.sym.sym) events_handle(&e); diff --git a/src/client/main.c b/src/client/main.c index 0cdf053..a492d84 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -53,7 +53,6 @@ int main(int argc, char** argv) textbuffer_t tb; textbuffer_t tb2; font_t *f; - int i; char buff[256]; colour_t glasscolour; colour_t icecolour; @@ -76,9 +75,7 @@ int main(int argc, char** argv) textbuffer_init(&tb,f,14,20,20,0,0,0,0); textbuffer_init(&tb2,f,14,20,40,0,0,0,0); - i = textbuffer_addstr(&tb,"Hello world! - ößäндгя ygj"); - - vlprintf("hello world %d",i); + textbuffer_addstr(&tb,"Hello world! - ößäндгя ygj"); glasscolour.r = 255; glasscolour.g = 255; diff --git a/src/core/command.c b/src/core/command.c index bff6300..7ffda7d 100644 --- a/src/core/command.c +++ b/src/core/command.c @@ -51,7 +51,7 @@ static int command_alias(array_t *args) n = command_data.list; while (n) { if (n->value) - vlprintf(CN_INFO "alias: %s %s",n->name,n->value); + vlprintf(CN_INFO, "alias: %s %s",n->name,n->value); n = n->next; } return 0; @@ -68,7 +68,7 @@ static int command_alias(array_t *args) } if (!n->value) { - vlprintf(CN_WARN "alias: Cannot unias built-in command '%s'",a); + vlprintf(CN_WARN, "alias: Cannot unias built-in command '%s'",a); return 1; } @@ -98,7 +98,7 @@ static int command_help(array_t *args) return 0; } - vlprintf(CN_INFO "%s [arguments]",c); + vlprintf(CN_INFO, "%s [arguments]",c); return 0; } return 0; @@ -106,7 +106,7 @@ static int command_help(array_t *args) static int control_forward(array_t *args) { - vlprintf(CN_INFO "forward"); + vlprintf(CN_INFO, "forward"); return 0; } @@ -194,7 +194,7 @@ int command_apply(char* name, char* value) n = nvp_get(&command_data.list,name); if (!n) { mutex_unlock(command_data.mutex); - vlprintf(CN_WARN "Unknown command: '%s'",name); + vlprintf(CN_WARN, "Unknown command: '%s'",name); return 1; } @@ -211,7 +211,7 @@ int command_apply(char* name, char* value) if (!n->data) { mutex_unlock(command_data.mutex); - vlprintf(CN_WARN "Invalid command: '%s'",name); + vlprintf(CN_WARN, "Invalid command: '%s'",name); return 1; } @@ -219,7 +219,7 @@ int command_apply(char* name, char* value) if (!s->func) { mutex_unlock(command_data.mutex); - vlprintf(CN_WARN "Invalid command: '%s'",name); + vlprintf(CN_WARN, "Invalid command: '%s'",name); return 1; } @@ -251,7 +251,7 @@ int command_exec(char* str) if (cmd[0] == '/') cmd++; - vlprintf(CN_INFO "%s",cmd); + vlprintf(CN_INFO, "%s",cmd); if (spc && spc[0]) { char* args = spc+1; diff --git a/src/core/log.c b/src/core/log.c index 1a3a5be..e2a7e60 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -106,9 +106,8 @@ int log_file_setter(char* v) } /* print formatted text to game and system consoles */ -void vlprintf(char* fmt,...) +void vlprintf(uint8_t type, char* fmt,...) { - char type = 5; char buff[1024]; char* b = buff; int s = 1024; @@ -117,12 +116,6 @@ void vlprintf(char* fmt,...) if (!fmt) return; - va_start(ap, fmt); - if (*fmt < ' ') { - type = *fmt; - fmt++; - } - /* if it's not logged, don't process it */ if ( !type @@ -131,10 +124,8 @@ void vlprintf(char* fmt,...) && (type < logdata.system_min_level || type > logdata.system_max_level) && (type < logdata.console_min_level || type > logdata.console_max_level) ) - ) { - va_end(ap); + ) return; - } switch (type) { case 1: @@ -165,6 +156,7 @@ void vlprintf(char* fmt,...) default:; } + va_start(ap, fmt); if (vsnprintf(b, s, fmt, ap) >= s) { va_end(ap); return; diff --git a/src/graphics/font.c b/src/graphics/font.c index 35ea9ac..d7edbef 100644 --- a/src/graphics/font.c +++ b/src/graphics/font.c @@ -52,7 +52,7 @@ int font_load(char* file, char* token) if (!strcmp(t,"ttf")) { r = font_load_ttf(f,file); }else{ - vlprintf(CN_ERROR "Unsupported Font: %s",file); + vlprintf(CN_ERROR, "Unsupported Font: %s",file); } if (r) { diff --git a/src/graphics/font_ttf.c b/src/graphics/font_ttf.c index 2d3ad90..3e7a882 100644 --- a/src/graphics/font_ttf.c +++ b/src/graphics/font_ttf.c @@ -270,7 +270,7 @@ int font_load_ttf(font_t *f, char* file) /* create the ascii fontpage */ if (font_ttf_gen_fontpage(f,0)) - vlprintf(CN_WARN "font_load_ttf: failed to generate ASCII fontpage"); + vlprintf(CN_WARN, "font_load_ttf: failed to generate ASCII fontpage"); return 0; } diff --git a/src/graphics/image.c b/src/graphics/image.c index fa7c364..ff75180 100644 --- a/src/graphics/image.c +++ b/src/graphics/image.c @@ -120,27 +120,27 @@ image_t *image_load_frommem(file_t *f) /* bmp image */ if (image_is_bmp(f)) { if (image_load_bmp(f,image)) { - vlprintf(CN_ERROR "Image Not Loaded: %s",f->name); + vlprintf(CN_ERROR, "Image Not Loaded: %s",f->name); free(image); image = NULL; } /* png image */ }else if (image_is_png(f)) { if (image_load_png(f,image)) { - vlprintf(CN_ERROR "Image Not Loaded: %s",f->name); + vlprintf(CN_ERROR, "Image Not Loaded: %s",f->name); free(image); image = NULL; } /* tga image */ }else if (image_is_tga(f)) { if (image_load_tga(f,image)) { - vlprintf(CN_ERROR "Image Not Loaded: %s",f->name); + vlprintf(CN_ERROR, "Image Not Loaded: %s",f->name); free(image); image = NULL; } /* unsupported image */ }else{ - vlprintf(CN_ERROR "Unsupported Image: %s",f->name); + vlprintf(CN_ERROR, "Unsupported Image: %s",f->name); free(image); image = NULL; } diff --git a/src/graphics/image_png.c b/src/graphics/image_png.c index e8e43fb..d3444a4 100644 --- a/src/graphics/image_png.c +++ b/src/graphics/image_png.c @@ -140,7 +140,7 @@ int image_load_png(file_t *f, image_t *p) free(px); /* unsupported image */ }else{ - vlprintf("PNG: unsupported image format: %dbpp",bpp); + vlprintf(CN_INFO, "PNG: unsupported image format: %dbpp",bpp); free(p->pixels); return 1; } diff --git a/src/graphics/material.c b/src/graphics/material.c index 8129ebb..77eab97 100644 --- a/src/graphics/material.c +++ b/src/graphics/material.c @@ -149,7 +149,7 @@ int mat_bind_with_opts(GLuint tex, uint32_t options) e = glGetError(); if (e != GL_NO_ERROR) { char* es = opengl_error_string(e); - vlprintf(CN_ERROR "%s",es); + vlprintf(CN_ERROR, "%s",es); return 1; } diff --git a/src/graphics/render.c b/src/graphics/render.c index 62fd395..d7e182e 100644 --- a/src/graphics/render.c +++ b/src/graphics/render.c @@ -19,6 +19,7 @@ #include "common.h" #include "graphics.h" +#include "ui.h" static struct { int ticks; @@ -54,16 +55,16 @@ void render_pre() /* render to frame */ void render_post() { - /* TODO: uncomment this - ui_render();*/ + ui_render(); - /* TODO: uncomment this - if (wm_data.cursor.mat) - render2d_quad_mat(wm_data.cursor.mat,mouse[CUR_X]+wm_data.cursor.x,mouse[CUR_Y]+wm_data.cursor.y,wm_data.cursor.w,wm_data.cursor.h);*/ + if (wm_data.cursor.mat) { + int mouse[2]; + events_get_mouse(mouse); + render2d_quad_mat(wm_data.cursor.mat,mouse[0]+wm_data.cursor.x,mouse[1]+wm_data.cursor.y,wm_data.cursor.w,wm_data.cursor.h); + } /* should get this from sky when in-game */ glClearColor(0, 0, 0, 1.0); - /* smooth blending so the hud layer doesn't hide the game layer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render3d(); diff --git a/src/graphics/shader.c b/src/graphics/shader.c index d6f7e56..04c8db5 100644 --- a/src/graphics/shader.c +++ b/src/graphics/shader.c @@ -42,7 +42,7 @@ static GLuint shader_load(file_t *f, GLenum type) if (i == GL_FALSE) { char buff[512]; glGetShaderInfoLog(s,512,&i,buff); - vlprintf("Shader %s failed to compile: %s",f->name,buff); + vlprintf(CN_WARN, "Shader %s failed to compile: %s",f->name,buff); glDeleteShader(s); s = 0; } @@ -116,7 +116,7 @@ shader_t *shader_create(char* name) glGetProgramiv(s->program, GL_LINK_STATUS, &i); if (i == GL_FALSE) { glGetProgramInfoLog(s->program, 512, &i, buff); - vlprintf("Shader failed to link: %s",buff); + vlprintf(CN_INFO, "Shader failed to link: %s",buff); } glValidateProgram(s->program); diff --git a/src/graphics/texture.c b/src/graphics/texture.c index 6f4a9c6..096c5d5 100644 --- a/src/graphics/texture.c +++ b/src/graphics/texture.c @@ -42,7 +42,7 @@ int tex_generate(texture_t *tex) e = glGetError(); if (e != GL_NO_ERROR) { char* es = opengl_error_string(e); - vlprintf(CN_ERROR "%s",es); + vlprintf(CN_ERROR, "%s",es); return 1; } } @@ -52,7 +52,7 @@ int tex_generate(texture_t *tex) e = glGetError(); if (e != GL_NO_ERROR) { char* es = opengl_error_string(e); - vlprintf(CN_ERROR "%s",es); + vlprintf(CN_ERROR, "%s",es); return 1; } @@ -60,7 +60,7 @@ int tex_generate(texture_t *tex) e = glGetError(); if (e != GL_NO_ERROR) { char* es = opengl_error_string(e); - vlprintf(CN_ERROR "%s",es); + vlprintf(CN_ERROR, "%s",es); return 1; } @@ -73,7 +73,7 @@ int tex_generate(texture_t *tex) e = glGetError(); if (e != GL_NO_ERROR) { char* es = opengl_error_string(e); - vlprintf(CN_ERROR "%s",es); + vlprintf(CN_ERROR, "%s",es); return 1; } @@ -108,7 +108,7 @@ int tex_generate(texture_t *tex) e = glGetError(); if (e != GL_NO_ERROR) { char* es = opengl_error_string(e); - vlprintf(CN_ERROR "%s",es); + vlprintf(CN_ERROR, "%s",es); return 1; } diff --git a/src/graphics/wm.c b/src/graphics/wm.c index da89144..413d9ad 100644 --- a/src/graphics/wm.c +++ b/src/graphics/wm.c @@ -86,7 +86,7 @@ void wm_capture(char* file) p = image_load_fromscreen(0,0,wm_data.size.width,wm_data.size.height,0); if (!p) { - vlprintf(CN_ERROR "Could not grab screen data"); + vlprintf(CN_ERROR, "Could not grab screen data"); return; } @@ -104,7 +104,7 @@ void wm_capture(char* file) file = "screenshot.bmp"; image_save_bmp(p,file); }else{ - vlprintf(CN_ERROR "Unsupported capture format '%s'",fmt); + vlprintf(CN_WARN, "Unsupported capture format '%s'",fmt); } free(p->pixels); diff --git a/src/graphics/wm_x11.c b/src/graphics/wm_x11.c index b31d1ff..ab4ea03 100644 --- a/src/graphics/wm_x11.c +++ b/src/graphics/wm_x11.c @@ -106,14 +106,14 @@ int wm_init() /* get a connection */ XF86VidModeQueryVersion(wm_data.dpy, &max, &min); - vlprintf(CN_INFO "XF86VidModeExtension version: %d.%d", max, min); + vlprintf(CN_INFO, "XF86VidModeExtension version: %d.%d", max, min); XF86VidModeGetAllModeLines(wm_data.dpy, wm_data.screen, &wm_data.mode_count, &wm_data.modes); /* save desktop resolution before switching modes */ wm_data.deskMode = *wm_data.modes[0]; glXv = (char*)glXGetClientString(wm_data.dpy, GLX_VERSION); - vlprintf(CN_INFO "glX version: %s",glXv,max,min); + vlprintf(CN_INFO, "glX version: %s",glXv,max,min); return wm_create(); } @@ -337,7 +337,7 @@ int wm_create() if (wm_data.dblbuff) db = "Double Buffered "; - vlprintf(CN_INFO "%sDirect Rendering: OpenGL %d.%d",db,major,minor); + vlprintf(CN_INFO, "%sDirect Rendering: OpenGL %d.%d",db,major,minor); } /* MUST be done, else rendering gets messed up */ diff --git a/src/lib/net_tcp.c b/src/lib/net_tcp.c index a200ba6..b175d50 100644 --- a/src/lib/net_tcp.c +++ b/src/lib/net_tcp.c @@ -66,7 +66,7 @@ int tcp_client_reconnect(net_connection_t *n) /* resolve hostname */ if (getaddrinfo(n->host, n->port, &n->hints, &n->addr)) { - vlprintf(CN_ERROR "Unable to resolve host '%s'",n->host); + vlprintf(CN_ERROR, "Unable to resolve host '%s'",n->host); return 1; } @@ -75,14 +75,14 @@ int tcp_client_reconnect(net_connection_t *n) /* open socket */ if ((n->fd = socket(n->addr->ai_family, n->addr->ai_socktype, n->addr->ai_protocol)) == -1) { - vlprintf(CN_ERROR "Unable to reconnect to host %s",n->host); + vlprintf(CN_ERROR, "Unable to reconnect to host %s",n->host); return 1; } /* connect to server */ if (connect(n->fd, n->addr->ai_addr, n->addr->ai_addrlen)) { shutdown(n->fd,2); - vlprintf(CN_ERROR "Unable to reconnect to host %s",n->host); + vlprintf(CN_ERROR, "Unable to reconnect to host %s",n->host); return 1; } @@ -146,7 +146,7 @@ int tcp_host_reconnect(net_connection_t *n) /* resolve hostname */ if (getaddrinfo(nhost, n->port, &n->hints, &n->addr)) { - vlprintf(CN_ERROR "Unable to resolve host '%s'",n->host); + vlprintf(CN_ERROR, "Unable to resolve host '%s'",n->host); return 1; } @@ -155,16 +155,16 @@ int tcp_host_reconnect(net_connection_t *n) /* open socket */ if ((n->fd = socket(n->hints.ai_family, n->hints.ai_socktype, n->hints.ai_protocol)) == -1) { - vlprintf(CN_ERROR "Unable to open port %u",n->port); + vlprintf(CN_ERROR, "Unable to open port %u",n->port); return 1; } /* bind to the socket */ if ((bind(n->fd, n->addr->ai_addr,sizeof(*n->addr->ai_addr))) < 0) { - vlprintf(CN_ERROR "Unable to bind port %u",n->port); + vlprintf(CN_ERROR, "Unable to bind port %u",n->port); return 1; } if (listen(n->fd,64) < 0) { - vlprintf(CN_ERROR "Unable to listen on port %u",n->port); + vlprintf(CN_ERROR, "Unable to listen on port %u",n->port); return 1; } @@ -181,7 +181,7 @@ int tcp_write(net_connection_t *n, void *buff, unsigned int size) if (n->state == NETSTATE_OPEN) { r = (int)write(n->fd,buff,size); if (r < 1) { - vlprintf(CN_ERROR "failed to write to connection %d (%d)",n->fd,errno); + vlprintf(CN_ERROR, "failed to write to connection %d (%d)",n->fd,errno); shutdown(n->fd,2); n->state = NETSTATE_CLOSED; } diff --git a/src/lib/net_udp.c b/src/lib/net_udp.c index 721d32d..d098bc7 100644 --- a/src/lib/net_udp.c +++ b/src/lib/net_udp.c @@ -68,7 +68,7 @@ int udp_client_reconnect(net_connection_t *n) /* resolve hostname */ if (getaddrinfo(n->host, n->port, &n->hints, &n->addr)) { - vlprintf(CN_ERROR "Unable to resolve host '%s'",n->host); + vlprintf(CN_ERROR, "Unable to resolve host '%s'",n->host); return 1; } @@ -77,14 +77,14 @@ int udp_client_reconnect(net_connection_t *n) /* open socket */ if ((n->fd = socket(n->addr->ai_family, n->addr->ai_socktype, n->addr->ai_protocol)) == -1) { - vlprintf(CN_ERROR "Unable to reconnect to host %s",n->host); + vlprintf(CN_ERROR, "Unable to reconnect to host %s",n->host); return 1; } /* connect to server */ if (connect(n->fd, n->addr->ai_addr, n->addr->ai_addrlen)) { shutdown(n->fd,2); - vlprintf(CN_ERROR "Unable to reconnect to host %s",n->host); + vlprintf(CN_ERROR, "Unable to reconnect to host %s",n->host); return 1; } @@ -147,7 +147,7 @@ int udp_host_reconnect(net_connection_t *n) /* resolve hostname */ if (getaddrinfo(nhost, n->port, &n->hints, &n->addr)) { - vlprintf(CN_ERROR "Unable to resolve host '%s'",n->host); + vlprintf(CN_ERROR, "Unable to resolve host '%s'",n->host); return 1; } @@ -156,12 +156,12 @@ int udp_host_reconnect(net_connection_t *n) /* open socket */ if ((n->fd = socket(n->hints.ai_family, n->hints.ai_socktype, n->hints.ai_protocol)) == -1) { - vlprintf(CN_ERROR "Unable to open port %u",n->port); + vlprintf(CN_ERROR, "Unable to open port %u",n->port); return 1; } /* bind to the socket */ if ((bind(n->fd, n->addr->ai_addr,sizeof(*n->addr->ai_addr))) < 0) { - vlprintf(CN_ERROR "Unable to bind port %u",n->port); + vlprintf(CN_ERROR, "Unable to bind port %u",n->port); return 1; } @@ -183,7 +183,7 @@ int udp_write(net_connection_t *n, void *buff, unsigned int size) r = (int)write(n->fd,buff,size); } if (r < 1) { - vlprintf(CN_ERROR "failed to write to connection %d (%d)",n->fd,errno); + vlprintf(CN_ERROR, "failed to write to connection %d (%d)",n->fd,errno); if (n->type != NETTYPE_UDP_HOST) shutdown(n->fd,2); n->state = NETSTATE_CLOSED; diff --git a/src/ui/ui.c b/src/ui/ui.c index 2ee3b38..7f2d09f 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -175,7 +175,7 @@ void ui_msg(uint8_t type, char* txt, int (*func)(), ...) widget_t *con; if (!(type == UIMSG_OC || type == UIMSG_OK || type == UIMSG_YN) || !txt) { - vlprintf(CN_WARN "Invalid message type: %d",type); + vlprintf(CN_WARN, "Invalid message type: %d",type); return; } -- 2.11.4.GIT