Commit 17930dd7 17930dd7cacf60c375408a26154301934a17609e by Sergey Poznyakoff

mail: honor columns/screen variables

* mail/util.c (util_command_list): Use util_screen_columns instead of
util_getcols.
(util_getcols): Don't use COLUMNS.
(util_getlines): Don't use LINES.
* mail/mail.c: Don't force COLUMNS and LINES (they are normally not
exported, so setting them will cause util_getcols and util_getlines
to return wrong results).
Set variable "columns" from envvar COLUMNS, if set to a numeric value.
Set variable "screen" from envvar LINES, if set to a numeric value.
* mail/from.c (format_headline): Use util_screen_columns instead of
util_getcols.
* mail/mailvar.c (mailvar_print,mail_variable): Likewise.
* mail/print.c (mail_print_msg): Likewise.
1 parent 131ddb25
...@@ -78,7 +78,7 @@ format_pad (size_t n) ...@@ -78,7 +78,7 @@ format_pad (size_t n)
78 static void 78 static void
79 format_headline (struct header_segm *seg, msgset_t *mspec, mu_message_t msg) 79 format_headline (struct header_segm *seg, msgset_t *mspec, mu_message_t msg)
80 { 80 {
81 int screen_cols = util_getcols () - 2; 81 int screen_cols = util_screen_columns () - 2;
82 int out_cols = 0; 82 int out_cols = 0;
83 struct header_call_args args; 83 struct header_call_args args;
84 84
......
...@@ -376,10 +376,7 @@ main (int argc, char **argv) ...@@ -376,10 +376,7 @@ main (int argc, char **argv)
376 376
377 /* set up the default environment */ 377 /* set up the default environment */
378 if (!getenv ("HOME")) 378 if (!getenv ("HOME"))
379 { 379 setenv ("HOME", util_get_homedir (), 0);
380 char *p = util_get_homedir ();
381 setenv ("HOME", p, 0);
382 }
383 380
384 /* Set up the default environment */ 381 /* Set up the default environment */
385 setenv ("DEAD", util_fullpath ("~/dead.letter"), 0); 382 setenv ("DEAD", util_fullpath ("~/dead.letter"), 0);
...@@ -390,14 +387,22 @@ main (int argc, char **argv) ...@@ -390,14 +387,22 @@ main (int argc, char **argv)
390 setenv ("PAGER", "more", 0); 387 setenv ("PAGER", "more", 0);
391 setenv ("SHELL", "sh", 0); 388 setenv ("SHELL", "sh", 0);
392 setenv ("VISUAL", "vi", 0); 389 setenv ("VISUAL", "vi", 0);
393 setenv ("COLUMNS", "80", 0);
394 setenv ("LINES", "24", 0);
395 390
396 /* set defaults for execution */ 391 /* set defaults for execution */
397 for (i = 0; i < sizeof (default_setup)/sizeof (default_setup[0]); i++) 392 for (i = 0; i < sizeof (default_setup)/sizeof (default_setup[0]); i++)
398 util_do_command ("%s", default_setup[i]); 393 util_do_command ("%s", default_setup[i]);
399 util_do_command ("set screen=%d", util_getlines ()); 394
400 util_do_command ("set columns=%d", util_getcols ()); 395 p = getenv ("LINES");
396 if (p && p[strspn (p, "0123456789")] == 0)
397 util_do_command ("set screen=%s", p);
398 else
399 util_do_command ("set screen=%d", util_getlines ());
400
401 p = getenv ("COLUMNS");
402 if (p && p[strspn (p, "0123456789")] == 0)
403 util_do_command ("set columns=%s", p);
404 else
405 util_do_command ("set columns=%d", util_getcols ());
401 406
402 /* Set the default mailer to sendmail. */ 407 /* Set the default mailer to sendmail. */
403 mailvar_set ("sendmail", 408 mailvar_set ("sendmail",
......
...@@ -39,8 +39,8 @@ sig_handler (int signo) ...@@ -39,8 +39,8 @@ sig_handler (int signo)
39 break; 39 break;
40 #if defined (SIGWINCH) 40 #if defined (SIGWINCH)
41 case SIGWINCH: 41 case SIGWINCH:
42 util_do_command ("set screen=%d", util_getlines()); 42 util_do_command ("set screen=%d", util_getlines ());
43 util_do_command ("set columns=%d", util_getcols()); 43 util_do_command ("set columns=%d", util_getcols ());
44 page_invalidate (1); 44 page_invalidate (1);
45 break; 45 break;
46 #endif 46 #endif
......
...@@ -749,7 +749,7 @@ mailvar_print (int set) ...@@ -749,7 +749,7 @@ mailvar_print (int set)
749 clos.out = open_pager (count); 749 clos.out = open_pager (count);
750 clos.prettyprint = mailvar_get (NULL, "variable-pretty-print", 750 clos.prettyprint = mailvar_get (NULL, "variable-pretty-print",
751 mailvar_type_boolean, 0) == 0; 751 mailvar_type_boolean, 0) == 0;
752 clos.width = util_getcols (); 752 clos.width = util_screen_columns ();
753 753
754 mu_list_foreach (varlist, mailvar_printer, &clos); 754 mu_list_foreach (varlist, mailvar_printer, &clos);
755 mu_list_destroy (&varlist); 755 mu_list_destroy (&varlist);
...@@ -845,7 +845,7 @@ int ...@@ -845,7 +845,7 @@ int
845 mail_variable (int argc, char **argv) 845 mail_variable (int argc, char **argv)
846 { 846 {
847 int pagelines = util_get_crt (); 847 int pagelines = util_get_crt ();
848 int width = util_getcols (); 848 int width = util_screen_columns ();
849 mu_stream_t out = open_pager (pagelines + 1); 849 mu_stream_t out = open_pager (pagelines + 1);
850 850
851 if (argc == 1) 851 if (argc == 1)
......
...@@ -45,7 +45,7 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data) ...@@ -45,7 +45,7 @@ mail_print_msg (msgset_t *mspec, mu_message_t mesg, void *data)
45 { 45 {
46 if (pagelines) 46 if (pagelines)
47 { 47 {
48 size_t col = (size_t)util_getcols (); 48 size_t col = (size_t) util_screen_columns ();
49 if (col) 49 if (col)
50 { 50 {
51 size_t size = 0; 51 size_t size = 0;
......
...@@ -311,7 +311,7 @@ util_command_list (void *table, size_t nmemb, size_t size) ...@@ -311,7 +311,7 @@ util_command_list (void *table, size_t nmemb, size_t size)
311 { 311 {
312 int i; 312 int i;
313 char *p; 313 char *p;
314 int cols = util_getcols (); 314 int cols = util_screen_columns ();
315 int pos; 315 int pos;
316 316
317 for (p = table, i = 0; i < nmemb; i++, p += size) 317 for (p = table, i = 0; i < nmemb; i++, p += size)
...@@ -349,16 +349,9 @@ int ...@@ -349,16 +349,9 @@ int
349 util_getcols (void) 349 util_getcols (void)
350 { 350 {
351 struct winsize ws; 351 struct winsize ws;
352
353 ws.ws_col = ws.ws_row = 0; 352 ws.ws_col = ws.ws_row = 0;
354 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0) 353 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_col == 0)
355 { 354 return 80; /* FIXME: Should we exit()/abort() if col <= 0 ? */
356 const char *columns = getenv ("COLUMNS");
357 if (columns)
358 ws.ws_col = strtol (columns, NULL, 10);
359 }
360
361 /* FIXME: Should we exit()/abort() if col <= 0 ? */
362 return ws.ws_col; 355 return ws.ws_col;
363 } 356 }
364 357
...@@ -370,17 +363,9 @@ int ...@@ -370,17 +363,9 @@ int
370 util_getlines (void) 363 util_getlines (void)
371 { 364 {
372 struct winsize ws; 365 struct winsize ws;
373
374 ws.ws_col = ws.ws_row = 0; 366 ws.ws_col = ws.ws_row = 0;
375 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row == 0) 367 if ((ioctl(1, TIOCGWINSZ, (char *) &ws) < 0) || ws.ws_row <= 2)
376 { 368 ws.ws_row = 24; /* FIXME: Should we exit()/abort() if row <= 2 ? */
377 const char *lines = getenv ("LINES");
378 if (lines)
379 ws.ws_row = strtol (lines, NULL, 10);
380 }
381
382 /* FIXME: Should we exit()/abort() if row <= 0 ? */
383
384 /* Reserve at least 2 line for the prompt. */ 369 /* Reserve at least 2 line for the prompt. */
385 return ws.ws_row - 2; 370 return ws.ws_row - 2;
386 } 371 }
......