Module Name:    src
Committed By:   christos
Date:           Thu Jun 20 00:45:18 UTC 2019

Modified Files:
        src/usr.bin/msgc: msg_sys.def msgdb.c

Log Message:
Introduce _fmt_ flavors of the menu functions that take a formatting string
so we can use fmtcheck(3) to check the formats of the messages strings.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/msgc/msg_sys.def
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/msgc/msgdb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/msgc/msg_sys.def
diff -u src/usr.bin/msgc/msg_sys.def:1.44 src/usr.bin/msgc/msg_sys.def:1.45
--- src/usr.bin/msgc/msg_sys.def:1.44	Fri Mar  1 12:02:21 2019
+++ src/usr.bin/msgc/msg_sys.def	Wed Jun 19 20:45:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_sys.def,v 1.44 2019/03/01 17:02:21 martin Exp $	*/
+/*	$NetBSD: msg_sys.def,v 1.45 2019/06/20 00:45:18 christos Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -158,7 +158,7 @@ msg_standend(void)
 	wstandend(msg_win);
 }
 
-static int
+static int __printflike(2, 0)
 _msg_vprintf(int auto_fill, const char *fmt, va_list ap)
 {
 	const char *wstart, *afterw;
@@ -285,28 +285,42 @@ out:
 }
 
 void
-msg_display(msg msg_no, ...)
+msg_display(msg msg_no)
+{
+
+	msg_printf("%s", msg_string(msg_no));
+}
+
+void __printflike(2, 3)
+msg_fmt_display(msg msg_no, const char *fmt, ...)
 {
 	va_list ap;
 
 	msg_clear();
 
-	va_start(ap, msg_no);
-	(void)_msg_vprintf(1, msg_string(msg_no), ap);
+	va_start(ap, fmt);
+	(void)_msg_vprintf(1, fmtcheck(msg_string(msg_no), fmt), ap);
 	va_end(ap);
 }
 
 void
-msg_display_add(msg msg_no, ...)
+msg_display_add(msg msg_no)
+{
+
+	msg_printf("%s", msg_string(msg_no));
+}
+
+void __printflike(2, 3)
+msg_fmt_display_add(msg msg_no, const char *fmt, ...)
 {
 	va_list ap;
 
-	va_start(ap, msg_no);
-	(void)_msg_vprintf(1, msg_string(msg_no), ap);
+	va_start(ap, fmt);
+	(void)_msg_vprintf(1, fmtcheck(msg_string(msg_no), fmt), ap);
 	va_end(ap);
 }
 
-void
+void __printflike(1, 2)
 msg_printf(const char *fmt, ...)
 {
 	va_list ap;
@@ -316,7 +330,7 @@ msg_printf(const char *fmt, ...)
 	va_end(ap);
 }
 
-static void
+static void __printflike(1, 0)
 _msg_vprompt(const char *fmt, int flags, const char *def, char *val,
     size_t val_buf_len, va_list ap)
 {
@@ -469,21 +483,36 @@ _msg_vprompt(const char *fmt, int flags,
 }
 
 void
-msg_prompt(msg msg_no, const char *def, char *val, size_t val_buf_len, ...)
+msg_prompt(msg msg_no, const char *def, char *val, size_t val_buf_len)
+{
+
+	msg_fmt_prompt(msg_no, def, val, val_buf_len, "");
+}
+
+void __printflike(5, 6)
+msg_fmt_prompt(msg msg_no, const char *def, char *val, size_t val_buf_len,
+    const char *fmt, ...)
 {
 	va_list ap;
 
 	msg_clear();
 
-	va_start(ap, val_buf_len);
-	_msg_vprompt(msg_string(msg_no), MSG_PROMPT_ECHO,
+	va_start(ap, fmt);
+	_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), MSG_PROMPT_ECHO,
 		def, val, val_buf_len, ap);
 	va_end(ap);
 }
 
 void
 msg_prompt_win(msg msg_no, int x, int y, int w, int h,
-	const char *def, char *val, size_t val_buf_len, ...)
+    const char *def, char *val, size_t val_buf_len)
+{
+    msg_fmt_prompt_win(msg_no, x, y, w, h, def, val, val_buf_len, "");
+}
+
+void __printflike(9, 10)
+msg_fmt_prompt_win(msg msg_no, int x, int y, int w, int h,
+    const char *def, char *val, size_t val_buf_len, const char *fmt, ...)
 {
 	va_list ap;
 	WINDOW *win;
@@ -495,10 +524,10 @@ msg_prompt_win(msg msg_no, int x, int y,
 	maxx = getmaxx(msg_win);
 	maxy = getmaxy(msg_win);
 	if (w == 0) {
-		va_start(ap, val_buf_len);
-		w = vsnprintf(NULL, 0, msg_string(msg_no), ap);
+		va_start(ap, fmt);
+		w = vsnprintf(NULL, 0, fmtcheck(msg_string(msg_no), fmt), ap);
 		va_end(ap);
-		if (def != NULL && *def != 0 && w + (int)val_buf_len * 2 < maxx) {
+		if (def != NULL && *def != 0 && w + (int)val_buf_len * 2 < maxx) 		{
 			w += 2 + strlen(def) + 1;
 			msg_flags &= ~MSG_PROMPT_HIDE_DFLT;
 		}
@@ -561,7 +590,7 @@ msg_prompt_win(msg msg_no, int x, int y,
 		msg_clear();
 	}
 
-	va_start(ap, val_buf_len);
+	va_start(ap, fmt);
 	_msg_vprompt(msg_string(msg_no), msg_flags, def, val, val_buf_len, ap);
 	va_end(ap);
 
@@ -579,35 +608,59 @@ msg_prompt_win(msg msg_no, int x, int y,
 	}
 }
 
-void
-msg_prompt_add(msg msg_no, const char *def, char *val, size_t val_buf_len, ...)
+void 
+msg_prompt_add(msg msg_no, const char *def, char *val, size_t val_buf_len)
+{
+
+	msg_fmt_prompt_add(msg_no, def, val, val_buf_len, "");
+}
+
+void __printflike(5, 6)
+msg_fmt_prompt_add(msg msg_no, const char *def, char *val, size_t val_buf_len,
+    const char *fmt, ...)
 {
 	va_list ap;
 
-	va_start(ap, val_buf_len);
-	_msg_vprompt(msg_string(msg_no), MSG_PROMPT_ECHO, def, val, val_buf_len, ap);
+	va_start(ap, fmt);
+	_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), MSG_PROMPT_ECHO, def,
+	    val, val_buf_len, ap);
 	va_end(ap);
 }
 
 void
-msg_prompt_noecho(msg msg_no, const char *def, char *val, size_t val_buf_len, ...)
+msg_prompt_noecho(msg msg_no, const char *def, char *val, size_t val_buf_len)
+{
+	msg_fmt_prompt_noecho(msg_no, def, val, val_buf_len, "");
+}
+
+void __printflike(5, 6)
+msg_fmt_prompt_noecho(msg msg_no, const char *def, char *val,
+    size_t val_buf_len, const char *fmt, ...)
 {
 	va_list ap;
 
 	msg_clear();
 
-	va_start(ap, val_buf_len);
-	_msg_vprompt(msg_string(msg_no), 0, def, val, val_buf_len, ap);
+	va_start(ap, fmt);
+	_msg_vprompt(fmtcheck(msg_string(msg_no), fmt), 0, def, val,
+	    val_buf_len, ap);
 	va_end(ap);
 }
 
 void
-msg_table_add(msg msg_no, ...)
+msg_table_add(msg msg_no)
+{
+
+	msg_printf("%s", msg_string(msg_no));
+}
+
+void __printflike(2, 3)
+msg_fmt_table_add(msg msg_no, const char *fmt, ...)
 {
 	va_list ap;
 
-	va_start(ap, msg_no);
-	(void)_msg_vprintf(0, msg_string(msg_no), ap);
+	va_start(ap, fmt);
+	(void)_msg_vprintf(0, fmtcheck(msg_string(msg_no), fmt), ap);
 	va_end(ap);
 }
 

Index: src/usr.bin/msgc/msgdb.c
diff -u src/usr.bin/msgc/msgdb.c:1.23 src/usr.bin/msgc/msgdb.c:1.24
--- src/usr.bin/msgc/msgdb.c:1.23	Tue Mar  6 11:26:01 2012
+++ src/usr.bin/msgc/msgdb.c	Wed Jun 19 20:45:18 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msgdb.c,v 1.23 2012/03/06 16:26:01 mbalmer Exp $	*/
+/*	$NetBSD: msgdb.c,v 1.24 2019/06/20 00:45:18 christos Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -41,7 +41,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: msgdb.c,v 1.23 2012/03/06 16:26:01 mbalmer Exp $");
+__RCSID("$NetBSD: msgdb.c,v 1.24 2019/06/20 00:45:18 christos Exp $");
 #endif
 
 
@@ -162,18 +162,44 @@ write_msg_file ()
 		"void msg_clear(void);\n"
 		"void msg_standout(void);\n"
 		"void msg_standend(void);\n"
-		"void msg_display(msg msg_no,...);\n"
-		"void msg_display_add(msg msg_no,...);\n"
 		"void msg_printf(const char *fmt, ...) __printflike(1, 2);\n"
-		"void msg_prompt (msg msg_no, const char *def,"
-			" char *val, size_t max_chars, ...);\n"
-		"void msg_prompt_add (msg msg_no, const char *def,"
-			" char *val, size_t max_chars, ...);\n"
-		"void msg_prompt_noecho (msg msg_no, const char *def,"
-			" char *val, size_t max_chars, ...);\n"
-		"void msg_prompt_win (msg, int, int, int, int,"
-			" const char *, char *, size_t, ...);\n"
-		"void msg_table_add(msg msg_no,...);\n"
+		"void msg_display(msg msg_no);\n"
+		"void msg_fmt_display(msg msg_no, const char *fmt, ...)"
+			" __printflike(2, 3);\n"
+
+		"void msg_display_add(msg msg_no);\n"
+		"void msg_fmt_display_add(msg msg_no, const char *fmt, ...);\n"
+
+		"void msg_prompt(msg msg_no, const char *def,"
+			" char *val, size_t max_chars);\n"
+		"void msg_fmt_prompt(msg msg_no, const char *def,"
+			" char *val, size_t max_chars, const char *fmt, ...)"
+			" __printflike(5, 6);\n"
+
+		"void msg_prompt_add(msg msg_no, const char *def,"
+			" char *val, size_t max_chars);\n"
+		"void msg_fmt_prompt_add(msg msg_no, const char *def,"
+			" char *val, size_t max_chars, const char *fmt, ...)"
+			" __printflike(5, 6);\n"
+
+		"void msg_prompt_noecho(msg msg_no, const char *def,"
+			" char *val, size_t max_chars);\n"
+		"void msg_fmt_prompt_noecho(msg msg_no, const char *def,"
+			" char *val, size_t max_chars, const char *fmt, ...)"
+			" __printflike(5, 6);\n"
+
+		"void msg_prompt_win(msg msg_no, int x, int y, int w,"
+			" int h, const char *def, char *val,"
+			" size_t max_chars);\n"
+		"void msg_fmt_prompt_win(msg msg_no, int x, int y, int w,"
+			" int h, const char *def, char *val, size_t max_chars,"
+			" const char *fmt, ...)"
+			" __printflike(9, 10);\n"
+
+		"void msg_table_add(msg msg_no);"
+		"void msg_fmt_table_add(msg msg_no, const char *fmt, ...)"
+			" __printflike(2, 3);\n"
+
 		"int msg_row(void);\n"
 		"\n"
 		"/* Message names */\n"

Reply via email to