Commit c7f34674 c7f34674d461d773f178efe4c90822ebe1ac9115 by Sergey Poznyakoff

Finished

1 parent 9044e249
Showing 1 changed file with 35 additions and 20 deletions
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
23 23
24 const char *argp_program_version = "mhl (" PACKAGE_STRING ")"; 24 const char *argp_program_version = "mhl (" PACKAGE_STRING ")";
25 static char doc[] = N_("GNU MH mhl\v" 25 static char doc[] = N_("GNU MH mhl\v"
26 "Options marked with `*' are not yet implemented.\n"
27 "Use -help to obtain the list of traditional MH options."); 26 "Use -help to obtain the list of traditional MH options.");
28 static char args_doc[] = N_("[files]"); 27 static char args_doc[] = N_("[files]");
29 28
...@@ -32,17 +31,17 @@ static struct argp_option options[] = { ...@@ -32,17 +31,17 @@ static struct argp_option options[] = {
32 {"folder", ARG_FOLDER, N_("FOLDER"), 0, 31 {"folder", ARG_FOLDER, N_("FOLDER"), 0,
33 N_("Specify folder to operate upon")}, 32 N_("Specify folder to operate upon")},
34 { "bell", ARG_BELL, N_("BOOL"), OPTION_ARG_OPTIONAL, 33 { "bell", ARG_BELL, N_("BOOL"), OPTION_ARG_OPTIONAL,
35 N_("* Ring the bell at the end of each output page") }, 34 N_("Ring the bell at the end of each output page") },
36 {"nobell", ARG_NOBELL, NULL, OPTION_HIDDEN, "" }, 35 {"nobell", ARG_NOBELL, NULL, OPTION_HIDDEN, "" },
37 { "clear", ARG_CLEAR, N_("BOOL"), OPTION_ARG_OPTIONAL, 36 { "clear", ARG_CLEAR, N_("BOOL"), OPTION_ARG_OPTIONAL,
38 N_("* Clear the screen after each page of output")}, 37 N_("Clear the screen after each page of output")},
39 {"noclear", ARG_NOCLEAR, NULL, OPTION_HIDDEN, "" }, 38 {"noclear", ARG_NOCLEAR, NULL, OPTION_HIDDEN, "" },
40 {"form", ARG_FORM, N_("FILE"), 0, 39 {"form", ARG_FORM, N_("FILE"), 0,
41 N_("* Read format from given file")}, 40 N_("Read format from given file")},
42 {"width", ARG_WIDTH, N_("NUMBER"), 0, 41 {"width", ARG_WIDTH, N_("NUMBER"), 0,
43 N_("* Set output width")}, 42 N_("Set output width")},
44 {"length", ARG_LENGTH, N_("NUMBER"), 0, 43 {"length", ARG_LENGTH, N_("NUMBER"), 0,
45 N_("* Set output screen length")}, 44 N_("Set output screen length")},
46 {"moreproc", ARG_MOREPROC, N_("PROG"), 0, 45 {"moreproc", ARG_MOREPROC, N_("PROG"), 0,
47 N_("Use given PROG instead of the default") }, 46 N_("Use given PROG instead of the default") },
48 {"nomoreproc", ARG_NOMOREPROC, NULL, 0, 47 {"nomoreproc", ARG_NOMOREPROC, NULL, 0,
...@@ -67,10 +66,12 @@ static int bell = 1; /* Ring the bell after each page of output */ ...@@ -67,10 +66,12 @@ static int bell = 1; /* Ring the bell after each page of output */
67 static int clear = 0; /* Clear the screen after each page of output */ 66 static int clear = 0; /* Clear the screen after each page of output */
68 static int length = 40; /* Length of output page */ 67 static int length = 40; /* Length of output page */
69 static int width = 80; /* Width of output page */ 68 static int width = 80; /* Width of output page */
70 static char *formfile = "mhl.format"; 69 static char *formfile = MHLIBDIR "/mhl.format";
71 static char *moreproc; 70 static char *moreproc;
72 static int nomoreproc; 71 static int nomoreproc;
73 72
73 static list_t format;
74
74 static int 75 static int
75 opt_handler (int key, char *arg, void *unused) 76 opt_handler (int key, char *arg, void *unused)
76 { 77 {
...@@ -139,11 +140,11 @@ open_output () ...@@ -139,11 +140,11 @@ open_output ()
139 int rc; 140 int rc;
140 stream_t output; 141 stream_t output;
141 142
142 if (interactive && !nomoreproc) 143 if (interactive && !moreproc && !nomoreproc)
143 moreproc = mh_global_profile_get ("moreproc", getenv ("PAGER")); 144 moreproc = mh_global_profile_get ("moreproc", getenv ("PAGER"));
144 else 145 else
145 moreproc = NULL; 146 moreproc = NULL;
146 147
147 if (moreproc) 148 if (moreproc)
148 rc = prog_stream_create (&output, moreproc, MU_STREAM_WRITE); 149 rc = prog_stream_create (&output, moreproc, MU_STREAM_WRITE);
149 else 150 else
...@@ -166,13 +167,12 @@ open_output () ...@@ -166,13 +167,12 @@ open_output ()
166 static void 167 static void
167 list_message (char *name, stream_t output) 168 list_message (char *name, stream_t output)
168 { 169 {
169 stream_t input;
170 int rc; 170 int rc;
171 char buf[512]; 171 stream_t input;
172 size_t n; 172 message_t msg;
173 173
174 if (!name) 174 if (!name)
175 rc = stdio_stream_create (&input, stdin, 0); 175 rc = stdio_stream_create (&input, stdin, MU_STREAM_SEEKABLE);
176 else 176 else
177 rc = file_stream_create (&input, name, MU_STREAM_READ); 177 rc = file_stream_create (&input, name, MU_STREAM_READ);
178 if (rc) 178 if (rc)
...@@ -188,12 +188,19 @@ list_message (char *name, stream_t output) ...@@ -188,12 +188,19 @@ list_message (char *name, stream_t output)
188 return; 188 return;
189 } 189 }
190 190
191 while (stream_sequential_readline (input, buf, sizeof buf, &n) == 0 191 msg = mh_stream_to_message (input);
192 && n > 0) 192 if (!msg)
193 stream_sequential_write (output, buf, n); 193 {
194 194 mh_error (_("input stream %s is not a message (%s)"),
195 stream_close (input); 195 name, mu_strerror (rc));
196 stream_destroy (&input, stream_get_owner (input)); 196 stream_close (input);
197 stream_destroy (&input, stream_get_owner (input));
198 }
199 else
200 {
201 mhl_format_run (format, width, length, clear, bell, msg, output);
202 message_unref (msg);
203 }
197 } 204 }
198 205
199 int 206 int
...@@ -208,11 +215,18 @@ main (int argc, char **argv) ...@@ -208,11 +215,18 @@ main (int argc, char **argv)
208 mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, 215 mh_argp_parse (argc, argv, options, mh_option, args_doc, doc,
209 opt_handler, NULL, &index); 216 opt_handler, NULL, &index);
210 217
218 format = mhl_format_compile (formfile);
219 if (!format)
220 exit (1);
221
211 argc -= index; 222 argc -= index;
212 argv += index; 223 argv += index;
213 224
214 if (argc == 0) 225 if (argc == 0)
215 nomoreproc = 1; 226 nomoreproc = 1;
227
228 if (!interactive)
229 bell = 0;
216 230
217 output = open_output (); 231 output = open_output ();
218 232
...@@ -221,6 +235,7 @@ main (int argc, char **argv) ...@@ -221,6 +235,7 @@ main (int argc, char **argv)
221 else 235 else
222 while (argc--) 236 while (argc--)
223 list_message (*argv++, output); 237 list_message (*argv++, output);
224 238
239 stream_close (output);
225 return 0; 240 return 0;
226 } 241 }
......