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 @@ ...@@ -17,9 +17,10 @@
17 17
18 #include "mail.h" 18 #include "mail.h"
19 19
20 static void alias_print __P((char *name)); 20 static void alias_print __P ((char *name));
21 static void alias_print_group __P((char *name, list_t list)); 21 static void alias_print_group __P ((char *name, list_t list));
22 static int alias_create __P((char *name, list_t *plist)); 22 static int alias_create __P ((char *name, list_t *plist));
23 static int alias_lookup __P ((char *name, list_t *plist));
23 24
24 /* 25 /*
25 * a[lias] [alias [address...]] 26 * a[lias] [alias [address...]]
...@@ -36,7 +37,7 @@ mail_alias (int argc, char **argv) ...@@ -36,7 +37,7 @@ mail_alias (int argc, char **argv)
36 else 37 else
37 { 38 {
38 list_t list; 39 list_t list;
39 40
40 if (alias_create(argv[1], &list)) 41 if (alias_create(argv[1], &list))
41 return 1; 42 return 1;
42 43
...@@ -60,16 +61,16 @@ struct _alias ...@@ -60,16 +61,16 @@ struct _alias
60 pair of them grows exponentially, starting from 64. 61 pair of them grows exponentially, starting from 64.
61 Hopefully no one will need more than 32797 aliases, and even if 62 Hopefully no one will need more than 32797 aliases, and even if
62 someone will, it is easy enough to add more numbers to the sequence. */ 63 someone will, it is easy enough to add more numbers to the sequence. */
63 size_t hash_size[] = 64 static unsigned int hash_size[] =
64 { 65 {
65 37, 101, 229, 487, 1009, 2039, 4091, 8191, 16411, 32797, 66 37, 101, 229, 487, 1009, 2039, 4091, 8191, 16411, 32797,
66 }; 67 };
67 /* Maximum number of re-hashes: */ 68 /* Maximum number of re-hashes: */
68 int max_rehash = sizeof (hash_size) / sizeof (hash_size[0]); 69 static unsigned int max_rehash = sizeof (hash_size) / sizeof (hash_size[0]);
69 alias_t *aliases; /* Table of aliases */ 70 static alias_t *aliases; /* Table of aliases */
70 size_t hash_num; /* Index to hash_size table */ 71 static unsigned int hash_num; /* Index to hash_size table */
71 72
72 static unsigned hash __P((char *name)); 73 static unsigned int hash __P((char *name));
73 static int alias_rehash __P((void)); 74 static int alias_rehash __P((void));
74 static alias_t *alias_lookup_or_install __P((char *name, int install)); 75 static alias_t *alias_lookup_or_install __P((char *name, int install));
75 static void alias_print_group __P((char *name, list_t list)); 76 static void alias_print_group __P((char *name, list_t list));
...@@ -91,8 +92,8 @@ alias_rehash() ...@@ -91,8 +92,8 @@ alias_rehash()
91 { 92 {
92 alias_t *old_aliases = aliases; 93 alias_t *old_aliases = aliases;
93 alias_t *ap; 94 alias_t *ap;
94 int i; 95 unsigned int i;
95 96
96 if (++hash_num >= max_rehash) 97 if (++hash_num >= max_rehash)
97 { 98 {
98 util_error("alias hash table full"); 99 util_error("alias hash table full");
...@@ -120,8 +121,7 @@ alias_t * ...@@ -120,8 +121,7 @@ alias_t *
120 alias_lookup_or_install(char *name, int install) 121 alias_lookup_or_install(char *name, int install)
121 { 122 {
122 unsigned i, pos; 123 unsigned i, pos;
123 alias_t *slot = NULL; 124
124
125 if (!aliases) 125 if (!aliases)
126 { 126 {
127 if (install) 127 if (install)
...@@ -144,20 +144,20 @@ alias_lookup_or_install(char *name, int install) ...@@ -144,20 +144,20 @@ alias_lookup_or_install(char *name, int install)
144 if (i == pos) 144 if (i == pos)
145 break; 145 break;
146 } 146 }
147 147
148 if (!install) 148 if (!install)
149 return NULL; 149 return NULL;
150 150
151 if (aliases[i].name == NULL) 151 if (aliases[i].name == NULL)
152 return &aliases[i]; 152 return &aliases[i];
153 153
154 if (alias_rehash()) 154 if (alias_rehash())
155 return NULL; 155 return NULL;
156 156
157 return alias_lookup_or_install(name, install); 157 return alias_lookup_or_install(name, install);
158 } 158 }
159 159
160 int 160 static int
161 alias_lookup(char *name, list_t *plist) 161 alias_lookup(char *name, list_t *plist)
162 { 162 {
163 alias_t *ap = alias_lookup_or_install(name, 0); 163 alias_t *ap = alias_lookup_or_install(name, 0);
...@@ -174,11 +174,11 @@ alias_print(char *name) ...@@ -174,11 +174,11 @@ alias_print(char *name)
174 { 174 {
175 if (!name) 175 if (!name)
176 { 176 {
177 int i; 177 unsigned int i;
178 178
179 if (!aliases) 179 if (!aliases)
180 return; 180 return;
181 181
182 for (i = 0; i < hash_size[hash_num]; i++) 182 for (i = 0; i < hash_size[hash_num]; i++)
183 { 183 {
184 if (aliases[i].name) 184 if (aliases[i].name)
...@@ -214,12 +214,12 @@ alias_create(char *name, list_t *plist) ...@@ -214,12 +214,12 @@ alias_create(char *name, list_t *plist)
214 if (!ap->name) 214 if (!ap->name)
215 return 1; 215 return 1;
216 } 216 }
217 217
218 *plist = ap->list; 218 *plist = ap->list;
219 219
220 return 0; 220 return 0;
221 } 221 }
222 222
223 void 223 void
224 alias_print_group(char *name, list_t list) 224 alias_print_group(char *name, list_t list)
225 { 225 {
...@@ -231,7 +231,7 @@ alias_print_group(char *name, list_t list) ...@@ -231,7 +231,7 @@ alias_print_group(char *name, list_t list)
231 void 231 void
232 alias_destroy(char *name) 232 alias_destroy(char *name)
233 { 233 {
234 int i, j, r; 234 unsigned int i, j, r;
235 alias_t *alias = alias_lookup_or_install(name, 0); 235 alias_t *alias = alias_lookup_or_install(name, 0);
236 if (!alias) 236 if (!alias)
237 return; 237 return;
...@@ -260,9 +260,8 @@ char * ...@@ -260,9 +260,8 @@ char *
260 alias_expand(char *name) 260 alias_expand(char *name)
261 { 261 {
262 list_t list; 262 list_t list;
263 263
264 if (!alias_lookup(name, &list)) 264 if (!alias_lookup(name, &list))
265 return strdup (name); 265 return strdup (name);
266 return util_slist_to_string(list, ","); 266 return util_slist_to_string(list, ",");
267 } 267 }
268
......
...@@ -89,7 +89,7 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -89,7 +89,7 @@ mail_copy0 (int argc, char **argv, int mark)
89 } 89 }
90 } 90 }
91 91
92 fprintf (ofile, "\"%s\" %3ld/%-5ld\n", filename, total_lines, total_size); 92 fprintf (ofile, "\"%s\" %3d/%-5d\n", filename, total_lines, total_size);
93 93
94 mailbox_close (mbx); 94 mailbox_close (mbx);
95 mailbox_destroy (&mbx); 95 mailbox_destroy (&mbx);
......
...@@ -29,8 +29,7 @@ struct decode_closure ...@@ -29,8 +29,7 @@ struct decode_closure
29 }; 29 };
30 30
31 static int print_stream __P ((stream_t, FILE *)); 31 static int print_stream __P ((stream_t, FILE *));
32 static int display_message __P ((message_t, msgset_t *msgset, 32 static int display_message __P ((message_t, msgset_t *msgset, void *closure));
33 struct decode_closure *closure));
34 static int display_message0 __P ((FILE *, message_t, const msgset_t *, int)); 33 static int display_message0 __P ((FILE *, message_t, const msgset_t *, int));
35 static int mailcap_lookup __P ((const char *)); 34 static int mailcap_lookup __P ((const char *));
36 static int get_content_encoding __P ((header_t hdr, char **value)); 35 static int get_content_encoding __P ((header_t hdr, char **value));
...@@ -46,24 +45,24 @@ mail_decode (int argc, char **argv) ...@@ -46,24 +45,24 @@ mail_decode (int argc, char **argv)
46 45
47 decode_closure.select_hdr = islower (argv[0][0]); 46 decode_closure.select_hdr = islower (argv[0][0]);
48 47
49 util_msgset_iterate (msgset, display_message, &decode_closure); 48 util_msgset_iterate (msgset, display_message, (void *)&decode_closure);
50 49
51 msgset_free (msgset); 50 msgset_free (msgset);
52 return 0; 51 return 0;
53 } 52 }
54 53
55 int 54 int
56 display_message (message_t mesg, msgset_t *msgset, 55 display_message (message_t mesg, msgset_t *msgset, void *arg)
57 struct decode_closure *closure)
58 { 56 {
59 FILE *out; 57 FILE *out;
60 size_t lines = 0; 58 size_t lines = 0;
59 struct decode_closure *closure = arg;
61 60
62 if (util_isdeleted (msgset->msg_part[0])) 61 if (util_isdeleted (msgset->msg_part[0]))
63 return 1; 62 return 1;
64 63
65 message_lines (mesg, &lines); 64 message_lines (mesg, &lines);
66 if ((util_find_env("crt"))->set && lines > util_getlines ()) 65 if ((util_find_env("crt"))->set && (int)lines > util_getlines ())
67 out = popen (getenv("PAGER"), "w"); 66 out = popen (getenv("PAGER"), "w");
68 else 67 else
69 out = ofile; 68 out = ofile;
...@@ -88,6 +87,8 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -88,6 +87,8 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
88 int select_hdr) 87 int select_hdr)
89 { 88 {
90 header_t hdr = NULL; 89 header_t hdr = NULL;
90
91 (void)msgset;
91 /* Print the selected headers only. */ 92 /* Print the selected headers only. */
92 if (select_hdr) 93 if (select_hdr)
93 { 94 {
...@@ -119,15 +120,15 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -119,15 +120,15 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
119 } 120 }
120 } 121 }
121 122
122 void 123 static void
123 display_part_header (FILE *out, const msgset_t *msgset, 124 display_part_header (FILE *out, const msgset_t *msgset,
124 char *type, char *encoding) 125 char *type, char *encoding)
125 { 126 {
126 int size = util_screen_columns () - 3; 127 int size = util_screen_columns () - 3;
127 int i; 128 unsigned int i;
128 129
129 fputc ('+', out); 130 fputc ('+', out);
130 for (i = 0; i <= size; i++) 131 for (i = 0; (int)i <= size; i++)
131 fputc ('-', out); 132 fputc ('-', out);
132 fputc ('+', out); 133 fputc ('+', out);
133 fputc ('\n', out); 134 fputc ('\n', out);
...@@ -141,7 +142,7 @@ display_part_header (FILE *out, const msgset_t *msgset, ...@@ -141,7 +142,7 @@ display_part_header (FILE *out, const msgset_t *msgset,
141 fprintf (out, "| Type=%s\n", type); 142 fprintf (out, "| Type=%s\n", type);
142 fprintf (out, "| encoding=%s\n", encoding); 143 fprintf (out, "| encoding=%s\n", encoding);
143 fputc ('+', out); 144 fputc ('+', out);
144 for (i = 0; i <= size; i++) 145 for (i = 0; (int)i <= size; i++)
145 fputc ('-', out); 146 fputc ('-', out);
146 fputc ('+', out); 147 fputc ('+', out);
147 fputc ('\n', out); 148 fputc ('\n', out);
...@@ -164,7 +165,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -164,7 +165,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
164 message_is_multipart (mesg, &ismime); 165 message_is_multipart (mesg, &ismime);
165 if (ismime) 166 if (ismime)
166 { 167 {
167 int j; 168 unsigned int j;
168 169
169 message_get_num_parts (mesg, &nparts); 170 message_get_num_parts (mesg, &nparts);
170 171
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
21 * d[elete] [msglist] 21 * d[elete] [msglist]
22 */ 22 */
23 23
24 int 24 static int
25 mail_delete0 () 25 mail_delete0 (void)
26 { 26 {
27 message_t msg; 27 message_t msg;
28 attribute_t attr; 28 attribute_t attr;
...@@ -39,13 +39,14 @@ mail_delete (int argc, char **argv) ...@@ -39,13 +39,14 @@ mail_delete (int argc, char **argv)
39 int rc = 0; 39 int rc = 0;
40 40
41 if (argc > 1) 41 if (argc > 1)
42 rc = util_msglist_command (mail_delete0, argc, argv, 0); 42 rc = util_msglist_command (mail_delete, argc, argv, 0);
43 else 43 else
44 rc = mail_delete0 (); 44 rc = mail_delete0 ();
45 45
46 /* Reajust the realcursor to no point to the deleted messages. */
46 if (cursor == realcursor) 47 if (cursor == realcursor)
47 { 48 {
48 int here = realcursor; 49 unsigned int here = realcursor;
49 do 50 do
50 { 51 {
51 message_t msg; 52 message_t msg;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 int 24 int
25 mail_eq (int argc, char **argv) 25 mail_eq (int argc, char **argv)
26 { 26 {
27 (void)argc; (void)argv;
27 fprintf (ofile, "%d\n", realcursor); 28 fprintf (ofile, "%d\n", realcursor);
28 return 0; 29 return 0;
29 } 30 }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
20 int 20 int
21 mail_exit (int argc, char **argv) 21 mail_exit (int argc, char **argv)
22 { 22 {
23 (void)argc; (void)argv;
23 mailbox_close (mbox); 24 mailbox_close (mbox);
24 exit (0); 25 exit (0);
25 } 26 }
......
...@@ -27,6 +27,8 @@ mail_folders (int argc, char **argv) ...@@ -27,6 +27,8 @@ mail_folders (int argc, char **argv)
27 char *path; 27 char *path;
28 struct mail_env_entry *env = util_find_env ("folder"); 28 struct mail_env_entry *env = util_find_env ("folder");
29 29
30 (void)argc; (void)argv;
31
30 if (!env->set) 32 if (!env->set)
31 { 33 {
32 util_error("No value set for \"folder\""); 34 util_error("No value set for \"folder\"");
...@@ -36,6 +38,6 @@ mail_folders (int argc, char **argv) ...@@ -36,6 +38,6 @@ mail_folders (int argc, char **argv)
36 path = util_fullpath(env->value); 38 path = util_fullpath(env->value);
37 util_do_command("! %s %s", getenv("LISTER"), path); 39 util_do_command("! %s %s", getenv("LISTER"), path);
38 free(path); 40 free(path);
39 41
40 return 0; 42 return 0;
41 } 43 }
......
...@@ -28,7 +28,6 @@ mail_followup (int argc, char **argv) ...@@ -28,7 +28,6 @@ mail_followup (int argc, char **argv)
28 message_t msg; 28 message_t msg;
29 header_t hdr; 29 header_t hdr;
30 char *str; 30 char *str;
31 int i;
32 msgset_t *msglist, *mp; 31 msgset_t *msglist, *mp;
33 struct send_environ env; 32 struct send_environ env;
34 int status; 33 int status;
......
...@@ -54,13 +54,13 @@ mail_from (int argc, char **argv) ...@@ -54,13 +54,13 @@ mail_from (int argc, char **argv)
54 address_t address = NULL; 54 address_t address = NULL;
55 if (address_create (&address, from) == 0) 55 if (address_create (&address, from) == 0)
56 { 56 {
57 char p[128]; 57 char name[128];
58 size_t len = strlen (from); 58 size_t len = strlen (from);
59 *p = '\0'; 59 *name = '\0';
60 address_get_personal (address, 1, p, sizeof p, NULL); 60 address_get_personal (address, 1, name, sizeof name, NULL);
61 if (*p && len) 61 if (*name && len)
62 { 62 {
63 strncpy (from, p, len - 1); 63 strncpy (from, name, len - 1);
64 from[len - 1] = '\0'; 64 from[len - 1] = '\0';
65 } 65 }
66 else 66 else
...@@ -103,7 +103,7 @@ mail_from (int argc, char **argv) ...@@ -103,7 +103,7 @@ mail_from (int argc, char **argv)
103 message_size (msg, &m_size); 103 message_size (msg, &m_size);
104 message_lines (msg, &m_lines); 104 message_lines (msg, &m_lines);
105 105
106 snprintf (st, sizeof(st), "%3ld/%-5ld", m_lines, m_size); 106 snprintf (st, sizeof(st), "%3d/%-5d", m_lines, m_size);
107 107
108 /* The "From" field will take a third of the screen. 108 /* The "From" field will take a third of the screen.
109 Subject will take the rest. 109 Subject will take the rest.
......
...@@ -45,13 +45,13 @@ mail_headers (int argc, char **argv) ...@@ -45,13 +45,13 @@ mail_headers (int argc, char **argv)
45 if (lines < 0) 45 if (lines < 0)
46 lines = util_screen_lines (); 46 lines = util_screen_lines ();
47 47
48 if (lines < total) 48 if ((unsigned int)lines < total)
49 { 49 {
50 low = list->msg_part[0] - (lines / 2); 50 low = list->msg_part[0] - (lines / 2);
51 if (low < 1) 51 if (low < 1)
52 low = 1; 52 low = 1;
53 high = low + lines; 53 high = low + lines;
54 if (high > total) 54 if ((unsigned int)high > total)
55 { 55 {
56 high = total; 56 high = total;
57 low = high - lines; 57 low = high - lines;
......
...@@ -49,7 +49,7 @@ _cond_push(int val) ...@@ -49,7 +49,7 @@ _cond_push(int val)
49 _cond_stack = realloc(_cond_stack, 49 _cond_stack = realloc(_cond_stack,
50 sizeof(_cond_stack[0])*_cond_stack_size); 50 sizeof(_cond_stack[0])*_cond_stack_size);
51 } 51 }
52 52
53 if (!_cond_stack) 53 if (!_cond_stack)
54 { 54 {
55 util_error("not enough memory"); 55 util_error("not enough memory");
...@@ -68,7 +68,7 @@ _cond_pop() ...@@ -68,7 +68,7 @@ _cond_pop()
68 } 68 }
69 return _cond_stack[--_cond_level]; 69 return _cond_stack[--_cond_level];
70 } 70 }
71 71
72 /* 72 /*
73 * i[f] s|r|t 73 * i[f] s|r|t
74 * mail-commands 74 * mail-commands
...@@ -131,6 +131,7 @@ int ...@@ -131,6 +131,7 @@ int
131 mail_else (int argc, char **argv) 131 mail_else (int argc, char **argv)
132 { 132 {
133 int cond; 133 int cond;
134 (void)argc; (void)argv;
134 if (_cond_level == 0) 135 if (_cond_level == 0)
135 { 136 {
136 util_error("else without matching if"); 137 util_error("else without matching if");
...@@ -146,6 +147,7 @@ mail_else (int argc, char **argv) ...@@ -146,6 +147,7 @@ mail_else (int argc, char **argv)
146 int 147 int
147 mail_endif (int argc, char **argv) 148 mail_endif (int argc, char **argv)
148 { 149 {
150 (void)argc; (void)argv;
149 if (_cond_level == 0) 151 if (_cond_level == 0)
150 { 152 {
151 util_error("endif without matching if"); 153 util_error("endif without matching if");
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 int 24 int
25 mail_inc (int argc, char **argv) 25 mail_inc (int argc, char **argv)
26 { 26 {
27 (void)argc; (void)argv;
27 if (!mailbox_is_updated (mbox)) 28 if (!mailbox_is_updated (mbox))
28 { 29 {
29 mailbox_messages_count (mbox, &total); 30 mailbox_messages_count (mbox, &total);
...@@ -31,6 +32,6 @@ mail_inc (int argc, char **argv) ...@@ -31,6 +32,6 @@ mail_inc (int argc, char **argv)
31 } 32 }
32 else 33 else
33 fprintf (ofile, "No new mail for %s\n", mail_whoami()); 34 fprintf (ofile, "No new mail for %s\n", mail_whoami());
34 35
35 return 0; 36 return 0;
36 } 37 }
......
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
25 int 25 int
26 mail_list (int argc, char **argv) 26 mail_list (int argc, char **argv)
27 { 27 {
28 char *cmd = NULL; 28 const char *cmd = NULL;
29 int i = 0, pos = 0, len = 0; 29 int i = 0, pos = 0, len = 0;
30 int cols = util_getcols (); 30 int cols = util_getcols ();
31 31
32 (void)argc; (void)argv;
33
32 for (i=0; mail_command_table[i].shortname != 0; i++) 34 for (i=0; mail_command_table[i].shortname != 0; i++)
33 { 35 {
34 len = strlen (mail_command_table[i].longname); 36 len = strlen (mail_command_table[i].longname);
......
...@@ -31,21 +31,21 @@ static char doc[] = "GNU mail -- the standard /bin/mail interface"; ...@@ -31,21 +31,21 @@ static char doc[] = "GNU mail -- the standard /bin/mail interface";
31 static char args_doc[] = "[address...]"; 31 static char args_doc[] = "[address...]";
32 32
33 static struct argp_option options[] = { 33 static struct argp_option options[] = {
34 {"exist", 'e', 0, 0, "Return true if mail exists"}, 34 {"exist", 'e', 0, 0, "Return true if mail exists", 0},
35 {"file", 'f', "FILE", OPTION_ARG_OPTIONAL, 35 {"file", 'f', "FILE", OPTION_ARG_OPTIONAL,
36 "Operate on mailbox FILE (default ~/mbox)"}, 36 "Operate on mailbox FILE (default ~/mbox)", 0},
37 {"byname", 'F', 0, 0, "Save messages according to sender"}, 37 {"byname", 'F', 0, 0, "Save messages according to sender", 0},
38 {"headers", 'H', 0, 0, "Write a header summary and exit"}, 38 {"headers", 'H', 0, 0, "Write a header summary and exit", 0},
39 {"ignore", 'i', 0, 0, "Ignore interrupts"}, 39 {"ignore", 'i', 0, 0, "Ignore interrupts", 0},
40 {"norc", 'n', 0, 0, "Do not read the system mailrc file"}, 40 {"norc", 'n', 0, 0, "Do not read the system mailrc file", 0},
41 {"nosum", 'N', 0, 0, "Do not display initial header summary"}, 41 {"nosum", 'N', 0, 0, "Do not display initial header summary", 0},
42 {"print", 'p', 0, 0, "Print all mail to standard output"}, 42 {"print", 'p', 0, 0, "Print all mail to standard output", 0},
43 {"quit", 'q', 0, 0, "Cause interrupts to terminate program"}, 43 {"quit", 'q', 0, 0, "Cause interrupts to terminate program", 0},
44 {"read", 'r', 0, 0, "Same as -p"}, 44 {"read", 'r', 0, 0, "Same as -p", 0},
45 {"subject", 's', "SUBJ", 0, "Send a message with a Subject of SUBJ"}, 45 {"subject", 's', "SUBJ", 0, "Send a message with a Subject of SUBJ", 0},
46 {"to", 't', 0, 0, "Precede message by a list of addresses"}, 46 {"to", 't', 0, 0, "Precede message by a list of addresses", 0},
47 {"user", 'u', "USER", 0, "Operate on USER's mailbox"}, 47 {"user", 'u', "USER", 0, "Operate on USER's mailbox", 0},
48 { 0 } 48 { NULL, 0, NULL, 0, NULL, 0 }
49 }; 49 };
50 50
51 struct arguments 51 struct arguments
...@@ -124,7 +124,7 @@ parse_opt (int key, char *arg, struct argp_state *state) ...@@ -124,7 +124,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
124 return 0; 124 return 0;
125 } 125 }
126 126
127 static struct argp argp = { options, parse_opt, args_doc, doc }; 127 static struct argp argp = { options, parse_opt, args_doc, doc, NULL, NULL, NULL };
128 128
129 static char * 129 static char *
130 mail_cmdline(void *closure, int cont) 130 mail_cmdline(void *closure, int cont)
...@@ -133,6 +133,8 @@ mail_cmdline(void *closure, int cont) ...@@ -133,6 +133,8 @@ mail_cmdline(void *closure, int cont)
133 char *prompt = NULL; 133 char *prompt = NULL;
134 char *rc; 134 char *rc;
135 135
136 (void)cont;
137
136 while (1) 138 while (1)
137 { 139 {
138 if (util_find_env ("autoinc")->set && !mailbox_is_updated (mbox)) 140 if (util_find_env ("autoinc")->set && !mailbox_is_updated (mbox))
...@@ -142,7 +144,7 @@ mail_cmdline(void *closure, int cont) ...@@ -142,7 +144,7 @@ mail_cmdline(void *closure, int cont)
142 } 144 }
143 145
144 if (interactive) 146 if (interactive)
145 prompt = pev->set && pev->value != NULL ? pev->value : "? "; 147 prompt = pev->set && pev->value != NULL ? pev->value : (char *)"? ";
146 148
147 rc = readline (prompt); 149 rc = readline (prompt);
148 150
...@@ -167,7 +169,7 @@ int ...@@ -167,7 +169,7 @@ int
167 main (int argc, char **argv) 169 main (int argc, char **argv)
168 { 170 {
169 struct mail_env_entry *mode = NULL, *prompt = NULL; 171 struct mail_env_entry *mode = NULL, *prompt = NULL;
170 int modelen = 0; 172 size_t modelen = 0;
171 struct arguments args; 173 struct arguments args;
172 174
173 ofile = stdout; 175 ofile = stdout;
...@@ -445,8 +447,7 @@ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\n\ ...@@ -445,8 +447,7 @@ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.\n\
445 int 447 int
446 mail_warranty(int argc, char **argv) 448 mail_warranty(int argc, char **argv)
447 { 449 {
450 (void)argc; (void)argv;
448 fprintf (ofile, "%s", warranty_stmt); 451 fprintf (ofile, "%s", warranty_stmt);
449 return 0; 452 return 0;
450 } 453 }
451
452
......
...@@ -58,7 +58,7 @@ ml_got_interrupt () ...@@ -58,7 +58,7 @@ ml_got_interrupt ()
58 return rc; 58 return rc;
59 } 59 }
60 60
61 int 61 static int
62 ml_getc (FILE *stream) 62 ml_getc (FILE *stream)
63 { 63 {
64 unsigned char c; 64 unsigned char c;
...@@ -86,7 +86,7 @@ ml_readline_init () ...@@ -86,7 +86,7 @@ ml_readline_init ()
86 return; 86 return;
87 87
88 #ifdef WITH_READLINE 88 #ifdef WITH_READLINE
89 rl_readline_name = "mail"; 89 rl_readline_name = (char *)"mail";
90 rl_attempted_completion_function = (CPPFunction*)ml_command_completion; 90 rl_attempted_completion_function = (CPPFunction*)ml_command_completion;
91 rl_getc_function = ml_getc; 91 rl_getc_function = ml_getc;
92 #endif 92 #endif
...@@ -114,7 +114,7 @@ ml_readline_init () ...@@ -114,7 +114,7 @@ ml_readline_init ()
114 static char *insert_text; 114 static char *insert_text;
115 115
116 static int 116 static int
117 ml_insert_hook () 117 ml_insert_hook (void)
118 { 118 {
119 if (insert_text) 119 if (insert_text)
120 rl_insert_text (insert_text); 120 rl_insert_text (insert_text);
...@@ -122,14 +122,14 @@ ml_insert_hook () ...@@ -122,14 +122,14 @@ ml_insert_hook ()
122 } 122 }
123 123
124 int 124 int
125 ml_reread (char *prompt, char **text) 125 ml_reread (const char *prompt, char **text)
126 { 126 {
127 char *s; 127 char *s;
128 128
129 ml_clear_interrupt (); 129 ml_clear_interrupt ();
130 insert_text = *text; 130 insert_text = *text;
131 rl_startup_hook = ml_insert_hook; 131 rl_startup_hook = ml_insert_hook;
132 s = readline (prompt); 132 s = readline ((char *)prompt);
133 if (!ml_got_interrupt ()) 133 if (!ml_got_interrupt ())
134 { 134 {
135 if (*text) 135 if (*text)
...@@ -150,6 +150,7 @@ ml_reread (char *prompt, char **text) ...@@ -150,6 +150,7 @@ ml_reread (char *prompt, char **text)
150 char ** 150 char **
151 ml_command_completion (char *cmd, int start, int end) 151 ml_command_completion (char *cmd, int start, int end)
152 { 152 {
153 (void)end;
153 if (start == 0) 154 if (start == 0)
154 return completion_matches (cmd, ml_command_generator); 155 return completion_matches (cmd, ml_command_generator);
155 return NULL; 156 return NULL;
...@@ -162,7 +163,7 @@ char * ...@@ -162,7 +163,7 @@ char *
162 ml_command_generator (char *text, int state) 163 ml_command_generator (char *text, int state)
163 { 164 {
164 static int i, len; 165 static int i, len;
165 char *name; 166 const char *name;
166 167
167 if (!state) 168 if (!state)
168 { 169 {
......
...@@ -29,13 +29,17 @@ struct header_data ...@@ -29,13 +29,17 @@ struct header_data
29 char *expr; 29 char *expr;
30 }; 30 };
31 31
32 static msgset_t *msgset_select (int (*sel)(), void *closure, int rev, 32 static msgset_t *msgset_select __P ((int (*sel) __P ((message_t, void *)),
33 int max_matches); 33 void *closure, int rev,
34 static int select_header (message_t msg, void *closure); 34 unsigned int max_matches));
35 static int select_body (message_t msg, void *closure); 35 static int select_header __P ((message_t msg, void *closure));
36 static int select_type (message_t msg, void *closure); 36 static int select_body __P ((message_t msg, void *closure));
37 static int select_sender (message_t msg, void *closure); 37 static int select_type __P ((message_t msg, void *closure));
38 static int select_deleted (message_t msg, void *closure); 38 static int select_sender __P ((message_t msg, void *closure));
39 static int select_deleted __P ((message_t msg, void *closure));
40
41 int yyerror __P ((const char *));
42 int yylex __P ((void));
39 43
40 static msgset_t *result; 44 static msgset_t *result;
41 %} 45 %}
...@@ -170,7 +174,6 @@ range : number ...@@ -170,7 +174,6 @@ range : number
170 } 174 }
171 else 175 else
172 { 176 {
173 msgset_t *mp;
174 $$ = msgset_range ($1, $3->msg_part[0]-1); 177 $$ = msgset_range ($1, $3->msg_part[0]-1);
175 if (!$$) 178 if (!$$)
176 YYERROR; 179 YYERROR;
...@@ -209,7 +212,7 @@ static int cur_ind; ...@@ -209,7 +212,7 @@ static int cur_ind;
209 static char *cur_p; 212 static char *cur_p;
210 213
211 int 214 int
212 yyerror (char *s) 215 yyerror (const char *s)
213 { 216 {
214 fprintf (stderr, "%s: ", xargv[0]); 217 fprintf (stderr, "%s: ", xargv[0]);
215 fprintf (stderr, "%s", s); 218 fprintf (stderr, "%s", s);
...@@ -226,6 +229,7 @@ yyerror (char *s) ...@@ -226,6 +229,7 @@ yyerror (char *s)
226 else 229 else
227 fprintf (stderr, " near %s", cur_p); 230 fprintf (stderr, " near %s", cur_p);
228 fprintf (stderr, "\n"); 231 fprintf (stderr, "\n");
232 return 0;
229 } 233 }
230 234
231 int 235 int
...@@ -324,7 +328,6 @@ msgset_parse (const int argc, char **argv, msgset_t **mset) ...@@ -324,7 +328,6 @@ msgset_parse (const int argc, char **argv, msgset_t **mset)
324 void 328 void
325 msgset_free (msgset_t *msg_set) 329 msgset_free (msgset_t *msg_set)
326 { 330 {
327 int i;
328 msgset_t *next; 331 msgset_t *next;
329 332
330 if (!msg_set) 333 if (!msg_set)
...@@ -382,7 +385,7 @@ msgset_t * ...@@ -382,7 +385,7 @@ msgset_t *
382 msgset_range (int low, int high) 385 msgset_range (int low, int high)
383 { 386 {
384 int i; 387 int i;
385 msgset_t *mp, *first = NULL, *last; 388 msgset_t *mp, *first = NULL, *last = NULL;
386 389
387 if (low == high) 390 if (low == high)
388 return msgset_make_1 (low); 391 return msgset_make_1 (low);
...@@ -409,7 +412,7 @@ msgset_t * ...@@ -409,7 +412,7 @@ msgset_t *
409 msgset_expand (msgset_t *set, msgset_t *expand_by) 412 msgset_expand (msgset_t *set, msgset_t *expand_by)
410 { 413 {
411 msgset_t *i, *j; 414 msgset_t *i, *j;
412 msgset_t *first = NULL, *last, *mp; 415 msgset_t *first = NULL, *last = NULL, *mp;
413 416
414 for (i = set; i; i = i->next) 417 for (i = set; i; i = i->next)
415 for (j = expand_by; j; j = j->next) 418 for (j = expand_by; j; j = j->next)
...@@ -432,10 +435,11 @@ msgset_expand (msgset_t *set, msgset_t *expand_by) ...@@ -432,10 +435,11 @@ msgset_expand (msgset_t *set, msgset_t *expand_by)
432 } 435 }
433 436
434 msgset_t * 437 msgset_t *
435 msgset_select (int (*sel)(), void *closure, int rev, int max_matches) 438 msgset_select (int (*sel) __P ((message_t, void *)), void *closure, int rev,
439 unsigned int max_matches)
436 { 440 {
437 size_t i, match_count = 0; 441 size_t i, match_count = 0;
438 msgset_t *first = NULL, *last, *mp; 442 msgset_t *first = NULL, *last = NULL, *mp;
439 message_t msg = NULL; 443 message_t msg = NULL;
440 444
441 if (max_matches == 0) 445 if (max_matches == 0)
...@@ -486,7 +490,7 @@ select_header (message_t msg, void *closure) ...@@ -486,7 +490,7 @@ select_header (message_t msg, void *closure)
486 struct header_data *hd = (struct header_data *)closure; 490 struct header_data *hd = (struct header_data *)closure;
487 header_t hdr; 491 header_t hdr;
488 char *contents; 492 char *contents;
489 char *header = hd->header ? hd->header : MU_HEADER_SUBJECT; 493 const char *header = hd->header ? hd->header : MU_HEADER_SUBJECT;
490 494
491 message_get_header (msg, &hdr); 495 message_get_header (msg, &hdr);
492 if (header_aget_value (hdr, header, &contents) == 0) 496 if (header_aget_value (hdr, header, &contents) == 0)
...@@ -572,10 +576,11 @@ select_body (message_t msg, void *closure) ...@@ -572,10 +576,11 @@ select_body (message_t msg, void *closure)
572 int 576 int
573 select_sender (message_t msg, void *closure) 577 select_sender (message_t msg, void *closure)
574 { 578 {
575 char *sender = (char*) closure; 579 /* char *sender = (char*) closure; */
576 /* FIXME: all messages from sender argv[i] */ 580 /* FIXME: all messages from sender argv[i] */
577 /* Annoying we can use address_create() for that 581 /* Annoying we can use address_create() for that
578 but to compare against what? The email ? */ 582 but to compare against what? The email ? */
583 (void)msg; (void)closure;
579 return 0; 584 return 0;
580 } 585 }
581 586
...@@ -613,6 +618,7 @@ select_deleted (message_t msg, void *closure) ...@@ -613,6 +618,7 @@ select_deleted (message_t msg, void *closure)
613 attribute_t attr= NULL; 618 attribute_t attr= NULL;
614 int rc; 619 int rc;
615 620
621 (void)closure;
616 message_get_attribute (msg, &attr); 622 message_get_attribute (msg, &attr);
617 rc = attribute_is_deleted (attr); 623 rc = attribute_is_deleted (attr);
618 return strcmp (xargv[0], "undelete") == 0 ? rc : !rc; 624 return strcmp (xargv[0], "undelete") == 0 ? rc : !rc;
...@@ -636,7 +642,7 @@ int ...@@ -636,7 +642,7 @@ int
636 main(int argc, char **argv) 642 main(int argc, char **argv)
637 { 643 {
638 msgset_t *mset = NULL; 644 msgset_t *mset = NULL;
639 int rc = parse_msgset (argc, argv, &mset); 645 int rc = msgset_parse (argc, argv, &mset);
640 646
641 for (; mset; mset = mset->next) 647 for (; mset; mset = mset->next)
642 msgset_print (mset); 648 msgset_print (mset);
......
...@@ -28,7 +28,7 @@ mail_pipe (int argc, char **argv) ...@@ -28,7 +28,7 @@ mail_pipe (int argc, char **argv)
28 message_t msg; 28 message_t msg;
29 stream_t stream; 29 stream_t stream;
30 char *cmd; 30 char *cmd;
31 FILE *pipe; 31 FILE *tube;
32 msgset_t *list, *mp; 32 msgset_t *list, *mp;
33 char buffer[512]; 33 char buffer[512];
34 off_t off = 0; 34 off_t off = 0;
...@@ -44,7 +44,7 @@ mail_pipe (int argc, char **argv) ...@@ -44,7 +44,7 @@ mail_pipe (int argc, char **argv)
44 if (msgset_parse (argc, argv, &list)) 44 if (msgset_parse (argc, argv, &list))
45 return 1; 45 return 1;
46 46
47 pipe = popen (cmd, "w"); 47 tube = popen (cmd, "w");
48 48
49 for (mp = list; mp; mp = mp->next) 49 for (mp = list; mp; mp = mp->next)
50 { 50 {
...@@ -56,15 +56,15 @@ mail_pipe (int argc, char **argv) ...@@ -56,15 +56,15 @@ mail_pipe (int argc, char **argv)
56 &n) == 0 && n != 0) 56 &n) == 0 && n != 0)
57 { 57 {
58 buffer[n] = '\0'; 58 buffer[n] = '\0';
59 fprintf (pipe, "%s", buffer); 59 fprintf (tube, "%s", buffer);
60 off += n; 60 off += n;
61 } 61 }
62 if ((util_find_env("page"))->set && mp->next) 62 if ((util_find_env("page"))->set && mp->next)
63 fprintf (pipe, "\f\n"); 63 fprintf (tube, "\f\n");
64 } 64 }
65 } 65 }
66 66
67 msgset_free (list); 67 msgset_free (list);
68 pclose (pipe); 68 pclose (tube);
69 return 0; 69 return 0;
70 } 70 }
......
...@@ -49,26 +49,25 @@ mail_print (int argc, char **argv) ...@@ -49,26 +49,25 @@ mail_print (int argc, char **argv)
49 49
50 message_lines (mesg, &lines); 50 message_lines (mesg, &lines);
51 51
52 if ((util_find_env("crt"))->set && lines > util_getlines ()) 52 if ((util_find_env("crt"))->set && lines > (size_t)util_getlines ())
53 out = popen (getenv("PAGER"), "w"); 53 out = popen (getenv("PAGER"), "w");
54 54
55 if (islower (argv[0][0])) 55 if (islower (argv[0][0]))
56 { 56 {
57 size_t i, num = 0; 57 size_t i, num = 0;
58 char buffer[512]; 58 char buf[512];
59 59
60 message_get_header (mesg, &hdr); 60 message_get_header (mesg, &hdr);
61 header_get_field_count (hdr, &num); 61 header_get_field_count (hdr, &num);
62 62
63 for (i = 1; i <= num; i++) 63 for (i = 1; i <= num; i++)
64 { 64 {
65 header_get_field_name (hdr, i, buffer, sizeof(buffer), NULL); 65 header_get_field_name (hdr, i, buf, sizeof buf, NULL);
66 if (mail_header_is_visible (buffer)) 66 if (mail_header_is_visible (buf))
67 { 67 {
68 fprintf (out, "%s: ", buffer); 68 fprintf (out, "%s: ", buf);
69 header_get_field_value (hdr, i, buffer, sizeof(buffer), 69 header_get_field_value (hdr, i, buf, sizeof buf, NULL);
70 NULL); 70 fprintf (out, "%s\n", buf);
71 fprintf (out, "%s\n", buffer);
72 } 71 }
73 } 72 }
74 fprintf (out, "\n"); 73 fprintf (out, "\n");
...@@ -78,7 +77,7 @@ mail_print (int argc, char **argv) ...@@ -78,7 +77,7 @@ mail_print (int argc, char **argv)
78 else 77 else
79 message_get_stream (mesg, &stream); 78 message_get_stream (mesg, &stream);
80 79
81 while (stream_read (stream, buffer, sizeof (buffer) - 1, off, &n) == 0 80 while (stream_read (stream, buffer, sizeof buffer - 1, off, &n) == 0
82 && n != 0) 81 && n != 0)
83 { 82 {
84 if (ml_got_interrupt()) 83 if (ml_got_interrupt())
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
25 int 25 int
26 mail_quit (int argc, char **argv) 26 mail_quit (int argc, char **argv)
27 { 27 {
28 (void)argc; (void)argv;
28 if (mail_mbox_close ()) 29 if (mail_mbox_close ())
29 return 1; 30 return 1;
30 exit (0); 31 exit (0);
...@@ -54,7 +55,7 @@ mail_mbox_close () ...@@ -54,7 +55,7 @@ mail_mbox_close ()
54 int 55 int
55 mail_mbox_commit () 56 mail_mbox_commit ()
56 { 57 {
57 int i; 58 unsigned int i;
58 mailbox_t dest_mbox = NULL; 59 mailbox_t dest_mbox = NULL;
59 int saved_count = 0; 60 int saved_count = 0;
60 message_t msg; 61 message_t msg;
...@@ -119,11 +120,11 @@ mail_mbox_commit () ...@@ -119,11 +120,11 @@ mail_mbox_commit ()
119 120
120 if (saved_count) 121 if (saved_count)
121 { 122 {
122 url_t url = NULL; 123 url_t u = NULL;
123 124
124 mailbox_get_url (dest_mbox, &url); 125 mailbox_get_url (dest_mbox, &u);
125 fprintf(ofile, "Saved %d messages in %s\n", saved_count, 126 fprintf(ofile, "Saved %d messages in %s\n", saved_count,
126 url_to_string (url)); 127 url_to_string (u));
127 mailbox_close (dest_mbox); 128 mailbox_close (dest_mbox);
128 mailbox_destroy (&dest_mbox); 129 mailbox_destroy (&dest_mbox);
129 } 130 }
......
...@@ -48,7 +48,7 @@ mail_send (int argc, char **argv) ...@@ -48,7 +48,7 @@ mail_send (int argc, char **argv)
48 env.outfiles = NULL; env.nfiles = 0; 48 env.outfiles = NULL; env.nfiles = 0;
49 49
50 if (argc < 2) 50 if (argc < 2)
51 env.to = readline ("To: "); 51 env.to = readline ((char *)"To: ");
52 else 52 else
53 { 53 {
54 while (--argc) 54 while (--argc)
...@@ -75,12 +75,12 @@ mail_send (int argc, char **argv) ...@@ -75,12 +75,12 @@ mail_send (int argc, char **argv)
75 } 75 }
76 76
77 if ((util_find_env ("askcc"))->set) 77 if ((util_find_env ("askcc"))->set)
78 env.cc = readline ("Cc: "); 78 env.cc = readline ((char *)"Cc: ");
79 if ((util_find_env ("askbcc"))->set) 79 if ((util_find_env ("askbcc"))->set)
80 env.bcc = readline ("Bcc: "); 80 env.bcc = readline ((char *)"Bcc: ");
81 81
82 if ((util_find_env ("asksub"))->set) 82 if ((util_find_env ("asksub"))->set)
83 env.subj = readline ("Subject: "); 83 env.subj = readline ((char *)"Subject: ");
84 else 84 else
85 env.subj = (util_find_env ("subject"))->value; 85 env.subj = (util_find_env ("subject"))->value;
86 86
...@@ -155,7 +155,7 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -155,7 +155,7 @@ mail_send0 (struct send_environ *env, int save_to)
155 while (!done) 155 while (!done)
156 { 156 {
157 char *buf; 157 char *buf;
158 buf = readline (" \b"); 158 buf = readline ((char *)" \b");
159 159
160 if (ml_got_interrupt ()) 160 if (ml_got_interrupt ())
161 { 161 {
...@@ -210,8 +210,10 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -210,8 +210,10 @@ mail_send0 (struct send_environ *env, int save_to)
210 struct mail_command_entry entry; 210 struct mail_command_entry entry;
211 entry = util_find_entry (mail_escape_table, argv[0]); 211 entry = util_find_entry (mail_escape_table, argv[0]);
212 212
213 if (entry.func) 213 if (entry.escfunc)
214 status = (*entry.func)(argc, argv, env); 214 {
215 status = (*entry.escfunc)(argc, argv, env);
216 }
215 else 217 else
216 util_error ("Unknown escape %s", argv[0]); 218 util_error ("Unknown escape %s", argv[0]);
217 } 219 }
...@@ -247,7 +249,7 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -247,7 +249,7 @@ mail_send0 (struct send_environ *env, int save_to)
247 else 249 else
248 { 250 {
249 char *buf = NULL; 251 char *buf = NULL;
250 int n; 252 unsigned int n;
251 rewind (env->file); 253 rewind (env->file);
252 while (getline (&buf, &n, env->file) > 0) 254 while (getline (&buf, &n, env->file) > 0)
253 fputs (buf, fp); 255 fputs (buf, fp);
...@@ -269,7 +271,6 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -269,7 +271,6 @@ mail_send0 (struct send_environ *env, int save_to)
269 { 271 {
270 mailer_t mailer; 272 mailer_t mailer;
271 message_t msg = NULL; 273 message_t msg = NULL;
272 int status;
273 message_create (&msg, NULL); 274 message_create (&msg, NULL);
274 275
275 /* Fill the header. */ 276 /* Fill the header. */
...@@ -366,7 +367,7 @@ mail_send0 (struct send_environ *env, int save_to) ...@@ -366,7 +367,7 @@ mail_send0 (struct send_environ *env, int save_to)
366 if (util_find_env ("sendmail")->set) 367 if (util_find_env ("sendmail")->set)
367 { 368 {
368 char *sendmail = util_find_env ("sendmail")->value; 369 char *sendmail = util_find_env ("sendmail")->value;
369 status = mailer_create (&mailer, sendmail); 370 int status = mailer_create (&mailer, sendmail);
370 if (status == 0) 371 if (status == 0)
371 { 372 {
372 if (util_find_env ("verbose")->set) 373 if (util_find_env ("verbose")->set)
...@@ -422,9 +423,9 @@ msg_to_pipe (const char *cmd, message_t msg) ...@@ -422,9 +423,9 @@ msg_to_pipe (const char *cmd, message_t msg)
422 stream_t stream = NULL; 423 stream_t stream = NULL;
423 char buffer[512]; 424 char buffer[512];
424 off_t off = 0; 425 off_t off = 0;
425 int n = 0; 426 unsigned int n = 0;
426 message_get_stream (msg, &stream); 427 message_get_stream (msg, &stream);
427 while (stream_read (stream, buffer, sizeof (buffer) - 1, off, &n) == 0 428 while (stream_read (stream, buffer, sizeof buffer - 1, off, &n) == 0
428 && n != 0) 429 && n != 0)
429 { 430 {
430 buffer[n] = '\0'; 431 buffer[n] = '\0';
......
...@@ -53,7 +53,7 @@ mail_shell (int argc, char **argv) ...@@ -53,7 +53,7 @@ mail_shell (int argc, char **argv)
53 argcv_string (argc-1, &argv[1], &buf); 53 argcv_string (argc-1, &argv[1], &buf);
54 54
55 argvec[0] = getenv("SHELL"); 55 argvec[0] = getenv("SHELL");
56 argvec[1] = "-c"; 56 argvec[1] = (char *)"-c";
57 argvec[2] = buf; 57 argvec[2] = buf;
58 argvec[3] = NULL; 58 argvec[3] = NULL;
59 59
......
...@@ -26,11 +26,12 @@ mail_summary (int argc, char **argv) ...@@ -26,11 +26,12 @@ mail_summary (int argc, char **argv)
26 { 26 {
27 message_t msg; 27 message_t msg;
28 attribute_t attr; 28 attribute_t attr;
29 int msgno; 29 size_t msgno;
30 size_t count = 0; 30 size_t count = 0;
31 int mseen = 0, mnew = 0, mdelete = 0; 31 int mseen = 0, mnew = 0, mdelete = 0;
32 int first_new = 0, first_unread = 0; 32 int first_new = 0, first_unread = 0;
33 33
34 (void)argc; (void)argv;
34 mailbox_messages_count (mbox, &count); 35 mailbox_messages_count (mbox, &count);
35 for (msgno = 1; msgno <= count; msgno++) 36 for (msgno = 1; msgno <= count; msgno++)
36 { 37 {
...@@ -38,7 +39,7 @@ mail_summary (int argc, char **argv) ...@@ -38,7 +39,7 @@ mail_summary (int argc, char **argv)
38 && (message_get_attribute (msg, &attr) == 0)) 39 && (message_get_attribute (msg, &attr) == 0))
39 { 40 {
40 int deleted = attribute_is_deleted (attr); 41 int deleted = attribute_is_deleted (attr);
41 42
42 if (deleted) 43 if (deleted)
43 mdelete++; 44 mdelete++;
44 if (attribute_is_seen (attr) && ! attribute_is_read (attr)) 45 if (attribute_is_seen (attr) && ! attribute_is_read (attr))
...@@ -74,4 +75,5 @@ mail_summary (int argc, char **argv) ...@@ -74,4 +75,5 @@ mail_summary (int argc, char **argv)
74 /* Set the cursor. */ 75 /* Set the cursor. */
75 cursor = realcursor = (first_new == 0) ? ((first_unread == 0) ? 76 cursor = realcursor = (first_new == 0) ? ((first_unread == 0) ?
76 1 : first_unread) : first_new ; 77 1 : first_unread) : first_new ;
78 return 0;
77 } 79 }
......
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
21 /* unt[ag] [msglist] */ 21 /* unt[ag] [msglist] */
22 22
23 static int 23 static int
24 tag_message (message_t mesg, msgset_t *msgset, int *action) 24 tag_message (message_t mesg, msgset_t *msgset, void *arg)
25 { 25 {
26 attribute_t attr; 26 attribute_t attr;
27 int *action = arg;
27 28
29 (void)msgset;
28 message_get_attribute (mesg, &attr); 30 message_get_attribute (mesg, &attr);
29 if (*action) 31 if (*action)
30 attribute_set_userflag (attr, MAIL_ATTRIBUTE_TAGGED); 32 attribute_set_userflag (attr, MAIL_ATTRIBUTE_TAGGED);
...@@ -42,7 +44,7 @@ mail_tag (int argc, char **argv) ...@@ -42,7 +44,7 @@ mail_tag (int argc, char **argv)
42 if (msgset_parse (argc, argv, &msgset)) 44 if (msgset_parse (argc, argv, &msgset))
43 return 1; 45 return 1;
44 46
45 util_msgset_iterate (msgset, tag_message, &action); 47 util_msgset_iterate (msgset, tag_message, (void *)&action);
46 48
47 msgset_free (msgset); 49 msgset_free (msgset);
48 return 0; 50 return 0;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
22 # include <termios.h> 22 # include <termios.h>
23 #endif 23 #endif
24 #include <sys/ioctl.h> 24 #include <sys/ioctl.h>
25 #include <sys/stat.h>
25 26
26 #ifdef HAVE_FCNTL_H 27 #ifdef HAVE_FCNTL_H
27 # include <fcntl.h> 28 # include <fcntl.h>
...@@ -104,7 +105,7 @@ util_do_command (const char *c, ...) ...@@ -104,7 +105,7 @@ util_do_command (const char *c, ...)
104 105
105 entry = util_find_entry (mail_command_table, argv[0]); 106 entry = util_find_entry (mail_command_table, argv[0]);
106 107
107 if (if_cond() == 0 && (entry.flags & EF_FLOW) == 0) 108 if (if_cond () == 0 && (entry.flags & EF_FLOW) == 0)
108 { 109 {
109 argcv_free (argc, argv); 110 argcv_free (argc, argv);
110 return 0; 111 return 0;
...@@ -166,11 +167,46 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor) ...@@ -166,11 +167,46 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor)
166 return status; 167 return status;
167 } 168 }
168 169
170 /* Same as util_msglis_command but the function comes from the escape
171 cmd table, so will have a different argument signature. */
172 int
173 util_msglist_esccmd (int (*escfunc)
174 __P ((int, char **, struct send_environ *)),
175 int argc, char **argv, struct send_environ *env,
176 int set_cursor)
177 {
178 msgset_t *list = NULL, *mp;
179 int status = 0;
180
181 if (msgset_parse (argc, argv, &list))
182 return 1;
183
184 realcursor = cursor;
185
186 for (mp = list; mp; mp = mp->next)
187 {
188 cursor = mp->msg_part[0];
189 /* NOTE: Should we bail on error also? */
190 if (escfunc (1, argv, env) != 0)
191 status = 1;
192 /* Bail out if we receive an interrupt. */
193 if (ml_got_interrupt () != 0)
194 break;
195 }
196 msgset_free (list);
197
198 if (set_cursor)
199 realcursor = cursor;
200 else
201 cursor = realcursor;
202 return status;
203 }
204
169 /* 205 /*
170 * returns the function to run for command 206 * returns the function to run for command
171 */ 207 */
172 function_t * 208 function_t *
173 util_command_get (char *cmd) 209 util_command_get (const char *cmd)
174 { 210 {
175 struct mail_command_entry entry = util_find_entry (mail_command_table, cmd); 211 struct mail_command_entry entry = util_find_entry (mail_command_table, cmd);
176 return entry.func; 212 return entry.func;
...@@ -180,7 +216,7 @@ util_command_get (char *cmd) ...@@ -180,7 +216,7 @@ util_command_get (char *cmd)
180 * returns the mail_command_entry structure for the command matching cmd 216 * returns the mail_command_entry structure for the command matching cmd
181 */ 217 */
182 struct mail_command_entry 218 struct mail_command_entry
183 util_find_entry (const struct mail_command_entry *table, char *cmd) 219 util_find_entry (const struct mail_command_entry *table, const char *cmd)
184 { 220 {
185 int i = 0, ll = 0, sl = 0; 221 int i = 0, ll = 0, sl = 0;
186 int len = strlen (cmd); 222 int len = strlen (cmd);
...@@ -228,9 +264,12 @@ util_getcols (void) ...@@ -228,9 +264,12 @@ util_getcols (void)
228 struct winsize ws; 264 struct winsize ws;
229 265
230 ws.ws_col = ws.ws_row = 0; 266 ws.ws_col = ws.ws_row = 0;
231 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) 267 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0)
232 || ws.ws_row == 0) 268 {
233 ws.ws_col = strtol (getenv("COLUMNS"), NULL, 10); 269 const char *columns = getenv ("COLUMNS");
270 if (columns)
271 ws.ws_col = strtol (columns, NULL, 10);
272 }
234 273
235 /* FIXME: Should we exit()/abort() if col <= 0 ? */ 274 /* FIXME: Should we exit()/abort() if col <= 0 ? */
236 return ws.ws_col; 275 return ws.ws_col;
...@@ -246,9 +285,12 @@ util_getlines (void) ...@@ -246,9 +285,12 @@ util_getlines (void)
246 struct winsize ws; 285 struct winsize ws;
247 286
248 ws.ws_col = ws.ws_row = 0; 287 ws.ws_col = ws.ws_row = 0;
249 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) 288 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0)
250 || ws.ws_row == 0) 289 {
251 ws.ws_row = strtol (getenv("LINES"), NULL, 10); 290 const char *lines = getenv ("LINES");
291 if (lines)
292 ws.ws_row = strtol (lines, NULL, 10);
293 }
252 294
253 /* FIXME: Should we exit()/abort() if row <= 0 ? */ 295 /* FIXME: Should we exit()/abort() if row <= 0 ? */
254 296
...@@ -257,12 +299,12 @@ util_getlines (void) ...@@ -257,12 +299,12 @@ util_getlines (void)
257 } 299 }
258 300
259 int 301 int
260 util_screen_lines() 302 util_screen_lines ()
261 { 303 {
262 struct mail_env_entry *ep = util_find_env("screen"); 304 struct mail_env_entry *ep = util_find_env ("screen");
263 size_t n; 305 size_t n;
264 306
265 if (ep && ep->set && (n = atoi(ep->value)) != 0) 307 if (ep && ep->set && (n = strtoul (ep->value, NULL, 10)) != 0)
266 return n; 308 return n;
267 n = util_getlines(); 309 n = util_getlines();
268 util_do_command ("set screen=%d", n); 310 util_do_command ("set screen=%d", n);
...@@ -270,12 +312,12 @@ util_screen_lines() ...@@ -270,12 +312,12 @@ util_screen_lines()
270 } 312 }
271 313
272 int 314 int
273 util_screen_columns() 315 util_screen_columns ()
274 { 316 {
275 struct mail_env_entry *ep = util_find_env("columns"); 317 struct mail_env_entry *ep = util_find_env("columns");
276 size_t n; 318 size_t n;
277 319
278 if (ep && ep->set && (n = atoi(ep->value)) != 0) 320 if (ep && ep->set && (n = strtoul (ep->value, NULL, 10)) != 0)
279 return n; 321 return n;
280 n = util_getcols(); 322 n = util_getcols();
281 util_do_command ("set columns=%d", n); 323 util_do_command ("set columns=%d", n);
...@@ -295,7 +337,7 @@ util_find_env (const char *variable) ...@@ -295,7 +337,7 @@ util_find_env (const char *variable)
295 /* Annoying, variable "ask" is equivalent to "asksub". */ 337 /* Annoying, variable "ask" is equivalent to "asksub". */
296 static const char *asksub = "asksub"; 338 static const char *asksub = "asksub";
297 const char *var = variable; 339 const char *var = variable;
298 int len = strlen (var); 340 size_t len = strlen (var);
299 node *t; 341 node *t;
300 342
301 if (len < 1) 343 if (len < 1)
...@@ -425,7 +467,7 @@ util_get_homedir() ...@@ -425,7 +467,7 @@ util_get_homedir()
425 } 467 }
426 468
427 char * 469 char *
428 util_fullpath(char *inpath) 470 util_fullpath(const char *inpath)
429 { 471 {
430 return mu_tilde_expansion(inpath, "/", NULL); 472 return mu_tilde_expansion(inpath, "/", NULL);
431 } 473 }
...@@ -548,7 +590,7 @@ util_slist_destroy (list_t *list) ...@@ -548,7 +590,7 @@ util_slist_destroy (list_t *list)
548 } 590 }
549 591
550 char * 592 char *
551 util_slist_to_string (list_t list, char *delim) 593 util_slist_to_string (list_t list, const char *delim)
552 { 594 {
553 iterator_t itr; 595 iterator_t itr;
554 char *name; 596 char *name;
...@@ -569,7 +611,7 @@ util_slist_to_string (list_t list, char *delim) ...@@ -569,7 +611,7 @@ util_slist_to_string (list_t list, char *delim)
569 } 611 }
570 612
571 void 613 void
572 util_strcat(char **dest, char *str) 614 util_strcat(char **dest, const char *str)
573 { 615 {
574 if (!*dest) 616 if (!*dest)
575 *dest = strdup (str); 617 *dest = strdup (str);
...@@ -593,10 +635,10 @@ util_strupper (char *s) ...@@ -593,10 +635,10 @@ util_strupper (char *s)
593 { 635 {
594 if (s) 636 if (s)
595 { 637 {
596 int i; 638 size_t i;
597 int len = strlen (s); 639 size_t len = strlen (s);
598 for (i = 0; i < len; i++) 640 for (i = 0; i < len; i++)
599 s[i] = toupper ((int)s[i]); 641 s[i] = toupper ((unsigned int)(s[i]));
600 } 642 }
601 } 643 }
602 644
...@@ -623,7 +665,7 @@ util_escape_percent (char **str) ...@@ -623,7 +665,7 @@ util_escape_percent (char **str)
623 /* and escape percent signs */ 665 /* and escape percent signs */
624 p = newstr; 666 p = newstr;
625 q = *str; 667 q = *str;
626 while (*p = *q++) 668 while ((*p = *q++))
627 { 669 {
628 if (*p == '%') 670 if (*p == '%')
629 *++p = '%'; 671 *++p = '%';
...@@ -679,7 +721,7 @@ util_save_outgoing (message_t msg, char *savefile) ...@@ -679,7 +721,7 @@ util_save_outgoing (message_t msg, char *savefile)
679 } 721 }
680 else 722 else
681 { 723 {
682 char *buf; 724 char *buf = NULL;
683 size_t bsize = 0; 725 size_t bsize = 0;
684 726
685 message_size (msg, &bsize); 727 message_size (msg, &bsize);
...@@ -786,7 +828,7 @@ int ...@@ -786,7 +828,7 @@ int
786 util_tempfile(char **namep) 828 util_tempfile(char **namep)
787 { 829 {
788 char *filename; 830 char *filename;
789 char *tmpdir; 831 const char *tmpdir;
790 int fd; 832 int fd;
791 833
792 /* We have to be extra careful about opening temporary files, since we 834 /* We have to be extra careful about opening temporary files, since we
...@@ -829,15 +871,15 @@ util_tempfile(char **namep) ...@@ -829,15 +871,15 @@ util_tempfile(char **namep)
829 return fd; 871 return fd;
830 } 872 }
831 873
832 int 874 static int
833 util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) 875 util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
834 { 876 {
835 int i; 877 unsigned int i;
836 878
837 for (i = 1; i < msgset->npart; i++) 879 for (i = 1; i < msgset->npart; i++)
838 { 880 {
839 message_t submsg = NULL; 881 message_t submsg = NULL;
840 int nparts = 0; 882 unsigned int nparts = 0;
841 char *type = NULL; 883 char *type = NULL;
842 header_t hdr = NULL; 884 header_t hdr = NULL;
843 885
...@@ -876,7 +918,9 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) ...@@ -876,7 +918,9 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
876 } 918 }
877 919
878 void 920 void
879 util_msgset_iterate (msgset_t *msgset, int (*fun)(), void *closure) 921 util_msgset_iterate (msgset_t *msgset,
922 int (*fun) __P ((message_t, msgset_t *, void *)),
923 void *closure)
880 { 924 {
881 for (; msgset; msgset = msgset->next) 925 for (; msgset; msgset = msgset->next)
882 { 926 {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
21 #include <sys/stat.h> 21 #include <sys/stat.h>
22 22
23 static void 23 static void
24 var_continue() 24 var_continue (void)
25 { 25 {
26 fprintf(stdout, "(continue)\n"); 26 fprintf(stdout, "(continue)\n");
27 } 27 }
...@@ -30,7 +30,7 @@ static int var_check_args (int argc, char **argv) ...@@ -30,7 +30,7 @@ static int var_check_args (int argc, char **argv)
30 { 30 {
31 if (argc == 1) 31 if (argc == 1)
32 { 32 {
33 util_error ("%c%s requires an argument", 33 util_error ("%c%s requires an argument",
34 util_find_env ("escape")->value[0], argv[0]); 34 util_find_env ("escape")->value[0], argv[0]);
35 return 1; 35 return 1;
36 } 36 }
...@@ -82,6 +82,7 @@ var_command(int argc, char **argv, struct send_environ *env) ...@@ -82,6 +82,7 @@ var_command(int argc, char **argv, struct send_environ *env)
82 int 82 int
83 var_help(int argc, char **argv, struct send_environ *env) 83 var_help(int argc, char **argv, struct send_environ *env)
84 { 84 {
85 (void)env;
85 if (argc < 2) 86 if (argc < 2)
86 return util_help(mail_escape_table, NULL); 87 return util_help(mail_escape_table, NULL);
87 else 88 else
...@@ -102,6 +103,9 @@ int ...@@ -102,6 +103,9 @@ int
102 var_sign(int argc, char **argv, struct send_environ *env) 103 var_sign(int argc, char **argv, struct send_environ *env)
103 { 104 {
104 struct mail_env_entry *p; 105 struct mail_env_entry *p;
106
107 (void)argc; (void)env;
108
105 if (isupper(argv[0][0])) 109 if (isupper(argv[0][0]))
106 p = util_find_env("Sign"); 110 p = util_find_env("Sign");
107 else 111 else
...@@ -114,7 +118,7 @@ var_sign(int argc, char **argv, struct send_environ *env) ...@@ -114,7 +118,7 @@ var_sign(int argc, char **argv, struct send_environ *env)
114 FILE *fp = fopen(name, "r"); 118 FILE *fp = fopen(name, "r");
115 char *buf = NULL; 119 char *buf = NULL;
116 size_t n = 0; 120 size_t n = 0;
117 121
118 if (!fp) 122 if (!fp)
119 { 123 {
120 util_error("can't open %s: %s", name, strerror(errno)); 124 util_error("can't open %s: %s", name, strerror(errno));
...@@ -124,7 +128,7 @@ var_sign(int argc, char **argv, struct send_environ *env) ...@@ -124,7 +128,7 @@ var_sign(int argc, char **argv, struct send_environ *env)
124 fprintf(stdout, "Reading %s\n", name); 128 fprintf(stdout, "Reading %s\n", name);
125 while (getline(&buf, &n, fp) > 0) 129 while (getline(&buf, &n, fp) > 0)
126 fprintf(ofile, "%s", buf); 130 fprintf(ofile, "%s", buf);
127 131
128 fclose(fp); 132 fclose(fp);
129 free(buf); 133 free(buf);
130 free(name); 134 free(name);
...@@ -162,7 +166,9 @@ var_deadletter(int argc, char **argv, struct send_environ *env) ...@@ -162,7 +166,9 @@ var_deadletter(int argc, char **argv, struct send_environ *env)
162 { 166 {
163 FILE *dead = fopen(getenv("DEAD"), "r"); 167 FILE *dead = fopen(getenv("DEAD"), "r");
164 int c; 168 int c;
165 169
170 (void)argc; (void)argv; (void)env;
171
166 while ((c = fgetc(dead)) != EOF) 172 while ((c = fgetc(dead)) != EOF)
167 fputc(c, ofile); 173 fputc(c, ofile);
168 fclose(dead); 174 fclose(dead);
...@@ -172,6 +178,7 @@ var_deadletter(int argc, char **argv, struct send_environ *env) ...@@ -172,6 +178,7 @@ var_deadletter(int argc, char **argv, struct send_environ *env)
172 static int 178 static int
173 var_run_editor(char *ed, int argc, char **argv, struct send_environ *env) 179 var_run_editor(char *ed, int argc, char **argv, struct send_environ *env)
174 { 180 {
181 (void)argc; (void)argv;
175 fclose(env->file); 182 fclose(env->file);
176 ofile = env->ofile; 183 ofile = env->ofile;
177 util_do_command("!%s %s", ed, env->filename); 184 util_do_command("!%s %s", ed, env->filename);
...@@ -200,6 +207,7 @@ var_visual(int argc, char **argv, struct send_environ *env) ...@@ -200,6 +207,7 @@ var_visual(int argc, char **argv, struct send_environ *env)
200 int 207 int
201 var_print(int argc, char **argv, struct send_environ *env) 208 var_print(int argc, char **argv, struct send_environ *env)
202 { 209 {
210 (void)env;
203 return mail_print(argc, argv); 211 return mail_print(argc, argv);
204 } 212 }
205 213
...@@ -207,6 +215,7 @@ var_print(int argc, char **argv, struct send_environ *env) ...@@ -207,6 +215,7 @@ var_print(int argc, char **argv, struct send_environ *env)
207 int 215 int
208 var_headers(int argc, char **argv, struct send_environ *env) 216 var_headers(int argc, char **argv, struct send_environ *env)
209 { 217 {
218 (void)argc; (void)argv;
210 ml_reread("To: ", &env->to); 219 ml_reread("To: ", &env->to);
211 ml_reread("Cc: ", &env->cc); 220 ml_reread("Cc: ", &env->cc);
212 ml_reread("Bcc: ", &env->bcc); 221 ml_reread("Bcc: ", &env->bcc);
...@@ -219,6 +228,7 @@ var_headers(int argc, char **argv, struct send_environ *env) ...@@ -219,6 +228,7 @@ var_headers(int argc, char **argv, struct send_environ *env)
219 int 228 int
220 var_insert(int argc, char **argv, struct send_environ *env) 229 var_insert(int argc, char **argv, struct send_environ *env)
221 { 230 {
231 (void)env;
222 if (var_check_args (argc, argv)) 232 if (var_check_args (argc, argv))
223 return 1; 233 return 1;
224 fprintf(ofile, "%s", util_find_env(argv[1])->value); 234 fprintf(ofile, "%s", util_find_env(argv[1])->value);
...@@ -231,7 +241,7 @@ int ...@@ -231,7 +241,7 @@ int
231 var_quote(int argc, char **argv, struct send_environ *env) 241 var_quote(int argc, char **argv, struct send_environ *env)
232 { 242 {
233 if (argc > 1) 243 if (argc > 1)
234 return util_msglist_command(var_quote, argc, argv, 0); 244 return util_msglist_esccmd (var_quote, argc, argv, env, 0);
235 else 245 else
236 { 246 {
237 message_t mesg; 247 message_t mesg;
...@@ -242,29 +252,28 @@ var_quote(int argc, char **argv, struct send_environ *env) ...@@ -242,29 +252,28 @@ var_quote(int argc, char **argv, struct send_environ *env)
242 off_t off = 0; 252 off_t off = 0;
243 size_t n = 0; 253 size_t n = 0;
244 char *prefix = util_find_env("indentprefix")->value; 254 char *prefix = util_find_env("indentprefix")->value;
245 255
246 if (mailbox_get_message(mbox, cursor, &mesg) != 0) 256 if (mailbox_get_message(mbox, cursor, &mesg) != 0)
247 return 1; 257 return 1;
248 258
249 fprintf(stdout, "Interpolating: %d\n", cursor); 259 fprintf(stdout, "Interpolating: %d\n", cursor);
250 260
251 if (islower(argv[0][0])) 261 if (islower(argv[0][0]))
252 { 262 {
253 size_t i, num = 0; 263 size_t i, num = 0;
254 char buffer[512]; 264 char buf[512];
255 265
256 message_get_header(mesg, &hdr); 266 message_get_header(mesg, &hdr);
257 header_get_field_count(hdr, &num); 267 header_get_field_count(hdr, &num);
258 268
259 for (i = 1; i <= num; i++) 269 for (i = 1; i <= num; i++)
260 { 270 {
261 header_get_field_name(hdr, i, buffer, sizeof(buffer), NULL); 271 header_get_field_name(hdr, i, buf, sizeof buf, NULL);
262 if (mail_header_is_visible(buffer)) 272 if (mail_header_is_visible(buf))
263 { 273 {
264 fprintf(ofile, "%s%s: ", prefix, buffer); 274 fprintf(ofile, "%s%s: ", prefix, buf);
265 header_get_field_value(hdr, i, buffer, sizeof(buffer), 275 header_get_field_value(hdr, i, buf, sizeof buf, NULL);
266 NULL); 276 fprintf(ofile, "%s\n", buf);
267 fprintf(ofile, "%s\n", buffer);
268 } 277 }
269 } 278 }
270 fprintf(ofile, "\n"); 279 fprintf(ofile, "\n");
...@@ -274,7 +283,7 @@ var_quote(int argc, char **argv, struct send_environ *env) ...@@ -274,7 +283,7 @@ var_quote(int argc, char **argv, struct send_environ *env)
274 else 283 else
275 message_get_stream(mesg, &stream); 284 message_get_stream(mesg, &stream);
276 285
277 while (stream_readline(stream, buffer, sizeof(buffer) - 1, off, &n) == 0 286 while (stream_readline(stream, buffer, sizeof buffer - 1, off, &n) == 0
278 && n != 0) 287 && n != 0)
279 { 288 {
280 buffer[n] = '\0'; 289 buffer[n] = '\0';
...@@ -292,8 +301,10 @@ var_type_input(int argc, char **argv, struct send_environ *env) ...@@ -292,8 +301,10 @@ var_type_input(int argc, char **argv, struct send_environ *env)
292 { 301 {
293 char buf[512]; 302 char buf[512];
294 303
304 (void)argc; (void)argv;
305
295 fprintf(env->ofile, "Message contains:\n"); 306 fprintf(env->ofile, "Message contains:\n");
296 307
297 if (env->to) 308 if (env->to)
298 fprintf(env->ofile, "To: %s\n", env->to); 309 fprintf(env->ofile, "To: %s\n", env->to);
299 if (env->cc) 310 if (env->cc)
...@@ -302,7 +313,7 @@ var_type_input(int argc, char **argv, struct send_environ *env) ...@@ -302,7 +313,7 @@ var_type_input(int argc, char **argv, struct send_environ *env)
302 fprintf(env->ofile, "Bcc: %s\n", env->bcc); 313 fprintf(env->ofile, "Bcc: %s\n", env->bcc);
303 if (env->subj) 314 if (env->subj)
304 fprintf(env->ofile, "Subject: %s\n\n", env->subj); 315 fprintf(env->ofile, "Subject: %s\n\n", env->subj);
305 316
306 rewind(env->file); 317 rewind(env->file);
307 while (fgets(buf, sizeof(buf), env->file)) 318 while (fgets(buf, sizeof(buf), env->file))
308 fputs(buf, env->ofile); 319 fputs(buf, env->ofile);
...@@ -320,7 +331,9 @@ var_read(int argc, char **argv, struct send_environ *env) ...@@ -320,7 +331,9 @@ var_read(int argc, char **argv, struct send_environ *env)
320 FILE *inf; 331 FILE *inf;
321 size_t size, lines; 332 size_t size, lines;
322 char buf[512]; 333 char buf[512];
323 334
335 (void)env;
336
324 if (var_check_args (argc, argv)) 337 if (var_check_args (argc, argv))
325 return 1; 338 return 1;
326 filename = util_fullpath(argv[1]); 339 filename = util_fullpath(argv[1]);
...@@ -373,13 +386,13 @@ var_write(int argc, char **argv, struct send_environ *env) ...@@ -373,13 +386,13 @@ var_write(int argc, char **argv, struct send_environ *env)
373 FILE *fp; 386 FILE *fp;
374 size_t size, lines; 387 size_t size, lines;
375 char buf[512]; 388 char buf[512];
376 389
377 if (var_check_args (argc, argv)) 390 if (var_check_args (argc, argv))
378 return 1; 391 return 1;
379 392
380 filename = util_fullpath(argv[1]); 393 filename = util_fullpath(argv[1]);
381 fp = fopen(filename, "w"); /*FIXME: check for the existence first */ 394 fp = fopen(filename, "w"); /*FIXME: check for the existence first */
382 395
383 if (!fp) 396 if (!fp)
384 { 397 {
385 util_error("can't open %s: %s\n", filename, strerror(errno)); 398 util_error("can't open %s: %s\n", filename, strerror(errno));
...@@ -405,6 +418,7 @@ var_write(int argc, char **argv, struct send_environ *env) ...@@ -405,6 +418,7 @@ var_write(int argc, char **argv, struct send_environ *env)
405 int 418 int
406 var_exit(int argc, char **argv, struct send_environ *env) 419 var_exit(int argc, char **argv, struct send_environ *env)
407 { 420 {
421 (void)argc; (void)argv; (void)env;
408 return util_do_command("quit"); 422 return util_do_command("quit");
409 } 423 }
410 424
...@@ -421,7 +435,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -421,7 +435,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
421 util_error("pipe: no command specified"); 435 util_error("pipe: no command specified");
422 return 1; 436 return 1;
423 } 437 }
424 438
425 if (pipe(p)) 439 if (pipe(p))
426 { 440 {
427 util_error("pipe: %s", strerror(errno)); 441 util_error("pipe: %s", strerror(errno));
...@@ -445,17 +459,17 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -445,17 +459,17 @@ var_pipe(int argc, char **argv, struct send_environ *env)
445 /* Child */ 459 /* Child */
446 int i; 460 int i;
447 char **xargv; 461 char **xargv;
448 462
449 /* Attache the pipes */ 463 /* Attache the pipes */
450 close(0); 464 close(0);
451 dup(p[0]); 465 dup(p[0]);
452 close(p[0]); 466 close(p[0]);
453 close(p[1]); 467 close(p[1]);
454 468
455 close(1); 469 close(1);
456 dup(fd); 470 dup(fd);
457 close(fd); 471 close(fd);
458 472
459 /* Execute the process */ 473 /* Execute the process */
460 xargv = xcalloc(argc, sizeof(xargv[0])); 474 xargv = xcalloc(argc, sizeof(xargv[0]));
461 for (i = 0; i < argc-1; i++) 475 for (i = 0; i < argc-1; i++)
...@@ -473,15 +487,15 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -473,15 +487,15 @@ var_pipe(int argc, char **argv, struct send_environ *env)
473 size_t lines, size; 487 size_t lines, size;
474 int rc = 1; 488 int rc = 1;
475 int status; 489 int status;
476 490
477 close(p[0]); 491 close(p[0]);
478 492
479 /* Parent */ 493 /* Parent */
480 fp = fdopen(p[1], "w"); 494 fp = fdopen(p[1], "w");
481 495
482 fclose(env->file); 496 fclose(env->file);
483 env->file = fopen(env->filename, "r"); 497 env->file = fopen(env->filename, "r");
484 498
485 lines = size = 0; 499 lines = size = 0;
486 while (getline(&buf, &n, env->file) > 0) 500 while (getline(&buf, &n, env->file) > 0)
487 { 501 {
...@@ -491,7 +505,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -491,7 +505,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
491 } 505 }
492 fclose(env->file); 506 fclose(env->file);
493 fclose(fp); /* Closes p[1] */ 507 fclose(fp); /* Closes p[1] */
494 508
495 waitpid(pid, &status, 0); 509 waitpid(pid, &status, 0);
496 if (!WIFEXITED(status)) 510 if (!WIFEXITED(status))
497 { 511 {
...@@ -508,7 +522,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -508,7 +522,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
508 rc = 0; 522 rc = 0;
509 } 523 }
510 524
511 fprintf(stdout, "\"|%s\" in: %d/%d ", argv[1], lines, size); 525 fprintf(stdout, "\"|%s\" in: %d/%d ", argv[1], lines, size);
512 if (rc) 526 if (rc)
513 { 527 {
514 fprintf(stdout, "no lines out\n"); 528 fprintf(stdout, "no lines out\n");
...@@ -520,7 +534,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -520,7 +534,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
520 rewind(fp); 534 rewind(fp);
521 535
522 env->file = fopen(env->filename, "w+"); 536 env->file = fopen(env->filename, "w+");
523 537
524 lines = size = 0; 538 lines = size = 0;
525 while (getline(&buf, &n, fp) > 0) 539 while (getline(&buf, &n, fp) > 0)
526 { 540 {
...@@ -530,7 +544,7 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -530,7 +544,7 @@ var_pipe(int argc, char **argv, struct send_environ *env)
530 } 544 }
531 fclose(env->file); 545 fclose(env->file);
532 546
533 fprintf(stdout, "out: %d/%d\n", lines, size); 547 fprintf(stdout, "out: %d/%d\n", lines, size);
534 } 548 }
535 549
536 /* Clean up the things */ 550 /* Clean up the things */
...@@ -542,6 +556,6 @@ var_pipe(int argc, char **argv, struct send_environ *env) ...@@ -542,6 +556,6 @@ var_pipe(int argc, char **argv, struct send_environ *env)
542 } 556 }
543 557
544 close(fd); 558 close(fd);
545 559
546 return 0; 560 return 0;
547 } 561 }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
21 * ve[rsion] 21 * ve[rsion]
22 */ 22 */
23 23
24 static char *with_defs[] = 24 static const char *with_defs[] =
25 { 25 {
26 #ifdef WITH_PTHREAD 26 #ifdef WITH_PTHREAD
27 "PTHREAD", 27 "PTHREAD",
...@@ -39,6 +39,7 @@ static char *with_defs[] = ...@@ -39,6 +39,7 @@ static char *with_defs[] =
39 int 39 int
40 mail_version (int argc, char **argv) 40 mail_version (int argc, char **argv)
41 { 41 {
42 (void)argc; (void)argv;
42 fprintf (ofile, "%s", argp_program_version); 43 fprintf (ofile, "%s", argp_program_version);
43 if (with_defs[0] != NULL) 44 if (with_defs[0] != NULL)
44 { 45 {
......
...@@ -102,7 +102,7 @@ mail_write (int argc, char **argv) ...@@ -102,7 +102,7 @@ mail_write (int argc, char **argv)
102 attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED); 102 attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
103 } 103 }
104 104
105 fprintf (ofile, "\"%s\" %3ld/%-5ld\n", filename, total_lines, total_size); 105 fprintf (ofile, "\"%s\" %3d/%-5d\n", filename, total_lines, total_size);
106 106
107 free (filename); 107 free (filename);
108 fclose (output); 108 fclose (output);
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
31 */ 31 */
32 32
33 static int 33 static int
34 z_parse_args(int argc, char **argv, int *return_count, int *return_dir) 34 z_parse_args(int argc, char **argv, unsigned int *return_count, int *return_dir)
35 { 35 {
36 int count = 1; 36 int count = 1;
37 int mul = 1; 37 int mul = 1;
...@@ -87,7 +87,7 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir) ...@@ -87,7 +87,7 @@ z_parse_args(int argc, char **argv, int *return_count, int *return_dir)
87 return 1; 87 return 1;
88 } 88 }
89 89
90 if ((mul = atoi(argp)) == 0) 90 if ((mul = strtoul (argp, NULL, 10)) == 0)
91 { 91 {
92 util_error("Bad number of pages"); 92 util_error("Bad number of pages");
93 return 1; 93 return 1;
...@@ -107,7 +107,7 @@ mail_z (int argc, char **argv) ...@@ -107,7 +107,7 @@ mail_z (int argc, char **argv)
107 { 107 {
108 unsigned int i, nlines; 108 unsigned int i, nlines;
109 unsigned int pagelines = util_screen_lines(); 109 unsigned int pagelines = util_screen_lines();
110 int count; 110 unsigned int count;
111 int dir; 111 int dir;
112 112
113 if (z_parse_args(argc, argv, &count, &dir)) 113 if (z_parse_args(argc, argv, &count, &dir))
...@@ -148,7 +148,7 @@ mail_z (int argc, char **argv) ...@@ -148,7 +148,7 @@ mail_z (int argc, char **argv)
148 return 0; 148 return 0;
149 } 149 }
150 break; 150 break;
151 151
152 case D_NONE: 152 case D_NONE:
153 { 153 {
154 /* z. is a GNU extension, so it will be more useful 154 /* z. is a GNU extension, so it will be more useful
...@@ -161,7 +161,7 @@ mail_z (int argc, char **argv) ...@@ -161,7 +161,7 @@ mail_z (int argc, char **argv)
161 int lastpage = total - pagelines + 1; 161 int lastpage = total - pagelines + 1;
162 if (lastpage <= 0) 162 if (lastpage <= 0)
163 lastpage = 1; 163 lastpage = 1;
164 if (cursor > lastpage) 164 if (cursor > (unsigned int)lastpage)
165 { 165 {
166 realcursor = cursor; 166 realcursor = cursor;
167 cursor = lastpage; 167 cursor = lastpage;
...@@ -185,7 +185,7 @@ mail_z (int argc, char **argv) ...@@ -185,7 +185,7 @@ mail_z (int argc, char **argv)
185 i++; 185 i++;
186 cursor++; 186 cursor++;
187 } 187 }
188 188
189 cursor = realcursor; 189 cursor = realcursor;
190 190
191 return 1; 191 return 1;
......