Commit 55e668ed authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Fix indentation

parent 378aa525
......@@ -56,7 +56,7 @@ PajeFileManager::PajeFileManager() : _filename(""), _filesize(-1), _lineid(0), _
}
PajeFileManager::PajeFileManager( const char * filename, ios_base::openmode mode ) :
_filename(filename), _filesize(-1), _lineid(0), _nbtks(0)
_filename(filename), _filesize(-1), _lineid(0), _nbtks(0)
{
_tokens = new char*[_PAJE_NBMAXTKS];
open(filename, mode);
......@@ -71,9 +71,9 @@ void PajeFileManager::open ( const char * filename, ios_base::openmode mode ) {
_filename = filename;
ifstream::open(filename, mode);
if (fail())
throw "Fail to open file";
if (fail())
throw "Fail to open file";
// get length of file:
seekg (0, ios::end);
......@@ -85,7 +85,7 @@ void PajeFileManager::open ( const char * filename, ios_base::openmode mode ) {
}
void PajeFileManager::close() {
ifstream::close();
ifstream::close();
_filesize = -1;
}
......@@ -99,10 +99,10 @@ long long PajeFileManager::get_size_loaded() {
float PajeFileManager::get_percent_loaded() {
if(_filesize != -1) {
return (float)tellg() / (float)_filesize;
return (float)tellg() / (float)_filesize;
}
else {
return 0.;
return 0.;
}
}
......@@ -113,14 +113,14 @@ int PajeFileManager::get_line(PajeLine *lineptr) {
// We set all the tokens to NULL
for (i=0; i<_PAJE_NBMAXTKS; i++) {
_tokens[i] = NULL;
_tokens[i] = NULL;
}
std::getline(*this, _line);
if (rdstate() != ifstream::goodbit) {
setstate(ifstream::eofbit); // We stop the reading if something happens to the state of the file.
lineptr->_nbtks = 0;
return _lineid;
lineptr->_nbtks = 0;
return _lineid;
}
_lineid++;
......@@ -129,115 +129,114 @@ int PajeFileManager::get_line(PajeLine *lineptr) {
_tokens[itks] = &_line[0];
for(i = 0; i<_line.size() /*&& ((c != '\n') &&(c != '\r\n')&&(c != '\r') && (c != '\0'))*/ && (itks < _PAJE_NBMAXTKS); i++) {
c = _line[i];
c = _line[i];
switch (c) {
// It's the end of the line, we just add the end caractere
// for the last token and increase the counter
case '\0' :
case '\n' :
{
_line[i] = '\0';
itks++;
break;
}
case '%' :
{
// In these case, we just have two tokens, one with the % and one without
itks++;
_tokens[itks] = &_line[i+1];
break;
}
case '\'' :
{
// Check if we are at the beginnning of a new one or not
if ( _tokens[itks][0] == '\'' ) {
_line[i] ='\0';
_tokens[itks]++;
} else {
_line[i] ='\0';
itks++;
_tokens[itks] = &_line[i+1];
}
switch (c) {
// It's the end of the line, we just add the end caractere
// for the last token and increase the counter
case '\0' :
case '\n' :
{
_line[i] = '\0';
itks++;
break;
}
case '%' :
{
// In these case, we just have two tokens, one with the % and one without
itks++;
_tokens[itks] = &_line[i+1];
break;
}
case '\'' :
{
// Check if we are at the beginnning of a new one or not
if ( _tokens[itks][0] == '\'' ) {
_line[i] ='\0';
_tokens[itks]++;
} else {
_line[i] ='\0';
itks++;
_tokens[itks] = &_line[i+1];
}
// Start a long token
while ( ( i < _filesize) && (_line[i] != '\'')) {
i++;
}
if((i==_filesize)){
setstate(ifstream::eofbit);
throw "Overflow";
return -1;
}
// We finish the token by replacing the \' by \0
_line[i] = '\0';
if(i+1<_line.size()){//begin a new token if we are not at the end of the line
itks++;
_tokens[itks] = &_line[i+1];
}
break;
}
case '"' :
{
// Check if we are at the beginnning of a new one or not
if ( _tokens[itks][0] == '"' ) {
_line[i] ='\0';
_tokens[itks]++;
} else {
_line[i] ='\0';
itks++;
_tokens[itks] = &_line[i+1];
}
// Start a long token
while ( ( i < _filesize) && (_line[i] != '\'')) {
i++;
}
if((i==_filesize)){
setstate(ifstream::eofbit);
throw "Overflow";
return -1;
}
// We finish the token by replacing the \' by \0
_line[i] = '\0';
if(i+1<_line.size()){//begin a new token if we are not at the end of the line
itks++;
_tokens[itks] = &_line[i+1];
}
break;
}
case '"' :
{
// Check if we are at the beginnning of a new one or not
if ( _tokens[itks][0] == '"' ) {
_line[i] ='\0';
_tokens[itks]++;
} else {
_line[i] ='\0';
itks++;
_tokens[itks] = &_line[i+1];
}
// Start a long token (-1 to have place or the null caractere)
while (( i < _filesize) && (_line[i] != '"')) {
i++;
}
// Start a long token (-1 to have place or the null caractere)
while (( i < _filesize) && (_line[i] != '"')) {
i++;
}
// We finish the token by replacing the " by \0
_line[i] = '\0';
if(i+1<_line.size()){//begin a new token if we are not at the end of the line
itks++;
_tokens[itks] = &_line[i+1];
}
if((i==_filesize)){
setstate(ifstream::eofbit);
throw "Overflow";
return -1;
}
break;
}
case ' ' :
case '\t' :
{
// Skip all spaces
while (( i < _filesize) && i<_line.size() && ((_line[i] == ' ') || (_line[i] == '\t')) ) {
_line[i] = '\0';
i++;
}
if((i==_filesize)){
setstate(ifstream::eofbit);
throw "Overflow";
return -1;
}
// We store a new token if it's a new space
if(i!=_line.size()){
if (_tokens[itks]!=NULL && _tokens[itks][0] != '\0')
itks++;
_tokens[itks] = &_line[i];
i--;
}
break;
}
default :
break;
}
// We finish the token by replacing the " by \0
_line[i] = '\0';
if(i+1<_line.size()){//begin a new token if we are not at the end of the line
itks++;
_tokens[itks] = &_line[i+1];
}
if((i==_filesize)){
setstate(ifstream::eofbit);
throw "Overflow";
return -1;
}
break;
}
case ' ' :
case '\t' :
{
// Skip all spaces
while (( i < _filesize) && (i<_line.size()) && ((_line[i] == ' ') || (_line[i] == '\t')) ) {
_line[i] = '\0';
i++;
}
if((i==_filesize)){
setstate(ifstream::eofbit);
throw "Overflow";
return -1;
}
// We store a new token if it's a new space
if(i!=_line.size()){
if (_tokens[itks]!=NULL && _tokens[itks][0] != '\0')
itks++;
_tokens[itks] = &_line[i];
i--;
}
break;
}
default :
break;
}
}
itks++; //add a token to avoid bugs, because we don't meet \n with std strings
itks++; //add a token to avoid bugs, because we don't meet \n with std strings
// We remove the last token if it is empty
if ((itks > 0) && (_tokens[itks-1][0] == '\0'))
itks--;
itks--;
_nbtks = itks;
lineptr->_id = _lineid;
......@@ -252,7 +251,7 @@ void PajeFileManager::print_line() {
cout << "==================" << _lineid << "=====================" << endl;
for(i=0; i < _nbtks; i++) {
cout << i << " : " << _tokens[i] << endl;
cout << i << " : " << _tokens[i] << endl;
}
cout << "===========================================" << endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment