termtest.c revision 26edd082186aa8164c586ad6fab094c56f59cb67
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <termio.h>
#include <stdlib.h>
#include <errno.h>
#include "wish.h"
#define BREAK 0
#define CASE 1
#define END 2
#define EXIT 3
#define PRINT 4
#define QUERY 5
#define UNKNOWN 6
#define NUMTOKENS 6
#define ARGSIZ 128
#define MAXSEQ 256
char *get_response(char *);
char *strnsave(char *, unsigned int);
void proc_file(char *);
void debug_out(bool, char *, char *);
void output(char *);
void initialize(void);
char Withbs[] = "\b\f\n\r \t\\\33";
char Woutbs[] = "bfnrst\\E";
int Retval;
int Debug;
int Level;
int Tok;
struct SR {
char *send;
char *recv;
int Num_used;
/* general purpose interrupt catcher */
void
intr(int n)
{
}
void
{
if (sig)
}
int
{
int i;
Retval = 1;
for (i = 0; i < 2; i++) {
if (i && Debug)
puts("Trying again...");
(void) get_response(NULL);
}
if (Retval)
return (Retval);
}
/*
* interprets an identify file
*/
void
{
char path[512];
return;
Level = 0;
return;
Retval = 0;
}
/*
* gets a string and returns static buffer
* expands "$0" to expand string
*/
char *
{
char *p;
char *s;
int c;
/* skip white space, comments */
while (isspace(c))
if (c == '#') {
while (c != EOF && c != '\n')
}
else
break;
}
/* collect string up to white space */
s = buf;
/* remove backslashes */
if (c == '\\') {
else if (isdigit(c)) {
int ac;
c -= '0';
else
}
else
}
}
else if (c == '$') {
/* expand $0 */
s += strlen(s);
continue;
}
*s++ = '$';
}
*s++ = c;
break;
}
*s = '\0';
if (c != EOF)
return buf;
}
/*
* get string and tokenize it
*/
int
get_token(void)
{
char *s;
int i;
s = get_string(NULL);
if (s[0] == '\0')
for (i = 0; i < NUMTOKENS; i++)
return Tok = i;
}
/*
* interpreter - executes 1 statement and returns
* expects a token to be preread into Tok
*/
void
{
char *s = NULL;
switch (Tok) {
case QUERY:
s = get_string(NULL);
if (!skip)
s = get_response(s);
Level++;
Level--;
return;
}
break;
case CASE:
return;
case EOF:
return;
case BREAK:
if (!skip) {
if (s) {
Level--;
Level++;
return;
}
else
}
break;
case PRINT:
s = get_string(arg);
if (!skip)
puts(s);
break;
case EXIT:
if (!skip)
cleanup(0);
break;
default:
break;
}
get_token();
}
/* case statement */
/*ARGSUSED*/
void
{
char *s;
char *ex;
int i;
bool fail;
for (i = 0; i < 10; i++)
newarg[i][0] = '\0';
s = get_string(NULL);
Level++;
if (!skip) {
if (recv) {
char *regex();
char *regcmp();
cleanup(2);
}
}
else
}
Level--;
}
/* print debugging info */
void
{
int i;
if (!Debug)
return;
for (i = 0; i < Level; i++)
putchar('\t');
if (skip)
if (s2) {
putchar(' ');
putchar('\'');
putchar('\'');
}
putchar('\n');
}
/* print a string "nicely" */
void
output(char *s)
{
while (*s) {
if (isprint(*s))
putchar(*s);
else if (*s < ' ') {
putchar('^');
putchar(*s + '@');
}
else {
putchar('\\');
if (*s & 0300)
if (*s & 0370)
}
s++;
}
}
/* query the terminal and return response */
char *
get_response(char *s)
{
char *recv;
char recvbuf[512];
char *rcvptr;
int numread;
char *lookup();
char *enter();
if (s == NULL || *s == '\0') {
initialize();
return s;
}
else {
if (Debug)
rcvptr++;
*rcvptr = '\0';
Level = 0;
}
return recv;
}
/*
* if we've already used this query, return what the response was
*/
char *
lookup(char *s)
{
int i;
for (i = 0; i < Num_used; i++)
return NULL;
}
/*
*/
char *
enter(char *s, char *r)
{
return strsave(r);
}
/*
* clear out the used sequences array, so we can try a second time
* to query the terminal
*/
void
initialize(void)
{
Num_used = 0;
}
char *
{
char *p;
return NULL;
p[len] = '\0';
return p;
}