comparison src/xs_length.c @ 56:6a3ce7260ae1

Changed some standard functions to glib ones
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 22 Jun 2003 00:17:04 +0000
parents 1788f4ce6a44
children 85811bcd049e
comparison
equal deleted inserted replaced
55:e3708b2bbc5f 56:6a3ce7260ae1
43 t_xs_dbentry *xs_db_node_new(void) 43 t_xs_dbentry *xs_db_node_new(void)
44 { 44 {
45 t_xs_dbentry *pResult; 45 t_xs_dbentry *pResult;
46 46
47 /* Allocate memory for new node */ 47 /* Allocate memory for new node */
48 pResult = (t_xs_dbentry *) calloc(1, sizeof(t_xs_dbentry)); 48 pResult = (t_xs_dbentry *) g_malloc0(sizeof(t_xs_dbentry));
49 if (pResult == NULL) return NULL; 49 if (pResult == NULL) return NULL;
50 50
51 return pResult; 51 return pResult;
52 } 52 }
53 53
323 323
324 /* Read the database */ 324 /* Read the database */
325 if (xs_cfg.songlenDBPath == NULL) 325 if (xs_cfg.songlenDBPath == NULL)
326 return -10; 326 return -10;
327 327
328 fprintf(stderr, "reading '%s'\n", xs_cfg.songlenDBPath);
329
330 if (xs_db_read(xs_cfg.songlenDBPath, &xs_database) < 0) 328 if (xs_db_read(xs_cfg.songlenDBPath, &xs_database) < 0)
331 return -9; 329 return -9;
332
333 fprintf(stderr, "read_done, now size DB for index\n");
334 330
335 /* Get size of db */ 331 /* Get size of db */
336 pCurr = xs_database; 332 pCurr = xs_database;
337 xs_dbnodes = 0; 333 xs_dbnodes = 0;
338 while (pCurr) 334 while (pCurr)
342 } 338 }
343 339
344 /* Check number of nodes */ 340 /* Check number of nodes */
345 if (xs_dbnodes > 0) 341 if (xs_dbnodes > 0)
346 { 342 {
347 fprintf(stderr, "allocating %i nodes...\n", xs_dbnodes);
348 /* Allocate memory for index-table */ 343 /* Allocate memory for index-table */
349 xs_dbindex = (t_xs_dbentry **) malloc(sizeof(t_xs_dbentry *) * xs_dbnodes); 344 xs_dbindex = (t_xs_dbentry **) g_malloc(sizeof(t_xs_dbentry *) * xs_dbnodes);
350 if (xs_dbindex == NULL) return -6; 345 if (xs_dbindex == NULL) return -6;
351 346
352 /* Get node-pointers to table */ 347 /* Get node-pointers to table */
353 i = 0; 348 i = 0;
354 pCurr = xs_database; 349 pCurr = xs_database;
356 { 351 {
357 xs_dbindex[i++] = pCurr; 352 xs_dbindex[i++] = pCurr;
358 pCurr = pCurr->pNext; 353 pCurr = pCurr->pNext;
359 } 354 }
360 355
361 fprintf(stderr, "sorting!\n");
362 /* Sort the indexes */ 356 /* Sort the indexes */
363 qsort(xs_dbindex, xs_dbnodes, sizeof(t_xs_dbentry *), xs_db_cmp); 357 qsort(xs_dbindex, xs_dbnodes, sizeof(t_xs_dbentry *), xs_db_cmp);
364 } 358 }
365 359
366 /* OK */ 360 /* OK */
485 fseek(inFile, 0L, SEEK_END); 479 fseek(inFile, 0L, SEEK_END);
486 songDataLen = ftell(inFile) - psidH.dataOffset; 480 songDataLen = ftell(inFile) - psidH.dataOffset;
487 fseek(inFile, psidH.dataOffset, SEEK_SET); 481 fseek(inFile, psidH.dataOffset, SEEK_SET);
488 482
489 /* Allocate memory */ 483 /* Allocate memory */
490 songData = (guint8 *) malloc(sizeof(guint8) * songDataLen); 484 songData = (guint8 *) g_malloc(sizeof(guint8) * songDataLen);
491 if (songData == NULL) 485 if (songData == NULL)
492 { 486 {
493 fclose(inFile); 487 fclose(inFile);
494 return -7; 488 return -7;
495 } 489 }
573 if ((subTune >= 0) && (subTune < dbEntry->nLengths)) 567 if ((subTune >= 0) && (subTune < dbEntry->nLengths))
574 iResult = dbEntry->sLengths[subTune - 1]; 568 iResult = dbEntry->sLengths[subTune - 1];
575 } 569 }
576 } 570 }
577 } 571 }
578 572 #if 0
579 // XSDEBUG("fname='%s', sub=%i, res=%i\n", fileName, subTune, iResult); 573 XSDEBUG("fname='%s', sub=%i, res=%i\n", fileName, subTune, iResult);
574 #endif
580 575
581 return iResult; 576 return iResult;
582 } 577 }
583 578
584 579