From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  4-AUG-1989 02:54
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Re: Anyone have a UNIX-Like CD for VMS

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Thu,  3 AUG 89 23:18:19 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Thu, 3 Aug 89 22:48:07 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.37)
	id AA21512; Thu, 3 Aug 89 22:36:24 -0700
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 4 Aug 89 01:13:58 GMT
From: oliveb!pyramid!leadsv!laic!nova!darin@apple.com  (Darin Johnson)
Organization: Lockheed AI Center, Menlo Park
Subject: Re: Anyone have a UNIX-Like CD for VMS
Message-Id: <649@laic.UUCP>
References: <8907242012.AA00554@ucbvax.Berkeley.EDU>, <12874@megaron.arizona.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <12874@megaron.arizona.edu> robert@arizona.edu (Robert J. Drabek) writes:
>In article <8907242012.AA00554@ucbvax.Berkeley.EDU>, TNIELAND@FALCON.BERKELEY.EDU (Ted Nieland) writes:
>> Does anyone have a UNIX-Like CD for VMS?
>The following is very Unix compatible.  The only caution is (like most
>of these programs) it doesn't verify that the directory exists...

This one does check for existence, and is pretty small.  Uses an undocumented
feature (at least not when I wrote it) of chdir() in VAXC.

cd -	goes to current directory
cd ..	goes up one directory
cd /	goes to top level of disk.
cd ../foo/bar

Can't move to other disks.  Also, can use standard VMS directory names.
I don't remember who the original author was, but I did some hacking on
it.  Just do "cd :== $foo:[bar]cd" and it should work.

==============================================================================
#define NULL 0
#define MAXSTRING 132

#include <ctype.h>
#include <rms.h>
#include <stdio.h>
#include <stsdef.h>
#include <ssdef.h>
#include <descrip.h>

struct dsc$descriptor_s desc,desc1;

main (argc,argv)
    int argc;
    char **argv;

{   char curdir[MAXSTRING],testdir[MAXSTRING],todir[MAXSTRING];
    char *p1,*dirspec,*strpos();
    int i;

    if (argc <= 1) {
	getlogical("SYS$LOGIN",todir);
	if (setdef(todir)) {
	    invalid_dirspec(todir);
	    return(1);
	}
    }
    else {
	p1 = argv[1];
	if (strchr(p1,'[')
	 || strpos(p1,"..")
	 || strchr(p1,'/')) {
	    if (setdef(p1)) {
		invalid_dirspec(p1);
		return(1);
	    }
	}
	else if (getlogical(p1,todir)) {
	    if (i=setdef(p1)) {
		invalid_dirspec(p1);
		return(1);
	    }
	}
	else {
	    dirspec = strrchr(p1,':');
	    if (!dirspec) {
		*todir = '\0';
		dirspec = p1;
	    }
	    else {
		i = dirspec-p1+1;
		strncpy(todir,p1,i);
		todir[i]='\0';
		dirspec++;
	    }
	    strcat(todir,"[");
	    if (*dirspec != '.'
	     && *dirspec != '-'
	     && dirspec == p1) strcat(todir,".");
	    strcat(todir,dirspec);
	    strcat(todir,"]");
	    if (setdef(todir)) {
		invalid_dirspec(todir);
		return(1);
	    }
	}
    }
}

int setdef(dir)
char *dir;
{
  int i;
  char wd1[MAXSTRING], wd2[MAXSTRING];
  getwd(wd1);
  chdir(dir, 1);
    /* check to see if we moved or not */
  getwd(wd2);
  if (strcmp(wd1, wd2)) return 0;
  return 1;
}

getlogical(logical_name,value)
char *logical_name,*value;
{   int valuelen;
    char cap_name[MAXSTRING],*cap_indx,*logical_indx;

    logical_indx = logical_name;
    cap_indx = cap_name;
    while (*cap_indx++ = toupper(*logical_indx++));
    setdesc(&desc,cap_name,strlen(cap_name));
    setdesc(&desc1,value,MAXSTRING-1);
    valuelen = 0;
    lib$sys_trnlog(&desc,&valuelen,&desc1,0,0,0);
    value[valuelen] = '\0';
    if (!strcmp(cap_name,value)) {
	return(0);
    }
    return(1);

}
getsymbol(symbol_name,value)
char *symbol_name,*value;
{   int valuelen,status;

    setdesc(&desc,symbol_name,strlen(symbol_name));
    setdesc(&desc1,value,MAXSTRING-1);
    valuelen = 0;
    status = lib$get_symbol(&desc,&desc1,&valuelen,0);
    if (status & STS$M_SUCCESS) {
	value[valuelen] = '\0';
	return(1);
    }
    else {
	return(0);
    }
}
getwd(pwd)
char *pwd;
{   int pwdlen;

    setdesc(&desc,pwd,MAXSTRING-1);
    pwdlen = 0;
    sys$setddir(0,&pwdlen,&desc);
    pwd[pwdlen] = '\0';
}
invalid_dirspec(dirspec)
char *dirspec;
{
    fprintf(stderr,"invalid directory %s\n",dirspec);
}
setdesc(descr,str,strlen)
struct dsc$descriptor_s *descr;
char *str;
int strlen;
{
    descr->dsc$w_length = strlen;
    descr->dsc$a_pointer = str;
    descr->dsc$b_class = DSC$K_CLASS_S;	/* String desc class */
    descr->dsc$b_dtype = DSC$K_DTYPE_T;	/* Ascii string type */
}
setsymbol(symbol_name,value)
char *symbol_name,*value;
{   int valuelen;

    setdesc(&desc,symbol_name,strlen(symbol_name));
    setdesc(&desc1,value,strlen(value));
    lib$set_symbol(&desc,&desc1,0);
}

char *strpos(str,searchstr)
char *str,*searchstr;
{   char *matchc,c,*matchstr;

    matchc = searchstr;
    c = *matchc++;
    while (c) {
	if (!*str) {
	    return(NULL);
	}
	else {
	    matchstr = str++;
	    while (c == *matchstr && *matchstr++) {
		c = *matchc++;
	    }
	    if (!c) {
	 	return(str - 1);
	    }
	    matchc = searchstr;
	    c = *matchc++;
	}
    }
    return(NULL);
}
============================================================================
Darin Johnson (leadsv!laic!darin@pyramid.pyramid.com)
	We now return you to your regularly scheduled program.

