From 5877be91301e5dd54ca125c0acd7bfb1ecc3dcd6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 20:35:54 +0000 Subject: No-op; remove trailing whitespace. --- src/stl_binary_writer.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/stl_binary_writer.cc') diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index 43b0adf..b9bd7e0 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -63,7 +63,7 @@ static void put_string (char* p, unsigned int n, string s) { assert (s.length() <= n); - + memcpy (p, s.c_str (), s.length ()); memset (p + s.length(), ' ', n - s.length ()); } @@ -123,7 +123,7 @@ sub::write_stl_binary ( assert (publisher.size() <= 32); assert (editor_name.size() <= 32); assert (editor_contact_details.size() <= 32); - + char* buffer = new char[1024]; memset (buffer, 0, 1024); ofstream output (file_name.string().c_str ()); @@ -144,7 +144,7 @@ sub::write_stl_binary ( ++lines; } } - + /* Code page: 850 */ put_string (buffer + 0, "850"); /* Disk format code */ @@ -256,12 +256,12 @@ sub::write_stl_binary ( 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::const_iterator k = j->blocks.begin(); k != j->blocks.end(); ++k) { if (k->underline && !underline) { text += "\x82"; @@ -277,20 +277,20 @@ sub::write_stl_binary ( text += "\x81"; italic = false; } - + text += utf16_to_iso6937 (utf_to_utf (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); -- cgit v1.2.3 From 5a843c4c224051237105a6e8de472ae9a216c001 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 16 Dec 2015 20:40:21 +0000 Subject: Replace use of cassert with exceptions. --- src/exceptions.cc | 30 ++++++++++++++++++++++++++++++ src/exceptions.h | 6 ++++++ src/stl_binary_tables.cc | 4 ++-- src/stl_binary_writer.cc | 31 ++++++++++++++++--------------- src/sub_assert.h | 22 ++++++++++++++++++++++ src/wscript | 1 + 6 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 src/exceptions.cc create mode 100644 src/sub_assert.h (limited to 'src/stl_binary_writer.cc') diff --git a/src/exceptions.cc b/src/exceptions.cc new file mode 100644 index 0000000..f33a1e2 --- /dev/null +++ b/src/exceptions.cc @@ -0,0 +1,30 @@ +/* + Copyright (C) 2014-2015 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "compose.hpp" +#include "exceptions.h" + +using std::string; +using namespace sub; + +ProgrammingError::ProgrammingError (string file, int line) + : MessageError (String::compose ("Programming error at %1:%2", file, line)) +{ + +} diff --git a/src/exceptions.h b/src/exceptions.h index 62be0d5..5995942 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -99,6 +99,12 @@ public: {} }; +class ProgrammingError : public MessageError +{ +public: + ProgrammingError (std::string file, int line); +}; + } #endif diff --git a/src/stl_binary_tables.cc b/src/stl_binary_tables.cc index f843421..db623bf 100644 --- a/src/stl_binary_tables.cc +++ b/src/stl_binary_tables.cc @@ -19,8 +19,8 @@ #include "stl_binary_tables.h" #include "exceptions.h" +#include "sub_assert.h" #include "compose.hpp" -#include using std::map; using std::string; @@ -55,7 +55,7 @@ enum_to_file (E k, map > m) } } - assert (false); + SUB_ASSERT (false); return F (); } diff --git a/src/stl_binary_writer.cc b/src/stl_binary_writer.cc index b9bd7e0..aa8943c 100644 --- a/src/stl_binary_writer.cc +++ b/src/stl_binary_writer.cc @@ -26,6 +26,7 @@ #include "iso6937.h" #include "stl_util.h" #include "compose.hpp" +#include "sub_assert.h" #include #include #include @@ -62,7 +63,7 @@ put_string (char* p, string s) 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 ()); @@ -76,7 +77,7 @@ put_int_as_string (char* p, int v, unsigned int n) 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 ()); } @@ -110,19 +111,19 @@ sub::write_stl_binary ( 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); diff --git a/src/sub_assert.h b/src/sub_assert.h new file mode 100644 index 0000000..67c8abe --- /dev/null +++ b/src/sub_assert.h @@ -0,0 +1,22 @@ +/* + Copyright (C) 2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "exceptions.h" + +#define SUB_ASSERT(x) if (!(x)) throw ProgrammingError (__FILE__, __LINE__); diff --git a/src/wscript b/src/wscript index a054a91..eafd1c9 100644 --- a/src/wscript +++ b/src/wscript @@ -15,6 +15,7 @@ def build(bld): colour.cc dcp_reader.cc effect.cc + exceptions.cc font_size.cc interop_dcp_reader.cc iso6937.cc -- cgit v1.2.3