/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018  - 2025 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ This program is free software; you can redistribute it and/or modify
#+ it under the terms of the GNU General Public License as published by
#+ the Free Software Foundation; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program is distributed in the hope that it will be useful,
#+ but WITHOUT ANY WARRANTY; without even the implied warranty of
#+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#+ GNU General Public License for more details.
#+
#+ You should have received a copy of the GNU General Public License
#+ along with this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	March 26, 2025

#include "includes.h"
#include "defines.h"
#include "common-externs.h"

//----------------------------------------------------------------
//	load album.lst
//----------------------------------------------------------------

void	LoadAlbums(char * file) {

	FILE *s1;
	char cmd[2048];

	int Album = 0, Track = 0;

	for (int i = 0; i < ALBUM_MAX; i++) {	// size of array
		strcpy(AlbumArray[i], "");
		}

//----------------------------------------------------------------
//	load program entries
//----------------------------------------------------------------

	s1 = fopen(file,"r");

	if (s1==NULL) {		// no album.lst file
		SP->acount = -1;	// album list is empty
		printf("*** No album.lst file found\n");
		return;
		}

	char tmp[2048],tme[32];
	int i;
	SP->acount=0;

	while (1) {

		tmp[0] = 0;

		if (fgets(tmp,2048,s1) == NULL) break; // read album.lst line
		if (tmp[0] == '#') continue; // comment

		tmp[strlen(tmp)-1] = 0; // remove newline char

		if (strlen(tmp) > ALB_MAX - 2) {
			printf("*** Album file reference too long: **%s**\n",cmd);
			continue;
			}

		strcpy(AlbumArray[SP->acount],tmp);	// record file name

		(SP->acount)++;
		if (SP->acount > ALBUM_MAX - 20) {
			(SP->acount)--;
			printf("*** More than %d lines in album.lst \n", PROGRAM_MAX);
			break;
			}
		}

	i = SP->acount;

	while (i < ALBUM_MAX) { // finish list
		strcpy(AlbumArray[i],"");
		i++;
		}

	fclose (s1);
	printf("*** album.lst loader\n");

	// acount is count of actual entries
	// ALBUM_MAX is size of array

	gtk_range_set_range (GTK_RANGE(albumScroll), 0, SP->acount);

	printf("SP->acount=%d ALBUM_MAX=%d\n", SP->acount, ALBUM_MAX);
	printf("\n");

	}

