/* * Load playlist. */ void OGG_LoadPlaylist(char *playlist) { byte *buffer; /* Buffer to read the file. */ char *ptr; /* Pointer for parsing the file. */ int i; /* Loop counter. */ int size; /* Length of buffer and strings. */ /* Open playlist. */ if ((size = FS_LoadFile(va("%s/%s.lst", OGG_DIR, ogg_playlist->string), (void **)&buffer)) < 0) { Com_Printf("OGG_LoadPlaylist: could not open playlist: %s.\n", strerror(errno)); return; } /* Count the files in playlist. */ for (ptr = strtok((char *)buffer, "\n"); ptr != NULL; ptr = strtok(NULL, "\n")) { if ((byte *)ptr != buffer) { ptr[-1] = '\n'; } if (OGG_Check(va("%s/%s", OGG_DIR, ptr))) { ogg_numfiles++; } } /* Allocate file list. */ ogg_filelist = malloc(sizeof(char *) * ogg_numfiles); i = 0; for (ptr = strtok((char *)buffer, "\n"); ptr != NULL; ptr = strtok(NULL, "\n")) { if (OGG_Check(va("%s/%s", OGG_DIR, ptr))) { ogg_filelist[i++] = strdup(va("%s/%s", OGG_DIR, ptr)); } } /* Free file buffer. */ FS_FreeFile(buffer); }
/* ========== OGG_LoadFileList Load list of Ogg Vorbis files in "music". ========== */ void OGG_LoadFileList(void) { char **list; /* List of .ogg files. */ int i; /* Loop counter. */ int j; /* Real position in list. */ /* Get file list. */ list = FS_ListFiles2(va("%s/*.ogg", OGG_DIR), &ogg_numfiles, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM); ogg_numfiles--; /* Check if there are posible Ogg files. */ if (list == NULL) return; /* Allocate list of files. */ ogg_filelist = malloc(sizeof(char *) * ogg_numfiles); /* Add valid Ogg Vorbis file to the list. */ for (i = 0, j = 0; i < ogg_numfiles; i++) { if (!OGG_Check(list[i])) { free(list[i]); continue; } ogg_filelist[j++] = list[i]; } /* Free the file list. */ free(list); /* Adjust the list size (remove space for invalid music files). */ ogg_numfiles = j; ogg_filelist = realloc(ogg_filelist, sizeof(char *) * ogg_numfiles); }