static void create_new_splitfile() { if (SPLIT_MAX_PIECES - 1 == numfiles) st_error("too many split files would be created -- maximum is %d",SPLIT_MAX_PIECES); if (NULL == (files[numfiles] = new_wave_info(NULL))) st_error("could not allocate memory for split points array"); }
static void get_extractable_tracks() { int i,start,end; char *p,*q,*seps = ","; for (i=0;i<numfiles;i++) extract_track[i] = FALSE; if (extract_tracks) { /* extract only tracks in user-specified list */ p = strtok(extract_tracks,seps); while (p) { if ((q = strstr(p,"-"))) { *q = 0; q++; } start = atoi(p); end = (q) ? ((*q) ? atoi(q) : SPLIT_MAX_PIECES) : start; if (start > end) { i = start; start = end; end = i; } if (start < 1) st_error("track number to extract (%d) is not in range [1 .. %d]",start,SPLIT_MAX_PIECES); if (end > SPLIT_MAX_PIECES) st_error("track number to extract (%d) is not in range [1 .. %d]",end,SPLIT_MAX_PIECES); start--; end--; for (i=start;i<=end;i++) { extract_track[i] = TRUE; numextracted++; } p = strtok(NULL,seps); } return; } /* extract all tracks */ for (i=0;i<SPLIT_MAX_PIECES;i++) { extract_track[i] = TRUE; numextracted++; } }
static int cd_withoutarg(t_system *sys) { if (chdir(sys->getenv(sys, "HOME")) == -1) return (st_error(sys, "Aucun fichier ou dossier de ce type.\n")); sys->setenv(sys, "OLDPWD", sys->getenv(sys, "PWD")); sys->setenv(sys, "PWD", sys->getenv(sys, "HOME")); return (0); }
static int cd_withargs(t_system *sys, t_elem *tmp) { if (sm_egal("-", (char*)tmp->mem)) { if (chdir(sys->getenv(sys, "OLDPWD")) == -1) return (st_error(sys, "Aucun fichier ou dossier de ce type.\n")); sys->setenv(sys, "OLDPWD", sys->getenv(sys, "PWD")); sys->setenv(sys, "PWD", getcwd(NULL, 0)); } else { if (chdir((char*)tmp->mem) == -1) return (st_error(sys, "Aucun fichier ou dossier de ce type.\n")); sys->setenv(sys, "OLDPWD", sys->getenv(sys, "PWD")); sys->setenv(sys, "PWD", getcwd(NULL, 0)); } return (0); }
lexeme *get_lex(lexer_info *linfo) { lexeme *lex = NULL; buffer buf; new_buffer(&buf); do { if (linfo->get_next_char) { linfo->get_next_char = 0; get_char(linfo); } switch (linfo->state) { case ST_START: lex = st_start(linfo, &buf); break; case ST_ONE_SYM_LEX: lex = st_one_sym_lex(linfo, &buf); break; case ST_ONE_TWO_SYM_LEX: lex = st_one_two_sym_lex(linfo, &buf); break; case ST_BACKSLASH: lex = st_backslash(linfo, &buf); break; case ST_BACKSLASH_IN_QUOTES: lex = st_backslash_in_quotes(linfo, &buf); break; case ST_IN_QUOTES: lex = st_in_quotes(linfo, &buf); break; case ST_WORD: lex = st_word(linfo, &buf); break; case ST_ERROR: lex = st_error(linfo, &buf); break; case ST_EOLN_EOF: lex = st_eoln_eof(linfo, &buf); break; } /* switch */ } while (lex == NULL); return lex; }
static bool process_file(char *filename) { int i; wave_info *info; bool success; if (NULL == (info = new_wave_info(filename))) st_error("cannot continue due to error(s) shown above"); input_is_cd_quality = (PROB_NOT_CD(info) ? FALSE : TRUE); get_extractable_tracks(); if (repeated_split_point) read_split_points_repeated(info); else read_split_points_file(info); if (files[numfiles-2]->beginning_byte > info->data_size) st_error("split points go beyond input file's data size"); if (files[numfiles-2]->beginning_byte == info->data_size) { st_free(files[numfiles-1]); numfiles--; } else { files[numfiles-1]->beginning_byte = info->data_size; files[numfiles-1]->data_size = info->data_size - files[numfiles-2]->beginning_byte; adjust_splitfile(numfiles-1); } success = split_file(info); for (i=0;i<numfiles;i++) st_free(files[i]); st_free(info); return success; }
static bool process(int argc,char **argv,int start) { int i; bool success; char *filename; input_init(start,argc,argv); input_read_all_files(); numfiles = input_get_file_count(); if (numfiles < 2) st_help("need two or more files to process"); if (NULL == (files = malloc((numfiles + 1) * sizeof(wave_info *)))) st_error("could not allocate memory for file info array"); for (i=0;i<numfiles;i++) { filename = input_get_filename(); if (NULL == (files[i] = new_wave_info(filename))) { st_error("could not open file: [%s]",filename); } } files[numfiles] = NULL; check_headers(); reorder_files(files,numfiles); success = do_join(); for (i=0;i<numfiles;i++) st_free(files[i]); st_free(files); return success; }
static int st_iscorrect(t_node *ast, t_system *s) { t_id id; id = ast->execute->id; if ((id == CMD_ARG || id == BUILTIN) && (ast->left || ast->right)) return (0); else if ((id == CMD_ARG || id == BUILTIN)) return (1); else if (!(ast->left && ast->right)) return (st_error(ast, s)); return ((!st_iscorrect(ast->left, s) ? 0 : st_iscorrect(ast->right, s))); }
static bool process(int argc,char **argv,int start) { char *filename; bool success; input_init(start,argc,argv); if (!(filename = input_get_filename())) { st_error("need exactly one file to process"); } success = process_file(filename); return success; }
static void check_headers() { int i; bool ba_warned = 0; for (i=0;i<numfiles;i++) { if (PROB_NOT_CD(files[i])) all_files_cd_quality = FALSE; if (PROB_HDR_INCONSISTENT(files[i])) st_error("file has an inconsistent header: [%s]",files[i]->filename); if (PROB_TRUNCATED(files[i])) st_error("file seems to be truncated: [%s]",files[i]->filename); } for (i=1;i<numfiles;i++) { if (files[i]->wave_format != files[0]->wave_format) st_error("WAVE format differs among these files"); if (files[i]->channels != files[0]->channels) st_error("number of channels differs among these files"); if (files[i]->samples_per_sec != files[0]->samples_per_sec) st_error("samples per second differs among these files"); if (files[i]->avg_bytes_per_sec != files[0]->avg_bytes_per_sec) st_error("average bytes per second differs among these files"); if (files[i]->bits_per_sample != files[0]->bits_per_sample) st_error("bits per sample differs among these files"); if (files[i]->block_align != files[0]->block_align) { if (!ba_warned) { st_warning("block align differs among these files"); ba_warned = TRUE; } } } }
static bool open_this_file(int i,char *outfilename,progress_info *proginfo) { unsigned char header[CANONICAL_HEADER_SIZE]; create_output_filename(files[i]->filename,files[i]->input_format->extension,outfilename); proginfo->filename1 = files[i]->filename; proginfo->filedesc1 = files[i]->m_ss; proginfo->filename2 = outfilename; if (NULL == (files[i]->output = open_output_stream(outfilename,&files[i]->output_proc))) { prog_error(proginfo); st_error("could not open output file: [%s]",outfilename); } make_canonical_header(header,files[i]); if ((numfiles - 1 == i) && pad) put_data_size(header,CANONICAL_HEADER_SIZE,files[i]->new_data_size+pad_bytes); else { put_data_size(header,CANONICAL_HEADER_SIZE,files[i]->new_data_size); if (files[i]->new_data_size & 1) put_chunk_size(header,(files[i]->new_data_size + 1) + CANONICAL_HEADER_SIZE - 8); } if (write_n_bytes(files[i]->output,header,CANONICAL_HEADER_SIZE,proginfo) != CANONICAL_HEADER_SIZE) { prog_error(proginfo); st_warning("error while writing %d-byte WAVE header",CANONICAL_HEADER_SIZE); return FALSE; } proginfo->filename2 = outfilename; proginfo->bytes_total = files[i]->new_data_size + CANONICAL_HEADER_SIZE; return TRUE; }
static bool write_fixed_files() { int cur_input,cur_output; unsigned long bytes_have,bytes_needed,bytes_to_xfer; char outfilename[FILENAME_SIZE]; bool success; progress_info proginfo; success = FALSE; cur_input = cur_output = 0; bytes_have = (unsigned long)files[cur_input]->data_size; bytes_needed = (unsigned long)files[cur_output]->new_data_size; proginfo.initialized = FALSE; proginfo.prefix = "Fixing"; proginfo.clause = "-->"; proginfo.filename1 = files[0]->filename; proginfo.filedesc1 = files[0]->m_ss; proginfo.filename2 = NULL; proginfo.filedesc2 = NULL; proginfo.bytes_total = 1; if (!open_this_file(cur_output,outfilename,&proginfo)) goto cleanup; if (!reopen_input_file(cur_input,&proginfo)) goto cleanup; while (cur_input < numfiles && cur_output < numfiles) { bytes_to_xfer = min(bytes_have,bytes_needed); if (transfer_n_bytes(files[cur_input]->input,files[cur_output]->output,bytes_to_xfer,&proginfo) != bytes_to_xfer) { prog_error(&proginfo); st_warning("error while transferring %lu bytes of data",bytes_to_xfer); goto cleanup; } bytes_have -= bytes_to_xfer; bytes_needed -= bytes_to_xfer; if (0 == bytes_have) { close_input_stream(files[cur_input]); files[cur_input]->input = NULL; cur_input++; if (cur_input < numfiles) { bytes_have = (unsigned long)files[cur_input]->data_size; if (!reopen_input_file(cur_input,&proginfo)) goto cleanup; } } if (0 == bytes_needed) { prog_success(&proginfo); if (numfiles - 1 == cur_output) { if (pad) { if (pad_bytes) { if (pad_bytes != write_padding(files[cur_output]->output,pad_bytes,NULL)) { prog_error(&proginfo); st_warning("error while padding with %d zero-bytes",pad_bytes); goto cleanup; } st_info("Padded last file with %d zero-bytes.\n",pad_bytes); } else st_info("No padding needed.\n"); } else { st_info("Last file was not padded, "); if (pad_bytes) st_info("though it needs %d bytes of padding.\n",pad_bytes); else st_info("nor was it needed.\n"); if ((files[cur_output]->new_data_size & 1) && (1 != write_padding(files[cur_output]->output,1,NULL))) { prog_error(&proginfo); st_warning("error while NULL-padding odd-sized data chunk"); goto cleanup; } } } close_output_stream(files[cur_output]); files[cur_output]->output = NULL; cur_output++; if (cur_output < numfiles) { bytes_needed = (unsigned long)files[cur_output]->new_data_size; if (!open_this_file(cur_output,outfilename,&proginfo)) goto cleanup; } } } success = TRUE; cleanup: if (!success) { close_output_stream(files[cur_output]); remove_file(outfilename); st_error("failed to fix files"); } return success; }
static bool split_file(wave_info *info) { unsigned char header[CANONICAL_HEADER_SIZE]; char outfilename[FILENAME_SIZE],filenum[FILENAME_SIZE]; int current; wint discard,bytes; bool success; wlong leadin_bytes, leadout_bytes, bytes_to_xfer; progress_info proginfo; // uwe double start_time, end_time, last_end_time; success = FALSE; proginfo.initialized = FALSE; proginfo.prefix = "Splitting"; proginfo.clause = "-->"; proginfo.filename1 = info->filename; proginfo.filedesc1 = info->m_ss; proginfo.filename2 = NULL; proginfo.filedesc2 = NULL; proginfo.bytes_total = 0; if (!open_input_stream(info)) { prog_error(&proginfo); st_error("could not reopen input file: [%s]",info->filename); } discard = info->header_size; while (discard > 0) { bytes = min(discard,CANONICAL_HEADER_SIZE); if (read_n_bytes(info->input,header,bytes,NULL) != bytes) { prog_error(&proginfo); st_error("error while discarding %d-byte WAVE header",info->header_size); } discard -= bytes; } leadin_bytes = (leadin) ? smrt_parse((unsigned char *)leadin,info) : 0; leadout_bytes = (leadout) ? smrt_parse((unsigned char *)leadout,info) : 0; adjust_for_leadinout(leadin_bytes,leadout_bytes); // uwe transcription st_output("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); st_output("<Trans version=\"2\">\n\n"); start_time = end_time = last_end_time = 0; for (current=0;current<numfiles;current++) { if (SPLIT_INPUT_CUE == input_type && cueinfo.format) { create_output_filename(cueinfo.filenames[current],"",outfilename); } else { st_snprintf(filenum,8,num_format,current+offset); create_output_filename(filenum,"",outfilename); } files[current]->chunk_size = files[current]->data_size + CANONICAL_HEADER_SIZE - 8; files[current]->channels = info->channels; files[current]->samples_per_sec = info->samples_per_sec; files[current]->avg_bytes_per_sec = info->avg_bytes_per_sec; files[current]->block_align = info->block_align; files[current]->bits_per_sample = info->bits_per_sample; files[current]->wave_format = info->wave_format; files[current]->rate = info->rate; files[current]->length = files[current]->data_size / (wlong)info->rate; files[current]->exact_length = (double)files[current]->data_size / (double)info->rate; files[current]->total_size = files[current]->chunk_size + 8; length_to_str(files[current]); proginfo.filedesc2 = files[current]->m_ss; proginfo.bytes_total = files[current]->total_size; if (extract_track[current]) { proginfo.prefix = "Splitting"; proginfo.filename2 = outfilename; // uwe transcription start_time += last_end_time; end_time += files[current]->data_size / (wlong)info->rate; last_end_time = end_time; printf("<Turn startTime=\"%.2f\"", start_time); // %.2f st_output(" endTime=\"%.2f\"", end_time); st_output(" splitFilename=\"%s\"", outfilename); st_output(" speaker=\"spk1\">\n"); st_output("<Sync time=\"%.2f\"/>\n", start_time); st_output("***Include transcript words here***\n"); st_output("</Turn>\n"); if (NULL == (files[current]->output = open_output_stream(outfilename,&files[current]->output_proc))) { prog_error(&proginfo); st_error("could not open output file"); } } else { proginfo.prefix = "Skipping "; proginfo.filename2 = NULLDEVICE; if (NULL == (files[current]->output = open_output(NULLDEVICE))) { prog_error(&proginfo); st_error("while skipping track %d: could not open output file: [%s]",current+1,NULLDEVICE); } files[current]->output_proc.pid = NO_CHILD_PID; } if (PROB_ODD_SIZED_DATA(files[current])) files[current]->chunk_size++; make_canonical_header(header,files[current]); // uwe disable //prog_update(&proginfo); if (write_n_bytes(files[current]->output,header,CANONICAL_HEADER_SIZE,&proginfo) != CANONICAL_HEADER_SIZE) { prog_error(&proginfo); st_warning("error while writing %d-byte WAVE header",CANONICAL_HEADER_SIZE); goto cleanup; } /* if this is not the first file, finish up writing previous file, and simultaneously start writing to current file */ if (0 != current) { /* write overlapping lead-in/lead-out data to both previous and current files */ if (transfer_n_bytes2(info->input,files[current]->output,files[current-1]->output,leadin_bytes+leadout_bytes,&proginfo) != leadin_bytes+leadout_bytes) { prog_error(&proginfo); st_warning("error while transferring %ld bytes of lead-in/lead-out",leadin_bytes+leadout_bytes); goto cleanup; } /* pad and close previous file */ if (PROB_ODD_SIZED_DATA(files[current-1]) && (1 != write_padding(files[current-1]->output,1,&proginfo))) { prog_error(&proginfo); st_warning("error while NULL-padding odd-sized data chunk"); goto cleanup; } close_output(files[current-1]->output,files[current-1]->output_proc); } /* transfer unique non-overlapping data from input file to current file */ bytes_to_xfer = files[current]->new_data_size; if (0 != current) bytes_to_xfer -= leadout_bytes; if (numfiles - 1 != current) bytes_to_xfer -= leadin_bytes; if (transfer_n_bytes(info->input,files[current]->output,bytes_to_xfer,&proginfo) != bytes_to_xfer) { prog_error(&proginfo); st_warning("error while transferring %ld bytes of data",bytes_to_xfer); goto cleanup; } /* if this is the last file, close it */ if (numfiles - 1 == current) { /* pad and close current file */ if (PROB_ODD_SIZED_DATA(files[current]) && (1 != write_padding(files[current]->output,1,&proginfo))) { prog_error(&proginfo); st_warning("error while NULL-padding odd-sized data chunk"); goto cleanup; } close_output(files[current]->output,files[current]->output_proc); // uwe transcription st_output("</Trans>\n"); } // uwe disable // prog_success(&proginfo); } close_input_stream(info); success = TRUE; cleanup: if (!success) { close_output(files[current]->output,files[current]->output_proc); remove_file(outfilename); st_error("failed to split file"); } return success; }
static bool do_join() { int i,bytes_to_skip,bytes_to_xfer; proc_info output_proc; char outfilename[FILENAME_SIZE]; wlong total=0; unsigned char header[CANONICAL_HEADER_SIZE]; FILE *output; wave_info *joined_info; bool success; progress_info proginfo; success = FALSE; create_output_filename("","",outfilename); for (i=0;i<numfiles;i++) total += files[i]->data_size; if (all_files_cd_quality && (total % CD_BLOCK_SIZE) != 0) { pad_bytes = CD_BLOCK_SIZE - (total % CD_BLOCK_SIZE); if (JOIN_NOPAD != pad_type) total += pad_bytes; } if (NULL == (joined_info = new_wave_info(NULL))) { st_error("could not allocate memory for joined file information"); } joined_info->chunk_size = total + CANONICAL_HEADER_SIZE - 8; joined_info->channels = files[0]->channels; joined_info->samples_per_sec = files[0]->samples_per_sec; joined_info->avg_bytes_per_sec = files[0]->avg_bytes_per_sec; joined_info->rate = files[0]->rate; joined_info->block_align = files[0]->block_align; joined_info->bits_per_sample = files[0]->bits_per_sample; joined_info->data_size = total; joined_info->wave_format = files[0]->wave_format; joined_info->problems = (files[0]->problems & PROBLEM_NOT_CD_QUALITY); if (PROB_ODD_SIZED_DATA(joined_info)) joined_info->chunk_size++; joined_info->total_size = joined_info->chunk_size + 8; joined_info->length = joined_info->data_size / joined_info->rate; joined_info->exact_length = (double)joined_info->data_size / (double)joined_info->rate; length_to_str(joined_info); proginfo.initialized = FALSE; proginfo.prefix = "Joining"; proginfo.clause = "-->"; proginfo.filename1 = files[0]->filename; proginfo.filedesc1 = files[0]->m_ss; proginfo.filename2 = outfilename; proginfo.filedesc2 = joined_info->m_ss; proginfo.bytes_total = files[0]->total_size; prog_update(&proginfo); if (NULL == (output = open_output_stream(outfilename,&output_proc))) { st_error("could not open output file"); } make_canonical_header(header,joined_info); if (write_n_bytes(output,header,CANONICAL_HEADER_SIZE,&proginfo) != CANONICAL_HEADER_SIZE) { prog_error(&proginfo); st_warning("error while writing %d-byte WAVE header",CANONICAL_HEADER_SIZE); goto cleanup; } if (all_files_cd_quality && (JOIN_PREPAD == pad_type) && pad_bytes) { if (pad_bytes != write_padding(output,pad_bytes,&proginfo)) { prog_error(&proginfo); st_warning("error while pre-padding with %d zero-bytes",pad_bytes); goto cleanup; } } for (i=0;i<numfiles;i++) { proginfo.bytes_total = files[i]->total_size; proginfo.filename1 = files[i]->filename; proginfo.filedesc1 = files[i]->m_ss; prog_update(&proginfo); if (!open_input_stream(files[i])) { prog_error(&proginfo); st_warning("could not reopen input file"); goto cleanup; } bytes_to_skip = files[i]->header_size; while (bytes_to_skip > 0) { bytes_to_xfer = min(bytes_to_skip,CANONICAL_HEADER_SIZE); if (read_n_bytes(files[i]->input,header,bytes_to_xfer,NULL) != bytes_to_xfer) { prog_error(&proginfo); st_warning("error while reading %d bytes of data",bytes_to_xfer); goto cleanup; } bytes_to_skip -= bytes_to_xfer; } if (transfer_n_bytes(files[i]->input,output,files[i]->data_size,&proginfo) != files[i]->data_size) { prog_error(&proginfo); st_warning("error while transferring %lu bytes of data",files[i]->data_size); goto cleanup; } prog_success(&proginfo); close_input_stream(files[i]); } if (all_files_cd_quality && JOIN_POSTPAD == pad_type && pad_bytes) { if (pad_bytes != write_padding(output,pad_bytes,NULL)) { prog_error(&proginfo); st_warning("error while post-padding with %d zero-bytes",pad_bytes); goto cleanup; } } if ((JOIN_NOPAD == pad_type) && PROB_ODD_SIZED_DATA(joined_info) && (1 != write_padding(output,1,NULL))) { prog_error(&proginfo); st_warning("error while NULL-padding odd-sized data chunk"); goto cleanup; } if (all_files_cd_quality) { if (JOIN_NOPAD != pad_type) { if (pad_bytes) st_info("%s-padded output file with %d zero-bytes.\n",((JOIN_PREPAD == pad_type)?"Pre":"Post"),pad_bytes); else st_info("No padding needed.\n"); } else { st_info("Output file was not padded, "); if (pad_bytes) st_info("though it needs %d bytes of padding.\n",pad_bytes); else st_info("nor was it needed.\n"); } } success = TRUE; cleanup: if ((CLOSE_CHILD_ERROR_OUTPUT == close_output(output,output_proc)) || !success) { success = FALSE; remove_file(outfilename); st_error("failed to join files"); } return success; }
static void module_sanity_check() { int i,j; if (st_modes[0]) { for (i=0;st_modes[i];i++) { if (NULL == st_modes[i]->name) st_error("found a mode module without a name"); if (NULL == st_modes[i]->description) st_error("mode module has no description: [%s]",st_modes[i]->name); if (NULL == st_modes[i]->run_main) st_error("mode module does not provide run_main(): [%s]",st_modes[i]->name); } for (i=0;st_modes[i];i++) { for (j=i+1;st_modes[j];j++) { if (!strcmp(st_modes[i]->name,st_modes[j]->name)) st_error("found modes with identical name: [%s]",st_modes[i]->name); } } } else st_error("no mode modules found"); if (st_formats[0]) { for (i=0;st_formats[i];i++) { if (NULL == st_formats[i]->name) st_error("found a format module without a name"); if (NULL == st_formats[i]->description) st_error("format module has no description: [%s]",st_formats[i]->name); if (!st_formats[i]->supports_input && !st_formats[i]->supports_output) st_error("format module doesn't support input or output: [%s]",st_formats[i]->name); if (!st_formats[i]->supports_input && st_formats[i]->decoder) st_error("format module doesn't support input but defines a decoder: [%s]",st_formats[i]->name); if (!st_formats[i]->supports_output && st_formats[i]->encoder) st_error("format module doesn't support output but defines an encoder: [%s]",st_formats[i]->name); } for (i=0;st_formats[i];i++) { for (j=i+1;st_formats[j];j++) { if (!strcmp(st_formats[i]->name,st_formats[j]->name)) st_error("found formats with identical name: [%s]",st_formats[i]->name); } } } else { st_error("no file formats modules found"); } }
static bool process(int argc,char **argv,int start) { int i,j,remainder; bool needs_fixing = FALSE,found_errors = FALSE,success; char *filename; input_init(start,argc,argv); input_read_all_files(); numfiles = input_get_file_count(); if (numfiles < 1) st_help("need one or more files to process"); if (NULL == (files = malloc((numfiles + 1) * sizeof(wave_info *)))) st_error("could not allocate memory for file info array"); for (i=0;i<numfiles;i++) { filename = input_get_filename(); if (NULL == (files[i] = new_wave_info(filename))) { st_error("could not open file: [%s]",filename); } } files[numfiles] = NULL; /* validate files */ for (i=0;i<numfiles;i++) { if (PROB_NOT_CD(files[i])) { st_warning("file is not CD-quality: [%s]",files[i]->filename); found_errors = TRUE; } if (PROB_HDR_INCONSISTENT(files[i])) { st_warning("file has an inconsistent header: [%s]",files[i]->filename); found_errors = TRUE; } if (PROB_TRUNCATED(files[i])) { st_warning("file seems to be truncated: [%s]",files[i]->filename); found_errors = TRUE; } if (PROB_BAD_BOUND(files[i])) needs_fixing = TRUE; } if (found_errors) st_error("could not fix files due to errors, see above"); if (check_only) exit(needs_fixing ? ST_EXIT_SUCCESS : ST_EXIT_ERROR); if (!needs_fixing) st_error("everything seems fine, no need for fixing"); reorder_files(files,numfiles); i = 0; while (!PROB_BAD_BOUND(files[i])) i++; if (skip) { if (i != 0) { st_warning("skipping first %d file%s because %s would not be changed",i,(1==i)?"":"s",(1==i)?"it":"they"); for (j=0;j<i;j++) st_free(files[j]); for (j=i;j<numfiles;j++) { files[j-i] = files[j]; files[j] = NULL; } numfiles -= i; } } if (numfiles < 1) st_error("need one or more files to process"); switch (desired_shift) { case SHIFT_BACKWARD: calculate_breaks_backward(); break; case SHIFT_FORWARD: calculate_breaks_forward(); break; case SHIFT_ROUND: calculate_breaks_round(); break; } calculation_sanity_check(); remainder = files[numfiles-1]->new_data_size % CD_BLOCK_SIZE; if (remainder) pad_bytes = CD_BLOCK_SIZE - remainder; success = write_fixed_files(); for (i=0;i<numfiles;i++) st_free(files[i]); st_free(files); return success; }
static void parse(int argc,char **argv,int *first_arg) { int c; st_ops.output_directory = CURRENT_DIR; st_ops.output_prefix = SPLIT_PREFIX; cueinfo.format = NULL; while ((c = st_getopt(argc,argv,"c:e:f:l:n:m:t:u:x:")) != -1) { switch (c) { case 'c': if (NULL == optarg) st_error("missing starting count"); offset = atoi(optarg); if (offset < 0) st_help("starting count cannot be negative"); break; case 'e': if (NULL == optarg) st_error("missing lead-in"); leadin = optarg; break; case 'f': if (NULL == optarg) st_error("missing split point file"); split_point_file = optarg; break; case 'l': if (NULL == optarg) st_error("missing repeated split point"); repeated_split_point = optarg; break; case 'm': if (NULL == optarg) st_error("missing character manipulation list"); manipulate_chars = optarg; break; case 'n': if (NULL == optarg) st_error("missing number output format"); num_format = optarg; break; case 't': if (NULL == optarg) st_error("missing cue format"); cueinfo.format = optarg; /* override existing output prefix, if not changed by the user */ if (!strcmp(st_ops.output_prefix,SPLIT_PREFIX)) st_ops.output_prefix = ""; break; case 'u': if (NULL == optarg) st_error("missing lead-out"); leadout = optarg; break; case 'x': if (NULL == optarg) st_error("missing track numbers to extract"); extract_tracks = optarg; break; } } if (optind >= argc && !split_point_file) st_help("if file to be split is not given, then a split point file must be specified"); *first_arg = optind; }
static void read_split_points_file(wave_info *info) { FILE *fd; unsigned char data[BUF_SIZE]; wlong current,previous = 0; int i,j; bool got_token; cueinfo.trackno = 0; cueinfo.in_global_section = TRUE; cueinfo.in_new_track_section = FALSE; strcpy(cueinfo.artist,""); strcpy(cueinfo.album,""); for (i=0;i<SPLIT_MAX_PIECES;i++) { strcpy(cueinfo.titles[i],""); strcpy(cueinfo.artists[i],""); } if (split_point_file) { if (NULL == (fd = fopen(split_point_file,"rb"))) st_error("could not open split point file: [%s]",split_point_file); } else { if (isatty(fileno(stdin))) st_info("enter split points:\n"); fd = stdin; } got_token = get_length_token(fd,data); while (got_token || !feof(fd)) { current = smrt_parse(data,info); if (0 == numfiles && 0 == current) { st_warning("discarding initial zero-valued split point"); } else { create_new_splitfile(); files[numfiles]->beginning_byte = current; if (files[numfiles]->beginning_byte <= previous) st_error("split point %lu is not greater than previous split point %lu",files[numfiles]->beginning_byte,previous); files[numfiles]->data_size = files[numfiles]->beginning_byte - previous; adjust_splitfile(numfiles); if (SPLIT_INPUT_CUE == input_type && 1 == cueinfo.trackno) { strcpy(cueinfo.titles[1],cueinfo.titles[0]); strcpy(cueinfo.titles[0],"pregap"); cueinfo.trackno++; offset--; } numfiles++; previous = current; } got_token = get_length_token(fd,data); } if (NULL == (files[numfiles] = new_wave_info(NULL))) st_error("could not allocate memory for split points array"); numfiles++; if (split_point_file) fclose(fd); if (1 == numfiles) st_error("no split points given -- nothing to do"); if (SPLIT_INPUT_CUE == input_type && cueinfo.format) { if (cueinfo.trackno < numfiles) st_error("not enough TITLE keywords in CUE sheet to name each output file"); /* global artist overrides track artist when not defined */ for (i=0;i<cueinfo.trackno;i++) { if (!strcmp(cueinfo.artists[i],"")) strcpy(cueinfo.artists[i],cueinfo.artist); } for (i=0;i<cueinfo.trackno;i++) cue_sprintf(i,cueinfo.filenames[i]); /* make sure there are no duplicate filenames */ for (i=0;i<cueinfo.trackno;i++) { for (j=i+1;j<cueinfo.trackno;j++) { if (!strcmp(cueinfo.filenames[i],cueinfo.filenames[j])) { st_error("detected duplicate filenames: [%s]",cueinfo.filenames[i]); } } } } }