#ifndef lint
static char sccsid[] = "@(#)tty.c 1.1 92/07/30 Copyright Sun Micro";
#endif
/*
* Copyright (c) 1987 by Sun Microsystems, Inc.
*/
#include <curses.h>
#include "sundiag.h"
#include "struct.h"
#include "tty.h"
#include <ctype.h>
#include <signal.h>
#include <fcntl.h>
#ifdef sun4
#include <mon/idprom.h>
#endif
/* global's */
WINDOW *tty_control[TTY_WINNO];/* control windows,up to TTY_WINNO pages each */
WINDOW *tty_status[TTY_WINNO]; /* status windows, up to TTY_WINNO pages each */
WINDOW *tty_option=NULL; /* option window(share just one ) */
WINDOW *tty_other=NULL; /* other window(share just one) */
WINDOW *control_button=NULL; /* the window to display command button */
WINDOW *status_button=NULL; /* the window to display test status */
WINDOW *console_tty=NULL; /* console/error message window(to draw box) */
WINDOW *message_tty=NULL; /* console/error message subwindow */
int tty_ppid=0; /* the parent pid of the sundiag */
int window_type=CONTROL_TTY;/* type of window currently displayed */
int control_index; /* index of current control window displayed */
int status_index; /* index of current status window displayed */
int control_max; /* the max. index of control windows(#-1) */
int status_max; /* the max. index of status windows(#-1) */
int status_page; /* current status page */
int status_row; /* current status row */
char *arg[20]; /* up to 20 command line arguments */
int arg_no; /* number of arguments available */
char com_line[82]; /* the image of the command line(NULL-terminated) */
/* external's */
extern char *build_sel_label(); /* in tests.c */
extern char get_com(); /* in ttyprocs.c */
extern char *strtok();
extern char *sprintf();
extern Notify_value kill_proc(); /* in sundiag.c */
extern Panel init_opt_panel();
/* static's */
static int command_row; /* the row to put the command promt */
static int message_row; /* the row to put the error message */
static char kill_char; /* the line kill character */
static char del_char; /* the character erase character */
static int status_lines; /* number of lines available for test status */
static int other_type; /* who is using the "other window"(see below) */
#define OTHER_OPTION 1
#define OTHER_OPFILE 2
#define OTHER_LOGFILE 3
#define OTHER_EEPROM 4
#define OTHER_SCHEDULE 5
#define OTHER_PROCESSORS 6
/* forward declarations */
extern switch_to_control();
static switch_to_status();
static struct com_tbl control_tbl1[]=
{
{"start", 's'},
{"options", 'o'},
{"logfiles", 'l'},
{"status", 'a'},
{"optfiles", 'f'},
{"stop", 't'},
{"quit", 'q'},
{"reset", 'r'},
{"suspend", 'p'},
{"resume", 'u'},
{"eeprom", 'e'},
{"schedule", 'm'},
{"processors", 'c'},
{"intervention", 'i'},
{"help", 'h'},
{"next", 'n'},
{"", '\0'}
};
static struct com_tbl control_tbl2[]=
{
{"tests", 'c'},
{"", '\0'}
};
static struct com_tbl control_tbl3[]=
{
{"default", 'd'},
{"all", 'a'},
{"none", 'n'},
{"", '\0'}
};
static struct com_tbl status_tbl[]=
{
{"done", 'd'},
{"next", 'n'},
{"help", 'h'},
{"", '\0'}
};
static struct com_tbl popup_tbl[]=
{
{"default", 'f'},
{"done", 'd'},
{"help", 'h'},
{"", '\0'}
};
/******************************************************************************
* init_tty_control(), initializes all the control windows needed. *
******************************************************************************/
static init_tty_control()
{
int lines; /* # of lines available for displaying tests */
int pages;
int group; /* current group id(index to groups[] */
int cur_test_i; /* current test index(to tests[]) */
int select_v;
int which_line;
char temp_buf[82];
lines = LINES-12;
for (pages=0, cur_test_i=0, group= -1; pages < TTY_WINNO; ++pages)
{
tty_control[pages] = newwin(lines, COLS-2, 8, 1);
if (cur_test_i == exist_tests) break; /* done */
for (which_line=0; which_line != lines; ++which_line)
{
if (tests[cur_test_i]->group != group)
{
group = tests[cur_test_i]->group;
groups[group].first = cur_test_i;
/* keep the first test in the group */
(void)mvwaddstr(tty_control[pages], which_line++,
16, groups[group].c_label);
if (which_line == lines) /* hit the end */
{
if (pages+1 == TTY_WINNO) break; /* use up */
tty_control[++pages] = newwin(lines, COLS-2, 8, 1);
which_line = 0;
}
}
if (tests[cur_test_i]->which_test == 1)
{
if (tests[cur_test_i]->test_no > 1) /* multiple tests */
{
if (tests[cur_test_i]->type != 2)
/* it is not a disabled intervention tests */
select_v = tests[cur_test_i]->dev_enable;
else
select_v = FALSE;
}
else
select_v = (tests[cur_test_i]->enable && tests[cur_test_i]->type!=2);
(void)sprintf(temp_buf, "%s%-30s%s", select_v?"->":" ",
build_sel_label(cur_test_i),
tests[cur_test_i]->popup?"[OPTION]":"");
(void)mvwaddstr(tty_control[pages], which_line, TEST_COL, temp_buf);
tests[cur_test_i]->select = (Panel_item)(which_line | (pages << 8));
}
else
--which_line; /* reuse this line */
if (++cur_test_i == exist_tests) break; /* no more */
}
if (cur_test_i == exist_tests) break; /* done */
}
control_max = pages;
control_button = newwin(5, COLS-2, 3, 1);
(void)sprintf(temp_buf, "[%s] [%s] [%s] [%s] [%s] [%s] [%s]", "START",
"OPTIONS", "STATUS", "SCHEDULE", "OPTFILES", "STOP", "QUIT");
(void)mvwaddstr(control_button, 0, 4, temp_buf);
(void)sprintf(temp_buf, "[%s] [%s] [%s] [%s] [%s] [%s] [%s]", "RESET",
"SUSPEND", "RESUME", " EEPROM ", "LOGFILES", "HELP", "NEXT");
(void)mvwaddstr(control_button, 1, 4, temp_buf);
(void)sprintf(temp_buf, "[%s]", "PROCESSORS");
(void)mvwaddstr(control_button, 2, 4, temp_buf);
(void)sprintf(temp_buf, "[INTERVENTION]: %-18s [TESTS]: %-20s",
intervention?"Enable":"Disable",
select_value!=0?
(select_value>1?"ALL [DEFAULT/NONE]":"NONE [ALL/DEFAULT]"):
"DEFAULT [NONE/ALL]");
(void)mvwaddstr(control_button, 3, 6, temp_buf);
}
/******************************************************************************
* get_next_page(), set/initialize next available status page. *
******************************************************************************/
get_next_page()
{
if (status_row >= status_lines)
{
++status_page;
status_row = 0;
if (tty_status[status_page] == NULL) /* not created yet */
tty_status[status_page] = newwin(status_lines, COLS-2, 6, 1);
(void)wclear(tty_status[status_page]);
}
}
/******************************************************************************
* init_tty_option(), initializes the option window. *
******************************************************************************/
static init_tty_option()
{
tty_option = newwin(LINES-7, COLS-2, 3, 1);
(void)wclear(tty_option);
}
/******************************************************************************
* init_tty_other(), initializes the other window. *
******************************************************************************/
static init_tty_other()
{
tty_other = newwin(LINES-7, COLS-2, 3, 1);
(void)wclear(tty_other);
}
/******************************************************************************
* init_tty_status(), initializes status_button and console_tty windows. *
******************************************************************************/
static init_tty_status()
{
status_button = newwin(2, COLS-2, 3, 1);
(void)wclear(status_button);
(void)mvwaddstr(status_button, 0, SYS_PASS_COL, "[NEXT] [DONE] [HELP]");
/* command to go back to control window */
time_display(); /* initilaize the "Elapsed time" couter */
console_tty = newwin(6, COLS-2, LINES-10, 1);
/* this window is opened just for displaying the "box" */
box(console_tty, '|', '-');
mvwaddch(console_tty, 0, 0, ' ');
mvwaddch(console_tty, 0, COLS-3, ' ');
mvwaddch(console_tty, 5, 0, ' ');
mvwaddch(