Mercurial > hg > xmms-sid
annotate src/xs_title.c @ 233:9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
and g_strdup() those stupid arguments. Waste of resources, IMHO, but
maybe it helps portability.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2004 13:32:04 +0000 |
parents | 608f31f6c095 |
children | dd201740a720 |
rev | line source |
---|---|
217 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Titlestring handling | |
5 | |
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org> | |
7 | |
8 This program is free software; you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program; if not, write to the Free Software | |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 */ | |
22 #include "xs_title.h" | |
23 #include "xs_support.h" | |
24 #include "xs_config.h" | |
25 #include <xmms/titlestring.h> | |
26 | |
27 | |
28 /* | |
29 * Create a title string based on given information and settings. | |
30 */ | |
31 #define VBUFSIZE (1024) | |
32 #define VPUTCH(MCH) \ | |
33 if (iIndex < VBUFSIZE) tmpBuf[iIndex++] = MCH; | |
34 #define VPUTSTR(MSTR) { \ | |
35 if (MSTR) { \ | |
36 if ((iIndex + strlen(MSTR) + 1) < VBUFSIZE) { \ | |
37 strcpy(&tmpBuf[iIndex], MSTR); \ | |
38 iIndex += strlen(MSTR); \ | |
39 } else \ | |
40 iIndex = VBUFSIZE; \ | |
41 } \ | |
42 } | |
43 | |
44 | |
45 gchar *xs_make_titlestring(gchar *pcFilename, | |
46 gint iSubTune, | |
47 gint iSidModel, | |
230 | 48 const gchar *formatString, const gchar *infoString0, |
49 const gchar *infoString1, const gchar *infoString2) | |
217 | 50 { |
51 gchar *tmpFilename, *tmpFilePath, *tmpFileExt, *pcStr, *pcResult, | |
52 tmpStr[VBUFSIZE], tmpBuf[VBUFSIZE]; | |
53 gint iIndex; | |
54 #ifdef HAVE_XMMSEXTRA | |
55 TitleInput *ptInput; | |
56 #endif | |
57 | |
58 /* Split the filename into path */ | |
59 tmpFilePath = g_strdup(pcFilename); | |
60 tmpFilename = xs_strrchr(tmpFilePath, '/'); | |
61 if (tmpFilename) | |
62 tmpFilename[1] = 0; | |
63 | |
64 /* Filename */ | |
65 tmpFilename = xs_strrchr(pcFilename, '/'); | |
66 if (tmpFilename) | |
67 tmpFilename = g_strdup(tmpFilename + 1); | |
68 else | |
69 tmpFilename = g_strdup(pcFilename); | |
70 | |
71 tmpFileExt = xs_strrchr(tmpFilename, '.'); | |
72 tmpFileExt[0] = 0; | |
73 | |
74 /* Extension */ | |
75 tmpFileExt = xs_strrchr(pcFilename, '.'); | |
76 | |
77 | |
78 #ifdef HAVE_XMMSEXTRA | |
79 /* Check if the titles are overridden or not */ | |
80 if (!xs_cfg.titleOverride) | |
81 { | |
82 /* Use generic XMMS titles */ | |
83 /* XMMS_NEW_TITLEINPUT(ptInput); | |
84 * We duplicate and add typecast to the code here due to XMMS's braindead headers | |
85 */ | |
86 ptInput = (TitleInput *) g_malloc0(sizeof(TitleInput)); | |
87 ptInput->__size = XMMS_TITLEINPUT_SIZE; | |
88 ptInput->__version = XMMS_TITLEINPUT_VERSION; | |
89 | |
90 /* Create the input fields */ | |
91 ptInput->file_name = tmpFilename; | |
92 ptInput->file_ext = tmpFileExt; | |
93 ptInput->file_path = tmpFilePath; | |
94 | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
95 ptInput->track_name = g_strdup(infoString0); |
217 | 96 ptInput->track_number = iSubTune; |
97 ptInput->album_name = NULL; | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
98 ptInput->performer = g_strdup(infoString1); |
217 | 99 ptInput->date = g_strdup((iSidModel == XS_SIDMODEL_6581) ? "SID6581" : "SID8580"); |
100 | |
101 ptInput->year = 0; | |
102 ptInput->genre = g_strdup("SID-tune"); | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
103 ptInput->comment = g_strdup(infoString2); |
217 | 104 |
105 /* Create the string */ | |
106 pcResult = xmms_get_titlestring(xmms_get_gentitle_format(), ptInput); | |
107 | |
108 /* Dispose all allocated memory */ | |
233
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
109 g_free(ptInput->track_name); |
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
110 g_free(ptInput->performer); |
9b5704548219
Compiler complains about discarding the const qualifier, so let's be dumb
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
111 g_free(ptInput->comment); |
217 | 112 g_free(ptInput->date); |
113 g_free(ptInput->genre); | |
114 g_free(ptInput); | |
115 } | |
116 else | |
117 #endif | |
118 { | |
119 /* Create the string */ | |
120 pcStr = xs_cfg.titleFormat; | |
121 iIndex = 0; | |
122 while (*pcStr && (iIndex < VBUFSIZE)) | |
123 { | |
124 if (*pcStr == '%') | |
125 { | |
126 pcStr++; | |
127 switch (*pcStr) { | |
128 case '%': VPUTCH('%'); break; | |
129 case 'f': VPUTSTR(tmpFilename); break; | |
130 case 'F': VPUTSTR(tmpFilePath); break; | |
131 case 'e': VPUTSTR(tmpFileExt); break; | |
132 case 'p': VPUTSTR(infoString1); break; | |
133 case 't': VPUTSTR(infoString0); break; | |
134 case 'c': VPUTSTR(infoString2); break; | |
135 case 's': VPUTSTR(formatString); break; | |
136 case 'm': | |
137 switch (iSidModel) { | |
138 case XS_SIDMODEL_6581: VPUTSTR("SID6581"); break; | |
139 case XS_SIDMODEL_8580: VPUTSTR("SID8580"); break; | |
140 default: VPUTSTR("Unknown SID"); break; | |
141 } | |
142 break; | |
143 case 'n': | |
144 snprintf(tmpStr, VBUFSIZE, "%i", iSubTune); | |
145 VPUTSTR(tmpStr); | |
146 break; | |
147 } | |
148 } else { | |
149 VPUTCH(*pcStr); | |
150 } | |
151 pcStr++; | |
152 } | |
153 | |
154 tmpBuf[iIndex] = 0; | |
155 | |
156 /* Make resulting string */ | |
157 pcResult = g_strdup(tmpBuf); | |
158 } | |
159 | |
160 /* Free temporary strings */ | |
161 g_free(tmpFilename); | |
162 g_free(tmpFilePath); | |
163 | |
164 return pcResult; | |
165 } |