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
00018 gList aL;
00019 bool doEndNewLine;
00020
00021
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
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
00058 gFileFetch (gFileFetch& ) ;
00059 gFileFetch& operator= (gFileFetch& ) ;
00060 };
00061
00062 class gConfig : public gControl {
00063 public:
00064
00065 enum eConfKind {
00066 e_ConfLinearFree,
00067
00068
00069 e_ConfLinear,
00070
00071
00072
00073 e_ConfSectionStrict,
00074
00075 e_ConfSectionFree
00076
00077
00078
00079 };
00080
00081 gConfig (eConfKind aKind=e_ConfLinearFree) ;
00082 gConfig (eConfKind aKind, char* fName, bool doOpenToRead=true) ;
00083 virtual ~gConfig () ;
00084
00085
00086 int lastOpError;
00087
00088
00089
00090
00091
00092
00093 int maxNLines;
00094 eConfKind confKind;
00095 gString sFileName;
00096 gList lineStartCommentL;
00097
00098
00099
00100 unsigned lineStartPos;
00101
00102
00103 bool doTrim;
00104
00105
00106 gList linesInputL;
00107
00108
00109 gString lineSepChrs;
00110 gList lineSepStrs;
00111
00112
00113 unsigned sectionStartPos;
00114 gString sectionSep;
00115
00116
00117
00118
00119
00120 int iLineError;
00121 unsigned nConf;
00122 gList* confL;
00123 gList* conpL;
00124
00125
00126 gList sectL;
00127 gList nIdxSectL;
00128 gList noSectL;
00129
00130
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
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
00169 gConfig (gConfig& ) ;
00170 gConfig& operator= (gConfig& ) ;
00171 };
00172
00173 #endif //gCONFIG_X_H
00174