+ free(copied);
+ return result;
+}
+
+/*
+ * If the terminal supports it, (re)set the left margin and return true.
+ * Otherwise, return false.
+ */
+static bool
+do_set_margin(int margin, bool no_op)
+{
+ bool result = FALSE;
+
+ if (margin == 0) { /* 0 is special case for resetting */
+ if (VALID_STRING(clear_margins)) {
+ result = TRUE;
+ if (!no_op)
+ tputs(clear_margins, 1, putch);
+ }
+ } else if (margin-- < 0) { /* margin will be 0-based from here on */
+ result = TRUE;
+ } else if (VALID_STRING(set_left_margin)) {
+ result = TRUE;
+ if (!no_op) {
+ /*
+ * assuming we're on the first column of the line, move the cursor
+ * to the column at which we will set a margin.
+ */
+ if (VALID_STRING(column_address)) {
+ tputs(TIPARM_1(column_address, margin), 1, putch);
+ } else if (margin >= 1) {
+ if (VALID_STRING(parm_right_cursor)) {
+ tputs(TIPARM_1(parm_right_cursor, margin), 1, putch);
+ } else {
+ while (margin-- > 0)
+ putch(' ');
+ }
+ }
+ tputs(set_left_margin, 1, putch);
+ }
+ } else if (VALID_STRING(set_left_margin_parm)) {
+ result = TRUE;
+ if (!no_op) {
+ if (VALID_STRING(set_right_margin_parm)) {
+ tputs(TIPARM_1(set_left_margin_parm, margin), 1, putch);
+ } else {
+ tputs(TIPARM_2(set_left_margin_parm, margin, max_cols), 1, putch);
+ }
+ }
+ } else if (VALID_STRING(set_lr_margin)) {
+ result = TRUE;
+ if (!no_op) {
+ tputs(TIPARM_2(set_lr_margin, margin, max_cols), 1, putch);
+ }
+ }