
/* DUpl v1.2 - (c) S.Gillibrand 1996-7 - Digital Design */
/* Compiled/Coded With DICE */

/*                                                                     ---- */
/* 1.0 - Not released - Bugged like hell %)                                 */
/* 1.1 - Initial release.                                                   */
/* 1.2 - Reworked & modified - Faster, cleaner - cooler #)                  */
/*                                                                     ---- */


#include <stdio.h>
#include <string.h>

main(ac, av)
char *av[];
{

	/* Define variables */

	char buf[60], path[128]="";
	short i, ii;
	int areas, len;

	/* Plug! */

	puts("\n[1mDUpl v1.2 - (c) S.Gillibrand 1996-7 - Digital Design Production - Part Of Upl![0m");
	puts("Coded In Pure C - Not Lame AREXX Compiled!\n");

	/* Check for parameters */

	if (ac != 3) {
		puts("Usage: \n");
		puts("	DUpl <File.Cfg Path> <Dupe File Destination Path>\n");
		exit(1);
	}

	/* Open main file pointers */

	FILE *fp=fopen(av[1],"r");
	FILE *dupl=fopen(av[2],"w");
	FILE *fpbbs;

	/* Check i/o */

	if (fp==NULL) {
		printf("\n[0m*** Error: Failed To Open [1m\"%s\"[0m For Input!\n\n",av[1]);
		exit(1);
	}
	if (dupl==NULL) {
		printf("\n[0m*** Error: Failed To Open [1m\"%s\"[0m For Output!\n\n",av[2]);
		exit(1);
	}

	/* Parse mumber of areas from file.cfg */

	for(i=0;i<3;i++)
		fgets(buf, sizeof(buf), fp);
	fgets(buf, sizeof(buf),fp);
	areas=atoi(buf);
	printf("%d Areas Found...\n\n", areas);

	/* main loop - Parse file area path and open files.bbs for that path */

	for(i=1;i<=areas;i++) {
		fgets(buf, sizeof(buf),fp);
		printf("[A[2KCompiling Area %d, (%d%% done) - [1m%s[0m", i, ((i*100)/areas), buf);
		fgets(buf, sizeof(buf),fp);
		strncat(path, buf, (strlen(buf)-1));
		strcat(path, "files.bbs");
		fpbbs=fopen(path,"r");
		if (fpbbs!=NULL) {
			fgets(buf, 128,fpbbs);

			/* Parse filename from files.bbs with no trailing spaces */

			while (!feof(fpbbs)) {
				if (buf[0] != '\\')
				{
					len=strcspn(buf, " ");
					buf[len]='\0';
					fprintf(dupl, "%s\n",buf);
				}
				fgets(buf, 128, fpbbs);
			}
			fclose(fpbbs);


		}
		else puts("[0mSkipping, Error With [1m\"Files.BBS\"[0m...\n\n");

		/* Skip uneeded junk from file.cfg */

		for (ii=1 ; ii<=6; ii++)
			fgets(buf, sizeof(buf) ,fp);

		strcpy(path,"");
	}

	fclose(fp);
	fclose(dupl);

	puts("\n[0m[4mOperation Complete - Thanx For Your Cooperation :-)\n[0m");

	exit(0);

}

/* Eof. */
