/* $Id: file_parse.c,v 1.9 2006/09/16 10:17:33 toad32767 Exp $ */ /** ** 2005, 2006 by Marco Trillo ** This file is part of UModPlayer, and is released by ** its autors to the Public Domain. ** In case it's not legally possible, its autors grant ** anyone the right to use, redistribute and modify ** this software for any purpose, without any conditions, ** unless such conditions are required by law. ** ** THIS FILE COMES WITHOUT ANY WARRANTY. THE AUTHORS ** SHALL NOT BE LIABLE FOR ANY DAMAGE RESULTING BY THE ** USE OR MISUSE OF THIS SOFTWARE. **/ #include #include LOCAL void RetrieveSongInfo(char* file, char* strbuf, int strbuflen) { int fd, len; MODULE mod; char name[32], *type, buf[512]; int inst, orders; fd = open(file, O_RDONLY); if (fd < 0) return; len = (int) read(fd, buf, 512); close(fd); if (len < 1) return; if (load_module(&mod, buf, len) < 0) return; module_name(&mod, name); type = module_typestr(module_type(&mod)); orders = number_orders(&mod); inst = number_instruments(&mod); snprintf(strbuf, strbuflen, ": <%s> [%s, %d inst, %d ords]", name, type, inst, orders); return; } EXPORT void SongList() { DIR *myd; struct dirent *elem; int i, namlen; char *z; myd = opendir("."); if (myd == NULL) return; for (i = 0; 1; ++i) { elem = readdir(myd); if (elem == NULL) break; namlen = strlen(elem->d_name); z = (char *) malloc(namlen + 64); if (z == NULL) continue; memcpy(z, elem->d_name, namlen + 1); RetrieveSongInfo(elem->d_name, z + namlen, 64); printf("+ %s\n", z); free(z); } closedir(myd); return; }