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

#include "dos_lib.h"
#include "lbio_lib.h"
#include "str_lib.h"

#include "defines.h"
#include "cus.h"
#include "rev.h"


void giveversioninfo(char *progname)
{
	strupr(progname);
	fprintf(stderr, "%s%s Release %s.%02d (%s) -- batch SMTP mail%s\n"
					"%s(c) Copyright 1992 Ralf S. Engelschall, All Rights Reserved.\n"
					"%s(c) Copyright 1992 Cyvaned Systems, All Rights Reserved.\n",
					ANSICTL_BOLD_ON, progname, Version, Revision, Date, ANSICTL_NORMAL_DISPLAY,
					progname, progname );
	strlwr(progname);
	return;
}


void giveusage(char *progname)
{
	fprintf(stderr, "Usage: %s [-s batchsize] [-c] [-v] [-?] system\n", progname);
	return;
}


char *getfield(char *file, char *field, char *target)
{
	FILE *fp = NULL;
	char buffer[RANGE_8BIT];
	char *bufptr;
	char *targetptr;
	char *rc;

	if ((fp = fopen(file, "r")) != NULL) {
		while ((fgets(buffer, RANGE_8BIT, fp)) != NULL) {
			bufptr = buffer;
			if ((strnicmp(bufptr, field, strlen(field))) == 0) {
				bufptr += strlen(field);
				if ((*bufptr == SP) || (*bufptr == HT)) {
					while ((*bufptr == SP) || (*bufptr == HT))
						bufptr++;
					if ((*bufptr != NL) && (*bufptr != NUL)) {
						targetptr = target;
						while ((*bufptr != NL) && (*bufptr != NUL) && (*bufptr != SP) &&
							   (*bufptr != HT) && (*bufptr != '#'))
							*targetptr++ = *bufptr++;
						*targetptr = NUL;
						CU(target);
					}
				}
			}
		}
	}
	rc = NULL;

	CUS:
	if (fp) fclose(fp);
	return rc;
}

