Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/msgc Introduce _fmt_ flavors of the menu functions t...



details:   https://anonhg.NetBSD.org/src/rev/a5de49e88b59
branches:  trunk
changeset: 452155:a5de49e88b59
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 20 00:45:18 2019 +0000

description:
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.

diffstat:

 usr.bin/msgc/msg_sys.def |  109 ++++++++++++++++++++++++++++++++++------------
 usr.bin/msgc/msgdb.c     |   52 ++++++++++++++++-----
 2 files changed, 120 insertions(+), 41 deletions(-)

diffs (285 lines):

diff -r 2dc3f7fcb6e1 -r a5de49e88b59 usr.bin/msgc/msg_sys.def
--- a/usr.bin/msgc/msg_sys.def  Thu Jun 20 00:43:55 2019 +0000
+++ b/usr.bin/msgc/msg_sys.def  Thu Jun 20 00:45:18 2019 +0000
@@ -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 @@
        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 @@
 }
 
 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 @@
        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 @@
 }
 
 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 @@
        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_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 @@
        }
 }
 
-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);
 }
 
diff -r 2dc3f7fcb6e1 -r a5de49e88b59 usr.bin/msgc/msgdb.c
--- a/usr.bin/msgc/msgdb.c      Thu Jun 20 00:43:55 2019 +0000
+++ b/usr.bin/msgc/msgdb.c      Thu Jun 20 00:45:18 2019 +0000
@@ -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 @@
                "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"



Home | Main Index | Thread Index | Old Index