1 /* $Id: file_parse.c,v 1.9 2006/09/16 10:17:33 toad32767 Exp $ */
2 /**
3  ** 2005, 2006 by Marco Trillo
4  ** This file is part of UModPlayer, and is released by
5  ** its autors to the Public Domain.
6  ** In case it's not legally possible, its autors grant
7  ** anyone the right to use, redistribute and modify
8  ** this software for any purpose, without any conditions,
9  ** unless such conditions are required by law.
10  **
11  ** THIS FILE COMES WITHOUT ANY WARRANTY. THE AUTHORS
12  ** SHALL NOT BE LIABLE FOR ANY DAMAGE RESULTING BY THE
13  ** USE OR MISUSE OF THIS SOFTWARE.
14  **/
15 
16 #include <umodplayer.h>
17 #include <text.h>
18 
19 
20 LOCAL void
RetrieveSongInfo(char * file,char * strbuf,int strbuflen)21 RetrieveSongInfo(char* file, char* strbuf, int strbuflen)
22 {
23 	int fd, len;
24 	MODULE mod;
25 	char name[32], *type, buf[512];
26 	int inst, orders;
27 
28 	fd = open(file, O_RDONLY);
29 	if (fd < 0)
30 		return;
31 
32 	len = (int) read(fd, buf, 512);
33 	close(fd);
34 
35 	if (len < 1)
36 		return;
37 
38 	if (load_module(&mod, buf, len) < 0)
39 		return;
40 
41 	module_name(&mod, name);
42 	type = module_typestr(module_type(&mod));
43 	orders = number_orders(&mod);
44 	inst = number_instruments(&mod);
45 
46 	snprintf(strbuf, strbuflen, ": <%s> [%s, %d inst, %d ords]", name, type, inst, orders);
47 	return;
48 }
49 
50 
51 EXPORT void
SongList()52 SongList()
53 {
54 	DIR *myd;
55 	struct dirent *elem;
56 	int i, namlen;
57 	char *z;
58 
59 	myd = opendir(".");
60 	if (myd == NULL)
61 		return;
62 	for (i = 0; 1; ++i) {
63 		elem = readdir(myd);
64 		if (elem == NULL)
65 			break;
66 		namlen = strlen(elem->d_name);
67 		z = (char *) malloc(namlen + 64);
68 		if (z == NULL)
69 			continue;
70 		memcpy(z, elem->d_name, namlen + 1);
71 		RetrieveSongInfo(elem->d_name, z + namlen, 64);
72 
73 		printf("+ %s\n", z);
74 
75 		free(z);
76 	}
77 	closedir(myd);
78 
79 	return;
80 }
81