]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/reset_cmd.c
ncurses 6.2 - patch 20200829
[ncurses.git] / progs / reset_cmd.c
index 058ebf9c5a0ddca1df1c09c0bebc140e779e3baa..2e118ae58bae9ad55b10cf47a950cd165e74f0f1 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2016-2017,2019 Free Software Foundation, Inc.              *
+ * Copyright 2019,2020 Thomas E. Dickey                                     *
+ * Copyright 2016,2017 Free Software Foundation, Inc.                       *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -52,7 +53,7 @@
 #include <sys/ptem.h>
 #endif
 
-MODULE_ID("$Id: reset_cmd.c,v 1.14 2019/02/23 18:33:19 tom Exp $")
+MODULE_ID("$Id: reset_cmd.c,v 1.21 2020/05/27 23:46:20 tom Exp $")
 
 /*
  * SCO defines TIOCGSIZE and the corresponding struct.  Other systems (SunOS,
@@ -413,6 +414,28 @@ set_conversions(TTY * tty_settings)
     tty_settings->c_lflag |= (ECHOE | ECHOK);
 }
 
+static bool
+sent_string(const char *s)
+{
+    bool sent = FALSE;
+    if (VALID_STRING(s)) {
+       tputs(s, 0, out_char);
+       sent = TRUE;
+    }
+    return sent;
+}
+
+static bool
+to_left_margin(void)
+{
+    if (VALID_STRING(carriage_return)) {
+       sent_string(carriage_return);
+    } else {
+       out_char('\r');
+    }
+    return TRUE;
+}
+
 /*
  * Set the hardware tabs on the terminal, using the 'ct' (clear all tabs),
  * 'st' (set one tab) and 'ch' (horizontal cursor addressing) capabilities.
@@ -423,41 +446,28 @@ set_conversions(TTY * tty_settings)
 static bool
 reset_tabstops(int wide)
 {
-    if ((init_tabs != 8) && (VALID_STRING(set_tab) && VALID_STRING(clear_all_tabs))) {
+    if ((init_tabs != 8)
+       && VALID_NUMERIC(init_tabs)
+       && VALID_STRING(set_tab)
+       && VALID_STRING(clear_all_tabs)) {
        int c;
 
-       (void) putc('\r', my_file);     /* Force to left margin. */
+       to_left_margin();
        tputs(clear_all_tabs, 0, out_char);
-
-       for (c = 8; c < wide; c += 8) {
-           /* Get to the right column.  In BSD tset, this used to try a bunch
-            * of half-clever things with cup and hpa, for an average saving of
-            * somewhat less than two character times per tab stop, less than
-            * .01 sec at 2400cps.  We lost all this cruft because it seemed to
-            * be introducing some odd bugs.
-            * -----------12345678----------- */
-           (void) fputs("        ", my_file);
-           tputs(set_tab, 0, out_char);
+       if (init_tabs > 1) {
+           if (init_tabs > wide)
+               init_tabs = (short) wide;
+           for (c = init_tabs; c < wide; c += init_tabs) {
+               fprintf(my_file, "%*s", init_tabs, " ");
+               tputs(set_tab, 0, out_char);
+           }
+           to_left_margin();
        }
-       putc('\r', my_file);
        return (TRUE);
     }
     return (FALSE);
 }
 
-static bool
-sent_string(const char *s)
-{
-    bool sent = FALSE;
-    if (VALID_STRING(s)) {
-       tputs(s, 0, out_char);
-       sent = TRUE;
-    }
-    return sent;
-}
-
-#define PUTCHAR(c) fputc(c, my_file)
-
 /* Output startup string. */
 bool
 send_init_strings(int fd GCC_UNUSED, TTY * old_settings)
@@ -486,44 +496,37 @@ send_init_strings(int fd GCC_UNUSED, TTY * old_settings)
                                  ? reset_2string
                                  : init_2string);
 
+       if (VALID_STRING(clear_margins)) {
+           need_flush |= sent_string(clear_margins);
+       } else
 #if defined(set_lr_margin)
        if (VALID_STRING(set_lr_margin)) {
-           need_flush |= sent_string(TPARM_2(set_lr_margin, 0,
-                                             columns - 1));
+           need_flush |= sent_string(TIPARM_2(set_lr_margin, 0, columns - 1));
        } else
 #endif
 #if defined(set_left_margin_parm) && defined(set_right_margin_parm)
            if (VALID_STRING(set_left_margin_parm)
                && VALID_STRING(set_right_margin_parm)) {
-           need_flush |= sent_string(TPARM_1(set_left_margin_parm, 0));
-           need_flush |= sent_string(TPARM_1(set_right_margin_parm,
-                                             columns - 1));
+           need_flush |= sent_string(TIPARM_1(set_left_margin_parm, 0));
+           need_flush |= sent_string(TIPARM_1(set_right_margin_parm,
+                                              columns - 1));
        } else
 #endif
-           if (VALID_STRING(clear_margins)
-               && VALID_STRING(set_left_margin)
+           if (VALID_STRING(set_left_margin)
                && VALID_STRING(set_right_margin)) {
-           need_flush |= sent_string(clear_margins);
-           if (carriage_return != 0) {
-               need_flush |= sent_string(carriage_return);
-           } else {
-               PUTCHAR('\r');
-           }
+           need_flush |= to_left_margin();
            need_flush |= sent_string(set_left_margin);
            if (VALID_STRING(parm_right_cursor)) {
-               need_flush |= sent_string(TPARM_1(parm_right_cursor,
-                                                 columns - 1));
+               need_flush |= sent_string(TIPARM_1(parm_right_cursor,
+                                                  columns - 1));
            } else {
                for (i = 0; i < columns - 1; i++) {
-                   PUTCHAR(' ');
+                   out_char(' ');
+                   need_flush = TRUE;
                }
            }
            need_flush |= sent_string(set_right_margin);
-           if (VALID_STRING(carriage_return)) {
-               need_flush |= sent_string(carriage_return);
-           } else {
-               PUTCHAR('\r');
-           }
+           need_flush |= to_left_margin();
        }
 
        need_flush |= reset_tabstops(columns);