Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib_ccx/lib_ccx.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct ccx_s_teletext_config {
// uint8_t se_mode : 1; // search engine compatible mode => Uses CCExtractor's write_format
// uint64_t utc_refvalue; // UTC referential value => Moved to ccx_decoders_common, so can be used for other decoders (608/xds) too
uint16_t user_page; // Page selected by user, which MIGHT be different to 'page' depending on autodetection stuff
int sentence_cap;
};
#define MAX_PID 65536
struct lib_ccx_ctx
Expand Down
2 changes: 2 additions & 0 deletions src/lib_ccx/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,8 @@ void parse_parameters (struct ccx_s_options *opt, int argc, char *argv[])
strcmp (argv[i],"-sc")==0)
{
ccx_options.sentence_cap=1;
// Teletext needs to be set as well
tlt_config.sentence_cap = 1;
continue;
}
if ((strcmp (argv[i],"--capfile")==0 ||
Expand Down
82 changes: 77 additions & 5 deletions src/lib_ccx/telxcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Werner Brückner -- Teletext in digital television
#include "hamming.h"
#include "teletext.h"
#include <signal.h>
#include "ccx_common_char_encoding.c"
#ifdef I18N
#include <libintl.h>
#include <locale.h>
Expand Down Expand Up @@ -235,6 +236,22 @@ static unsigned ucs2_buffer_prev_used=0;
static uint64_t prev_hide_timestamp;
static uint64_t prev_show_timestamp;

char cap_telx(const char *a)
{ static int flag=1;

if(*a == '?' || *a=='.' || *a == '!' || *a == ':')
{flag = 1; return *a; }

if(flag && (*a != '?' || *a != '.' || *a != '!' || *a != ':'))
{
flag = 0;
return cctoupper(*a);
}
else
return cctolower(*a);

}

void page_buffer_add_string (const char *s)
{
if (page_buffer_cur_size<(page_buffer_cur_used+strlen (s)+1))
Expand All @@ -245,9 +262,22 @@ void page_buffer_add_string (const char *s)
if (!page_buffer_cur)
fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory to process teletext page.\n");
}
memcpy (page_buffer_cur+page_buffer_cur_used, s, strlen (s));
page_buffer_cur_used+=strlen (s);

if(strlen(s) <= 2 && ((*s >= 'A' && *s <= 'Z') || (*s >= 'a' && *s <= 'z')) && tlt_config.sentence_cap || (*s == '.'))
{char t = cap_telx(s);
s = &t;
memcpy (page_buffer_cur+page_buffer_cur_used, s,1);

page_buffer_cur_used+=1;
page_buffer_cur[page_buffer_cur_used]=0;
}

else
{memcpy (page_buffer_cur+page_buffer_cur_used, s,strlen(s));

page_buffer_cur_used+=strlen(s);
page_buffer_cur[page_buffer_cur_used]=0;
}
}

void ucs2_buffer_add_char (uint64_t c)
Expand Down Expand Up @@ -460,6 +490,7 @@ void process_page(struct lib_ccx_ctx *ctx, teletext_page_t *page) {
timecode_show[12] = 0;
timestamp_to_srttime(page->hide_timestamp, timecode_hide);
timecode_hide[12] = 0;
int i_flag=0; // flag to detect presence of " I " - matter of Capitalization

// process data
for (uint8_t row = 1; row < 25; row++) {
Expand Down Expand Up @@ -588,9 +619,50 @@ void process_page(struct lib_ccx_ctx *ctx, teletext_page_t *page) {


if (v >= 0x20) {
//if (ctx->wbout1.fh!=-1) fdprintf(ctx->wbout1.fh, "%s", u);
page_buffer_add_string (u);
if (ccx_options.gui_mode_reports) // For now we just handle the easy stuff

if(u[0] == ' '){ //just to detect presence of " I "

if(i_flag == 0){
i_flag = 1;
continue;
}
else if (i_flag == 2)
i_flag++;
}

if(i_flag == 1 && u[0] == 'I'){
i_flag = 2;
continue;
}

if(i_flag==3 && u[0]== ' '){ //" I " - detected. Add " I ".
char p[3] = {' ','I',' '} ;
page_buffer_add_string(p);
i_flag=0;
continue;
}

if(i_flag == 2 && u[0]!=' '){ //" I" detected earlier but next char i.e. u,
char temp_1[2] = {'I','\0'}; // contains a char, therefore "I" is a part of word.
char temp_2[2] = {' ','\0'};
page_buffer_add_string(temp_2); //recover string that was skipped order to detect "I"
page_buffer_add_string(temp_1);
page_buffer_add_string(u); //after adding skipped string, add current char now
i_flag=0;
continue;
}

if(i_flag==1){
char l[2]= {' ','\0'};
page_buffer_add_string(l);
i_flag=0;
}


page_buffer_add_string (u); //u contains non-"I" character here.add that.
i_flag=0;

if (ccx_options.gui_mode_reports) // For now we just handle the easy stuff
fprintf (stderr,"%s",u);
}
}
Expand Down