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 <math.h>
00039
00040 #include "splt.h"
00041
00042 int splt_of_set_default_values(splt_state *state)
00043 {
00044 int err = SPLT_OK;
00045
00046 state->oformat.format_string = NULL;
00047 splt_of_set_oformat(state, SPLT_DEFAULT_CDDB_CUE_OUTPUT, &err, SPLT_TRUE);
00048
00049 return err;
00050 }
00051
00052 void splt_of_free_oformat(splt_state *state)
00053 {
00054 splt_oformat *oformat = &state->oformat;
00055
00056 if (oformat->format_string)
00057 {
00058 free(oformat->format_string);
00059 oformat->format_string = NULL;
00060 }
00061 }
00062
00063 void splt_of_set_oformat_digits_tracks(splt_state *state, int tracks)
00064 {
00065 splt_oformat *oformat = &state->oformat;
00066
00067 int i = (int) (log10((double) (tracks)));
00068 oformat->output_format_digits = (char) (i + '1');
00069
00070
00071 oformat->output_alpha_format_digits = 1;
00072 for (i = (tracks - 1) / 26; i > 0; i /= 27)
00073 {
00074 ++ oformat->output_alpha_format_digits;
00075 }
00076 }
00077
00078 void splt_of_set_oformat_digits(splt_state *state)
00079 {
00080 splt_of_set_oformat_digits_tracks(state, splt_t_get_splitnumber(state));
00081 }
00082
00083 static int splt_of_new_oformat(splt_state *state, const char *format_string)
00084 {
00085 splt_of_free_oformat(state);
00086 return splt_su_copy(format_string, &state->oformat.format_string);
00087 }
00088
00089 void splt_of_set_oformat(splt_state *state, const char *format_string,
00090 int *error, int ignore_incorrect_format_warning)
00091 {
00092 if (format_string == NULL || format_string[0] == '\0')
00093 {
00094 *error = SPLT_OUTPUT_FORMAT_ERROR;
00095 return;
00096 }
00097
00098 int j = 0;
00099 while (j <= SPLT_OUTNUM)
00100 {
00101 memset(state->oformat.format[j], '\0', SPLT_MAXOLEN);
00102 j++;
00103 }
00104
00105 int err = splt_of_new_oformat(state, format_string);
00106 if (err < 0) { *error = err; return; }
00107
00108 char *new_str = NULL;
00109 err = splt_su_copy(format_string, &new_str);
00110 if (err < 0) { *error =err; return; }
00111
00112 err = splt_of_parse_outformat(new_str, state);
00113 if (! ignore_incorrect_format_warning)
00114 {
00115 *error = err;
00116 }
00117
00118 free(new_str);
00119 new_str = NULL;
00120
00121 if (*error > 0)
00122 {
00123 splt_of_set_oformat_digits(state);
00124 }
00125 }
00126
00127 int splt_of_reparse_oformat(splt_state *state)
00128 {
00129 int err = SPLT_OK;
00130
00131 const char *format = splt_of_get_oformat(state);
00132 if (format != NULL)
00133 {
00134 char *old_format = NULL;
00135 err = splt_su_copy(format, &old_format);
00136 if (err < 0) { return err; }
00137
00138 splt_of_set_oformat(state, old_format, &err, SPLT_TRUE);
00139
00140 free(old_format);
00141 old_format = NULL;
00142 }
00143
00144 return err;
00145 }
00146
00147 int splt_of_get_oformat_number_of_digits_as_int(splt_state *state)
00148 {
00149 return state->oformat.output_format_digits - '0';
00150 }
00151
00152 char splt_of_get_oformat_number_of_digits_as_char(splt_state *state)
00153 {
00154 return state->oformat.output_format_digits;
00155 }
00156
00157 const char *splt_of_get_oformat(splt_state *state)
00158 {
00159 return state->oformat.format_string;
00160 }
00161