/*
* BANNER
* Copyright (c) 1989 by Grant Robert Wagner. All rights reserved.
*
* Compile using QuickC v2.00 - qcl /Ox /W3
*/
#include <io.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#define NUL '\0'
#define COPYRIGHT cputs("\r\nBANNER v1.0\r\nCopyright (c) 1989 by Grant Robert Wagner. All rights reserved.");

void main(int argc,char *argv[]),
	addbanner(char *path,char *input,struct find_t *file),
	document(void);

void main(
	int argc,
	char *argv[]
)
{
	char pattern[_MAX_PATH],zippath[_MAX_PATH],drive[_MAX_DRIVE],
		f_name[_MAX_FNAME],ext[_MAX_EXT];
	char *error[] = {
		"BANNER done processing.",
		"*.ZIP file(s) not found. Path or file(s) do not exist.",
		"Banner file not found. Path or file does not exist.",
		"Not enough parameters!"
	};
	struct find_t zip;
								
	COPYRIGHT;
	if (argc > 2) {
		_splitpath(argv[1],drive,zippath,f_name,ext);
		_makepath(pattern,drive,zippath,f_name,"ZIP");
		if (!access(argv[2],0)) {
			if (!_dos_findfirst(pattern,_A_NORMAL,&zip)) {
				do {
					addbanner(zippath,argv[2],&zip);
				} while (!_dos_findnext(&zip));
			errno = 0;
			}
			else
				errno = 1;
		}
		else
			errno = 2;
	}
	else
		errno = 3;
	cputs("\r\r\n\n");
	cputs(error[errno]);
	cputs("\r\r\n\n");
	document();
}

void addbanner(
	char *path,
	char *input,
	struct find_t *file
)
{
	char command[_MAX_PATH];

	strcpy(command,"pkzip -z -q ");
	strcat(command,path);
	strcat(command,file->name);
	strcat(command," <");
	strcat(command,input);
	system(command);
}

void document(
	void
)
{
	cputs("Command format: BANNER d:\\path\\zipfiles[.ZIP] d:\\path\\banner.ext\r\r\n\n");
	cputs("Description: adds a comment contained in d:\\path\\banner.ext to\r\n");
	cputs("             all ZIP files specified by d:\\path\\filename[.ZIP]\r\n");
	cputs("             (wildcard characters `*' and `?' are valid)\r\r\n\n");
	cputs("\t*** NOTE: PKZIP v1.01 MUST BE ON YOUR CURRENT PATH ***\r\r\n\n");
	cputs("\tIf you use find BANNER useful please send $10 to:\r\n");
	cputs("\t\tGrant Robert Wagner\r\n\t\t253 -14 Ferris Lane\r\n");
	cputs("\t\tRegina, Saskatchewan, Canada, S4S 6X7\r\r\n\n");
	cputs("\tBugs can be reported on Negative Zone BBS * 306-586-3520\r\n");
	cputs("\t300/1200/2400 bps - 8 data bits - No parity - 1 stop bit\r\n");
}
