00001
00002
00003
00004
00005
00006
00007 #ifdef USE_STD
00008 #include <cmath>
00009 #include <cstdlib>
00010 #include <iostream>
00011 #include <fstream>
00012 #include <string>
00013 using namespace std;
00014 #else
00015 #include <math.h>
00016 #include <stdlib.h>
00017 #include <iostream.h>
00018 #include <fstream.h>
00019 #include <string.h>
00020 #endif
00021
00022 #include "DCFlogifstream.h"
00023
00024 #include "DCFutility.h"
00025
00026 DCFlogifstream::DCFlogifstream( string filenamebase )
00027 : _dcffilepos(0), _dcfeof(0), _usrfilepos(0), _usreof(0)
00028 {
00029 dcflogfilename( filenamebase, _filenamelog );
00030 _ifs = new ifstream( _filenamelog.c_str() );
00031 (*_ifs).good() ? _filenotfound = 0 : _filenotfound = 1;
00032 };
00033
00034 DCFlogifstream::~DCFlogifstream()
00035 {
00036 delete _ifs;
00037 };
00038
00039 int DCFlogifstream::nextDCF( string line )
00040 {
00041 if ( ( _filenotfound == 1 ) || ( _dcfeof == 1 ) ) return 1;
00042
00043 string tmpbuf="";
00044
00045 int found = 0;
00046 (*_ifs).seekg( _dcffilepos, ios::beg );
00047
00048 int i;
00049 char c;
00050
00051 while ( ( found == 0 ) && ( _dcfeof == 0 ) ) {
00052 c=' ';
00053 i=0;
00054 while ( ( c == ' ' ) && (*_ifs).good() ) { (*_ifs).get(c); }
00055 while ( ( c != ' ' ) && ( c != 10 ) && (*_ifs).good() ) {
00056 tmpbuf += c;
00057 (*_ifs).get(c);
00058 }
00059 if ( (*_ifs).eof() ) _dcfeof = 1;
00060 if ( tmpbuf == "DCF" ) found = 1;
00061 c=' ';
00062 i=0;
00063 while ( ( c == ' ' ) && (*_ifs).good() ) { (*_ifs).get(c); }
00064 while ( ( c != 10 ) && (*_ifs).good() ) {
00065 tmpbuf += c;
00066 (*_ifs).get(c);
00067 }
00068 }
00069
00070 if ( (*_ifs).eof() ) _dcfeof=1;
00071 line = tmpbuf;
00072 _dcffilepos = (*_ifs).tellg();
00073 (*_ifs).clear();
00074 return _dcfeof;
00075 };
00076
00077 int DCFlogifstream::nextUSR( string line )
00078 {
00079 if ( ( _filenotfound == 1 ) || ( _usreof == 1 ) ) return 1;
00080 string tmpbuf="";
00081 int found=0;
00082 (*_ifs).seekg( _usrfilepos, ios::beg );
00083
00084 int i;
00085 char c;
00086
00087 while ( ( found == 0 ) && ( _usreof == 0 ) ) {
00088 c=' ';
00089 i=0;
00090 while ( ( c == ' ' ) && (*_ifs).good() ) { (*_ifs).get(c); }
00091 while ( ( c != ' ' ) && ( c != 10 ) && (*_ifs).good() ) {
00092 tmpbuf += c;
00093 (*_ifs).get(c);
00094 }
00095 if ( (*_ifs).eof() ) _usreof = 1;
00096 if ( tmpbuf == "USR" ) found = 1;
00097 c = ' ';
00098 i = 0;
00099 while ( ( c == ' ' ) && (*_ifs).good() ) { (*_ifs).get(c); }
00100 while ( ( c != 10 ) && (*_ifs).good() ) {
00101 tmpbuf += c;
00102 (*_ifs).get(c);
00103 }
00104 }
00105
00106 if ( (*_ifs).eof() ) _usreof = 1;
00107 line = tmpbuf;
00108 _usrfilepos = (*_ifs).tellg();
00109 (*_ifs).clear();
00110 return _usreof;
00111 };
00112
00113 int DCFlogifstream::getarg( const int narg, const string line, string arg )
00114 {
00115 int i = 0;
00116 int found = 0;
00117 int eol = 0;
00118 int iarg = 0;
00119
00120 int j;
00121 char c;
00122
00123 while ( found==0 && eol==0 ) {
00124 c = ' ';
00125
00126 while ( c == ' ' ) { c = line[i++]; }
00127
00128 arg="";
00129 while ( ( c != ' ' ) && ( i < line.size() ) ) {
00130 arg += c;
00131 c = line[i++];
00132 }
00133
00134 if ( i == line.size() ) eol = 1;
00135 if ( (++iarg) == narg ) found = 1;
00136 }
00137
00138 if ( found == 0 ) arg = "";
00139
00140 return !found;
00141
00142 };
00143