⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdrtns.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lintstatic  char sccsid[] = "@(#)sdrtns.c	1.1  7/30/92 Copyright Sun Micro"; #endif/****************************************************************************** * sdrtns.c								      * *									      * * Purpose: Sundiag interface routines to be used by all the Sundiag test *          codes. * Routines: *	    int  process_sundiag_args(argc, argv, index) *	    void send_message(ret_code, msg_type, format[, arg]...) *	    void exception(sig, code, scp, addr) *	    void finish() *	    void display_usage(rtn_usage) *	    void standard_usage() *          void test_init(argc, argv, process_test_args, routine_usage,                         test_usage_msg) *          void test_end() *	    void check_usage(routine_usage) *	    void check_coredump() ******************************************************************************/#include <stdio.h>#include <sys/types.h>#include <sys/time.h>#include <errno.h>#include <signal.h>#ifdef	 SVR4#include <sys/siginfo.h>#endif	 SVR4#include <varargs.h>#include <ctype.h>#include "sdrtns.h"#include "testnames.h"#include "../../lib/include/libonline.h"/* external variables going to be used by sundiag */int	single_pass = FALSE;int	core_file = FALSE;int	verbose = FALSE;int	quick_test = FALSE;int	run_on_error = FALSE;int	exec_by_sundiag = FALSE;int     list_usage = FALSE;int     debug = FALSE;int	trace = FALSE;int	trace_level = 0;int	test_error = 0;char	*func_name = "unknown_function";char    *hostname=NULL;char	*device_name="unknown_device";char	*test_name="unknown_test";/* external functions  for this routine sdrtns.c */#ifndef	SVR4extern	char	*sprintf();#endif	SVR4/* static variables only used in routine sdrtns.c */static  char  msg_buf[MESSAGE_SIZE];static  char    *argstr;static  va_list  arg_ptr;static  int      argint;static  double   argdouble;/****************************************************************************** * process_sundiag_args(), searchs for the sundiag-specific command line      * * arguments and set the corresponding variables.			      * * Input: argc and argv, command line arguments.			      * *	  index, pointer to the index of the argument to be checked.	      * * Output: TRUE, if matched; otherwise FALSE.				      * ******************************************************************************/int process_sundiag_args(argc, argv, index)int	argc;char	*argv[];int	*index;		/* pointer to the index of the argument to be checked */{    char  *arg;    arg = argv[*index];    if (strcmp(arg, "s") == 0)		/* is currently executed by SUndiag */	exec_by_sundiag = TRUE;    else if (strcmp(arg, "v") == 0)	/* should be run in verbose mode */	verbose = TRUE;    else if (strcmp(arg, "q") == 0)	/* should be run in quick(short) mode */	quick_test = TRUE;    else if (strcmp(arg, "r") == 0)	/* should be run_on_error */	run_on_error = TRUE;    else if (strcmp(arg, "p") == 0)	/* run only one internal pass */	single_pass = TRUE;    else if (strcmp(arg, "c") == 0)	/* catch signal to prevent core dump */	core_file = TRUE;    else if (strcmp(arg, "u") == 0)	/* list commamnd usage */	list_usage = TRUE;    else if (strcmp(arg, "d") == 0)    /* debug mode set up */	debug = TRUE;    else if (strcmp(arg, "t") == 0)     /* trace mode */	trace = TRUE;    else if (strcmp(arg, "h") == 0)	/* send messages to specified host */    {      if (*index+1 < argc)        hostname = argv[++(*index)];	/* get the hostname and increment the index */      else   	return(FALSE);			/* no hostname right after h */    }    else	return(FALSE);			/* none matched */    return(TRUE);			/* at least one of the above matched */}/****************************************************************************** * send_message(exit_code, type, format[, arg]...), the message handler       * *              for sundiag tests. It also checks verbose/debug flag to 		eliminate the work in test codes. * Input: *         int exit_code: the exit code to be used when exiting(if != 0).     * *	   int type:      the mesage type, could be one of INFO, WARNING, 			  FATAL, ERROR, CONSOLE, LOGFILE, VERBOSE, DEBUG,			  TRACE, and VERBOSE+DEBUG or DEBUG+VERBOSE ( it			  means VERBOSE or DEBUG). 			  Note: any undefined type will be treated as VERBOSE 			  if d or v are set at command line, otherwise no 			  message will be sent. *	   char *format:  same as format of printf;   * Output: none.							      * * Note: the entire process will exit from here if ret_code != 0.	      * ******************************************************************************/void send_message (exit_code, type, va_alist)int exit_code;int type;va_dcl{    char    *control;    char    *msg;    extern char *control_parse();    int	    send_flag = FALSE;    static int	cleanup_flag = FALSE;     va_start(arg_ptr);    control = va_arg(arg_ptr, char *);    msg = control_parse (control);    va_end(arg_ptr);     error_base = 0;    switch (type) {	/* verbose has formatted message, debug not */	case INFO:		error_base = 7000;		/* for sundiag mode only */		send_flag = TRUE;		break;	case WARNING:		error_base = 5000;		/* for sundiag mode only */		send_flag = TRUE;		break;	case FATAL:		error_base = 3000;		/* for sundiag mode only */		send_flag = TRUE;		break;	case ERROR:		error_base = 9000;		/* for sundiag mode only */		send_flag = TRUE;		test_error++;			/* increment error count */		break;	case LOGFILE:	case CONSOLE:		send_flag = TRUE;		break;        case VERBOSE:           /* verbose has formatted message, debug not */		send_flag = (verbose)? TRUE : FALSE;                break;        case DEBUG:		send_flag = (debug)? TRUE : FALSE;                break;            case TRACE:		send_flag = (trace)? TRUE : FALSE;                break;	case VERBOSE+DEBUG:	default:		if (verbose || debug) {			send_flag = TRUE;			type = VERBOSE;		}    } /* end of switch; send it over to the server by RPC */    if (send_flag) send_rpc_msg(exit_code, type, msg);    if (exit_code != 0) {    			/* exit from here */         if (!cleanup_flag) {	   cleanup_flag = TRUE;                /* only one is allowed */           clean_up();                         /* clean up the mess first */ 	}        exit(exit_code);    }}static char *control_parse(control_str)char *control_str;{   char *msgptr;   static char msg[MESSAGE_SIZE];   extern char *strip_sym();   extern char *strcat();   msgptr = &msg[0];         while (*control_str != NULL) {        if (*control_str == '%') {            *msgptr = NULL;	    if (*(control_str+1) == '%') {		control_str++; 		control_str++; 		strcat (msg, "%");	    }	    else                strcat (msg, strip_sym(&control_str));            msgptr = msg + strlen(msg);        }   /* end of if(*control_str) */        else           *msgptr++ = *control_str++;   } /* end of while */   *msgptr = NULL;   return (msg);}static char *strip_sym(strptr)char **strptr;{     char  pattern[10], *pattern_ptr;     static char  buf[50];     char  *string;     string = *strptr;     pattern_ptr = &pattern[0];     while (!isalpha(*string)) {           *pattern_ptr++ = *string++;           ++(*strptr);     }     ++(*strptr);     *pattern_ptr++ = *string;     *pattern_ptr = NULL;               /* end the string */     switch (*string) {                                                 case 'd':           case 'i':           case 'o':           case 'u':           case 'x':           case 'c':                      argint = va_arg(arg_ptr, int);                      sprintf(buf, pattern, argint);                      break;           case 'f':           case 'e':           case 'E':           case 'G':           case 'g':                      argdouble = va_arg(arg_ptr, double);                      sprintf(buf, pattern, argdouble);                      break;           case 's':                      argstr = va_arg(arg_ptr, char *);                      sprintf(buf, pattern, argstr);                      break;           default:                      argint = va_arg(arg_ptr, int);                      sprintf(buf, pattern, argint);     } /* end of switch */     return (buf);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -