From f2316f12e24e940c58590502075d21a46d783619 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sat, 16 Jul 2011 19:15:08 +0000 Subject: [PATCH] Lua: statusmessage() now clears remainder of line git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1820 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/factory.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/factory.c b/src/factory.c index 7b2521c3..469f9a85 100644 --- a/src/factory.c +++ b/src/factory.c @@ -58,6 +58,7 @@ char * Bound_script[10]; #include // for DBL_MAX #include // chdir() #include //for INT_MIN +#include // strncpy() /// /// Number of characters for name in fileselector. @@ -1261,18 +1262,28 @@ int L_UpdateScreen(lua_State* L) int L_StatusMessage(lua_State* L) { - const char* msg; - char* msg2; - int nb_args = lua_gettop(L); - LUA_ARG_LIMIT(1,"statusmessage"); + const char* msg; + char msg2[25]; + int len; + int nb_args = lua_gettop(L); + LUA_ARG_LIMIT(1,"statusmessage"); - LUA_ARG_STRING(1, "statusmessage", msg); - msg2 = strdup(msg); - if(strlen(msg)>24) - msg2[24] = 0; // Cut off long messages - Print_in_menu(msg2,0); - free(msg2); - return 0; + LUA_ARG_STRING(1, "statusmessage", msg); + len=strlen(msg); + if (len<=24) + { + strcpy(msg2, msg); + // fill remainder with spaces + for (;len<24;len++) + msg2[len]=' '; + msg2[24]='\0'; + } + else + { + strncpy(msg2, msg, 24); + } + Print_in_menu(msg2,0); + return 0; }