Thread: Qucik Newbie Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    2

    Quick Newbie Help

    Sorry to bother you with a newbie question (I have no idea of C programming...): I'm running Litestream, an alternative lightweight Shoutcast streaming utility on my server, but I would like to modify it, so that it doesn't only write the file name that is currently played to regular server logs, but also to a single text file, so I can proccess it with PHP and display a "Now Playing" window on my website.

    Here's the file that needs to be modified (playlist.c)

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    
    #include "stream_std.h"
    #include "playlist.h"
    
    #include "textutils.h"
    
    extern int last_played;
    
    FILE* open_next_file(char* _files[], int _nfiles, int* _curfile) {
    	int startfile = *_curfile;
    	FILE* fp;
    	char message[1024];
    
    	if (last_played) 
    	{
    	    stream_msg("finished playlist");
    	    return(NULL); 
    	}
    
    	do {
    		fp = fopen(_files[*_curfile], "r");
    
    		if (!fp) {
    			sprintf(message, "could not open %s", _files[*_curfile]);
    			stream_err(message);
    		}
    		else {
    			sprintf(message, "opened %s", _files[*_curfile]);
    			stream_msg(message);
    		}
    
    		*_curfile = (*_curfile + 1) % _nfiles;
    
    		/* check for playlist wrap-around */
    		if (0 == *_curfile) 
    			last_played = 1;
    
    		if (fp)
    			break;
    
    		if (*_curfile == startfile) {
    			stream_msg("no reasonable files found");
    			return(NULL);
    		}
    	} while (!fp);
    
    	return(fp);
    }
    
    playlist* read_playlist(const char* _filename) {
    	FILE* fp;
    	playlist* list;
    
    	char filename[1024];
    	char comparison[1024];
    
    	list = (playlist*) malloc(sizeof(playlist));
    	list->used = 0;
    	list->size = 16;
    	list->names = (char**) malloc(sizeof(char*) * list->size);
    
    	/* test for filename of *.mp3 */
    	strncpy(filename, _filename, 1024);
    	strncpy(comparison, stripspaces(filename, LEADING | TRAILING), 1024);
    	if ((strlen(comparison) > 4) && 
    	    !strncmp(comparison + (strlen(comparison)-4), ".mp3", 1020)) {
    	    /* found a simple mp3 file */
    	    if (list->used == list->size) {
    		list->size *= 2;
    		list->names = (char**) realloc(list->names, sizeof(char*) * list->size);
    	    }
    	    list->names[list->used++] = strdup(stripspaces(filename, LEADING | TRAILING));
    	} else {
    	    if (!(fp = fopen(_filename, "r")))
    		return(NULL);
    
    	    while (!feof(fp) && !ferror(fp)) {
    		if (!(fgets(filename, sizeof(filename), fp)))
    		    break;
    
    		if (list->used == list->size) {
    		    list->size *= 2;
    		    list->names = (char**) realloc(list->names, sizeof(char*) * list->size);
    		}
    		list->names[list->used++] = strdup(stripspaces(filename, LEADING | TRAILING));
    	    }
    	    fclose(fp);
    	}
    	return(list);
    }
    Thanks a lot for you help in advance!

    Litestream Source Download
    Last edited by floid; 12-06-2005 at 06:50 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  2. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  3. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  4. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 12:27 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM