17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5de81e71eSTim Marsland * Common Development and Distribution License (the "License"). 6de81e71eSTim Marsland * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21de81e71eSTim Marsland 227c478bd9Sstevel@tonic-gate /* 23de81e71eSTim Marsland * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * tput - print terminal attribute 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * return-codes - command line arguments: 347c478bd9Sstevel@tonic-gate * 0: ok if boolean capname -> TRUE 357c478bd9Sstevel@tonic-gate * 1: for boolean capname -> FALSE 367c478bd9Sstevel@tonic-gate * 377c478bd9Sstevel@tonic-gate * return-codes - standard input arguments: 387c478bd9Sstevel@tonic-gate * 0: ok; tput for all lines was successful 397c478bd9Sstevel@tonic-gate * 407c478bd9Sstevel@tonic-gate * return-codes - both cases: 417c478bd9Sstevel@tonic-gate * 2 usage error 427c478bd9Sstevel@tonic-gate * 3 bad terminal type given or no terminfo database 437c478bd9Sstevel@tonic-gate * 4 unknown capname 447c478bd9Sstevel@tonic-gate * -1 capname is a numeric variable that is not specified in the 457c478bd9Sstevel@tonic-gate * terminfo database(E.g. tpu -T450 lines). 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * tput printfs a value if an INT capname was given; e.g. cols. 487c478bd9Sstevel@tonic-gate * putp's a string if a STRING capname was given; e.g. clear. and 497c478bd9Sstevel@tonic-gate * for BOOLEAN capnames, e.g. hard-copy, just returns the boolean value. 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <curses.h> 537c478bd9Sstevel@tonic-gate #include <term.h> 547c478bd9Sstevel@tonic-gate #include <fcntl.h> 557c478bd9Sstevel@tonic-gate #include <ctype.h> 567c478bd9Sstevel@tonic-gate #include <stdlib.h> 577c478bd9Sstevel@tonic-gate #include <string.h> 587c478bd9Sstevel@tonic-gate #include <sys/types.h> 597c478bd9Sstevel@tonic-gate #include <unistd.h> 607c478bd9Sstevel@tonic-gate #include <locale.h> 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* externs from libcurses */ 637c478bd9Sstevel@tonic-gate extern int tigetnum(); 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate static int outputcap(char *cap, int argc, char **argv); 667c478bd9Sstevel@tonic-gate static int allnumeric(char *string); 677c478bd9Sstevel@tonic-gate static int getpad(char *cap); 687c478bd9Sstevel@tonic-gate static void setdelay(); 697c478bd9Sstevel@tonic-gate static void settabs(); 707c478bd9Sstevel@tonic-gate static void cat(char *file); 717c478bd9Sstevel@tonic-gate static void initterm(); 727c478bd9Sstevel@tonic-gate static void reset_term(); 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate static char *progname; /* argv[0] */ 757c478bd9Sstevel@tonic-gate static int CurrentBaudRate; /* current baud rate */ 767c478bd9Sstevel@tonic-gate static int reset = 0; /* called as reset_term */ 777c478bd9Sstevel@tonic-gate static int fildes = 1; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate int 807c478bd9Sstevel@tonic-gate main(int argc, char **argv) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate int i, std_argc; 837c478bd9Sstevel@tonic-gate char *term = getenv("TERM"); 847c478bd9Sstevel@tonic-gate char *cap, std_input = FALSE; 857c478bd9Sstevel@tonic-gate int setuperr; 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 887c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 897c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 907c478bd9Sstevel@tonic-gate #endif 917c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate progname = argv[0]; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "ST:")) != EOF) { 967c478bd9Sstevel@tonic-gate switch (i) { 977c478bd9Sstevel@tonic-gate case 'T': 987c478bd9Sstevel@tonic-gate fildes = -1; 997c478bd9Sstevel@tonic-gate (void) putenv("LINES="); 1007c478bd9Sstevel@tonic-gate (void) putenv("COLUMNS="); 1017c478bd9Sstevel@tonic-gate term = optarg; 1027c478bd9Sstevel@tonic-gate break; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate case 'S': 1057c478bd9Sstevel@tonic-gate std_input = TRUE; 1067c478bd9Sstevel@tonic-gate break; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate case '?': /* FALLTHROUGH */ 1097c478bd9Sstevel@tonic-gate usage: /* FALLTHROUGH */ 1107c478bd9Sstevel@tonic-gate default: 1117c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext( 112de81e71eSTim Marsland "usage:\t%s [-T [term]] capname " 113de81e71eSTim Marsland "[parm argument...]\n"), progname); 1147c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("OR:\t%s -S <<\n"), 1157c478bd9Sstevel@tonic-gate progname); 1167c478bd9Sstevel@tonic-gate exit(2); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate if (!term || !*term) { 1217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1227c478bd9Sstevel@tonic-gate gettext("%s: No value for $TERM and no -T specified\n"), 1237c478bd9Sstevel@tonic-gate progname); 1247c478bd9Sstevel@tonic-gate exit(2); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate (void) setupterm(term, fildes, &setuperr); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate switch (setuperr) { 1307c478bd9Sstevel@tonic-gate case -2: 1317c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1327c478bd9Sstevel@tonic-gate gettext("%s: unreadable terminal descriptor \"%s\"\n"), 1337c478bd9Sstevel@tonic-gate progname, term); 1347c478bd9Sstevel@tonic-gate exit(3); 1357c478bd9Sstevel@tonic-gate break; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate case -1: 1387c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1397c478bd9Sstevel@tonic-gate gettext("%s: no terminfo database\n"), progname); 1407c478bd9Sstevel@tonic-gate exit(3); 1417c478bd9Sstevel@tonic-gate break; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate case 0: 1447c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1457c478bd9Sstevel@tonic-gate gettext("%s: unknown terminal \"%s\"\n"), 1467c478bd9Sstevel@tonic-gate progname, term); 1477c478bd9Sstevel@tonic-gate exit(3); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate reset_shell_mode(); 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* command line arguments */ 1537c478bd9Sstevel@tonic-gate if (!std_input) { 1547c478bd9Sstevel@tonic-gate if (argc == optind) 1557c478bd9Sstevel@tonic-gate goto usage; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate cap = argv[optind++]; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate if (strcmp(cap, "init") == 0) 1607c478bd9Sstevel@tonic-gate initterm(); 1617c478bd9Sstevel@tonic-gate else if (strcmp(cap, "reset") == 0) 1627c478bd9Sstevel@tonic-gate reset_term(); 1637c478bd9Sstevel@tonic-gate else if (strcmp(cap, "longname") == 0) 1647c478bd9Sstevel@tonic-gate (void) printf("%s\n", longname()); 1657c478bd9Sstevel@tonic-gate else 1667c478bd9Sstevel@tonic-gate exit(outputcap(cap, argc, argv)); 1677c478bd9Sstevel@tonic-gate return (0); 1687c478bd9Sstevel@tonic-gate } else { /* standard input argumets */ 169*e1c8dda0SGarrett D'Amore char buff[128]; 1707c478bd9Sstevel@tonic-gate char **v; 1717c478bd9Sstevel@tonic-gate 172*e1c8dda0SGarrett D'Amore /* allocate storage for the 'faked' argv[] array */ 1737c478bd9Sstevel@tonic-gate v = (char **)malloc(10 * sizeof (char *)); 174*e1c8dda0SGarrett D'Amore for (i = 0; i < 10; i++) 175*e1c8dda0SGarrett D'Amore v[i] = (char *)malloc(32 * sizeof (char)); 1767c478bd9Sstevel@tonic-gate 177*e1c8dda0SGarrett D'Amore while (gets(buff) != NULL) { 1787c478bd9Sstevel@tonic-gate /* read standard input line; skip over empty lines */ 1797c478bd9Sstevel@tonic-gate if ((std_argc = 1807c478bd9Sstevel@tonic-gate sscanf(buff, "%s %s %s %s %s %s %s %s %s %s", 1817c478bd9Sstevel@tonic-gate v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], 1827c478bd9Sstevel@tonic-gate v[8], v[9])) < 1) { 1837c478bd9Sstevel@tonic-gate continue; 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate cap = v[0]; 1877c478bd9Sstevel@tonic-gate optind = 1; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate if (strcmp(cap, "init") == 0) { 1907c478bd9Sstevel@tonic-gate initterm(); 1917c478bd9Sstevel@tonic-gate } else if (strcmp(cap, "reset") == 0) { 1927c478bd9Sstevel@tonic-gate reset_term(); 1937c478bd9Sstevel@tonic-gate } else if (strcmp(cap, "longname") == 0) { 1947c478bd9Sstevel@tonic-gate (void) printf("%s\n", longname()); 1957c478bd9Sstevel@tonic-gate } else { 1967c478bd9Sstevel@tonic-gate (void) outputcap(cap, std_argc, v); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate (void) fflush(stdout); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate return (0); 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate static long parm[9] = { 2067c478bd9Sstevel@tonic-gate 0, 0, 0, 0, 0, 0, 0, 0, 0 2077c478bd9Sstevel@tonic-gate }; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate static int 2107c478bd9Sstevel@tonic-gate outputcap(char *cap, int argc, char **argv) 2117c478bd9Sstevel@tonic-gate { 2127c478bd9Sstevel@tonic-gate int parmset = 0; 2137c478bd9Sstevel@tonic-gate char *thisstr; 2147c478bd9Sstevel@tonic-gate int i; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate if ((i = tigetflag(cap)) >= 0) 2177c478bd9Sstevel@tonic-gate return (1 - i); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate if ((i = tigetnum(cap)) >= -1) { 2207c478bd9Sstevel@tonic-gate (void) printf("%d\n", i); 2217c478bd9Sstevel@tonic-gate return (0); 2227c478bd9Sstevel@tonic-gate } 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate if ((thisstr = tigetstr(cap)) != (char *)-1) { 2257c478bd9Sstevel@tonic-gate if (!thisstr) { 2267c478bd9Sstevel@tonic-gate return (1); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate for (parmset = 0; optind < argc; optind++, parmset++) 2297c478bd9Sstevel@tonic-gate if (allnumeric(argv[optind])) 2307c478bd9Sstevel@tonic-gate parm[parmset] = atoi(argv[optind]); 2317c478bd9Sstevel@tonic-gate else 2327c478bd9Sstevel@tonic-gate parm[parmset] = (int)argv[optind]; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate if (parmset) 2357c478bd9Sstevel@tonic-gate putp(tparm(thisstr, 236de81e71eSTim Marsland parm[0], parm[1], parm[2], parm[3], 237de81e71eSTim Marsland parm[4], parm[5], parm[6], parm[7], parm[8])); 2387c478bd9Sstevel@tonic-gate else 2397c478bd9Sstevel@tonic-gate putp(thisstr); 2407c478bd9Sstevel@tonic-gate return (0); 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2447c478bd9Sstevel@tonic-gate gettext("%s: unknown terminfo capability '%s'\n"), progname, cap); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate exit(4); 2477c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate /* 2517c478bd9Sstevel@tonic-gate * The decision as to whether an argument is a number or not is to simply 2527c478bd9Sstevel@tonic-gate * look at whether there are any non-digits in the string. 2537c478bd9Sstevel@tonic-gate */ 2547c478bd9Sstevel@tonic-gate static int 2557c478bd9Sstevel@tonic-gate allnumeric(char *string) 2567c478bd9Sstevel@tonic-gate { 2577c478bd9Sstevel@tonic-gate if (*string) { 2587c478bd9Sstevel@tonic-gate while (*string) { 2597c478bd9Sstevel@tonic-gate if (!isdigit(*string++)) { 2607c478bd9Sstevel@tonic-gate return (0); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate return (1); 2647c478bd9Sstevel@tonic-gate } else { 2657c478bd9Sstevel@tonic-gate return (0); 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate /* 2707c478bd9Sstevel@tonic-gate * SYSTEM DEPENDENT TERMINAL DELAY TABLES 2717c478bd9Sstevel@tonic-gate * 2727c478bd9Sstevel@tonic-gate * These tables maintain the correspondence between the delays 2737c478bd9Sstevel@tonic-gate * defined in terminfo and the delay algorithms in the tty driver 2747c478bd9Sstevel@tonic-gate * on the particular systems. For each type of delay, the bits used 2757c478bd9Sstevel@tonic-gate * for that delay must be specified, in XXbits, and a table 2767c478bd9Sstevel@tonic-gate * must be defined giving correspondences between delays and 2777c478bd9Sstevel@tonic-gate * algorithms. Algorithms which are not fixed delays, such 2787c478bd9Sstevel@tonic-gate * as dependent on current column or line number, must be 2797c478bd9Sstevel@tonic-gate * kludged in some way at this time. 2807c478bd9Sstevel@tonic-gate * 2817c478bd9Sstevel@tonic-gate * Some of this was taken from tset(1). 2827c478bd9Sstevel@tonic-gate */ 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate struct delay 2857c478bd9Sstevel@tonic-gate { 2867c478bd9Sstevel@tonic-gate int d_delay; 2877c478bd9Sstevel@tonic-gate int d_bits; 2887c478bd9Sstevel@tonic-gate }; 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate /* The appropriate speeds for various termio settings. */ 2917c478bd9Sstevel@tonic-gate static int speeds[] = { 2927c478bd9Sstevel@tonic-gate 0, /* B0, */ 2937c478bd9Sstevel@tonic-gate 50, /* B50, */ 2947c478bd9Sstevel@tonic-gate 75, /* B75, */ 2957c478bd9Sstevel@tonic-gate 110, /* B110, */ 2967c478bd9Sstevel@tonic-gate 134, /* B134, */ 2977c478bd9Sstevel@tonic-gate 150, /* B150, */ 2987c478bd9Sstevel@tonic-gate 200, /* B200, */ 2997c478bd9Sstevel@tonic-gate 300, /* B300, */ 3007c478bd9Sstevel@tonic-gate 600, /* B600, */ 3017c478bd9Sstevel@tonic-gate 1200, /* B1200, */ 3027c478bd9Sstevel@tonic-gate 1800, /* B1800, */ 3037c478bd9Sstevel@tonic-gate 2400, /* B2400, */ 3047c478bd9Sstevel@tonic-gate 4800, /* B4800, */ 3057c478bd9Sstevel@tonic-gate 9600, /* B9600, */ 3067c478bd9Sstevel@tonic-gate 19200, /* EXTA, */ 3077c478bd9Sstevel@tonic-gate 38400, /* EXTB, */ 3087c478bd9Sstevel@tonic-gate 57600, /* B57600, */ 3097c478bd9Sstevel@tonic-gate 76800, /* B76800, */ 3107c478bd9Sstevel@tonic-gate 115200, /* B115200, */ 3117c478bd9Sstevel@tonic-gate 153600, /* B153600, */ 3127c478bd9Sstevel@tonic-gate 230400, /* B230400, */ 3137c478bd9Sstevel@tonic-gate 307200, /* B307200, */ 3147c478bd9Sstevel@tonic-gate 460800, /* B460800, */ 315de81e71eSTim Marsland 921600, /* B921600, */ 3167c478bd9Sstevel@tonic-gate 0, 3177c478bd9Sstevel@tonic-gate }; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate #if defined(SYSV) || defined(USG) 3207c478bd9Sstevel@tonic-gate /* Unix 3.0 on up */ 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* Carriage Return delays */ 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate static int CRbits = CRDLY; 3257c478bd9Sstevel@tonic-gate static struct delay CRdelay[] = 3267c478bd9Sstevel@tonic-gate { 3277c478bd9Sstevel@tonic-gate 0, CR0, 3287c478bd9Sstevel@tonic-gate 80, CR1, 3297c478bd9Sstevel@tonic-gate 100, CR2, 3307c478bd9Sstevel@tonic-gate 150, CR3, 3317c478bd9Sstevel@tonic-gate -1 3327c478bd9Sstevel@tonic-gate }; 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate /* New Line delays */ 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate static int NLbits = NLDLY; 3377c478bd9Sstevel@tonic-gate static struct delay NLdelay[] = 3387c478bd9Sstevel@tonic-gate { 3397c478bd9Sstevel@tonic-gate 0, NL0, 3407c478bd9Sstevel@tonic-gate 100, NL1, 3417c478bd9Sstevel@tonic-gate -1 3427c478bd9Sstevel@tonic-gate }; 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* Back Space delays */ 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate static int BSbits = BSDLY; 3477c478bd9Sstevel@tonic-gate static struct delay BSdelay[] = 3487c478bd9Sstevel@tonic-gate { 3497c478bd9Sstevel@tonic-gate 0, BS0, 3507c478bd9Sstevel@tonic-gate 50, BS1, 3517c478bd9Sstevel@tonic-gate -1 3527c478bd9Sstevel@tonic-gate }; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate /* TaB delays */ 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate static int TBbits = TABDLY; 3577c478bd9Sstevel@tonic-gate static struct delay TBdelay[] = 3587c478bd9Sstevel@tonic-gate { 3597c478bd9Sstevel@tonic-gate 0, TAB0, 3607c478bd9Sstevel@tonic-gate 11, TAB1, /* special M37 delay */ 3617c478bd9Sstevel@tonic-gate 100, TAB2, 3627c478bd9Sstevel@tonic-gate /* TAB3 is XTABS and not a delay */ 3637c478bd9Sstevel@tonic-gate -1 3647c478bd9Sstevel@tonic-gate }; 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* Form Feed delays */ 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate static int FFbits = FFDLY; 3697c478bd9Sstevel@tonic-gate static struct delay FFdelay[] = 3707c478bd9Sstevel@tonic-gate { 3717c478bd9Sstevel@tonic-gate 0, FF0, 3727c478bd9Sstevel@tonic-gate 2000, FF1, 3737c478bd9Sstevel@tonic-gate -1 3747c478bd9Sstevel@tonic-gate }; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate #else /* BSD */ 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate /* Carriage Return delays */ 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate int CRbits = CRDELAY; 3817c478bd9Sstevel@tonic-gate struct delay CRdelay[] = 3827c478bd9Sstevel@tonic-gate { 3837c478bd9Sstevel@tonic-gate 0, CR0, 3847c478bd9Sstevel@tonic-gate 9, CR3, 3857c478bd9Sstevel@tonic-gate 80, CR1, 3867c478bd9Sstevel@tonic-gate 160, CR2, 3877c478bd9Sstevel@tonic-gate -1 3887c478bd9Sstevel@tonic-gate }; 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate /* New Line delays */ 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate int NLbits = NLDELAY; 3937c478bd9Sstevel@tonic-gate struct delay NLdelay[] = 3947c478bd9Sstevel@tonic-gate { 3957c478bd9Sstevel@tonic-gate 0, NL0, 3967c478bd9Sstevel@tonic-gate 66, NL1, /* special M37 delay */ 3977c478bd9Sstevel@tonic-gate 100, NL2, 3987c478bd9Sstevel@tonic-gate -1 3997c478bd9Sstevel@tonic-gate }; 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate /* Tab delays */ 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate int TBbits = TBDELAY; 4047c478bd9Sstevel@tonic-gate struct delay TBdelay[] = 4057c478bd9Sstevel@tonic-gate { 4067c478bd9Sstevel@tonic-gate 0, TAB0, 4077c478bd9Sstevel@tonic-gate 11, TAB1, /* special M37 delay */ 4087c478bd9Sstevel@tonic-gate -1 4097c478bd9Sstevel@tonic-gate }; 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate /* Form Feed delays */ 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate int FFbits = VTDELAY; 4147c478bd9Sstevel@tonic-gate struct delay FFdelay[] = 4157c478bd9Sstevel@tonic-gate { 4167c478bd9Sstevel@tonic-gate 0, FF0, 4177c478bd9Sstevel@tonic-gate 2000, FF1, 4187c478bd9Sstevel@tonic-gate -1 4197c478bd9Sstevel@tonic-gate }; 4207c478bd9Sstevel@tonic-gate #endif /* BSD */ 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /* 4237c478bd9Sstevel@tonic-gate * Initterm, a.k.a. reset_term, does terminal specific initialization. In 4247c478bd9Sstevel@tonic-gate * particular, the init_strings from terminfo are output and tabs are 4257c478bd9Sstevel@tonic-gate * set, if they aren't hardwired in. Much of this stuff was done by 4267c478bd9Sstevel@tonic-gate * the tset(1) program. 4277c478bd9Sstevel@tonic-gate */ 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate /* 4307c478bd9Sstevel@tonic-gate * Figure out how many milliseconds of padding the capability cap 4317c478bd9Sstevel@tonic-gate * needs and return that number. Padding is stored in the string as "$<n>", 4327c478bd9Sstevel@tonic-gate * where n is the number of milliseconds of padding. More than one 4337c478bd9Sstevel@tonic-gate * padding string is allowed within the string, although this is unlikely. 4347c478bd9Sstevel@tonic-gate */ 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate static int 4377c478bd9Sstevel@tonic-gate getpad(char *cap) 4387c478bd9Sstevel@tonic-gate { 4397c478bd9Sstevel@tonic-gate int padding = 0; 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate /* No padding needed at speeds below padding_baud_rate */ 4427c478bd9Sstevel@tonic-gate if (padding_baud_rate > CurrentBaudRate || cap == NULL) 4437c478bd9Sstevel@tonic-gate return (0); 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate while (*cap) { 4467c478bd9Sstevel@tonic-gate if ((cap[0] == '$') && (cap[1] == '<')) { 4477c478bd9Sstevel@tonic-gate cap++; 4487c478bd9Sstevel@tonic-gate cap++; 4497c478bd9Sstevel@tonic-gate padding += atoi(cap); 4507c478bd9Sstevel@tonic-gate while (isdigit (*cap)) 4517c478bd9Sstevel@tonic-gate cap++; 4527c478bd9Sstevel@tonic-gate while (*cap == '.' || *cap == '/' || *cap == '*' || 4537c478bd9Sstevel@tonic-gate isdigit(*cap)) 4547c478bd9Sstevel@tonic-gate cap++; 4557c478bd9Sstevel@tonic-gate while (*cap == '>') 4567c478bd9Sstevel@tonic-gate cap++; 4577c478bd9Sstevel@tonic-gate } else { 4587c478bd9Sstevel@tonic-gate cap++; 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate return (padding); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate /* 4667c478bd9Sstevel@tonic-gate * Set the appropriate delay bits in the termio structure for 4677c478bd9Sstevel@tonic-gate * the given delay. 4687c478bd9Sstevel@tonic-gate */ 4697c478bd9Sstevel@tonic-gate static void 4707c478bd9Sstevel@tonic-gate setdelay(delay, delaytable, bits, flags) 4717c478bd9Sstevel@tonic-gate register int delay; 4727c478bd9Sstevel@tonic-gate struct delay delaytable[]; 4737c478bd9Sstevel@tonic-gate int bits; 4747c478bd9Sstevel@tonic-gate #ifdef SYSV 4757c478bd9Sstevel@tonic-gate tcflag_t *flags; 4767c478bd9Sstevel@tonic-gate #else /* SYSV */ 4777c478bd9Sstevel@tonic-gate unsigned short *flags; 4787c478bd9Sstevel@tonic-gate #endif /* SYSV */ 4797c478bd9Sstevel@tonic-gate { 4807c478bd9Sstevel@tonic-gate register struct delay *p; 4817c478bd9Sstevel@tonic-gate register struct delay *lastdelay; 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate /* Clear out the bits, replace with new ones */ 4847c478bd9Sstevel@tonic-gate *flags &= ~bits; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* Scan the delay table for first entry with adequate delay */ 4877c478bd9Sstevel@tonic-gate for (lastdelay = p = delaytable; 4887c478bd9Sstevel@tonic-gate (p -> d_delay >= 0) && (p -> d_delay < delay); 4897c478bd9Sstevel@tonic-gate p++) { 4907c478bd9Sstevel@tonic-gate lastdelay = p; 4917c478bd9Sstevel@tonic-gate } 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* use last entry if none will do */ 4947c478bd9Sstevel@tonic-gate *flags |= lastdelay -> d_bits; 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate /* 4987c478bd9Sstevel@tonic-gate * Set the hardware tabs on the terminal, using clear_all_tabs, 4997c478bd9Sstevel@tonic-gate * set_tab, and column_address capabilities. Cursor_address and cursor_right 5007c478bd9Sstevel@tonic-gate * may also be used, if necessary. 5017c478bd9Sstevel@tonic-gate * This is done before the init_file and init_3string, so they can patch in 5027c478bd9Sstevel@tonic-gate * case we blow this. 5037c478bd9Sstevel@tonic-gate */ 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate static void 5067c478bd9Sstevel@tonic-gate settabs() 5077c478bd9Sstevel@tonic-gate { 5087c478bd9Sstevel@tonic-gate register int c; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /* Do not set tabs if they power up properly. */ 5117c478bd9Sstevel@tonic-gate if (init_tabs == 8) 5127c478bd9Sstevel@tonic-gate return; 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate if (set_tab) { 5157c478bd9Sstevel@tonic-gate /* Force the cursor to be at the left margin. */ 5167c478bd9Sstevel@tonic-gate if (carriage_return) 5177c478bd9Sstevel@tonic-gate putp(carriage_return); 5187c478bd9Sstevel@tonic-gate else 5197c478bd9Sstevel@tonic-gate (void) putchar('\r'); 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate /* Clear any current tab settings. */ 5227c478bd9Sstevel@tonic-gate if (clear_all_tabs) 5237c478bd9Sstevel@tonic-gate putp(clear_all_tabs); 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate /* Set the tabs. */ 5267c478bd9Sstevel@tonic-gate for (c = 8; c < columns; c += 8) { 5277c478bd9Sstevel@tonic-gate /* Get to that column. */ 5287c478bd9Sstevel@tonic-gate (void) fputs(" ", stdout); 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate /* Set the tab. */ 5317c478bd9Sstevel@tonic-gate putp(set_tab); 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate /* Get back to the left column. */ 5357c478bd9Sstevel@tonic-gate if (carriage_return) 5367c478bd9Sstevel@tonic-gate putp(carriage_return); 5377c478bd9Sstevel@tonic-gate else 5387c478bd9Sstevel@tonic-gate (void) putchar('\r'); 5397c478bd9Sstevel@tonic-gate 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate /* 5447c478bd9Sstevel@tonic-gate * Copy "file" onto standard output. 5457c478bd9Sstevel@tonic-gate */ 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate static void 5487c478bd9Sstevel@tonic-gate cat(file) 5497c478bd9Sstevel@tonic-gate char *file; /* File to copy. */ 5507c478bd9Sstevel@tonic-gate { 5517c478bd9Sstevel@tonic-gate register int fd; /* File descriptor. */ 5527c478bd9Sstevel@tonic-gate register ssize_t i; /* Number characters read. */ 5537c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; /* Buffer to read into. */ 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate fd = open(file, O_RDONLY); 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate if (fd < 0) { 5587c478bd9Sstevel@tonic-gate perror("Cannot open initialization file"); 5597c478bd9Sstevel@tonic-gate } else { 5607c478bd9Sstevel@tonic-gate while ((i = read(fd, buf, BUFSIZ)) > (ssize_t)0) 5617c478bd9Sstevel@tonic-gate (void) write(fileno(stdout), buf, (unsigned)i); 5627c478bd9Sstevel@tonic-gate (int)close(fd); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate /* 5677c478bd9Sstevel@tonic-gate * Initialize the terminal. 5687c478bd9Sstevel@tonic-gate * Send the initialization strings to the terminal. 5697c478bd9Sstevel@tonic-gate */ 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate static void 5727c478bd9Sstevel@tonic-gate initterm() 5737c478bd9Sstevel@tonic-gate { 5747c478bd9Sstevel@tonic-gate register int filedes; /* File descriptor for ioctl's. */ 5757c478bd9Sstevel@tonic-gate #if defined(SYSV) || defined(USG) 5767c478bd9Sstevel@tonic-gate struct termio termmode; /* To hold terminal settings. */ 5777c478bd9Sstevel@tonic-gate struct termios termmodes; /* To hold terminal settings. */ 5787c478bd9Sstevel@tonic-gate int i; 5797c478bd9Sstevel@tonic-gate int istermios = -1; 5807c478bd9Sstevel@tonic-gate #define GTTY(fd, mode) ioctl(fd, TCGETA, mode) 5817c478bd9Sstevel@tonic-gate #define GTTYS(fd, mode) \ 5827c478bd9Sstevel@tonic-gate (istermios = ioctl(fd, TCGETS, mode)) 5837c478bd9Sstevel@tonic-gate #define STTY(fd, mode) ioctl(fd, TCSETAW, mode) 5847c478bd9Sstevel@tonic-gate #define STTYS(fd, mode) ioctl(fd, TCSETSW, mode) 5857c478bd9Sstevel@tonic-gate #define SPEED(mode) (mode.c_cflag & CBAUD) 5867c478bd9Sstevel@tonic-gate #define SPEEDS(mode) (cfgetospeed(&mode)) 5877c478bd9Sstevel@tonic-gate #define OFLAG(mode) mode.c_oflag 5887c478bd9Sstevel@tonic-gate #else /* BSD */ 5897c478bd9Sstevel@tonic-gate struct sgttyb termmode; /* To hold terminal settings. */ 5907c478bd9Sstevel@tonic-gate #define GTTY(fd, mode) gtty(fd, mode) 5917c478bd9Sstevel@tonic-gate #define STTY(fd, mode) stty(fd, mode) 5927c478bd9Sstevel@tonic-gate #define SPEED(mode) (mode.sg_ospeed & 017) 5937c478bd9Sstevel@tonic-gate #define OFLAG(mode) mode.sg_flags 5947c478bd9Sstevel@tonic-gate #define TAB3 XTABS 5957c478bd9Sstevel@tonic-gate #endif 5967c478bd9Sstevel@tonic-gate 5977c478bd9Sstevel@tonic-gate /* Get the terminal settings. */ 5987c478bd9Sstevel@tonic-gate /* First try standard output, then standard error, */ 5997c478bd9Sstevel@tonic-gate /* then standard input, then /dev/tty. */ 6007c478bd9Sstevel@tonic-gate #ifdef SYSV 6017c478bd9Sstevel@tonic-gate if ((filedes = 1, GTTYS(filedes, &termmodes) < 0) || 6027c478bd9Sstevel@tonic-gate (filedes = 2, GTTYS(filedes, &termmodes) < 0) || 6037c478bd9Sstevel@tonic-gate (filedes = 0, GTTYS(filedes, &termmodes) < 0) || 6047c478bd9Sstevel@tonic-gate (filedes = open("/dev/tty", O_RDWR), 6057c478bd9Sstevel@tonic-gate GTTYS(filedes, &termmodes) < 0)) { 6067c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6077c478bd9Sstevel@tonic-gate if ((filedes = 1, GTTY(filedes, &termmode) == -1) || 6087c478bd9Sstevel@tonic-gate (filedes = 2, GTTY(filedes, &termmode) == -1) || 6097c478bd9Sstevel@tonic-gate (filedes = 0, GTTY(filedes, &termmode) == -1) || 6107c478bd9Sstevel@tonic-gate (filedes = open("/dev/tty", O_RDWR), 6117c478bd9Sstevel@tonic-gate GTTY(filedes, &termmode) == -1)) { 6127c478bd9Sstevel@tonic-gate filedes = -1; 6137c478bd9Sstevel@tonic-gate CurrentBaudRate = speeds[B1200]; 6147c478bd9Sstevel@tonic-gate } else 6157c478bd9Sstevel@tonic-gate CurrentBaudRate = speeds[SPEED(termmode)]; 6167c478bd9Sstevel@tonic-gate #ifdef SYSV 6177c478bd9Sstevel@tonic-gate termmodes.c_lflag = termmode.c_lflag; 6187c478bd9Sstevel@tonic-gate termmodes.c_oflag = termmode.c_oflag; 6197c478bd9Sstevel@tonic-gate termmodes.c_iflag = termmode.c_iflag; 6207c478bd9Sstevel@tonic-gate termmodes.c_cflag = termmode.c_cflag; 6217c478bd9Sstevel@tonic-gate for (i = 0; i < NCC; i++) 6227c478bd9Sstevel@tonic-gate termmodes.c_cc[i] = termmode.c_cc[i]; 6237c478bd9Sstevel@tonic-gate } else 6247c478bd9Sstevel@tonic-gate CurrentBaudRate = speeds[SPEEDS(termmodes)]; 6257c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate if (xon_xoff) { 6287c478bd9Sstevel@tonic-gate #ifdef SYSV 6297c478bd9Sstevel@tonic-gate OFLAG(termmodes) &= 6307c478bd9Sstevel@tonic-gate ~(NLbits | CRbits | BSbits | FFbits | TBbits); 6317c478bd9Sstevel@tonic-gate #else /* SYSV */ 6327c478bd9Sstevel@tonic-gate OFLAG(termmode) &= 6337c478bd9Sstevel@tonic-gate ~(NLbits | CRbits | BSbits | FFbits | TBbits); 6347c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6357c478bd9Sstevel@tonic-gate } else { 6367c478bd9Sstevel@tonic-gate #ifdef SYSV 637de81e71eSTim Marsland setdelay(getpad(carriage_return), 638de81e71eSTim Marsland CRdelay, CRbits, &OFLAG(termmodes)); 639de81e71eSTim Marsland setdelay(getpad(scroll_forward), 640de81e71eSTim Marsland NLdelay, NLbits, &OFLAG(termmodes)); 641de81e71eSTim Marsland setdelay(getpad(cursor_left), 642de81e71eSTim Marsland BSdelay, BSbits, &OFLAG(termmodes)); 643de81e71eSTim Marsland setdelay(getpad(form_feed), 644de81e71eSTim Marsland FFdelay, FFbits, &OFLAG(termmodes)); 645de81e71eSTim Marsland setdelay(getpad(tab), 646de81e71eSTim Marsland TBdelay, TBbits, &OFLAG(termmodes)); 6477c478bd9Sstevel@tonic-gate #else /* SYSV */ 648de81e71eSTim Marsland setdelay(getpad(carriage_return), 649de81e71eSTim Marsland CRdelay, CRbits, &OFLAG(termmode)); 650de81e71eSTim Marsland setdelay(getpad(scroll_forward), 651de81e71eSTim Marsland NLdelay, NLbits, &OFLAG(termmode)); 652de81e71eSTim Marsland setdelay(getpad(cursor_left), 653de81e71eSTim Marsland BSdelay, BSbits, &OFLAG(termmode)); 654de81e71eSTim Marsland setdelay(getpad(form_feed), 655de81e71eSTim Marsland FFdelay, FFbits, &OFLAG(termmode)); 656de81e71eSTim Marsland setdelay(getpad(tab), 657de81e71eSTim Marsland TBdelay, TBbits, &OFLAG(termmode)); 6587c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate /* If tabs can be sent to the tty, turn off their expansion. */ 6627c478bd9Sstevel@tonic-gate if (tab && set_tab || init_tabs == 8) { 6637c478bd9Sstevel@tonic-gate #ifdef SYSV 6647c478bd9Sstevel@tonic-gate OFLAG(termmodes) &= ~(TAB3); 6657c478bd9Sstevel@tonic-gate #else /* SYSV */ 6667c478bd9Sstevel@tonic-gate OFLAG(termmode) &= ~(TAB3); 6677c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6687c478bd9Sstevel@tonic-gate } else { 6697c478bd9Sstevel@tonic-gate #ifdef SYSV 6707c478bd9Sstevel@tonic-gate OFLAG(termmodes) |= TAB3; 6717c478bd9Sstevel@tonic-gate #else /* SYSV */ 6727c478bd9Sstevel@tonic-gate OFLAG(termmode) |= TAB3; 6737c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate /* Do the changes to the terminal settings */ 6777c478bd9Sstevel@tonic-gate #ifdef SYSV 6787c478bd9Sstevel@tonic-gate if (istermios < 0) { 6797c478bd9Sstevel@tonic-gate int i; 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate termmode.c_lflag = termmodes.c_lflag; 6827c478bd9Sstevel@tonic-gate termmode.c_oflag = termmodes.c_oflag; 6837c478bd9Sstevel@tonic-gate termmode.c_iflag = termmodes.c_iflag; 6847c478bd9Sstevel@tonic-gate termmode.c_cflag = termmodes.c_cflag; 6857c478bd9Sstevel@tonic-gate for (i = 0; i < NCC; i++) 6867c478bd9Sstevel@tonic-gate termmode.c_cc[i] = termmodes.c_cc[i]; 6877c478bd9Sstevel@tonic-gate (void) STTY(filedes, &termmode); 6887c478bd9Sstevel@tonic-gate } else 6897c478bd9Sstevel@tonic-gate (void) STTYS(filedes, &termmodes); 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate #else /* SYSV */ 6927c478bd9Sstevel@tonic-gate (void) STTY(filedes, &termmode); 6937c478bd9Sstevel@tonic-gate #endif /* SYSV */ 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate /* Send first initialization strings. */ 6967c478bd9Sstevel@tonic-gate if (init_prog) 6977c478bd9Sstevel@tonic-gate (void) system(init_prog); 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate if (reset && reset_1string) { 7007c478bd9Sstevel@tonic-gate putp(reset_1string); 7017c478bd9Sstevel@tonic-gate } else if (init_1string) { 7027c478bd9Sstevel@tonic-gate putp(init_1string); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate if (reset && reset_2string) { 7067c478bd9Sstevel@tonic-gate putp(reset_2string); 7077c478bd9Sstevel@tonic-gate } else if (init_2string) { 7087c478bd9Sstevel@tonic-gate putp(init_2string); 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate /* Set up the tabs stops. */ 7127c478bd9Sstevel@tonic-gate settabs(); 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate /* Send out initializing file. */ 7157c478bd9Sstevel@tonic-gate if (reset && reset_file) { 7167c478bd9Sstevel@tonic-gate cat(reset_file); 7177c478bd9Sstevel@tonic-gate } else if (init_file) { 7187c478bd9Sstevel@tonic-gate cat(init_file); 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate /* Send final initialization strings. */ 7227c478bd9Sstevel@tonic-gate if (reset && reset_3string) { 7237c478bd9Sstevel@tonic-gate putp(reset_3string); 7247c478bd9Sstevel@tonic-gate } else if (init_3string) { 7257c478bd9Sstevel@tonic-gate putp(init_3string); 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if (carriage_return) { 7297c478bd9Sstevel@tonic-gate putp(carriage_return); 7307c478bd9Sstevel@tonic-gate } else { 7317c478bd9Sstevel@tonic-gate (void) putchar('\r'); 7327c478bd9Sstevel@tonic-gate } 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate /* Send color initialization strings */ 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate if (orig_colors) 7377c478bd9Sstevel@tonic-gate putp(orig_colors); 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate if (orig_pair) 7407c478bd9Sstevel@tonic-gate putp(orig_pair); 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate /* Let the terminal settle down. */ 7437c478bd9Sstevel@tonic-gate (void) fflush(stdout); 7447c478bd9Sstevel@tonic-gate (void) sleep(1); 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate static void 7487c478bd9Sstevel@tonic-gate reset_term() 7497c478bd9Sstevel@tonic-gate { 7507c478bd9Sstevel@tonic-gate reset++; 7517c478bd9Sstevel@tonic-gate initterm(); 7527c478bd9Sstevel@tonic-gate } 753