gconfig.h

Go to the documentation of this file.
00001 #ifndef gCONFIG_X_H
00002 #define gCONFIG_X_H
00003 
00004 #include "glist.h"
00005 #include "gfile.h"
00006 
00007 #define CONF_CHR_LINE_ERR 0x255
00008 ////////////////////////////////////////////////////////////
00009 class gFileFetch : public gFileText {
00010 public:
00011     gFileFetch (int maxLines=-1) ;
00012     gFileFetch (gString& sFName, int maxLines=-1) ;
00013     gFileFetch (char* fName, int maxLines=-1, bool aShowProgress=false) ;
00014     gFileFetch (gString& sInput, bool aShowProgress) ;
00015     virtual ~gFileFetch () ;
00016 
00017     // Public data-members
00018     gList aL;
00019     bool doEndNewLine;
00020 
00021     // Get methods
00022     virtual bool IsBufferOk () {
00023         return isFetchBufferOk;
00024     }
00025 
00026     virtual char* Str (unsigned idx) {
00027         return aL.Str( idx );
00028     }
00029 
00030     virtual bool BufferAutoAdjust () {
00031         return doResize;
00032     }
00033 
00034     // Set methods
00035     bool Fetch (gString& sFName) ;
00036     void AdjustBuffer (bool doBufferResize) {
00037         doResize = doBufferResize;
00038     }
00039 
00040     virtual bool SetFileReport (FILE* fRep) ;
00041     virtual bool SetDeviceReport (eDeviceKind aDKind) ;
00042 
00043 protected:
00044     int maxNLines;
00045     bool isFetchBufferOk;
00046     bool doResize;
00047 
00048     bool doShowProgress;
00049     FILE* fVRepErr;
00050 
00051     int thisReadFile (bool& isOk, gList& zL) ;
00052     int thisReadAll (bool& isOk, bool& isBufOk, gList& zL) ;
00053     int thisReadFileThrough (gList& zL, t_uint32& nBytes) ;
00054     int thisReadStringAsFile (gString& sInput, gList& zL) ;
00055 
00056 private:
00057     // Operators,empty
00058     gFileFetch (gFileFetch& ) ; //empty
00059     gFileFetch& operator= (gFileFetch& ) ; //empty
00060 };
00061 ////////////////////////////////////////////////////////////
00062 class gConfig : public gControl {
00063 public:
00064     // Public enums
00065     enum eConfKind {
00066         e_ConfLinearFree,   // e.g. /etc/host.conf
00067                             // Each line one config.
00068                             //
00069         e_ConfLinear,       // e.g. /etc/sysconfig/network
00070                             // Each line one config, and
00071                             // separated with specific char.
00072                             //
00073         e_ConfSectionStrict,// e.g. win.ini or smb.conf
00074                             // Section like [] or X:
00075         e_ConfSectionFree   // e.g. httpd.conf
00076                             // Section like <A>&</A> and other
00077                             // parts linear.
00078                             //
00079     };
00080 
00081     gConfig (eConfKind aKind=e_ConfLinearFree) ;
00082     gConfig (eConfKind aKind, char* fName, bool doOpenToRead=true) ;
00083     virtual ~gConfig () ;
00084 
00085     // Public data-members
00086     int lastOpError;           // Errors
00087                                //  1-10 : pre-parse
00088                                //  21: No section specified
00089                                //  22: Invalid section separator
00090                                //
00091                                //
00092                                //
00093     int maxNLines;             // Max.number of lines allowed (-1:no limit)
00094     eConfKind confKind;
00095     gString sFileName;
00096     gList lineStartCommentL;   // Usually #
00097                                // This is a list with all
00098                                // strings considered as comments.
00099                                //
00100     unsigned lineStartPos;     // 0: any; 1: first chr, 2: ...
00101                                // Default is 0.
00102                                //
00103     bool doTrim;               // Usually true
00104 
00105     // => input control
00106     gList linesInputL;
00107 
00108     // => line parser configs
00109     gString lineSepChrs;       // By default '='
00110     gList lineSepStrs;         // By default no strings
00111 
00112     // => section parser configs
00113     unsigned sectionStartPos;  // By default 1 (first chr)
00114     gString sectionSep;        // By default "[]"
00115 
00116     // => parsed results
00117     //    If has n sections contains n * confL;
00118     //    If is linear, each list contains the separator,
00119     //    the left arg and the right arg (3 elements).
00120     int iLineError;   // Line index with error (0=no error)
00121     unsigned nConf;   // Number of 'confL'/'conpL'
00122     gList* confL;     // The raw configurations
00123     gList* conpL;     // The parsed configurations
00124                       // Both vectors of lists are [1..n] based.
00125 
00126     gList  sectL;     // Section raw list
00127     gList  nIdxSectL; // Index(line) of sections found
00128     gList  noSectL;   // Header lines before sections
00129 
00130     // Get methods
00131     bool HasSections () {
00132         return hasSections;
00133     }
00134 
00135     bool HasSection (unsigned idxSection) ;
00136     bool HasSection (unsigned idxSection, unsigned& nLines) ;
00137 
00138     unsigned GetSectionFromName (char* sSection) ;
00139     virtual gList* GetSection (char* sSection) ;
00140 
00141     bool GetSectionLine (unsigned idxSection,
00142                          unsigned idxLine,
00143                          gString& sSep,
00144                          gString& sLeft,
00145                          gString& sRight,
00146                          bool& isAssign) ;
00147 
00148     // Set methods
00149     bool SetConfKind (eConfKind aKind) ;
00150     bool Process () ;
00151     bool Process (char* fName) ;
00152 
00153 protected:
00154     bool hasSections;
00155     gList cfgL;
00156 
00157     int thisConfigInit () ;
00158     int thisConfigDelete () ;
00159 
00160     int thisRead (char* fName, gList& aL, gList& idxL) ;
00161 
00162     int thisProcess (gList& aL, gList& iLineL, int& lineError) ;
00163     int thisParseLine (char* str, gList& pL) ;
00164     int thisAddLineToList (gList& lineL, gList& pL) ;
00165     bool thisSectionChrStartEnd (t_uchar uSecChr) ;
00166 
00167 private:
00168     // Operators,empty
00169     gConfig (gConfig& ) ; //empty
00170     gConfig& operator= (gConfig& ) ; //empty
00171 };
00172 ////////////////////////////////////////////////////////////
00173 #endif //gCONFIG_X_H
00174 

Generated on Sat Aug 18 02:40:51 2007 for xpfweb_v2x lib by  doxygen 1.4.2