#include "iso6937.h"
#include "stl_util.h"
#include "compose.hpp"
+#include "sub_assert.h"
#include <boost/locale.hpp>
#include <list>
#include <cmath>
static void
put_string (char* p, unsigned int n, string s)
{
- assert (s.length() <= n);
-
+ SUB_ASSERT (s.length() <= n);
+
memcpy (p, s.c_str (), s.length ());
memset (p + s.length(), ' ', n - s.length ());
}
static void
put_int_as_string (char* p, int v, unsigned int n)
{
- std::stringstream s;
+ locked_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);
+ SUB_ASSERT (s.str().length() == n);
put_string (p, s.str ());
}
boost::filesystem::path file_name
)
{
- assert (original_programme_title.size() <= 32);
- assert (original_episode_title.size() <= 32);
- assert (translated_programme_title.size() <= 32);
- assert (translated_episode_title.size() <= 32);
- assert (translator_name.size() <= 32);
- assert (translator_contact_details.size() <= 32);
- assert (creation_date.size() == 6);
- assert (revision_date.size() == 6);
- assert (revision_number <= 99);
- assert (country_of_origin.size() == 3);
- assert (publisher.size() <= 32);
- assert (editor_name.size() <= 32);
- assert (editor_contact_details.size() <= 32);
-
+ SUB_ASSERT (original_programme_title.size() <= 32);
+ SUB_ASSERT (original_episode_title.size() <= 32);
+ SUB_ASSERT (translated_programme_title.size() <= 32);
+ SUB_ASSERT (translated_episode_title.size() <= 32);
+ SUB_ASSERT (translator_name.size() <= 32);
+ SUB_ASSERT (translator_contact_details.size() <= 32);
+ SUB_ASSERT (creation_date.size() == 6);
+ SUB_ASSERT (revision_date.size() == 6);
+ SUB_ASSERT (revision_number <= 99);
+ SUB_ASSERT (country_of_origin.size() == 3);
+ SUB_ASSERT (publisher.size() <= 32);
+ SUB_ASSERT (editor_name.size() <= 32);
+ SUB_ASSERT (editor_contact_details.size() <= 32);
+
char* buffer = new char[1024];
memset (buffer, 0, 1024);
ofstream output (file_name.string().c_str ());
++lines;
}
}
-
+
/* Code page: 850 */
put_string (buffer + 0, "850");
/* Disk format code */
put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_NONE), 1);
/* Comment flag */
put_int_as_int (buffer + 15, tables.comment_enum_to_file (COMMENT_NO), 1);
-
+
/* Text */
string text;
bool italic = false;
bool underline = false;
-
+
for (list<Block>::const_iterator k = j->blocks.begin(); k != j->blocks.end(); ++k) {
if (k->underline && !underline) {
text += "\x82";
text += "\x81";
italic = false;
}
-
+
text += utf16_to_iso6937 (utf_to_utf<wchar_t> (k->text));
}
-
+
text += "\x8A";
-
+
if (text.length() > 111) {
text = text.substr (111);
}
-
+
while (text.length() < 112) {
text += "\x8F";
}
-
+
put_string (buffer + 16, text);
output.write (buffer, 128);