[Alsaplayer-devel] New release, was: svn checkout 1240 fixes my gtk2 problem

Dominique Michel dominique.michel at citycable.ch
Thu Jun 28 19:27:31 BST 2007


Le Wed, 27 Jun 2007 22:19:55 +0100,
MadeJ <madejos at o2.pl> a écrit :

> 
> 
> Dominique Michel wrote:
> >
> >
> > I try a few things but get only garbage when compiling. (compil errors)
> >
> >   
> like what ?
> if you're talking about cddb it was just an idea how it may work not
> exact code

I know that.

> if something else i'm not sure what
> 

It is a huge while loop that read the cddb info and extract the needed stuff
for the display.

What I try was to put the DTITLE info in a new variable to be able to use it
later in the loop. Already that was failing. The problem for me here is that I
begun to learn C but I have not reached the chapter on the character strings.
So, it is already a lot of things I don't understand in this part of the
existing code.

If it was working, it will be another problem anyway, I don't know if it will
be trivial to rewrite the while loop or if it will be needed to almost
completely rewrite it.

Here is the original function with the while loop:

 void cddb_read_file (char *file, struct cdda_local_data *data)
{
	char line[BUFFER_SIZE], name[BUFFER_SIZE];
	char *token = NULL, *tmp, *divider, *s, *post;
	int i, index = 1;
	FILE *f;

	/* try to open the file */
	f = fopen (file, "r");
	if (! f) {
		alsaplayer_error("couldn't open file");
		return;	  
	}
	/* read it line by line */
	while (!feof (f)) {
		if ((fgets (line, sizeof (line), f))) {
			if (! (strstr (line, "DTITLE="))) {
				/* check if is the music name.. */
				if ((strstr (line, "TTITLE"))) {
					token = strtok (line, "=");
					if (!token) { 
						alsaplayer_error("error: TTITLE
has no arguments"); continue;
					}
					token = strtok (NULL, "=");
					if (!token) {
						alsaplayer_error("TTITLE has no
arguments"); continue;
					}	  
					/* seek for the \r character */
					for (i = 0; i < (int)strlen (token);
i++) { if ((token[i] == '\n') || (token[i] == '\r'))
							break;
					}
					if (sscanf(line, "TTITLE%d=", &index)) {
						//alsaplayer_error("Found index
%d", index); index++;
					} else {
						index = 1;
						alsaplayer_error("Error reading
index number!"); }
					token[i] = '\0';
					sprintf (name, "%s", token);
					if (data->tracks[index].track) {
						post = (char
*)malloc(strlen(data->tracks[index].track) + strlen(name) + 1); *post = '\0';
						strcat(post,
data->tracks[index].track); strcat(post, name);
						free(data->tracks[index].track);
						data->tracks[index].track =
strdup(post); free(post);
					} else {	
						data->tracks[index].track =
strdup (name); }	
				}
				continue;
			} else {
				/* print the album name */
				tmp = strtok (line, "=");
				if (!tmp) { 
					alsaplayer_error ("error: no arguments
given on %s", line); continue;
				}
				tmp = strtok (NULL, "=");
				if (!tmp) {
					alsaplayer_error ("error: no arguments
given on %s", line); continue;
				}
				divider = strstr (tmp, " / ");
				if (!divider) { 
					alsaplayer_error("No divider found in
DTITLE"); data->tracks[1].artist = strdup(tmp);
					data->tracks[1].album = strdup(tmp);
				} else {
					data->tracks[1].album = strdup
(divider+3); tmp[strlen(tmp)-strlen(data->tracks[1].album)-3] = '\0';
					data->tracks[1].artist = strdup (tmp);
				}	
				if ((s = strstr(data->tracks[1].artist, "\r")))
{ *s = '\0';
				}
				if ((s = strstr(data->tracks[1].artist, "\n")))
{ *s = '\0';
				} 
				if ((s = strstr(data->tracks[1].album, "\r"))) {
					*s = '\0';
				}
				if ((s = strstr(data->tracks[1].album, "\n"))) {
					*s = '\0';
				}
				if
(data->tracks[1].album[strlen(data->tracks[1].album)-1] == ' ')
{ data->tracks[1].album[strlen(data->tracks[1].album)-1] = '\0'; }
				if
(data->tracks[1].artist[strlen(data->tracks[1].artist)-1] == ' ')
{ data->tracks[1].artist[strlen(data->tracks[1].artist)-1] = '\0'; }
				if (global_verbose) {
					alsaplayer_error ("Artist: %s",
data->tracks[1].artist); alsaplayer_error ("Album name: %s",
data->tracks[1].album); }
			}
		}	/* if */
	}	/* while */
}

Dominique



More information about the alsaplayer-devel mailing list