Don't try to cat/play missing files
authorBrian Dickman <brian.dickman@gmail.com>
Mon, 21 May 2012 04:49:31 +0000 (21:49 -0700)
committerBrian Dickman <brian.dickman@gmail.com>
Mon, 28 May 2012 21:39:57 +0000 (14:39 -0700)
src/modules/utils/simpleshell/SimpleShell.cpp

index 6d53ae0..c650cca 100644 (file)
@@ -86,6 +86,10 @@ void SimpleShell::cat_command( string parameters, StreamOutput* stream ){
    
     // Open file 
     FILE *lp = fopen(filename.c_str(), "r");
+    if(lp == NULL) {
+       stream->printf("File not found: %s\r\n", filename.c_str());
+       return;
+    }
     string buffer;
     int c;
     int newlines = 0; 
@@ -103,7 +107,13 @@ void SimpleShell::cat_command( string parameters, StreamOutput* stream ){
 // Play a gcode file by considering each line as if it was received on the serial console
 void SimpleShell::play_command( string parameters, StreamOutput* stream ){
     // Get filename
-    this->current_file_handler = fopen( this->absolute_from_relative(shift_parameter( parameters )).c_str(), "r");
+    string filename          = this->absolute_from_relative(shift_parameter( parameters ));
+    this->current_file_handler = fopen( filename.c_str(), "r");
+    if(this->current_file_handler == NULL)
+    {
+       stream->printf("File not found: %s\r\n", filename.c_str());
+       return;
+    }
     this->playing_file = true;
     this->current_stream = stream;
 }