comparison src/xs_length.c @ 57:85811bcd049e

Improved, re-written configuration code and lots of minor fixes
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 22 Jun 2003 11:01:03 +0000
parents 6a3ce7260ae1
children 0d1df20745dd
comparison
equal deleted inserted replaced
56:6a3ce7260ae1 57:85811bcd049e
197 197
198 198
199 /* 199 /*
200 * Read database to memory 200 * Read database to memory
201 */ 201 */
202 gint xs_db_read(gchar *dbFilename, t_xs_dbentry **dataBase) 202 gint xs_db_read(gchar *dbFilename)
203 { 203 {
204 FILE *inFile; 204 FILE *inFile;
205 gchar inLine[XS_BUFSIZE]; 205 gchar inLine[XS_BUFSIZE];
206 gint lineNum, linePos, iOK; 206 guint lineNum, linePos;
207 gboolean iOK;
207 t_xs_dbentry *tmpNode; 208 t_xs_dbentry *tmpNode;
208 209
209 /* Try to open the file */ 210 /* Try to open the file */
210 if ((inFile = fopen(dbFilename, "ra")) == NULL) 211 if ((inFile = fopen(dbFilename, "ra")) == NULL)
211 { 212 {
262 263
263 xs_db_node_free(tmpNode); 264 xs_db_node_free(tmpNode);
264 } else { 265 } else {
265 /* First playtime is after '=' */ 266 /* First playtime is after '=' */
266 linePos++; 267 linePos++;
267 iOK = 1; 268 iOK = TRUE;
268 269
269 while ((linePos < strlen(inLine)) && (iOK)) 270 while ((linePos < strlen(inLine)) && iOK)
270 { 271 {
271 xs_findnext(inLine, &linePos); 272 xs_findnext(inLine, &linePos);
272 273
273 if (tmpNode->nLengths < XS_STIL_MAXENTRY) 274 if (tmpNode->nLengths < XS_STIL_MAXENTRY)
274 { 275 {
275 tmpNode->sLengths[tmpNode->nLengths] = 276 tmpNode->sLengths[tmpNode->nLengths] =
276 xs_gettime(inLine, &linePos); 277 xs_gettime(inLine, &linePos);
277 tmpNode->nLengths++; 278 tmpNode->nLengths++;
278 } else 279 } else
279 iOK = 0; 280 iOK = FALSE;
280 } 281 }
281 282
282 /* Add an entry to db in memory */ 283 /* Add an entry to db in memory */
283 if (iOK) 284 if (iOK)
284 xs_db_node_insert(tmpNode); 285 xs_db_node_insert(tmpNode);
323 324
324 /* Read the database */ 325 /* Read the database */
325 if (xs_cfg.songlenDBPath == NULL) 326 if (xs_cfg.songlenDBPath == NULL)
326 return -10; 327 return -10;
327 328
328 if (xs_db_read(xs_cfg.songlenDBPath, &xs_database) < 0) 329 if (xs_db_read(xs_cfg.songlenDBPath) < 0)
329 return -9; 330 return -9;
330 331
331 /* Get size of db */ 332 /* Get size of db */
332 pCurr = xs_database; 333 pCurr = xs_database;
333 xs_dbnodes = 0; 334 xs_dbnodes = 0;
560 /* Get the hash and then look up from db */ 561 /* Get the hash and then look up from db */
561 if (xs_get_sid_hash(fileName, dbHash) == 0) 562 if (xs_get_sid_hash(fileName, dbHash) == 0)
562 { 563 {
563 dbEntry = xs_db_get(dbHash); 564 dbEntry = xs_db_get(dbHash);
564 565
565 if (dbEntry) 566 if (dbEntry && (subTune >= 0) && (subTune < dbEntry->nLengths))
566 { 567 iResult = dbEntry->sLengths[subTune - 1];
567 if ((subTune >= 0) && (subTune < dbEntry->nLengths))
568 iResult = dbEntry->sLengths[subTune - 1];
569 }
570 } 568 }
571 } 569 }
572 #if 0 570 #if 0
573 XSDEBUG("fname='%s', sub=%i, res=%i\n", fileName, subTune, iResult); 571 XSDEBUG("fname='%s', sub=%i, res=%i\n", fileName, subTune, iResult);
574 #endif 572 #endif