Jspice3
paths.c
Go to the documentation of this file.
1 /***************************************************************************
2 SCED - Schematic Capture Editor
3 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
4 Copyright 1990 Regents of the University of California. All rights reserved.
5 Authors: 1981 Giles C. Billingsley (parts of KIC layout editor)
6  1992 Stephen R. Whiteley
7 ****************************************************************************/
8 
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 
13 static char *path;
14 
15 /* OpenDevice() is user supplied */
16 #ifdef __STDC__
17 extern FILE *OpenDevice(char*);
18 extern char *copy(char*);
19 #else
20 extern FILE *OpenDevice();
21 extern char *copy();
22 #endif
23 
24 
25 int
26 PSetPath(string)
27 
28 char *string;
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 }
43 
44 
45 int
46 PAppendPath(string)
47 
48 char *string;
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 }
64 
65 
66 char *
68 
69 {
70  return (path);
71 }
72 
73 
74 FILE *
75 POpen(file, mode, prealname)
76 
77 char *file; /* Name of the file to be opened. */
78 char *mode; /* The file mode, as given to fopen. */
79 char **prealname; /* Pointer to a location that will be filled
80  * in with the address of the real name of
81  * the file that was successfully opened.
82  * If NULL, then nothing is stored.
83  */
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()
Definition: cddefs.h:119
char * PGetPath()
Definition: paths.c:67
FILE * p
Definition: proc2mod.c:48
int PSetPath(char *string)
Definition: paths.c:26
#define NULL
Definition: spdefs.h:121
char * copy()
FILE * POpen(char *file, char *mode, char **prealname)
Definition: paths.c:75
int PAppendPath(char *string)
Definition: paths.c:46
FILE * OpenDevice()
static char * path
Definition: paths.c:13
char * trealloc()
void free()