Jspice3
libfuncs.c File Reference
#include "spice.h"
#include "misc.h"
Include dependency graph for libfuncs.c:

Go to the source code of this file.

Macros

#define TEMPFORMAT   "temp%s%d"
 

Functions

FILE * popen (char *cmd, char *mode) const
 
int pclose (FILE *fp)
 
void perror (char *str)
 
int access (char *pth, int m)
 
int system (char *str)
 
int unlink (char *fn)
 
char * getenv (char *c)
 
void clearerr (FILE *fp)
 
char * getcwd (char *buf, int size)
 
int getpid ()
 
char * smktemp (char *id)
 
double erfc (double x)
 

Variables

static char * tfile
 

Macro Definition Documentation

#define TEMPFORMAT   "temp%s%d"

Definition at line 166 of file libfuncs.c.

Function Documentation

int access ( char *  pth,
int  m 
)

Definition at line 75 of file libfuncs.c.

78 {
79  return (-1);
80 }
void clearerr ( FILE *  fp)

Definition at line 116 of file libfuncs.c.

118 {}
double erfc ( double  x)

Definition at line 253 of file libfuncs.c.

255 {
256 /* Returns the complementary error function with fractional error
257  * everywhere less that 1.2e-7. From Numerical Recipes in C.
258  */
259  double t, z, ans;
260 
261  z = fabs(x);
262  t = 1.0/(1.0 + 0.5*x);
263  ans = t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+
264  t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+
265  t*(-0.82215223+t*0.17087277)))))))));
266  return (x >= 0 ? ans : 2.0 - ans);
267 }
Definition: cddefs.h:192
char* getcwd ( char *  buf,
int  size 
)

Definition at line 124 of file libfuncs.c.

127 {
128  if (buf == NULL)
129  buf = tmalloc(4);
130  *buf = '\0';
131  return (buf);
132 }
static char buf[MAXPROMPT]
Definition: arg.c:18
char * tmalloc()
#define NULL
Definition: spdefs.h:121
char* getenv ( char *  c)

Definition at line 106 of file libfuncs.c.

108 {
109  return (NULL);
110 }
#define NULL
Definition: spdefs.h:121
int getpid ( )

Definition at line 137 of file libfuncs.c.

138 {
139  return (100);
140 }
int pclose ( FILE *  fp)

Definition at line 41 of file libfuncs.c.

44 {
45  if (fp)
46  (void)fclose(fp);
47  if (tfile) {
48  (void)unlink(tfile);
49  tfree(tfile);
50  }
51  return (0);
52 }
static char * tfile
Definition: libfuncs.c:15
#define tfree(x)
Definition: cdmacs.h:22
int unlink(char *fn)
Definition: libfuncs.c:96
void perror ( char *  str)

Definition at line 59 of file libfuncs.c.

62 {
63  char *m = "error occurred\n";
64  if (str && *str)
65  (void)fprintf(stderr,"%s: %s",str,m);
66  else
67  (void)fprintf(stderr,"%s",m);
68 }
Definition: cddefs.h:109
FILE* popen ( char *  cmd,
char *  mode 
) const

Definition at line 20 of file libfuncs.c.

23 {
24  char buf[BSIZE_SP];
25  FILE *fp;
26 
27  tfile = smktemp("po");
28  fp = fopen(tfile,"w");
29  if (fp != NULL) {
30  (void)sprintf(buf, "%s > %s",cmd,tfile);
31  (void)system(buf);
32  (void)fclose(fp);
33  fp = fopen(tfile,"r");
34  return (fp);
35  }
36  return (NULL);
37 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
int system(char *str)
Definition: libfuncs.c:85
char * smktemp(char *id)
Definition: libfuncs.c:170
static char * tfile
Definition: libfuncs.c:15
#define NULL
Definition: spdefs.h:121
char* smktemp ( char *  id)

Definition at line 170 of file libfuncs.c.

173 {
174  char rbuf[513];
175  char *nbuf;
176  static int num;
177 
178  if (num == 0) {
179  num = getpid();
180  }
181  else
182  num++;
183 
184  if (!id)
185  id = "sp";
186 
187  sprintf(rbuf, TEMPFORMAT, id, num);
188  nbuf = (char *) malloc(strlen(rbuf) + 1);
189  strcpy(nbuf, rbuf);
190 
191  return (nbuf);
192 }
char * strcpy()
char * malloc()
#define TEMPFORMAT
Definition: libfuncs.c:166
int getpid()
Definition: libfuncs.c:137
int system ( char *  str)

Definition at line 85 of file libfuncs.c.

87 {
88  fprintf(stderr, "Can not execute: %s\n",str);
89  return (-1);
90 }
int unlink ( char *  fn)

Definition at line 96 of file libfuncs.c.

98 {
99  return (-1);
100 }

Variable Documentation

char* tfile
static

Definition at line 15 of file libfuncs.c.