* util.c (msglen): Constify first argument.

* wtools.c (query_dialog): Constify string argments.
(create_message): New function, forked from message().
(message): Return void.  Allocate memory dynamically.
* wtools.h: Eliminate D_INSERT.  Adjust all users.
This commit is contained in:
Pavel Roskin 2003-10-25 21:12:05 +00:00
parent 2d33b5047e
commit f75d4598eb
7 changed files with 73 additions and 45 deletions

View File

@ -1,5 +1,11 @@
2003-10-25 Pavel Roskin <proski@gnu.org> 2003-10-25 Pavel Roskin <proski@gnu.org>
* util.c (msglen): Constify first argument.
* wtools.c (query_dialog): Constify string argments.
(create_message): New function, forked from message().
(message): Return void. Allocate memory dynamically.
* wtools.h: Eliminate D_INSERT. Adjust all users.
* background.c: Replace all message stubs with a new function * background.c: Replace all message stubs with a new function
mc_message(). Protect against strlen(MSG_ERROR). Adjust all mc_message(). Protect against strlen(MSG_ERROR). Adjust all
dependencies. dependencies.

View File

@ -76,7 +76,7 @@ static char* learn_title = N_("Learn keys");
static int learn_button (int action) static int learn_button (int action)
{ {
unsigned char *seq; unsigned char *seq;
Dlg_head *d = message (D_INSERT | 1, _(" Teach me a key "), Dlg_head *d = create_message (D_ERROR, _(" Teach me a key "),
_("Please press the %s\n" _("Please press the %s\n"
"and then wait until this message disappears.\n\n" "and then wait until this message disappears.\n\n"
"Then, press it again to see if OK appears\n" "Then, press it again to see if OK appears\n"

View File

@ -90,7 +90,7 @@ is_printable (int c)
} }
/* Returns the message dimensions (lines and columns) */ /* Returns the message dimensions (lines and columns) */
int msglen (char *text, int *lines) int msglen (const char *text, int *lines)
{ {
int max = 0; int max = 0;
int line_len = 0; int line_len = 0;

View File

@ -7,7 +7,7 @@
/* String managing functions */ /* String managing functions */
int is_printable (int c); int is_printable (int c);
int msglen (char *text, int *lines); int msglen (const char *text, int *lines);
char *trim (char *s, char *d, int len); char *trim (char *s, char *d, int len);
char *name_quote (const char *c, int quote_percent); char *name_quote (const char *c, int quote_percent);
char *fake_name_quote (const char *c, int quote_percent); char *fake_name_quote (const char *c, int quote_percent);

View File

@ -1595,7 +1595,7 @@ search (WView *view, char *text,
got_interrupt (); got_interrupt ();
if (verbose) { if (verbose) {
d = message (D_INSERT, _("Search"), _("Searching %s"), text); d = create_message (D_NORMAL, _("Search"), _("Searching %s"), text);
mc_refresh (); mc_refresh ();
} }

View File

@ -1,7 +1,3 @@
/* {{{ */
/* {{{ Copyright Notice */
/* Widget based utility functions. /* Widget based utility functions.
Copyright (C) 1994, 1995 the Free Software Foundation Copyright (C) 1994, 1995 the Free Software Foundation
@ -26,8 +22,6 @@
*/ */
/* }}} */
#include <config.h> #include <config.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -45,9 +39,6 @@
#include "key.h" /* For mi_getch() */ #include "key.h" /* For mi_getch() */
#include "complete.h" /* INPUT_COMPLETE_CD */ #include "complete.h" /* INPUT_COMPLETE_CD */
/* }}} */
/* {{{ Listbox utility functions */
Listbox * Listbox *
create_listbox_window (int cols, int lines, char *title, char *help) create_listbox_window (int cols, int lines, char *title, char *help)
@ -100,17 +91,14 @@ int run_listbox (Listbox *l)
return val; return val;
} }
/* }}} */
/* {{{ Query Dialog functions */
static Dlg_head *last_query_dlg; static Dlg_head *last_query_dlg;
static int sel_pos = 0; static int sel_pos = 0;
/* Used to ask questions to the user */ /* Used to ask questions to the user */
int int
query_dialog (char *header, char *text, int flags, int count, ...) query_dialog (const char *header, const char *text, int flags, int count, ...)
{ {
va_list ap; va_list ap;
Dlg_head *query_dlg; Dlg_head *query_dlg;
@ -205,38 +193,70 @@ void query_set_sel (int new_sel)
sel_pos = new_sel; sel_pos = new_sel;
} }
/* }}} */
/* {{{ The message function */ /* Create message dialog */
static struct Dlg_head *
/* To show nice messages to the users */ do_create_message (int flags, const char *title, const char *text)
struct Dlg_head *
message (int error, char *header, const char *text, ...)
{ {
va_list args; char *p;
char buffer [4096];
Dlg_head *d; Dlg_head *d;
/* Setup the display information */ /* Add empty lines before and after the message */
strcpy (buffer, "\n"); p = g_strdup_printf ("\n%s\n", text);
va_start (args, text); query_dialog (title, p, flags, 0);
g_vsnprintf (&buffer [1], sizeof (buffer) - 2, text, args);
strcat (buffer, "\n");
va_end (args);
query_dialog (header, buffer, error, 0);
d = last_query_dlg; d = last_query_dlg;
init_dlg (d); init_dlg (d);
if (!(error & D_INSERT)){ g_free (p);
mi_getch ();
dlg_run_done (d); return d;
destroy_dlg (d);
} else
return d;
return 0;
} }
/* }}} */
/*
* Create message dialog. The caller must call dlg_run_done() and
* destroy_dlg() to dismiss it. Not safe to call from background.
*/
struct Dlg_head *
create_message (int flags, const char *title, const char *text, ...)
{
va_list args;
Dlg_head *d;
char *p;
va_start (args, text);
p = g_strdup_vprintf (text, args);
va_end (args);
d = do_create_message (flags, title, p);
g_free (p);
return d;
}
/*
* Show message dialog. Dismiss it when any key is pressed.
* Not safe to call from background.
*/
void
message (int flags, const char *title, const char *text, ...)
{
va_list args;
Dlg_head *d;
char *p;
va_start (args, text);
p = g_strdup_vprintf (text, args);
va_end (args);
d = do_create_message (flags, title, p);
g_free (p);
mi_getch ();
dlg_run_done (d);
destroy_dlg (d);
}
/* {{{ Quick dialog routines */ /* {{{ Quick dialog routines */

View File

@ -68,19 +68,21 @@ char *real_input_dialog_help (char *header, char *text, char *help, char *def_te
void query_set_sel (int new_sel); void query_set_sel (int new_sel);
struct Dlg_head *message (int error, char *header, const char *text, ...) struct Dlg_head *create_message (int flags, const char *title,
const char *text, ...)
__attribute__ ((format (printf, 3, 4)));
void message (int flags, const char *title, const char *text, ...)
__attribute__ ((format (printf, 3, 4))); __attribute__ ((format (printf, 3, 4)));
/* Use this as header for message() - it expands to "Error" */ /* Use this as header for message() - it expands to "Error" */
#define MSG_ERROR ((char *) -1) #define MSG_ERROR ((char *) -1)
int query_dialog (char *header, char *text, int flags, int count, ...); int query_dialog (const char *header, const char *text, int flags, int count, ...);
/* flags for message() and query_dialog() */ /* flags for message() and query_dialog() */
enum { enum {
D_NORMAL = 0, D_NORMAL = 0,
D_ERROR = 1, D_ERROR = 1,
D_INSERT = 2
} /* dialog options */; } /* dialog options */;
#endif /* __WTOOLS_H */ #endif /* __WTOOLS_H */