    /*********************************************************************\
    *  Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu)   *
    *                                                                     *
    *  You may copy or modify this file in any manner you wish, provided  *
    *  that this notice is always included, and that you hold the author  *
    *  harmless for any loss or damage resulting from the installation or *
    *  use of this software.                                              *
    \*********************************************************************/

#include "client_def.h"

extern char **glob();
extern char *env_dir;
extern char *util_abs_path();

#define Y_or_N(y) ((flags & (y)) ?  "Y" : "N")
#define Machine(y) ((flags & (y)) ? "you" : "other")

static print_pro(p)
    char *p;
{
    UBUF *ub;
    char flags;
    unsigned len, len1;
    char *pro1, *pro2;

    ub = client_interact(CC_GET_PRO,0L, strlen(p),p+1, 0,NULLP);
    len = ub->len; len1 = ub->pos;
    pro1 = ub->buf; pro2 = ub->buf+len;

    if(ub->cmd == CC_ERR)
    {
	fprintf(stderr, "ERR: %s\n",ub->buf);
	return(0);

    } else
    {
	fprintf(stderr, "directory mode: ");
	if(len1)
	{
	  flags = *pro2;
	  fprintf(stderr,
		 "(owner: %s)(del: %s)(create: %s)(mkdir: %s)(private: %s)\n",
		 Machine(DIR_OWNER), Y_or_N(DIR_DEL), Y_or_N(DIR_ADD),
		 Y_or_N(DIR_MKDIR), Y_or_N(DIR_PRIV));
	}
	fprintf(stderr, "%s", pro1);
	fprintf(stderr, "\n");
	return(1);
    }
}

main(argc,argv,envp)
    int argc;
    char **argv, **envp;
{
    char *np;
    char **av, *av2[2];

    env_client();
    if(argc == 1)
    {
	print_pro("/");
	puts("/");
    }
    else
    {
        if(!(av = glob(argv[1]))) { av = av2; av2[0] = *argv; av2[1] = 0; }
	np = util_abs_path(*av);
	if(print_pro(np))
	    puts(np);
	else
#ifdef VMS
	{
	    puts(env_dir);
	    client_done();
	    exit(3);
	}
#else
	    puts(env_dir);
#endif /* VMS */
    }
    client_done();
    exit(0);
}
