#include <stdio.h>
#include <string.h>
#ifdef MSDOS
#include <io.h>
#endif
#include "global.h"
#include "config.h"
#include "files.h"

#ifdef TRANSLATE
extern char *skipwhite __ARGS((char *cp));
extern char *skipnonwhite __ARGS((char *cp));
char *translate __ARGS((register char *searchfor, int *didwe));


char *
translate (searchfor, didwe)
register char *searchfor;
int *didwe;
{
FILE *fp;
char buf[256];
char *retval, *trans;

	retval = strdup (searchfor);
	*didwe = 0;
	sprintf (buf, "%s/translat", Spool);
	if ((fp = fopen (buf, "rt")) == NULL)
		return (retval);
	while (!feof(fp))	{
		fgets(buf, 256, fp);
		if (feof(fp))
			continue;
		rip (buf);
		if ((*buf == '#')  || !*buf)
			continue;	/* skip comment lines */
		trans = skipwhite(buf);
		if (trans != buf)	/* can't start with white space */
			continue;
		trans = skipnonwhite(buf);
		if (!*trans)	/* invalid line - no translate name */
			continue;
		*trans++ = 0;
		trans = skipwhite(trans);
		if (strnicmp (searchfor, buf, strlen(buf)))
			continue;	/* no match */
		free (retval);
		retval = strdup (trans);
		*didwe = 1;
		break;
	}
	fclose (fp);
	return (retval);
}


#endif /* TRANSLATE */
