Jspice3
dos.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: UCB CAD Group
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /* Misc things for DOS */
9 
10 #ifdef MSDOS
11 
12 #include "spice.h"
13 #include <dos.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 
17 /*
18  * Directory emulation
19  */
20 
21 #ifdef HAVE_DOSDIRS
22 #include <direct.h>
23 
24 #if !__NDPC__
25 
26 #include <fcntl.h>
27 
28 struct dos_dir {
29  char d_name[8];
30  char d_ext[3];
31  char d_attr;
32  char d_fill[10];
33  short d_time, d_date;
34  short d_ino;
35  long d_size;
36 };
37 
38 
39 DIR *
40 opendir(path)
41 
42 char *path;
43 {
44  static int i;
45 
46  i = open(path, O_RDONLY);
47  if (i == -1)
48  return (NULL);
49  else
50  return ((DIR *) &i);
51 }
52 
53 
54 struct direct *
55 readdir(i)
56 
57 DIR *i;
58 {
59  static struct direct d;
60  static struct dos_dir dd;
61 
62  if (read(*i, &dd, sizeof (struct dos_dir)) < sizeof (struct dos_dir))
63  return (NULL);
64  else {
65  strncpy(d.d_name, dd.d_name, sizeof(dd.d_name));
66  d.d_name[sizeof(dd.d_name)] = 0;
67  strcat(d.d_name, ".");
68  strcat(d.d_name, dd.d_ext);
69  d.d_namelen = strlen(d.d_name);
70  d.d_ino = dd.d_ino;
71  d.d_reclen = sizeof(d); /* XXX */
72  return (&d);
73  }
74 }
75 
76 
77 void
78 closedir(i)
79 
80 DIR *i;
81 {
82  (void) close (*i);
83  return;
84 }
85 
86 #else
87 
88 
89 DIR *
90 opendir(dir)
91 
92 char *dir;
93 {
94  struct find_t *d;
95  char buf[128];
96 
97  strcpy(buf,dir);
98  if (*buf == '\\' && *(buf+1) == '\0')
99  strcat(buf,"*.*");
100  else
101  strcat(buf,"\\*.*");
102 
103  d = (struct find_t *) malloc(sizeof(struct find_t));
104  if (d == NULL) return NULL;
105  if (findfirst(buf,d,0x1f)) {
106  free(d);
107  return (NULL);
108  }
109  return ((DIR *) d);
110 }
111 
112 
113 struct direct *
114 readdir(d)
115 
116 DIR *d;
117 {
118  char *c;
119  static struct direct dd;
120  int i;
121 
122  if (d == NULL) return NULL;
123  strcpy(dd.d_name,((struct find_t *)d)->name);
124 
125  for (c = dd.d_name; *c; c++)
126  if (isupper(*c)) *c = tolower(*c);
127 
128  if (findnext((struct find_t *)d))
129  return (NULL);
130  return (&dd);
131 }
132 
133 
134 void
135 closedir(d)
136 
137 DIR *d;
138 {
139  if (d)
140  free(d);
141 }
142 
143 #endif
144 #endif /* HAVE_DOSDIRS */
145 
146 
147 /****************************************************************************/
148 #if __NDPC__
149 /* fopen() broken, fix in wp.c plot5.c hplaser.c */
150 /* vsprintf broken also */
151 FILE *
152 ndp_fopen(file,mode)
153 char *file, *mode;
154 {
155  FILE *fp;
156 
157  if (mode[1] == 'b') {
158  _pmode = 0x8000;
159  fp = fopen(file,mode);
160  _pmode = 0x4000;
161  }
162  else
163  fp = fopen(file,mode);
164  return (fp);
165 }
166 #define fopen ndp_fopen
167 #endif
168 
169 
170 int
171 dos_tics()
172 /* read tic count directly */
173 {
174  int tics = 0;
175 #if __NDPC__
176  blk_mb(&tics,0x34,0x046c,4);
177 #else
178 #if __GNUC__
179  tics = *(long*)(0xe000046c);
180 #endif
181 #endif
182  return (tics);
183 }
184 
185 
186 /****************************************************************************/
187 #ifdef __GNUC__
188 unsigned int
189 _memavl()
190 {
191  return (_go32_dpmi_remaining_virtual_memory());
192 }
193 #endif
194 
195 #else
196 int dos_dummy_int; /* define something to keep linkers happy */
197 #endif
static char buf[MAXPROMPT]
Definition: arg.c:18
int dos_dummy_int
Definition: dos.c:196
char * strcpy()
char * malloc()
Definition: cddefs.h:237
#define NULL
Definition: spdefs.h:121
static double c
Definition: vectors.c:16
static char * path
Definition: paths.c:13
void free()