diff --git a/bind.c b/bind.c index 62f20b5..d5bd86f 100644 --- a/bind.c +++ b/bind.c @@ -18,45 +18,14 @@ #include "ebind.h" #include "exec.h" #include "file.h" -#include "fileio.h" +#include "flook.h" #include "input.h" #include "line.h" #include "names.h" #include "window.h" -/* possible names and paths of help files under different OSs */ -static const char *pathname[] = { -#if MSDOS - "emacs.rc", - "emacs.hlp", - "\\sys\\public\\", - "\\usr\\bin\\", - "\\bin\\", - "\\", - "" -#endif - -#if V7 | BSD | USG - ".emacsrc", - "emacs.hlp", -#if PKCODE - "/usr/global/lib/", "/usr/local/bin/", "/usr/local/lib/", -#endif - "/usr/local/", "/usr/lib/", "" -#endif - -#if VMS -{ - "emacs.rc", "emacs.hlp", "", -#if PKCODE - "sys$login:", "emacs_dir:", -#endif - "sys$sysdevice:[vmstools]" -#endif -}; - -#define PATHNAME_SIZE (sizeof pathname / sizeof pathname[ 0]) +static char *getfname( fn_t) ; int help(int f, int n) { /* give me some help!!!! @@ -508,90 +477,6 @@ int startup(char *sfname) return dofile(fname); } -/* - * Look up the existance of a file along the normal or PATH - * environment variable. Look first in the HOME directory if - * asked and possible - * - * char *fname; base file name to search for - * int hflag; Look in the HOME environment variable first? - */ -char *flook( const char *fname, int hflag) -{ - char *home; /* path to home directory */ - char *path; /* environmental PATH variable */ - char *sp; /* pointer into path spec */ - int i; /* index */ - static char fspec[NSTRING]; /* full path spec to search */ - -#if ENVFUNC - - if (hflag) { - home = getenv("HOME"); - if (home != NULL) { - /* build home dir file spec */ - strcpy(fspec, home); - strcat(fspec, "/"); - strcat(fspec, fname); - - /* and try it out */ - if (ffropen(fspec) == FIOSUC) { - ffclose(); - return fspec; - } - } - } -#endif - - /* always try the current directory first */ - strcpy( fspec, fname) ; - if( ffropen( fspec) == FIOSUC) { - ffclose() ; - return fspec ; - } -#if ENVFUNC - /* get the PATH variable */ - path = getenv("PATH"); - if (path != NULL) - while (*path) { - - /* build next possible file spec */ - sp = fspec; - while (*path && (*path != PATHCHR)) - *sp++ = *path++; - - /* add a terminating dir separator if we need it */ - if (sp != fspec) - *sp++ = '/'; - *sp = 0; - strcat(fspec, fname); - - /* and try it out */ - if (ffropen(fspec) == FIOSUC) { - ffclose(); - return fspec; - } - - if (*path == PATHCHR) - ++path; - } -#endif - - /* look it up via the old table method */ - for( i = 2; i < PATHNAME_SIZE ; i++) { - strcpy(fspec, pathname[i]); - strcat(fspec, fname); - - /* and try it out */ - if (ffropen(fspec) == FIOSUC) { - ffclose(); - return fspec; - } - } - - return NULL; /* no such luck */ -} - /* * change a key command to a string we can print out * @@ -659,7 +544,7 @@ int (*getbind(int c))(int, int) * This function takes a ptr to function and gets the name * associated with it. */ -char *getfname(fn_t func) +static char *getfname(fn_t func) { struct name_bind *nptr; /* pointer into the name binding table */ diff --git a/bind.h b/bind.h index ae7de26..a5efd9f 100644 --- a/bind.h +++ b/bind.h @@ -14,10 +14,8 @@ int buildlist( int type, char *mstring) ; int strinc( char *source, char *sub) ; unsigned int getckey( int mflag) ; int startup( char *sfname) ; -char *flook( const char *fname, int hflag) ; void cmdstr( int c, char *seq) ; fn_t getbind( int c) ; -char *getfname( fn_t) ; fn_t fncmatch( char *) ; unsigned int stock( char *keyname) ; char *transbind( char *skey) ; diff --git a/eval.c b/eval.c index d809351..2beff5a 100644 --- a/eval.c +++ b/eval.c @@ -17,7 +17,7 @@ #include "estruct.h" #include "edef.h" #include "exec.h" -#include "fileio.h" +#include "flook.h" #include "input.h" #include "line.h" #include "random.h" diff --git a/exec.c b/exec.c index d0cf737..a437523 100644 --- a/exec.c +++ b/exec.c @@ -19,6 +19,7 @@ #include "edef.h" #include "eval.h" #include "file.h" +#include "flook.h" #include "input.h" #include "line.h" diff --git a/fileio.c b/fileio.c index 1401076..7ae3508 100644 --- a/fileio.c +++ b/fileio.c @@ -207,24 +207,3 @@ fio_code ffgetline(void) #endif return FIOSUC; } - -/* - * does exist on disk? - * - * char *fname; file to check for existance - */ -boolean fexist( const char *fname) -{ - FILE *fp; - - /* try to open the file for reading */ - fp = fopen(fname, "r"); - - /* if it fails, just return false! */ - if (fp == NULL) - return FALSE; - - /* otherwise, close it and report true */ - fclose(fp); - return TRUE; -} diff --git a/fileio.h b/fileio.h index 704ab96..c6cb436 100644 --- a/fileio.h +++ b/fileio.h @@ -27,7 +27,6 @@ extern int flen ; /* current allocated length of fline */ extern int ftype ; extern int fpayload ; /* actual length of fline content */ -boolean fexist( const char *fname) ; fio_code ffclose( void) ; fio_code ffgetline( void) ; fio_code ffputline( unsigned char *buf, int nbuf, int dosflag) ; diff --git a/flook.c b/flook.c new file mode 100644 index 0000000..0524816 --- /dev/null +++ b/flook.c @@ -0,0 +1,144 @@ +/* flook.c -- implements flook.h */ +#include "flook.h" + + +#include +#include +#include + + +#include "fileio.h" + + +/* possible names and paths of help files under different OSs */ +const char *pathname[] = { +#if MSDOS + "emacs.rc", + "emacs.hlp", + "\\sys\\public\\", + "\\usr\\bin\\", + "\\bin\\", + "\\", + "" +#endif + +#if V7 | BSD | USG + ".emacsrc", + "emacs.hlp", +#if PKCODE + "/usr/global/lib/", "/usr/local/bin/", "/usr/local/lib/", +#endif + "/usr/local/", "/usr/lib/", "" +#endif + +#if VMS +{ + "emacs.rc", "emacs.hlp", "", +#if PKCODE + "sys$login:", "emacs_dir:", +#endif + "sys$sysdevice:[vmstools]" +#endif +}; + +#define PATHNAME_SIZE (sizeof pathname / sizeof pathname[ 0]) + + +/* + * does exist on disk? + * + * char *fname; file to check for existance + */ +boolean fexist( const char *fname) +{ + FILE *fp; + + /* try to open the file for reading */ + fp = fopen(fname, "r"); + + /* if it fails, just return false! */ + if (fp == NULL) + return FALSE; + + /* otherwise, close it and report true */ + fclose(fp); + return TRUE; +} + +/* + * Look up the existance of a file along the normal or PATH + * environment variable. Look first in the HOME directory if + * asked and possible + * + * char *fname; base file name to search for + * int hflag; Look in the HOME environment variable first? + */ +char *flook( const char *fname, int hflag) +{ + char *home; /* path to home directory */ + char *path; /* environmental PATH variable */ + char *sp; /* pointer into path spec */ + int i; /* index */ + static char fspec[NSTRING]; /* full path spec to search */ + +#if ENVFUNC + + if (hflag) { + home = getenv("HOME"); + if (home != NULL) { + /* build home dir file spec */ + strcpy(fspec, home); + strcat(fspec, "/"); + strcat(fspec, fname); + + /* and try it out */ + if( fexist( fspec)) + return fspec ; + } + } +#endif + + /* always try the current directory first */ + strcpy( fspec, fname) ; + if( fexist( fspec)) + return fspec ; + +#if ENVFUNC + /* get the PATH variable */ + path = getenv("PATH"); + if (path != NULL) + while (*path) { + + /* build next possible file spec */ + sp = fspec; + while (*path && (*path != PATHCHR)) + *sp++ = *path++; + + /* add a terminating dir separator if we need it */ + if (sp != fspec) + *sp++ = '/'; + *sp = 0; + strcat(fspec, fname); + + /* and try it out */ + if( fexist( fspec)) + return fspec ; + + if (*path == PATHCHR) + ++path; + } +#endif + + /* look it up via the old table method */ + for( i = 2; i < PATHNAME_SIZE ; i++) { + strcpy(fspec, pathname[i]); + strcat(fspec, fname); + + /* and try it out */ + if( fexist( fspec)) + return fspec ; + } + + return NULL; /* no such luck */ +} + diff --git a/flook.h b/flook.h new file mode 100644 index 0000000..3779644 --- /dev/null +++ b/flook.h @@ -0,0 +1,9 @@ +#include "estruct.h" + + +extern const char *pathname[] ; + + +boolean fexist( const char *fname) ; +char *flook( const char *fname, int hflag) ; +