Commit edc010f2 edc010f2c2c0f875d61a44b6ff82f2768a37f2d8 by Alain Magloire

* mail/echo.c: Make it aware of escape char '\'.

        * mail/next.c: Should print the message also.
        * mail/previous.c: Should print the message also.
        * mail/util.c(util_do_command): Memory leak cmd
        was not free(cmd).  An empty line means now "next".
1 parent f96b8316
1 2002-03-13 Sergey Poznyakoff 1 2002-03-13 Sergey Poznyakoff
2 2
3 * mail/echo.c: Make it aware of escape char '\'.
4 * mail/next.c: Should print the message also.
5 * mail/previous.c: Should print the message also.
6 * mail/util.c(util_do_command): Memory leak cmd
7 was not free(cmd). An empty line means now "next".
8
9 2002-03-13 Sergey Poznyakoff
10
3 * include/mailutils/Makefile.am: Added types.h 11 * include/mailutils/Makefile.am: Added types.h
4 12
5 * argp/{argp-eexst.c,argp-namefrob.h,argp.h, 13 * argp/{argp-eexst.c,argp-namefrob.h,argp.h,
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
21 * ec[ho] string ... 21 * ec[ho] string ...
22 */ 22 */
23 23
24 static int echo (char *s);
25
24 int 26 int
25 mail_echo (int argc, char **argv) 27 mail_echo (int argc, char **argv)
26 { 28 {
...@@ -28,8 +30,120 @@ mail_echo (int argc, char **argv) ...@@ -28,8 +30,120 @@ mail_echo (int argc, char **argv)
28 if (argc > 1) 30 if (argc > 1)
29 { 31 {
30 for (i = 1; i < argc - 1; i++) 32 for (i = 1; i < argc - 1; i++)
31 fprintf (ofile, "%s ", argv[i]); 33 {
32 fprintf (ofile, "%s\n", argv[argc - 1]); 34 echo (argv[i]);
35 fputc (' ', ofile);
36 }
37 /* Last argument. */
38 if (echo(argv[argc - 1]) == 0)
39 fputc ('\n', ofile);
40 }
41 return 0;
42 }
43
44 /* Cumbersome switch for checking escape char '\'
45 if present replace with appropriately.
46 Return of 1 means to not print newline. */
47 static int
48 echo (char *s)
49 {
50 int process_escape = 0;
51 int c;
52
53 if (s == NULL)
54 return 0;
55
56 for (; (c = *s) != 0; s++)
57 {
58 if (process_escape)
59 {
60 switch (c)
61 {
62 /* \a Bell. */
63 case 'a':
64 c = '\a';
65 break;
66
67 /* \b Backspace. */
68 case 'b':
69 c = '\b';
70 break;
71
72 /* \c means not to print ending newline. */
73 /* Bail out and tell the caller not to print newline. */
74 case 'c':
75 return 1;
76 break;
77
78 /* \f Formfeed. */
79 case 'f':
80 c = '\f';
81 break;
82
83 /* \n Newline. */
84 case 'n':
85 c = '\n';
86 break;
87
88 /* \r Carriage return. */
89 case 'r':
90 c = '\r';
91 break;
92
93 /* \t Tab. */
94 case 't':
95 c = '\t';
96 break;
97
98 /* \v Vertical Tab. */
99 case 'v':
100 c = '\v';
101 break;
102
103 /* Escape sequence. */
104 case '\\':
105 c = '\\';
106 break;
107
108 /* \0x99 for example, let strtol() handle it. */
109 /* WARNING: Side effects because of strtol(). */
110 case '0':
111 {
112 long number = strtol (s, &s, 0);
113 switch (number)
114 {
115 case LONG_MIN:
116 case LONG_MAX:
117 /* if (errno == ERANGE) */
118 /* fputc (c, ofile); */
119 break;
120
121 default:
122 fprintf (ofile, "%d", number);
123 s--;
124 continue;
125 }
126 }
127 break;
128
129 /* Can not be here. */
130 case '\0':
131 return 0;
132 break;
133
134 /* \\ means \ It was not an escape char. */
135 default:
136 fputc ('\\', ofile);
137
138 }
139 process_escape =0;
140 }
141 else if (c == '\\') /* Find the escape char, go back and process. */
142 {
143 process_escape = 1;
144 continue;
145 }
146 fputc (c, ofile);
33 } 147 }
34 return 0; 148 return 0;
35 } 149 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
30 # include <alloca.h> 30 # include <alloca.h>
31 #endif 31 #endif
32 #include <errno.h> 32 #include <errno.h>
33 #include <limits.h>
33 #include <stdio.h> 34 #include <stdio.h>
34 #include <stdlib.h> 35 #include <stdlib.h>
35 #include <unistd.h> 36 #include <unistd.h>
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -29,7 +29,6 @@ mail_next (int argc, char **argv) ...@@ -29,7 +29,6 @@ mail_next (int argc, char **argv)
29 { 29 {
30 cursor++; 30 cursor++;
31 realcursor++; 31 realcursor++;
32 return 0;
33 } 32 }
34 else 33 else
35 { 34 {
...@@ -38,7 +37,7 @@ mail_next (int argc, char **argv) ...@@ -38,7 +37,7 @@ mail_next (int argc, char **argv)
38 cursor = list->msg_part[0]; 37 cursor = list->msg_part[0];
39 realcursor = cursor; 38 realcursor = cursor;
40 msgset_free (list); 39 msgset_free (list);
41 return 0;
42 } 40 }
41 util_do_command("print");
43 return 1; 42 return 1;
44 } 43 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -29,7 +29,6 @@ mail_previous (int argc, char **argv) ...@@ -29,7 +29,6 @@ mail_previous (int argc, char **argv)
29 { 29 {
30 cursor--; 30 cursor--;
31 realcursor--; 31 realcursor--;
32 return 0;
33 } 32 }
34 else 33 else
35 { 34 {
...@@ -39,7 +38,7 @@ mail_previous (int argc, char **argv) ...@@ -39,7 +38,7 @@ mail_previous (int argc, char **argv)
39 cursor = list->msg_part[0]; 38 cursor = list->msg_part[0];
40 realcursor = cursor; 39 realcursor = cursor;
41 msgset_free (list); 40 msgset_free (list);
42 return 0;
43 } 41 }
42 util_do_command ("print");
44 return 1; 43 return 1;
45 } 44 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -97,20 +97,29 @@ util_do_command (const char *c, ...) ...@@ -97,20 +97,29 @@ util_do_command (const char *c, ...)
97 { 97 {
98 struct mail_command_entry entry; 98 struct mail_command_entry entry;
99 99
100 if (cmd[0] == '#') 100 /* Ignore comments */
101 if (cmd[0] == '#') {
102 free (cmd);
101 return 0; 103 return 0;
104 }
102 105
103 if (argcv_get (cmd, delim, NULL, &argc, &argv) != 0) 106 /* Hitting return i.e. no command, is equivalent to next
104 return argcv_free (argc, argv); 107 according to the POSIX spec. */
108 if (cmd[0] == '\0') {
109 free (cmd);
110 cmd = strdup ("next");
111 }
105 112
106 entry = util_find_entry (mail_command_table, argv[0]); 113 if (argcv_get (cmd, delim, NULL, &argc, &argv) == 0)
107
108 if (if_cond () == 0 && (entry.flags & EF_FLOW) == 0)
109 { 114 {
110 argcv_free (argc, argv); 115
111 return 0; 116 entry = util_find_entry (mail_command_table, argv[0]);
117
118 /* Make sure we are not in any if/else */
119 if (! (if_cond () == 0 && (entry.flags & EF_FLOW) == 0))
120 command = entry.func;
112 } 121 }
113 command = entry.func; 122 free (cmd);
114 } 123 }
115 else 124 else
116 command = util_command_get ("quit"); 125 command = util_command_get ("quit");
......