env.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A * Note log_emit gathers up characters and issues a syslog or write to 2N/A * error log file if enabled. 2N/A }
else if (c ==
'\r')
2N/A if ((c >=
0x20 && c <=
0x7f) || c ==
'\n' || c ==
'\r' ||
2N/A * 'key?' - abort if stdin is not a tty. 2N/A * 'key' - abort if stdin is not a tty, will block on read if char not avail. 2N/A int cwidth;
/* column width specified in format */ 2N/A * Called by fmt_str() function to validate and extract formatting 2N/A * information from the supplied input buffer. 2N/A * Supported formats are: 2N/A * %d - signed decimal 2N/A * %ld - signed 64 bit data 2N/A * %lx - unsigned 64 bit data 2N/A * %p - unsigned 64 bit data(pointer) 2N/A * %% - print as single "%" character 2N/A * Return values are: 2N/A * 0 - valid formatting 2N/A * 1 - invalid formatting found in the input buffer 2N/A * -1 - NULL pointer passed in for caller's receptacle 2N/A * For valid formatting, caller's supplied cmn_fmt_t elements are 2N/A * > 0 - returned value is the field width 2N/A * < 0 - returned value is negation of field width for 2N/A * 64 bit data formats 2N/A * formatted column width(if specified), otherwise 0 2N/A * contains the formatting(single) character 2N/A /* check for left justification character */ 2N/A /* check for column width specification */ 2N/A /* if ljust specified w/o size, return format error */ 2N/A /* check for column width specification */ 2N/A /* if a column width was specified, save it in caller's struct */ 2N/A /* if too many digits in the width return error */ 2N/A /* check for long format specifier */ 2N/A /* process by specific format type */ 2N/A return (
1);
/* unknown format type */ 2N/A * Called by fmt_str() to setup arguments for subsequent snprintf() 2N/A * calls. For cases not involving column width limitations, processing 2N/A * simply POPs the data stack as required to setup caller's arg(or 2N/A * llarg, as appropriate). When a column width is specified for output, 2N/A * a temporary buffer is constructed to contain snprintf() generated 2N/A * output for the argument. Testing is then performed to determine if 2N/A * the specified column width will require truncation of the output. 2N/A * If so, truncation of least significant digits is performed as 2N/A * necessary, and caller's arg(or llarg) is adjusted to obtain the 2N/A * specified column width. 2N/A if (
fw > 0) {
/* check for normal (not long) formats */ 2N/A /* initialize format string for snprintf call */ 2N/A /* process by format type */ 2N/A "fmt_args:invalid format type! (%s)\n",
2N/A /* check if a column width was specified */ 2N/A /* allocate a scratch buffer */ 2N/A "fmt_args: snprintf output error\n");
2N/A /* if truncation is necessary, do it */ 2N/A }
else {
/* process long formats */ 2N/A /* check if a column width was specified */ 2N/A /* allocate a scratch buffer */ 2N/A "fmt_args: snprintf error\n");
2N/A "fmt_args: snprintf error\n");
2N/A "fmt_args: snprintf error\n");
2N/A "invalid long format type! (l%s)\n",
2N/A /* if truncation is necessary, do it */ 2N/A * Extracts text from caller's input buffer, processes explicit 2N/A * formatting as necessary, and outputs formatted text to caller's 2N/A * env - pointer to caller's fcode environment 2N/A * fmt - pointer to caller's input buffr 2N/A * fmtbuf - ponter to caller's receptacle buffer 2N/A * bsize - size of caller's fmtbuf buffer 2N/A * This function performs an initial test to determine if caller's 2N/A * input buffer contains formatting(specified by presence of "%") 2N/A * in the buffer. If so, validfmt() function is called to verify 2N/A * the formatting, after which the buffer is processed according 2N/A * to the field width specified by validfmt() output. Special 2N/A * processing is required when caller's buffer contains a double 2N/A * "%" ("%%"), in which case the second "%" is accepted as normal 2N/A "fmt_str: NULL ptr supplied to validfmt()\n");
2N/A "fmt_str: invalid format type! (%s)\n",
2N/A if (
fw > 0) {
/* process normal (not long) formats */ 2N/A /* if here, fw must be a long format */ 2N/A /* if more input buffer to process, recurse */ 2N/A /* call to extract args for snprintf() calls below */ 2N/A if (
fw > 0) {
/* process normal (not long) formats */ 2N/A "fmt_str: invalid format (%s)\n",
2N/A }
else /* process long formats */ 2N/A * Pops data stack to obtain message text, and calls fmt_str() 2N/A * function to perform any message formatting necessary. 2N/A * This function is called from fc_cmn_end() or directly in 2N/A * processing a cmn-append token. Since a pre-existing message 2N/A * context is assumed, initial checking is performed to verify 2N/A "fc_cmn_append: no message context for append\n");
2N/A "fc_cmn_append: append exceeds max msg size\n");
2N/A * Process ]cmn-end token to log the message initiated by a preceding 2N/A * fc_cmn_start() call. 2N/A * Since nested cmn-xxx[ calls are supported, a test is made to determine 2N/A * if this is the final cmn-end of a nested sequence. If so, or if 2N/A * there was no nesting, log_message() is called with the appropriate 2N/A * text buffer. Otherwise, the root variable is adjusted to point to 2N/A * the preceding message in the sequence and links in the list are 2N/A * updated. No logging is performed until the final ]cmn-end of the 2N/A * sequence is processed; then, messages are logged in FIFO order. 2N/A * Generic function to begin a common message. 2N/A * Allocates a new cmn_msg_t to associate with the message, and sets 2N/A * up initial text as specified by callers' inputs: 2N/A * env - pointer to caller's fcode environment 2N/A * head - pointer to initial text portion of the message 2N/A * path - flag to indicate if a device path is to be generated 2N/A * Process cmn-type[ token. 2N/A * Invokes fc_cmn_start() to create a message containing blank 2N/A * header and no device path information. 2N/A * Process cmn-msg[ token. 2N/A * Invokes fc_cmn_start() to create a message containing blank 2N/A * header but specifying device path information. 2N/A * Process cmn-note[ token. 2N/A * Invokes fc_cmn_start() to create a message with NOTICE stamping in 2N/A * the header and specification of device path information. 2N/A * Process cmn-warn[ token. 2N/A * Invokes fc_cmn_start() to create a message with WARNING stamping in 2N/A * the header and specification of device path information. 2N/A * Process cmn-error[ token. 2N/A * Invokes fc_cmn_start() to create a message with ERROR stamping in 2N/A * the header and specification of device path information. 2N/A * Process cmn-fatal[ token. 2N/A * Invokes fc_cmn_start() to create a message with FATAL stamping in 2N/A * the header and specification of device path information.