Commit 1da17967 1da179679b3e0b59f9fb3cba683a1a35b5e12240 by Jakob Kaivo

Fix some buglets in mailx, prepare some commands for GNU extensions

1 parent d685b048
......@@ -25,8 +25,11 @@ int
mail_echo (int argc, char **argv)
{
int i = 0;
for (i = 1; i < argc-1; i++)
printf ("%s ", argv[i]);
printf ("%s\n", argv[argc]);
if (argc > 1)
{
for (i = 1; i < argc - 1; i++)
printf ("%s ", argv[i]);
printf ("%s\n", argv[argc - 1]);
}
return 0;
}
......
......@@ -18,7 +18,7 @@
#include "mail.h"
/*
* fo[llowup] [message]
* fo[llowup] [msglist] -- GNU extension
* F[ollowup] [msglist]
*/
......
......@@ -18,36 +18,51 @@
#include "mail.h"
/*
* h[eaders] [message]
* h[eaders] [msglist] -- GNU extension
*/
/*
* NOTE: check for messages near each other and only print them once
* should probably build a dynamic msglist for this
*/
int
mail_headers (int argc, char **argv)
{
char buf[64];
int low = 1, high = total, middle = cursor;
int lines = util_getlines () - 2;
if (argc > 2)
return 1;
if (argc == 2)
middle = strtol (argv[1], NULL, 10);
if (lines < total)
int low = 1, high = total, *list = NULL, i = 0;
int lines = util_getlines ();
int num = util_expand_msglist (argc, argv, &list);
if (num == 0)
{
low = middle - (lines / 2);
if (low < 1)
low = 1;
high = low + lines;
if (high > total)
list = malloc (sizeof(int));
*list = cursor;
num = 1;
}
lines = (lines / num) - 2;
for (i = 0; i < num; i++)
{
if (lines < total)
{
high = total;
low = high - lines;
low = list[i] - (lines / 2);
if (low < 1)
low = 1;
high = low + lines;
if (high > total)
{
high = total;
low = high - lines;
}
}
memset (buf, '\0', 64);
snprintf (buf, 64, "from %d-%d", low, high);
util_do_command (buf);
}
memset (buf, '\0', 64);
snprintf (buf, 64, "from %d-%d", low, high);
return util_do_command (buf);
free (list);
return 0;
}
......
......@@ -140,7 +140,7 @@ struct mail_command_entry util_find_entry __P((char *cmd));
int util_getcols __P((void));
int util_getlines __P((void));
struct mail_env_entry *util_find_env __P((char *var));
int util_printenv __P((void));
int util_printenv __P((int set));
#ifdef __cplusplus
}
......
......@@ -18,8 +18,8 @@
#include "mail.h"
/*
* r[eply] [message]
* r[espond] [message]
* r[eply] [msglist] -- GNU extension
* r[espond] [msglist] -- GNU extension
* R[eply] [msglist]
* R[espond] [msglist]
*/
......
......@@ -30,7 +30,7 @@ mail_set (int argc, char **argv)
{
if (argc < 2)
{
return util_printenv ();
return util_printenv (1);
}
else
{
......@@ -42,6 +42,8 @@ mail_set (int argc, char **argv)
if (!strncmp ("no", argv[i], 2))
{
entry = util_find_env (&argv[i][2]);
if (entry == NULL)
return 1;
entry->set = 0;
free (entry->value);
}
......@@ -57,14 +59,18 @@ mail_set (int argc, char **argv)
}
value = strdup (&var[j+1]);
entry = util_find_env (var);
free (var);
if (entry == NULL)
return 1;
entry->set = 1;
free (entry->value);
entry->value = value;
free (var);
}
else
{
entry = util_find_env(argv[i]);
if (entry == NULL)
return 1;
entry->set = 1;
free (entry->value);
entry->value = NULL;
......
......@@ -24,8 +24,7 @@ const struct mail_command_entry mail_command_table[] = {
{ "C", "Copy", mail_copy, "C[opy] [msglist]" },
{ "cd", "cd", mail_cd, "cd [directory]" },
{ "ch", "chdir", mail_cd, "ch[dir] directory" },
{ "c", "copy", mail_copy,
"c[opy] [file]\nc[opy] [msglist] file" },
{ "c", "copy", mail_copy, "c[opy] [[msglist] file]" },
{ "d", "delete", mail_delete, "d[elete] [msglist]" },
{ "di", "discard", mail_discard,
"di[scard] [header-field...]" },
......@@ -40,12 +39,12 @@ const struct mail_command_entry mail_command_table[] = {
{ "fi", "file", mail_file, "fi[le] [file]" },
{ "fold", "folder", mail_file, "fold[er] [file]" },
{ "folders", "folders", mail_folders, "folders" },
{ "fo", "followup", mail_followup, "fo[llowup] [message]" },
{ "fo", "followup", mail_followup, "fo[llowup] [msglist]" },
{ "f", "from", mail_from, "f[rom] [msglist]" },
{ "g", "group", mail_alias,
"g[roup] [alias [address...]]" },
{ "h", "headers", mail_headers, "h[eaders] [message]" },
{ "hel", "help", mail_help, "hel[p] [command]" },
{ "h", "headers", mail_headers, "h[eaders] [msglist]" },
{ "hel", "help", mail_help, "hel[p] [command...]" },
{ "ho", "hold", mail_hold, "ho[ld] [msglist]" },
{ "i", "if", mail_if, "i[f] s|r" }, /* FIXME */
{ "ig", "ignore", mail_discard, "ig[nore] [header-field...]" },
......@@ -55,18 +54,17 @@ const struct mail_command_entry mail_command_table[] = {
{ "n", "next", mail_next, "n[ext] [message]" },
{ "P", "Print", mail_print, "P[rint] [msglist]" },
{ "pi", "pipe", mail_pipe, "pi[pe] [[msglist] command]" },
{ "pre", "preserve", mail_hold, "pre[server] [msglist]" },
{ "pre", "preserve", mail_hold, "pre[serve] [msglist]" },
{ "prev", "previous", mail_previous, "prev[ious] [message]" },
{ "p", "print", mail_print, "p[rint] [msglist]" },
{ "q", "quit", mail_quit, "q[uit]" },
{ "R", "Reply", mail_reply, "R[eply] [msglist]" },
{ "R", "Respond", mail_reply, "R[espond] [msglist]" },
{ "r", "reply", mail_reply, "r[eply] [message]" },
{ "r", "respond", mail_reply, "r[espond] [message]" },
{ "r", "reply", mail_reply, "r[eply] [msglist]" },
{ "r", "respond", mail_reply, "r[espond] [msglist]" },
{ "ret", "retain", mail_retain, "ret[ain] [header-field]" },
{ "S", "Save", mail_save, "S[ave] [msglist]" },
{ "s", "save", mail_save,
"s[ave] [file]\ns[ave] [msglist] file" },
{ "s", "save", mail_save, "s[ave] [[msglist] file]" },
{ "se", "set", mail_set,
"se[t] [name[=[string]]...] [name=number...] [noname...]" },
{ "sh", "shell", mail_shell, "sh[ell]" },
......@@ -81,11 +79,10 @@ const struct mail_command_entry mail_command_table[] = {
{ "uns", "unset", mail_unset, "uns[et] name..." },
{ "v", "visual", mail_visual, "v[isual] [msglist]" },
{ "W", "Write", mail_write, "W[rite] [msglist]" },
{ "w", "write", mail_write,
"w[rite] [file]\nw[rite] [msglist] file" },
{ "w", "write", mail_write, "w[rite] [[msglist] file]" },
{ "x", "xit", mail_exit, "x[it]" },
{ "z", "", mail_z, "z[+|-]" },
{ "?", "?", mail_help, "? [command]" },
{ "?", "?", mail_help, "? [command...]" },
{ "!", "", mail_bang, "!command" },
{ "=", "=", mail_eq, "=" },
{ "#", "#", NULL, "# comment" },
......
......@@ -18,26 +18,27 @@
#include "mail.h"
/*
* uns[et] name...
* uns[et] [name...] -- GNU extension
*/
int
mail_unset (int argc, char **argv)
{
if (argc < 2)
return 1;
return util_printenv (0);
else
{
int status = 0, i = 1;
for (i=1; i < argc; i++)
{
char *buf = malloc ((6+strlen (argv[i])) * sizeof (char));
char *buf = malloc ((7+strlen (argv[i])) * sizeof (char));
strcpy (buf, "set no");
strcat (buf, argv[i]);
if (!util_do_command (buf))
status = 1;
free (buf);
}
return status;
}
return 1;
}
......
......@@ -36,9 +36,6 @@ util_ll_add (node *c, int data)
{
c->next = malloc (sizeof (node));
c->data = data;
/* c->env_entry.var = NULL;
c->env_entry.set = 0;
c->env_entry.value = NULL;*/
c->next->env_entry.var = NULL;
c->next->env_entry.set = 0;
c->next->env_entry.value = NULL;
......@@ -380,6 +377,9 @@ util_find_env (char *variable)
int len = strlen (var), need_free = 0;
node *t;
if (len < 1)
return NULL;
if (len == strlen ("ask") && !strcmp ("ask", var))
{
var = strdup ("asksub");
......@@ -407,7 +407,7 @@ util_find_env (char *variable)
return &(env_cursor->env_entry);
}
}
/* env_cursor = util_ll_add (env_cursor, 0); */
env_cursor->env_entry.var = strdup (var);
env_cursor->env_entry.set = 0;
env_cursor->env_entry.value = NULL;
......@@ -422,12 +422,12 @@ util_find_env (char *variable)
* print the environment
*/
int
util_printenv (void)
util_printenv (int set)
{
for (env_cursor = environment; env_cursor != NULL;
env_cursor = env_cursor->next)
{
if (env_cursor->env_entry.set)
if (env_cursor->env_entry.set == set)
{
printf ("%s", env_cursor->env_entry.var);
if (env_cursor->env_entry.value != NULL)
......
......@@ -18,9 +18,9 @@
#include "mail.h"
/*
* w[rite] [file] GNU extension
* w[rite] [file] -- GNU extension
* w[rite] [msglist] file
* W[rite] [msglist] GNU extension
* W[rite] [msglist] -- GNU extension
*/
/*
......