/* logcall.c -- log callers from DLG Pro to an ASCII file logs:call.log.
 *    USAGE: logcall [-h] [-?] [-flogfilename] name port date comments...
 *    EXAMPLE: logcall -fLogs:Call.Log "Vitas P" TL0 "3-Dec-92 05:34:26" "User logged in"
 *    COMPILE WITH: dcc [-DDEBUG] -o logcall logcall.c
 *    $Id: logcall.c,v 1.1 92/12/03 06:23:08 vitas Exp Locker: vitas $
 *    Copyleft 1992 Vitas Povilaitis
 *    Source and binary is freely redistributable.
 */

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

static char *version = { "$VER: logcall 1.1 (03.12.1992) Copyleft 1992 Vitas Povilaitis $Revision: 1.1 $ $Date: 92/12/03 06:23:08 $" };

main(int argc, char *argv[])
{
	FILE *fd;
	char *filename = "Logs:Call.Log";
	int argindex = 1;

	if (argc == 1)
		return (0);

	if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-?")) {
		printf("USAGE: %s [-h] [-?] [-flogfilename] name port date comments...\n", argv[0]);
		return (0);
	}

	if (!strncmp(argv[1], "-f", 2)) {
		filename = &argv[1][2];
		while (*filename == ' ' && *filename == '\t')
			filename++;
		argindex = 2;

		if (argc == 2)
			return (0);
	}
	
	if ((fd = fopen(filename, "a")) == NULL && (fd = fopen(filename, "w")) == NULL) {
			fprintf(stderr, "%s: can't open %s for output\n", argv[0], filename);
			return (10);
		}

	while (argindex < argc) {
		char *p;
		p = argv[argindex];
		while (*p)
			fputc(*p++, fd);
		argindex++;
		if (argindex < argc)
			fputc('\t', fd);
	}
	fputc('\n', fd);

	fclose(fd);
	return (0);
}
