comparison src/xs_title.c @ 660:b0743dc9165d

Change tabs to 4 spaces, everywhere.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Apr 2008 22:10:05 +0300
parents acaba070cf49
children c8648efaebba
comparison
equal deleted inserted replaced
659:04ea91a61225 660:b0743dc9165d
25 #include "xs_config.h" 25 #include "xs_config.h"
26 26
27 27
28 static void xs_path_split(gchar *path, gchar **tmpFilename, gchar **tmpFilePath, gchar **tmpFileExt) 28 static void xs_path_split(gchar *path, gchar **tmpFilename, gchar **tmpFilePath, gchar **tmpFileExt)
29 { 29 {
30 gchar *tmpStr; 30 gchar *tmpStr;
31 31
32 /* Split the filename into path */ 32 /* Split the filename into path */
33 *tmpFilePath = g_strdup(path); 33 *tmpFilePath = g_strdup(path);
34 tmpStr = xs_strrchr(*tmpFilePath, '/'); 34 tmpStr = xs_strrchr(*tmpFilePath, '/');
35 if (tmpStr) tmpStr[1] = 0; 35 if (tmpStr) tmpStr[1] = 0;
36 36
37 /* Filename */ 37 /* Filename */
38 *tmpFilename = xs_strrchr(path, '/'); 38 *tmpFilename = xs_strrchr(path, '/');
39 if (*tmpFilename) 39 if (*tmpFilename)
40 *tmpFilename = g_strdup(*tmpFilename + 1); 40 *tmpFilename = g_strdup(*tmpFilename + 1);
41 else 41 else
42 *tmpFilename = g_strdup(path); 42 *tmpFilename = g_strdup(path);
43 43
44 tmpStr = xs_strrchr(*tmpFilename, '.'); 44 tmpStr = xs_strrchr(*tmpFilename, '.');
45 tmpStr[0] = 0; 45 tmpStr[0] = 0;
46 46
47 /* Extension */ 47 /* Extension */
48 *tmpFileExt = xs_strrchr(path, '.'); 48 *tmpFileExt = xs_strrchr(path, '.');
49 } 49 }
50 50
51 51
52 /* Create a title string based on given information and settings. 52 /* Create a title string based on given information and settings.
53 */ 53 */
54 #define VPUTCH(MCH) \ 54 #define VPUTCH(MCH) \
55 if (index < XS_BUF_SIZE) tmpBuf[index++] = MCH; 55 if (index < XS_BUF_SIZE) tmpBuf[index++] = MCH;
56 56
57 #define VPUTSTR(MSTR) { \ 57 #define VPUTSTR(MSTR) { \
58 if (MSTR) { \ 58 if (MSTR) { \
59 if ((index + strlen(MSTR) + 1) < XS_BUF_SIZE) {\ 59 if ((index + strlen(MSTR) + 1) < XS_BUF_SIZE) {\
60 strcpy(&tmpBuf[index], MSTR); \ 60 strcpy(&tmpBuf[index], MSTR); \
61 index += strlen(MSTR); \ 61 index += strlen(MSTR); \
62 } else \ 62 } else \
63 index = XS_BUF_SIZE; \ 63 index = XS_BUF_SIZE; \
64 } \ 64 } \
65 } 65 }
66 66
67 67
68 gchar *xs_make_titlestring(xs_tuneinfo_t *p, gint subTune) 68 gchar *xs_make_titlestring(xs_tuneinfo_t *p, gint subTune)
69 { 69 {
70 gchar *tmpFilename, *tmpFilePath, *tmpFileExt, 70 gchar *tmpFilename, *tmpFilePath, *tmpFileExt,
71 *str, *result, tmpStr[XS_BUF_SIZE], tmpBuf[XS_BUF_SIZE]; 71 *str, *result, tmpStr[XS_BUF_SIZE], tmpBuf[XS_BUF_SIZE];
72 xs_subtuneinfo_t *subInfo; 72 xs_subtuneinfo_t *subInfo;
73 gint index; 73 gint index;
74 74
75 /* Get filename parts */ 75 /* Get filename parts */
76 xs_path_split(p->sidFilename, &tmpFilename, 76 xs_path_split(p->sidFilename, &tmpFilename,
77 &tmpFilePath, &tmpFileExt); 77 &tmpFilePath, &tmpFileExt);
78 78
79 /* Get sub-tune information */ 79 /* Get sub-tune information */
80 if ((subTune > 0) && (subTune <= p->nsubTunes)) { 80 if ((subTune > 0) && (subTune <= p->nsubTunes)) {
81 subInfo = &(p->subTunes[subTune - 1]); 81 subInfo = &(p->subTunes[subTune - 1]);
82 } else 82 } else
83 subInfo = NULL; 83 subInfo = NULL;
84 84
85 85
86 /* Check if the titles are overridden or not */ 86 /* Check if the titles are overridden or not */
87 #ifdef HAVE_XMMSEXTRA 87 #ifdef HAVE_XMMSEXTRA
88 if (!xs_cfg.titleOverride) { 88 if (!xs_cfg.titleOverride) {
89 TitleInput *pTuple; 89 TitleInput *pTuple;
90 90
91 pTuple = (TitleInput *) g_malloc0(sizeof(TitleInput)); 91 pTuple = (TitleInput *) g_malloc0(sizeof(TitleInput));
92 pTuple->__size = XMMS_TITLEINPUT_SIZE; 92 pTuple->__size = XMMS_TITLEINPUT_SIZE;
93 pTuple->__version = XMMS_TITLEINPUT_VERSION; 93 pTuple->__version = XMMS_TITLEINPUT_VERSION;
94 94
95 /* Create the input fields */ 95 /* Create the input fields */
96 pTuple->file_name = tmpFilename; 96 pTuple->file_name = tmpFilename;
97 pTuple->file_ext = tmpFileExt; 97 pTuple->file_ext = tmpFileExt;
98 pTuple->file_path = tmpFilePath; 98 pTuple->file_path = tmpFilePath;
99 99
100 pTuple->track_name = g_strdup(p->sidName); 100 pTuple->track_name = g_strdup(p->sidName);
101 pTuple->track_number = subTune; 101 pTuple->track_number = subTune;
102 pTuple->album_name = NULL; 102 pTuple->album_name = NULL;
103 pTuple->performer = g_strdup(p->sidComposer); 103 pTuple->performer = g_strdup(p->sidComposer);
104 pTuple->date = g_strdup((p->sidModel == XS_SIDMODEL_6581) ? "SID6581" : "SID8580"); 104 pTuple->date = g_strdup((p->sidModel == XS_SIDMODEL_6581) ? "SID6581" : "SID8580");
105 105
106 pTuple->year = 0; 106 pTuple->year = 0;
107 pTuple->genre = g_strdup("SID-tune"); 107 pTuple->genre = g_strdup("SID-tune");
108 pTuple->comment = g_strdup(p->sidCopyright); 108 pTuple->comment = g_strdup(p->sidCopyright);
109 109
110 result = xmms_get_titlestring(xmms_get_gentitle_format(), pTuple); 110 result = xmms_get_titlestring(xmms_get_gentitle_format(), pTuple);
111 111
112 g_free(pTuple->track_name); 112 g_free(pTuple->track_name);
113 g_free(pTuple->album_name); 113 g_free(pTuple->album_name);
114 g_free(pTuple->performer); 114 g_free(pTuple->performer);
115 g_free(pTuple->date); 115 g_free(pTuple->date);
116 g_free(pTuple->genre); 116 g_free(pTuple->genre);
117 g_free(pTuple->comment); 117 g_free(pTuple->comment);
118 g_free(pTuple); 118 g_free(pTuple);
119 } else 119 } else
120 #endif 120 #endif
121 { 121 {
122 /* Create the string */ 122 /* Create the string */
123 str = xs_cfg.titleFormat; 123 str = xs_cfg.titleFormat;
124 index = 0; 124 index = 0;
125 while (*str && (index < XS_BUF_SIZE)) { 125 while (*str && (index < XS_BUF_SIZE)) {
126 if (*str == '%') { 126 if (*str == '%') {
127 str++; 127 str++;
128 switch (*str) { 128 switch (*str) {
129 case '%': 129 case '%':
130 VPUTCH('%'); 130 VPUTCH('%');
131 break; 131 break;
132 case 'f': 132 case 'f':
133 VPUTSTR(tmpFilename); 133 VPUTSTR(tmpFilename);
134 break; 134 break;
135 case 'F': 135 case 'F':
136 VPUTSTR(tmpFilePath); 136 VPUTSTR(tmpFilePath);
137 break; 137 break;
138 case 'e': 138 case 'e':
139 VPUTSTR(tmpFileExt); 139 VPUTSTR(tmpFileExt);
140 break; 140 break;
141 case 'p': 141 case 'p':
142 VPUTSTR(p->sidComposer); 142 VPUTSTR(p->sidComposer);
143 break; 143 break;
144 case 't': 144 case 't':
145 VPUTSTR(p->sidName); 145 VPUTSTR(p->sidName);
146 break; 146 break;
147 case 'c': 147 case 'c':
148 VPUTSTR(p->sidCopyright); 148 VPUTSTR(p->sidCopyright);
149 break; 149 break;
150 case 's': 150 case 's':
151 VPUTSTR(p->sidFormat); 151 VPUTSTR(p->sidFormat);
152 break; 152 break;
153 case 'm': 153 case 'm':
154 switch (p->sidModel) { 154 switch (p->sidModel) {
155 case XS_SIDMODEL_6581: 155 case XS_SIDMODEL_6581:
156 VPUTSTR("6581"); 156 VPUTSTR("6581");
157 break; 157 break;
158 case XS_SIDMODEL_8580: 158 case XS_SIDMODEL_8580:
159 VPUTSTR("8580"); 159 VPUTSTR("8580");
160 break; 160 break;
161 case XS_SIDMODEL_ANY: 161 case XS_SIDMODEL_ANY:
162 VPUTSTR("ANY"); 162 VPUTSTR("ANY");
163 break; 163 break;
164 default: 164 default:
165 VPUTSTR("?"); 165 VPUTSTR("?");
166 break; 166 break;
167 } 167 }
168 break; 168 break;
169 case 'C': 169 case 'C':
170 if (subInfo && (subInfo->tuneSpeed > 0)) { 170 if (subInfo && (subInfo->tuneSpeed > 0)) {
171 switch (subInfo->tuneSpeed) { 171 switch (subInfo->tuneSpeed) {
172 case XS_CLOCK_PAL: 172 case XS_CLOCK_PAL:
173 VPUTSTR("PAL"); 173 VPUTSTR("PAL");
174 break; 174 break;
175 case XS_CLOCK_NTSC: 175 case XS_CLOCK_NTSC:
176 VPUTSTR("NTSC"); 176 VPUTSTR("NTSC");
177 break; 177 break;
178 case XS_CLOCK_ANY: 178 case XS_CLOCK_ANY:
179 VPUTSTR("ANY"); 179 VPUTSTR("ANY");
180 break; 180 break;
181 case XS_CLOCK_VBI: 181 case XS_CLOCK_VBI:
182 VPUTSTR("VBI"); 182 VPUTSTR("VBI");
183 break; 183 break;
184 case XS_CLOCK_CIA: 184 case XS_CLOCK_CIA:
185 VPUTSTR("CIA"); 185 VPUTSTR("CIA");
186 break; 186 break;
187 default: 187 default:
188 g_snprintf(tmpStr, XS_BUF_SIZE, 188 g_snprintf(tmpStr, XS_BUF_SIZE,
189 "%iHz", subInfo->tuneSpeed); 189 "%iHz", subInfo->tuneSpeed);
190 VPUTSTR(tmpStr); 190 VPUTSTR(tmpStr);
191 } 191 }
192 } else 192 } else
193 VPUTSTR("?"); 193 VPUTSTR("?");
194 break; 194 break;
195 case 'n': 195 case 'n':
196 g_snprintf(tmpStr, XS_BUF_SIZE, "%i", subTune); 196 g_snprintf(tmpStr, XS_BUF_SIZE, "%i", subTune);
197 VPUTSTR(tmpStr); 197 VPUTSTR(tmpStr);
198 break; 198 break;
199 case 'N': 199 case 'N':
200 g_snprintf(tmpStr, XS_BUF_SIZE, "%i", p->nsubTunes); 200 g_snprintf(tmpStr, XS_BUF_SIZE, "%i", p->nsubTunes);
201 VPUTSTR(tmpStr); 201 VPUTSTR(tmpStr);
202 break; 202 break;
203 } 203 }
204 } else 204 } else
205 VPUTCH(*str); 205 VPUTCH(*str);
206 206
207 str++; 207 str++;
208 } 208 }
209 209
210 tmpBuf[index] = 0; 210 tmpBuf[index] = 0;
211 211
212 /* Make resulting string */ 212 /* Make resulting string */
213 result = g_strdup(tmpBuf); 213 result = g_strdup(tmpBuf);
214 } 214 }
215 215
216 /* Free temporary strings */ 216 /* Free temporary strings */
217 g_free(tmpFilename); 217 g_free(tmpFilename);
218 g_free(tmpFilePath); 218 g_free(tmpFilePath);
219 219
220 return result; 220 return result;
221 } 221 }