/*
   <p>Test harness for the diracc module.</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include <stdio.h>
#include <dirent.h>
#include "environ.h"

#ifdef LINUX
#include <stdlib.h>
#endif

main(int argc, char **argv)
{
    DIRPATH    *dp;
    char       name[NAMELTH];
    char       dirname[NAMELTH];
    int        enttype;

    setprog(argv[0]);
    
    printf("\nDirectory: ");
    scanf("%s",dirname);
    printf("\n");

    dp = diropen(dirname);
    if (dp == NULL) 
    {
        printf("Can't open directory %s\n",dirname);
        exit(1);
    }

    while ((enttype = dirread(dp,name)) != DIR_EOF)
    {
        printf("Found [%s] - ",name);
        switch (enttype)
        {
            case DIR_NULL:    printf("null entry\n");
                            break;
            case DIR_SUBDIR: printf("directory\n");
                            break;
            case DIR_FILE:    printf("file\n");
                            break;
            default:        printf("bad reply(%d)\n",enttype);
        }
    }

    if(dirclose(dp) == EOF)
        printf("Can't close directory\n");

    printf("Test finished\n");

    return(0);
}
