Commit 58729edc authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

Corrected one bug while the trace is very small and loaded by command

line or grpahically (not by the menu).
Changed the about box to 1.0.

Tokensource... added some verification when we close files because they 
may not exist (by example, launched by command line)
parent 14d98c39
......@@ -142,8 +142,7 @@ bool Interface_console::draw_trace(const string & filename, const int format){
time_elapsed.start();
buf_txt.str("");
while(!parser.is_end_of_parsing()) {
while(!(parser.is_end_of_parsing() && thread.isFinished())) {
loaded_f = parser.get_size_loaded();/* value between 0 and 1. Should be multiplied by 100 to obtain a percentage */
loaded = (int)(loaded_f*100.0f);
......@@ -174,7 +173,7 @@ bool Interface_console::draw_trace(const string & filename, const int format){
_progress_dialog->setLabelText(QString( buf_txt.str().c_str()));
buf_txt.str("");
}
}
cout << endl;
......@@ -203,7 +202,7 @@ bool Interface_console::draw_trace(const string & filename, const int format){
_main_window->setDisabled (false);
}
// Wait for the end of the thread
while(!thread.isFinished()) {
while(!thread.wait()) {
}
......
......@@ -546,10 +546,9 @@ void Interface_graphic::on_about_triggered(){
QMessageBox::about(this, tr("About ViTE"),
tr("<h2>ViTE</h2>"
"the <b>Vi</b><i>sual </i><b>T</b><i>race</i> <b>E</b><i>xplorer</i> - <i>version 0.3</i> - <i>March 2009</i>.<br /><br />"
"the <b>Vi</b><i>sual </i><b>T</b><i>race</i> <b>E</b><i>xplorer</i> - <i>version 1.0</i> - <i>June 2009</i>.<br /><br />"
"Under the CeCILL A licence. The content can be found <a href=\"http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\">here</a>."
"<p><b>Developers:</b><ul><li>Kevin COULOMB</li><li>Johnny JAZEIX</li><li>Olivier LAGRASSE</li><li>Jule MARCOUEILLE</li><li>Pascal NOISETTE</li><li>Arthur REDONDY</li><li>Cl&eacute;ment VUCHENER</li></ul></p>"
"This software was made for a school engineering project for INRIA researchers.<br />"
"<p><b>Developers:</b><ul><li>Kevin COULOMB</li><li>Mathieu FAVERGE</li><li>Johnny JAZEIX</li><li>Olivier LAGRASSE</li><li>Jule MARCOUEILLE</li><li>Pascal NOISETTE</li><li>Arthur REDONDY</li><li>Cl&eacute;ment VUCHENER</li></ul></p>"
"The main page project is: <a href=\"http://vite.gforge.inria.fr/\">http://vite.gforge.inria.fr/</a>.<br /><br />"));
}
......
#include "TokenSource.hpp"
using namespace std;
int TokenSource::_cursor = 0;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
std::ifstream TokenSource::_file;
int TokenSource::_filesize = 1;
#else
off_t TokenSource::_filesize = 1;
#endif
TokenSource::TokenSource(){
//no file are opened
//you must use open later
_is_eof = true;
_cursor = 0;
}
TokenSource::TokenSource(const char *filename){
open(filename);
}
TokenSource::~TokenSource(){
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
_file.close();
#else
if (munmap(_buffer, _filesize) == -1){
Error::set(Error::_MUNMAP, Error::_WARNING);
}
_buffer = NULL;
close(_fd);
#endif
if (!_token.empty()) {
_token.clear();
}
}
void TokenSource::open(const char *filename){
_is_eof = false;
/* Getting the file size */
#if defined (WIN32)|| !defined(_POSIX_MAPPED_FILES)
_file.open(filename, ios::in);
_file.seekg (0, ios::end);
TokenSource::_filesize = _file.tellg();
_file.seekg (0, ios::beg);
#else
struct stat buf;
if(stat(filename, &buf) == -1) {
throw Error::_FSTAT;
}
_filesize = buf.st_size;
#endif
if(TokenSource::_filesize == 0) {
throw Error::_EMPTY_FILE;
}
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
fill_buffer();
#else
if ((_fd = ::open(filename, O_RDONLY)) == -1) {
throw Error::_OPEN;
}
#undef _MMAP
if ((_buffer = (char *)mmap(0, _filesize, PROT_READ, MAP_PRIVATE, _fd, 0)) == MAP_FAILED) {
throw Error::_MMAP;
}
#endif
}
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
bool TokenSource::fill_buffer() {
if (_file.eof()) {
return false;
}
else {
_file.read(_buffer, BUFFER_SIZE);
_buffer_size = _file.gcount();
return true;
}
}
#endif
bool TokenSource::go_to_next_token() {
while(_buffer[_cursor] == ' ' || _buffer[_cursor] == '\t') {
_cursor ++;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_cursor >= _buffer_size) {
if (!fill_buffer()) {
return true;
}
_cursor = 0;
}
#else
if(ensure_capacity())
break;
#endif
}
return false;
}
void TokenSource::build_composite_token() {
_cursor ++;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_cursor == _buffer_size) {
if (!fill_buffer()) {
Error::set(Error::_FSTAT, Error::_WARNING);
return;
}
_cursor = 0;
}
#else
if (ensure_capacity()) {
Error::set(Error::_FSTAT, Error::_WARNING);
return;
}
#endif
do {
_token.push_back(_buffer[_cursor]);
_cursor ++;
if (ensure_capacity()) {
break;
}
}
while((_buffer[_cursor] != '"') && (_buffer[_cursor] != '\''));
_cursor ++;
ensure_capacity();
}
void TokenSource::build_simple_token() {
while(_buffer[_cursor] != ' ' && _buffer[_cursor] != '\n' && _buffer[_cursor] != '\t'){
_token.push_back(_buffer[_cursor]);
_cursor ++;
if (ensure_capacity()){
break;
}
}
}
bool TokenSource::ensure_capacity() {
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_cursor >= _buffer_size) {
if (!fill_buffer()) {
_is_eof = true;
return true;
}
_cursor = 0;
}
return false;
#else
if (_cursor < _filesize)
return false;
_is_eof = true;
return true;
#endif
}
void TokenSource::build_line_breaks() {
while(_buffer[_cursor] == '\n') {
_cursor ++;
if (ensure_capacity()) {
break;
}
}
_token.push_back('\n');
}
void TokenSource::build_definition_starter() {
_cursor ++;
ensure_capacity();
_token.push_back('%');
}
std::string *TokenSource::read_token() {
//regexp recognition
//a token is
//(1) a line break
//(2) composite : a char buffer delimited by \"
//(3) a char buffer delimited by space
if (!_token.empty()) {
_token.clear();
}
if (_is_eof || go_to_next_token()) {
return NULL;
}
if (_buffer[_cursor] == '\n') {
build_line_breaks();
}
else if (_buffer[_cursor] == '%') {
build_definition_starter();
}
else if ((_buffer[_cursor] != '"') &&
(_buffer[_cursor] != '\'')){
build_simple_token();
}
else {
build_composite_token();
}
return &_token;
}
float TokenSource::get_size_loaded() {
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_file == NULL)
return 1.0f;
if (!_file.is_open())
return 2.0f;
if (_file.bad())
return 3.0f;
return ((float)_file.tellg())/(float)TokenSource::_filesize;
#else
if(_filesize == 0) {
return 1.0f;
}
return ((float)_cursor)/(float)_filesize;
#endif
}
void TokenSource::reinit_cursor() {
_cursor = 0;
}
#include "TokenSource.hpp"
using namespace std;
int TokenSource::_cursor = 0;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
std::ifstream TokenSource::_file;
int TokenSource::_filesize = 1;
#else
off_t TokenSource::_filesize = 1;
#endif
TokenSource::TokenSource(){
//no file are opened
//you must use open later
_is_eof = true;
_is_mmap_ok = false;
_is_file_opened = false;
_cursor = 0;
}
TokenSource::TokenSource(const char *filename){
open(filename);
}
TokenSource::~TokenSource(){
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if(_is_file_opened) {
_file.close();
}
#else
if (_is_mmap_ok) {
if(munmap(_buffer, _filesize) == -1){
Error::set(Error::_MUNMAP, Error::_WARNING);
}
}
_buffer = NULL;
if(_is_file_opened){
close(_fd);
}
#endif
if (!_token.empty()) {
_token.clear();
}
}
void TokenSource::open(const char *filename){
_is_eof = false;
/* Getting the file size */
#if defined (WIN32)|| !defined(_POSIX_MAPPED_FILES)
if(_file.open(filename, ios::in)){
_is_file_opened = true;
}
_file.seekg (0, ios::end);
TokenSource::_filesize = _file.tellg();
_file.seekg (0, ios::beg);
#else
struct stat buf;
if(stat(filename, &buf) == -1) {
throw Error::_FSTAT;
}
_filesize = buf.st_size;
#endif
if(TokenSource::_filesize == 0) {
throw Error::_EMPTY_FILE;
}
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
fill_buffer();
#else
if ((_fd = ::open(filename, O_RDONLY)) == -1) {
throw Error::_OPEN;
}
_is_file_opened = true;
#undef _MMAP
if ((_buffer = (char *)mmap(0, _filesize, PROT_READ, MAP_PRIVATE, _fd, 0)) == MAP_FAILED) {
throw Error::_MMAP;
}
_is_mmap_ok = true;
#endif
}
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
bool TokenSource::fill_buffer() {
if (_file.eof()) {
return false;
}
else {
_file.read(_buffer, BUFFER_SIZE);
_buffer_size = _file.gcount();
return true;
}
}
#endif
bool TokenSource::go_to_next_token() {
while(_buffer[_cursor] == ' ' || _buffer[_cursor] == '\t') {
_cursor ++;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_cursor >= _buffer_size) {
if (!fill_buffer()) {
return true;
}
_cursor = 0;
}
#else
if(ensure_capacity())
break;
#endif
}
return false;
}
void TokenSource::build_composite_token() {
_cursor ++;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_cursor == _buffer_size) {
if (!fill_buffer()) {
Error::set(Error::_FSTAT, Error::_WARNING);
return;
}
_cursor = 0;
}
#else
if (ensure_capacity()) {
Error::set(Error::_FSTAT, Error::_WARNING);
return;
}
#endif
do {
_token.push_back(_buffer[_cursor]);
_cursor ++;
if (ensure_capacity()) {
break;
}
}
while((_buffer[_cursor] != '"') && (_buffer[_cursor] != '\''));
_cursor ++;
ensure_capacity();
}
void TokenSource::build_simple_token() {
while(_buffer[_cursor] != ' ' && _buffer[_cursor] != '\n' && _buffer[_cursor] != '\t'){
_token.push_back(_buffer[_cursor]);
_cursor ++;
if (ensure_capacity()){
break;
}
}
}
bool TokenSource::ensure_capacity() {
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_cursor >= _buffer_size) {
if (!fill_buffer()) {
_is_eof = true;
return true;
}
_cursor = 0;
}
return false;
#else
if (_cursor < _filesize)
return false;
_is_eof = true;
return true;
#endif
}
void TokenSource::build_line_breaks() {
while(_buffer[_cursor] == '\n') {
_cursor ++;
if (ensure_capacity()) {
break;
}
}
_token.push_back('\n');
}
void TokenSource::build_definition_starter() {
_cursor ++;
ensure_capacity();
_token.push_back('%');
}
std::string *TokenSource::read_token() {
//regexp recognition
//a token is
//(1) a line break
//(2) composite : a char buffer delimited by \"
//(3) a char buffer delimited by space
if (!_token.empty()) {
_token.clear();
}
if (_is_eof || go_to_next_token()) {
return NULL;
}
if (_buffer[_cursor] == '\n') {
build_line_breaks();
}
else if (_buffer[_cursor] == '%') {
build_definition_starter();
}
else if ((_buffer[_cursor] != '"') &&
(_buffer[_cursor] != '\'')){
build_simple_token();
}
else {
build_composite_token();
}
return &_token;
}
float TokenSource::get_size_loaded() {
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_file == NULL)
return 1.0f;
if (!_file.is_open())
return 2.0f;
if (_file.bad())
return 3.0f;
return ((float)_file.tellg())/(float)TokenSource::_filesize;
#else
if(_filesize == 0) {
return 1.0f;
}
return ((float)_cursor)/(float)_filesize;
#endif
}
void TokenSource::reinit_cursor() {
_cursor = 0;
}
......@@ -50,8 +50,9 @@ private:
static int _cursor;
bool _is_eof;
bool _is_mmap_ok;
bool _is_file_opened;
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
int _buffer_size;
static std::ifstream _file;
......
Markdown is supported
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