Commit 73895a52 73895a52221e74ddc2f5130eb6798ed7b24b250a by Alain Magloire

The exercise is to crank up the warnings from gcc and cleanup

	the code based on the hints generated by the compiler.  The usual
	errors:
	- signed vs unsigned, signedness or unsignedness problems.
	- printf() wrong formats
	- wrong prototypes declarations
	- and different buglets
	- "const char *" vs "char *"
	- unused variables
	- unused arguments.  Tell the compiler by typecasting to void
	 (void)var.
	- Some variable when shadowed, meaning in another block variable
	of the same name where reused.
	- atoi() is not an ANSI C function, we should use strtol().

	Changes to comply to GNU coding standards, and nuke trailing spaces.

	* mail/alias.c (alia_lookup): No prototypes and scope static.
	(hash_num, max_rehash, aliases): Scope static and unsigned.
	(hash): unsigned.
	(alias_rehash): i unsigned.
	(alias_lookup_or_install): slot variable unused.
	(alias_destroy): unsigned.
	* mail/copy.c (mail_copy0): fprintf wrong format.
	* mail/decode.c: dislay_message change prototype.
	(mail_decode): Cast when calling util_msgset_iterate().
	(display_message): Prototype change.
	(display_headers): unsigned issues.
	* mail/delete.c: Buglet was caling mail_delete0() instead of
	mail_delete.
	* mail/eq.c: Unused arguments.
	* mail/exit.c: Unused arguments.
	* mail/folders.c: Unused arguments.
	* mail/followup.c: Unused variables.
	* mail/from.c (mail_from): variable buffer was shadowing use variable
	name instead. snprintf() formatting issues.
* mail/headers.c: Unsigned issues.
	* mail/if.c: Unused arguments.
	* mail/inc.c: Unused arguments.
	* mail/list.c: Use const char *.
	* mail/mail.c: options[], argp[] initialised all elements.
	(mail_cmdline): Unused arguments.
	(main): Unsigned issues.
	(mail_warranty): Unused arguments.
	* mail/mail.h: function_t with complete prototype this necessary
	to let the compiler do proper checks.
	struct mail_command_entry rearrange the fields and a new field
	int (*escfunc) __P ((int, char **, struct send_environ *));
	Indentation rearrangements.
	* mail/mailline.c (ml_getc): Scope is static now.
	typecast for const char *.
	(ml_reread): Typecast.
	* mail/msgset.y: Declare yyerror() and yylex().
	(msgset_select): Change of prototpe to let the compiler do checks.
	(selec_sender): Unsused arguments.
	* mail/pipe.c: Rename variable pipe to tube.
	* mail/print.c: Unsigness and some shadow variables.
	* mail/quit.c: Shadow variables.
	* mail/send.c: Typecast when necessary. Use the second (escfunc)
	field now. Some shadow variables.
	* mail/shell.c: Unsigned.
	* mail/table.c: Readjust the table to correspond to the signature
	change in mail.h.
	* mail/tag.c: Prototype change.
	* mail/util.c (util_msglist_esccmd): New function.
	(util_find_entry): Prototype change.  And check return value
	of getenv().
	(util_screen_lines): Change atoi() to strtoul().
	(util_screen_columns): Change atoi() to strtoul().
	(util_find_env): Signedness.
	(util_fullpath): Prototype changed(const).
	(util_slist_to_string):Protorype changed (const).
	(util_strcat) :Protorype changed (const).
	(util_tempfile): const.
	* mail/var.c: Unsignedness, Unused arguments.
	(var_quote):  Use new function util_msglist_esccmd().
	* mail/version.c: Unused arguments.
	* mail/write.c: printf formats.
	* mail/z.c: Signedness.
1 parent 068a9ac3
......@@ -17,9 +17,10 @@
#include "mail.h"
static void alias_print __P((char *name));
static void alias_print_group __P((char *name, list_t list));
static int alias_create __P((char *name, list_t *plist));
static void alias_print __P ((char *name));
static void alias_print_group __P ((char *name, list_t list));
static int alias_create __P ((char *name, list_t *plist));
static int alias_lookup __P ((char *name, list_t *plist));
/*
* a[lias] [alias [address...]]
......@@ -60,16 +61,16 @@ struct _alias
pair of them grows exponentially, starting from 64.
Hopefully no one will need more than 32797 aliases, and even if
someone will, it is easy enough to add more numbers to the sequence. */
size_t hash_size[] =
static unsigned int hash_size[] =
{
37, 101, 229, 487, 1009, 2039, 4091, 8191, 16411, 32797,
};
/* Maximum number of re-hashes: */
int max_rehash = sizeof (hash_size) / sizeof (hash_size[0]);
alias_t *aliases; /* Table of aliases */
size_t hash_num; /* Index to hash_size table */
static unsigned int max_rehash = sizeof (hash_size) / sizeof (hash_size[0]);
static alias_t *aliases; /* Table of aliases */
static unsigned int hash_num; /* Index to hash_size table */
static unsigned hash __P((char *name));
static unsigned int hash __P((char *name));
static int alias_rehash __P((void));
static alias_t *alias_lookup_or_install __P((char *name, int install));
static void alias_print_group __P((char *name, list_t list));
......@@ -91,7 +92,7 @@ alias_rehash()
{
alias_t *old_aliases = aliases;
alias_t *ap;
int i;
unsigned int i;
if (++hash_num >= max_rehash)
{
......@@ -120,7 +121,6 @@ alias_t *
alias_lookup_or_install(char *name, int install)
{
unsigned i, pos;
alias_t *slot = NULL;
if (!aliases)
{
......@@ -157,7 +157,7 @@ alias_lookup_or_install(char *name, int install)
return alias_lookup_or_install(name, install);
}
int
static int
alias_lookup(char *name, list_t *plist)
{
alias_t *ap = alias_lookup_or_install(name, 0);
......@@ -174,7 +174,7 @@ alias_print(char *name)
{
if (!name)
{
int i;
unsigned int i;
if (!aliases)
return;
......@@ -231,7 +231,7 @@ alias_print_group(char *name, list_t list)
void
alias_destroy(char *name)
{
int i, j, r;
unsigned int i, j, r;
alias_t *alias = alias_lookup_or_install(name, 0);
if (!alias)
return;
......@@ -265,4 +265,3 @@ alias_expand(char *name)
return strdup (name);
return util_slist_to_string(list, ",");
}
......
......@@ -89,7 +89,7 @@ mail_copy0 (int argc, char **argv, int mark)
}
}
fprintf (ofile, "\"%s\" %3ld/%-5ld\n", filename, total_lines, total_size);
fprintf (ofile, "\"%s\" %3d/%-5d\n", filename, total_lines, total_size);
mailbox_close (mbx);
mailbox_destroy (&mbx);
......
......@@ -29,8 +29,7 @@ struct decode_closure
};
static int print_stream __P ((stream_t, FILE *));
static int display_message __P ((message_t, msgset_t *msgset,
struct decode_closure *closure));
static int display_message __P ((message_t, msgset_t *msgset, void *closure));
static int display_message0 __P ((FILE *, message_t, const msgset_t *, int));
static int mailcap_lookup __P ((const char *));
static int get_content_encoding __P ((header_t hdr, char **value));
......@@ -46,24 +45,24 @@ mail_decode (int argc, char **argv)
decode_closure.select_hdr = islower (argv[0][0]);
util_msgset_iterate (msgset, display_message, &decode_closure);
util_msgset_iterate (msgset, display_message, (void *)&decode_closure);
msgset_free (msgset);
return 0;
}
int
display_message (message_t mesg, msgset_t *msgset,
struct decode_closure *closure)
display_message (message_t mesg, msgset_t *msgset, void *arg)
{
FILE *out;
size_t lines = 0;
struct decode_closure *closure = arg;
if (util_isdeleted (msgset->msg_part[0]))
return 1;
message_lines (mesg, &lines);
if ((util_find_env("crt"))->set && lines > util_getlines ())
if ((util_find_env("crt"))->set && (int)lines > util_getlines ())
out = popen (getenv("PAGER"), "w");
else
out = ofile;
......@@ -88,6 +87,8 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
int select_hdr)
{
header_t hdr = NULL;
(void)msgset;
/* Print the selected headers only. */
if (select_hdr)
{
......@@ -119,15 +120,15 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
}
}
void
static void
display_part_header (FILE *out, const msgset_t *msgset,
char *type, char *encoding)
{
int size = util_screen_columns () - 3;
int i;
unsigned int i;
fputc ('+', out);
for (i = 0; i <= size; i++)
for (i = 0; (int)i <= size; i++)
fputc ('-', out);
fputc ('+', out);
fputc ('\n', out);
......@@ -141,7 +142,7 @@ display_part_header (FILE *out, const msgset_t *msgset,
fprintf (out, "| Type=%s\n", type);
fprintf (out, "| encoding=%s\n", encoding);
fputc ('+', out);
for (i = 0; i <= size; i++)
for (i = 0; (int)i <= size; i++)
fputc ('-', out);
fputc ('+', out);
fputc ('\n', out);
......@@ -164,7 +165,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
message_is_multipart (mesg, &ismime);
if (ismime)
{
int j;
unsigned int j;
message_get_num_parts (mesg, &nparts);
......
......@@ -21,8 +21,8 @@
* d[elete] [msglist]
*/
int
mail_delete0 ()
static int
mail_delete0 (void)
{
message_t msg;
attribute_t attr;
......@@ -39,13 +39,14 @@ mail_delete (int argc, char **argv)
int rc = 0;
if (argc > 1)
rc = util_msglist_command (mail_delete0, argc, argv, 0);
rc = util_msglist_command (mail_delete, argc, argv, 0);
else
rc = mail_delete0 ();
/* Reajust the realcursor to no point to the deleted messages. */
if (cursor == realcursor)
{
int here = realcursor;
unsigned int here = realcursor;
do
{
message_t msg;
......
......@@ -24,6 +24,7 @@
int
mail_eq (int argc, char **argv)
{
(void)argc; (void)argv;
fprintf (ofile, "%d\n", realcursor);
return 0;
}
......
......@@ -20,6 +20,7 @@
int
mail_exit (int argc, char **argv)
{
(void)argc; (void)argv;
mailbox_close (mbox);
exit (0);
}
......
......@@ -27,6 +27,8 @@ mail_folders (int argc, char **argv)
char *path;
struct mail_env_entry *env = util_find_env ("folder");
(void)argc; (void)argv;
if (!env->set)
{
util_error("No value set for \"folder\"");
......
......@@ -28,7 +28,6 @@ mail_followup (int argc, char **argv)
message_t msg;
header_t hdr;
char *str;
int i;
msgset_t *msglist, *mp;
struct send_environ env;
int status;
......
......@@ -54,13 +54,13 @@ mail_from (int argc, char **argv)
address_t address = NULL;
if (address_create (&address, from) == 0)
{
char p[128];
char name[128];
size_t len = strlen (from);
*p = '\0';
address_get_personal (address, 1, p, sizeof p, NULL);
if (*p && len)
*name = '\0';
address_get_personal (address, 1, name, sizeof name, NULL);
if (*name && len)
{
strncpy (from, p, len - 1);
strncpy (from, name, len - 1);
from[len - 1] = '\0';
}
else
......@@ -103,7 +103,7 @@ mail_from (int argc, char **argv)
message_size (msg, &m_size);
message_lines (msg, &m_lines);
snprintf (st, sizeof(st), "%3ld/%-5ld", m_lines, m_size);
snprintf (st, sizeof(st), "%3d/%-5d", m_lines, m_size);
/* The "From" field will take a third of the screen.
Subject will take the rest.
......
......@@ -45,13 +45,13 @@ mail_headers (int argc, char **argv)
if (lines < 0)
lines = util_screen_lines ();
if (lines < total)
if ((unsigned int)lines < total)
{
low = list->msg_part[0] - (lines / 2);
if (low < 1)
low = 1;
high = low + lines;
if (high > total)
if ((unsigned int)high > total)
{
high = total;
low = high - lines;
......
......@@ -131,6 +131,7 @@ int
mail_else (int argc, char **argv)
{
int cond;
(void)argc; (void)argv;
if (_cond_level == 0)
{
util_error("else without matching if");
......@@ -146,6 +147,7 @@ mail_else (int argc, char **argv)
int
mail_endif (int argc, char **argv)
{
(void)argc; (void)argv;
if (_cond_level == 0)
{
util_error("endif without matching if");
......
......@@ -24,6 +24,7 @@
int
mail_inc (int argc, char **argv)
{
(void)argc; (void)argv;
if (!mailbox_is_updated (mbox))
{
mailbox_messages_count (mbox, &total);
......
......@@ -25,10 +25,12 @@
int
mail_list (int argc, char **argv)
{
char *cmd = NULL;
const char *cmd = NULL;
int i = 0, pos = 0, len = 0;
int cols = util_getcols ();
(void)argc; (void)argv;
for (i=0; mail_command_table[i].shortname != 0; i++)
{
len = strlen (mail_command_table[i].longname);
......
......@@ -31,21 +31,21 @@ static char doc[] = "GNU mail -- the standard /bin/mail interface";
static char args_doc[] = "[address...]";
static struct argp_option options[] = {
{"exist", 'e', 0, 0, "Return true if mail exists"},
{"exist", 'e', 0, 0, "Return true if mail exists", 0},
{"file", 'f', "FILE", OPTION_ARG_OPTIONAL,
"Operate on mailbox FILE (default ~/mbox)"},
{"byname", 'F', 0, 0, "Save messages according to sender"},
{"headers", 'H', 0, 0, "Write a header summary and exit"},
{"ignore", 'i', 0, 0, "Ignore interrupts"},
{"norc", 'n', 0, 0, "Do not read the system mailrc file"},
{"nosum", 'N', 0, 0, "Do not display initial header summary"},
{"print", 'p', 0, 0, "Print all mail to standard output"},
{"quit", 'q', 0, 0, "Cause interrupts to terminate program"},
{"read", 'r', 0, 0, "Same as -p"},
{"subject", 's', "SUBJ", 0, "Send a message with a Subject of SUBJ"},
{"to", 't', 0, 0, "Precede message by a list of addresses"},
{"user", 'u', "USER", 0, "Operate on USER's mailbox"},
{ 0 }
"Operate on mailbox FILE (default ~/mbox)", 0},
{"byname", 'F', 0, 0, "Save messages according to sender", 0},
{"headers", 'H', 0, 0, "Write a header summary and exit", 0},
{"ignore", 'i', 0, 0, "Ignore interrupts", 0},
{"norc", 'n', 0, 0, "Do not read the system mailrc file", 0},
{"nosum", 'N', 0, 0, "Do not display initial header summary", 0},
{"print", 'p', 0, 0, "Print all mail to standard output", 0},
{"quit", 'q', 0, 0, "Cause interrupts to terminate program", 0},
{"read", 'r', 0, 0, "Same as -p", 0},
{"subject", 's', "SUBJ", 0, "Send a message with a Subject of SUBJ", 0},
{"to", 't', 0, 0, "Precede message by a list of addresses", 0},
{"user", 'u', "USER", 0, "Operate on USER's mailbox", 0},
{ NULL, 0, NULL, 0, NULL, 0 }
};
struct arguments
......@@ -124,7 +124,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
return 0;
}
static struct argp argp = { options, parse_opt, args_doc, doc };
static struct argp argp = { options, parse_opt, args_doc, doc, NULL, NULL, NULL };
static char *
mail_cmdline(void *closure, int cont)
......@@ -133,6 +133,8 @@ mail_cmdline(void *closure, int cont)
char *prompt = NULL;
char *rc;
(void)cont;
while (1)
{
if (util_find_env ("autoinc")->set && !mailbox_is_updated (mbox))
......@@ -142,7 +144,7 @@ mail_cmdline(void *closure, int cont)
}
if (interactive)
prompt = pev->set && pev->value != NULL ? pev->value : "? ";
prompt = pev->set && pev->value != NULL ? pev->value : (char *)"? ";
rc = readline (prompt);
......@@ -167,7 +169,7 @@ int
main (int argc, char **argv)
{
struct mail_env_entry *mode = NULL, *prompt = NULL;
int modelen = 0;
size_t modelen = 0;
struct arguments args;
ofile = stdout;
......@@ -445,8 +447,7 @@ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\n\
int
mail_warranty(int argc, char **argv)
{
(void)argc; (void)argv;
fprintf (ofile, "%s", warranty_stmt);
return 0;
}
......
......@@ -80,7 +80,7 @@ extern "C" {
/* Type definitions */
#ifndef function_t
typedef int function_t ();
typedef int function_t __P ((int, char **));
#endif
/* Values for mail_command_entry.flags */
......@@ -88,20 +88,6 @@ typedef int function_t ();
#define EF_FLOW 0x01 /* Flow control command */
#define EF_SEND 0x02 /* Send command */
struct mail_command_entry {
char *shortname;
char *longname;
int flags;
function_t *func;
char *synopsis;
};
struct mail_env_entry {
char *var;
int set;
char *value;
};
struct send_environ
{
char *to;
......@@ -116,13 +102,28 @@ struct send_environ
int nfiles;
};
struct mail_command_entry {
const char *shortname;
const char *longname;
const char *synopsis;
int flags;
int (*func) __P ((int, char **));
int (*escfunc) __P ((int, char **, struct send_environ *));
};
struct mail_env_entry {
char *var;
int set;
char *value;
};
typedef struct message_set msgset_t;
struct message_set
{
msgset_t *next; /* Link to the next message set */
int npart; /* Number of parts in this set */
int *msg_part; /* Array of part numbers: msg_part[0] is the message
unsigned int npart; /* Number of parts in this set */
unsigned int *msg_part;/* Array of part numbers: msg_part[0] is the message
number */
};
......@@ -137,146 +138,150 @@ extern const struct mail_command_entry mail_command_table[];
extern const struct mail_command_entry mail_escape_table[];
/* Functions */
int mail_alias __P((int argc, char **argv));
int mail_alt __P((int argc, char **argv)); /* command alternates */
int mail_cd __P((int argc, char **argv));
int mail_copy __P((int argc, char **argv));
int mail_decode __P((int argc, char **argv));
int mail_delete __P((int argc, char **argv));
int mail_discard __P((int argc, char **argv));
int mail_dp __P((int argc, char **argv));
int mail_echo __P((int argc, char **argv));
int mail_edit __P((int argc, char **argv));
int mail_else __P((int argc, char **argv));
int mail_endif __P((int argc, char **argv));
int mail_exit __P((int argc, char **argv));
int mail_file __P((int argc, char **argv));
int mail_folders __P((int argc, char **argv));
int mail_followup __P((int argc, char **argv));
int mail_from __P((int argc, char **argv));
int mail_headers __P((int argc, char **argv));
int mail_hold __P((int argc, char **argv));
int mail_help __P((int argc, char **argv));
int mail_if __P((int argc, char **argv));
int mail_inc __P((int argc, char **argv));
int mail_list __P((int argc, char **argv));
int mail_send __P((int argc, char **argv)); /* command mail */
int mail_mbox __P((int argc, char **argv));
int mail_next __P((int argc, char **argv));
int mail_pipe __P((int argc, char **argv));
int mail_previous __P((int argc, char **argv));
int mail_print __P((int argc, char **argv));
int mail_quit __P((int argc, char **argv));
int mail_reply __P((int argc, char **argv));
int mail_retain __P((int argc, char **argv));
int mail_save __P((int argc, char **argv));
int mail_set __P((int argc, char **argv));
int mail_shell __P((int argc, char **argv));
int mail_size __P((int argc, char **argv));
int mail_source __P((int argc, char **argv));
int mail_summary __P((int argc, char **argv));
int mail_tag __P((int argc, char **argv));
int mail_top __P((int argc, char **argv));
int mail_touch __P((int argc, char **argv));
int mail_unalias __P((int argc, char **argv));
int mail_undelete __P((int argc, char **argv));
int mail_unset __P((int argc, char **argv));
int mail_version __P((int argc, char **argv));
int mail_visual __P((int argc, char **argv));
int mail_warranty __P((int argc, char **argv));
int mail_write __P((int argc, char **argv));
int mail_z __P((int argc, char **argv));
int mail_eq __P((int argc, char **argv)); /* command = */
int if_cond __P((void));
void mail_mainloop __P((char *(*input) __P((void *, int)), void *closure, int do_history));
int mail_copy0 __P((int argc, char **argv, int mark));
int mail_send0 __P((struct send_environ *env, int save_to));
void free_env_headers __P((struct send_environ *env));
/*void print_message __P((message_t mesg, char *prefix, int all_headers, FILE *file));*/
int mail_mbox_commit __P((void));
int mail_is_my_name __P((char *name));
void mail_set_my_name __P((char *name));
char *mail_whoami __P((void));
int mail_header_is_visible __P((char *str));
int mail_mbox_close __P((void));
int var_shell __P((int argc, char **argv, struct send_environ *env));
int var_command __P((int argc, char **argv, struct send_environ *env));
int var_help __P((int argc, char **argv, struct send_environ *env));
int var_sign __P((int argc, char **argv, struct send_environ *env));
int var_bcc __P((int argc, char **argv, struct send_environ *env));
int var_cc __P((int argc, char **argv, struct send_environ *env));
int var_deadletter __P((int argc, char **argv, struct send_environ *env));
int var_editor __P((int argc, char **argv, struct send_environ *env));
int var_print __P((int argc, char **argv, struct send_environ *env));
int var_headers __P((int argc, char **argv, struct send_environ *env));
int var_insert __P((int argc, char **argv, struct send_environ *env));
int var_quote __P((int argc, char **argv, struct send_environ *env));
int var_type_input __P((int argc, char **argv, struct send_environ *env));
int var_read __P((int argc, char **argv, struct send_environ *env));
int var_subj __P((int argc, char **argv, struct send_environ *env));
int var_to __P((int argc, char **argv, struct send_environ *env));
int var_visual __P((int argc, char **argv, struct send_environ *env));
int var_write __P((int argc, char **argv, struct send_environ *env));
int var_exit __P((int argc, char **argv, struct send_environ *env));
int var_pipe __P((int argc, char **argv, struct send_environ *env));
extern int mail_alias __P ((int argc, char **argv));
extern int mail_alt __P ((int argc, char **argv)); /* command alternates */
extern int mail_cd __P ((int argc, char **argv));
extern int mail_copy __P ((int argc, char **argv));
extern int mail_decode __P ((int argc, char **argv));
extern int mail_delete __P ((int argc, char **argv));
extern int mail_discard __P ((int argc, char **argv));
extern int mail_dp __P ((int argc, char **argv));
extern int mail_echo __P ((int argc, char **argv));
extern int mail_edit __P ((int argc, char **argv));
extern int mail_else __P ((int argc, char **argv));
extern int mail_endif __P ((int argc, char **argv));
extern int mail_exit __P ((int argc, char **argv));
extern int mail_file __P ((int argc, char **argv));
extern int mail_folders __P ((int argc, char **argv));
extern int mail_followup __P ((int argc, char **argv));
extern int mail_from __P ((int argc, char **argv));
extern int mail_headers __P ((int argc, char **argv));
extern int mail_hold __P ((int argc, char **argv));
extern int mail_help __P ((int argc, char **argv));
extern int mail_if __P ((int argc, char **argv));
extern int mail_inc __P ((int argc, char **argv));
extern int mail_list __P ((int argc, char **argv));
extern int mail_send __P ((int argc, char **argv)); /* command mail */
extern int mail_mbox __P ((int argc, char **argv));
extern int mail_next __P ((int argc, char **argv));
extern int mail_pipe __P ((int argc, char **argv));
extern int mail_previous __P ((int argc, char **argv));
extern int mail_print __P ((int argc, char **argv));
extern int mail_quit __P ((int argc, char **argv));
extern int mail_reply __P ((int argc, char **argv));
extern int mail_retain __P ((int argc, char **argv));
extern int mail_save __P ((int argc, char **argv));
extern int mail_set __P ((int argc, char **argv));
extern int mail_shell __P ((int argc, char **argv));
extern int mail_size __P ((int argc, char **argv));
extern int mail_source __P ((int argc, char **argv));
extern int mail_summary __P ((int argc, char **argv));
extern int mail_tag __P ((int argc, char **argv));
extern int mail_top __P ((int argc, char **argv));
extern int mail_touch __P ((int argc, char **argv));
extern int mail_unalias __P ((int argc, char **argv));
extern int mail_undelete __P ((int argc, char **argv));
extern int mail_unset __P ((int argc, char **argv));
extern int mail_version __P ((int argc, char **argv));
extern int mail_visual __P ((int argc, char **argv));
extern int mail_warranty __P ((int argc, char **argv));
extern int mail_write __P ((int argc, char **argv));
extern int mail_z __P ((int argc, char **argv));
extern int mail_eq __P ((int argc, char **argv)); /* command = */
extern int if_cond __P ((void));
extern void mail_mainloop __P ((char *(*input) __P((void *, int)), void *closure, int do_history));
extern int mail_copy0 __P ((int argc, char **argv, int mark));
extern int mail_send0 __P ((struct send_environ *env, int save_to));
extern void free_env_headers __P ((struct send_environ *env));
/*extern void print_message __P((message_t mesg, char *prefix, int all_headers, FILE *file));*/
extern int mail_mbox_commit __P ((void));
extern int mail_is_my_name __P ((char *name));
extern void mail_set_my_name __P ((char *name));
extern char *mail_whoami __P ((void));
extern int mail_header_is_visible __P ((char *str));
extern int mail_mbox_close __P ((void));
extern int var_shell __P ((int argc, char **argv, struct send_environ *env));
extern int var_command __P ((int argc, char **argv, struct send_environ *env));
extern int var_help __P ((int argc, char **argv, struct send_environ *env));
extern int var_sign __P ((int argc, char **argv, struct send_environ *env));
extern int var_bcc __P ((int argc, char **argv, struct send_environ *env));
extern int var_cc __P ((int argc, char **argv, struct send_environ *env));
extern int var_deadletter __P ((int argc, char **argv, struct send_environ *env));
extern int var_editor __P ((int argc, char **argv, struct send_environ *env));
extern int var_print __P ((int argc, char **argv, struct send_environ *env));
extern int var_headers __P ((int argc, char **argv, struct send_environ *env));
extern int var_insert __P ((int argc, char **argv, struct send_environ *env));
extern int var_quote __P ((int argc, char **argv, struct send_environ *env));
extern int var_type_input __P ((int argc, char **argv, struct send_environ *env));
extern int var_read __P ((int argc, char **argv, struct send_environ *env));
extern int var_subj __P ((int argc, char **argv, struct send_environ *env));
extern int var_to __P ((int argc, char **argv, struct send_environ *env));
extern int var_visual __P ((int argc, char **argv, struct send_environ *env));
extern int var_write __P ((int argc, char **argv, struct send_environ *env));
extern int var_exit __P ((int argc, char **argv, struct send_environ *env));
extern int var_pipe __P ((int argc, char **argv, struct send_environ *env));
/* msgsets */
void msgset_free __P((msgset_t *msg_set));
msgset_t *msgset_make_1 __P((int number));
msgset_t *msgset_append __P((msgset_t *one, msgset_t *two));
msgset_t *msgset_range __P((int low, int high));
msgset_t *msgset_expand __P((msgset_t *set, msgset_t *expand_by));
msgset_t * msgset_dup __P((const msgset_t *set));
int parse_msgset __P((const int argc, char **argv, msgset_t **mset));
int util_do_command __P((const char *cmd, ...));
int util_msglist_command __P((function_t *func, int argc, char **argv, int set_cursor));
function_t* util_command_get __P((char *cmd));
char *util_stripwhite __P((char *string));
struct mail_command_entry util_find_entry __P((const struct mail_command_entry *table, char *cmd));
int util_getcols __P((void));
int util_getlines __P((void));
int util_screen_lines __P((void));
int util_screen_columns __P((void));
struct mail_env_entry *util_find_env __P((const char *var));
int util_printenv __P((int set));
int util_setenv __P((const char *name, const char *value, int overwrite));
int util_isdeleted __P((int message));
char *util_get_homedir __P((void));
char *util_fullpath __P((char *inpath));
char *util_get_sender __P((int msgno, int strip));
void util_slist_print __P((list_t list, int nl));
int util_slist_lookup __P((list_t list, char *str));
void util_slist_add __P((list_t *list, char *value));
void util_slist_destroy __P((list_t *list));
char *util_slist_to_string __P((list_t list, char *delim));
void util_strcat __P((char **dest, char *str));
void util_strupper __P((char *str));
void util_escape_percent __P((char **str));
char *util_outfolder_name __P((char *str));
void util_save_outgoing __P((message_t msg, char *savefile));
void util_error __P((const char *format, ...));
int util_help __P((const struct mail_command_entry *table, char *word));
int util_tempfile __P((char **namep));
void util_msgset_iterate __P((msgset_t *msgset, int (*fun)(), void *closure));
int util_get_content_type __P((header_t hdr, char **value));
int ml_got_interrupt __P((void));
void ml_clear_interrupt __P((void));
void ml_readline_init __P((void));
int ml_reread __P((char *prompt, char **text));
char *alias_expand __P((char *name));
void alias_destroy __P((char *name));
extern void msgset_free __P ((msgset_t *msg_set));
extern msgset_t *msgset_make_1 __P ((int number));
extern msgset_t *msgset_append __P ((msgset_t *one, msgset_t *two));
extern msgset_t *msgset_range __P ((int low, int high));
extern msgset_t *msgset_expand __P ((msgset_t *set, msgset_t *expand_by));
extern msgset_t *msgset_dup __P ((const msgset_t *set));
extern int msgset_parse __P ((const int argc, char **argv, msgset_t **mset));
extern int util_do_command __P ((const char *cmd, ...));
extern int util_msglist_command __P ((function_t *func, int argc, char **argv, int set_cursor));
extern int util_msglist_esccmd
__P ((int (*escfunc) __P ((int, char **, struct send_environ *)),
int argc, char **argv, struct send_environ *env, int set_cursor));
extern function_t* util_command_get __P ((const char *cmd));
extern char *util_stripwhite __P ((char *string));
extern struct mail_command_entry util_find_entry __P ((const struct mail_command_entry *table, const char *cmd));
extern int util_getcols __P ((void));
extern int util_getlines __P ((void));
extern int util_screen_lines __P ((void));
extern int util_screen_columns __P ((void));
extern struct mail_env_entry *util_find_env __P ((const char *var));
extern int util_printenv __P ((int set));
extern int util_setenv __P ((const char *name, const char *value, int overwrite));
extern int util_isdeleted __P ((int message));
extern char *util_get_homedir __P ((void));
extern char *util_fullpath __P ((const char *inpath));
extern char *util_get_sender __P ((int msgno, int strip));
extern void util_slist_print __P ((list_t list, int nl));
extern int util_slist_lookup __P ((list_t list, char *str));
extern void util_slist_add __P ((list_t *list, char *value));
extern void util_slist_destroy __P ((list_t *list));
extern char *util_slist_to_string __P ((list_t list, const char *delim));
extern void util_strcat __P ((char **dest, const char *str));
extern void util_strupper __P ((char *str));
extern void util_escape_percent __P ((char **str));
extern char *util_outfolder_name __P ((char *str));
extern void util_save_outgoing __P ((message_t msg, char *savefile));
extern void util_error __P ((const char *format, ...));
extern int util_help __P ((const struct mail_command_entry *table, char *word));
extern int util_tempfile __P ((char **namep));
extern void util_msgset_iterate __P ((msgset_t *msgset, int (*fun) __P ((message_t, msgset_t *, void *)), void *closure));
extern int util_get_content_type __P ((header_t hdr, char **value));
extern int util_get_hdr_value __P ((header_t hdr, const char *name, char **value));
extern int ml_got_interrupt __P ((void));
extern void ml_clear_interrupt __P ((void));
extern void ml_readline_init __P ((void));
extern int ml_reread __P ((const char *prompt, char **text));
extern char *alias_expand __P ((char *name));
extern void alias_destroy __P ((char *name));
#ifndef HAVE_READLINE_READLINE_H
char *readline __P((const char *prompt));
extern char *readline __P ((const char *prompt));
#endif
#ifndef _PATH_SENDMAIL
......@@ -293,4 +298,3 @@ char *readline __P((const char *prompt));
#endif
#endif /* _MAIL_H */
......
......@@ -58,7 +58,7 @@ ml_got_interrupt ()
return rc;
}
int
static int
ml_getc (FILE *stream)
{
unsigned char c;
......@@ -86,7 +86,7 @@ ml_readline_init ()
return;
#ifdef WITH_READLINE
rl_readline_name = "mail";
rl_readline_name = (char *)"mail";
rl_attempted_completion_function = (CPPFunction*)ml_command_completion;
rl_getc_function = ml_getc;
#endif
......@@ -114,7 +114,7 @@ ml_readline_init ()
static char *insert_text;
static int
ml_insert_hook ()
ml_insert_hook (void)
{
if (insert_text)
rl_insert_text (insert_text);
......@@ -122,14 +122,14 @@ ml_insert_hook ()
}
int
ml_reread (char *prompt, char **text)
ml_reread (const char *prompt, char **text)
{
char *s;
ml_clear_interrupt ();
insert_text = *text;
rl_startup_hook = ml_insert_hook;
s = readline (prompt);
s = readline ((char *)prompt);
if (!ml_got_interrupt ())
{
if (*text)
......@@ -150,6 +150,7 @@ ml_reread (char *prompt, char **text)
char **
ml_command_completion (char *cmd, int start, int end)
{
(void)end;
if (start == 0)
return completion_matches (cmd, ml_command_generator);
return NULL;
......@@ -162,7 +163,7 @@ char *
ml_command_generator (char *text, int state)
{
static int i, len;
char *name;
const char *name;
if (!state)
{
......
......@@ -29,13 +29,17 @@ struct header_data
char *expr;
};
static msgset_t *msgset_select (int (*sel)(), void *closure, int rev,
int max_matches);
static int select_header (message_t msg, void *closure);
static int select_body (message_t msg, void *closure);
static int select_type (message_t msg, void *closure);
static int select_sender (message_t msg, void *closure);
static int select_deleted (message_t msg, void *closure);
static msgset_t *msgset_select __P ((int (*sel) __P ((message_t, void *)),
void *closure, int rev,
unsigned int max_matches));
static int select_header __P ((message_t msg, void *closure));
static int select_body __P ((message_t msg, void *closure));
static int select_type __P ((message_t msg, void *closure));
static int select_sender __P ((message_t msg, void *closure));
static int select_deleted __P ((message_t msg, void *closure));
int yyerror __P ((const char *));
int yylex __P ((void));
static msgset_t *result;
%}
......@@ -170,7 +174,6 @@ range : number
}
else
{
msgset_t *mp;
$$ = msgset_range ($1, $3->msg_part[0]-1);
if (!$$)
YYERROR;
......@@ -209,7 +212,7 @@ static int cur_ind;
static char *cur_p;
int
yyerror (char *s)
yyerror (const char *s)
{
fprintf (stderr, "%s: ", xargv[0]);
fprintf (stderr, "%s", s);
......@@ -226,6 +229,7 @@ yyerror (char *s)
else
fprintf (stderr, " near %s", cur_p);
fprintf (stderr, "\n");
return 0;
}
int
......@@ -324,7 +328,6 @@ msgset_parse (const int argc, char **argv, msgset_t **mset)
void
msgset_free (msgset_t *msg_set)
{
int i;
msgset_t *next;
if (!msg_set)
......@@ -382,7 +385,7 @@ msgset_t *
msgset_range (int low, int high)
{
int i;
msgset_t *mp, *first = NULL, *last;
msgset_t *mp, *first = NULL, *last = NULL;
if (low == high)
return msgset_make_1 (low);
......@@ -409,7 +412,7 @@ msgset_t *
msgset_expand (msgset_t *set, msgset_t *expand_by)
{
msgset_t *i, *j;
msgset_t *first = NULL, *last, *mp;
msgset_t *first = NULL, *last = NULL, *mp;
for (i = set; i; i = i->next)
for (j = expand_by; j; j = j->next)
......@@ -432,10 +435,11 @@ msgset_expand (msgset_t *set, msgset_t *expand_by)
}
msgset_t *
msgset_select (int (*sel)(), void *closure, int rev, int max_matches)
msgset_select (int (*sel) __P ((message_t, void *)), void *closure, int rev,
unsigned int max_matches)
{
size_t i, match_count = 0;
msgset_t *first = NULL, *last, *mp;
msgset_t *first = NULL, *last = NULL, *mp;
message_t msg = NULL;
if (max_matches == 0)
......@@ -486,7 +490,7 @@ select_header (message_t msg, void *closure)
struct header_data *hd = (struct header_data *)closure;
header_t hdr;
char *contents;
char *header = hd->header ? hd->header : MU_HEADER_SUBJECT;
const char *header = hd->header ? hd->header : MU_HEADER_SUBJECT;
message_get_header (msg, &hdr);
if (header_aget_value (hdr, header, &contents) == 0)
......@@ -572,10 +576,11 @@ select_body (message_t msg, void *closure)
int
select_sender (message_t msg, void *closure)
{
char *sender = (char*) closure;
/* char *sender = (char*) closure; */
/* FIXME: all messages from sender argv[i] */
/* Annoying we can use address_create() for that
but to compare against what? The email ? */
(void)msg; (void)closure;
return 0;
}
......@@ -613,6 +618,7 @@ select_deleted (message_t msg, void *closure)
attribute_t attr= NULL;
int rc;
(void)closure;
message_get_attribute (msg, &attr);
rc = attribute_is_deleted (attr);
return strcmp (xargv[0], "undelete") == 0 ? rc : !rc;
......@@ -636,7 +642,7 @@ int
main(int argc, char **argv)
{
msgset_t *mset = NULL;
int rc = parse_msgset (argc, argv, &mset);
int rc = msgset_parse (argc, argv, &mset);
for (; mset; mset = mset->next)
msgset_print (mset);
......
......@@ -28,7 +28,7 @@ mail_pipe (int argc, char **argv)
message_t msg;
stream_t stream;
char *cmd;
FILE *pipe;
FILE *tube;
msgset_t *list, *mp;
char buffer[512];
off_t off = 0;
......@@ -44,7 +44,7 @@ mail_pipe (int argc, char **argv)
if (msgset_parse (argc, argv, &list))
return 1;
pipe = popen (cmd, "w");
tube = popen (cmd, "w");
for (mp = list; mp; mp = mp->next)
{
......@@ -56,15 +56,15 @@ mail_pipe (int argc, char **argv)
&n) == 0 && n != 0)
{
buffer[n] = '\0';
fprintf (pipe, "%s", buffer);
fprintf (tube, "%s", buffer);
off += n;
}
if ((util_find_env("page"))->set && mp->next)
fprintf (pipe, "\f\n");
fprintf (tube, "\f\n");
}
}
msgset_free (list);
pclose (pipe);
pclose (tube);
return 0;
}
......
......@@ -49,26 +49,25 @@ mail_print (int argc, char **argv)
message_lines (mesg, &lines);
if ((util_find_env("crt"))->set && lines > util_getlines ())
if ((util_find_env("crt"))->set && lines > (size_t)util_getlines ())
out = popen (getenv("PAGER"), "w");
if (islower (argv[0][0]))
{
size_t i, num = 0;
char buffer[512];
char buf[512];
message_get_header (mesg, &hdr);
header_get_field_count (hdr, &num);
for (i = 1; i <= num; i++)
{
header_get_field_name (hdr, i, buffer, sizeof(buffer), NULL);
if (mail_header_is_visible (buffer))
header_get_field_name (hdr, i, buf, sizeof buf, NULL);
if (mail_header_is_visible (buf))
{
fprintf (out, "%s: ", buffer);
header_get_field_value (hdr, i, buffer, sizeof(buffer),
NULL);
fprintf (out, "%s\n", buffer);
fprintf (out, "%s: ", buf);
header_get_field_value (hdr, i, buf, sizeof buf, NULL);
fprintf (out, "%s\n", buf);
}
}
fprintf (out, "\n");
......@@ -78,7 +77,7 @@ mail_print (int argc, char **argv)
else
message_get_stream (mesg, &stream);
while (stream_read (stream, buffer, sizeof (buffer) - 1, off, &n) == 0
while (stream_read (stream, buffer, sizeof buffer - 1, off, &n) == 0
&& n != 0)
{
if (ml_got_interrupt())
......
......@@ -25,6 +25,7 @@
int
mail_quit (int argc, char **argv)
{
(void)argc; (void)argv;
if (mail_mbox_close ())
return 1;
exit (0);
......@@ -54,7 +55,7 @@ mail_mbox_close ()
int
mail_mbox_commit ()
{
int i;
unsigned int i;
mailbox_t dest_mbox = NULL;
int saved_count = 0;
message_t msg;
......@@ -119,11 +120,11 @@ mail_mbox_commit ()
if (saved_count)
{
url_t url = NULL;
url_t u = NULL;
mailbox_get_url (dest_mbox, &url);
mailbox_get_url (dest_mbox, &u);
fprintf(ofile, "Saved %d messages in %s\n", saved_count,
url_to_string (url));
url_to_string (u));
mailbox_close (dest_mbox);
mailbox_destroy (&dest_mbox);
}
......
......@@ -48,7 +48,7 @@ mail_send (int argc, char **argv)
env.outfiles = NULL; env.nfiles = 0;
if (argc < 2)
env.to = readline ("To: ");
env.to = readline ((char *)"To: ");
else
{
while (--argc)
......@@ -75,12 +75,12 @@ mail_send (int argc, char **argv)
}
if ((util_find_env ("askcc"))->set)
env.cc = readline ("Cc: ");
env.cc = readline ((char *)"Cc: ");
if ((util_find_env ("askbcc"))->set)
env.bcc = readline ("Bcc: ");
env.bcc = readline ((char *)"Bcc: ");
if ((util_find_env ("asksub"))->set)
env.subj = readline ("Subject: ");
env.subj = readline ((char *)"Subject: ");
else
env.subj = (util_find_env ("subject"))->value;
......@@ -155,7 +155,7 @@ mail_send0 (struct send_environ *env, int save_to)
while (!done)
{
char *buf;
buf = readline (" \b");
buf = readline ((char *)" \b");
if (ml_got_interrupt ())
{
......@@ -210,8 +210,10 @@ mail_send0 (struct send_environ *env, int save_to)
struct mail_command_entry entry;
entry = util_find_entry (mail_escape_table, argv[0]);
if (entry.func)
status = (*entry.func)(argc, argv, env);
if (entry.escfunc)
{
status = (*entry.escfunc)(argc, argv, env);
}
else
util_error ("Unknown escape %s", argv[0]);
}
......@@ -247,7 +249,7 @@ mail_send0 (struct send_environ *env, int save_to)
else
{
char *buf = NULL;
int n;
unsigned int n;
rewind (env->file);
while (getline (&buf, &n, env->file) > 0)
fputs (buf, fp);
......@@ -269,7 +271,6 @@ mail_send0 (struct send_environ *env, int save_to)
{
mailer_t mailer;
message_t msg = NULL;
int status;
message_create (&msg, NULL);
/* Fill the header. */
......@@ -366,7 +367,7 @@ mail_send0 (struct send_environ *env, int save_to)
if (util_find_env ("sendmail")->set)
{
char *sendmail = util_find_env ("sendmail")->value;
status = mailer_create (&mailer, sendmail);
int status = mailer_create (&mailer, sendmail);
if (status == 0)
{
if (util_find_env ("verbose")->set)
......@@ -422,9 +423,9 @@ msg_to_pipe (const char *cmd, message_t msg)
stream_t stream = NULL;
char buffer[512];
off_t off = 0;
int n = 0;
unsigned int n = 0;
message_get_stream (msg, &stream);
while (stream_read (stream, buffer, sizeof (buffer) - 1, off, &n) == 0
while (stream_read (stream, buffer, sizeof buffer - 1, off, &n) == 0
&& n != 0)
{
buffer[n] = '\0';
......
......@@ -53,7 +53,7 @@ mail_shell (int argc, char **argv)
argcv_string (argc-1, &argv[1], &buf);
argvec[0] = getenv("SHELL");
argvec[1] = "-c";
argvec[1] = (char *)"-c";
argvec[2] = buf;
argvec[3] = NULL;
......
......@@ -26,11 +26,12 @@ mail_summary (int argc, char **argv)
{
message_t msg;
attribute_t attr;
int msgno;
size_t msgno;
size_t count = 0;
int mseen = 0, mnew = 0, mdelete = 0;
int first_new = 0, first_unread = 0;
(void)argc; (void)argv;
mailbox_messages_count (mbox, &count);
for (msgno = 1; msgno <= count; msgno++)
{
......@@ -74,4 +75,5 @@ mail_summary (int argc, char **argv)
/* Set the cursor. */
cursor = realcursor = (first_new == 0) ? ((first_unread == 0) ?
1 : first_unread) : first_new ;
return 0;
}
......
......@@ -18,112 +18,109 @@
#include "mail.h"
const struct mail_command_entry mail_command_table[] = {
{ "a", "alias", 0, mail_alias,
"a[lias] [alias [address...]]" },
{ "alt", "alternates", 0, mail_alt, "alt[ernates] name..." },
{ "C", "Copy", 0, mail_copy, "C[opy] [msglist]" },
{ "cd", "cd", 0, mail_cd, "cd [directory]" },
{ "ch", "chdir", 0, mail_cd, "ch[dir] directory" },
{ "c", "copy", 0, mail_copy, "c[opy] [[msglist] file]" },
{ "dec", "decode", 0, mail_decode, "dec[ode] [msglist]" },
{ "d", "delete", 0, mail_delete, "d[elete] [msglist]" },
{ "di", "discard", 0, mail_discard,
"di[scard] [header-field...]" },
{ "dp", "dp", 0, mail_dp, "dp [msglist]" },
{ "dt", "dt", 0, mail_dp, "dt [msglist]" },
{ "ec", "echo", 0, mail_echo, "ec[ho] string ..." },
{ "e", "edit", 0, mail_edit, "e[dit] [msglist]" },
{ "el", "else", EF_FLOW, mail_else, "el[se]" },
{ "en", "endif", EF_FLOW, mail_endif, "en[dif]" },
{ "ex", "exit", 0, mail_exit, "ex[it]" },
{ "F", "Followup", EF_SEND, mail_followup,"F[ollowup] [msglist]" },
{ "fi", "file", 0, mail_file, "fi[le] [file]" },
{ "fold", "folder", 0, mail_file, "fold[er] [file]" },
{ "folders", "folders", 0, mail_folders,"folders" },
{ "fo", "followup", EF_SEND, mail_followup,"fo[llowup] [msglist]" },
{ "f", "from", 0, mail_from, "f[rom] [msglist]" },
{ "g", "group", 0, mail_alias,
"g[roup] [alias [address...]]" },
{ "h", "headers", 0, mail_headers,"h[eaders] [msglist]" },
{ "hel", "help", 0, mail_help, "hel[p] [command...]" },
{ "ho", "hold", 0, mail_hold, "ho[ld] [msglist]" },
{ "i", "if", EF_FLOW, mail_if, "i[f] s|r|t" },
{ "ig", "ignore", 0, mail_discard,"ig[nore] [header-field...]" },
{ "inc", "incorporate", 0, mail_inc, "inc[orporate]" },
{ "l", "list", 0, mail_list, "l[ist]" },
{ "m", "mail", EF_SEND, mail_send, "m[ail] [address...]" },
{ "mb", "mbox", 0, mail_mbox, "mb[ox] [msglist]" },
{ "n", "next", 0, mail_next, "n[ext] [message]" },
{ "P", "Print", 0, mail_print, "P[rint] [msglist]" },
{ "pi", "pipe", 0, mail_pipe, "pi[pe] [[msglist] command]" },
{ "pre", "preserve", 0, mail_hold, "pre[serve] [msglist]" },
{ "prev", "previous", 0, mail_previous,"prev[ious] [message]" },
{ "p", "print", 0, mail_print, "p[rint] [msglist]" },
{ "q", "quit", 0, mail_quit, "q[uit]" },
{ "R", "Reply", EF_SEND, mail_reply, "R[eply] [msglist]" },
{ "R", "Respond", EF_SEND, mail_reply, "R[espond] [msglist]" },
{ "r", "reply", EF_SEND, mail_reply, "r[eply] [msglist]" },
{ "r", "respond", EF_SEND, mail_reply, "r[espond] [msglist]" },
{ "ret", "retain", 0, mail_retain, "ret[ain] [header-field]" },
{ "S", "Save", 0, mail_save, "S[ave] [msglist]" },
{ "s", "save", 0, mail_save, "s[ave] [[msglist] file]" },
{ "se", "set", 0, mail_set,
"se[t] [name[=[string]]...] [name=number...] [noname...]" },
{ "sh", "shell", 0, mail_shell, "sh[ell] [command]" },
{ "si", "size", 0, mail_size, "si[ze] [msglist]" },
{ "so", "source", 0, mail_source, "so[urce] file" },
{ "su", "summary", 0, mail_summary, "su[mmary]" },
{ "T", "Type", 0, mail_print, "T[ype] [msglist]" },
{ "ta", "tag", 0, mail_tag, "ta[g] [msglist]" },
{ "to", "top", 0, mail_top, "to[p] [msglist]" },
{ "tou", "touch", 0, mail_touch, "tou[ch] [msglist]" },
{ "t", "type", 0, mail_print, "t[ype] [msglist]" },
{ "una", "unalias", 0, mail_unalias,"una[lias] [alias]..." },
{ "u", "undelete", 0, mail_undelete,"u[ndelete] [msglist]" },
{ "uns", "unset", 0, mail_unset, "uns[et] name..." },
{ "unt", "untag", 0, mail_tag, "unt[ag] [msglist]" },
{ "ve", "version", 0, mail_version, "ve[rsion]" },
{ "v", "visual", 0, mail_visual, "v[isual] [msglist]" },
{ "wa", "warranty", 0, mail_warranty,"wa[rranty]" },
{ "W", "Write", 0, mail_write, "W[rite] [msglist]" },
{ "w", "write", 0, mail_write, "w[rite] [[msglist] file]" },
{ "x", "xit", 0, mail_exit, "x[it]" },
{ "z", "", 0, mail_z, "z[+|-|. [count]]" },
{ "?", "?", 0, mail_help, "? [command...]" },
{ "!", "", 0, mail_shell, "![command]" },
{ "=", "=", 0, mail_eq, "=" },
{ "#", "#", 0, NULL, "# comment" },
{ "*", "*", 0, mail_list, "*" },
{ "+", "+", 0, mail_next, "+ [message]" },
{ "|", "|", 0, mail_pipe, "| [[msglist] command]" },
{ "-", "-", 0, mail_previous,"- [message]" },
{ 0, 0, 0, 0, 0}
{ "a", "alias", "a[lias] [alias [address...]]", 0, mail_alias, 0 },
{ "alt", "alternates", "alt[ernates] name...", 0, mail_alt, 0 },
{ "C", "Copy", "C[opy] [msglist]", 0, mail_copy, 0 },
{ "cd", "cd", "cd [directory]", 0, mail_cd, 0 },
{ "ch", "chdir", "ch[dir] directory", 0, mail_cd, 0 },
{ "c", "copy", "c[opy] [[msglist] file]", 0, mail_copy, 0 },
{ "dec", "decode", "dec[ode] [msglist]", 0, mail_decode, 0 },
{ "d", "delete", "d[elete] [msglist]", 0, mail_delete, 0 },
{ "di", "discard", "di[scard] [header-field...]", 0, mail_discard, 0 },
{ "dp", "dp", "dp [msglist]", 0, mail_dp, 0 },
{ "dt", "dt", "dt [msglist]", 0, mail_dp, 0 },
{ "ec", "echo", "ec[ho] string ...", 0, mail_echo, 0 },
{ "e", "edit", "e[dit] [msglist]", 0, mail_edit, 0 },
{ "el", "else", "el[se]", EF_FLOW, mail_else, 0 },
{ "en", "endif", "en[dif]", EF_FLOW, mail_endif, 0 },
{ "ex", "exit", "ex[it]", 0, mail_exit, 0 },
{ "F", "Followup", "F[ollowup] [msglist]", EF_SEND, mail_followup, 0 },
{ "fi", "file", "fi[le] [file]", 0, mail_file, 0 },
{ "fold", "folder", "fold[er] [file]", 0, mail_file, 0 },
{ "folders", "folders", "folders", 0, mail_folders, 0 },
{ "fo", "followup", "fo[llowup] [msglist]", EF_SEND, mail_followup, 0 },
{ "f", "from", "f[rom] [msglist]", 0, mail_from, 0 },
{ "g", "group", "g[roup] [alias [address...]]", 0, mail_alias, 0 },
{ "h", "headers", "h[eaders] [msglist]", 0, mail_headers, 0 },
{ "hel", "help", "hel[p] [command...]", 0, mail_help, 0 },
{ "ho", "hold", "ho[ld] [msglist]", 0, mail_hold, 0 },
{ "i", "if", "i[f] s|r|t", EF_FLOW, mail_if, 0 },
{ "ig", "ignore", "ig[nore] [header-field...]", 0, mail_discard, 0 },
{ "inc", "incorporate", "inc[orporate]", 0, mail_inc, 0 },
{ "l", "list", "l[ist]", 0, mail_list, 0 },
{ "m", "mail", "m[ail] [address...]", EF_SEND, mail_send, 0 },
{ "mb", "mbox", "mb[ox] [msglist]", 0, mail_mbox, 0 },
{ "n", "next", "n[ext] [message]", 0, mail_next, 0 },
{ "P", "Print", "P[rint] [msglist]", 0, mail_print, 0 },
{ "pi", "pipe", "pi[pe] [[msglist] command]", 0, mail_pipe, 0 },
{ "pre", "preserve", "pre[serve] [msglist]", 0, mail_hold, 0 },
{ "prev", "previous", "prev[ious] [message]", 0, mail_previous, 0 },
{ "p", "print", "p[rint] [msglist]", 0, mail_print, 0 },
{ "q", "quit", "q[uit]", 0, mail_quit, 0 },
{ "R", "Reply", "R[eply] [msglist]", EF_SEND, mail_reply, 0 },
{ "R", "Respond", "R[espond] [msglist]", EF_SEND, mail_reply, 0 },
{ "r", "reply", "r[eply] [msglist]", EF_SEND, mail_reply, 0 },
{ "r", "respond", "r[espond] [msglist]", EF_SEND, mail_reply, 0 },
{ "ret", "retain", "ret[ain] [header-field]", 0, mail_retain, 0 },
{ "S", "Save", "S[ave] [msglist]", 0, mail_save, 0 },
{ "s", "save", "s[ave] [[msglist] file]", 0, mail_save, 0 },
{ "se", "set", "se[t] [name[=[string]]...] [name=number...] [noname...]",
0, mail_set, 0 },
{ "sh", "shell", "sh[ell] [command]", 0, mail_shell, 0 },
{ "si", "size", "si[ze] [msglist]", 0, mail_size, 0 },
{ "so", "source", "so[urce] file", 0, mail_source, 0 },
{ "su", "summary", "su[mmary]", 0, mail_summary, 0 },
{ "T", "Type", "T[ype] [msglist]", 0, mail_print, 0 },
{ "ta", "tag", "ta[g] [msglist]", 0, mail_tag, 0 },
{ "to", "top", "to[p] [msglist]", 0, mail_top, 0 },
{ "tou", "touch", "tou[ch] [msglist]", 0, mail_touch, 0 },
{ "t", "type", "t[ype] [msglist]", 0, mail_print, 0 },
{ "una", "unalias", "una[lias] [alias]...", 0, mail_unalias, 0 },
{ "u", "undelete", "u[ndelete] [msglist]", 0, mail_undelete, 0 },
{ "uns", "unset", "uns[et] name...", 0, mail_unset, 0 },
{ "unt", "untag", "unt[ag] [msglist]", 0, mail_tag, 0 },
{ "ve", "version", "ve[rsion]", 0, mail_version, 0 },
{ "v", "visual", "v[isual] [msglist]", 0, mail_visual, 0 },
{ "wa", "warranty", "wa[rranty]", 0, mail_warranty, 0 },
{ "W", "Write", "W[rite] [msglist]", 0, mail_write, 0 },
{ "w", "write", "w[rite] [[msglist] file]", 0, mail_write, 0 },
{ "x", "xit", "x[it]", 0, mail_exit, 0 },
{ "z", "", "z[+|-|. [count]]", 0, mail_z, 0 },
{ "?", "?", "? [command...]", 0, mail_help, 0 },
{ "!", "", "![command]", 0, mail_shell, 0 },
{ "=", "=", "=", 0, mail_eq, 0 },
{ "#", "#", "# comment", 0, NULL, 0 },
{ "*", "*", "*", 0, mail_list, 0 },
{ "+", "+", "+ [message]", 0, mail_next, 0 },
{ "|", "|", "| [[msglist] command]", 0, mail_pipe, 0 },
{ "-", "-", "- [message]", 0, mail_previous, 0 },
{ 0, 0, 0, 0, 0, 0}
};
const struct mail_command_entry mail_escape_table[] = {
{"!", "!", 0, var_shell, "![shell-command]"},
{":", ":", 0, var_command, ":[mail-command]"},
{"-", "-", 0, var_command, "-[mail-command]"},
{"?", "?", 0, var_help, "?"},
{"A", "A", 0, var_sign, "A"},
{"a", "a", 0, var_sign, "a"},
{"b", "b", 0, var_bcc, "b[bcc-list]"},
{"c", "c", 0, var_cc, "c[cc-list]"},
{"d", "d", 0, var_deadletter, "d"},
{"e", "e", 0, var_editor, "e"},
{"f", "f", 0, var_print, "f[mesg-list]"},
{"F", "F", 0, var_print, "F[mesg-list]"},
{"h", "h", 0, var_headers, "h"},
{"i", "i", 0, var_insert, "i[var-name]"},
{"m", "m", 0, var_quote, "m[mesg-list]"},
{"M", "M", 0, var_quote, "M[mesg-list]"},
{"p", "p", 0, var_type_input,"p"},
{"r", "<", 0, var_read, "r[filename]"},
{"s", "s", 0, var_subj, "s[string]"},
{"t", "t", 0, var_to, "t[name-list]"},
{"v", "v", 0, var_visual, "v"},
{"w", "w", 0, var_write, "w[filename]"},
{"x", "x", 0, var_exit, "x"},
{"|", "|", 0, var_pipe, "|[shell-command]"},
{0, 0, 0, 0}
{"!", "!", "![shell-command]", 0, 0, var_shell },
{":", ":", ":[mail-command]", 0, 0, var_command },
{"-", "-", "-[mail-command]", 0, 0, var_command },
{"?", "?", "?", 0, 0, var_help },
{"A", "A", "A", 0, 0, var_sign },
{"a", "a", "a", 0, 0, var_sign },
{"b", "b", "b[bcc-list]", 0, 0, var_bcc },
{"c", "c", "c[cc-list]", 0, 0, var_cc },
{"d", "d", "d", 0, 0, var_deadletter },
{"e", "e", "e", 0, 0, var_editor },
{"f", "f", "f[mesg-list]", 0, 0, var_print },
{"F", "F", "F[mesg-list]", 0, 0, var_print },
{"h", "h", "h", 0, 0, var_headers },
{"i", "i", "i[var-name]", 0, 0, var_insert },
{"m", "m", "m[mesg-list]", 0, 0, var_quote },
{"M", "M", "M[mesg-list]", 0, 0, var_quote },
{"p", "p", "p", 0, 0, var_type_input },
{"r", "<", "r[filename]", 0, 0, var_read },
{"s", "s", "s[string]", 0, 0, var_subj },
{"t", "t", "t[name-list]", 0, 0, var_to },
{"v", "v", "v", 0, 0, var_visual },
{"w", "w", "w[filename]", 0, 0, var_write },
{"x", "x", "x", 0, 0, var_exit },
{"|", "|", "|[shell-command]", 0, 0, var_pipe },
{0, 0, 0, 0, 0, 0}
};
......
......@@ -21,10 +21,12 @@
/* unt[ag] [msglist] */
static int
tag_message (message_t mesg, msgset_t *msgset, int *action)
tag_message (message_t mesg, msgset_t *msgset, void *arg)
{
attribute_t attr;
int *action = arg;
(void)msgset;
message_get_attribute (mesg, &attr);
if (*action)
attribute_set_userflag (attr, MAIL_ATTRIBUTE_TAGGED);
......@@ -42,7 +44,7 @@ mail_tag (int argc, char **argv)
if (msgset_parse (argc, argv, &msgset))
return 1;
util_msgset_iterate (msgset, tag_message, &action);
util_msgset_iterate (msgset, tag_message, (void *)&action);
msgset_free (msgset);
return 0;
......
......@@ -22,6 +22,7 @@
# include <termios.h>
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
......@@ -104,7 +105,7 @@ util_do_command (const char *c, ...)
entry = util_find_entry (mail_command_table, argv[0]);
if (if_cond() == 0 && (entry.flags & EF_FLOW) == 0)
if (if_cond () == 0 && (entry.flags & EF_FLOW) == 0)
{
argcv_free (argc, argv);
return 0;
......@@ -166,11 +167,46 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor)
return status;
}
/* Same as util_msglis_command but the function comes from the escape
cmd table, so will have a different argument signature. */
int
util_msglist_esccmd (int (*escfunc)
__P ((int, char **, struct send_environ *)),
int argc, char **argv, struct send_environ *env,
int set_cursor)
{
msgset_t *list = NULL, *mp;
int status = 0;
if (msgset_parse (argc, argv, &list))
return 1;
realcursor = cursor;
for (mp = list; mp; mp = mp->next)
{
cursor = mp->msg_part[0];
/* NOTE: Should we bail on error also? */
if (escfunc (1, argv, env) != 0)
status = 1;
/* Bail out if we receive an interrupt. */
if (ml_got_interrupt () != 0)
break;
}
msgset_free (list);
if (set_cursor)
realcursor = cursor;
else
cursor = realcursor;
return status;
}
/*
* returns the function to run for command
*/
function_t *
util_command_get (char *cmd)
util_command_get (const char *cmd)
{
struct mail_command_entry entry = util_find_entry (mail_command_table, cmd);
return entry.func;
......@@ -180,7 +216,7 @@ util_command_get (char *cmd)
* returns the mail_command_entry structure for the command matching cmd
*/
struct mail_command_entry
util_find_entry (const struct mail_command_entry *table, char *cmd)
util_find_entry (const struct mail_command_entry *table, const char *cmd)
{
int i = 0, ll = 0, sl = 0;
int len = strlen (cmd);
......@@ -228,9 +264,12 @@ util_getcols (void)
struct winsize ws;
ws.ws_col = ws.ws_row = 0;
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0)
|| ws.ws_row == 0)
ws.ws_col = strtol (getenv("COLUMNS"), NULL, 10);
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0)
{
const char *columns = getenv ("COLUMNS");
if (columns)
ws.ws_col = strtol (columns, NULL, 10);
}
/* FIXME: Should we exit()/abort() if col <= 0 ? */
return ws.ws_col;
......@@ -246,9 +285,12 @@ util_getlines (void)
struct winsize ws;
ws.ws_col = ws.ws_row = 0;
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0)
|| ws.ws_row == 0)
ws.ws_row = strtol (getenv("LINES"), NULL, 10);
if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0)
{
const char *lines = getenv ("LINES");
if (lines)
ws.ws_row = strtol (lines, NULL, 10);
}
/* FIXME: Should we exit()/abort() if row <= 0 ? */
......@@ -257,12 +299,12 @@ util_getlines (void)
}
int
util_screen_lines()
util_screen_lines ()
{
struct mail_env_entry *ep = util_find_env("screen");
struct mail_env_entry *ep = util_find_env ("screen");
size_t n;
if (ep && ep->set && (n = atoi(ep->value)) != 0)
if (ep && ep->set && (n = strtoul (ep->value, NULL, 10)) != 0)
return n;
n = util_getlines();
util_do_command ("set screen=%d", n);
......@@ -270,12 +312,12 @@ util_screen_lines()
}
int
util_screen_columns()
util_screen_columns ()
{
struct mail_env_entry *ep = util_find_env("columns");
size_t n;
if (ep && ep->set && (n = atoi(ep->value)) != 0)
if (ep && ep->set && (n = strtoul (ep->value, NULL, 10)) != 0)
return n;
n = util_getcols();
util_do_command ("set columns=%d", n);
......@@ -295,7 +337,7 @@ util_find_env (const char *variable)
/* Annoying, variable "ask" is equivalent to "asksub". */
static const char *asksub = "asksub";
const char *var = variable;
int len = strlen (var);
size_t len = strlen (var);
node *t;
if (len < 1)
......@@ -425,7 +467,7 @@ util_get_homedir()
}
char *
util_fullpath(char *inpath)
util_fullpath(const char *inpath)
{
return mu_tilde_expansion(inpath, "/", NULL);
}
......@@ -548,7 +590,7 @@ util_slist_destroy (list_t *list)
}
char *
util_slist_to_string (list_t list, char *delim)
util_slist_to_string (list_t list, const char *delim)
{
iterator_t itr;
char *name;
......@@ -569,7 +611,7 @@ util_slist_to_string (list_t list, char *delim)
}
void
util_strcat(char **dest, char *str)
util_strcat(char **dest, const char *str)
{
if (!*dest)
*dest = strdup (str);
......@@ -593,10 +635,10 @@ util_strupper (char *s)
{
if (s)
{
int i;
int len = strlen (s);
size_t i;
size_t len = strlen (s);
for (i = 0; i < len; i++)
s[i] = toupper ((int)s[i]);
s[i] = toupper ((unsigned int)(s[i]));
}
}
......@@ -623,7 +665,7 @@ util_escape_percent (char **str)
/* and escape percent signs */
p = newstr;
q = *str;
while (*p = *q++)
while ((*p = *q++))
{
if (*p == '%')
*++p = '%';
......@@ -679,7 +721,7 @@ util_save_outgoing (message_t msg, char *savefile)
}
else
{
char *buf;
char *buf = NULL;
size_t bsize = 0;
message_size (msg, &bsize);
......@@ -786,7 +828,7 @@ int
util_tempfile(char **namep)
{
char *filename;
char *tmpdir;
const char *tmpdir;
int fd;
/* We have to be extra careful about opening temporary files, since we
......@@ -829,15 +871,15 @@ util_tempfile(char **namep)
return fd;
}
int
static int
util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
{
int i;
unsigned int i;
for (i = 1; i < msgset->npart; i++)
{
message_t submsg = NULL;
int nparts = 0;
unsigned int nparts = 0;
char *type = NULL;
header_t hdr = NULL;
......@@ -876,7 +918,9 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
}
void
util_msgset_iterate (msgset_t *msgset, int (*fun)(), void *closure)
util_msgset_iterate (msgset_t *msgset,
int (*fun) __P ((message_t, msgset_t *, void *)),
void *closure)
{
for (; msgset; msgset = msgset->next)
{
......
......@@ -21,7 +21,7 @@
#include <sys/stat.h>
static void
var_continue()
var_continue (void)
{
fprintf(stdout, "(continue)\n");
}
......@@ -82,6 +82,7 @@ var_command(int argc, char **argv, struct send_environ *env)
int
var_help(int argc, char **argv, struct send_environ *env)
{
(void)env;
if (argc < 2)
return util_help(mail_escape_table, NULL);
else
......@@ -102,6 +103,9 @@ int
var_sign(int argc, char **argv, struct send_environ *env)
{
struct mail_env_entry *p;
(void)argc; (void)env;
if (isupper(argv[0][0]))
p = util_find_env("Sign");
else
......@@ -163,6 +167,8 @@ var_deadletter(int argc, char **argv, struct send_environ *env)
FILE *dead = fopen(getenv("DEAD"), "r");
int c;
(void)argc; (void)argv; (void)env;
while ((c = fgetc(dead)) != EOF)
fputc(c, ofile);
fclose(dead);
......@@ -172,6 +178,7 @@ var_deadletter(int argc, char **argv, struct send_environ *env)
static int
var_run_editor(char *ed, int argc, char **argv, struct send_environ *env)
{
(void)argc; (void)argv;
fclose(env->file);
ofile = env->ofile;
util_do_command("!%s %s", ed, env->filename);
......@@ -200,6 +207,7 @@ var_visual(int argc, char **argv, struct send_environ *env)
int
var_print(int argc, char **argv, struct send_environ *env)
{
(void)env;
return mail_print(argc, argv);
}
......@@ -207,6 +215,7 @@ var_print(int argc, char **argv, struct send_environ *env)
int
var_headers(int argc, char **argv, struct send_environ *env)
{
(void)argc; (void)argv;
ml_reread("To: ", &env->to);
ml_reread("Cc: ", &env->cc);
ml_reread("Bcc: ", &env->bcc);
......@@ -219,6 +228,7 @@ var_headers(int argc, char **argv, struct send_environ *env)
int
var_insert(int argc, char **argv, struct send_environ *env)
{
(void)env;
if (var_check_args (argc, argv))
return 1;
fprintf(ofile, "%s", util_find_env(argv[1])->value);
......@@ -231,7 +241,7 @@ int
var_quote(int argc, char **argv, struct send_environ *env)
{
if (argc > 1)
return util_msglist_command(var_quote, argc, argv, 0);
return util_msglist_esccmd (var_quote, argc, argv, env, 0);
else
{
message_t mesg;
......@@ -251,20 +261,19 @@ var_quote(int argc, char **argv, struct send_environ *env)
if (islower(argv[0][0]))
{
size_t i, num = 0;
char buffer[512];
char buf[512];
message_get_header(mesg, &hdr);
header_get_field_count(hdr, &num);
for (i = 1; i <= num; i++)
{
header_get_field_name(hdr, i, buffer, sizeof(buffer), NULL);
if (mail_header_is_visible(buffer))
header_get_field_name(hdr, i, buf, sizeof buf, NULL);
if (mail_header_is_visible(buf))
{
fprintf(ofile, "%s%s: ", prefix, buffer);
header_get_field_value(hdr, i, buffer, sizeof(buffer),
NULL);
fprintf(ofile, "%s\n", buffer);
fprintf(ofile, "%s%s: ", prefix, buf);
header_get_field_value(hdr, i, buf, sizeof buf, NULL);
fprintf(ofile, "%s\n", buf);
}
}
fprintf(ofile, "\n");
......@@ -274,7 +283,7 @@ var_quote(int argc, char **argv, struct send_environ *env)
else
message_get_stream(mesg, &stream);
while (stream_readline(stream, buffer, sizeof(buffer) - 1, off, &n) == 0
while (stream_readline(stream, buffer, sizeof buffer - 1, off, &n) == 0
&& n != 0)
{
buffer[n] = '\0';
......@@ -292,6 +301,8 @@ var_type_input(int argc, char **argv, struct send_environ *env)
{
char buf[512];
(void)argc; (void)argv;
fprintf(env->ofile, "Message contains:\n");
if (env->to)
......@@ -321,6 +332,8 @@ var_read(int argc, char **argv, struct send_environ *env)
size_t size, lines;
char buf[512];
(void)env;
if (var_check_args (argc, argv))
return 1;
filename = util_fullpath(argv[1]);
......@@ -405,6 +418,7 @@ var_write(int argc, char **argv, struct send_environ *env)
int
var_exit(int argc, char **argv, struct send_environ *env)
{
(void)argc; (void)argv; (void)env;
return util_do_command("quit");
}
......
......@@ -21,7 +21,7 @@
* ve[rsion]
*/
static char *with_defs[] =
static const char *with_defs[] =
{
#ifdef WITH_PTHREAD
"PTHREAD",
......@@ -39,6 +39,7 @@ static char *with_defs[] =
int
mail_version (int argc, char **argv)
{
(void)argc; (void)argv;
fprintf (ofile, "%s", argp_program_version);
if (with_defs[0] != NULL)
{
......
......@@ -102,7 +102,7 @@ mail_write (int argc, char **argv)
attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
}
fprintf (ofile, "\"%s\" %3ld/%-5ld\n", filename, total_lines, total_size);
fprintf (ofile, "\"%s\" %3d/%-5d\n", filename, total_lines, total_size);
free (filename);
fclose (output);
......
......@@ -31,7 +31,7 @@
*/
static int
z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
z_parse_args(int argc, char **argv, unsigned int *return_count, int *return_dir)
{
int count = 1;
int mul = 1;
......@@ -87,7 +87,7 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
return 1;
}
if ((mul = atoi(argp)) == 0)
if ((mul = strtoul (argp, NULL, 10)) == 0)
{
util_error("Bad number of pages");
return 1;
......@@ -107,7 +107,7 @@ mail_z (int argc, char **argv)
{
unsigned int i, nlines;
unsigned int pagelines = util_screen_lines();
int count;
unsigned int count;
int dir;
if (z_parse_args(argc, argv, &count, &dir))
......@@ -161,7 +161,7 @@ mail_z (int argc, char **argv)
int lastpage = total - pagelines + 1;
if (lastpage <= 0)
lastpage = 1;
if (cursor > lastpage)
if (cursor > (unsigned int)lastpage)
{
realcursor = cursor;
cursor = lastpage;
......