print_op_and_params () { /*** prints until '(', ';', ' ' or '\n' encountered then prints `_OP' ***/ while ( c != '(' && c != ';' && c != ' ' && c != '\n' && c != EOF ) { putc( c, scriptfile_out ); c = getc ( scriptfile_in ); }; fputs ( "_OP\n", scriptfile_out ); rem_ws (); if ( c == '(' ) { /*** params present ***/ c = getc ( scriptfile_in ); while ( c != ')' ) { /*** print until ',', ' ', '\t' or ')' ***/ while ( c != ',' && c != ' ' && c != '\t' && c != ')' && c != EOF ) { putc( c, scriptfile_out ); c = getc ( scriptfile_in ); }; if ( c == ',' ) { putc( '\n', scriptfile_out ); }; if ( c != ')' && c != EOF ) { c = getc ( scriptfile_in ); } } }; putc( '\n', scriptfile_out ); rem_ws (); }
MapConfig Utils::ReadFile(const char * fileName) { string line, input = ""; stringstream rem_ws; /* used to remove whitespaces */ ifstream mapFile (fileName); int numberOfGates; MapConfig inputMap; if (mapFile.is_open()) { /* Read map id, number of gates and width x height */ mapFile >> inputMap.id >> numberOfGates >> inputMap.width >> inputMap.height ; /* Read all the gates */ for( int i = 0 ; i < numberOfGates ; i++ ) { Gate g; int col, line; /* col, line, id (for map or entity) */ mapFile >> col >> line >> g.second ; g.first.first = col + 1; g.first.second = line + 1; inputMap.gates.push_back( g ); } /* Now read the map itself */ while ( getline (mapFile, line) ) { stringstream rem_ws( line ); while( rem_ws >> line ) inputMap.str.append( line ); } mapFile.close(); }