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 "MCFlogifstream.h"
00023
00024 #include "MCFutility.h"
00025
00026 MCFlogifstream::MCFlogifstream( string filenamebase )
00027 : _mcffilepos(0), _mcfeof(0), _usrfilepos(0), _usreof(0)
00028 {
00029 mcflogfilename( filenamebase, _filenamelog );
00030 _ifs = new ifstream( _filenamelog.c_str() );
00031 (*_ifs).good() ? _filenotfound = 0 : _filenotfound = 1;
00032 };
00033
00034 MCFlogifstream::~MCFlogifstream()
00035 {
00036 delete _ifs;
00037 };
00038
00039 int MCFlogifstream::nextMCF( string line )
00040 {
00041 if ( ( _filenotfound == 1 ) || ( _mcfeof == 1 ) ) return 1;
00042
00043 string tmpbuf="";
00044
00045 int found = 0;
00046 (*_ifs).seekg( _mcffilepos, ios::beg );
00047
00048 int i;
00049 char c;
00050
00051 while ( ( found == 0 ) && ( _mcfeof == 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() ) _mcfeof = 1;
00060 if ( tmpbuf == "MCF" ) 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() ) _mcfeof=1;
00071 line = tmpbuf;
00072 _mcffilepos = (*_ifs).tellg();
00073 (*_ifs).clear();
00074 return _mcfeof;
00075 };
00076
00077 int MCFlogifstream::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 tmpbuf = "";
00091 while ( ( c == ' ' ) && (*_ifs).good() ) { (*_ifs).get(c); }
00092 while ( ( c != ' ' ) && ( c != 10 ) && (*_ifs).good() ) {
00093 tmpbuf += c;
00094 (*_ifs).get(c);
00095 }
00096 if ( (*_ifs).eof() ) _usreof = 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 cout << tmpbuf << found << endl;
00105 }
00106 cout << tmpbuf << found << endl;
00107
00108 if ( (*_ifs).eof() ) _usreof = 1;
00109 line = tmpbuf;
00110 _usrfilepos = (*_ifs).tellg();
00111 (*_ifs).clear();
00112 return _usreof;
00113 };
00114
00115 int MCFlogifstream::getarg( const int narg, const string line, string arg )
00116 {
00117 int i = 0;
00118 int found = 0;
00119 int eol = 0;
00120 int iarg = 0;
00121
00122 int j;
00123 char c;
00124
00125 while ( found==0 && eol==0 ) {
00126 c = ' ';
00127
00128 while ( c == ' ' ) { c = line[i++]; }
00129
00130 arg="";
00131 while ( ( c != ' ' ) && ( i < (int)line.size() ) ) {
00132 arg += c;
00133 c = line[i++];
00134 }
00135
00136 if ( i == (int)line.size() ) eol = 1;
00137 if ( (++iarg) == narg ) found = 1;
00138 }
00139
00140 if ( found == 0 ) arg = "";
00141
00142 return !found;
00143
00144 };
00145