[mw-devel] MW3 r1360 - trunk/src/client

arthur at sucs.org arthur at sucs.org
Tue Nov 26 19:47:38 GMT 2013


Author: arthur
Date: 2013-11-26 19:47:38 +0000 (Tue, 26 Nov 2013)
New Revision: 1360

Modified:
   trunk/src/client/main.c
   trunk/src/client/main.h
   trunk/src/client/who.c
Log:
fix doing/what by forcing the output through display_message so that colour codes get properly translated


Modified: trunk/src/client/main.c
===================================================================
--- trunk/src/client/main.c	2013-11-26 17:22:29 UTC (rev 1359)
+++ trunk/src/client/main.c	2013-11-26 19:47:38 UTC (rev 1360)
@@ -1109,6 +1109,17 @@
 
 }
 
+void format_message(const char *format, ...)
+{
+	char * text = NULL;
+	va_list va;
+	va_start(va, format);
+	vasprintf(&text, format, va);
+	va_end(va);
+	display_message(text, 0, 1);
+	free(text);
+}
+
 void display_message(const char *text, int beeps, int newline)
 {
 	static int	count = 0;

Modified: trunk/src/client/main.h
===================================================================
--- trunk/src/client/main.h	2013-11-26 17:22:29 UTC (rev 1359)
+++ trunk/src/client/main.h	2013-11-26 19:47:38 UTC (rev 1360)
@@ -3,6 +3,7 @@
 
 void close_down(int exitmode, char *sourceuser, char *reason);
 void display_message(const char *text, int beeps, int newline);
+void format_message(const char *format, ...) __attribute__((format(printf,1,0)));
 void printfile(char *filename);
 void broadcast_onoffcode(int code, int method, const char *sourceuser, const char *reason);
 void reset_timeout(int secs);

Modified: trunk/src/client/who.c
===================================================================
--- trunk/src/client/who.c	2013-11-26 17:22:29 UTC (rev 1359)
+++ trunk/src/client/who.c	2013-11-26 19:47:38 UTC (rev 1360)
@@ -20,11 +20,13 @@
 #include "talker.h"
 #include "userio.h"
 #include "who.h"
+#include "main.h"
 
 extern int busy;
 extern struct person *user;
 extern struct room myroom;
 
+/* called only by cmdline flags */
 void what_list(void) {
 	struct person	u;
 	int		ufile;
@@ -67,15 +69,15 @@
 	if (s_wizchat(user->special)) wizchat=1; else wizchat=0;
 
 	if (mode==1) 
-		printf("\nUser status...\n");
+		format_message("\nUser status...");
 	else
-	if (wiz) printf("\nPID    %-*s %-*s  Idle  What...\n",NAMESIZE,"Name",20,"RealName");
-	else printf("\n %-*s Idle   What...\n",NAMESIZE,"Name");
+	if (wiz) format_message("\nPID    %-*s %-*s  Idle  What...",NAMESIZE,"Name",20,"RealName");
+	else format_message("\n %-*s Idle   What...",NAMESIZE,"Name");
 
 	divider = NULL;
 	for (int i = 0; i < screen_w(); i++) string_add(&divider, "-");
 
-	printf("%s\n", divider);
+	format_message("%s", divider);
 
 	while (read(wfile,&w,sizeof(w)))
 	{
@@ -99,7 +101,7 @@
 		{
 			if (mode == 1) {
 				if (u.dowhen && u.doing[0] != 0)
-				printf("%s %s (%s ago)\n",u.name, u.doing ,itime(time(0)-u.dowhen));
+				format_message("%s %s\033-- (%s ago)",u.name, u.doing ,itime(time(0)-u.dowhen));
 			} else {
 			if (cm_flags(u.chatmode,CM_ONCHAT,CM_MODE_ANY))
 			{
@@ -172,16 +174,15 @@
 
 			if (wiz)
 			{
-				printf("%-5d %c%-*s %-20.20s %6s %s\n",w.pid,chat,NAMESIZE,u.name,u.realname,itime(time(0)-u.idletime),u.doing);
+				format_message("%-5d %c%-*s %-20.20s %6s %s\033--",w.pid,chat,NAMESIZE,u.name,u.realname,itime(time(0)-u.idletime),u.doing);
 			}else
 			{
-				printf("%c%-*s %6s %s\n",wizchat?chat:' ',NAMESIZE,u.name,itime(time(0)-u.idletime),u.doing);
+				format_message("%c%-*s %6s %s\033--",wizchat?chat:' ',NAMESIZE,u.name,itime(time(0)-u.idletime),u.doing);
 			}
 			}
 		}
 	}
-	printf("%s\n", divider);
-	putchar('\n');
+	format_message("%s", divider);
 	close(wfile);
 	close(ufile);
 




More information about the mw-devel mailing list