00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00037 #include <string.h>
00038 #include <ctype.h>
00039 #include <math.h>
00040
00041 #include "splt.h"
00042
00051 static short splt_u_output_variable_is_valid(char v, int *amb)
00052 {
00053 switch (v)
00054 {
00055 case 's':
00056 case 'S':
00057 case 'm':
00058 case 'M':
00059 case 'h':
00060 case 'H':
00061 case 'a':
00062 case 'A':
00063 case 'b':
00064 case 'f':
00065 case 'g':
00066 case 'p':
00067 break;
00068 case 't':
00069 case 'l':
00070 case 'L':
00071 case 'u':
00072 case 'U':
00073 case 'n':
00074 case 'N':
00075 *amb = SPLT_OUTPUT_FORMAT_OK;
00076 break;
00077 default:
00078 return SPLT_FALSE;
00079 }
00080
00081 return SPLT_TRUE;
00082 }
00083
00084 int splt_of_parse_outformat(char *s, splt_state *state)
00085 {
00086 char *ptrs = NULL, *ptre = NULL;
00087 int i=0, amb = SPLT_OUTPUT_FORMAT_AMBIGUOUS, len=0;
00088
00089 size_t size = strlen(s);
00090 for (i = 0; i < size; i++)
00091 {
00092 if (s[i]=='+')
00093 {
00094 s[i]=' ';
00095 }
00096 else
00097 {
00098 if (s[i] == SPLT_VARCHAR)
00099 {
00100 s[i]='%';
00101 }
00102 }
00103 }
00104
00105 ptrs = s;
00106 i = 0;
00107 ptre = strchr(ptrs+1, '%');
00108 if (s[0] != '%')
00109 {
00110 if (ptre==NULL)
00111 {
00112 len = strlen(ptrs);
00113 }
00114 else
00115 {
00116 len = ptre-ptrs;
00117 }
00118 if (len > SPLT_MAXOLEN)
00119 {
00120 len = SPLT_MAXOLEN;
00121 }
00122 strncpy(state->oformat.format[i++], ptrs, len);
00123 }
00124 else
00125 {
00126 ptre = s;
00127 }
00128
00129
00130 if (splt_io_input_is_stdout(state))
00131 {
00132 return SPLT_OUTPUT_FORMAT_OK;
00133 }
00134
00135 char err[2] = { '\0' };
00136
00137 if (ptre == NULL)
00138 {
00139 splt_e_set_error_data(state, err);
00140 return SPLT_OUTPUT_FORMAT_AMBIGUOUS;
00141 }
00142 ptrs = ptre;
00143
00144 char *last_ptre = NULL;
00145 while (((ptre = strchr(ptrs+1, '%')) != NULL) && (i < SPLT_OUTNUM))
00146 {
00147 char cf = *(ptrs+1);
00148
00149 len = ptre-ptrs;
00150 if (len > SPLT_MAXOLEN)
00151 {
00152 len = SPLT_MAXOLEN;
00153 }
00154
00155 if (!splt_u_output_variable_is_valid(cf, &amb))
00156 {
00157 err[0] = cf;
00158 splt_e_set_error_data(state, err);
00159 return SPLT_OUTPUT_FORMAT_ERROR;
00160 }
00161
00162 strncpy(state->oformat.format[i++], ptrs, len);
00163 ptrs = ptre;
00164 last_ptre = ptre;
00165 }
00166
00167 if (last_ptre && *last_ptre != '\0')
00168 {
00169 char v = *(last_ptre+1);
00170 if (!splt_u_output_variable_is_valid(v, &amb))
00171 {
00172 err[0] = v;
00173 splt_e_set_error_data(state, err);
00174 return SPLT_OUTPUT_FORMAT_ERROR;
00175 }
00176 }
00177
00178 strncpy(state->oformat.format[i], ptrs, strlen(ptrs));
00179
00180 if (ptrs[1]=='t')
00181 {
00182 amb = SPLT_OUTPUT_FORMAT_OK;
00183 }
00184
00185 if (ptrs[1]=='n')
00186 {
00187 amb = SPLT_OUTPUT_FORMAT_OK;
00188 }
00189
00190 return amb;
00191 }
00192
00193 static const char *splt_u_get_format_ptr(const char *format, char *temp)
00194 {
00195 int format_length = strlen(format);
00196 const char *format_ptr = format;
00197
00198 if ((format_length > 2) && isdigit(format[2]))
00199 {
00200 temp[2] = format[2];
00201 format_ptr = format + 1;
00202 }
00203
00204 return format_ptr;
00205 }
00206
00207 static int splt_u_get_requested_num_of_digits(splt_state *state, const char *format,
00208 int *requested_num_of_digits, int is_alpha)
00209 {
00210 int format_length = strlen(format);
00211 int number_of_digits = 0;
00212 if (is_alpha)
00213 {
00214 number_of_digits = state->oformat.output_alpha_format_digits;
00215 }
00216 else
00217 {
00218 number_of_digits = splt_of_get_oformat_number_of_digits_as_int(state);
00219 }
00220 int max_number_of_digits = number_of_digits;
00221 *requested_num_of_digits = number_of_digits;
00222
00223 if ((format_length > 2) && isdigit(format[2]))
00224 {
00225 *requested_num_of_digits = format[2] - '0';
00226 }
00227
00228 if (*requested_num_of_digits > number_of_digits)
00229 {
00230 max_number_of_digits = *requested_num_of_digits;
00231 }
00232
00233 return max_number_of_digits;
00234 }
00235
00249 static void splt_u_alpha_track(splt_state *state, int nfield,
00250 char *fm, int fm_length, int number_of_digits, int tracknumber)
00251 {
00252 char *format = state->oformat.format[nfield];
00253 int lowercase = (toupper(format[1]) == 'L');
00254 char a = lowercase ? 'a' : 'A';
00255 int zerobased = tracknumber - 1;
00256 int i = 1, min_digits = state->oformat.output_alpha_format_digits;
00257
00258 if (number_of_digits > 1)
00259 {
00260
00261 if (number_of_digits < min_digits)
00262 number_of_digits = min_digits;
00263 for (i = 1; i <= number_of_digits; ++ i, zerobased /= 26)
00264 {
00265 int digit = (zerobased % 26);
00266 fm[number_of_digits - i] = a + digit;
00267 }
00268 }
00269 else
00270 {
00271
00272 number_of_digits = min_digits;
00273
00274
00275 fm[number_of_digits - 1] = a + (zerobased % 26);
00276
00277
00278 zerobased /= 26;
00279 for (i = 2; i <= number_of_digits; ++ i, zerobased /= 27)
00280 {
00281 int digit = (zerobased % 27);
00282 fm[number_of_digits - i] = a + digit - 1;
00283 }
00284 }
00285
00286 int offset = 0;
00287 if ((strlen(format) > 2) && isdigit(format[2]))
00288 {
00289 offset = 1;
00290 }
00291 snprintf(fm + number_of_digits, fm_length - number_of_digits,
00292 "%s", format + 2 + offset);
00293 }
00294
00295 char splt_of_get_number_of_digits_from_total_time(splt_state *state)
00296 {
00297 long total_time = splt_t_get_total_time(state);
00298 if (total_time <= 0)
00299 {
00300 return '2';
00301 }
00302
00303 long minutes = total_time / 100 / 60;
00304 int i = (int) (log10l((long double) minutes));
00305 char number_of_digits = (char) (i + '1');
00306 if (number_of_digits == '1')
00307 {
00308 return '2';
00309 }
00310
00311 return number_of_digits;
00312 }
00313
00323 int splt_of_put_output_format_filename(splt_state *state, int current_split)
00324 {
00325 int error = SPLT_OK;
00326
00327 int output_filenames = splt_o_get_int_option(state, SPLT_OPT_OUTPUT_FILENAMES);
00328 if (output_filenames == SPLT_OUTPUT_CUSTOM)
00329 {
00330 return error;
00331 }
00332
00333 char *temp = NULL;
00334 char *fm = NULL;
00335 int i = 0;
00336 char *output_filename = NULL;
00337 int output_filename_size = 0;
00338
00339 char *title = NULL;
00340 char *artist = NULL;
00341 char *album = NULL;
00342 char *genre = NULL;
00343 char *performer = NULL;
00344 char *artist_or_performer = NULL;
00345 char *original_filename = NULL;
00346
00347 int split_file_number = splt_t_get_current_split_file_number(state);
00348 int tags_index = split_file_number - 1;
00349
00350 if (current_split == -1)
00351 {
00352 current_split = splt_t_get_current_split_file_number(state) - 1;
00353 }
00354
00355 long mins = -1; long secs = -1; long hundr = -1;
00356 long point_value = splt_sp_get_splitpoint_value(state, current_split, &error);
00357 splt_co_get_mins_secs_hundr(point_value, &mins, &secs, &hundr);
00358 long next_mins = -1; long next_secs = -1; long next_hundr = -1;
00359 long next_point_value = -1;
00360 if (splt_sp_splitpoint_exists(state, current_split + 1))
00361 {
00362 next_point_value = splt_sp_get_splitpoint_value(state, current_split + 1, &error);
00363 long total_time = splt_t_get_total_time(state);
00364 if (total_time > 0 && next_point_value > total_time)
00365 {
00366 next_point_value = total_time;
00367 }
00368 splt_co_get_mins_secs_hundr(next_point_value, &next_mins, &next_secs, &next_hundr);
00369 }
00370
00371 int fm_length = 0;
00372
00373
00374 int remaining_tags_like_x =
00375 splt_o_get_int_option(state,SPLT_OPT_ALL_REMAINING_TAGS_LIKE_X);
00376 if ((tags_index >= state->split.real_tagsnumber) &&
00377 (remaining_tags_like_x != -1))
00378 {
00379 tags_index = remaining_tags_like_x;
00380 }
00381
00382 const char *output_format = splt_of_get_oformat(state);
00383 short write_eof = SPLT_FALSE;
00384 if ((next_point_value == LONG_MAX) &&
00385 (strcmp(output_format, SPLT_DEFAULT_OUTPUT) == 0))
00386 {
00387 write_eof = SPLT_TRUE;
00388 }
00389
00390 splt_d_print_debug(state,"The output format is _%s_\n", output_format);
00391
00392 long mMsShH_value = -1;
00393 short eof_written = SPLT_FALSE;
00394
00395 for (i = 0; i < SPLT_OUTNUM; i++)
00396 {
00397 if (strlen(state->oformat.format[i]) == 0)
00398 {
00399 break;
00400 }
00401
00402 if (state->oformat.format[i][0] == '%')
00403 {
00404
00405 if (temp)
00406 {
00407 free(temp);
00408 temp = NULL;
00409 }
00410
00411 int temp_len = strlen(state->oformat.format[i])+10;
00412 if ((temp = malloc(temp_len * sizeof(char))) == NULL)
00413 {
00414 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00415 goto end;
00416 }
00417 memset(temp, 0x0, temp_len);
00418
00419 temp[0] = '%';
00420 temp[1] = 's';
00421 char char_variable = state->oformat.format[i][1];
00422 switch (char_variable)
00423 {
00424 case 's':
00425 mMsShH_value = secs;
00426 goto put_value;
00427 case 'S':
00428 mMsShH_value = next_secs;
00429 goto put_value;
00430 case 'm':
00431 mMsShH_value = mins;
00432 goto put_value;
00433 case 'M':
00434 mMsShH_value = next_mins;
00435 goto put_value;
00436 case 'h':
00437 mMsShH_value = hundr;
00438 goto put_value;
00439 case 'H':
00440 mMsShH_value = next_hundr;
00441 put_value:
00442 if (!eof_written)
00443 {
00444 if (write_eof &&
00445 (char_variable == 'S' ||
00446 char_variable == 'M' ||
00447 char_variable == 'H'))
00448 {
00449 write_eof = SPLT_FALSE;
00450 eof_written = SPLT_TRUE;
00451
00452 fm_length = strlen(temp) + 4;
00453 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00454 {
00455 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00456 goto end;
00457 }
00458 snprintf(fm, fm_length, temp, "EOF");
00459 }
00460 else if (mMsShH_value != -1)
00461 {
00462 temp[1] = '0';
00463 char number_of_digits = '2';
00464 if (char_variable == 'M' || char_variable == 'm')
00465 {
00466 number_of_digits = splt_of_get_number_of_digits_from_total_time(state);
00467 }
00468 temp[2] = number_of_digits;
00469 temp[3] = 'l';
00470 temp[4] = 'd';
00471
00472 const char *format = NULL;
00473 int offset = 5;
00474
00475
00476 if ((strcmp(state->oformat.format_string, SPLT_DEFAULT_OUTPUT) == 0) &&
00477 (mMsShH_value == 0) &&
00478 (char_variable == 'h' || char_variable == 'H'))
00479 {
00480 if (char_variable == 'h')
00481 {
00482 format = state->oformat.format[i]+2;
00483 offset = 0;
00484 }
00485 else
00486 {
00487 output_filename[strlen(output_filename)-1] = '\0';
00488 break;
00489 }
00490 }
00491 else
00492 {
00493 format = splt_u_get_format_ptr(state->oformat.format[i], temp);
00494 }
00495
00496 int requested_num_of_digits = 0;
00497 int max_number_of_digits = splt_u_get_requested_num_of_digits(state,
00498 state->oformat.format[i], &requested_num_of_digits, SPLT_FALSE);
00499
00500 snprintf(temp + offset, temp_len, "%s", format + 2);
00501
00502 fm_length = strlen(temp) + 1 + max_number_of_digits;
00503 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00504 {
00505 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00506 goto end;
00507 }
00508
00509 snprintf(fm, fm_length, temp, mMsShH_value);
00510 }
00511 }
00512 break;
00513 case 'A':
00514 if (splt_tu_tags_exists(state,tags_index))
00515 {
00516 artist_or_performer =
00517 (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_PERFORMER);
00518 splt_su_clean_string(state, artist_or_performer, &error);
00519 if (error < 0) { goto end; };
00520
00521 if (artist_or_performer == NULL || artist_or_performer[0] == '\0')
00522 {
00523 artist_or_performer =
00524 (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_ARTIST);
00525 splt_su_clean_string(state, artist_or_performer, &error);
00526 if (error < 0) { goto end; };
00527 }
00528 }
00529 else
00530 {
00531 artist_or_performer = NULL;
00532 }
00533
00534
00535 if (artist_or_performer != NULL)
00536 {
00537 snprintf(temp+2,temp_len, "%s", state->oformat.format[i]+2);
00538
00539 int artist_length = 0;
00540 artist_length = strlen(artist_or_performer);
00541 fm_length = strlen(temp) + artist_length + 1;
00542 }
00543 else
00544 {
00545 snprintf(temp,temp_len, "%s", state->oformat.format[i]+2);
00546 fm_length = strlen(temp) + 1;
00547 }
00548
00549 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00550 {
00551 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00552 goto end;
00553 }
00554
00555
00556 if (artist_or_performer != NULL)
00557 {
00558 snprintf(fm, fm_length, temp, artist_or_performer);
00559 }
00560 else
00561 {
00562 snprintf(fm, fm_length, "%s", temp);
00563 }
00564
00565 break;
00566 case 'a':
00567 if (splt_tu_tags_exists(state,tags_index))
00568 {
00569
00570 artist =
00571 (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_ARTIST);
00572 splt_su_clean_string(state, artist, &error);
00573 if (error < 0) { goto end; };
00574 }
00575 else
00576 {
00577 artist = NULL;
00578 }
00579
00580
00581 if (artist != NULL)
00582 {
00583 snprintf(temp+2,temp_len, "%s", state->oformat.format[i]+2);
00584
00585 int artist_length = 0;
00586 artist_length = strlen(artist);
00587 fm_length = strlen(temp) + artist_length + 1;
00588 }
00589 else
00590 {
00591 snprintf(temp,temp_len, "%s", state->oformat.format[i]+2);
00592 fm_length = strlen(temp) + 1;
00593 }
00594
00595 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00596 {
00597 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00598 goto end;
00599 }
00600
00601
00602 if (artist != NULL)
00603 {
00604 snprintf(fm, fm_length, temp, artist);
00605 }
00606 else
00607 {
00608 snprintf(fm, fm_length, "%s", temp);
00609 }
00610 break;
00611 case 'b':
00612 if (splt_tu_tags_exists(state,tags_index))
00613 {
00614
00615 album =
00616 (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_ALBUM);
00617 splt_su_clean_string(state, album, &error);
00618 if (error < 0) { goto end; };
00619 }
00620 else
00621 {
00622 album = NULL;
00623 }
00624
00625
00626 if (album != NULL)
00627 {
00628 int album_length = 0;
00629 album_length = strlen(album);
00630 snprintf(temp+2, temp_len, "%s", state->oformat.format[i]+2);
00631
00632 fm_length = strlen(temp) + album_length + 1;
00633 }
00634 else
00635 {
00636 snprintf(temp,temp_len, "%s", state->oformat.format[i]+2);
00637 fm_length = strlen(temp) + 1;
00638 }
00639
00640 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00641 {
00642 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00643 goto end;
00644 }
00645
00646
00647 if (album != NULL)
00648 {
00649 snprintf(fm, fm_length, temp, album);
00650 }
00651 else
00652 {
00653 snprintf(fm, fm_length, "%s", temp);
00654 }
00655 break;
00656 case 'g':
00657 if (splt_tu_tags_exists(state,tags_index))
00658 {
00659
00660 genre =
00661 (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_GENRE);
00662 splt_su_clean_string(state, genre, &error);
00663 if (error < 0) { goto end; };
00664 }
00665 else
00666 {
00667 genre = NULL;
00668 }
00669
00670
00671 if (genre != NULL)
00672 {
00673 int genre_length = 0;
00674 genre_length = strlen(genre);
00675 snprintf(temp+2, temp_len, "%s", state->oformat.format[i]+2);
00676
00677 fm_length = strlen(temp) + genre_length + 1;
00678 }
00679 else
00680 {
00681 snprintf(temp,temp_len, "%s", state->oformat.format[i]+2);
00682 fm_length = strlen(temp) + 1;
00683 }
00684
00685 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00686 {
00687 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00688 goto end;
00689 }
00690
00691
00692 if (genre != NULL)
00693 {
00694 snprintf(fm, fm_length, temp, genre);
00695 }
00696 else
00697 {
00698 snprintf(fm, fm_length, "%s", temp);
00699 }
00700 break;
00701 case 't':
00702 if (splt_tu_tags_exists(state,tags_index))
00703 {
00704 title = (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_TITLE);
00705 splt_su_clean_string(state, title, &error);
00706 if (error < 0) { goto end; };
00707 }
00708 else
00709 {
00710 title = NULL;
00711 }
00712
00713
00714 if (title != NULL)
00715 {
00716 int title_length = 0;
00717 title_length = strlen(title);
00718 snprintf(temp+2, temp_len, "%s", state->oformat.format[i]+2);
00719
00720 fm_length = strlen(temp) + title_length + 1;
00721 }
00722 else
00723 {
00724 snprintf(temp,temp_len, "%s", state->oformat.format[i]+2);
00725 fm_length = strlen(temp) + 1;
00726 }
00727
00728 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00729 {
00730 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00731 goto end;
00732 }
00733
00734
00735 if (title != NULL)
00736 {
00737 snprintf(fm, fm_length, temp, title);
00738 }
00739 else
00740 {
00741 snprintf(fm, fm_length, "%s", temp);
00742 }
00743 break;
00744 case 'p':
00745 if (splt_tu_tags_exists(state,tags_index))
00746 {
00747 performer = (char *)splt_tu_get_tags_field(state,tags_index, SPLT_TAGS_PERFORMER);
00748 splt_su_clean_string(state, performer, &error);
00749 if (error < 0) { goto end; };
00750 }
00751 else
00752 {
00753 performer = NULL;
00754 }
00755
00756
00757 if (performer != NULL)
00758 {
00759 int performer_length = 0;
00760 performer_length = strlen(performer);
00761 snprintf(temp+2, temp_len, "%s", state->oformat.format[i]+2);
00762
00763 fm_length = strlen(temp) + performer_length + 1;
00764 }
00765 else
00766 {
00767 snprintf(temp,temp_len, "%s", state->oformat.format[i]+2);
00768 fm_length = strlen(temp) + 1;
00769 }
00770
00771 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00772 {
00773 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00774 goto end;
00775 }
00776
00777 if (performer != NULL)
00778 {
00779 snprintf(fm, fm_length, temp, performer);
00780 }
00781 else
00782 {
00783 snprintf(fm, fm_length, "%s", temp);
00784 }
00785 break;
00786 case 'l':
00787 case 'L':
00788 case 'u':
00789 case 'U':
00790 case 'n':
00791 case 'N':
00792 temp[1] = '0';
00793 temp[2] = splt_of_get_oformat_number_of_digits_as_char(state);
00794 temp[3] = 'd';
00795
00796 int tracknumber = split_file_number;
00797
00798
00799
00800 int split_mode = splt_o_get_int_option(state,SPLT_OPT_SPLIT_MODE);
00801 if ((isupper(state->oformat.format[i][1])) ||
00802 ((split_mode != SPLT_OPTION_TIME_MODE) &&
00803 (split_mode != SPLT_OPTION_NORMAL_MODE) &&
00804 (split_mode != SPLT_OPTION_SILENCE_MODE) &&
00805 (split_mode != SPLT_OPTION_TRIM_SILENCE_MODE) &&
00806 (split_mode != SPLT_OPTION_ERROR_MODE) &&
00807 (split_mode != SPLT_OPTION_LENGTH_MODE)))
00808 {
00809 if (splt_tu_tags_exists(state, tags_index))
00810 {
00811 int *tags_track = (int *)splt_tu_get_tags_field(state, tags_index, SPLT_TAGS_TRACK);
00812 if (tags_track && *tags_track > 0)
00813 {
00814 tracknumber = *tags_track;
00815 }
00816 }
00817 }
00818
00819 int requested_num_of_digits = 0;
00820 int max_num_of_digits = splt_u_get_requested_num_of_digits(state,
00821 state->oformat.format[i], &requested_num_of_digits, SPLT_FALSE);
00822
00823 int alpha_requested_num_of_digits = 0;
00824 int alpha_max_num_of_digits = splt_u_get_requested_num_of_digits(state,
00825 state->oformat.format[i], &alpha_requested_num_of_digits, SPLT_TRUE);
00826
00827 int is_numeric = toupper(state->oformat.format[i][1]) == 'N';
00828 if (is_numeric)
00829 {
00830 const char *format = splt_u_get_format_ptr(state->oformat.format[i], temp);
00831
00832 snprintf(temp + 4, temp_len, "%s",format + 2);
00833 fm_length = strlen(temp) + 1 + max_num_of_digits;
00834 }
00835 else
00836 {
00837 fm_length = strlen(state->oformat.format[i]) + 1 + alpha_max_num_of_digits;
00838 }
00839
00840 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00841 {
00842 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00843 goto end;
00844 }
00845 memset(fm, '\0', fm_length);
00846
00847 if (is_numeric)
00848 {
00849 snprintf(fm, fm_length, temp, tracknumber);
00850 }
00851 else
00852 {
00853 splt_u_alpha_track(state, i, fm, fm_length,
00854 alpha_requested_num_of_digits, tracknumber);
00855 }
00856 break;
00857 case 'f':
00858 if (splt_t_get_filename_to_split(state) != NULL)
00859 {
00860 original_filename = strdup(splt_su_get_fname_without_path(splt_t_get_filename_to_split(state)));
00861 if (original_filename)
00862 {
00863 snprintf(temp+2,temp_len, "%s", state->oformat.format[i]+2);
00864
00865 splt_su_cut_extension(original_filename);
00866
00867 int filename_length = strlen(original_filename);
00868
00869 fm_length = strlen(temp) + filename_length;
00870 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00871 {
00872 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00873 goto end;
00874 }
00875
00876 snprintf(fm, fm_length, temp, original_filename);
00877 free(original_filename);
00878 original_filename = NULL;
00879 }
00880 else
00881 {
00882 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00883 goto end;
00884 }
00885 }
00886 break;
00887 }
00888 }
00889 else
00890 {
00891 fm_length = SPLT_MAXOLEN;
00892 if ((fm = malloc(fm_length * sizeof(char))) == NULL)
00893 {
00894 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00895 goto end;
00896 }
00897
00898 strncpy(fm, state->oformat.format[i], SPLT_MAXOLEN);
00899 }
00900
00901 int fm_size = 7;
00902 if (fm != NULL)
00903 {
00904 fm_size = strlen(fm);
00905 }
00906
00907
00908 if (!output_filename)
00909 {
00910 if ((output_filename = malloc((1+fm_size)*sizeof(char))) == NULL)
00911 {
00912 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00913 goto end;
00914 }
00915 output_filename_size = fm_size;
00916 output_filename[0] = '\0';
00917 }
00918 else
00919 {
00920 output_filename_size += fm_size+1;
00921 if ((output_filename = realloc(output_filename, output_filename_size
00922 * sizeof(char))) == NULL)
00923 {
00924 error = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00925 goto end;
00926 }
00927 }
00928
00929 if (fm != NULL)
00930 {
00931 strcat(output_filename, fm);
00932 }
00933
00934
00935 if (fm)
00936 {
00937 free(fm);
00938 fm = NULL;
00939 }
00940 }
00941
00942 splt_d_print_debug(state,"The new output filename is _%s_\n", output_filename);
00943 int cur_splt = splt_t_get_current_split(state);
00944 int name_error = splt_sp_set_splitpoint_name(state, cur_splt, output_filename);
00945 if (name_error != SPLT_OK) { error = name_error; }
00946
00947 end:
00948 if (output_filename)
00949 {
00950 free(output_filename);
00951 output_filename = NULL;
00952 }
00953 if (fm)
00954 {
00955 free(fm);
00956 fm = NULL;
00957 }
00958 if (temp)
00959 {
00960 free(temp);
00961 temp = NULL;
00962 }
00963
00964 return error;
00965 }
00966