00001 #ifndef DEBUGPARSE_H 00002 #define DEBUGPARSE_H 00003 /* ========================================================================== ** 00004 * debugparse.c 00005 * 00006 * Copyright (C) 1998 by Christopher R. Hertel 00007 * 00008 * Email: crh@ubiqx.mn.org 00009 * 00010 * -------------------------------------------------------------------------- ** 00011 * This module is a very simple parser for Samba debug log files. 00012 * -------------------------------------------------------------------------- ** 00013 * 00014 * This library is free software; you can redistribute it and/or 00015 * modify it under the terms of the GNU Library General Public 00016 * License as published by the Free Software Foundation; either 00017 * version 2 of the License, or (at your option) any later version. 00018 * 00019 * This library is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 * Library General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Library General Public 00025 * License along with this library; if not, write to the Free 00026 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 * 00028 * -------------------------------------------------------------------------- ** 00029 * The important function in this module is dbg_char2token(). The rest is 00030 * basically fluff. (Potentially useful fluff, but still fluff.) 00031 * ========================================================================== ** 00032 */ 00033 00034 #include "includes.h" 00035 00036 /* This module compiles quite nicely outside of the Samba environment. 00037 * You'll need the following headers: 00038 #include <ctype.h> 00039 #include <stdio.h> 00040 #include <string.h> 00041 */ 00042 00043 /* -------------------------------------------------------------------------- ** 00044 * These are the tokens returned by dbg_char2token(). 00045 */ 00046 00047 typedef enum 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; 00060 00061 /* -------------------------------------------------------------------------- ** 00062 * Function prototypes... 00063 */ 00064 00065 const char *dbg_token2string( dbg_Token tok ); 00066 /* ------------------------------------------------------------------------ ** 00067 * Given a token, return a string describing the token. 00068 * 00069 * Input: tok - One of the set of dbg_Tokens defined in debugparse.h. 00070 * 00071 * Output: A string identifying the token. This is useful for debugging, 00072 * etc. 00073 * 00074 * Note: If the token is not known, this function will return the 00075 * string "<unknown>". 00076 * 00077 * ------------------------------------------------------------------------ ** 00078 */ 00079 00080 dbg_Token dbg_char2token( dbg_Token *state, int c ); 00081 /* ------------------------------------------------------------------------ ** 00082 * Parse input one character at a time. 00083 * 00084 * Input: state - A pointer to a token variable. This is used to 00085 * maintain the parser state between calls. For 00086 * each input stream, you should set up a separate 00087 * state variable and initialize it to dbg_null. 00088 * Pass a pointer to it into this function with each 00089 * character in the input stream. See dbg_test() 00090 * for an example. 00091 * c - The "current" character in the input stream. 00092 * 00093 * Output: A token. 00094 * The token value will change when delimiters are found, 00095 * which indicate a transition between syntactical objects. 00096 * Possible return values are: 00097 * 00098 * dbg_null - The input character was an end-of-line. 00099 * This resets the parser to its initial state 00100 * in preparation for parsing the next line. 00101 * dbg_eof - Same as dbg_null, except that the character 00102 * was an end-of-file. 00103 * dbg_ignore - Returned for whitespace and delimiters. 00104 * These lexical tokens are only of interest 00105 * to the parser. 00106 * dbg_header - Indicates the start of a header line. The 00107 * input character was '[' and was the first on 00108 * the line. 00109 * dbg_timestamp - Indicates that the input character was part 00110 * of a header timestamp. 00111 * dbg_level - Indicates that the input character was part 00112 * of the debug-level value in the header. 00113 * dbg_sourcefile - Indicates that the input character was part 00114 * of the sourcefile name in the header. 00115 * dbg_function - Indicates that the input character was part 00116 * of the function name in the header. 00117 * dbg_lineno - Indicates that the input character was part 00118 * of the DEBUG call line number in the header. 00119 * dbg_message - Indicates that the input character was part 00120 * of the DEBUG message text. 00121 * 00122 * ------------------------------------------------------------------------ ** 00123 */ 00124 00125 00126 /* -------------------------------------------------------------------------- */ 00127 #endif /* DEBUGPARSE_H */