1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 07:16:23 -05:00

Move flook and fexist to flook tosimplify dependency graph.

This commit is contained in:
Renaud 2013-06-10 18:14:09 +08:00
parent fb395c3f01
commit 5bbc6104ae
8 changed files with 158 additions and 143 deletions

121
bind.c
View File

@ -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 */

2
bind.h
View File

@ -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) ;

2
eval.c
View File

@ -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"

1
exec.c
View File

@ -19,6 +19,7 @@
#include "edef.h"
#include "eval.h"
#include "file.h"
#include "flook.h"
#include "input.h"
#include "line.h"

View File

@ -207,24 +207,3 @@ fio_code ffgetline(void)
#endif
return FIOSUC;
}
/*
* does <fname> 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;
}

View File

@ -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) ;

144
flook.c Normal file
View File

@ -0,0 +1,144 @@
/* flook.c -- implements flook.h */
#include "flook.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 <fname> 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 */
}

9
flook.h Normal file
View File

@ -0,0 +1,9 @@
#include "estruct.h"
extern const char *pathname[] ;
boolean fexist( const char *fname) ;
char *flook( const char *fname, int hflag) ;