Fix some buglets in mailx, prepare some commands for GNU extensions
Showing
10 changed files
with
77 additions
and
55 deletions
... | @@ -25,8 +25,11 @@ int | ... | @@ -25,8 +25,11 @@ int |
25 | mail_echo (int argc, char **argv) | 25 | mail_echo (int argc, char **argv) |
26 | { | 26 | { |
27 | int i = 0; | 27 | int i = 0; |
28 | for (i = 1; i < argc-1; i++) | 28 | if (argc > 1) |
29 | printf ("%s ", argv[i]); | 29 | { |
30 | printf ("%s\n", argv[argc]); | 30 | for (i = 1; i < argc - 1; i++) |
31 | printf ("%s ", argv[i]); | ||
32 | printf ("%s\n", argv[argc - 1]); | ||
33 | } | ||
31 | return 0; | 34 | return 0; |
32 | } | 35 | } | ... | ... |
... | @@ -18,36 +18,51 @@ | ... | @@ -18,36 +18,51 @@ |
18 | #include "mail.h" | 18 | #include "mail.h" |
19 | 19 | ||
20 | /* | 20 | /* |
21 | * h[eaders] [message] | 21 | * h[eaders] [msglist] -- GNU extension |
22 | */ | ||
23 | |||
24 | /* | ||
25 | * NOTE: check for messages near each other and only print them once | ||
26 | * should probably build a dynamic msglist for this | ||
22 | */ | 27 | */ |
23 | 28 | ||
24 | int | 29 | int |
25 | mail_headers (int argc, char **argv) | 30 | mail_headers (int argc, char **argv) |
26 | { | 31 | { |
27 | char buf[64]; | 32 | char buf[64]; |
28 | int low = 1, high = total, middle = cursor; | 33 | int low = 1, high = total, *list = NULL, i = 0; |
29 | int lines = util_getlines () - 2; | 34 | int lines = util_getlines (); |
30 | 35 | int num = util_expand_msglist (argc, argv, &list); | |
31 | if (argc > 2) | 36 | |
32 | return 1; | 37 | if (num == 0) |
33 | |||
34 | if (argc == 2) | ||
35 | middle = strtol (argv[1], NULL, 10); | ||
36 | |||
37 | if (lines < total) | ||
38 | { | 38 | { |
39 | low = middle - (lines / 2); | 39 | list = malloc (sizeof(int)); |
40 | if (low < 1) | 40 | *list = cursor; |
41 | low = 1; | 41 | num = 1; |
42 | high = low + lines; | 42 | } |
43 | if (high > total) | 43 | |
44 | lines = (lines / num) - 2; | ||
45 | |||
46 | for (i = 0; i < num; i++) | ||
47 | { | ||
48 | if (lines < total) | ||
44 | { | 49 | { |
45 | high = total; | 50 | low = list[i] - (lines / 2); |
46 | low = high - lines; | 51 | if (low < 1) |
52 | low = 1; | ||
53 | high = low + lines; | ||
54 | if (high > total) | ||
55 | { | ||
56 | high = total; | ||
57 | low = high - lines; | ||
58 | } | ||
47 | } | 59 | } |
60 | |||
61 | memset (buf, '\0', 64); | ||
62 | snprintf (buf, 64, "from %d-%d", low, high); | ||
63 | util_do_command (buf); | ||
48 | } | 64 | } |
49 | 65 | ||
50 | memset (buf, '\0', 64); | 66 | free (list); |
51 | snprintf (buf, 64, "from %d-%d", low, high); | 67 | return 0; |
52 | return util_do_command (buf); | ||
53 | } | 68 | } | ... | ... |
... | @@ -140,7 +140,7 @@ struct mail_command_entry util_find_entry __P((char *cmd)); | ... | @@ -140,7 +140,7 @@ struct mail_command_entry util_find_entry __P((char *cmd)); |
140 | int util_getcols __P((void)); | 140 | int util_getcols __P((void)); |
141 | int util_getlines __P((void)); | 141 | int util_getlines __P((void)); |
142 | struct mail_env_entry *util_find_env __P((char *var)); | 142 | struct mail_env_entry *util_find_env __P((char *var)); |
143 | int util_printenv __P((void)); | 143 | int util_printenv __P((int set)); |
144 | 144 | ||
145 | #ifdef __cplusplus | 145 | #ifdef __cplusplus |
146 | } | 146 | } | ... | ... |
... | @@ -18,8 +18,8 @@ | ... | @@ -18,8 +18,8 @@ |
18 | #include "mail.h" | 18 | #include "mail.h" |
19 | 19 | ||
20 | /* | 20 | /* |
21 | * r[eply] [message] | 21 | * r[eply] [msglist] -- GNU extension |
22 | * r[espond] [message] | 22 | * r[espond] [msglist] -- GNU extension |
23 | * R[eply] [msglist] | 23 | * R[eply] [msglist] |
24 | * R[espond] [msglist] | 24 | * R[espond] [msglist] |
25 | */ | 25 | */ | ... | ... |
... | @@ -30,7 +30,7 @@ mail_set (int argc, char **argv) | ... | @@ -30,7 +30,7 @@ mail_set (int argc, char **argv) |
30 | { | 30 | { |
31 | if (argc < 2) | 31 | if (argc < 2) |
32 | { | 32 | { |
33 | return util_printenv (); | 33 | return util_printenv (1); |
34 | } | 34 | } |
35 | else | 35 | else |
36 | { | 36 | { |
... | @@ -42,6 +42,8 @@ mail_set (int argc, char **argv) | ... | @@ -42,6 +42,8 @@ mail_set (int argc, char **argv) |
42 | if (!strncmp ("no", argv[i], 2)) | 42 | if (!strncmp ("no", argv[i], 2)) |
43 | { | 43 | { |
44 | entry = util_find_env (&argv[i][2]); | 44 | entry = util_find_env (&argv[i][2]); |
45 | if (entry == NULL) | ||
46 | return 1; | ||
45 | entry->set = 0; | 47 | entry->set = 0; |
46 | free (entry->value); | 48 | free (entry->value); |
47 | } | 49 | } |
... | @@ -57,14 +59,18 @@ mail_set (int argc, char **argv) | ... | @@ -57,14 +59,18 @@ mail_set (int argc, char **argv) |
57 | } | 59 | } |
58 | value = strdup (&var[j+1]); | 60 | value = strdup (&var[j+1]); |
59 | entry = util_find_env (var); | 61 | entry = util_find_env (var); |
62 | free (var); | ||
63 | if (entry == NULL) | ||
64 | return 1; | ||
60 | entry->set = 1; | 65 | entry->set = 1; |
61 | free (entry->value); | 66 | free (entry->value); |
62 | entry->value = value; | 67 | entry->value = value; |
63 | free (var); | ||
64 | } | 68 | } |
65 | else | 69 | else |
66 | { | 70 | { |
67 | entry = util_find_env(argv[i]); | 71 | entry = util_find_env(argv[i]); |
72 | if (entry == NULL) | ||
73 | return 1; | ||
68 | entry->set = 1; | 74 | entry->set = 1; |
69 | free (entry->value); | 75 | free (entry->value); |
70 | entry->value = NULL; | 76 | entry->value = NULL; | ... | ... |
... | @@ -24,8 +24,7 @@ const struct mail_command_entry mail_command_table[] = { | ... | @@ -24,8 +24,7 @@ const struct mail_command_entry mail_command_table[] = { |
24 | { "C", "Copy", mail_copy, "C[opy] [msglist]" }, | 24 | { "C", "Copy", mail_copy, "C[opy] [msglist]" }, |
25 | { "cd", "cd", mail_cd, "cd [directory]" }, | 25 | { "cd", "cd", mail_cd, "cd [directory]" }, |
26 | { "ch", "chdir", mail_cd, "ch[dir] directory" }, | 26 | { "ch", "chdir", mail_cd, "ch[dir] directory" }, |
27 | { "c", "copy", mail_copy, | 27 | { "c", "copy", mail_copy, "c[opy] [[msglist] file]" }, |
28 | "c[opy] [file]\nc[opy] [msglist] file" }, | ||
29 | { "d", "delete", mail_delete, "d[elete] [msglist]" }, | 28 | { "d", "delete", mail_delete, "d[elete] [msglist]" }, |
30 | { "di", "discard", mail_discard, | 29 | { "di", "discard", mail_discard, |
31 | "di[scard] [header-field...]" }, | 30 | "di[scard] [header-field...]" }, |
... | @@ -40,12 +39,12 @@ const struct mail_command_entry mail_command_table[] = { | ... | @@ -40,12 +39,12 @@ const struct mail_command_entry mail_command_table[] = { |
40 | { "fi", "file", mail_file, "fi[le] [file]" }, | 39 | { "fi", "file", mail_file, "fi[le] [file]" }, |
41 | { "fold", "folder", mail_file, "fold[er] [file]" }, | 40 | { "fold", "folder", mail_file, "fold[er] [file]" }, |
42 | { "folders", "folders", mail_folders, "folders" }, | 41 | { "folders", "folders", mail_folders, "folders" }, |
43 | { "fo", "followup", mail_followup, "fo[llowup] [message]" }, | 42 | { "fo", "followup", mail_followup, "fo[llowup] [msglist]" }, |
44 | { "f", "from", mail_from, "f[rom] [msglist]" }, | 43 | { "f", "from", mail_from, "f[rom] [msglist]" }, |
45 | { "g", "group", mail_alias, | 44 | { "g", "group", mail_alias, |
46 | "g[roup] [alias [address...]]" }, | 45 | "g[roup] [alias [address...]]" }, |
47 | { "h", "headers", mail_headers, "h[eaders] [message]" }, | 46 | { "h", "headers", mail_headers, "h[eaders] [msglist]" }, |
48 | { "hel", "help", mail_help, "hel[p] [command]" }, | 47 | { "hel", "help", mail_help, "hel[p] [command...]" }, |
49 | { "ho", "hold", mail_hold, "ho[ld] [msglist]" }, | 48 | { "ho", "hold", mail_hold, "ho[ld] [msglist]" }, |
50 | { "i", "if", mail_if, "i[f] s|r" }, /* FIXME */ | 49 | { "i", "if", mail_if, "i[f] s|r" }, /* FIXME */ |
51 | { "ig", "ignore", mail_discard, "ig[nore] [header-field...]" }, | 50 | { "ig", "ignore", mail_discard, "ig[nore] [header-field...]" }, |
... | @@ -55,18 +54,17 @@ const struct mail_command_entry mail_command_table[] = { | ... | @@ -55,18 +54,17 @@ const struct mail_command_entry mail_command_table[] = { |
55 | { "n", "next", mail_next, "n[ext] [message]" }, | 54 | { "n", "next", mail_next, "n[ext] [message]" }, |
56 | { "P", "Print", mail_print, "P[rint] [msglist]" }, | 55 | { "P", "Print", mail_print, "P[rint] [msglist]" }, |
57 | { "pi", "pipe", mail_pipe, "pi[pe] [[msglist] command]" }, | 56 | { "pi", "pipe", mail_pipe, "pi[pe] [[msglist] command]" }, |
58 | { "pre", "preserve", mail_hold, "pre[server] [msglist]" }, | 57 | { "pre", "preserve", mail_hold, "pre[serve] [msglist]" }, |
59 | { "prev", "previous", mail_previous, "prev[ious] [message]" }, | 58 | { "prev", "previous", mail_previous, "prev[ious] [message]" }, |
60 | { "p", "print", mail_print, "p[rint] [msglist]" }, | 59 | { "p", "print", mail_print, "p[rint] [msglist]" }, |
61 | { "q", "quit", mail_quit, "q[uit]" }, | 60 | { "q", "quit", mail_quit, "q[uit]" }, |
62 | { "R", "Reply", mail_reply, "R[eply] [msglist]" }, | 61 | { "R", "Reply", mail_reply, "R[eply] [msglist]" }, |
63 | { "R", "Respond", mail_reply, "R[espond] [msglist]" }, | 62 | { "R", "Respond", mail_reply, "R[espond] [msglist]" }, |
64 | { "r", "reply", mail_reply, "r[eply] [message]" }, | 63 | { "r", "reply", mail_reply, "r[eply] [msglist]" }, |
65 | { "r", "respond", mail_reply, "r[espond] [message]" }, | 64 | { "r", "respond", mail_reply, "r[espond] [msglist]" }, |
66 | { "ret", "retain", mail_retain, "ret[ain] [header-field]" }, | 65 | { "ret", "retain", mail_retain, "ret[ain] [header-field]" }, |
67 | { "S", "Save", mail_save, "S[ave] [msglist]" }, | 66 | { "S", "Save", mail_save, "S[ave] [msglist]" }, |
68 | { "s", "save", mail_save, | 67 | { "s", "save", mail_save, "s[ave] [[msglist] file]" }, |
69 | "s[ave] [file]\ns[ave] [msglist] file" }, | ||
70 | { "se", "set", mail_set, | 68 | { "se", "set", mail_set, |
71 | "se[t] [name[=[string]]...] [name=number...] [noname...]" }, | 69 | "se[t] [name[=[string]]...] [name=number...] [noname...]" }, |
72 | { "sh", "shell", mail_shell, "sh[ell]" }, | 70 | { "sh", "shell", mail_shell, "sh[ell]" }, |
... | @@ -81,11 +79,10 @@ const struct mail_command_entry mail_command_table[] = { | ... | @@ -81,11 +79,10 @@ const struct mail_command_entry mail_command_table[] = { |
81 | { "uns", "unset", mail_unset, "uns[et] name..." }, | 79 | { "uns", "unset", mail_unset, "uns[et] name..." }, |
82 | { "v", "visual", mail_visual, "v[isual] [msglist]" }, | 80 | { "v", "visual", mail_visual, "v[isual] [msglist]" }, |
83 | { "W", "Write", mail_write, "W[rite] [msglist]" }, | 81 | { "W", "Write", mail_write, "W[rite] [msglist]" }, |
84 | { "w", "write", mail_write, | 82 | { "w", "write", mail_write, "w[rite] [[msglist] file]" }, |
85 | "w[rite] [file]\nw[rite] [msglist] file" }, | ||
86 | { "x", "xit", mail_exit, "x[it]" }, | 83 | { "x", "xit", mail_exit, "x[it]" }, |
87 | { "z", "", mail_z, "z[+|-]" }, | 84 | { "z", "", mail_z, "z[+|-]" }, |
88 | { "?", "?", mail_help, "? [command]" }, | 85 | { "?", "?", mail_help, "? [command...]" }, |
89 | { "!", "", mail_bang, "!command" }, | 86 | { "!", "", mail_bang, "!command" }, |
90 | { "=", "=", mail_eq, "=" }, | 87 | { "=", "=", mail_eq, "=" }, |
91 | { "#", "#", NULL, "# comment" }, | 88 | { "#", "#", NULL, "# comment" }, | ... | ... |
... | @@ -18,26 +18,27 @@ | ... | @@ -18,26 +18,27 @@ |
18 | #include "mail.h" | 18 | #include "mail.h" |
19 | 19 | ||
20 | /* | 20 | /* |
21 | * uns[et] name... | 21 | * uns[et] [name...] -- GNU extension |
22 | */ | 22 | */ |
23 | 23 | ||
24 | int | 24 | int |
25 | mail_unset (int argc, char **argv) | 25 | mail_unset (int argc, char **argv) |
26 | { | 26 | { |
27 | if (argc < 2) | 27 | if (argc < 2) |
28 | return 1; | 28 | return util_printenv (0); |
29 | else | 29 | else |
30 | { | 30 | { |
31 | int status = 0, i = 1; | 31 | int status = 0, i = 1; |
32 | for (i=1; i < argc; i++) | 32 | for (i=1; i < argc; i++) |
33 | { | 33 | { |
34 | char *buf = malloc ((6+strlen (argv[i])) * sizeof (char)); | 34 | char *buf = malloc ((7+strlen (argv[i])) * sizeof (char)); |
35 | strcpy (buf, "set no"); | 35 | strcpy (buf, "set no"); |
36 | strcat (buf, argv[i]); | 36 | strcat (buf, argv[i]); |
37 | if (!util_do_command (buf)) | 37 | if (!util_do_command (buf)) |
38 | status = 1; | 38 | status = 1; |
39 | free (buf); | 39 | free (buf); |
40 | } | 40 | } |
41 | return status; | ||
41 | } | 42 | } |
42 | return 1; | 43 | return 1; |
43 | } | 44 | } | ... | ... |
... | @@ -36,9 +36,6 @@ util_ll_add (node *c, int data) | ... | @@ -36,9 +36,6 @@ util_ll_add (node *c, int data) |
36 | { | 36 | { |
37 | c->next = malloc (sizeof (node)); | 37 | c->next = malloc (sizeof (node)); |
38 | c->data = data; | 38 | c->data = data; |
39 | /* c->env_entry.var = NULL; | ||
40 | c->env_entry.set = 0; | ||
41 | c->env_entry.value = NULL;*/ | ||
42 | c->next->env_entry.var = NULL; | 39 | c->next->env_entry.var = NULL; |
43 | c->next->env_entry.set = 0; | 40 | c->next->env_entry.set = 0; |
44 | c->next->env_entry.value = NULL; | 41 | c->next->env_entry.value = NULL; |
... | @@ -380,6 +377,9 @@ util_find_env (char *variable) | ... | @@ -380,6 +377,9 @@ util_find_env (char *variable) |
380 | int len = strlen (var), need_free = 0; | 377 | int len = strlen (var), need_free = 0; |
381 | node *t; | 378 | node *t; |
382 | 379 | ||
380 | if (len < 1) | ||
381 | return NULL; | ||
382 | |||
383 | if (len == strlen ("ask") && !strcmp ("ask", var)) | 383 | if (len == strlen ("ask") && !strcmp ("ask", var)) |
384 | { | 384 | { |
385 | var = strdup ("asksub"); | 385 | var = strdup ("asksub"); |
... | @@ -407,7 +407,7 @@ util_find_env (char *variable) | ... | @@ -407,7 +407,7 @@ util_find_env (char *variable) |
407 | return &(env_cursor->env_entry); | 407 | return &(env_cursor->env_entry); |
408 | } | 408 | } |
409 | } | 409 | } |
410 | /* env_cursor = util_ll_add (env_cursor, 0); */ | 410 | |
411 | env_cursor->env_entry.var = strdup (var); | 411 | env_cursor->env_entry.var = strdup (var); |
412 | env_cursor->env_entry.set = 0; | 412 | env_cursor->env_entry.set = 0; |
413 | env_cursor->env_entry.value = NULL; | 413 | env_cursor->env_entry.value = NULL; |
... | @@ -422,12 +422,12 @@ util_find_env (char *variable) | ... | @@ -422,12 +422,12 @@ util_find_env (char *variable) |
422 | * print the environment | 422 | * print the environment |
423 | */ | 423 | */ |
424 | int | 424 | int |
425 | util_printenv (void) | 425 | util_printenv (int set) |
426 | { | 426 | { |
427 | for (env_cursor = environment; env_cursor != NULL; | 427 | for (env_cursor = environment; env_cursor != NULL; |
428 | env_cursor = env_cursor->next) | 428 | env_cursor = env_cursor->next) |
429 | { | 429 | { |
430 | if (env_cursor->env_entry.set) | 430 | if (env_cursor->env_entry.set == set) |
431 | { | 431 | { |
432 | printf ("%s", env_cursor->env_entry.var); | 432 | printf ("%s", env_cursor->env_entry.var); |
433 | if (env_cursor->env_entry.value != NULL) | 433 | if (env_cursor->env_entry.value != NULL) | ... | ... |
... | @@ -18,9 +18,9 @@ | ... | @@ -18,9 +18,9 @@ |
18 | #include "mail.h" | 18 | #include "mail.h" |
19 | 19 | ||
20 | /* | 20 | /* |
21 | * w[rite] [file] GNU extension | 21 | * w[rite] [file] -- GNU extension |
22 | * w[rite] [msglist] file | 22 | * w[rite] [msglist] file |
23 | * W[rite] [msglist] GNU extension | 23 | * W[rite] [msglist] -- GNU extension |
24 | */ | 24 | */ |
25 | 25 | ||
26 | /* | 26 | /* | ... | ... |
-
Please register or sign in to post a comment