summaryrefslogtreecommitdiff
path: root/src/stl_binary_writer.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-29 14:20:17 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-29 14:20:17 +0100
commitf6fb2090f4180f8cd507d694f7eb663b3f25d2f0 (patch)
tree0df38a2b6377f12c3760197c7a107984e1e3407f /src/stl_binary_writer.cc
parentaebf2cb7812c8f593b85182611b587e6014aefc6 (diff)
Separate out STL binary tables so that writer can use them; start of writer.
Diffstat (limited to 'src/stl_binary_writer.cc')
-rw-r--r--src/stl_binary_writer.cc45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc
index 34e4d73..8ec8c67 100644
--- a/src/stl_binary_writer.cc
+++ b/src/stl_binary_writer.cc
@@ -17,15 +17,18 @@
*/
+#include "stl_binary_writer.h"
+#include "compose.hpp"
#include <list>
#include <cmath>
#include <fstream>
-#include "stl_binary_writer.h"
-#include "compose.hpp"
+#include <iomanip>
using std::list;
using std::ofstream;
using std::string;
+using std::setw;
+using std::setfill;
using namespace sub;
static void
@@ -35,10 +38,24 @@ put_string (char* p, string s)
}
static void
-put_string (char* p, int n, string s)
+put_string (char* p, unsigned int n, string s)
{
+ assert (s.length() <= n);
+
memcpy (p, s.c_str (), s.length ());
- memset (p + s.length(), ' ', s.length () - n);
+ memset (p + s.length(), ' ', n - s.length ());
+}
+
+static void
+put_int (char* p, int v, unsigned int n)
+{
+ std::stringstream s;
+ /* Be careful to ensure we get no thousands separators */
+ s.imbue (std::locale::classic ());
+ s << setw (n) << setfill ('0');
+ s << v;
+ assert (s.str().length() == n);
+ put_string (p, s.str ());
}
/** @param language ISO 3-character country code for the language of the subtitles */
@@ -46,7 +63,7 @@ void
sub::write_stl_binary (
list<Subtitle> subtitles,
float frames_per_second,
- string language,
+ Language language,
string original_programme_title,
string original_episode_title,
string translated_programme_title,
@@ -63,7 +80,6 @@ sub::write_stl_binary (
boost::filesystem::path file_name
)
{
- assert (language.size() == 3);
assert (original_programme_title.size() <= 32);
assert (original_episode_title.size() <= 32);
assert (translated_programme_title.size() <= 32);
@@ -80,6 +96,7 @@ sub::write_stl_binary (
char* buffer = new char[1024];
ofstream output (file_name.string().c_str ());
+ STLBinaryTables tables;
/* Code page: 850 */
put_string (buffer + 0, "850");
@@ -89,7 +106,7 @@ sub::write_stl_binary (
put_string (buffer + 11, "0");
/* Character code table: Latin (ISO 6937) */
put_string (buffer + 12, "00");
- put_string (buffer + 14, language);
+ put_string (buffer + 14, tables.language_enum_to_file (language));
put_string (buffer + 16, 32, original_programme_title);
put_string (buffer + 48, 32, original_episode_title);
put_string (buffer + 80, 32, translated_programme_title);
@@ -100,11 +117,11 @@ sub::write_stl_binary (
put_string (buffer + 208, "0000000000000000");
put_string (buffer + 224, creation_date);
put_string (buffer + 230, revision_date);
- put_string (buffer + 236, String::compose ("%02d", revision_number));
+ put_int (buffer + 236, revision_number, 2);
/* TTI blocks */
- put_string (buffer + 238, String::compose ("%05d", subtitles.size ()));
+ put_int (buffer + 238, subtitles.size (), 5);
/* Total number of subtitles */
- put_string (buffer + 243, String::compose ("%05d", subtitles.size ()));
+ put_int (buffer + 243, subtitles.size (), 5);
/* Total number of subtitle groups */
put_string (buffer + 248, "000");
/* Maximum number of displayable characters in any text row */
@@ -123,10 +140,10 @@ sub::write_stl_binary (
put_string (buffer + 272, "1");
/* Disk sequence number */
put_string (buffer + 273, "1");
- put_string (buffer + 274, country_of_origin);
- put_string (buffer + 277, publisher);
- put_string (buffer + 309, editor_name);
- put_string (buffer + 341, editor_contact_details);
+ put_string (buffer + 274, 32, country_of_origin);
+ put_string (buffer + 277, 32, publisher);
+ put_string (buffer + 309, 32, editor_name);
+ put_string (buffer + 341, 32, editor_contact_details);
output.write (buffer, 1024);