From acb0d0eb1311adf035876a450699b9dff004c5eb Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 12 Feb 2012 02:32:40 +1000 Subject: Make sendBack and Forth varargs. --- LuaSL/src/LuaSL.h | 4 ++-- LuaSL/src/LuaSL_utilities.c | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'LuaSL') diff --git a/LuaSL/src/LuaSL.h b/LuaSL/src/LuaSL.h index 723f00d..9f55e2a 100644 --- a/LuaSL/src/LuaSL.h +++ b/LuaSL/src/LuaSL.h @@ -64,8 +64,8 @@ typedef struct void loggingStartup(gameGlobals *game); char *getDateTime(struct tm **nowOut, char *dateOut, time_t *tiemOut); -void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message); -void sendForth(gameGlobals *game, const char *SID, const char *message); +void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message, ...); +void sendForth(gameGlobals *game, const char *SID, const char *message, ...); float timeDiff(struct timeval *now, struct timeval *then); #include "LuaSL_LSL_tree.h" diff --git a/LuaSL/src/LuaSL_utilities.c b/LuaSL/src/LuaSL_utilities.c index ab4ea65..e43bdeb 100644 --- a/LuaSL/src/LuaSL_utilities.c +++ b/LuaSL/src/LuaSL_utilities.c @@ -66,20 +66,36 @@ char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) return (dateTime); } -void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message) +void sendBack(gameGlobals *game, Ecore_Con_Client *client, const char *SID, const char *message, ...) { + va_list args; char buf[PATH_MAX]; - - sprintf(buf, "%s.%s\n", SID, message); + int length = strlen(SID); + + strncpy(buf, SID, length); + buf[length++] = '.'; + va_start(args, message); + length += vsprintf(&buf[length], message, args); + va_end(args); + buf[length++] = '\n'; + buf[length++] = '\0'; ecore_con_client_send(client, buf, strlen(buf)); ecore_con_client_flush(client); } -void sendForth(gameGlobals *game, const char *SID, const char *message) +void sendForth(gameGlobals *game, const char *SID, const char *message, ...) { + va_list args; char buf[PATH_MAX]; - - snprintf(buf, sizeof(buf), "%s.%s\n", SID, message); + int length = strlen(SID); + + strncpy(buf, SID, length); + buf[length++] = '.'; + va_start(args, message); + length += vsprintf(&buf[length], message, args); + va_end(args); + buf[length++] = '\n'; + buf[length++] = '\0'; ecore_con_server_send(game->server, buf, strlen(buf)); ecore_con_server_flush(game->server); } -- cgit v1.1