From 9c4f2d32ca77635510c7e2142c9480025cad96f2 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 6 Oct 2002 04:40:18 +0000 Subject: [PATCH] Add print and print.center GIB commands and fix a nasty bug with threads that could cause a double free. --- libs/console/client.c | 18 ++++++++++++++++++ libs/util/gib_builtin.c | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libs/console/client.c b/libs/console/client.c index 87453f070..cbf82aaa9 100644 --- a/libs/console/client.c +++ b/libs/console/client.c @@ -55,6 +55,7 @@ static const char rcsid[] = #include "QF/sys.h" #include "QF/va.h" #include "QF/vid.h" +#include "QF/gib_builtin.h" #include "compat.h" @@ -339,6 +340,19 @@ C_SayTeam (const char *line) } +void +C_GIB_Print_Center_f (void) +{ + if (GIB_Argc () != 2) { + Cbuf_Error ("syntax", + "print.center: invalid syntax\n" + "usage: print.center text"); + return; + } + SCR_CenterPrint (GIB_Argv(1)); +} + + static void C_Init (void) { @@ -393,6 +407,10 @@ C_Init (void) Cmd_AddCommand ("clear", Clear_f, "Clear the console"); Cmd_AddCommand ("condump", Condump_f, "dump the console text to a " "file"); + + // register GIB builtins + GIB_Builtin_Add ("print.center", C_GIB_Print_Center_f, GIB_BUILTIN_NORMAL); + con_initialized = true; } diff --git a/libs/util/gib_builtin.c b/libs/util/gib_builtin.c index 406b663bf..c63af9229 100644 --- a/libs/util/gib_builtin.c +++ b/libs/util/gib_builtin.c @@ -477,7 +477,9 @@ GIB_Thread_Kill_f (void) return; } for (cur = thread->cbuf; cur; cur = cur->down) { - GIB_DATA(cur)->type = GIB_BUFFER_NORMAL; + // Kill all loops + if (GIB_DATA(cur)->type == GIB_BUFFER_LOOP) + GIB_DATA(cur)->type = GIB_BUFFER_PROXY; // Proxy to prevent shared locals being freed dstring_clearstr (cur->line); dstring_clearstr (cur->buf); } @@ -660,6 +662,18 @@ GIB_Range_f (void) dstring_delete (dstr); } +void +GIB_Print_f (void) +{ + if (GIB_Argc() != 2) { + Cbuf_Error ("syntax", + "print: invalid syntax\n" + "usage: print text"); + return; + } + Sys_Printf ("%s", GIB_Argv(1)); +} + void GIB_Builtin_Init (void) { @@ -685,4 +699,5 @@ GIB_Builtin_Init (void) GIB_Builtin_Add ("file.write", GIB_File_Write_f, GIB_BUILTIN_NORMAL); GIB_Builtin_Add ("file.find", GIB_File_Find_f, GIB_BUILTIN_NORMAL); GIB_Builtin_Add ("range", GIB_Range_f, GIB_BUILTIN_NORMAL); + GIB_Builtin_Add ("print", GIB_Print_f, GIB_BUILTIN_NORMAL); }