home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ssdef.h>
- #include <dirent.h>
-
- static lowercopy();
- char *unix2vms();
- char *malloc();
- static int debug = 0;
- int all_versions = 0;
-
- DIR *opendir(filename)
- char *filename;
- {
- int status;
- DIR *dirp;
- char *p, q[256];
- if (debug) fprintf(stderr,"opendir called %s\n",filename);
- dirp = (DIR *)malloc(sizeof(DIR));
- dirp->fab = (struct FAB *)malloc(sizeof(struct FAB));
- dirp->nam = (struct NAM *)malloc(sizeof(struct NAM));
- dirp->buffer = malloc(NAM$C_MAXRSS);
- dirp->output = malloc(NAM$C_MAXRSS);
- dirp->exp_output = malloc(NAM$C_MAXRSS);
- dirp->ddirent = (struct dirent *)malloc(sizeof(struct dirent));
- bzero(dirp->fab,sizeof(struct FAB));
- bzero(dirp->nam,sizeof(struct NAM));
- bzero(dirp->ddirent,sizeof(struct dirent));
- strcpy(q, filename);
- if (q[strlen(q)-1] != '/') strcat(q,"/");
- strcpy(dirp->buffer,unix2vms(q));
- if (all_versions) strcat(dirp->buffer,"*.*;*");
- else strcat(dirp->buffer,"*.*");
- if (debug) fprintf(stderr,"dir = %s\n",dirp->buffer);
- dirp->fab->fab$b_bid = FAB$C_BID;
- dirp->fab->fab$b_bln = FAB$C_BLN;
- dirp->fab->fab$l_fna = dirp->buffer;
- dirp->fab->fab$b_fns = strlen(dirp->buffer);
- dirp->fab->fab$l_nam = dirp->nam;
- dirp->nam->nam$b_bid = NAM$C_BID;
- dirp->nam->nam$b_bln = NAM$C_BLN;
- dirp->nam->nam$l_rsa = dirp->output;
- dirp->nam->nam$b_rss = NAM$C_MAXRSS;
- dirp->nam->nam$l_esa = dirp->exp_output;
- dirp->nam->nam$b_ess = NAM$C_MAXRSS;
- status = sys$parse(dirp->fab,0,0);
- if (status != RMS$_NORMAL) {
- if (debug) fprintf(stderr," failed\n");
- return(NULL);
- }
- if (debug) fprintf(stderr,"succeeded\n");
- return(dirp);
- }
-
- struct dirent *readdir(dirp)
- DIR *dirp;
- {
- int status;
- if (debug) fprintf(stderr,"readdir called\n");
- status = sys$search(dirp->fab,0,0);
- if (status != RMS$_NORMAL) {
- if (debug) fprintf(stderr," failed\n");
- return(NULL);
- }
- dirp->nam->nam$l_rsa[dirp->nam->nam$b_rsl] = '\0';
- dirp->ddirent->d_namlen = dirp->nam->nam$l_ver - dirp->nam->nam$l_name;
- bzero(dirp->ddirent->d_name,257);
- lowercopy(dirp->nam->nam$l_name,dirp->ddirent->d_name,dirp->ddirent->d_namlen);
- dirp->dd_loc++;
- dirp->ddirent->d_ino = 1234; /*shouldn't be zero!*/
- if (debug) fprintf(stderr," returns %s\n",dirp->ddirent->d_name);
- return(dirp->ddirent);
- }
-
- void seekdir(dirp, loc)
- DIR *dirp;
- long loc;
- {
- int i;
- if (debug) fprintf(stderr,"seekdir called\n");
- sys$close(dirp->fab);
- sys$parse(dirp->fab,0,0);
- for (i=0; i<loc; i++) sys$search(dirp->fab);
- dirp->dd_loc = loc;
- }
-
- long telldir(dirp)
- DIR *dirp;
- {
- if (debug) fprintf(stderr,"telldir called\n");
- return(dirp->dd_loc);
- }
-
- closedir(dirp)
- DIR *dirp;
- {
- if (debug) fprintf(stderr,"closedir called\n");
- sys$close(dirp->fab);
- free(dirp->fab);
- free(dirp->nam);
- free(dirp->buffer);
- free(dirp->output);
- free(dirp->exp_output);
- free(dirp->ddirent);
- free(dirp);
- }
-
- /*chdir works but doesn't change "PATH" variable! so we have to catch it*/
- static char *current_path = NULL;
-
- int si_chdir(path)
- char *path;
- {
- char *malloc();
- int i;
- if (current_path == NULL) current_path = malloc(128);
- i = chdir(path);
- if (i == 0) {
- strcpy(current_path,path);
- if (path[strlen(path)-1] != '/') strcat(current_path,"/");
- }
- return(i);
- }
-
- char *si_getenv(name)
- char *name;
- {
- static char buffer[128];
- char tmp[128], *p, *q, *r, *strchr(), *getenv();
- if (strcmp(name,"PATH") == 0) {
- if (current_path == NULL) return(getenv("PATH"));
- return(unix2vms(current_path));
- }
- if (strcmp(name,"HOME") != 0) return(getenv(name));
- strcpy(tmp,getenv(name));
- p = tmp;
- q = buffer;
- r = strchr(tmp,':');
- if (r == NULL) {
- strcpy(buffer,tmp);
- return(buffer);
- }
- *r = '\0';
- *buffer = '/';
- strcpy(buffer+1,p);
- strcat(buffer,"/");
- r++;
- r++;
- p = r;
- q = r;
- while ( (r = strchr(p,'.')) != NULL) {
- *r = '/';
- p = r+1;
- }
- r = strchr(p,']');
- *r = '\0';
- strcat(buffer,q);
- return(buffer);
- }
-
- static lowercopy(src, dst, length)
- char *src, *dst;
- int length;
- {
- int i;
- for (i=0;i<length;i++) *dst++ = tolower(*src++);
- }
-
-
-