From ef276403963bca27aeb4d4604d97bdba308bd7e4 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 25 May 2016 18:49:31 -0400 Subject: [PATCH] 2016-05-25 Fred Gleason Added a '--escape-string=' parameters to rdexport(1). --- ChangeLog | 2 ++ utils/rdexport/rdexport.cpp | 34 +++++++++++++++++++++++++++++++++- utils/rdexport/rdexport.h | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5dfadb76..30070636 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15168,3 +15168,5 @@ Ubuntu 16.04 [GitHub pull request #000130]. 2016-05-25 Fred Gleason * Incremented the package version to 2.13.0int00. +2016-05-25 Fred Gleason + Added a '--escape-string=' parameters to rdexport(1). diff --git a/utils/rdexport/rdexport.cpp b/utils/rdexport/rdexport.cpp index 933fe21c..d64aaddd 100644 --- a/utils/rdexport/rdexport.cpp +++ b/utils/rdexport/rdexport.cpp @@ -41,6 +41,7 @@ MainObject::MainObject(QObject *parent) :QObject(parent) { export_metadata_pattern="%n_%j"; + export_escape_string="_"; // // Read Command Options @@ -73,6 +74,14 @@ MainObject::MainObject(QObject *parent) } cmd->setProcessed(i,true); } + if(cmd->key(i)=="--escape-string") { + if(cmd->value(i)!=SanitizePath(cmd->value(i))) { + fprintf(stderr,"rdxport: illegal character(s) in escape string\n"); + exit(256); + } + export_escape_string=cmd->value(i); + cmd->setProcessed(i,true); + } if(cmd->key(i)=="--group") { export_groups.push_back(cmd->value(i)); cmd->setProcessed(i,true); @@ -326,7 +335,7 @@ QString MainObject::ResolveOutputName(RDCart *cart,RDCut *cut, name.replace("%u",cart->userDefined()); name.replace("%y",QString().sprintf("%d",cart->year())); - QString ret=name; + QString ret=SanitizePath(name); int count=1; while(QFile::exists(export_output_to+"/"+ret+"."+exten)) { ret=name+QString().sprintf("[%d]",count++); @@ -336,6 +345,29 @@ QString MainObject::ResolveOutputName(RDCart *cart,RDCut *cut, } +QString MainObject::SanitizePath(const QString &pathname) const +{ + // + // Remove illegal characters from the filepath. + // (from https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#naming_conventions + // + QString ret=pathname; + + ret.replace("/",export_escape_string); + ret.replace(":",export_escape_string); + ret.replace("<",export_escape_string); + ret.replace(">",export_escape_string); + ret.replace(":",export_escape_string); + ret.replace("\"",export_escape_string); + ret.replace("\\",export_escape_string); + ret.replace("|",export_escape_string); + ret.replace("?",export_escape_string); + ret.replace("*",export_escape_string); + + return ret; +} + + void MainObject::Verbose(const QString &msg) { if(export_verbose) { diff --git a/utils/rdexport/rdexport.h b/utils/rdexport/rdexport.h index 4b52070a..46912562 100644 --- a/utils/rdexport/rdexport.h +++ b/utils/rdexport/rdexport.h @@ -49,6 +49,7 @@ class MainObject : public QObject void ExportCart(unsigned cartnum); void ExportCut(RDCart *cart,RDCut *cut); QString ResolveOutputName(RDCart *cart,RDCut *cut,const QString &exten); + QString SanitizePath(const QString &pathname) const; void Verbose(const QString &msg); std::vector export_start_carts; std::vector export_end_carts; @@ -60,6 +61,7 @@ class MainObject : public QObject RDStation *export_station; RDUser *export_user; bool export_verbose; + QString export_escape_string; };