/*
 * |P|I|X|O| Image cataloging using html and thumb nails
 * Released under GPL http://www.gnu.org/copyleft/gpl.html
 *
 * kishan@hackorama.com www.hackorama.com     2001 MAY
 *
 * Requires OpenIL image library from http://www.openil.org 
 * OpenIL is available for Windows,GNU/Linux,Unix platforms
 *
 * on GNU/Linux or Unix :
 *   g++  main.cpp options.cpp files.cpp image.cpp 
 *        page.cpp boxfit.cpp -lIL -lILU 
 *
 *   make sure libIL.so and libILU.so are in LD_LIBRARY_PATH
 *
 * On windows : 
 *   Create a win32 console appliaction project on MSVC++
 *   uncomment "#define _WINDOWS" in "main.h"
 *   modify the link options to include the OpenIL libs 
 */

#include "main.h"

#include "files.h"

#include "page.h"

#include "options.h"

#include "image.h"


void work( char **list, int count, char *base , Options *opt);

int
main( int argc , char* argv[] )
{
	char *dir = new char[ PATH_MAX+1 ]; 
	Options *opt = new Options( argc, argv , 1 );
	if( opt->helped ){
		opt->cleanUp();
		delete opt;
		delete[] dir; 
		return 0;
	}
	if( opt->dir == NULL )
		strcpy( dir , "." );
	else
		strcpy ( dir, opt->dir );

	Files *pfile = new Files( dir );
	if( pfile->getCount() > 0 )
		work( pfile->getList(), pfile->getCount() , pfile->getBase() , opt );
	else
		fprintf( stderr, "\n\nNo valid image files found at \"%s\"\n", dir );

	pfile->cleanUp();
	delete pfile ;
	opt->cleanUp();
	delete opt;
	delete[] dir; 
#ifndef SILENT

	fprintf( stdout, "\n|P|I|X|O|  |hackorama|dot|com|\n\n");
#endif /* SILENT */

	return 0;
}

void
work(char** list, int count, char* base , Options *opt)
{
	char cright[200];
	strcpy( cright, "<font face=helvetica size=-1>[ Please click on the image");
	strcat( cright, " for the full sized version ]</font>");

	if( ! opt->no_images ){
		Image *img = new Image( list, count );
		img->setSize( opt->tw, opt->th, opt->mw, opt->mh );
		img->setBase( base );
		img->process();
		img->cleanUp();
		delete img ;
	}
	if( ! opt->no_pages ){
		Page  *page = new Page( list, count , opt->size );
		page->setBase( base );
		page->setCopyright( cright );
		page->process();
		page->cleanUp();
		delete page ;
	}
}



syntax highlighted by Code2HTML, v. 0.9