chiark / gitweb /
Add documentation for `msg'.
[mgLib] / msg.c
diff --git a/msg.c b/msg.c
index 6c0ca9dae6997735e6b79263a12189984139e1eb..08a02851248054ef99c8b412fd5074ab2492048b 100644 (file)
--- a/msg.c
+++ b/msg.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: msg.c,v 1.1 1998/12/11 09:44:21 mdw Exp $
+ * $Id: msg.c,v 1.4 1999/04/29 20:48:13 mdw Exp $
  *
  * Display a message and get an answer
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: msg.c,v $
+ * Revision 1.4  1999/04/29 20:48:13  mdw
+ * Add documentation for `msg'.
+ *
+ * Revision 1.3  1999/03/25 23:36:10  mdw
+ * Compile to nothing in absence of GTK, for the benefit of parent packages
+ * which contain non-GTK-dependent parts.
+ *
+ * Revision 1.2  1998/12/15 23:48:06  mdw
+ * Use `dstr_putf' for formatting, rather than `sprintf'.
+ *
  * Revision 1.1  1998/12/11 09:44:21  mdw
  * Initial version.
  *
  */
 
+#ifdef HAVE_GTK
+
 /*----- Header files ------------------------------------------------------*/
 
 #include <stdarg.h>
@@ -44,6 +56,7 @@
 #include <gtk/gtk.h>
 
 #include <mLib/alloc.h>
+#include <mLib/dstr.h>
 
 #include "cancel.h"
 #include "mdwfocus.h"
@@ -65,6 +78,14 @@ static int creply;
  *
  * Use:                Displays a message to the user in a nice dialogue box and
  *             returns the index of the button selected.
+ *
+ *             The @msg@ argument is a @printf@-style format string, which
+ *             contains the message to actually be shown.  The @buttons@
+ *             argument is a comma-separated list of buttons to be drawn,
+ *             from right to left.  A button name can be preceded with `:'
+ *             to indicate that it's the default, or `~' if it's the
+ *             `cancel' button.  The return value is the zero-based index
+ *             of the button selected.
  */
 
 static int close(GtkWidget *w, gpointer p)
@@ -94,21 +115,19 @@ int msg(const char *buttons, const char *msg, ...)
   /* --- Set up the message string --- */
 
   {
-    char buf[1024];
+    dstr d;
     va_list ap;
 
     va_start(ap, msg);
-#ifdef HAVE_VSNPRINTF
-    vsnprintf(buf, sizeof(buf), msg, ap);
-#else
-    vsprintf(buf, sizeof(buf), msg, ap);
-#endif
+    dstr_create(&d);
+    dstr_vputf(&d, msg, ap);
     va_end(ap);
-    w = gtk_label_new(buf);
+    w = gtk_label_new(d.buf);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dbox)->vbox), w, 1, 1, 0);
     gtk_window_position(GTK_WINDOW(dbox), GTK_WIN_POS_MOUSE);
     gtk_widget_show(w);
     gtk_misc_set_padding(GTK_MISC(w), 16, 16);
+    dstr_destroy(&d);
   }
 
   /* --- Set up the buttons --- */
@@ -153,10 +172,14 @@ int msg(const char *buttons, const char *msg, ...)
        cancel(GTK_WINDOW(dbox), w);
       gtk_widget_show(w);
     }
+    free(p);
+
+    /* --- Preflight checklist --- */
 
     gtk_widget_realize(dbox);
     if (f & f_mdwfocus)
       mdwfocus(dbox);
+
   }
 
   /* --- Ready --- */
@@ -170,3 +193,7 @@ int msg(const char *buttons, const char *msg, ...)
 }
 
 /*----- That's all, folks -------------------------------------------------*/
+
+#else
+  int mgLib_msg = 0;
+#endif