Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/msgc don't bother calculated up MAXSTR, especially s...



details:   https://anonhg.NetBSD.org/src/rev/cd09a39b85d8
branches:  trunk
changeset: 473934:cd09a39b85d8
user:      cgd <cgd%NetBSD.org@localhost>
date:      Tue Jun 22 15:00:37 1999 +0000

description:
don't bother calculated up MAXSTR, especially since the value calculated
is _bogus_ in the face of printf-like message formatting!  Instead,
calcuate the max size to format when the message window is set.  We know
that we'll never want to format more characters than can fit in the window.

diffstat:

 usr.bin/msgc/msg_sys.def |  24 ++++++++++++++++++++----
 usr.bin/msgc/msgdb.c     |  11 +++--------
 2 files changed, 23 insertions(+), 12 deletions(-)

diffs (103 lines):

diff -r 559fbfd4db0b -r cd09a39b85d8 usr.bin/msgc/msg_sys.def
--- a/usr.bin/msgc/msg_sys.def  Tue Jun 22 14:51:57 1999 +0000
+++ b/usr.bin/msgc/msg_sys.def  Tue Jun 22 15:00:37 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_sys.def,v 1.5 1999/06/19 00:40:29 cgd Exp $        */
+/*     $NetBSD: msg_sys.def,v 1.6 1999/06/22 15:00:37 cgd Exp $        */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -37,7 +37,8 @@
  */
 
 static WINDOW *msg_win = NULL;
-static char cbuffer [ MAXSTR ];
+static char *cbuffer;
+static size_t cbuffersize;
 static int do_echo = 1;
 
 /* Routines */
@@ -47,9 +48,24 @@
        fprintf (stderr, "\a");
 }
 
-void msg_window(WINDOW *window)
+int msg_window(WINDOW *window)
 {
+       size_t ncbuffersize;
+       char *ncbuffer;
+
        msg_win = window;
+
+       ncbuffersize = getmaxx(window) * getmaxy(window) + 1;
+       if (ncbuffersize > cbuffersize) {
+               ncbuffer = malloc(ncbuffersize);
+               if (ncbuffer == NULL)
+                       return 1;
+               if (cbuffer != NULL)
+                       free(cbuffer);
+               cbuffer = ncbuffer;
+               cbuffersize = ncbuffersize;
+       }
+       return 0;
 }
 
 char *msg_string (int msg_no)
@@ -77,7 +93,7 @@
 {
        int ret;
 
-       ret = vsnprintf (cbuffer, MAXSTR, fmt, ap);
+       ret = vsnprintf (cbuffer, cbuffersize, fmt, ap);
        waddstr (msg_win, cbuffer);
        wrefresh (msg_win);
        return ret;
diff -r 559fbfd4db0b -r cd09a39b85d8 usr.bin/msgc/msgdb.c
--- a/usr.bin/msgc/msgdb.c      Tue Jun 22 14:51:57 1999 +0000
+++ b/usr.bin/msgc/msgdb.c      Tue Jun 22 15:00:37 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msgdb.c,v 1.4 1999/06/19 19:25:10 cgd Exp $    */
+/*     $NetBSD: msgdb.c,v 1.5 1999/06/22 15:00:37 cgd Exp $    */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -46,11 +46,9 @@
 
 static struct id_rec *head = NULL, *tail = NULL;
 static int msg_no = 0;
-static int maxstr = 1;
 
 void define_msg (char *name, char *value)
 {
-       int vlen = strlen(value);
        struct id_rec *tmp = (struct id_rec *)malloc(sizeof(struct id_rec));
 
        if (find_id (root, name))
@@ -68,9 +66,6 @@
        }
 
        insert_id (&root, tmp);
-
-       if (vlen > maxstr)
-               maxstr = vlen;
 }
 
 static void write_str (FILE *f, char *str)
@@ -148,7 +143,7 @@
                "\n"
                "/* Prototypes */\n"
                "void msg_beep(void);\n"
-               "void msg_window(WINDOW *window);\n"
+               "int  msg_window(WINDOW *window);\n"
                "char *msg_string (int msg_no);\n"
                "void msg_clear(void);\n"
                "void msg_standout(void);\n"
@@ -175,7 +170,7 @@
                (void) fprintf (out_file, "#define MSG_%s\t%d\n",
                                t->id, t->msg_no);
        }
-       (void) fprintf (out_file, "#define MAXSTR %d\n\n#endif\n", 2*maxstr);
+       (void) fprintf (out_file, "\n#endif\n");
 
        fclose (out_file);
 



Home | Main Index | Thread Index | Old Index