|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 3860 (0xf14)
Types: TextFile
Names: »unixext.c«
└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
└─⟦this⟧ »./DVIware/lpr-viewers/crudetype/unixext.c«
└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
└─⟦af5ba6c8e⟧ »unix3.0/DVIWARE.tar.Z«
└─⟦ca79c7339⟧
└─⟦this⟧ »DVIware/lpr-viewers/crudetype/unixext.c«
/* External procedures for unix crudetype */
/* Written by RMD (nearly all copied from H.Trickey's dvityext.c ) */
/* Ought to be rewritten in cleaner form... */
#include <stdio.h>
#include "site.h"
/*Only needed to define TEXFONTS */
#ifdef SYSV
#include <string.h>
extern int sprintf();
#else
#include <strings.h>
extern char *sprintf();
#endif
#define TRUE 1
#define FALSE 0
char *fontpath;
extern char *getenv();
/*
* setpaths is called to set up the pointer fontpath
* as follows: if the user's environment has a value for TEXFONTS
* then use it; otherwise, use defaultfontpath.
*/
setpaths()
{
register char *envpath;
if ((envpath = getenv("TEXFONTS")) != NULL)
fontpath = envpath;
else
fontpath = TEXFONTS;
}
#define namelength 100 /* should agree with dvitype.ch */
extern char curname[],realnameoffile[]; /* these have size namelength */
/*
* testaccess(amode,filepath)
*
* Test whether or not the file whose name is in the global curname
* can be opened for reading (if mode=READACCESS)
* or writing (if mode=WRITEACCESS).
*
* The filepath argument is one of the ...FILEPATH constants defined below.
* If the filename given in curname does not begin with '/', we try
* prepending all the ':'-separated areanames in the appropriate path to the
* filename until access can be made, if it ever can.
*
* The realnameoffile global array will contain the name that yielded an
* access success.
*/
#define READACCESS 4
#define WRITEACCESS 2
#define NOFILEPATH 0
#define FONTFILEPATH 3
testaccess(amode,filepath)
int amode,filepath;
{
register boolean ok;
register char *p;
char *curpathplace;
int f;
switch(filepath) {
case NOFILEPATH: curpathplace = NULL; break;
case FONTFILEPATH: curpathplace = fontpath; break;
}
if (curname[0]=='/') /* file name has absolute path */
curpathplace = NULL;
do {
packrealnameoffile(&curpathplace);
if (amode==READACCESS)
/* use system call "access" to see if we could read it */
if (access(realnameoffile,READACCESS)==0) ok = TRUE;
else ok = FALSE;
else {
/* WRITEACCESS: use creat to see if we could create it, but close
the file again if we're OK, to let pc open it for real */
f = creat(realnameoffile,0666);
ok = (f >= 0);
if (ok)
(void) close(f);
}
} while (!ok && curpathplace != NULL);
if (ok) { /* pad realnameoffile with blanks, as Pascal wants */
for (p = realnameoffile; *p != '\0'; p++)
/* nothing: find end of string */ ;
while (p < &(realnameoffile[namelength]))
*p++ = ' ';
}
return (ok);
}
/*
* packrealnameoffile(cpp) makes realnameoffile contain the directory at *cpp,
* followed by '/', followed by the characters in curname up until the
* first blank there, and finally a '\0'. The cpp pointer is left pointing
* at the next directory in the path.
* But: if *cpp == NULL, then we are supposed to use curname as is.
*/
static packrealnameoffile(cpp)
char **cpp;
{
register char *p,*realname;
realname = realnameoffile;
if ((p = *cpp)!=NULL) {
while ((*p != ':') && (*p != '\0')) {
*realname++ = *p++;
if (realname == &(realnameoffile[namelength-1]))
break;
}
if (*p == '\0') *cpp = NULL; /* at end of path now */
else *cpp = p+1; /* else get past ':' */
*realname++ = '/'; /* separate the area from the name to follow */
}
/* now append curname to realname... */
/* There was a very peculiar bug here, I tried to fix it. (RMD).
Originally this said "p = curname+1 ;" this cut off the
first character of the name */
p = curname ;
while (*p != ' ') {
if (realname >= &(realnameoffile[namelength-1])) {
(void) fprintf(stderr,"! Full file name is too long\n");
break;
}
*realname++ = *p++;
}
*realname = '\0';
}