comparison src/xs_stil.c @ 240:f436e16fa6d9

Fixed cosmetic bug in handling of multi-line fields (COMMENT).
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Dec 2004 15:04:04 +0000
parents e613873c3379
children 5a18af547f58
comparison
equal deleted inserted replaced
239:7833df935239 240:f436e16fa6d9
89 } 89 }
90 90
91 91
92 /* Read database (additively) to given db-structure 92 /* Read database (additively) to given db-structure
93 */ 93 */
94 #define XS_STILDB_MULTI if (isMulti) { isMulti = FALSE; xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), "\n"); }
95
96
94 gint xs_stildb_read(t_xs_stildb *db, gchar *dbFilename) 97 gint xs_stildb_read(t_xs_stildb *db, gchar *dbFilename)
95 { 98 {
96 FILE *inFile; 99 FILE *inFile;
97 gchar inLine[XS_BUFSIZE + 10]; 100 gchar inLine[XS_BUF_SIZE + 16]; /* Since we add some chars here and there */
98 guint lineNum, linePos, eolPos; 101 guint lineNum, linePos, eolPos;
99 t_xs_stil_node *tmpNode; 102 t_xs_stil_node *tmpNode;
100 gboolean isError; 103 gboolean isError, isMulti;
101 gint subEntry; 104 gint subEntry;
102 assert(db); 105 assert(db);
103 106
104 /* Try to open the file */ 107 /* Try to open the file */
105 if ((inFile = fopen(dbFilename, "ra")) == NULL) 108 if ((inFile = fopen(dbFilename, "ra")) == NULL)
109 } 112 }
110 113
111 /* Read and parse the data */ 114 /* Read and parse the data */
112 lineNum = 0; 115 lineNum = 0;
113 isError = FALSE; 116 isError = FALSE;
117 isMulti = FALSE;
114 tmpNode = NULL; 118 tmpNode = NULL;
115 subEntry = 0; 119 subEntry = 0;
116 120
117 while (!feof(inFile) && !isError) 121 while (!feof(inFile) && !isError)
118 { 122 {
119 fgets(inLine, XS_BUFSIZE, inFile); 123 fgets(inLine, XS_BUF_SIZE, inFile);
124 inLine[XS_BUF_SIZE-1] = 0;
120 linePos = eolPos = 0; 125 linePos = eolPos = 0;
121 xs_findeol(inLine, &eolPos); 126 xs_findeol(inLine, &eolPos);
122 inLine[eolPos] = 0; 127 inLine[eolPos] = 0;
123 lineNum++; 128 lineNum++;
124 129
189 } 194 }
190 195
191 /* Some other type */ 196 /* Some other type */
192 if (strncmp(inLine, " NAME:", 8) == 0) 197 if (strncmp(inLine, " NAME:", 8) == 0)
193 { 198 {
199 XS_STILDB_MULTI
200
194 g_free(tmpNode->subTune[subEntry].pName); 201 g_free(tmpNode->subTune[subEntry].pName);
195 tmpNode->subTune[subEntry].pName = g_strdup(&inLine[9]); 202 tmpNode->subTune[subEntry].pName = g_strdup(&inLine[9]);
196 } else 203 } else
197 if (strncmp(inLine, " AUTHOR:", 8) == 0) 204 if (strncmp(inLine, " AUTHOR:", 8) == 0)
198 { 205 {
206 XS_STILDB_MULTI
207
199 g_free(tmpNode->subTune[subEntry].pAuthor); 208 g_free(tmpNode->subTune[subEntry].pAuthor);
200 tmpNode->subTune[subEntry].pAuthor = g_strdup(&inLine[9]); 209 tmpNode->subTune[subEntry].pAuthor = g_strdup(&inLine[9]);
201 } else 210 } else
202 if (strncmp(inLine, " TITLE:", 8) == 0) 211 if (strncmp(inLine, " TITLE:", 8) == 0)
203 { 212 {
213 XS_STILDB_MULTI
214
204 inLine[eolPos++] = '\n'; 215 inLine[eolPos++] = '\n';
205 inLine[eolPos++] = 0; 216 inLine[eolPos++] = 0;
206 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[2]); 217 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[2]);
207 } else 218 } else
208 if (strncmp(inLine, " ARTIST:", 8) == 0) 219 if (strncmp(inLine, " ARTIST:", 8) == 0)
209 { 220 {
221 XS_STILDB_MULTI
222
210 inLine[eolPos++] = '\n'; 223 inLine[eolPos++] = '\n';
211 inLine[eolPos++] = 0; 224 inLine[eolPos++] = 0;
212 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[1]); 225 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[1]);
213 } else 226 } else
214 if (strncmp(inLine, "COMMENT:", 8) == 0) 227 if (strncmp(inLine, "COMMENT:", 8) == 0)
228 {
229 XS_STILDB_MULTI
230
231 isMulti = TRUE;
215 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), inLine); 232 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), inLine);
216 else 233 } else
217 if (strncmp(inLine, " ", 8) == 0) 234 if (strncmp(inLine, " ", 8) == 0)
235 {
218 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[8]); 236 xs_pstrcat(&(tmpNode->subTune[subEntry].pInfo), &inLine[8]);
237 }
219 break; 238 break;
220 } 239 }
221 240
222 } /* while */ 241 } /* while */
223 242