Skip to content

Commit 1a13bbb

Browse files
authored
[FIX] Issues in Tests (#1638)
* fix: add ucla checks for millis_separator * fix: reassign back profane and capitalization lists to c * fix: C formatting * fix(rust): clippy warnings
1 parent 90f9f0a commit 1a13bbb

File tree

10 files changed

+68
-27
lines changed

10 files changed

+68
-27
lines changed

src/lib_ccx/ccx_encoders_helpers.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
// userdefined rgb color
1414
unsigned char usercolor_rgb[8] = "";
1515

16-
struct word_list
17-
{
18-
char **words;
19-
size_t len;
20-
size_t capacity;
21-
};
22-
2316
struct word_list capitalization_list = {
2417
.words = NULL,
2518
.len = 0,

src/lib_ccx/ccx_encoders_helpers.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "ccx_decoders_structs.h"
77
#include "ccx_decoders_608.h"
88
#include "ccx_encoders_common.h"
9-
#include <png.h>
109

1110
extern struct word_list capitalization_list;
1211
extern struct word_list profane;
@@ -15,6 +14,13 @@ extern const char *profane_builtin[];
1514

1615
extern unsigned char usercolor_rgb[8];
1716

17+
struct word_list
18+
{
19+
char **words;
20+
size_t len;
21+
size_t capacity;
22+
};
23+
1824
struct ccx_encoders_helpers_settings_t
1925
{
2026
int trim_subs;
@@ -43,6 +49,4 @@ void shell_sort(void *base, int nb, size_t size, int (*compar)(const void *p1, c
4349

4450
void ccx_encoders_helpers_perform_shellsort_words(void);
4551
void ccx_encoders_helpers_setup(enum ccx_encoding_type encoding, int no_font_color, int no_type_setting, int trim_subs);
46-
47-
int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, uint8_t depth);
4852
#endif

src/lib_ccx/ccx_encoders_spupng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ccfont2.xbm" // CC font from libzvbi
22
#include "ccx_common_common.h"
3-
#include "ccx_encoders_common.h"
3+
#include "ccx_encoders_spupng.h"
44
#include <png.h>
55
#include <ft2build.h>
66
#include <math.h>

src/lib_ccx/ccx_encoders_spupng.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <png.h>
2+
#include "ccx_encoders_common.h"
3+
4+
int mapclut_paletee(png_color *palette, png_byte *alpha, uint32_t *clut, uint8_t depth);

src/rust/build.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@ fn main() {
3333
"gop_time_code",
3434
"ccx_s_options",
3535
"ccx_s_teletext_config",
36-
"ccx_output_format",
37-
"ccx_boundary_time",
3836
"ccx_output_date_format",
3937
"ccx_encoding_type",
40-
"ccx_output_date_format",
4138
"ccx_decoder_608_settings",
4239
"ccx_decoder_608_report",
43-
"ccx_output_format",
4440
"uint8_t",
41+
"word_list",
4542
]);
4643

4744
#[cfg(feature = "hardsubx_ocr")]

src/rust/lib_ccxr/src/common/options.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,23 @@ impl Default for Options {
639639
}
640640
}
641641
}
642+
643+
impl Options {
644+
pub fn millis_separator(&self) -> char {
645+
if self.ucla {
646+
'.'
647+
} else {
648+
self.date_format.millis_separator()
649+
}
650+
}
651+
}
652+
653+
impl EncoderConfig {
654+
pub fn millis_separator(&self) -> char {
655+
if self.ucla {
656+
'.'
657+
} else {
658+
self.date_format.millis_separator()
659+
}
660+
}
661+
}

src/rust/src/common.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl FromRust<Options> for ccx_s_options {
6969
self.settings_dtvcc = options.settings_dtvcc.to_ctype();
7070
self.is_608_enabled = options.is_608_enabled as _;
7171
self.is_708_enabled = options.is_708_enabled as _;
72-
self.millis_separator = options.date_format.millis_separator() as _;
72+
self.millis_separator = options.millis_separator() as _;
7373
self.binary_concat = options.binary_concat as _;
7474
self.use_gop_as_pts = if let Some(usegops) = options.use_gop_as_pts {
7575
if usegops {
@@ -257,7 +257,7 @@ impl CType2<ccx_s_teletext_config, &Options> for TeletextConfig {
257257
encoding: value.enc_cfg.encoding.to_ctype() as _,
258258
nofontcolor: self.nofontcolor.into(),
259259
nohtmlescape: self.nohtmlescape.into(),
260-
millis_separator: self.date_format.millis_separator() as _,
260+
millis_separator: value.millis_separator() as _,
261261
latrusmap: self.latrusmap.into(),
262262
};
263263
config.set_verbose(self.verbose.into());
@@ -571,7 +571,7 @@ impl CType<encoder_cfg> for EncoderConfig {
571571
ucla: self.ucla as _,
572572
encoding: self.encoding as _,
573573
date_format: self.date_format.to_ctype(),
574-
millis_separator: self.date_format.millis_separator() as _,
574+
millis_separator: self.millis_separator() as _,
575575
autodash: self.autodash as _,
576576
trim_subs: self.trim_subs as _,
577577
sentence_cap: self.sentence_cap as _,
@@ -625,3 +625,13 @@ impl CType<encoder_cfg> for EncoderConfig {
625625
}
626626
}
627627
}
628+
629+
impl CType<word_list> for Vec<String> {
630+
unsafe fn to_ctype(&self) -> word_list {
631+
word_list {
632+
words: string_to_c_chars(self.clone()),
633+
len: self.len(),
634+
capacity: self.capacity(),
635+
}
636+
}
637+
}

src/rust/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::{io::Write, os::raw::c_char, os::raw::c_int};
2929
use args::Args;
3030
use bindings::*;
3131
use clap::{error::ErrorKind, Parser};
32-
use common::{CType2, FromRust};
32+
use common::{CType, CType2, FromRust};
3333
use decoder::Dtvcc;
3434
use lib_ccxr::{common::Options, teletext::TeletextConfig, util::log::ExitCause};
3535
use parser::OptionsExt;
@@ -60,6 +60,8 @@ extern "C" {
6060
static mut MPEG_CLOCK_FREQ: c_int;
6161
static mut tlt_config: ccx_s_teletext_config;
6262
static mut ccx_options: ccx_s_options;
63+
static mut capitalization_list: word_list;
64+
static mut profane: word_list;
6365
}
6466

6567
/// Initialize env logger with custom format, using stdout as target
@@ -253,22 +255,30 @@ pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_ch
253255
}
254256
};
255257

256-
let mut capitalization_list: Vec<String> = Vec::new();
257-
let mut profane: Vec<String> = Vec::new();
258+
let mut _capitalization_list: Vec<String> = Vec::new();
259+
let mut _profane: Vec<String> = Vec::new();
258260

259261
let mut opt = Options::default();
260262
let mut _tlt_config = TeletextConfig::default();
261263

262264
opt.parse_parameters(
263265
&args,
264266
&mut _tlt_config,
265-
&mut capitalization_list,
266-
&mut profane,
267+
&mut _capitalization_list,
268+
&mut _profane,
267269
);
268270
tlt_config = _tlt_config.to_ctype(&opt);
271+
269272
// Convert the rust struct (CcxOptions) to C struct (ccx_s_options), so that it can be used by the C code
270273
ccx_options.copy_from_rust(opt);
271274

275+
if !_capitalization_list.is_empty() {
276+
capitalization_list = _capitalization_list.to_ctype();
277+
}
278+
if !_profane.is_empty() {
279+
profane = _profane.to_ctype();
280+
}
281+
272282
ExitCause::Ok.exit_code()
273283
}
274284

src/rust/src/parser.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,11 +1222,9 @@ impl OptionsExt for Options {
12221222
tlt_config.page = Cell::new(TeletextPageNumber::from(tlt_config.user_page));
12231223
}
12241224

1225-
let mut millis_separator = ',';
12261225
// Red Hen/ UCLA Specific stuff
12271226
if args.ucla {
12281227
self.ucla = true;
1229-
millis_separator = '.';
12301228
self.enc_cfg.no_bom = true;
12311229

12321230
if !self.transcript_settings.is_final {
@@ -1291,11 +1289,15 @@ impl OptionsExt for Options {
12911289
}
12921290

12931291
if args.sects {
1294-
self.date_format = TimestampFormat::Seconds { millis_separator };
1292+
self.date_format = TimestampFormat::Seconds {
1293+
millis_separator: ',',
1294+
};
12951295
}
12961296

12971297
if args.datets {
1298-
self.date_format = TimestampFormat::Date { millis_separator };
1298+
self.date_format = TimestampFormat::Date {
1299+
millis_separator: ',',
1300+
};
12991301
}
13001302

13011303
if args.teletext {

src/rust/wrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
#include "../lib_ccx/lib_ccx.h"
1111
#include "../lib_ccx/hardsubx.h"
1212
#include "../lib_ccx/utility.h"
13+
#include "../lib_ccx/ccx_encoders_helpers.h"

0 commit comments

Comments
 (0)