#define MAIN	1

#include "ispell.h"
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>

Local ichar_t	         aqq[100];
Local char hashname[MAXPATHLEN];
Local char *LibDict = NULL;		/* Pointer to name of $(LIBDIR)/dict */

Local char *err;

Public int
main(int argc, char *argv[])

{

    int i;
    char *	p;
    char *	libvar = NULL;	/* stays NULL unless on MS-DOS */
    static char	libdictname[sizeof DEFHASH];

    if(argc < 2)
       {
	fprintf(stderr, "test <slowo>\n");
	exit(1);
       }

#ifdef MSDOS
    /*
    ** Allow to give the dictionary directory through an
    ** environment variable, in addition to the default LIBDIR.
    */
    libvar = getenv (LIBRARYVAR);
    if (libvar != NULL)
	(void) sprintf (hashname, "%s/%s", libvar, DEFHASH);
#endif

    p = getenv ("DICTIONARY");
    if (p != NULL)
	{
	if (last_slash (p) != NULL)
	    (void) strcpy (hashname, p);
			    /*
			    ** If LIBRARYVAR is defined, relative name means
			    ** a file in that directory.
			    */
	else if (libvar != NULL)
	    (void) sprintf (hashname, "%s/%s", libvar, p);
	else
	    (void) sprintf (hashname, "%s/%s", LIBDIR, p);
	(void) strcpy (libdictname, p);
	p = mypath_rindex (p, '.');
	if (p == NULL  ||  strcmp (p, HASHSUFFIX) != 0)
	    (void) strcat (hashname, HASHSUFFIX);
		    /*
		    ** The dot to which p points might belong to a directory
		    ** part of the dictionary pathname, not to its basename.
		    */
	else if (p != NULL && last_slash (p) != NULL)
	    (void) strcat (hashname, HASHSUFFIX);
	LibDict = last_slash (libdictname);
	if (LibDict != NULL)
	    LibDict++;
	else
	    LibDict = libdictname;
	p = mypath_rindex (LibDict, '.');
	if (p != NULL)
	    *p = '\0';
	}
    else if (libvar == NULL)	/* libvar might be non-NULL only on MS-DOS */
	(void) sprintf (hashname, "%s/%s", LIBDIR, DEFHASH);

    printf("%s\n", hashname);
    if ((err = linit(hashname)) != NULL)
       {
	fprintf(stderr, "%s\n", err);
	exit (1);
       }

    if (LibDict == NULL)
	{
	(void) strcpy (libdictname, DEFHASH);
	LibDict = libdictname;
	p = rindex (libdictname, '.');
	if (p != NULL  &&  strcmp (p, HASHSUFFIX) == 0)
	    *p = '\0';	/* Don't want ext. in LibDict */
	}
    treeinit (NULL, LibDict);
    for(i = 0; i < strlen(argv[1]); i++)
       {
	aqq[i] = (unsigned char)argv[1][i];
        printf(" %d-%c", iswordch(aqq[i]), aqq[i]);
       }
    aqq[i] = '\0';
    printf("\n");
    fprintf(stderr, "%s=%d\n", argv[1], good(aqq, 0, 0, 0, 0));
    exit(0);
}

