INT CommandExpand (LPTSTR param) { /*cmd is the command that was given, in this case it will always be "expand" param is whatever is given after the command*/ LPTSTR *arg = NULL; INT args; INT i; INT nEvalArgs = 0; /* nunber of evaluated arguments */ DWORD dwFlags = 0; DWORD dwAttrFlags = 0; DWORD dwFiles = 0; LONG ch; TCHAR szOrginalArg[MAX_PATH]; /*checks the first two chars of param to see if it is /? this however allows the following command to not show help "expand frog.cab /?" */ if (!StringsLoaded) { LoadStrings(); } if (!_tcsncmp (param, _T("/?"), 2)) { //ConOutResPaging(TRUE,STRING_DEL_HELP1); return 0; } nErrorLevel = 0; arg = split (param, &args, FALSE); if (args == 0) { /* only command given */ error_req_param_missing (); freep (arg); return 1; } /* check for options anywhere in command line */ for (i = 0; i < args; i++) { if (*arg[i] == _T('-')) { /*found a command, but check to make sure it has something after it*/ if (_tcslen (arg[i]) >= 2) { ch = _totupper (arg[i][1]); if (ch == _T('R')) { dwFlags |= EXPAND_RENAME; } else if (ch == _T('D')) { dwFlags |= EXPAND_DISPLAY; } else if (ch == _T('F')) { dwFlags |= EXPAND_FILES; } else if (ch == _T('Y')) { dwFlags |= EXPAND_YES; } } nEvalArgs++; } } /* there are only options on the command line --> error!!! there is the same number of args as there is flags, so none of the args were filenames*/ if (args == nEvalArgs) { error_req_param_missing (); freep (arg); return 1; } /* check for filenames anywhere in command line */ for (i = 0; i < args && !(dwFiles & 0x80000000); i++) { /*this checks to see if it isnt a flag, if it isnt, we assume it is a file name*/ if((*arg[i] == _T('/')) || (*arg[i] == _T('-'))) continue; /* We want to make a copies of the argument */ freep (arg); /*Based on MS cmd, we only tell what files are being deleted when /S is used */ if (dwFlags & DEL_TOTAL) { dwFiles &= 0x7fffffff; if (dwFiles < 2) { ConOutResPrintf(STRING_DEL_HELP3, dwFiles); } else { ConOutResPrintf(STRING_DEL_HELP4, dwFiles); } } return 0; }
INT cmd_time (LPTSTR param) { LPTSTR *arg; INT argc; INT i; INT nTimeString = -1; if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_TIME_HELP1); return 0; } nErrorLevel = 0; /* build parameter array */ arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) { if (_tcsicmp (arg[i], _T("/t")) == 0) { /* Display current time in short format */ SYSTEMTIME st; TCHAR szTime[20]; GetLocalTime(&st); FormatTime(szTime, &st); ConOutPuts(szTime); freep(arg); return 0; } if ((*arg[i] != _T('/')) && (nTimeString == -1)) nTimeString = i; } if (nTimeString == -1) { ConOutResPrintf(STRING_LOCALE_HELP1); ConOutPrintf(_T(": %s\n"), GetTimeString()); } while (1) { if (nTimeString == -1) { TCHAR s[40]; ConOutResPuts(STRING_TIME_HELP2); ConInString (s, 40); TRACE ("\'%s\'\n", debugstr_aw(s)); while (*s && s[_tcslen (s) - 1] < _T(' ')) s[_tcslen(s) - 1] = _T('\0'); if (ParseTime (s)) { freep (arg); return 0; } } else { if (ParseTime (arg[nTimeString])) { freep (arg); return 0; } /* force input the next time around. */ nTimeString = -1; } ConErrResPuts(STRING_TIME_ERROR1); nErrorLevel = 1; } freep (arg); return 0; }
INT CommandChoice (LPTSTR param) { LPTSTR lpOptions; TCHAR Options[6]; LPTSTR lpText = NULL; BOOL bNoPrompt = FALSE; BOOL bCaseSensitive = FALSE; BOOL bTimeout = FALSE; INT nTimeout = 0; TCHAR cDefault = _T('\0'); INPUT_RECORD ir; LPTSTR p, np; LPTSTR *arg; INT argc; INT i; INT val; INT GCret; TCHAR Ch; DWORD amount,clk; LoadString(CMD_ModuleHandle, STRING_CHOICE_OPTION, Options, 4); lpOptions = Options; if (_tcsncmp (param, _T("/?"), 2) == 0) { ConOutResPaging(TRUE,STRING_CHOICE_HELP); return 0; } /* retrieve text */ p = param; while (TRUE) { if (*p == _T('\0')) break; if (*p != _T('/')) { lpText = p; break; } np = _tcschr (p, _T(' ')); if (!np) break; p = np + 1; } /* build parameter array */ arg = split (param, &argc, FALSE); /* evaluate arguments */ if (argc > 0) { for (i = 0; i < argc; i++) { if (_tcsnicmp (arg[i], _T("/c"), 2) == 0) { if (arg[i][2] == _T(':')) lpOptions = &arg[i][3]; else lpOptions = &arg[i][2]; if (_tcslen (lpOptions) == 0) { ConErrResPuts(STRING_CHOICE_ERROR); freep (arg); return 1; } } else if (_tcsnicmp (arg[i], _T("/n"), 2) == 0) { bNoPrompt = TRUE; } else if (_tcsnicmp (arg[i], _T("/s"), 2) == 0) { bCaseSensitive = TRUE; } else if (_tcsnicmp (arg[i], _T("/t"), 2) == 0) { LPTSTR s; if (arg[i][2] == _T(':')) { cDefault = arg[i][3]; s = &arg[i][4]; } else { cDefault = arg[i][2]; s = &arg[i][3]; } if (*s != _T(',')) { ConErrResPuts(STRING_CHOICE_ERROR_TXT); freep (arg); return 1; } s++; nTimeout = _ttoi(s); bTimeout = TRUE; } else if (arg[i][0] == _T('/')) { ConErrResPrintf(STRING_CHOICE_ERROR_OPTION, arg[i]); freep (arg); return 1; } } } /* print text */ if (lpText) ConOutPrintf (_T("%s"), lpText); /* print options */ if (bNoPrompt == FALSE) { ConOutPrintf (_T("[%c"), lpOptions[0]); for (i = 1; (unsigned)i < _tcslen (lpOptions); i++) ConOutPrintf (_T(",%c"), lpOptions[i]); ConOutPrintf (_T("]?")); } ConInFlush (); if(!bTimeout) { while (TRUE) { ConInKey (&ir); val = IsKeyInString (lpOptions, #ifdef _UNICODE ir.Event.KeyEvent.uChar.UnicodeChar, #else ir.Event.KeyEvent.uChar.AsciiChar, #endif bCaseSensitive); if (val >= 0) { ConOutPrintf (_T("%c\n"), lpOptions[val]); nErrorLevel = val + 1; break; } Beep (440, 50); } freep (arg); TRACE ("ErrorLevel: %d\n", nErrorLevel); return 0; } clk = GetTickCount (); amount = nTimeout*1000; loop: GCret = GetCharacterTimeout (&Ch, amount - (GetTickCount () - clk)); switch (GCret) { case GC_TIMEOUT: TRACE ("GC_TIMEOUT\n"); TRACE ("elapsed %d msecs\n", GetTickCount () - clk); break; case GC_NOKEY: TRACE ("GC_NOKEY\n"); TRACE ("elapsed %d msecs\n", GetTickCount () - clk); goto loop; case GC_KEYREAD: TRACE ("GC_KEYREAD\n"); TRACE ("elapsed %d msecs\n", GetTickCount () - clk); TRACE ("read %c", Ch); if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1) { Beep (440, 50); goto loop; } cDefault=Ch; break; } TRACE ("exiting wait loop after %d msecs\n", GetTickCount () - clk); val = IsKeyInString (lpOptions, cDefault, bCaseSensitive); ConOutPrintf (_T("%c\n"), lpOptions[val]); nErrorLevel = val + 1; freep (arg); TRACE ("ErrorLevel: %d\n", nErrorLevel); return 0; }
int write_cc_bitmap_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *context) { int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; unsigned h1, m1, s1, ms1; LLONG start_time, end_time; if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER)) { start_time = context->prev_start + context->subs_delay; end_time = sub->start_time - 1; } else if (!(sub->flags & SUB_EOD_MARKER)) { start_time = sub->start_time + context->subs_delay; end_time = sub->end_time - 1; } if (sub->nb_data == 0) return ret; rect = sub->data; if (sub->flags & SUB_EOD_MARKER) context->prev_start = sub->start_time; if (rect[0].ocr_text && *(rect[0].ocr_text)) { if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) { char *token = NULL; token = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length); if (context->transcript_settings->showStartTime) { char buf1[80]; if (context->transcript_settings->relativeTimestamp) { millis_to_date(start_time + context->subs_delay, buf1, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf1); } else { mstotime(start_time + context->subs_delay, &h1, &m1, &s1, &ms1); time_t start_time_int = (start_time + context->subs_delay) / 1000; int start_time_dec = (start_time + context->subs_delay) % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf1, context->millis_separator, start_time_dec); } } if (context->transcript_settings->showEndTime) { char buf2[80]; if (context->transcript_settings->relativeTimestamp) { millis_to_date(end_time, buf2, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf2); } else { time_t end_time_int = end_time / 1000; int end_time_dec = end_time % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf2, context->millis_separator, end_time_dec); } } if (context->transcript_settings->showCC) { fdprintf(context->out->fh, "%s|", language[sub->lang_index]); } if (context->transcript_settings->showMode) { fdprintf(context->out->fh, "DVB|"); } while (token) { char *newline_pos = strstr(token, context->encoded_crlf); if (!newline_pos) { fdprintf(context->out->fh, "%s", token); break; } else { while (token != newline_pos) { fdprintf(context->out->fh, "%c", *token); token++; } token += context->encoded_crlf_length; fdprintf(context->out->fh, "%c", ' '); } } write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); } } #endif sub->nb_data = 0; freep(&sub->data); return ret; }
void free(void *ptr) { dprintf(fd, "free(x%lx);\n", (unsigned long)ptr); freep(ptr); }
static int init_output_ctx(struct encoder_ctx *ctx, struct encoder_cfg *cfg) { int ret = EXIT_OK; int nb_lang; char *basefilename = NULL; // Input filename without the extension char *extension = NULL; // Input filename without the extension #define check_ret(filename) if (ret != EXIT_OK) \ { \ print_error(cfg->gui_mode_reports,"Failed %s\n", filename); \ return ret; \ } if (cfg->cc_to_stdout == CCX_FALSE && cfg->send_to_srv == CCX_FALSE && cfg->extract == 12) nb_lang = 2; else nb_lang = 1; ctx->out = malloc(sizeof(struct ccx_s_write) * nb_lang); if(!ctx->out) return -1; ctx->nb_out = nb_lang; if(cfg->cc_to_stdout == CCX_FALSE && cfg->send_to_srv == CCX_FALSE) { if (cfg->output_filename != NULL) { // Use the given output file name for the field specified by // the -1, -2 switch. If -12 is used, the filename is used for // field 1. if (cfg->extract == 12) { basefilename = get_basename(cfg->output_filename); extension = get_file_extension(cfg->write_format); ret = init_write(&ctx->out[0], strdup(cfg->output_filename)); check_ret(cfg->output_filename); ret = init_write(&ctx->out[1], create_outfilename(basefilename, "_2", extension)); check_ret(ctx->out[1].filename); } else if (cfg->extract == 1) { ret = init_write(ctx->out, strdup(cfg->output_filename)); check_ret(cfg->output_filename); } else { ret = init_write(ctx->out, strdup(cfg->output_filename)); check_ret(cfg->output_filename); } } else if (cfg->write_format != CCX_OF_NULL) { basefilename = get_basename(ctx->first_input_file); extension = get_file_extension(cfg->write_format); if (cfg->extract == 12) { ret = init_write(&ctx->out[0], create_outfilename(basefilename, "_1", extension)); check_ret(ctx->out[0].filename); ret = init_write(&ctx->out[1], create_outfilename(basefilename, "_2", extension)); check_ret(ctx->out[1].filename); } else if (cfg->extract == 1) { ret = init_write(ctx->out, create_outfilename(basefilename, NULL, extension)); check_ret(ctx->out->filename); } else { ret = init_write(ctx->out, create_outfilename(basefilename, NULL, extension)); check_ret(ctx->out->filename); } } freep(&basefilename); freep(&extension); } if (cfg->cc_to_stdout == CCX_TRUE) { ctx->out[0].fh = STDOUT_FILENO; ctx->out[0].filename = NULL; mprint ("Sending captions to stdout.\n"); } if (cfg->send_to_srv == CCX_TRUE) { ctx->out[0].fh = -1; ctx->out[0].filename = NULL; connect_to_srv(ccx_options.srv_addr, ccx_options.srv_port, ccx_options.tcp_desc, ccx_options.tcp_password); } if (cfg->dtvcc_extract) { for (int i = 0; i < CCX_DTVCC_MAX_SERVICES; i++) { if (!cfg->services_enabled[i]) { ctx->dtvcc_writers[i].fd = -1; ctx->dtvcc_writers[i].filename = NULL; ctx->dtvcc_writers[i].cd = (iconv_t) -1; continue; } if (cfg->cc_to_stdout) { ctx->dtvcc_writers[i].fd = STDOUT_FILENO; ctx->dtvcc_writers[i].filename = NULL; ctx->dtvcc_writers[i].cd = (iconv_t) -1; } else { if (cfg->output_filename) basefilename = get_basename(cfg->output_filename); else basefilename = get_basename(ctx->first_input_file); ccx_dtvcc_writer_init(&ctx->dtvcc_writers[i], basefilename, ctx->program_number, i + 1, cfg->write_format, cfg); free(basefilename); } } } if(ret) { print_error(cfg->gui_mode_reports, "Output filename is same as one of input filenames. Check output parameters.\n"); return CCX_COMMON_EXIT_FILE_CREATION_FAILED; } return EXIT_OK; }
int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) { int wrote_something = 0; int ret = 0; if(!context) return CCX_OK; if (sub->type == CC_608) { struct eia608_screen *data = NULL; struct ccx_s_write *out; for(data = sub->data; sub->nb_data ; sub->nb_data--,data++) { // Determine context based on channel. This replaces the code that was above, as this was incomplete (for cases where -12 was used for example) out = get_output_ctx(context, data->my_field); context->new_sentence = 1; if(data->format == SFORMAT_XDS) { data->end_time = data->end_time + context->subs_delay; xds_write_transcript_line_prefix (context, out, data->start_time, data->end_time, data->cur_xds_packet_class); if(data->xds_len > 0) { ret = write (out->fh, data->xds_str, data->xds_len); if (ret < data->xds_len) { mprint("WARNING:Loss of data\n"); } } freep (&data->xds_str); write_newline(context, 0); continue; } if(!data->start_time) break; data->end_time = data->end_time + context->subs_delay; switch (context->write_format) { case CCX_OF_SRT: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_srt(data, context); break; case CCX_OF_WEBVTT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_webvtt(data, context); break; case CCX_OF_SAMI: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_sami(data, context); break; case CCX_OF_SMPTETT: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_smptett(data, context); break; case CCX_OF_TRANSCRIPT: wrote_something = write_cc_buffer_as_transcript2(data, context); break; case CCX_OF_SPUPNG: wrote_something = write_cc_buffer_as_spupng(data, context); break; default: break; } if (wrote_something) context->last_displayed_subs_ms = data->end_time; if (context->gui_mode_reports) write_cc_buffer_to_gui(sub->data, context); } freep(&sub->data); } if(sub->type == CC_BITMAP) { switch (context->write_format) { case CCX_OF_SRT: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_srt(sub, context); break; case CCX_OF_WEBVTT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_webvtt(sub, context); break; case CCX_OF_SAMI: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_sami(sub, context); break; case CCX_OF_SMPTETT: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_smptett(sub, context); break; case CCX_OF_TRANSCRIPT: wrote_something = write_cc_bitmap_as_transcript(sub, context); break; case CCX_OF_SPUPNG: wrote_something = write_cc_bitmap_as_spupng(sub, context); break; default: break; } } if (sub->type == CC_RAW) { if (context->send_to_srv) net_send_header(sub->data, sub->nb_data); else { ret = write(context->out->fh, sub->data, sub->nb_data); if ( ret < sub->nb_data) { mprint("WARNING: Loss of data\n"); } } sub->nb_data = 0; } if(sub->type == CC_TEXT) { switch (context->write_format) { case CCX_OF_SRT: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_srt(sub, context); break; case CCX_OF_WEBVTT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_webvtt(sub, context); break; case CCX_OF_SAMI: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_sami(sub, context); break; case CCX_OF_SMPTETT: if (!context->startcredits_displayed && context->start_credits_text!=NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_smptett(sub, context); break; case CCX_OF_TRANSCRIPT: wrote_something = write_cc_subtitle_as_transcript(sub, context); break; case CCX_OF_SPUPNG: wrote_something = write_cc_subtitle_as_spupng(sub, context); break; default: break; } sub->nb_data = 0; } if (!sub->nb_data) freep(&sub->data); return wrote_something; }
INT cmd_replace (LPTSTR param) { LPTSTR *arg; INT argc, i,filesReplaced = 0, nFiles, srcIndex = -1, destIndex = -1; DWORD dwFlags = 0; TCHAR szDestPath[MAX_PATH], szSrcPath[MAX_PATH], tmpSrcPath[MAX_PATH]; BOOL doMore = TRUE; /* Help wanted? */ if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_REPLACE_HELP1); return 0; } /* Divide the argument in to an array of c-strings */ arg = split (param, &argc, FALSE, FALSE); nFiles = argc; /* Read options */ for (i = 0; i < argc; i++) { if (arg[i][0] == _T('/')) { if (_tcslen(arg[i]) == 2) { switch (_totupper(arg[i][1])) { case _T('A'): dwFlags |= REPLACE_ADD; break; case _T('P'): dwFlags |= REPLACE_CONFIRM; break; case _T('R'): dwFlags |= REPLACE_READ_ONLY; break; case _T('S'): dwFlags |= REPLACE_SUBDIR; break; case _T('W'): dwFlags |= REPLACE_DISK; break; case _T('U'): dwFlags |= REPLACE_UPDATE; break; default: invalid_switch(arg[i]); return 0; } } else { invalid_switch(arg[i]); freep(arg); return 0; } nFiles--; } else { if (srcIndex == -1) { srcIndex = i; } else if (destIndex == -1) { destIndex = i; } else { invalid_switch(arg[i]); freep(arg); return 0; } } } /* See so that at least source is there */ if (nFiles < 1) { ConOutResPaging(TRUE,STRING_REPLACE_HELP2); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } /* Check so that not both update and add switch is added and subdir */ if ((dwFlags & REPLACE_UPDATE || dwFlags & REPLACE_SUBDIR) && (dwFlags & REPLACE_ADD)) { ConOutResPaging(TRUE,STRING_REPLACE_ERROR4); ConOutResPaging(TRUE,STRING_REPLACE_HELP7); freep(arg); return 1; } /* If we have a destination get the full path */ if (destIndex != -1) { if (_tcslen(arg[destIndex]) == 2 && arg[destIndex][1] == ':') GetRootPath(arg[destIndex],szDestPath,MAX_PATH); else { /* Check for wildcards in destination directory */ if (_tcschr (arg[destIndex], _T('*')) != NULL || _tcschr (arg[destIndex], _T('?')) != NULL) { ConOutResPrintf(STRING_REPLACE_ERROR2,arg[destIndex]); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } getPath(szDestPath, arg[destIndex]); /* Make sure that destination exists */ if (!IsExistingDirectory(szDestPath)) { ConOutResPrintf(STRING_REPLACE_ERROR2, szDestPath); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } } } else { /* Dest is current dir */ GetCurrentDirectory(MAX_PATH,szDestPath); } /* Get the full source path */ if (!(_tcslen(arg[srcIndex]) == 2 && arg[srcIndex][1] == ':')) getPath(szSrcPath, arg[srcIndex]); else _tcscpy(szSrcPath,arg[srcIndex]); /* Source does not have wildcards */ if (_tcschr (arg[srcIndex], _T('*')) == NULL && _tcschr (arg[srcIndex], _T('?')) == NULL) { /* Check so that source is not a directory, because that is not allowed */ if (IsExistingDirectory(szSrcPath)) { ConOutResPrintf(STRING_REPLACE_ERROR6, szSrcPath); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } /* Check if the file exists */ if (!IsExistingFile(szSrcPath)) { ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } } /* /w switch is set so wait for any key to be pressed */ if (dwFlags & REPLACE_DISK) { msg_pause(); cgetchar(); } /* Add an extra \ to the destination path if needed */ if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\')) _tcscat(szDestPath, _T("\\")); /* Save source path */ _tcscpy(tmpSrcPath,szSrcPath); /* Replace in dest dir */ filesReplaced += recReplace(dwFlags, tmpSrcPath, szDestPath, &doMore); /* If subdir switch is set replace in the subdirs to */ if (dwFlags & REPLACE_SUBDIR && doMore) { filesReplaced += recFindSubDirs(dwFlags, szSrcPath, szDestPath, &doMore); } /* If source == dest write no more */ if (filesReplaced != -1) { /* No files replaced */ if (filesReplaced==0) { /* Add switch dependent output */ if (dwFlags & REPLACE_ADD) ConOutResPaging(TRUE,STRING_REPLACE_HELP7); else ConOutResPaging(TRUE,STRING_REPLACE_HELP3); } /* Some files replaced */ else { /* Add switch dependent output */ if (dwFlags & REPLACE_ADD) ConOutResPrintf(STRING_REPLACE_HELP8, filesReplaced); else ConOutResPrintf(STRING_REPLACE_HELP4, filesReplaced); } } /* Return memory */ freep(arg); return 1; }
static LPSTR * split( LPSTR s, LPINT args) { LPSTR *arg; LPSTR start; LPSTR q; INT ac; INT_PTR len; BOOL bQuoted; arg = RtlAllocateHeap(ProcessHeap, 0 , sizeof(LPTSTR)); if (arg == NULL) return NULL; *arg = NULL; ac = 0; while (*s) { bQuoted = FALSE; /* skip leading spaces */ while (*s && (isspace(*s) || iscntrl(*s))) ++s; start = s; /* the first character can be '/' */ if (*s == '/') s++; /* skip to next word delimiter or start of next option */ while (isprint(*s)) { /* if quote (") then set bQuoted */ bQuoted ^= (*s == '\"'); /* Check if we have unquoted text */ if (!bQuoted) { /* check for separators */ if (isspace(*s) || (*s == '/')) { /* Make length at least one character */ if (s == start) s++; break; } } s++; } /* a word was found */ if (s != start) { len = s - start; q = RtlAllocateHeap(ProcessHeap, 0, len + 1); if (q == NULL) { freep(arg); return NULL; } memcpy(q, start, len); q[len] = '\0'; StripQuotes(q); if (!add_entry(&ac, &arg, q)) { RtlFreeHeap(ProcessHeap, 0, q); freep(arg); return NULL; } RtlFreeHeap(ProcessHeap, 0, q); } } *args = ac; return arg; }
struct encoder_ctx *update_encoder_list_cinfo(struct lib_ccx_ctx *ctx, struct cap_info* cinfo) { struct encoder_ctx *enc_ctx; unsigned int pn = 0; unsigned char in_format = 1; char *extension; if (ctx->write_format == CCX_OF_NULL) return NULL; if(cinfo) { pn = cinfo->program_number; if (cinfo->codec == CCX_CODEC_ISDB_CC) in_format = 3; else if (cinfo->codec == CCX_CODEC_TELETEXT) in_format = 2; else in_format = 1; } list_for_each_entry(enc_ctx, &ctx->enc_ctx_head, list, struct encoder_ctx) { if ( ctx->multiprogram == CCX_FALSE) return enc_ctx; if (enc_ctx->program_number == pn) return enc_ctx; } extension = get_file_extension(ccx_options.enc_cfg.write_format); if (!extension && ccx_options.enc_cfg.write_format != CCX_OF_CURL) return NULL; if(ctx->multiprogram == CCX_FALSE) { if(ctx->out_interval != -1) { int len; len = strlen(ctx->basefilename) + 10 + strlen(extension); freep(&ccx_options.enc_cfg.output_filename); ccx_options.enc_cfg.output_filename = malloc(len); sprintf(ccx_options.enc_cfg.output_filename, "%s_%06d%s", ctx->basefilename, ctx->segment_counter+1, extension); } if (list_empty(&ctx->enc_ctx_head)) { ccx_options.enc_cfg.program_number = pn; ccx_options.enc_cfg.in_format = in_format; enc_ctx = init_encoder(&ccx_options.enc_cfg); if (!enc_ctx) return NULL; list_add_tail( &(enc_ctx->list), &(ctx->enc_ctx_head) ); } } else { int len; len = strlen(ctx->basefilename) + 10 + strlen(extension); ccx_options.enc_cfg.program_number = pn; ccx_options.enc_cfg.output_filename = malloc(len); if (!ccx_options.enc_cfg.output_filename) { freep(&extension); return NULL; } sprintf(ccx_options.enc_cfg.output_filename, "%s_%d%s", ctx->basefilename, pn, extension); enc_ctx = init_encoder(&ccx_options.enc_cfg); if (!enc_ctx) { freep(&extension); freep(&ccx_options.enc_cfg.output_filename); return NULL; } list_add_tail( &(enc_ctx->list), &(ctx->enc_ctx_head) ); freep(&extension); freep(&ccx_options.enc_cfg.output_filename); } // DVB related enc_ctx->prev = NULL; if (cinfo) if (cinfo->codec == CCX_CODEC_DVB) enc_ctx->write_previous = 0; freep(&extension); return enc_ctx; }
void dinit_timing_ctx(struct ccx_common_timing_ctx **arg) { freep(arg); }
void print_file_report(struct lib_ccx_ctx *ctx) { struct lib_cc_decode *dec_ctx = NULL; struct ccx_demuxer *demux_ctx = ctx->demux_ctx; printf("File: "); switch (ccx_options.input_source) { case CCX_DS_FILE: if (ctx->current_file < 0) { printf("file is not openened yet\n"); return; } printf("%s\n", ctx->inputfile[ctx->current_file]); break; case CCX_DS_STDIN: printf("stdin\n"); break; case CCX_DS_TCP: case CCX_DS_NETWORK: printf("network\n"); break; } struct cap_info* program; printf("Stream Mode: "); switch (demux_ctx->stream_mode) { case CCX_SM_TRANSPORT: printf("Transport Stream\n"); printf("Program Count: %d\n", demux_ctx->freport.program_cnt); printf("Program Numbers: "); for (int i = 0; i < demux_ctx->nb_program; i++) printf("%u ", demux_ctx->pinfo[i].program_number); printf("\n"); for (int i = 0; i < 65536; i++) { if (demux_ctx->PIDs_programs[i] == 0) continue; printf("PID: %u, Program: %u, ", i, demux_ctx->PIDs_programs[i]->program_number); int j; for (j = 0; j < SUB_STREAMS_CNT; j++) { if (demux_ctx->freport.dvb_sub_pid[j] == i) { printf("DVB Subtitles\n"); break; } if (demux_ctx->freport.tlt_sub_pid[j] == i) { printf("Teletext Subtitles\n"); break; } } if (j == SUB_STREAMS_CNT) printf("%s\n", desc[demux_ctx->PIDs_programs[i]->printable_stream_type]); } break; case CCX_SM_PROGRAM: printf("Program Stream\n"); break; case CCX_SM_ASF: printf("ASF\n"); break; case CCX_SM_WTV: printf("WTV\n"); break; case CCX_SM_ELEMENTARY_OR_NOT_FOUND: printf("Not Found\n"); break; case CCX_SM_MP4: printf("MP4\n"); break; case CCX_SM_MCPOODLESRAW: printf("McPoodle's raw\n"); break; case CCX_SM_RCWT: printf("BIN\n"); break; #ifdef WTV_DEBUG case CCX_SM_HEX_DUMP: printf("Hex\n"); break; #endif default: break; } if(list_empty(&demux_ctx->cinfo_tree.all_stream)) { print_cc_report(ctx, NULL); } list_for_each_entry(program, &demux_ctx->cinfo_tree.pg_stream, pg_stream, struct cap_info) { struct cap_info* info = NULL; printf("//////// Program #%u: ////////\n", program->program_number); printf("DVB Subtitles: "); info = get_sib_stream_by_type(program, CCX_CODEC_DVB); if(info) printf("Yes\n"); else printf("No\n"); printf("Teletext: "); info = get_sib_stream_by_type(program, CCX_CODEC_TELETEXT); if(info) { printf("Yes\n"); dec_ctx = update_decoder_list_cinfo(ctx, info); printf("Pages With Subtitles: "); tlt_print_seen_pages(dec_ctx); printf("\n"); } else printf("No\n"); printf("ATSC Closed Caption: "); info = get_sib_stream_by_type(program, CCX_CODEC_ATSC_CC); if(info) { printf("Yes\n"); print_cc_report(ctx, info); } else printf("No\n"); info = get_best_sib_stream(program); if(!info) continue; dec_ctx = update_decoder_list_cinfo(ctx, info); if (dec_ctx->in_bufferdatatype == CCX_PES && (info->stream == CCX_SM_TRANSPORT || info->stream == CCX_SM_PROGRAM || info->stream == CCX_SM_ASF || info->stream == CCX_SM_WTV)) { printf("Width: %u\n", dec_ctx->current_hor_size); printf("Height: %u\n", dec_ctx->current_vert_size); printf("Aspect Ratio: %s\n", aspect_ratio_types[dec_ctx->current_aspect_ratio]); printf("Frame Rate: %s\n", framerates_types[dec_ctx->current_frame_rate]); } printf("\n"); } printf("MPEG-4 Timed Text: %s\n", Y_N(ctx->freport.mp4_cc_track_cnt)); if (ctx->freport.mp4_cc_track_cnt) { printf("MPEG-4 Timed Text tracks count: %d\n", ctx->freport.mp4_cc_track_cnt); } freep(&ctx->freport.data_from_608); memset(&ctx->freport, 0, sizeof (struct file_report)); #undef Y_N }
INT CommandTimer (LPTSTR param) { // all timers are kept static DWORD clksT[10]; // timers status // set all the clocks off by default static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}; // TRUE if /S in command line BOOL bS = FALSE; // avoid to set clk_n more than once BOOL bCanNSet = TRUE; INT NewClkStatus = NCS_NOT_SPECIFIED; // the clock number specified on the command line // 1 by default INT clk_n=1; // output format INT iFormat=1; // command line parsing variables INT argc; LPTSTR *p; INT i; if (_tcsncmp (param, _T("/?"), 2) == 0) { ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator); return 0; } nErrorLevel = 0; p = split (param, &argc, FALSE, FALSE); //read options for (i = 0; i < argc; i++) { //set timer on if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED) { NewClkStatus = NCS_ON; continue; } //set timer off if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED) { NewClkStatus = NCS_OFF; continue; } // other options if (p[i][0] == _T('/')) { // set timer number if (_istdigit(p[i][1]) && bCanNSet) { clk_n = p[i][1] - _T('0'); bCanNSet = FALSE; continue; } // set s(plit) option if (_totupper(p[i][1]) == _T('S')) { bS = TRUE; continue; } // specify format if (_totupper(p[i][1]) == _T('F')) { iFormat = p[i][2] - _T('0'); continue; } } } // do stuff (start/stop/read timer) if (NewClkStatus == NCS_ON) { cT=GetTickCount(); cS=TRUE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } if (bS) { if (cS) { ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPrintf(_T("%s\n"), GetTimeString()); PrintElapsedTime(GetTickCount()-cT, iFormat); freep(p); return 0; } cT=GetTickCount(); cS=TRUE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } if (NewClkStatus == NCS_NOT_SPECIFIED) { if (cS) { cS=FALSE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPrintf(_T("%s\n"), GetTimeString()); PrintElapsedTime(GetTickCount()-cT, iFormat); freep(p); return 0; } cT=GetTickCount(); cS=TRUE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } if (NewClkStatus == NCS_OFF) { if (cS) { cS=FALSE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPrintf(_T("%s\n"), GetTimeString()); PrintElapsedTime(GetTickCount()-cT, iFormat); freep(p); return 0; } ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } freep(p); return 0; }
INT cmd_rmdir (LPTSTR param) { TCHAR ch; INT args; INT dirCount; LPTSTR *arg; INT i; BOOL RD_SUB = FALSE; BOOL RD_QUIET = FALSE; INT res; INT nError = 0; TCHAR szFullPath[MAX_PATH]; if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_RMDIR_HELP); return 0; } arg = split (param, &args, FALSE, FALSE); dirCount = 0; /* check for options anywhere in command line */ for (i = 0; i < args; i++) { if (*arg[i] == _T('/')) { /*found a command, but check to make sure it has something after it*/ if (_tcslen (arg[i]) == 2) { ch = _totupper (arg[i][1]); if (ch == _T('S')) { RD_SUB = TRUE; } else if (ch == _T('Q')) { RD_QUIET = TRUE; } } } else { dirCount++; } } if (dirCount == 0) { /* No folder to remove */ error_req_param_missing(); freep(arg); return 1; } for (i = 0; i < args; i++) { if (*arg[i] == _T('/')) continue; if (RD_SUB) { /* ask if they want to delete evrything in the folder */ if (!RD_QUIET) { res = FilePromptYNA (STRING_DEL_HELP2); if (res == PROMPT_NO || res == PROMPT_BREAK) { nError = 1; continue; } if (res == PROMPT_ALL) RD_QUIET = TRUE; } /* get the folder name */ GetFullPathName(arg[i],MAX_PATH,szFullPath,NULL); /* remove trailing \ if any, but ONLY if dir is not the root dir */ if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] == _T('\\')) szFullPath[_tcslen(szFullPath) - 1] = _T('\0'); res = DeleteFolder(szFullPath); } else { res = RemoveDirectory(arg[i]); } if (!res) { /* Couldn't delete the folder, print out the error */ nError = GetLastError(); ErrorMessage(nError, _T("RD")); } } freep (arg); return nError; }
INT CommandChcp (LPTSTR param) { LPTSTR *arg; INT args; UINT uNewCodePage; /* print help */ if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_CHCP_HELP); return 0; } nErrorLevel = 0; /* get parameters */ arg = split (param, &args, FALSE); if (args == 0) { /* display active code page number */ ConErrResPrintf(STRING_CHCP_ERROR1, InputCodePage); freep (arg); return 0; } if (args >= 2) { /* too many parameters */ ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, param); nErrorLevel = 1; freep (arg); return 1; } uNewCodePage = (UINT)_ttoi(arg[0]); if (uNewCodePage == 0) { ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, arg[0]); freep (arg); nErrorLevel = 1; return 1; } if (!SetConsoleCP(uNewCodePage)) { ConErrResPuts(STRING_CHCP_ERROR4); } else { SetConsoleOutputCP (uNewCodePage); InitLocale (); InputCodePage= GetConsoleCP(); } freep (arg); return 0; }
static INT CommandDumpSector( PCONSOLE_STATE State, LPSTR param) { OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; UNICODE_STRING PathName; HANDLE hDisk = NULL; DISK_GEOMETRY DiskGeometry; NTSTATUS Status; LPTSTR *argv = NULL; INT argc = 0; WCHAR DriveName[40]; ULONG ulDrive; // ULONG ulSector; LARGE_INTEGER Sector, SectorCount, Offset; PUCHAR Buffer = NULL; DPRINT1("param: %s\n", param); if (!strcmp(param, "/?")) { HelpDumpSector(); return 0; } argv = split(param, &argc); DPRINT1("argc: %d\n", argc); DPRINT1("argv: %p\n", argv); if (argc != 2) { goto done; } DPRINT1("Device: %s\n", argv[0]); DPRINT1("Sector: %s\n", argv[1]); ulDrive = strtoul(argv[0], NULL, 0); // ulSector = strtoul(argv[1], NULL, 0); Sector.QuadPart = _atoi64(argv[1]); /* Build full drive name */ // swprintf(DriveName, L"\\\\.\\PHYSICALDRIVE%lu", ulDrive); swprintf(DriveName, L"\\Device\\Harddisk%lu\\Partition0", ulDrive); RtlInitUnicodeString(&PathName, DriveName); InitializeObjectAttributes(&ObjectAttributes, &PathName, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, NULL, NULL); Status = NtOpenFile(&hDisk, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateFile failed (Status 0x%08lx)\n", Status); goto done; } Status = NtDeviceIoControlFile(hDisk, NULL, NULL, NULL, &IoStatusBlock, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &DiskGeometry, sizeof(DISK_GEOMETRY)); if (!NT_SUCCESS(Status)) { DPRINT1("NtDeviceIoControlFile failed (Status 0x%08lx)\n", Status); goto done; } DPRINT1("Drive number: %lu\n", ulDrive); DPRINT1("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n" "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n", DiskGeometry.Cylinders.QuadPart, DiskGeometry.MediaType, DiskGeometry.TracksPerCylinder, DiskGeometry.SectorsPerTrack, DiskGeometry.BytesPerSector); DPRINT1("Sector: %I64u\n", Sector.QuadPart); SectorCount.QuadPart = DiskGeometry.Cylinders.QuadPart * (ULONGLONG)DiskGeometry.TracksPerCylinder * (ULONGLONG)DiskGeometry.SectorsPerTrack; if (Sector.QuadPart >= SectorCount.QuadPart) { CONSOLE_ConOutPrintf("Invalid sector number! Valid range: [0 - %I64u]\n", SectorCount.QuadPart - 1); goto done; } Buffer = RtlAllocateHeap(ProcessHeap, 0, DiskGeometry.BytesPerSector); if (Buffer == NULL) { DPRINT1("Buffer allocation failed\n"); goto done; } Offset.QuadPart = Sector.QuadPart * DiskGeometry.BytesPerSector; DPRINT1("Offset: %I64u\n", Offset.QuadPart); Status = NtReadFile(hDisk, NULL, NULL, NULL, &IoStatusBlock, Buffer, DiskGeometry.BytesPerSector, &Offset, NULL); if (!NT_SUCCESS(Status)) { DPRINT1("NtReadFile failed (Status 0x%08lx)\n", Status); goto done; } HexDump(Buffer, DiskGeometry.BytesPerSector); done: if (Buffer != NULL) RtlFreeHeap(ProcessHeap, 0, Buffer); if (hDisk != NULL) NtClose(hDisk); freep(argv); return 0; }
int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *context) { int length; int ret = 0; LLONG start_time; LLONG end_time; char *str; struct cc_subtitle *osub = sub; struct cc_subtitle *lsub = sub; while(sub) { if(sub->type == CC_TEXT) { start_time = sub->start_time; end_time = sub->end_time; } if (context->sentence_cap) { //TODO capitalize (context, line_number,data); //TODO correct_case(line_number, data); } str = sub->data; length = strlen(str); if (context->encoding!=CCX_ENC_UNICODE) { dbg_print(CCX_DMT_DECODER_608, "\r"); dbg_print(CCX_DMT_DECODER_608, "%s\n", str); } if (length>0) { if (start_time == -1) { // CFS: Means that the line has characters but we don't have a timestamp for the first one. Since the timestamp // is set for example by the write_char function, it possible that we don't have one in empty lines (unclear) // For now, let's not consider this a bug as before and just return. // fatal (EXIT_BUG_BUG, "Bug in timedtranscript (ts_start_of_current_line==-1). Please report."); return 0; } if (context->transcript_settings->showStartTime){ char buf1[80]; if (context->transcript_settings->relativeTimestamp){ millis_to_date(start_time + context->subs_delay, buf1, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf1); } else { time_t start_time_int = (start_time + context->subs_delay) / 1000; int start_time_dec = (start_time + context->subs_delay) % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf1,context->millis_separator,start_time_dec); } } if (context->transcript_settings->showEndTime){ char buf2[80]; if (context->transcript_settings->relativeTimestamp){ millis_to_date(end_time, buf2, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf2); } else { time_t end_time_int = (end_time + context->subs_delay) / 1000; int end_time_dec = (end_time + context->subs_delay) % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf2,context->millis_separator,end_time_dec); } } if (context->transcript_settings->showCC) { if(context->in_fileformat == 2 ) fdprintf(context->out->fh, sub->info); else //TODO, data->my_field == 1 ? data->channel : data->channel + 2); // Data from field 2 is CC3 or 4 fdprintf(context->out->fh, "CC?|"); } if (context->transcript_settings->showMode){ fdprintf(context->out->fh, "%s|", sub->mode); } ret = write(context->out->fh, str, length); if(ret < length) { mprint("Warning:Loss of data\n"); } ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); if(ret < context->encoded_crlf_length) { mprint("Warning:Loss of data\n"); } } freep(&sub->data); lsub = sub; sub = sub->next; } while(lsub != osub) { sub = lsub->prev; freep(&lsub); lsub = sub; } return ret; }
static INT CommandPartInfo( PCONSOLE_STATE State, LPSTR param) { OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; UNICODE_STRING PathName; HANDLE hDisk = NULL; DISK_GEOMETRY DiskGeometry; NTSTATUS Status; LPTSTR *argv = NULL; INT argc = 0; WCHAR DriveName[40]; ULONG ulDrive, i; PDRIVE_LAYOUT_INFORMATION LayoutBuffer = NULL; PPARTITION_INFORMATION PartitionInfo; DPRINT1("param: %s\n", param); if (!strcmp(param, "/?")) { HelpPartInfo(); return 0; } argv = split(param, &argc); DPRINT1("argc: %d\n", argc); DPRINT1("argv: %p\n", argv); if (argc != 1) { goto done; } DPRINT1("Device: %s\n", argv[0]); ulDrive = strtoul(argv[0], NULL, 0); /* Build full drive name */ swprintf(DriveName, L"\\Device\\Harddisk%lu\\Partition0", ulDrive); RtlInitUnicodeString(&PathName, DriveName); InitializeObjectAttributes(&ObjectAttributes, &PathName, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, NULL, NULL); Status = NtOpenFile(&hDisk, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE | FILE_RANDOM_ACCESS); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateFile failed (Status 0x%08lx)\n", Status); goto done; } Status = NtDeviceIoControlFile(hDisk, NULL, NULL, NULL, &IoStatusBlock, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &DiskGeometry, sizeof(DISK_GEOMETRY)); if (!NT_SUCCESS(Status)) { DPRINT1("NtDeviceIoControlFile failed (Status 0x%08lx)\n", Status); goto done; } CONSOLE_ConOutPrintf("Drive number: %lu\n", ulDrive); CONSOLE_ConOutPrintf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n" "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n", DiskGeometry.Cylinders.QuadPart, DiskGeometry.MediaType, DiskGeometry.TracksPerCylinder, DiskGeometry.SectorsPerTrack, DiskGeometry.BytesPerSector); LayoutBuffer = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, 8192); if (LayoutBuffer == NULL) { DPRINT1("LayoutBuffer allocation failed\n"); goto done; } Status = NtDeviceIoControlFile(hDisk, NULL, NULL, NULL, &IoStatusBlock, IOCTL_DISK_GET_DRIVE_LAYOUT, NULL, 0, LayoutBuffer, 8192); if (!NT_SUCCESS(Status)) { DPRINT1("NtDeviceIoControlFile(IOCTL_DISK_GET_DRIVE_LAYOUT) failed (Status 0x%08lx)\n", Status); goto done; } CONSOLE_ConOutPrintf("Partitions: %lu Signature: %lx\n\n", LayoutBuffer->PartitionCount, LayoutBuffer->Signature); CONSOLE_ConOutPrintf(" # Start Size Hidden Nr Type Boot\n"); CONSOLE_ConOutPrintf("-- --------------- --------------- ------------ -- ---- ----\n"); for (i = 0; i < LayoutBuffer->PartitionCount; i++) { PartitionInfo = &LayoutBuffer->PartitionEntry[i]; CONSOLE_ConOutPrintf("%2lu %15I64u %15I64u %12lu %2lu %2x %c\n", i, PartitionInfo->StartingOffset.QuadPart / DiskGeometry.BytesPerSector, PartitionInfo->PartitionLength.QuadPart / DiskGeometry.BytesPerSector, PartitionInfo->HiddenSectors, PartitionInfo->PartitionNumber, PartitionInfo->PartitionType, PartitionInfo->BootIndicator ? '*': ' '); } CONSOLE_ConOutPrintf("\n"); done: if (LayoutBuffer != NULL) RtlFreeHeap(ProcessHeap, 0, LayoutBuffer); if (hDisk != NULL) NtClose(hDisk); freep(argv); return 0; }
struct encoder_ctx *init_encoder(struct encoder_cfg *opt) { int ret; int i; struct encoder_ctx *ctx = malloc(sizeof(struct encoder_ctx)); if(!ctx) return NULL; ctx->buffer = (unsigned char *) malloc (INITIAL_ENC_BUFFER_CAPACITY); if (!ctx->buffer) { free(ctx); return NULL; } ctx->capacity=INITIAL_ENC_BUFFER_CAPACITY; ctx->srt_counter = 0; ctx->program_number = opt->program_number; ctx->send_to_srv = opt->send_to_srv; ctx->multiple_files = opt->multiple_files; ctx->first_input_file = opt->first_input_file; ret = init_output_ctx(ctx, opt); if (ret != EXIT_OK) { freep(&ctx->buffer); free(ctx); return NULL; } ctx->in_fileformat = opt->in_format; /** used in case of SUB_EOD_MARKER */ ctx->prev_start = -1; ctx->subs_delay = opt->subs_delay; ctx->last_displayed_subs_ms = 0; ctx->date_format = opt->date_format; ctx->millis_separator = opt->millis_separator; ctx->startcredits_displayed = 0; ctx->encoding = opt->encoding; ctx->write_format = opt->write_format; ctx->transcript_settings = &opt->transcript_settings; ctx->no_bom = opt->no_bom; ctx->sentence_cap = opt->sentence_cap; ctx->trim_subs = opt->trim_subs; ctx->autodash = opt->autodash; ctx->no_font_color = opt->no_font_color; ctx->no_type_setting = opt->no_type_setting; ctx->gui_mode_reports = opt->gui_mode_reports; ctx->extract = opt->extract; ctx->subline = (unsigned char *) malloc (SUBLINESIZE); if(!ctx->subline) { freep(&ctx->out); freep(&ctx->buffer); free(ctx); return NULL; } ctx->start_credits_text = opt->start_credits_text; ctx->end_credits_text = opt->end_credits_text; ctx->startcreditsnotbefore = opt->startcreditsnotbefore; ctx->startcreditsnotafter = opt->startcreditsnotafter; ctx->startcreditsforatleast = opt->startcreditsforatleast; ctx->startcreditsforatmost = opt->startcreditsforatmost; ctx->endcreditsforatleast = opt->endcreditsforatleast; ctx->endcreditsforatmost = opt->endcreditsforatmost; ctx->new_sentence = 1; // Capitalize next letter? if (opt->line_terminator_lf) ctx->encoded_crlf_length = encode_line(ctx, ctx->encoded_crlf, (unsigned char *) "\n"); else ctx->encoded_crlf_length = encode_line(ctx, ctx->encoded_crlf, (unsigned char *) "\r\n"); ctx->encoded_br_length = encode_line(ctx, ctx->encoded_br, (unsigned char *) "<br>"); for (i = 0; i < ctx->nb_out; i++) write_subtitle_file_header(ctx,ctx->out+i); ctx->dtvcc_extract = opt->dtvcc_extract; return ctx; }
void ccx_decoder_608_dinit_library(void **ctx) { freep(ctx); }
int write_cc_subtitle_as_transcript(struct cc_subtitle *sub, struct encoder_ctx *context) { int length; int ret = 0; LLONG start_time = -1; LLONG end_time = -1; char *str; char *save_str; struct cc_subtitle *osub = sub; struct cc_subtitle *lsub = sub; while (sub) { if (sub->type == CC_TEXT) { start_time = sub->start_time; end_time = sub->end_time; } if (context->sentence_cap) { //TODO capitalize (context, line_number,data); //TODO correct_case_with_dictionary(line_number, data); } if (start_time == -1) { // CFS: Means that the line has characters but we don't have a timestamp for the first one. Since the timestamp // is set for example by the write_char function, it possible that we don't have one in empty lines (unclear) // For now, let's not consider this a bug as before and just return. // fatal (EXIT_BUG_BUG, "Bug in timedtranscript (ts_start_of_current_line==-1). Please report."); return 0; } str = sub->data; str = strtok_r(str, "\r\n", &save_str); do { length = get_str_basic(context->subline, (unsigned char*)str, context->trim_subs, sub->enc_type, context->encoding, strlen(str)); if (length <= 0) { continue; } if (context->transcript_settings->showStartTime) { char buf[80]; if (context->transcript_settings->relativeTimestamp) { millis_to_date(start_time + context->subs_delay, buf, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf); } else { time_t start_time_int = (start_time + context->subs_delay) / 1000; int start_time_dec = (start_time + context->subs_delay) % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf, context->millis_separator, start_time_dec); } } if (context->transcript_settings->showEndTime) { char buf[80]; if (context->transcript_settings->relativeTimestamp) { millis_to_date(end_time + context->subs_delay, buf, context->date_format, context->millis_separator); fdprintf(context->out->fh, "%s|", buf); } else { time_t end_time_int = (end_time + context->subs_delay) / 1000; int end_time_dec = (end_time + context->subs_delay) % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf, context->millis_separator, end_time_dec); } } if (context->transcript_settings->showCC) { if (context->in_fileformat == 1) //TODO, data->my_field == 1 ? data->channel : data->channel + 2); // Data from field 2 is CC3 or 4 fdprintf(context->out->fh, "CC?|"); else if (!context->ucla || !strcmp(sub->mode, "TLT")) fdprintf(context->out->fh, sub->info); } if (context->transcript_settings->showMode) { if (context->ucla && strcmp(sub->mode, "TLT") == 0) fdprintf(context->out->fh, "|"); else fdprintf(context->out->fh, "%s|", sub->mode); } ret = write(context->out->fh, context->subline, length); if (ret < length) { mprint("Warning:Loss of data\n"); } ret = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); if (ret < context->encoded_crlf_length) { mprint("Warning:Loss of data\n"); } } while ((str = strtok_r(NULL, "\r\n", &save_str))); freep(&sub->data); lsub = sub; sub = sub->next; } while (lsub != osub) { sub = lsub->prev; freep(&lsub); lsub = sub; } return ret; }
INT cmd_move (LPTSTR param) { LPTSTR *arg; INT argc, i, nFiles; LPTSTR pszDest; TCHAR szDestPath[MAX_PATH]; TCHAR szFullDestPath[MAX_PATH]; TCHAR szSrcDirPath[MAX_PATH]; TCHAR szSrcPath[MAX_PATH]; TCHAR szFullSrcPath[MAX_PATH]; DWORD dwFlags = 0; INT nOverwrite = 0; WIN32_FIND_DATA findBuffer; HANDLE hFile; /* used only when source and destination directories are on different volume*/ HANDLE hDestFile; WIN32_FIND_DATA findDestBuffer; TCHAR szMoveDest[MAX_PATH]; TCHAR szMoveSrc[MAX_PATH]; LPTSTR pszDestDirPointer; LPTSTR pszSrcDirPointer; INT nDirLevel = 0; LPTSTR pszFile; BOOL OnlyOneFile; BOOL FoundFile; BOOL MoveStatus; DWORD dwMoveFlags = 0; DWORD dwMoveStatusFlags = 0; if (!_tcsncmp (param, _T("/?"), 2)) { #if 0 ConOutPuts (_T("Moves files and renames files and directories.\n\n" "To move one or more files:\n" "MOVE [/N][/Y|/-Y][drive:][path]filename1[,...] destination\n" "\n" "To rename a directory:\n" "MOVE [/N][/Y|/-Y][drive:][path]dirname1 dirname2\n" "\n" " [drive:][path]filename1 Specifies the location and name of the file\n" " or files you want to move.\n" " /N Nothing. Don everthing but move files or direcories.\n" " /Y\n" " /-Y\n" "...")); #else ConOutResPaging(TRUE,STRING_MOVE_HELP2); #endif return 0; } nErrorLevel = 0; arg = splitspace(param, &argc); /* read options */ for (i = 0; i < argc; i++) { if (!_tcsicmp(arg[i], _T("/N"))) dwFlags |= MOVE_NOTHING; else if (!_tcsicmp(arg[i], _T("/Y"))) dwFlags |= MOVE_OVER_YES; else if (!_tcsicmp(arg[i], _T("/-Y"))) dwFlags |= MOVE_OVER_NO; else break; } nFiles = argc - i; if (nFiles < 1) { /* there must be at least one pathspec */ error_req_param_missing(); freep(arg); return 1; } if (nFiles > 2) { /* there are more than two pathspecs */ error_too_many_parameters(param); freep(arg); return 1; } /* If no destination is given, default to current directory */ pszDest = (nFiles == 1) ? _T(".") : arg[i + 1]; /* check for wildcards in source and destination */ if (_tcschr(pszDest, _T('*')) != NULL || _tcschr(pszDest, _T('?')) != NULL) { /* '*'/'?' in dest, this doesnt happen. give folder name instead*/ error_invalid_parameter_format(pszDest); freep(arg); return 1; } if (_tcschr(arg[i], _T('*')) != NULL || _tcschr(arg[i], _T('?')) != NULL) { dwMoveStatusFlags |= MOVE_SOURCE_HAS_WILD; } /* get destination */ GetFullPathName (pszDest, MAX_PATH, szDestPath, NULL); TRACE ("Destination: %s\n", debugstr_aw(szDestPath)); /* get source folder */ GetFullPathName(arg[i], MAX_PATH, szSrcDirPath, &pszFile); if (pszFile != NULL) *pszFile = _T('\0'); TRACE ("Source Folder: %s\n", debugstr_aw(szSrcDirPath)); hFile = FindFirstFile (arg[i], &findBuffer); if (hFile == INVALID_HANDLE_VALUE) { ErrorMessage (GetLastError (), arg[i]); freep (arg); return 1; } /* check for special cases "." and ".." and if found skip them */ FoundFile = TRUE; while(FoundFile && (_tcscmp(findBuffer.cFileName,_T(".")) == 0 || _tcscmp(findBuffer.cFileName,_T("..")) == 0)) FoundFile = FindNextFile (hFile, &findBuffer); if (!FoundFile) { /* what? we don't have anything to move? */ error_file_not_found(); FindClose(hFile); freep(arg); return 1; } OnlyOneFile = TRUE; /* check if there can be found files as files have first priority */ if (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) dwMoveStatusFlags |= MOVE_SOURCE_IS_DIR; else dwMoveStatusFlags |= MOVE_SOURCE_IS_FILE; while(OnlyOneFile && FindNextFile(hFile,&findBuffer)) { if (!(findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { ConOutPrintf(_T("")); if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) OnlyOneFile = FALSE; else { /* this has been done this way so that we don't disturb other settings if they have been set before this */ dwMoveStatusFlags |= MOVE_SOURCE_IS_FILE; dwMoveStatusFlags &= ~MOVE_SOURCE_IS_DIR; } } } FindClose(hFile); TRACE ("Do we have only one file: %s\n", OnlyOneFile ? "TRUE" : "FALSE"); /* we have to start again to be sure we don't miss any files or folders*/ hFile = FindFirstFile (arg[i], &findBuffer); if (hFile == INVALID_HANDLE_VALUE) { ErrorMessage (GetLastError (), arg[i]); freep (arg); return 1; } /* check for special cases "." and ".." and if found skip them */ FoundFile = TRUE; while(FoundFile && (_tcscmp(findBuffer.cFileName,_T(".")) == 0 || _tcscmp(findBuffer.cFileName,_T("..")) == 0)) FoundFile = FindNextFile (hFile, &findBuffer); if (!FoundFile) { /* huh? somebody removed files and/or folders which were there */ error_file_not_found(); FindClose(hFile); freep(arg); return 1; } /* check if source and destination paths are on different volumes */ if (szSrcDirPath[0] != szDestPath[0]) dwMoveStatusFlags |= MOVE_PATHS_ON_DIF_VOL; /* move it */ do { TRACE ("Found file/directory: %s\n", debugstr_aw(findBuffer.cFileName)); nOverwrite = 1; dwMoveFlags = 0; dwMoveStatusFlags &= ~MOVE_DEST_IS_FILE & ~MOVE_DEST_IS_DIR & ~MOVE_SRC_CURRENT_IS_DIR & ~MOVE_DEST_EXISTS; _tcscpy(szFullSrcPath,szSrcDirPath); if(szFullSrcPath[_tcslen(szFullSrcPath) - 1] != _T('\\')) _tcscat (szFullSrcPath, _T("\\")); _tcscat(szFullSrcPath,findBuffer.cFileName); _tcscpy(szSrcPath, szFullSrcPath); if (IsExistingDirectory(szSrcPath)) { /* source is directory */ if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) { dwMoveStatusFlags |= MOVE_SRC_CURRENT_IS_DIR; /* source is file but at the current round we found a directory */ continue; } TRACE ("Source is dir: %s\n", debugstr_aw(szSrcPath)); dwMoveFlags = MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } /* if source is file we don't need to do anything special */ if (IsExistingDirectory(szDestPath)) { /* destination is existing directory */ TRACE ("Destination is directory: %s\n", debugstr_aw(szDestPath)); dwMoveStatusFlags |= MOVE_DEST_IS_DIR; /*build the dest string(accounts for *)*/ _tcscpy (szFullDestPath, szDestPath); /*check to see if there is an ending slash, if not add one*/ if(szFullDestPath[_tcslen(szFullDestPath) - 1] != _T('\\')) _tcscat (szFullDestPath, _T("\\")); _tcscat (szFullDestPath, findBuffer.cFileName); if (IsExistingFile(szFullDestPath) || IsExistingDirectory(szFullDestPath)) dwMoveStatusFlags |= MOVE_DEST_EXISTS; dwMoveFlags |= MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } if (IsExistingFile(szDestPath)) { /* destination is a file */ TRACE ("Destination is file: %s\n", debugstr_aw(szDestPath)); dwMoveStatusFlags |= MOVE_DEST_IS_FILE | MOVE_DEST_EXISTS; _tcscpy (szFullDestPath, szDestPath); dwMoveFlags |= MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } TRACE ("Move Status Flags: 0x%X\n",dwMoveStatusFlags); if (dwMoveStatusFlags & MOVE_SOURCE_IS_DIR && dwMoveStatusFlags & MOVE_DEST_IS_DIR && dwMoveStatusFlags & MOVE_SOURCE_HAS_WILD) { /* We are not allowed to have existing source and destination dir when there is wildcard in source */ error_syntax(NULL); FindClose(hFile); freep(arg); return 1; } if (!(dwMoveStatusFlags & (MOVE_DEST_IS_FILE | MOVE_DEST_IS_DIR))) { /* destination doesn't exist */ _tcscpy (szFullDestPath, szDestPath); if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) dwMoveStatusFlags |= MOVE_DEST_IS_FILE; if (dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) dwMoveStatusFlags |= MOVE_DEST_IS_DIR; dwMoveFlags |= MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE && dwMoveStatusFlags & MOVE_DEST_IS_FILE && !OnlyOneFile) { /*source has many files but there is only one destination file*/ error_invalid_parameter_format(pszDest); FindClose(hFile); freep (arg); return 1; } /*checks to make sure user wanted/wants the override*/ if((dwFlags & MOVE_OVER_NO) && (dwMoveStatusFlags & MOVE_DEST_EXISTS)) continue; if(!(dwFlags & MOVE_OVER_YES) && (dwMoveStatusFlags & MOVE_DEST_EXISTS)) nOverwrite = MoveOverwrite (szFullDestPath); if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK) continue; if (nOverwrite == PROMPT_ALL) dwFlags |= MOVE_OVER_YES; ConOutPrintf (_T("%s => %s "), szSrcPath, szFullDestPath); /* are we really supposed to do something */ if (dwFlags & MOVE_NOTHING) continue; /*move the file*/ if (!(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR && dwMoveStatusFlags & MOVE_PATHS_ON_DIF_VOL)) /* we aren't moving source folder to different drive */ MoveStatus = MoveFileEx (szSrcPath, szFullDestPath, dwMoveFlags); else { /* we are moving source folder to different drive */ _tcscpy(szMoveDest, szFullDestPath); _tcscpy(szMoveSrc, szSrcPath); DeleteFile(szMoveDest); MoveStatus = CreateDirectory(szMoveDest, NULL); /* we use default security settings */ if (MoveStatus) { _tcscat(szMoveDest,_T("\\")); _tcscat(szMoveSrc,_T("\\")); nDirLevel = 0; pszDestDirPointer = szMoveDest + _tcslen(szMoveDest); pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc); _tcscpy(pszSrcDirPointer,_T("*.*")); hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer); if (hDestFile == INVALID_HANDLE_VALUE) MoveStatus = FALSE; else { BOOL FirstTime = TRUE; FoundFile = TRUE; MoveStatus = FALSE; while(FoundFile) { if (FirstTime) FirstTime = FALSE; else FoundFile = FindNextFile (hDestFile, &findDestBuffer); if (!FoundFile) { /* Nothing to do in this folder so we stop working on it */ FindClose(hDestFile); (pszSrcDirPointer)--; (pszDestDirPointer)--; _tcscpy(pszSrcDirPointer,_T("")); _tcscpy(pszDestDirPointer,_T("")); if (nDirLevel > 0) { TCHAR szTempPath[MAX_PATH]; INT nDiff; FoundFile = TRUE; /* we need to continue our seek for files */ nDirLevel--; RemoveDirectory(szMoveSrc); GetDirectory(szMoveSrc,szTempPath,0); nDiff = _tcslen(szMoveSrc) - _tcslen(szTempPath); pszSrcDirPointer = pszSrcDirPointer - nDiff; _tcscpy(pszSrcDirPointer,_T("")); GetDirectory(szMoveDest,szTempPath,0); nDiff = _tcslen(szMoveDest) - _tcslen(szTempPath); pszDestDirPointer = pszDestDirPointer - nDiff; _tcscpy(pszDestDirPointer,_T("")); if(szMoveSrc[_tcslen(szMoveSrc) - 1] != _T('\\')) _tcscat (szMoveSrc, _T("\\")); if(szMoveDest[_tcslen(szMoveDest) - 1] != _T('\\')) _tcscat (szMoveDest, _T("\\")); pszDestDirPointer = szMoveDest + _tcslen(szMoveDest); pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc); _tcscpy(pszSrcDirPointer,_T("*.*")); hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer); if (hDestFile == INVALID_HANDLE_VALUE) continue; FirstTime = TRUE; } else { MoveStatus = TRUE; /* we moved everything so lets tell user about it */ RemoveDirectory(szMoveSrc); } continue; } /* if we find "." or ".." we'll skip them */ if (_tcscmp(findDestBuffer.cFileName,_T(".")) == 0 || _tcscmp(findDestBuffer.cFileName,_T("..")) == 0) continue; _tcscpy(pszSrcDirPointer, findDestBuffer.cFileName); _tcscpy(pszDestDirPointer, findDestBuffer.cFileName); if (IsExistingFile(szMoveSrc)) { FoundFile = CopyFile(szMoveSrc, szMoveDest, FALSE); if (!FoundFile) continue; DeleteFile(szMoveSrc); } else { FindClose(hDestFile); CreateDirectory(szMoveDest, NULL); _tcscat(szMoveDest,_T("\\")); _tcscat(szMoveSrc,_T("\\")); nDirLevel++; pszDestDirPointer = szMoveDest + _tcslen(szMoveDest); pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc); _tcscpy(pszSrcDirPointer,_T("*.*")); hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer); if (hDestFile == INVALID_HANDLE_VALUE) { FoundFile = FALSE; continue; } FirstTime = TRUE; } } } } } if (MoveStatus) ConOutResPrintf(STRING_MOVE_ERROR1); else ConOutResPrintf(STRING_MOVE_ERROR2); } while ((!OnlyOneFile || dwMoveStatusFlags & MOVE_SRC_CURRENT_IS_DIR ) && !(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) && FindNextFile (hFile, &findBuffer)); FindClose (hFile); freep (arg); return 0; }
int cd_dir(char *param, int cdd, const char * const fctname) { char **argv, *dir; int argc, opts; int rv, freeDir; if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0) return 1; freeDir = 0; rv = 1; /* if doing a CD and no parameters given, print out current directory */ if(argc == 0) { if((dir = cwd(0)) != 0) { puts(dir); freeDir = 1; goto okRet; } goto errRet; } else if(argc != 1) { error_syntax(0); goto errRet; } else { assert(argv[0]); #ifdef FEATURE_CDD_FNAME /* if path refers to an existing file and not directory, ignore filename portion */ if (cdd && (dfnstat(argv[0]) & DFN_FILE)) { dir = strrchr(argv[0], '\\'); if (dir == NULL) { dir = argv[0]; if (dir[1] == ':') dir[2]='\0'; /* change drive only, no path */ else goto okRet; /* no drive, no path, so exit early */ } else /* includes a path or refers to root dir */ { *(dir+1) = '\0'; } } #endif dir = strchr(argv[0], '\0'); /* take off trailing \ if any, but ONLY if dir is not the root dir */ while(dir > &argv[0][1] && *--dir == '\\' && dir[-1] != ':') *dir = '\0'; dir = argv[0]; #ifdef FEATURE_LAST_DIR if(strcmp(dir, "-") == 0) { assert(!freeDir); /* change to last directory */ lastDirGet(&dir); freeDir = 1; } lastDirSet(); if(!dir) /* "CD -" without a CD before at all */ goto okRet; #endif if(*dir && dir[1] == ':') { if(cdd) { if(changeDrive(*dir) != 0) goto errRet; if(!dir[2]) /* only change drive */ goto okRet; } else if(!dir[2]) { /* Real CHDIR displays CWD of specified drive */ assert(freeDir == 0); if((dir = cwd(*dir)) != 0) { puts(dir); freeDir = 1; goto okRet; } goto errRet; } } dprintf(("%s: '%s'\n", fctname, dir)); if(chdir(dir) != 0) { error_dirfct_failed(fctname, dir); goto errRet; } } okRet: rv = 0; errRet: freep(argv); if(freeDir) free(dir); return rv; }
int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) { int wrote_something = 0; int ret = 0; if(!context) return CCX_OK; context = change_filename(context); #ifdef ENABLE_SHARING if (ccx_options.sharing_enabled) ccx_share_send(sub); #endif //ENABLE_SHARING if (context->splitbysentence) { // Write to a buffer that is later s+plit to generate split // in sentences if (sub->type == CC_BITMAP) wrote_something = write_cc_bitmap_to_sentence_buffer(sub, context); } else { // Write subtitles as they come if (sub->type == CC_608) { struct eia608_screen *data = NULL; struct ccx_s_write *out; for (data = sub->data; sub->nb_data; sub->nb_data--, data++) { // Determine context based on channel. This replaces the code that was above, as this was incomplete (for cases where -12 was used for example) out = get_output_ctx(context, data->my_field); if (data->format == SFORMAT_XDS) { data->end_time = data->end_time + context->subs_delay; xds_write_transcript_line_prefix(context, out, data->start_time, data->end_time, data->cur_xds_packet_class); if (data->xds_len > 0) { ret = write(out->fh, data->xds_str, data->xds_len); if (ret < data->xds_len) { mprint("WARNING:Loss of data\n"); } } freep(&data->xds_str); write_newline(context, 0); continue; } data->end_time = data->end_time + context->subs_delay; switch (context->write_format) { case CCX_OF_SRT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_srt(data, context); break; case CCX_OF_G608: wrote_something = write_cc_buffer_as_g608(data, context); break; case CCX_OF_WEBVTT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_webvtt(data, context); break; case CCX_OF_SAMI: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_sami(data, context); break; case CCX_OF_SMPTETT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, data->start_time); wrote_something = write_cc_buffer_as_smptett(data, context); break; case CCX_OF_TRANSCRIPT: wrote_something = write_cc_buffer_as_transcript2(data, context); break; case CCX_OF_SPUPNG: wrote_something = write_cc_buffer_as_spupng(data, context); break; case CCX_OF_SIMPLE_XML: if (ccx_options.keep_output_closed && context->out->temporarily_closed) { temporarily_open_output(context->out); write_subtitle_file_header(context, context->out); } wrote_something = write_cc_buffer_as_simplexml(data, context); if (ccx_options.keep_output_closed) { write_subtitle_file_footer(context, context->out); temporarily_close_output(context->out); } break; default: break; } if (wrote_something) context->last_displayed_subs_ms = data->end_time; if (context->gui_mode_reports) write_cc_buffer_to_gui(sub->data, context); } freep(&sub->data); } if (sub->type == CC_BITMAP) { switch (context->write_format) { case CCX_OF_SRT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_srt(sub, context); break; case CCX_OF_WEBVTT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_webvtt(sub, context); break; case CCX_OF_SAMI: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_sami(sub, context); break; case CCX_OF_SMPTETT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_bitmap_as_smptett(sub, context); break; case CCX_OF_TRANSCRIPT: wrote_something = write_cc_bitmap_as_transcript(sub, context); break; case CCX_OF_SPUPNG: wrote_something = write_cc_bitmap_as_spupng(sub, context); break; case CCX_OF_SIMPLE_XML: wrote_something = write_cc_bitmap_as_simplexml(sub, context); break; #ifdef WITH_LIBCURL case CCX_OF_CURL: wrote_something = write_cc_bitmap_as_libcurl(sub, context); break; #endif default: break; } } if (sub->type == CC_RAW) { if (context->send_to_srv) net_send_header(sub->data, sub->nb_data); else { ret = write(context->out->fh, sub->data, sub->nb_data); if (ret < sub->nb_data) { mprint("WARNING: Loss of data\n"); } } sub->nb_data = 0; } if (sub->type == CC_TEXT) { switch (context->write_format) { case CCX_OF_SRT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_srt(sub, context); break; case CCX_OF_WEBVTT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_webvtt(sub, context); break; case CCX_OF_SAMI: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_sami(sub, context); break; case CCX_OF_SMPTETT: if (!context->startcredits_displayed && context->start_credits_text != NULL) try_to_add_start_credits(context, sub->start_time); wrote_something = write_cc_subtitle_as_smptett(sub, context); break; case CCX_OF_TRANSCRIPT: wrote_something = write_cc_subtitle_as_transcript(sub, context); break; case CCX_OF_SPUPNG: wrote_something = write_cc_subtitle_as_spupng(sub, context); break; case CCX_OF_SIMPLE_XML: wrote_something = write_cc_subtitle_as_simplexml(sub, context); break; default: break; } sub->nb_data = 0; } } if (!sub->nb_data) freep(&sub->data); if (wrote_something && context->force_flush) fsync(context->out->fh); // Don't buffer return wrote_something; }
INT cmd_type (LPTSTR param) { TCHAR buff[256]; HANDLE hFile, hConsoleOut; DWORD dwRet; INT argc,i; LPTSTR *argv; LPTSTR errmsg; BOOL bPaging = FALSE; BOOL bFirstTime = TRUE; hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE); if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_TYPE_HELP1); return 0; } if (!*param) { error_req_param_missing (); return 1; } argv = split (param, &argc, TRUE); for(i = 0; i < argc; i++) { if(*argv[i] == _T('/') && _tcslen(argv[i]) >= 2 && _totupper(argv[i][1]) == _T('P')) { bPaging = TRUE; } } for (i = 0; i < argc; i++) { if (_T('/') == argv[i][0] && _totupper(argv[i][1]) != _T('P')) { ConErrResPrintf(STRING_TYPE_ERROR1, argv[i] + 1); continue; } nErrorLevel = 0; hFile = CreateFile(argv[i], GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL); if(hFile == INVALID_HANDLE_VALUE) { FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &errmsg, 0, NULL); ConErrPrintf (_T("%s - %s"), argv[i], errmsg); LocalFree (errmsg); nErrorLevel = 1; continue; } if (bPaging) { while (FileGetString (hFile, buff, sizeof(buff) / sizeof(TCHAR))) { if (ConOutPrintfPaging(bFirstTime, _T("%s"), buff) == 1) { bCtrlBreak = FALSE; CloseHandle(hFile); freep(argv); return 0; } bFirstTime = FALSE; } } else { while (ReadFile(hFile, buff, sizeof(buff), &dwRet, NULL) && dwRet > 0) { WriteFile(hConsoleOut, buff, dwRet, &dwRet, NULL); if (bCtrlBreak) { bCtrlBreak = FALSE; CloseHandle(hFile); freep(argv); return 0; } } } CloseHandle(hFile); } freep (argv); return 0; }
INT CommandAttrib (LPTSTR param) { LPTSTR *arg; INT argc, i; TCHAR szPath[MAX_PATH]; TCHAR szFileName [MAX_PATH]; BOOL bRecurse = FALSE; BOOL bDirectories = FALSE; DWORD dwAttrib = 0; DWORD dwMask = 0; /* initialize strings */ szPath[0] = _T('\0'); szFileName[0] = _T('\0'); /* print help */ if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_ATTRIB_HELP); return 0; } nErrorLevel = 0; /* build parameter array */ arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) { if (_tcsicmp (arg[i], _T("/s")) == 0) bRecurse = TRUE; else if (_tcsicmp (arg[i], _T("/d")) == 0) bDirectories = TRUE; } /* create attributes and mask */ for (i = 0; i < argc; i++) { if (*arg[i] == _T('+')) { if (_tcslen (arg[i]) != 2) { error_invalid_parameter_format (arg[i]); freep (arg); return -1; } switch ((TCHAR)_totupper (arg[i][1])) { case _T('A'): dwMask |= FILE_ATTRIBUTE_ARCHIVE; dwAttrib |= FILE_ATTRIBUTE_ARCHIVE; break; case _T('H'): dwMask |= FILE_ATTRIBUTE_HIDDEN; dwAttrib |= FILE_ATTRIBUTE_HIDDEN; break; case _T('R'): dwMask |= FILE_ATTRIBUTE_READONLY; dwAttrib |= FILE_ATTRIBUTE_READONLY; break; case _T('S'): dwMask |= FILE_ATTRIBUTE_SYSTEM; dwAttrib |= FILE_ATTRIBUTE_SYSTEM; break; default: error_invalid_parameter_format (arg[i]); freep (arg); return -1; } } else if (*arg[i] == _T('-')) { if (_tcslen (arg[i]) != 2) { error_invalid_parameter_format (arg[i]); freep (arg); return -1; } switch ((TCHAR)_totupper (arg[i][1])) { case _T('A'): dwMask |= FILE_ATTRIBUTE_ARCHIVE; dwAttrib &= ~FILE_ATTRIBUTE_ARCHIVE; break; case _T('H'): dwMask |= FILE_ATTRIBUTE_HIDDEN; dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN; break; case _T('R'): dwMask |= FILE_ATTRIBUTE_READONLY; dwAttrib &= ~FILE_ATTRIBUTE_READONLY; break; case _T('S'): dwMask |= FILE_ATTRIBUTE_SYSTEM; dwAttrib &= ~FILE_ATTRIBUTE_SYSTEM; break; default: error_invalid_parameter_format (arg[i]); freep (arg); return -1; } } } if (argc == 0) { DWORD len; len = GetCurrentDirectory (MAX_PATH, szPath); if (szPath[len-1] != _T('\\')) { szPath[len] = _T('\\'); szPath[len + 1] = 0; } _tcscpy (szFileName, _T("*.*")); PrintAttribute (szPath, szFileName, bRecurse); freep (arg); return 0; } /* get full file name */ for (i = 0; i < argc; i++) { if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/'))) { LPTSTR p; GetFullPathName (arg[i], MAX_PATH, szPath, NULL); p = _tcsrchr (szPath, _T('\\')) + 1; _tcscpy (szFileName, p); *p = _T('\0'); if (dwMask == 0) PrintAttribute (szPath, szFileName, bRecurse); else ChangeAttribute (szPath, szFileName, dwMask, dwAttrib, bRecurse, bDirectories); } } freep (arg); return 0; }
/* * @param alpha out * @param intensity in * @param palette out should be already initialized * @param bitmap in * @param size in size of bitmap * @param max_color in * @param nb_color in */ static int quantize_map(png_byte *alpha, png_color *palette, uint8_t *bitmap, int size, int max_color, int nb_color) { /* * occurrence of color in image */ uint32_t *histogram = NULL; /* intensity ordered table */ uint8_t *iot = NULL; /* array of color with most occurrence according to histogram * save index of intensity order table */ uint32_t *mcit = NULL; struct transIntensity ti = { alpha,palette}; int ret = 0; histogram = (uint32_t*) malloc(nb_color * sizeof(uint32_t)); if (!histogram) { ret = -1; goto end; } iot = (uint8_t*) malloc(nb_color * sizeof(uint8_t)); if (!iot) { ret = -1; goto end; } mcit = (uint32_t*) malloc(nb_color * sizeof(uint32_t)); if (!mcit) { ret = -1; goto end; } memset(histogram, 0, nb_color * sizeof(uint32_t)); /* initializing intensity ordered table with serial order of unsorted color table */ for (int i = 0; i < nb_color; i++) { iot[i] = i; } memset(mcit, 0, nb_color * sizeof(uint32_t)); /* calculate histogram of image */ for (int i = 0; i < size; i++) { histogram[bitmap[i]]++; } /* sorted in increasing order of intensity */ shell_sort((void*)iot, nb_color, sizeof(*iot), check_trans_tn_intensity, (void*)&ti); #ifdef OCR_DEBUG ccx_common_logging.log_ftn("Intensity ordered table\n"); for (int i = 0; i < nb_color; i++) { ccx_common_logging.log_ftn("%02d) map %02d hist %02d\n", i, iot[i], histogram[iot[i]]); } #endif /** * using selection sort since need to find only max_color * Hostogram becomes invalid in this loop */ for (int i = 0; i < max_color; i++) { uint32_t max_val = 0; uint32_t max_ind = 0; int j; for (j = 0; j < nb_color; j++) { if (max_val < histogram[iot[j]]) { max_val = histogram[iot[j]]; max_ind = j; } } for (j = i; j > 0 && max_ind < mcit[j - 1]; j--) { mcit[j] = mcit[j - 1]; } mcit[j] = max_ind; histogram[iot[max_ind]] = 0; } #ifdef OCR_DEBUG ccx_common_logging.log_ftn("max redundant intensities table\n"); for (int i = 0; i < max_color; i++) { ccx_common_logging.log_ftn("%02d) mcit %02d\n", i, mcit[i]); } #endif for (int i = 0, mxi = 0; i < nb_color; i++) { int step, inc; if (i == mcit[mxi]) { mxi = (mxi < max_color) ? mxi + 1 : mxi; continue; } inc = (mxi) ? -1 : 0; step = mcit[mxi + inc] + ((mcit[mxi] - mcit[mxi + inc]) / 2); if (i <= step) { int index = iot[mcit[mxi + inc]]; alpha[iot[i]] = alpha[index]; palette[iot[i]].red = palette[index].red; palette[iot[i]].blue = palette[index].blue; palette[iot[i]].green = palette[index].green; } else { int index = iot[mcit[mxi]]; alpha[iot[i]] = alpha[index]; palette[iot[i]].red = palette[index].red; palette[iot[i]].blue = palette[index].blue; palette[iot[i]].green = palette[index].green; } } #ifdef OCR_DEBUG ccx_common_logging.log_ftn("Colors present in quantized Image\n"); for (int i = 0; i < nb_color; i++) { ccx_common_logging.log_ftn("%02d)r %03d g %03d b %03d a %03d\n", i, palette[i].red, palette[i].green, palette[i].blue, alpha[i]); } #endif end: freep(&histogram); freep(&mcit); freep(&iot); return ret; }
int write_cc_bitmap_as_srt(struct cc_subtitle *sub, struct encoder_ctx *context) { int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; LLONG ms_start, ms_end; unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; char timeline[128]; int len = 0; int used; int i = 0; char *str; if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER)) { ms_start = context->prev_start; ms_end = sub->start_time; } else if ( !(sub->flags & SUB_EOD_MARKER)) { ms_start = sub->start_time; ms_end = sub->end_time; } else if (context->prev_start == -1 && (sub->flags & SUB_EOD_MARKER)) { ms_start = 1; ms_end = sub->start_time; } if(sub->nb_data == 0 ) return 0; if(sub->flags & SUB_EOD_MARKER) context->prev_start = sub->start_time; str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length); if (str) { if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) { mstotime (ms_start,&h1,&m1,&s1,&ms1); mstotime (ms_end-1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. context->srt_counter++; sprintf(timeline, "%u\r\n", context->srt_counter); used = encode_line(context, context->buffer,(unsigned char *) timeline); write(context->out->fh, context->buffer, used); sprintf (timeline, "%02u:%02u:%02u,%03u --> %02u:%02u:%02u,%03u\r\n", h1,m1,s1,ms1, h2,m2,s2,ms2); used = encode_line(context, context->buffer,(unsigned char *) timeline); write (context->out->fh, context->buffer, used); len = strlen(str); write (context->out->fh, str, len); write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length); } freep(&str); } for(i = 0, rect = sub->data; i < sub->nb_data; i++, rect++) { freep(rect->data); freep(rect->data+1); } #endif sub->nb_data = 0; freep(&sub->data); return ret; }
static void dinit_decoder_setting (struct ccx_decoders_common_settings_t **setting) { freep(setting); }
int write_cc_bitmap_as_libcurl(struct cc_subtitle *sub, struct encoder_ctx *context) { int ret = 0; #ifdef ENABLE_OCR struct cc_bitmap* rect; LLONG ms_start, ms_end; unsigned h1, m1, s1, ms1; unsigned h2, m2, s2, ms2; char timeline[128]; int len = 0; int used; int i = 0; char *str; if (context->prev_start != -1 && (sub->flags & SUB_EOD_MARKER)) { ms_start = context->prev_start; ms_end = sub->start_time; } else if (!(sub->flags & SUB_EOD_MARKER)) { ms_start = sub->start_time; ms_end = sub->end_time; } else if (context->prev_start == -1 && (sub->flags & SUB_EOD_MARKER)) { ms_start = 1; ms_end = sub->start_time; } if (sub->nb_data == 0) return 0; if (sub->flags & SUB_EOD_MARKER) context->prev_start = sub->start_time; str = paraof_ocrtext(sub, context->encoded_crlf, context->encoded_crlf_length); if (str) { if (context->prev_start != -1 || !(sub->flags & SUB_EOD_MARKER)) { millis_to_time(ms_start, &h1, &m1, &s1, &ms1); millis_to_time(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. context->srt_counter++; sprintf(timeline, "group_id=ccextractordev&start_time=%" PRIu64 "&end_time=%" PRIu64 "&lang=en", ms_start, ms_end); char *curlline = NULL; curlline = str_reallocncat(curlline, timeline); curlline = str_reallocncat(curlline, "&payload="); char *urlencoded=curl_easy_escape (curl, str, 0); curlline = str_reallocncat(curlline,urlencoded); curl_free (urlencoded); mprint("%s", curlline); char *result = malloc(strlen(ccx_options.curlposturl) + strlen("/frame/") + 1); strcpy(result, ccx_options.curlposturl); strcat(result, "/frame/"); curl_easy_setopt(curl, CURLOPT_URL, result); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, curlline); free(result); res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) mprint("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); } freep(&str); } for (i = 0, rect = sub->data; i < sub->nb_data; i++, rect++) { freep(rect->data); freep(rect->data + 1); } #endif sub->nb_data = 0; freep(&sub->data); return ret; }