📄 panelprocs.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)panelprocs.c 1.40 91/04/09 Copyright Sun Micro";#endif/* * Copyright (c) 1987 by Sun Microsystems, Inc. */#include "sundiag.h"#include <sys/stat.h>#include <sys/dir.h>#include <sys/file.h>#include <fcntl.h>#include <vfork.h>#include "struct.h"#include "procs.h"#include "sundiag_msg.h"int running=IDLE; /* to keep the system status */int selection_flag=TRUE;extern char *malloc();extern char *strcpy();extern char *sprintf();extern FILE *fopen();extern time_t time();extern Panel_item test_item; /* defined in panel.c */extern Pixrect *start_button, *stop_button; /* defined in panel.c */extern Pixrect *reset_button, *suspend_button;extern Pixrect *resume_button;extern Pixrect *ttime_button, *ttime_button_org; /* defined in panel.c */extern Pixrect *options_button, *options_button_org;extern Pixrect *opf_button, *opf_button_org;extern Pixrect *eeprom_button, *eeprom_button_org;extern Pixrect *cpu_button, *cpu_button_org;/* forward references */extern frame_destroy_proc();extern load_option_files();extern store_option_files();extern list_option_files();extern remove_option_files();static Frame display_frame=NULL;static Textsw display_sw=NULL;static char *cur_logname=" ";static Frame of_frame=NULL;static Panel of_panel;static Panel_item core_item;static Panel_item single_item;static Panel_item quick_item;static Panel_item verbose_item;static Panel_item trace_item;static Panel_item auto_item;static Panel_item run_error_item;static Panel_item max_passes_item;static Panel_item max_errors_item;static Panel_item max_tests_item;static Panel_item email_item;static Panel_item address_item;static Panel_item log_period_item;static Panel_item printer_name_item;static Panel_item of_fname_item;static Frame o_frame=NULL;static Panel o_panel;static short gray25[4] = { /* 25 % gray pattern */ 0x8888, 0x2222, 0x4444, 0x1111};static mpr_static(gray25_pr, 16, 4, 1, gray25);/****************************************************************************** * Grays out the image of the button on the screen. * * Input: ip, the handle of the button to be grayed. * ******************************************************************************/static gray_button(ip)Panel_item ip;{ Pixrect *image_mpr; image_mpr = (Pixrect *)panel_get(ip, PANEL_LABEL_IMAGE); /* gray out the button label */ (void)pr_replrop(image_mpr, 0, 0, image_mpr->pr_width, image_mpr->pr_height, PIX_SRC | PIX_DST, (Pixrect *)(LINT_CAST(&gray25_pr)), 0, 0); (void)panel_paint(ip, PANEL_NO_CLEAR);}/****************************************************************************** * Grays out all the buttons which are not accessible while the tests are * * running(i.e. the System status is "testing"). * ******************************************************************************/static gray_all_buttons(){ gray_button(ttime_item); gray_button(options_item); gray_button(option_files_item); if (strcmp(cpuname, "SPARCsystem 600 MP")) { gray_button(eeprom_item); } gray_button(cpu_item);}/****************************************************************************** * Un-grays all the buttons which are not accessible while the tests are * * running(i.e. the System status is "testing"). * ******************************************************************************/light_all_buttons(){ (void)pr_rop(ttime_button, 0, 0, ttime_button->pr_width, ttime_button->pr_height, PIX_SRC, ttime_button_org, 0, 0); (void)pr_rop(options_button, 0, 0, ttime_button->pr_width, ttime_button->pr_height, PIX_SRC, options_button_org, 0, 0); (void)pr_rop(opf_button, 0, 0, ttime_button->pr_width, ttime_button->pr_height, PIX_SRC, opf_button_org, 0, 0); if (strcmp(cpuname, "SPARCsystem 600 MP")) { (void)pr_rop(eeprom_button, 0, 0, ttime_button->pr_width, ttime_button->pr_height, PIX_SRC, eeprom_button_org, 0, 0); } (void)pr_rop(cpu_button, 0, 0, ttime_button->pr_width, ttime_button->pr_height, PIX_SRC, cpu_button_org, 0, 0); (void)panel_paint(ttime_item, PANEL_CLEAR); (void)panel_paint(options_item, PANEL_CLEAR); (void)panel_paint(option_files_item, PANEL_CLEAR); if (strcmp(cpuname, "SPARCsystem 600 MP")) { (void)panel_paint(eeprom_item, PANEL_CLEAR); } (void)panel_paint(cpu_item, PANEL_CLEAR);}/****************************************************************************** * Notify procedure for "Start Tests" button. * ******************************************************************************/extern int vmem_wait; /* defined in tests.c */extern int fb_delay; /* defined in tests.c */start_proc(){ disable_batch(); /* disable batch processing for now */ if (running != IDLE) { (void)confirm("Already started testing!", TRUE); return; } vmem_wait = 0; /* initialize the vmem wait counter */ fb_delay = 0; /* initialize the frame buffer delay */ time_display(); /* redisplay the "Elapsed Time" */ last_elapse = (long)time((time_t *)0); /* get the current time of the day */ running = GO; status_display(); logmsg(start_all_info, 1, START_ALL_INFO); /* *** start all tests *** */ log_status(); /* also log current status to information file */ if (tty_mode) return; /* that's it for TTY mode */ if (o_frame != NULL) /* close the system option popup if it was opened */ frame_destroy_proc(o_frame); if (of_frame != NULL) /* close the option file popup if it was opened */ frame_destroy_proc(of_frame); (void)panel_set(test_item, PANEL_LABEL_IMAGE, stop_button, PANEL_NOTIFY_PROC, stop_proc, 0); (void)panel_set(reset_item, PANEL_LABEL_IMAGE, suspend_button, PANEL_NOTIFY_PROC, suspend_proc, 0); gray_all_buttons(); /* Gray out the unaccessible buttons */} /****************************************************************************** * Notify procedure for "Stop Tests" button. * ******************************************************************************/stop_proc(){ disable_batch(); /* disable batch processing for now */ if (running != GO && running != SUSPEND && running != KILL) { (void)confirm("No tests are running!", TRUE); return; } if (running == GO || running == KILL) { elapse_count += (int)time((time_t *)0) - last_elapse; /* increment the elapsed seconds */ (void)time_display(); /* display elapse time on status subwindow */ } kill_all_tests(); /* kill all tests before quiting */ status_display(); logmsg(stop_all_info, 1, STOP_ALL_INFO); /* *** Stop all tests *** */} /****************************************************************************** * Notify procedure for "Reset" button. * * Note: the "Reset" button will be disabled when tests are running. * ******************************************************************************/reset_proc(){ int test_id; if (running != IDLE) { (void)confirm("Can't reset while running tests!", TRUE); return; } for (test_id=0; test_id != exist_tests; ++test_id) { tests[test_id]->pass = 0; tests[test_id]->error = 0; } logmsg(reset_pecount_info, 1, RESET_PECOUNT_INFO); /* *** Reset pass/error counts *** */ elapse_count = 0; /* also reset the elaspse counter */ time_display(); /* update it on screen too */ print_status(); /* refresh the status */}/****************************************************************************** * log_print(), prints the specified log file. * ******************************************************************************/static int lpr_object;static int *lpr_handle = &lpr_object;/*ARGSUSED*/static void log_print(filename)char *filename;{ char buff[162]; int pid; (void)sprintf(buff, "fold %s | lpr -p -P%s -T %s", filename, printer_name, filename); if ((pid=vfork()) == 0) /* child */ { (void)execl("/bin/csh", "csh", "-c", buff, (char *)0); _exit(127); } if (pid != -1) /* succeeded */ (void)notify_set_wait3_func((Notify_client)lpr_handle, notify_default_wait3, pid);}/****************************************************************************** * Notify procedure for "Log Files" button. * ******************************************************************************/static char *unix_msg="/usr/adm/messages";static char *unix_msg1="/usr/adm/messages.0";static char *unix_msg2="/usr/adm/messages.1";static char *unix_tmp_msg="/tmp/unix.msg";static display_log(); /* forward reference */static append_text(); /* forward reference */log_files_menu_proc(item, event)Panel_item item;Event *event;{ int log_file_action; FILE *tmp; if (event_id(event) == MS_LEFT && event_is_down(event)) { display_log(error_file); /* left button to display ERROR log */ cur_logname = error_file; (void)window_set(display_frame, FRAME_LABEL, cur_logname, WIN_SHOW, TRUE, 0); } else if (event_id(event) == MS_RIGHT && event_is_down(event)) { log_file_action = (int)menu_show(log_files_menu, sundiag_control, event, 0); /* display the menu */ switch(log_file_action) { case 1: /* display ERROR log file */ display_log(error_file); cur_logname = error_file; (void)window_set(display_frame, FRAME_LABEL, cur_logname, WIN_SHOW, TRUE, 0); break; case 2: /* remove ERROR log file */ if (confirm_yes("OK to remove sundiag error logs?")) { (void)fclose(error_fp); if (unlink(error_file) != 0) perror("unlink(error_file)"); error_fp = fopen(error_file, "a"); if (strcmp(cur_logname, error_file) == 0) (void)window_set((Frame)display_sw, TEXTSW_FILE, error_file, 0); /* reopen(in case it was opened now) */ } break; case 3: /* print ERROR log file */ log_print(error_file); break; case 4: /* display INFO log file */ display_log(info_file); cur_logname = info_file; (void)window_set(display_frame, FRAME_LABEL, cur_logname, WIN_SHOW, TRUE, 0); break; case 5: /* remove INFO log file */ if (confirm_yes("OK to remove sundiag information logs?")) { (void)fclose(info_fp); if (unlink(info_file) != 0) perror("unlink(info_file)"); info_fp = fopen(info_file, "a"); if (strcmp(cur_logname, info_file) == 0) (void)window_set((Frame)display_sw, TEXTSW_FILE, info_file, 0); /* reopen(in case it was opened now) */ } break; case 6: /* print INFO log file */ log_print(info_file); break; case 7: /* display UNIX log file */ if (access(unix_msg, F_OK) != 0) /* not exist */ if ((tmp=fopen(unix_msg, "a")) != NULL) (void)fclose(tmp); /* create it */ display_log(unix_msg); cur_logname = unix_msg; (void)window_set(display_sw, TEXTSW_INSERTION_POINT, 0, 0); (void)window_set(display_sw, TEXTSW_INSERT_FROM_FILE, unix_msg2, TEXTSW_INSERT_FROM_FILE, unix_msg1, 0); (void)unlink(unix_tmp_msg); (void)textsw_store_file(display_sw, unix_tmp_msg, 0, 0); (void)unlink(unix_tmp_msg); (void)window_set(display_frame, FRAME_LABEL, unix_tmp_msg, WIN_SHOW, TRUE, 0); break; case 8: /* remove UNIX log file */ if (confirm_yes("OK to remove Unix logs?")) { (void)unlink(unix_msg1); (void)unlink(unix_msg2); (void)unlink(unix_tmp_msg); tmp = fopen(unix_msg, "w"); fclose(tmp); if (strcmp(cur_logname, unix_msg) == 0) (void)window_set((Frame)display_sw, TEXTSW_FILE, unix_tmp_msg, 0); /* reopen(in case it was opened now) */ } break; case 9: /* print UNIX log file */ log_print(unix_msg); break; } } else (void)panel_default_handle_event(item, event);}/****************************************************************************** * Displays(shows) the specified log file in the popup text subwindow. * * Input: log_name, the name of the log file to be displayed. * ******************************************************************************/static display_log(log_name)char *log_name;{ if (display_sw == (Textsw)NULL) /* if the text subwindow was not created yet */ { display_frame = window_create(sundiag_frame, FRAME, FRAME_SHOW_LABEL, TRUE, WIN_X, (int)(STATUS_WIDTH*frame_width)+15, WIN_Y, 40, 0); display_sw = (Textsw)window_create(display_frame, TEXTSW, WIN_WIDTH, ATTR_COLS(80), WIN_HEIGHT, ATTR_ROWS(32), 0); window_fit(display_frame); } /* always reopen the file for TEXT subwindow */ (void)window_set((Frame)display_sw, TEXTSW_FILE, log_name, TEXTSW_FIRST, 0, 0);}/****************************************************************************** * append_text(), appends the contents of the passed file into the TEXT * * subwindow(display_sw). * * input: the name of the file to be appended. * ******************************************************************************/static append_text(filename)char *filename;{ int fd, count; char read_buf[514]; if ((fd=open(filename, O_RDONLY)) == -1) return; (void)window_set(display_sw, TEXTSW_INSERTION_POINT, TEXTSW_INFINITY, 0); while ((count=read(fd, read_buf, 512)) == 512) (void)textsw_insert(display_sw, read_buf, 512); if (count != 0) (void)textsw_insert(display_sw, read_buf, count); (void)close(fd);}/****************************************************************************** * Notify procedure for "Option Files" button. * ******************************************************************************//***** forward references *****/static Panel_setting fname_proc();static done_option_files();/*ARGSUSED*/option_files_proc(item, event)Panel_item item;Event *event;{ if (running == GO) return; /* not accessible when testing */ /* o_frame & of_frame can't be up at the same time */ if (o_frame != NULL) frame_destroy_proc(o_frame); of_frame = window_create(sundiag_frame, FRAME,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -