列挙型 | |
enum | dbg_Token { dbg_null = 0, dbg_ignore, dbg_header, dbg_timestamp, dbg_level, dbg_sourcefile, dbg_function, dbg_lineno, dbg_message, dbg_eof } |
関数 | |
const char * | dbg_token2string (dbg_Token tok) |
dbg_Token | dbg_char2token (dbg_Token *state, int c) |
enum dbg_Token |
dbg_null | |
dbg_ignore | |
dbg_header | |
dbg_timestamp | |
dbg_level | |
dbg_sourcefile | |
dbg_function | |
dbg_lineno | |
dbg_message | |
dbg_eof |
debugparse.h の 47 行で定義されています。
00048 { 00049 dbg_null = 0, 00050 dbg_ignore, 00051 dbg_header, 00052 dbg_timestamp, 00053 dbg_level, 00054 dbg_sourcefile, 00055 dbg_function, 00056 dbg_lineno, 00057 dbg_message, 00058 dbg_eof 00059 } dbg_Token;
const char* dbg_token2string | ( | dbg_Token | tok | ) |
debugparse.c の 48 行で定義されています。
参照先 dbg_eof・dbg_function・dbg_header・dbg_ignore・dbg_level・dbg_lineno・dbg_message・dbg_null・dbg_sourcefile・dbg_timestamp.
参照元 dbg_test().
00052 : tok - One of the set of dbg_Tokens defined in debugparse.h. 00053 * 00054 * Output: A string identifying the token. This is useful for debugging, 00055 * etc. 00056 * 00057 * Note: If the token is not known, this function will return the 00058 * string "<unknown>". 00059 * 00060 * ------------------------------------------------------------------------ ** 00061 */ 00062 { 00063 switch( tok ) 00064 { 00065 case dbg_null: 00066 return( "null" ); 00067 case dbg_ignore: 00068 return( "ignore" ); 00069 case dbg_header: 00070 return( "header" ); 00071 case dbg_timestamp: 00072 return( "time stamp" ); 00073 case dbg_level: 00074 return( "level" ); 00075 case dbg_sourcefile: 00076 return( "source file" ); 00077 case dbg_function: 00078 return( "function" ); 00079 case dbg_lineno: 00080 return( "line number" ); 00081 case dbg_message: 00082 return( "message" ); 00083 case dbg_eof: 00084 return( "[EOF]" ); 00085 } 00086 return( "<unknown>" ); 00087 } /* dbg_token2string */
debugparse.c の 89 行で定義されています。
参照先 dbg_eof・dbg_function・dbg_header・dbg_ignore・dbg_level・dbg_lineno・dbg_message・dbg_null・dbg_sourcefile・dbg_timestamp.
参照元 dbg_test()・main().
00093 : state - A pointer to a token variable. This is used to 00094 * maintain the parser state between calls. For 00095 * each input stream, you should set up a separate 00096 * state variable and initialize it to dbg_null. 00097 * Pass a pointer to it into this function with each 00098 * character in the input stream. See dbg_test() 00099 * for an example. 00100 * c - The "current" character in the input stream. 00101 * 00102 * Output: A token. 00103 * The token value will change when delimiters are found, 00104 * which indicate a transition between syntactical objects. 00105 * Possible return values are: 00106 * 00107 * dbg_null - The input character was an end-of-line. 00108 * This resets the parser to its initial state 00109 * in preparation for parsing the next line. 00110 * dbg_eof - Same as dbg_null, except that the character 00111 * was an end-of-file. 00112 * dbg_ignore - Returned for whitespace and delimiters. 00113 * These lexical tokens are only of interest 00114 * to the parser. 00115 * dbg_header - Indicates the start of a header line. The 00116 * input character was '[' and was the first on 00117 * the line. 00118 * dbg_timestamp - Indicates that the input character was part 00119 * of a header timestamp. 00120 * dbg_level - Indicates that the input character was part 00121 * of the debug-level value in the header. 00122 * dbg_sourcefile - Indicates that the input character was part 00123 * of the sourcefile name in the header. 00124 * dbg_function - Indicates that the input character was part 00125 * of the function name in the header. 00126 * dbg_lineno - Indicates that the input character was part 00127 * of the DEBUG call line number in the header. 00128 * dbg_message - Indicates that the input character was part 00129 * of the DEBUG message text. 00130 * 00131 * ------------------------------------------------------------------------ ** 00132 */ 00133 { 00134 /* The terminating characters that we see will greatly depend upon 00135 * how they are read. For example, if gets() is used instead of 00136 * fgets(), then we will not see newline characters. A lot also 00137 * depends on the calling function, which may handle terminators 00138 * itself. 00139 * 00140 * '\n', '\0', and EOF are all considered line terminators. The 00141 * dbg_eof token is sent back if an EOF is encountered. 00142 * 00143 * Warning: only allow the '\0' character to be sent if you are 00144 * using gets() to read whole lines (thus replacing '\n' 00145 * with '\0'). Sending '\0' at the wrong time will mess 00146 * up the parsing. 00147 */ 00148 switch( c ) 00149 { 00150 case EOF: 00151 *state = dbg_null; /* Set state to null (initial state) so */ 00152 return( dbg_eof ); /* that we can restart with new input. */ 00153 case '\n': 00154 case '\0': 00155 *state = dbg_null; /* A newline or eoln resets to the null state. */ 00156 return( dbg_null ); 00157 } 00158 00159 /* When within the body of the message, only a line terminator 00160 * can cause a change of state. We've already checked for line 00161 * terminators, so if the current state is dbg_msgtxt, simply 00162 * return that as our current token. 00163 */ 00164 if( dbg_message == *state ) 00165 return( dbg_message ); 00166 00167 /* If we are at the start of a new line, and the input character 00168 * is an opening bracket, then the line is a header line, otherwise 00169 * it's a message body line. 00170 */ 00171 if( dbg_null == *state ) 00172 { 00173 if( '[' == c ) 00174 { 00175 *state = dbg_timestamp; 00176 return( dbg_header ); 00177 } 00178 *state = dbg_message; 00179 return( dbg_message ); 00180 } 00181 00182 /* We've taken care of terminators, text blocks and new lines. 00183 * The remaining possibilities are all within the header line 00184 * itself. 00185 */ 00186 00187 /* Within the header line, whitespace can be ignored *except* 00188 * within the timestamp. 00189 */ 00190 if( isspace( c ) ) 00191 { 00192 /* Fudge. The timestamp may contain space characters. */ 00193 if( (' ' == c) && (dbg_timestamp == *state) ) 00194 return( dbg_timestamp ); 00195 /* Otherwise, ignore whitespace. */ 00196 return( dbg_ignore ); 00197 } 00198 00199 /* Okay, at this point we know we're somewhere in the header. 00200 * Valid header *states* are: dbg_timestamp, dbg_level, 00201 * dbg_sourcefile, dbg_function, and dbg_lineno. 00202 */ 00203 switch( c ) 00204 { 00205 case ',': 00206 if( dbg_timestamp == *state ) 00207 { 00208 *state = dbg_level; 00209 return( dbg_ignore ); 00210 } 00211 break; 00212 case ']': 00213 if( dbg_level == *state ) 00214 { 00215 *state = dbg_sourcefile; 00216 return( dbg_ignore ); 00217 } 00218 break; 00219 case ':': 00220 if( dbg_sourcefile == *state ) 00221 { 00222 *state = dbg_function; 00223 return( dbg_ignore ); 00224 } 00225 break; 00226 case '(': 00227 if( dbg_function == *state ) 00228 { 00229 *state = dbg_lineno; 00230 return( dbg_ignore ); 00231 } 00232 break; 00233 case ')': 00234 if( dbg_lineno == *state ) 00235 { 00236 *state = dbg_null; 00237 return( dbg_ignore ); 00238 } 00239 break; 00240 } 00241 00242 /* If the previous block did not result in a state change, then 00243 * return the current state as the current token. 00244 */ 00245 return( *state ); 00246 } /* dbg_char2token */