From 7212d6848ae2c8761d6e45e55b4d8126f45562de Mon Sep 17 00:00:00 2001 From: Diptanshu8 Date: Thu, 16 Mar 2017 15:58:38 +0530 Subject: [PATCH] Refactoring --- src/lib_ccx/matroska.c | 14 ++++++-------- src/lib_ccx/matroska.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib_ccx/matroska.c b/src/lib_ccx/matroska.c index d21e68a5..7b681ec7 100644 --- a/src/lib_ccx/matroska.c +++ b/src/lib_ccx/matroska.c @@ -622,11 +622,11 @@ void parse_segment_track_entry(struct matroska_ctx* mkv_ctx) { sub_track->lang_index = 0; sub_track->codec_id = codec_id; sub_track->sentence_count = 0; - for (int i = 0; i < mkv_ctx->sub_tracks_count; i++) if (strcmp((const char *)mkv_ctx->sub_tracks[i]->lang, (const char *)lang) == 0) sub_track->lang_index++; - mkv_ctx->sub_tracks[mkv_ctx->sub_tracks_count] = sub_track; + mkv_ctx->sub_tracks = realloc(mkv_ctx->sub_tracks, sizeof(struct matroska_sub_track*) * (mkv_ctx->sub_tracks_count + 1)); + mkv_ctx->sub_tracks[mkv_ctx->sub_tracks_count] = sub_track; mkv_ctx->sub_tracks_count++; } else @@ -763,7 +763,6 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra { char* filename = generate_filename_from_track(mkv_ctx, track); mprint("\nOutput file: %s", filename); - int size=0; int desc; #ifdef WIN32 desc = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, S_IREAD | S_IWRITE); @@ -798,11 +797,10 @@ void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* tra write(desc, " --> ", 5); write(desc, timestamp_end, strlen(timestamp_start)); write(desc, "\n", 1); - while (sentence->text[0] == '\n'){ + int size=0; + while (sentence->text+size=='\n' || sentence->text+size=='\r' ) size++; - sentence->text++; - } - write(desc, sentence->text, sentence->text_size-size); + write(desc, sentence->text+size, sentence->text_size-size); write(desc, "\n\n", 2); free(timestamp_start); @@ -939,7 +937,7 @@ int matroska_loop(struct lib_ccx_ctx *ctx) mkv_ctx->current_second = 0; mkv_ctx->filename = ctx->inputfile[ctx->current_file]; mkv_ctx->file = create_file(ctx); - mkv_ctx->sub_tracks = malloc(sizeof(struct matroska_sub_track*)); + mkv_ctx->sub_tracks = malloc(sizeof(struct matroska_sub_track**)); matroska_parse(mkv_ctx); diff --git a/src/lib_ccx/matroska.h b/src/lib_ccx/matroska.h index e67b4d34..82375912 100644 --- a/src/lib_ccx/matroska.h +++ b/src/lib_ccx/matroska.h @@ -248,7 +248,7 @@ char* generate_filename_from_track(struct matroska_ctx* mkv_ctx, struct matroska char* ass_ssa_sentence_erase_read_order(char* text); void save_sub_track(struct matroska_ctx* mkv_ctx, struct matroska_sub_track* track); void free_sub_track(struct matroska_sub_track* track); -void matroska_save_all(struct matroska_ctx* mkv_ctx); +void matroska_save_all(struct matroska_ctx* mkv_ctx,char* lang); void matroska_free_all(struct matroska_ctx* mkv_ctx); void matroska_parse(struct matroska_ctx* mkv_ctx); FILE* create_file(struct lib_ccx_ctx *ctx);