/******************************************************************************
 * Steve Rider - stever@transmission23.com
 * QuickPics
 *   Image galleries for the web made easy
 *
 * qp.c - internal and config settings
 *
 *****************************************************************************/
/* 20 February 98 */

#include "qp.h"
#include "utility.h"


/***************************************************************************n
 *
 * QuickPics object definitions
 *
 ****************************************************************************/

void QP_Init()
{
	/* Config entries */
	QP.quiet_level = 0;
	QP.prompt_for_description = 0;
	QP.prompt_for_date = 0;
	QP.prompt_for_thumbnail_creation = 1;
	QP.write_thumbnails = 0;	/* no effect unless override flag */

	/* Footer */
	strcpy(QP.footer,"These images are sorted, arranged, processed and presented by way of the <a href=\"http://www.retina.net/~stever/src/QuickPics\">Stever QuickPics system</a>.");
	QP.footersize = 1;
	strcpy(QP.footerfont,"");
	strcpy(QP.footercolor,"#cccccc");
	QP.footerbold = 0;
	QP.footeritalic = 0;

	/* Filename properties */
	strcpy(QP.index_html,"index.html");
	strcpy(QP.folder_configfile,"info.txt");
	strcpy(QP.thumbnail_identifier,"-sm");

	/* Global settings */
	QP.thumbnailsize = 75;
	QP.max_width = 1000;
	QP.quality = 75;
	strcpy(QP.page_width,"95%");
	QP.picture_width = 450;
	QP.prev_next_thumbnails = 1;


	/* Root properties */
	QP.root_write_toolbar = 1;

	strcpy(QP.root_bgcolor,"#000000");
	strcpy(QP.root_textcolor,"#cccccc");
	strcpy(QP.root_linkcolor,"#dc1f1f");
	strcpy(QP.root_vlinkcolor,"#dc1f1f");
	strcpy(QP.root_alinkcolor,"#dc1f1f");

	/* Root title */
	QP.root_titlesize = 6;
	strcpy(QP.root_titlefont,"");
	strcpy(QP.root_titlecolor,"#cccccc");
	QP.root_titlebold = 1;
	QP.root_titleitalic = 1;

	/* Root description */
	QP.root_headingsize = 3;
	strcpy(QP.root_headingfont,"");
	strcpy(QP.root_headingcolor,"#cccccc");
	QP.root_headingbold = 0;
	QP.root_headingitalic = 0;

	/* Root all folder properties */
	QP.root_propertiessize = 3;
	strcpy(QP.root_propertiesfont,"");
	strcpy(QP.root_propertiescolor,"#cccccc");
	QP.root_propertiesbold = 0;
	QP.root_propertiesitalic = 0;

	/* Root foldername */
	QP.root_foldernamesize = 5;
	strcpy(QP.root_foldernamefont,"");
	strcpy(QP.root_foldernamecolor,"#cccccc");
	QP.root_foldernamebold = 0;
	QP.root_foldernameitalic = 0;

	/* Root table properties */
	QP.root_border = 0;
	QP.root_cols = 3;
	QP.root_pictureborder = 0;

	/* Root thumbnail descriptions */
	QP.root_descsize = 2;
	strcpy(QP.root_descfont,"");
	strcpy(QP.root_desccolor,"#cccccc");
	QP.root_descbold = 0;
	QP.root_descitalic = 0;


	/* Index properties */
	QP.index_write_toolbar = 1;

	strcpy(QP.index_bgcolor,"#000000");
	strcpy(QP.index_textcolor,"#cccccc");
	strcpy(QP.index_linkcolor,"#dc1f1f");
	strcpy(QP.index_vlinkcolor,"#dc1f1f");
	strcpy(QP.index_alinkcolor,"#dc1f1f");

	/* Index title */
	QP.index_titlesize = 6;
	strcpy(QP.index_titlefont,"");
	strcpy(QP.index_titlecolor,"#cccccc");
	QP.index_titlebold = 1;
	QP.index_titleitalic = 1;

	/* Index folder description */
	QP.index_headingsize = 3;
	strcpy(QP.index_headingfont,"");
	strcpy(QP.index_headingcolor,"#cccccc");
	QP.index_headingbold = 0;
	QP.index_headingitalic = 0;

	/* Index folder properties */
	QP.index_propertiessize = 3;
	strcpy(QP.index_propertiesfont,"");
	strcpy(QP.index_propertiescolor,"#cccccc");
	QP.index_propertiesbold = 0;
	QP.index_propertiesitalic = 0;

	/* Index table properties */
	QP.index_border = 0;
	QP.index_cols = 4;
	QP.index_pictureborder = 0;

	/* Index thumbnail descriptions */
	QP.index_descsize = 2;
	strcpy(QP.index_descfont,"");
	strcpy(QP.index_desccolor,"#cccccc");
	QP.index_descbold = 0;
	QP.index_descitalic = 0;


	/* Pic page properties */
	QP.pic_write_toolbar = 0;

	strcpy(QP.pic_bgcolor,"#000000");
	strcpy(QP.pic_textcolor,"#cccccc");
	strcpy(QP.pic_linkcolor,"#dc1f1f");
	strcpy(QP.pic_vlinkcolor,"#dc1f1f");
	strcpy(QP.pic_alinkcolor,"#dc1f1f");

	/* Pic title */
	QP.pic_titlesize = 6;
	strcpy(QP.pic_titlefont,"");
	strcpy(QP.pic_titlecolor,"#cccccc");
	QP.pic_titlebold = 1;
	QP.pic_titleitalic = 1;

	/* Pic image descriptions */
	QP.pic_descsize = 3;
	strcpy(QP.pic_descfont,"");
	strcpy(QP.pic_desccolor,"#cccccc");
	QP.pic_descbold = 0;
	QP.pic_descitalic = 0;


	/* Initialize config-less entries */
	QP.write_new_config = 0;
	QP.override_quiet = 0;
	QP.override_description = 0;
	QP.override_date = 0;
	QP.override_thumbnail = 0;
	strcpy(QP.rootdir,"");
	strcpy(QP.configfile,DEFAULTCONFIGFILE);
	strcpy(QP.build,"1.6");
	sprintf(QP.copyright,"QuickPics %s (c) 1998 Steve Rider (stever@transmission23.com)",QP.build);
}

int QP_ReadConfig()
{
	int	line = 0;
	char	s[MAXTEXTLEN], ident[MAXTEXTLEN];
	char	token1[MAXTEXTLEN], token2[MAXTEXTLEN];
	FILE	*f;

	/* Write new config? */
	if(QP.write_new_config)
	{
		QP_WriteConfig();

		if(QP.write_new_config == 2)
			exit(0);
		return 1;
	}

	/* Open config, write if none exists. */
	f = fopen(QP.configfile,"r");
	if(f == NULL)
	{
		QP_WriteConfig();
		return 0;
	}

	/* Read each line */
	while(readline(f,s))
	{
		line++;

		/* Remove spaces from beginning and end */
		rmspace(s);

		/* ignore comments */
		if(s[0] && s[0] != '#')
		{
			/* extract identifier code */
			str_element(ident,s,1);
			quoted_str_element(token1,s,2);
			quoted_str_element(token2,s,3);

			if(!token1[0])
				printf("[%d] Config file error: Invalid # of parameters.\n",line);
			else if(isequal(ident,"set"))
			{
				if(!token1[0] || !token2[0])
					printf("[%d] Config file error: Invalid # of parameters.\n",line);
				else if(!QP_SetVar(line,token1,token2))
					printf("[%d] Config file error: Unable to set variable \"%s\".\n",line,token1);
			}
			else
				printf("[%d] Config file error: Invalid identifier \"%s\".",line,ident);
		}
	}
	fclose(f);

	return line;
}

int QP_SetVar(int line, char *n, char *v)
{
	if(!n || !v)
		return 0;

	if(!n[0] || !v[0])
		return 0;

	if(!isanumber(v))
	{
		if(!rmquotes(v))
		{
			printf("[%d] Config file error: variable string not quoted.\n",line);
			return 0;
		}
	}

	/* initialize config variables */
	if(isequal(n,"quiet-level") && !QP.override_quiet)
		QP.quiet_level = atoi(v);
	else if(isequal(n,"prompt-for-description"))
	{
		if(!QP.override_description)
			QP.prompt_for_description = atoi(v);
	}
	else if(isequal(n,"prompt-for-date"))
	{
		if(!QP.override_date)
			QP.prompt_for_date = atoi(v);
	}
	else if(isequal(n,"prompt-for-thumbnail-creation"))
		QP.prompt_for_thumbnail_creation = atoi(v);

	else if(isequal(n,"index-html"))
		strcpy(QP.index_html,v);
	else if(isequal(n,"folder-configfile"))
		strcpy(QP.folder_configfile,v);
	else if(isequal(n,"thumbnail-identifier"))
		strcpy(QP.thumbnail_identifier,v);

	else if(isequal(n,"thumbnailsize"))
		QP.thumbnailsize = atoi(v);
	else if(isequal(n,"max-width"))
		QP.max_width = atoi(v);
	else if(isequal(n,"quality"))
		QP.quality = atoi(v);
	else if(isequal(n,"page-width"))
		strcpy(QP.page_width,v);
	else if(isequal(n,"picture-width"))
		QP.picture_width = atoi(v);
	else if(isequal(n,"prev-next-thumbnails"))
		QP.prev_next_thumbnails = atoi(v);

	
	else if(isequal(n,"root-write-toolbar"))
		QP.root_write_toolbar = atoi(v);
	else if(isequal(n,"root-bgcolor"))
		strcpy(QP.root_bgcolor,v);
	else if(isequal(n,"root-textcolor"))
		strcpy(QP.root_textcolor,v);
	else if(isequal(n,"root-linkcolor"))
		strcpy(QP.root_linkcolor,v);
	else if(isequal(n,"root-vlinkcolor"))
		strcpy(QP.root_vlinkcolor,v);
	else if(isequal(n,"root-alinkcolor"))
		strcpy(QP.root_alinkcolor,v);

	else if(isequal(n,"root-titlesize"))
		QP.root_titlesize = atoi(v);
	else if(isequal(n,"root-titlefont"))
		strcpy(QP.root_titlefont,v);
	else if(isequal(n,"root-titlecolor"))
		strcpy(QP.root_titlecolor,v);
	else if(isequal(n,"root-titlebold"))
		QP.root_titlebold = atoi(v);
	else if(isequal(n,"root-titleitalic"))
		QP.root_titleitalic = atoi(v);
	
	else if(isequal(n,"root-headingsize"))
		QP.root_headingsize = atoi(v);
	else if(isequal(n,"root-headingfont"))
		strcpy(QP.root_headingfont,v);
	else if(isequal(n,"root-headingcolor"))
		strcpy(QP.root_headingcolor,v);
	else if(isequal(n,"root-headingbold"))
		QP.root_headingbold = atoi(v);
	else if(isequal(n,"root-headingitalic"))
		QP.root_headingitalic = atoi(v);
	
	else if(isequal(n,"root-propertiessize"))
		QP.root_propertiessize = atoi(v);
	else if(isequal(n,"root-propertiesfont"))
		strcpy(QP.root_propertiesfont,v);
	else if(isequal(n,"root-propertiescolor"))
		strcpy(QP.root_propertiescolor,v);
	else if(isequal(n,"root-propertiesbold"))
		QP.root_propertiesbold = atoi(v);
	else if(isequal(n,"root-propertiesitalic"))
		QP.root_propertiesitalic = atoi(v);
	
	else if(isequal(n,"root-foldernamesize"))
		QP.root_foldernamesize = atoi(v);
	else if(isequal(n,"root-foldernamefont"))
		strcpy(QP.root_foldernamefont,v);
	else if(isequal(n,"root-foldernamecolor"))
		strcpy(QP.root_foldernamecolor,v);
	else if(isequal(n,"root-foldernamebold"))
		QP.root_foldernamebold = atoi(v);
	else if(isequal(n,"root-foldernameitalic"))
		QP.root_foldernameitalic = atoi(v);
	
	else if(isequal(n,"root-border"))
		QP.root_border = atoi(v);
	else if(isequal(n,"root-cols"))
		QP.root_cols = atoi(v);
	else if(isequal(n,"root-pictureborder"))
		QP.root_pictureborder = atoi(v);

	else if(isequal(n,"root-descsize"))
		QP.root_descsize = atoi(v);
	else if(isequal(n,"root-descfont"))
		strcpy(QP.root_descfont,v);
	else if(isequal(n,"root-desccolor"))
		strcpy(QP.root_desccolor,v);
	else if(isequal(n,"root-descbold"))
		QP.root_descbold = atoi(v);
	else if(isequal(n,"root-descitalic"))
		QP.root_descitalic = atoi(v);
	
	else if(isequal(n,"index-write-toolbar"))
		QP.index_write_toolbar = atoi(v);
	else if(isequal(n,"index-bgcolor"))
		strcpy(QP.index_bgcolor,v);
	else if(isequal(n,"index-textcolor"))
		strcpy(QP.index_textcolor,v);
	else if(isequal(n,"index-linkcolor"))
		strcpy(QP.index_linkcolor,v);
	else if(isequal(n,"index-vlinkcolor"))
		strcpy(QP.index_vlinkcolor,v);
	else if(isequal(n,"index-alinkcolor"))
		strcpy(QP.index_alinkcolor,v);

	else if(isequal(n,"index-titlesize"))
		QP.index_titlesize = atoi(v);
	else if(isequal(n,"index-titlefont"))
		strcpy(QP.index_titlefont,v);
	else if(isequal(n,"index-titlecolor"))
		strcpy(QP.index_titlecolor,v);
	else if(isequal(n,"index-titlebold"))
		QP.index_titlebold = atoi(v);
	else if(isequal(n,"index-titleitalic"))
		QP.index_titleitalic = atoi(v);
	
	else if(isequal(n,"index-headingsize"))
		QP.index_headingsize = atoi(v);
	else if(isequal(n,"index-headingfont"))
		strcpy(QP.index_headingfont,v);
	else if(isequal(n,"index-headingcolor"))
		strcpy(QP.index_headingcolor,v);
	else if(isequal(n,"index-headingbold"))
		QP.index_headingbold = atoi(v);
	else if(isequal(n,"index-headingitalic"))
		QP.index_headingitalic = atoi(v);
	
	else if(isequal(n,"index-propertiessize"))
		QP.index_propertiessize = atoi(v);
	else if(isequal(n,"index-propertiesfont"))
		strcpy(QP.index_propertiesfont,v);
	else if(isequal(n,"index-propertiescolor"))
		strcpy(QP.index_propertiescolor,v);
	else if(isequal(n,"index-propertiesbold"))
		QP.index_propertiesbold = atoi(v);
	else if(isequal(n,"index-propertiesitalic"))
		QP.index_propertiesitalic = atoi(v);
	
	else if(isequal(n,"index-border"))
		QP.index_border = atoi(v);
	else if(isequal(n,"index-cols"))
		QP.index_cols = atoi(v);
	else if(isequal(n,"index-pictureborder"))
		QP.index_pictureborder = atoi(v);

	else if(isequal(n,"index-descsize"))
		QP.index_descsize = atoi(v);
	else if(isequal(n,"index-descfont"))
		strcpy(QP.index_descfont,v);
	else if(isequal(n,"index-desccolor"))
		strcpy(QP.index_desccolor,v);
	else if(isequal(n,"index-descbold"))
		QP.index_descbold = atoi(v);
	else if(isequal(n,"index-descitalic"))
		QP.index_descitalic = atoi(v);
	
	else if(isequal(n,"pic-write-toolbar"))
		QP.pic_write_toolbar = atoi(v);
	else if(isequal(n,"pic-bgcolor"))
		strcpy(QP.pic_bgcolor,v);
	else if(isequal(n,"pic-textcolor"))
		strcpy(QP.pic_textcolor,v);
	else if(isequal(n,"pic-linkcolor"))
		strcpy(QP.pic_linkcolor,v);
	else if(isequal(n,"pic-vlinkcolor"))
		strcpy(QP.pic_vlinkcolor,v);
	else if(isequal(n,"pic-alinkcolor"))
		strcpy(QP.pic_alinkcolor,v);

	else if(isequal(n,"pic-titlesize"))
		QP.pic_titlesize = atoi(v);
	else if(isequal(n,"pic-titlefont"))
		strcpy(QP.pic_titlefont,v);
	else if(isequal(n,"pic-titlecolor"))
		strcpy(QP.pic_titlecolor,v);
	else if(isequal(n,"pic-titlebold"))
		QP.pic_titlebold = atoi(v);
	else if(isequal(n,"pic-titleitalic"))
		QP.pic_titleitalic = atoi(v);
	
	else if(isequal(n,"pic-descsize"))
		QP.pic_descsize = atoi(v);
	else if(isequal(n,"pic-descfont"))
		strcpy(QP.pic_descfont,v);
	else if(isequal(n,"pic-desccolor"))
		strcpy(QP.pic_desccolor,v);
	else if(isequal(n,"pic-descbold"))
		QP.pic_descbold = atoi(v);
	else if(isequal(n,"pic-descitalic"))
		QP.pic_descitalic = atoi(v);

	else if(isequal(n,"footersize"))
		QP.footersize = atoi(v);
	else if(isequal(n,"footerfont"))
		strcpy(QP.footerfont,v);
	else if(isequal(n,"footercolor"))
		strcpy(QP.footercolor,v);
	else if(isequal(n,"footerbold"))
		QP.footerbold = atoi(v);
	else if(isequal(n,"footeritalic"))
		QP.footeritalic = atoi(v);

	else
		return 0;

	return 1;
}

void QP_WriteConfig()
{
	FILE	*f;
	char	date[MAXTEXTLEN];

	f = fopen(QP.configfile,"w");
	if(f == NULL)
	{
		printf("Unable to write config file: %s\n",QP.configfile);
		return;
	}

	/* here we go */
	printf("Writing new config file: %s/%s\n",BaseFilename(QP.rootdir),QP.configfile);
	timet_to_date_short(time(NULL),date);
	fprintf(f,"##############################################################################\n");
	fprintf(f,"## QuickPics %s - Configuration file\n",QP.build);
	fprintf(f,"## Creation time: %s\n",date);
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Look at command-line switches to see how you can override\n");
	fprintf(f,"# Run-time options.\n");
	fprintf(f,"# Use the '-c' switch to create a new config file.\n");
	fprintf(f,"#\n");
	fprintf(f,"# Note: Using the '-c' switch in conjuction with run-time switches creates\n");
	fprintf(f,"#       a config file with the values of the override switches.  Cool!\n");
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Run-time options\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"\n");
	fprintf(f,"# Quiet level (0-normal, 1-small output, 2-no output)\n");
	fprintf(f,"set quiet-level %d\n",QP.quiet_level);
	fprintf(f,"\n");
	fprintf(f,"# Enter descriptions and dates when running QuickPics?\n");
	fprintf(f,"set prompt-for-description %d\n",QP.prompt_for_description);
	fprintf(f,"set prompt-for-date %d\n",QP.prompt_for_date);
	fprintf(f,"\n");
	fprintf(f,"# Prompt to create thumbnails? (always create thumbnails if 0)\n");
	fprintf(f,"set prompt-for-thumbnail-creation %d\n",QP.prompt_for_thumbnail_creation);
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Files\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"\n");
	fprintf(f,"# The filename for each folder's index.html\n");
	fprintf(f,"set index-html \"%s\"\n",QP.index_html);
	fprintf(f,"\n");
	fprintf(f,"# Contains folder name and description, and descriptions of images in folder\n");
	fprintf(f,"set folder-configfile \"%s\"\n",QP.folder_configfile);
	fprintf(f,"\n");
	fprintf(f,"# Thumbnail extension\n");
	fprintf(f,"set thumbnail-identifier \"%s\"\n",QP.thumbnail_identifier);
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Global settings\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"\n");
	fprintf(f,"# Thumbnail size (not necessarily exact.  Can only resize 1/2, 1/4, 1/8)\n");
	fprintf(f,"set thumbnailsize %d\n",QP.thumbnailsize);
	fprintf(f,"\n");
	fprintf(f,"# Height determines thumbnail size.  Use width if original width > max_width\n");
	fprintf(f,"set max-width %d\n",QP.max_width);
	fprintf(f,"\n");
	fprintf(f,"# Quality of thumbnail jpeg compression.  Useful ranges are between 70 and 95.\n");
	fprintf(f,"set quality %d\n",QP.quality);
	fprintf(f,"\n");
	fprintf(f,"# Width of page (table width for toolbar and index)\n");
	fprintf(f,"set page-width %s\n",QP.page_width);
	fprintf(f,"\n");
	fprintf(f,"# Average width of pictures (for \"Prev Next\" toolbar, don't use percentages)\n");
	fprintf(f,"set picture-width %d\n",QP.picture_width);
	fprintf(f,"\n");
	fprintf(f,"# Use \"Prev Next\" thumbnails in picture area?\n");
	fprintf(f,"set prev-next-thumbnails %d\n",QP.prev_next_thumbnails);
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Root index page\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# The root index page is the main entrance page to the gallery.\n");
	fprintf(f,"\n");
	fprintf(f,"# Write toolbar on root page?\n");
	fprintf(f,"set root-write-toolbar \"%d\"\n",QP.root_write_toolbar);
	fprintf(f,"\n");
	fprintf(f,"# HTML Body properties\n");
	fprintf(f,"set root-bgcolor \"%s\"\n",QP.root_bgcolor);
	fprintf(f,"set root-textcolor \"%s\"\n",QP.root_textcolor);
	fprintf(f,"set root-linkcolor \"%s\"\n",QP.root_linkcolor);
	fprintf(f,"set root-vlinkcolor \"%s\"\n",QP.root_vlinkcolor);
	fprintf(f,"set root-alinkcolor \"%s\"\n",QP.root_alinkcolor);
	fprintf(f,"\n");
	fprintf(f,"# HTML Title properties (title of gallery)\n");
	fprintf(f,"set root-titlesize %d\n",QP.root_titlesize);
	fprintf(f,"set root-titlefont \"%s\"\n",QP.root_titlefont);
	fprintf(f,"set root-titlecolor \"%s\"\n",QP.root_titlecolor);
	fprintf(f,"set root-titlebold %d\n",QP.root_titlebold);
	fprintf(f,"set root-titleitalic %d\n",QP.root_titleitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Description properties (description of gallery)\n");
	fprintf(f,"set root-headingsize %d\n",QP.root_headingsize);
	fprintf(f,"set root-headingfont \"%s\"\n",QP.root_headingfont);
	fprintf(f,"set root-headingcolor \"%s\"\n",QP.root_headingcolor);
	fprintf(f,"set root-headingbold %d\n",QP.root_headingbold);
	fprintf(f,"set root-headingitalic %d\n",QP.root_headingitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML All folder properties (# images in # folders)\n");
	fprintf(f,"set root-propertiessize %d\n",QP.root_propertiessize);
	fprintf(f,"set root-propertiesfont \"%s\"\n",QP.root_propertiesfont);
	fprintf(f,"set root-propertiescolor \"%s\"\n",QP.root_propertiescolor);
	fprintf(f,"set root-propertiesbold %d\n",QP.root_propertiesbold);
	fprintf(f,"set root-propertiesitalic %d\n",QP.root_propertiesitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Foldername properties (caption above thumbnail)\n");
	fprintf(f,"set root-foldernamesize %d\n",QP.root_foldernamesize);
	fprintf(f,"set root-foldernamefont \"%s\"\n",QP.root_foldernamefont);
	fprintf(f,"set root-foldernamecolor \"%s\"\n",QP.root_foldernamecolor);
	fprintf(f,"set root-foldernamebold %d\n",QP.root_foldernamebold);
	fprintf(f,"set root-foldernameitalic %d\n",QP.root_foldernameitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Table properties (table of thumbnails)\n");
	fprintf(f,"set root-border %d\n",QP.root_border);
	fprintf(f,"set root-cols %d\n",QP.root_cols);
	fprintf(f,"set root-pictureborder %d\n",QP.root_pictureborder);
	fprintf(f,"\n");
	fprintf(f,"# HTML Thumbnail Description properties (caption below thumbnail)\n");
	fprintf(f,"set root-descsize %d\n",QP.root_descsize);
	fprintf(f,"set root-descfont \"%s\"\n",QP.root_descfont);
	fprintf(f,"set root-desccolor \"%s\"\n",QP.root_desccolor);
	fprintf(f,"set root-descbold %d\n",QP.root_descbold);
	fprintf(f,"set root-descitalic %d\n",QP.root_descitalic);
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Folder index page\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# The folder index pages are located in each folder, and are different from\n");
	fprintf(f,"# from the root index page in that folder index pages display images,\n");
	fprintf(f,"# so they have no foldername caption above the thumbnail.\n");
	fprintf(f,"#\n");
	fprintf(f,"# They are made separate so that their properties can be made distinct.\n");
	fprintf(f,"\n");
	fprintf(f,"# Write toolbar on index pages?\n");
	fprintf(f,"set index-write-toolbar \"%d\"\n",QP.index_write_toolbar);
	fprintf(f,"\n");
	fprintf(f,"# HTML Body properties\n");
	fprintf(f,"set index-bgcolor \"%s\"\n",QP.index_bgcolor);
	fprintf(f,"set index-textcolor \"%s\"\n",QP.index_textcolor);
	fprintf(f,"set index-linkcolor \"%s\"\n",QP.index_linkcolor);
	fprintf(f,"set index-vlinkcolor \"%s\"\n",QP.index_vlinkcolor);
	fprintf(f,"set index-alinkcolor \"%s\"\n",QP.index_alinkcolor);
	fprintf(f,"\n");
	fprintf(f,"# HTML Title properties (name of folder)\n");
	fprintf(f,"set index-titlesize %d\n",QP.index_titlesize);
	fprintf(f,"set index-titlefont \"%s\"\n",QP.index_titlefont);
	fprintf(f,"set index-titlecolor \"%s\"\n",QP.index_titlecolor);
	fprintf(f,"set index-titlebold %d\n",QP.index_titlebold);
	fprintf(f,"set index-titleitalic %d\n",QP.index_titleitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Description properties (description of folder)\n");
	fprintf(f,"set index-headingsize %d\n",QP.index_headingsize);
	fprintf(f,"set index-headingfont \"%s\"\n",QP.index_headingfont);
	fprintf(f,"set index-headingcolor \"%s\"\n",QP.index_headingcolor);
	fprintf(f,"set index-headingbold %d\n",QP.index_headingbold);
	fprintf(f,"set index-headingitalic %d\n",QP.index_headingitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Folder properties (# images in folder)\n");
	fprintf(f,"set index-propertiessize %d\n",QP.index_propertiessize);
	fprintf(f,"set index-propertiesfont \"%s\"\n",QP.index_propertiesfont);
	fprintf(f,"set index-propertiescolor \"%s\"\n",QP.index_propertiescolor);
	fprintf(f,"set index-propertiesbold %d\n",QP.index_propertiesbold);
	fprintf(f,"set index-propertiesitalic %d\n",QP.index_propertiesitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Table properties (table of thumbnails)\n");
	fprintf(f,"set index-border %d\n",QP.index_border);
	fprintf(f,"set index-cols %d\n",QP.index_cols);
	fprintf(f,"set index-pictureborder %d\n",QP.index_pictureborder);
	fprintf(f,"\n");
	fprintf(f,"# HTML Thumbnail Description properties (caption below thumbnail)\n");
	fprintf(f,"set index-descsize %d\n",QP.index_descsize);
	fprintf(f,"set index-descfont \"%s\"\n",QP.index_descfont);
	fprintf(f,"set index-desccolor \"%s\"\n",QP.index_desccolor);
	fprintf(f,"set index-descbold %d\n",QP.index_descbold);
	fprintf(f,"set index-descitalic %d\n",QP.index_descitalic);
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Single Picture page\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# The single picture page displays a single image.\n");
	fprintf(f,"\n");
	fprintf(f,"# Write toolbar on each picture page?\n");
	fprintf(f,"set pic-write-toolbar \"%d\"\n",QP.pic_write_toolbar);
	fprintf(f,"\n");
	fprintf(f,"# HTML Body properties\n");
	fprintf(f,"set pic-bgcolor \"%s\"\n",QP.pic_bgcolor);
	fprintf(f,"set pic-textcolor \"%s\"\n",QP.pic_textcolor);
	fprintf(f,"set pic-linkcolor \"%s\"\n",QP.pic_linkcolor);
	fprintf(f,"set pic-vlinkcolor \"%s\"\n",QP.pic_vlinkcolor);
	fprintf(f,"set pic-alinkcolor \"%s\"\n",QP.pic_alinkcolor);
	fprintf(f,"\n");
	fprintf(f,"# HTML Title properties (name of folder)\n");
	fprintf(f,"set pic-titlesize %d\n",QP.pic_titlesize);
	fprintf(f,"set pic-titlefont \"%s\"\n",QP.pic_titlefont);
	fprintf(f,"set pic-titlecolor \"%s\"\n",QP.pic_titlecolor);
	fprintf(f,"set pic-titlebold %d\n",QP.pic_titlebold);
	fprintf(f,"set pic-titleitalic %d\n",QP.pic_titleitalic);
	fprintf(f,"\n");
	fprintf(f,"# HTML Description properties (caption below image)\n");
	fprintf(f,"set pic-descsize %d\n",QP.pic_descsize);
	fprintf(f,"set pic-descfont \"%s\"\n",QP.pic_descfont);
	fprintf(f,"set pic-desccolor \"%s\"\n",QP.pic_desccolor);
	fprintf(f,"set pic-descbold %d\n",QP.pic_descbold);
	fprintf(f,"set pic-descitalic %d\n",QP.pic_descitalic);
	fprintf(f,"\n");
	fprintf(f,"\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# Footer\n");
	fprintf(f,"##############################################################################\n");
	fprintf(f,"# The footer is appended to the bottom of every page.\n");
	fprintf(f,"\n");
	fprintf(f,"set footersize %d\n",QP.footersize);
	fprintf(f,"set footerfont \"%s\"\n",QP.footerfont);
	fprintf(f,"set footercolor \"%s\"\n",QP.footercolor);
	fprintf(f,"set footerbold %d\n",QP.footerbold);
	fprintf(f,"set footeritalic %d\n",QP.footeritalic);
	fprintf(f,"\n");

	fclose(f);
}
