a better fix for CUE/TOC string escaping: if the text is not Latin-1 already, reject it because TOC certainly cannot handle UTF-8 and CUE is probably better off without it too
git-svn-id: svn://localhost/ardour2/branches/3.0@11320 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
bc3e1a2122
commit
9a21640567
|
@ -185,7 +185,7 @@ class ExportHandler : public ExportElementFactory
|
|||
void write_index_info_toc (CDMarkerStatus & status);
|
||||
|
||||
void frames_to_cd_frames_string (char* buf, framepos_t when);
|
||||
std::string toc_escape_string (const std::string&);
|
||||
std::string cd_marker_file_escape_string (const std::string&);
|
||||
|
||||
int cue_tracknum;
|
||||
int cue_indexnum;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "ardour/export_handler.h"
|
||||
|
||||
#include <glibmm.h>
|
||||
#include <glibmm/convert.h>
|
||||
|
||||
#include "pbd/convert.h"
|
||||
#include "pbd/filesystem.h"
|
||||
|
@ -268,6 +269,7 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp
|
|||
{
|
||||
string filepath = get_cd_marker_filename(filename, format);
|
||||
|
||||
try {
|
||||
void (ExportHandler::*header_func) (CDMarkerStatus &);
|
||||
void (ExportHandler::*track_func) (CDMarkerStatus &);
|
||||
void (ExportHandler::*index_func) (CDMarkerStatus &);
|
||||
|
@ -370,6 +372,14 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp
|
|||
|
||||
(this->*track_func) (status);
|
||||
}
|
||||
|
||||
} catch (std::exception& e) {
|
||||
error << string_compose (_("an error occured while writing a TOC/CUE file: %1"), e.what()) << endmsg;
|
||||
::unlink (filepath.c_str());
|
||||
} catch (Glib::Exception& e) {
|
||||
error << string_compose (_("an error occured while writing a TOC/CUE file: %1"), e.what()) << endmsg;
|
||||
::unlink (filepath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
|
@ -440,7 +450,7 @@ ExportHandler::write_toc_header (CDMarkerStatus & status)
|
|||
|
||||
status.out << "CD_DA" << endl;
|
||||
status.out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl;
|
||||
status.out << " LANGUAGE 0 {" << endl << " TITLE " << toc_escape_string (title) << endl ;
|
||||
status.out << " LANGUAGE 0 {" << endl << " TITLE " << cd_marker_file_escape_string (title) << endl ;
|
||||
status.out << " PERFORMER \"\"" << endl << " }" << endl << "}" << endl;
|
||||
}
|
||||
|
||||
|
@ -469,15 +479,15 @@ ExportHandler::write_track_info_cue (CDMarkerStatus & status)
|
|||
|
||||
}
|
||||
if (status.marker->name() != "") {
|
||||
status.out << " TITLE \"" << status.marker->name() << "\"" << endl;
|
||||
status.out << " TITLE " << cd_marker_file_escape_string (status.marker->name()) << endl;
|
||||
}
|
||||
|
||||
if (status.marker->cd_info.find("performer") != status.marker->cd_info.end()) {
|
||||
status.out << " PERFORMER \"" << status.marker->cd_info["performer"] << "\"" << endl;
|
||||
status.out << " PERFORMER " << cd_marker_file_escape_string (status.marker->cd_info["performer"]) << endl;
|
||||
}
|
||||
|
||||
if (status.marker->cd_info.find("composer") != status.marker->cd_info.end()) {
|
||||
status.out << " SONGWRITER \"" << status.marker->cd_info["composer"] << "\"" << endl;
|
||||
status.out << " SONGWRITER " << cd_marker_file_escape_string (status.marker->cd_info["composer"]) << endl;
|
||||
}
|
||||
|
||||
if (status.track_position != status.track_start_frame) {
|
||||
|
@ -515,16 +525,16 @@ ExportHandler::write_track_info_toc (CDMarkerStatus & status)
|
|||
}
|
||||
|
||||
status.out << "CD_TEXT {" << endl << " LANGUAGE 0 {" << endl << " TITLE "
|
||||
<< toc_escape_string (status.marker->name()) << endl;
|
||||
<< cd_marker_file_escape_string (status.marker->name()) << endl;
|
||||
|
||||
if (status.marker->cd_info.find("performer") != status.marker->cd_info.end()) {
|
||||
status.out << " PERFORMER " << toc_escape_string (status.marker->cd_info["performer"]);
|
||||
status.out << " PERFORMER " << cd_marker_file_escape_string (status.marker->cd_info["performer"]);
|
||||
} else {
|
||||
status.out << " PERFORMER \"\"";
|
||||
}
|
||||
|
||||
if (status.marker->cd_info.find("composer") != status.marker->cd_info.end()) {
|
||||
status.out << " COMPOSER " << toc_escape_string (status.marker->cd_info["composer"]) << endl;
|
||||
status.out << " COMPOSER " << cd_marker_file_escape_string (status.marker->cd_info["composer"]) << endl;
|
||||
}
|
||||
|
||||
if (status.marker->cd_info.find("isrc") != status.marker->cd_info.end()) {
|
||||
|
@ -538,7 +548,7 @@ ExportHandler::write_track_info_toc (CDMarkerStatus & status)
|
|||
status.out << " }" << endl << "}" << endl;
|
||||
|
||||
frames_to_cd_frames_string (buf, status.track_position);
|
||||
status.out << "FILE " << toc_escape_string (status.filename) << ' ' << buf;
|
||||
status.out << "FILE " << cd_marker_file_escape_string (status.filename) << ' ' << buf;
|
||||
|
||||
frames_to_cd_frames_string (buf, status.track_duration);
|
||||
status.out << buf << endl;
|
||||
|
@ -585,24 +595,27 @@ ExportHandler::frames_to_cd_frames_string (char* buf, framepos_t when)
|
|||
}
|
||||
|
||||
std::string
|
||||
ExportHandler::toc_escape_string (const std::string& txt)
|
||||
ExportHandler::cd_marker_file_escape_string (const std::string& txt)
|
||||
{
|
||||
Glib::ustring utxt (txt);
|
||||
Glib::ustring out;
|
||||
Glib::ustring check (txt);
|
||||
std::string out;
|
||||
char buf[5];
|
||||
|
||||
if (!check.is_ascii()) {
|
||||
throw Glib::ConvertError (Glib::ConvertError::NO_CONVERSION, string_compose (_("Cannot convert %1 to Latin-1 text"), txt));
|
||||
}
|
||||
|
||||
out = '"';
|
||||
|
||||
for (Glib::ustring::iterator c = utxt.begin(); c != utxt.end(); ++c) {
|
||||
for (std::string::const_iterator c = txt.begin(); c != txt.end(); ++c) {
|
||||
|
||||
if ((*c) == '"') {
|
||||
out += "\\\"";
|
||||
} else if ((*c) == '\\') {
|
||||
out += "\\034";
|
||||
} else if (g_unichar_isprint (*c)) {
|
||||
out += "\\134";
|
||||
} else if (isprint (*c)) {
|
||||
out += *c;
|
||||
} else {
|
||||
/* this isn't really correct */
|
||||
snprintf (buf, sizeof (buf), "\\%03o", *c);
|
||||
out += buf;
|
||||
}
|
||||
|
@ -610,7 +623,7 @@ ExportHandler::toc_escape_string (const std::string& txt)
|
|||
|
||||
out += '"';
|
||||
|
||||
return std::string (out);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace ARDOUR
|
||||
|
|
Loading…
Reference in New Issue
Block a user