Jspice3
paths.c File Reference
#include <stdio.h>
#include <string.h>
#include <ctype.h>
Include dependency graph for paths.c:

Go to the source code of this file.

Functions

FILE * OpenDevice ()
 
char * copy ()
 
int PSetPath (char *string)
 
int PAppendPath (char *string)
 
char * PGetPath ()
 
FILE * POpen (char *file, char *mode, char **prealname)
 

Variables

static char * path
 

Function Documentation

char* copy ( )
FILE* OpenDevice ( )
int PAppendPath ( char *  string)

Definition at line 46 of file paths.c.

49 {
50  char buf[2048], *s, *trealloc();
51  int len;
52 
53  if (!path)
54  return (PSetPath(string));
55  strcpy(buf,string);
56  cp_pathfix(buf);
57  len = strlen(path);
58  path = trealloc(path,len + strlen(buf) + 2);
59  s = path + len;
60  *s = ' ';
61  strcpy(s+1,buf);
62  return (0);
63 }
void cp_pathfix(char *buf)
Definition: help.c:198
static char buf[MAXPROMPT]
Definition: arg.c:18
char * strcpy()
Definition: cddefs.h:119
int PSetPath(char *string)
Definition: paths.c:26
static char * path
Definition: paths.c:13
char * trealloc()
char* PGetPath ( )

Definition at line 67 of file paths.c.

69 {
70  return (path);
71 }
static char * path
Definition: paths.c:13
FILE* POpen ( char *  file,
char *  mode,
char **  prealname 
)

Definition at line 75 of file paths.c.

84 {
85  char buf[512], buf1[512];
86  char *p, *q;
87  FILE *f;
88 
89  strcpy(buf,file);
90  cp_pathfix(buf);
91  file = buf;
92 
93  /*
94  * The function OpenDevice() must be supplied externally. The intended
95  * purpose is to support multi-symbol files (libraries). OpenDevice()
96  * would check to see if "file" is included in the library, and if so,
97  * returns a file pointer suitably offset. Otherwise NULL is returned.
98  * Note that libraries are only opened for reading.
99  */
100  if (!strcmp(mode,"r")) {
101  f = OpenDevice(file);
102  if (f) {
103  if (prealname)
104  *prealname = copy(file);
105  return (f);
106  }
107  }
108 
109  if (!path || !*path || file[0] == '/'
110 #ifdef MSDOS
111  || file[0] == '\\' || file[1] == ':'
112 #endif
113  ) {
114  if (prealname)
115  *prealname = copy(file);
116  return (fopen(file,mode));
117  }
118 
119  /* Last, but not least, try going through the path. */
120 
121  p = path;
122  while (*p != '\0') {
123  while (isspace(*p)) p++;
124  q = buf1;
125  while ((*p != '\0') && !isspace(*p))
126  *q++ = *p++;
127  *q++ = '/';
128  strcpy(q, file);
129  cp_pathfix(buf1);
130  f = fopen(buf1, mode);
131  if (f != NULL) {
132  if (prealname)
133  *prealname = copy(buf1);
134  return (f);
135  }
136  }
137  return (NULL);
138 }
void cp_pathfix(char *buf)
Definition: help.c:198
static char buf[MAXPROMPT]
Definition: arg.c:18
char * strcpy()
FILE * p
Definition: proc2mod.c:48
#define NULL
Definition: spdefs.h:121
char * copy()
FILE * OpenDevice()
static char * path
Definition: paths.c:13
int PSetPath ( char *  string)

Definition at line 26 of file paths.c.

29 {
30  char buf[2048];
31 
32  if (path) {
33  free(path);
34  path = 0;
35  }
36  if (string) {
37  strcpy(buf,string);
38  cp_pathfix(buf);
39  path = copy(buf);
40  }
41  return (0);
42 }
void cp_pathfix(char *buf)
Definition: help.c:198
static char buf[MAXPROMPT]
Definition: arg.c:18
char * strcpy()
char * copy()
static char * path
Definition: paths.c:13
void free()

Variable Documentation

char* path
static

Definition at line 13 of file paths.c.