From f0154de5b3d1fea9d9ca62265c739e039576249c Mon Sep 17 00:00:00 2001 From: Bernhard Kubicek Date: Sat, 19 Nov 2011 15:36:49 +0100 Subject: [PATCH] found bug that disabled printing from root. --- Marlin/cardreader.pde | 64 +++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/Marlin/cardreader.pde b/Marlin/cardreader.pde index 4c869e4276..2771668a46 100644 --- a/Marlin/cardreader.pde +++ b/Marlin/cardreader.pde @@ -192,41 +192,43 @@ void CardReader::openFile(char* name,bool read) char *fname=name; char *dirname_start,*dirname_end; - dirname_start=strchr(name,'/')+1; - while(dirname_start!=NULL) + if(name[0]=='/') { - dirname_end=strchr(dirname_start,'/'); - //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name)); - //SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name)); - if(dirname_end!=NULL && dirname_end>dirname_start) + dirname_start=strchr(name,'/')+1; + while(dirname_start>0) { - char subdirname[13]; - strncpy(subdirname, dirname_start, dirname_end-dirname_start); - subdirname[dirname_end-dirname_start]=0; - SERIAL_ECHOLN(subdirname); - if(!myDir.open(curDir,subdirname,O_READ)) + dirname_end=strchr(dirname_start,'/'); + //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name)); + //SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name)); + if(dirname_end>0 && dirname_end>dirname_start) { - SERIAL_PROTOCOLPGM("open failed, File: "); - SERIAL_PROTOCOL(subdirname); - SERIAL_PROTOCOLLNPGM("."); - return; + char subdirname[13]; + strncpy(subdirname, dirname_start, dirname_end-dirname_start); + subdirname[dirname_end-dirname_start]=0; + SERIAL_ECHOLN(subdirname); + if(!myDir.open(curDir,subdirname,O_READ)) + { + SERIAL_PROTOCOLPGM("open failed, File: "); + SERIAL_PROTOCOL(subdirname); + SERIAL_PROTOCOLLNPGM("."); + return; + } + else + ;//SERIAL_ECHOLN("dive ok"); + + curDir=&myDir; + dirname_start=dirname_end+1; } - else - SERIAL_ECHOLN("dive ok"); - - curDir=&myDir; - dirname_start=dirname_end+1; - } - else // the reminder after all /fsa/fdsa/ is the filename - { - fname=dirname_start; - //SERIAL_ECHOLN("remaider"); - //SERIAL_ECHOLN(fname); - break; + else // the reminder after all /fsa/fdsa/ is the filename + { + fname=dirname_start; + //SERIAL_ECHOLN("remaider"); + //SERIAL_ECHOLN(fname); + break; + } + } - } - if(read) { if (file.open(curDir, fname, O_READ)) @@ -242,7 +244,9 @@ void CardReader::openFile(char* name,bool read) } else { - SERIAL_PROTOCOLLNPGM("file.open failed"); + SERIAL_PROTOCOLPGM("open failed, File: "); + SERIAL_PROTOCOL(fname); + SERIAL_PROTOCOLLNPGM("."); } } else