- if (reset && reset_1string != NULL) {
- PUTS(reset_1string);
- } else if (init_1string != NULL) {
- PUTS(init_1string);
- }
- FLUSH;
-
- if (reset && reset_2string != NULL) {
- PUTS(reset_2string);
- } else if (init_2string != NULL) {
- PUTS(init_2string);
- }
- FLUSH;
-
- if (set_lr_margin != NULL) {
- PUTS(tparm(set_lr_margin, 0, columns - 1));
- } else if (set_left_margin_parm != NULL
- && set_right_margin_parm != NULL) {
- PUTS(tparm(set_left_margin_parm, 0));
- PUTS(tparm(set_right_margin_parm, columns - 1));
- } else if (clear_margins != NULL && set_left_margin != NULL
- && set_right_margin != NULL) {
- PUTS(clear_margins);
- if (carriage_return != NULL) {
- PUTS(carriage_return);
- } else {
- PUTCHAR('\r');
- }
- PUTS(set_left_margin);
- if (parm_right_cursor) {
- PUTS(tparm(parm_right_cursor, columns - 1));
- } else {
- for(i = 0; i < columns - 1; i++) {
- PUTCHAR(' ');
- }
- }
- PUTS(set_right_margin);
- if (carriage_return != NULL) {
- PUTS(carriage_return);
- } else {
- PUTCHAR('\r');
- }
- }
- FLUSH;
-
- if (init_tabs != 8) {
- if (clear_all_tabs != NULL && set_tab != NULL) {
- for(i = 0; i < columns - 1; i += 8) {
- if (parm_right_cursor) {
- PUTS(tparm(parm_right_cursor, 8));
- } else {
- for(j = 0; j < 8; j++)
- PUTCHAR(' ');
- }
- PUTS(set_tab);
- }
- FLUSH;
- }
- }
-
- if (reset && reset_file != NULL) {
- f = fopen(reset_file, "r");
- if (f == NULL) {
- quit(errno, "Can't open reset_file: '%s'", reset_file);
- }
- while((c = fgetc(f)) != EOF) {
- PUTCHAR(c);
- }
- fclose(f);
- } else if (init_file != NULL) {
- f = fopen(init_file, "r");
- if (f == NULL) {
- quit(errno, "Can't open init_file: '%s'", init_file);
- }
- while((c = fgetc(f)) != EOF) {
- PUTCHAR(c);
- }
- fclose(f);
+static int
+exit_code(int token, int value)
+{
+ int result = 99;
+
+ switch (token) {
+ case BOOLEAN:
+ result = !value; /* TRUE=0, FALSE=1 */
+ break;
+ case NUMBER:
+ result = 0; /* always zero */
+ break;
+ case STRING:
+ result = value; /* 0=normal, 1=missing */
+ break;
+ }
+ return result;
+}
+
+static int
+tput(int argc, char *argv[])
+{
+ NCURSES_CONST char *name;
+ char *s;
+ int i, j, c;
+ int status;
+ FILE *f;
+#if !PURE_TERMINFO
+ bool termcap = FALSE;
+#endif
+
+ if ((name = argv[0]) == 0)
+ name = "";
+ check_aliases(name);
+ if (is_reset || is_init) {
+ if (init_prog != 0) {
+ system(init_prog);
+ }
+ FLUSH;
+
+ if (is_reset && reset_1string != 0) {
+ PUTS(reset_1string);
+ } else if (init_1string != 0) {
+ PUTS(init_1string);
+ }
+ FLUSH;
+
+ if (is_reset && reset_2string != 0) {
+ PUTS(reset_2string);
+ } else if (init_2string != 0) {
+ PUTS(init_2string);
+ }
+ FLUSH;
+
+#ifdef set_lr_margin
+ if (set_lr_margin != 0) {
+ PUTS(TPARM_2(set_lr_margin, 0, columns - 1));
+ } else
+#endif
+#ifdef set_left_margin_parm
+ if (set_left_margin_parm != 0
+ && set_right_margin_parm != 0) {
+ PUTS(TPARM_1(set_left_margin_parm, 0));
+ PUTS(TPARM_1(set_right_margin_parm, columns - 1));
+ } else
+#endif
+ if (clear_margins != 0
+ && set_left_margin != 0
+ && set_right_margin != 0) {
+ PUTS(clear_margins);
+ if (carriage_return != 0) {
+ PUTS(carriage_return);
+ } else {
+ PUTCHAR('\r');
+ }
+ PUTS(set_left_margin);
+ if (parm_right_cursor) {
+ PUTS(TPARM_1(parm_right_cursor, columns - 1));
+ } else {
+ for (i = 0; i < columns - 1; i++) {
+ PUTCHAR(' ');