STATUS xfsetdirs(char *dir, char *frompath, char *intopath) { auto i2 dirflag; auto char *s; char *locbuf; STATUS status; locbuf = XF_REQMEM(MAX_LOC + 1, FALSE); if (dir == NULL || *dir == EOS) { /* Default to current directory. */ status = LOgt(locbuf, &Xf_dir); if(status != OK) { #ifdef UNIX status = LOfakepwd(locbuf, &Xf_dir); #endif if(status != OK) { IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0); return(FAIL); } } dir = NULL; } else { STlcopy(dir, locbuf, MAX_LOC); if (LOfroms(PATH, locbuf, &Xf_dir) != OK) { IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir); return (FAIL); } if (!LOisfull(&Xf_dir)) { auto LOCATION xloc; char xbuf[MAX_LOC + 1]; /* ** path spec. is a relative specification -- we must expand it ** to a full pathname. */ LOcopy(&Xf_dir, xbuf, &xloc); status = LOgt(locbuf, &Xf_dir); if(status != OK) { IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0); return(FAIL); } LOaddpath(&Xf_dir, &xloc, &Xf_dir); } /* LOisdir and LOexist are archaic and should be replaced by LOinfo. */ LOisdir(&Xf_dir, &dirflag); if (dirflag != ISDIR || LOexist(&Xf_dir) != OK) { IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir); return (FAIL); } } LOtos(&Xf_dir, &s); /* the COPY FROM path doesn't have to exist. */ if (frompath != NULL && *frompath != EOS) Xf_from_path = saveloc(frompath); /* the COPY INTO path doesn't have to exist. */ if (intopath != NULL && *intopath != EOS) Xf_into_path = saveloc(intopath); IIUGmsg(ERget(S_XF0064_Unload_Directory_is), FALSE, 1, (PTR)(Xf_into_path == NULL ? s : Xf_into_path)); IIUGmsg(ERget(S_XF0065_Reload_Directory_is), FALSE, 1, (PTR)(Xf_from_path == NULL ? s : Xf_from_path)); return (OK); }
/* ** pp_open() -- open a file for reading. The use of the include path list ** is used to resolve files that may not be in the current default ** location. */ static STATUS pp_open( FILE **input, char *filepath, bool def_dir ) { LOCATION loc; LOCATION loctest; char buf[ MAX_LOC + 1 ]; char bufdev[ MAX_LOC + 1 ]; char bufpath[ MAX_LOC + 1 ]; char bufsave[ MAX_LOC + 1 ]; char buftest[ MAX_LOC + 1 ]; STATUS sts; IPATH *ipath; bool found = FALSE; bool file_has_path, dir_has_path; /* ** Check to see if we should first look in the default directory, ** this directory will be the first entry in the Include list. */ if (def_dir == TRUE) ipath = &ihead; else ipath = ihead.next; /* Convert the filename to open to a LOCATION */ STcopy(filepath, bufsave); if (OK != (sts = LOfroms( PATH & FILENAME, bufsave, &loc )) ) return (sts); /* ** Search for the file in each directory in the include list. ** No expansion possible if there are no include directories. */ while (ipath != NULL && found == FALSE) { /* Initialize loctest so LOaddpath will work */ LOcopy(&loc, buftest, &loctest); /* Is there a device (VMS) and/or a path for the directory? */ STcopy(ERx(""), bufdev); STcopy(ERx(""), bufpath); sts = LOdetail(ipath->pathloc, bufdev, bufpath, buf, buf, buf); if (sts != OK) break; if (STlength(bufdev) + STlength(bufpath) > 0 ) dir_has_path = TRUE; else dir_has_path = FALSE; /* Don't mess with the filename if it was an absolute path */ /* or if this include directory path is empty */ if (LOisfull(&loctest) == FALSE && dir_has_path == TRUE ) { /* Is there a path for the file? */ sts = LOdetail(&loctest, buf, bufpath, buf, buf, buf); if (sts != OK) break; file_has_path = (STlength(bufpath) > 0 ? TRUE : FALSE); /* ** If there's no path component then copy in the ** next prefix, else append it. ** If LOaddpath succeeds, the result will also have ** the original filename. If it fails then drop out. ** LOaddpath can fail if loctest is an absolute path, ** but we already checked for that. */ if ( file_has_path ) { sts =LOaddpath(ipath->pathloc, &loc, &loctest); } else { LOcopy(ipath->pathloc, buftest, &loctest); /* ** If we can't set the filename from loc, ** then something is wrong, and will continue ** to be wrong. Get out of the loop. */ sts = LOstfile(&loc, &loctest); } } /* ** If all of the filename manipulations have succeeded ** then check for the file's existance. */ if (sts == OK && LOexist(&loctest) == OK) { found = TRUE; LOcopy(&loctest, buf, &loc); } /* Prepare for the next path in the include list */ ipath = ipath->next; } /* ** If the file existed then return back the result from the open, ** otherwise all of our efforts were a bust, return back a failure. */ if (found) return ( SIfopen(&loc, ERx("r"), SI_TXT, MAX_LINE, input) ); else return (FAIL); }