Loading...
Searching...
No Matches
feFopen.cc File Reference
`#include "singular_resourcesconfig.h"`
`#include "feResource.h"`
`#include "feFopen.h"`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include <unistd.h>`
`#include <errno.h>`

Go to the source code of this file.

## Functions

void | WerrorS (const char *s)
FILE * | feFopen (const char *path, const char *mode, char *where, short useWerror, short path_only)
FILE * | myfopen (const char *path, const char *mode)
size_t | myfread (void *ptr, size_t size, size_t nmemb, FILE *stream)

## Variables

VAR void(* | WerrorS_callback )(const char *s) = NULL
VAR void(* | PrintS_callback )(const char *s) = NULL
VAR short | errorreported =0

## Function Documentation

## feFopen()

FILE * feFopen | ( | const char * | path,
|  | const char * | mode,
|  | char * | where,
|  | short | useWerror,
|  | short | path_only )

Definition at line 47 of file feFopen.cc.

{
char longpath[MAXPATHLEN];
if (path[0]=='~')
{
if (path[1] == DIR_SEP)
{
const char* home = getenv("HOME");
#ifdef __CUGWIN__
if ((home==NULL)||(!access(home,X_OK)))
home = getenv("SINGHOME");
#endif
if (home != NULL)
{
strcpy(longpath, home);
strcat(longpath, &(path[1]));
path = longpath;
}
}
#if defined(HAVE_PWD_H) && defined(HAVE_GETPWNAM)
else
{
char* dir_sep;
struct passwd *pw_entry;
strcpy (longpath, path);
dir_sep = strchr(longpath, DIR_SEP);
if (dir_sep==NULL)
{
char buf[256];
strcpy(buf,"illegal ~ in filename >>");
strncat(buf,longpath,235);
strcat(buf,"<<");
WerrorS(buf);
return NULL;
}
*dir_sep = '\0';
pw_entry = getpwnam(&longpath[1]);
if (pw_entry != NULL)
{
strcpy(longpath, pw_entry->pw_dir);
dir_sep = strchr((char *)path, DIR_SEP);
strcat(longpath, dir_sep);
path = longpath;
}
}
#endif
}
FILE * f=NULL;
if (! path_only)
{
struct stat statbuf;
int res = -1;
do
{
res = stat(path,&statbuf);
} while((res < 0) and (errno == EINTR));
if ((res == 0)
&& (S_ISREG(statbuf.st_mode)))
f = myfopen(path,mode);
}
if (where!=NULL) strcpy(where,path);
if ((*mode=='r') &&
(path[0]!=DIR_SEP) &&
! (path[0] == '.' && path[1] == DIR_SEP) &&
(f==NULL))
{
char found = 0;
char* spath = feResource('s');
char *s;
if (where==NULL) s=(char *)malloc(1024);
else s=where;
if (spath!=NULL)
{
char *p,*q;
p = spath;
while( (q=strchr(p, fePathSep)) != NULL)
{
*q = '\0';
strcpy(s,p);
*q = fePathSep;
strcat(s, DIR_SEPP);
strcat(s, path);
if(!access(s, R_OK)) { found++; break; }
p = q+1;
}
if(!found)
{
strcpy(s,p);
strcat(s, DIR_SEPP);
strcat(s, path);
}
f=myfopen(s,mode);
if (f!=NULL)
{
if (where==NULL) free(s);
return f;
}
}
else
{
if (where!=NULL) strcpy(s/*where*/,path);
f=myfopen(path,mode);
}
if (where==NULL) free(s);
}
if ((f==NULL)&&(useWerror))
{
char buf[256];
strcpy(buf,"cannot open `");
strncat(buf,path,240);
strcat(buf,"`");
WerrorS(buf);
}
return f;
}
p
int p
Definition cfModGcd.cc:4086
f
FILE * f
Definition checklibs.c:9
s
const CanonicalForm int s
Definition facAbsFact.cc:51
res
CanonicalForm res
Definition facAbsFact.cc:60
found
bool found
Definition facFactorize.cc:55
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
myfopen
FILE * myfopen(const char *path, const char *mode)
Definition feFopen.cc:167
feResource
static char * feResource(feResourceConfig config, int warn)
Definition feResource.cc:233
fePathSep
const char fePathSep
Definition feResource.h:58
DIR_SEPP
#define DIR_SEPP
Definition feResource.h:7
DIR_SEP
#define DIR_SEP
Definition feResource.h:6
getenv
char * getenv()
free
#define free
Definition omAllocFunc.c:14
malloc
#define malloc
Definition omAllocFunc.c:12
NULL
#define NULL
Definition omList.c:12
MAXPATHLEN
#define MAXPATHLEN
Definition omRet2Info.c:22
buf
int status int void * buf
Definition si_signals.h:69

## myfopen()

FILE * myfopen | ( | const char * | path,
|  | const char * | mode )

Definition at line 167 of file feFopen.cc.

{
#if (defined(__CUGWIN__))
char mmode[4];
int i;
int done = 0;
for (i=0;;i++)
{
mmode[i] = mode[i];
if (mode[i] == '\0') break;
if (mode[i] == 'w') done = 1;
if (mode[i] == 'a') done = 1;
if (mode[i] == 'b') done = 1;
}
if (! done)
{
mmode[i] = 'b';
mmode[i+1] = '\0';
}
return fopen(path, mmode);
#else
return fopen(path, mode);
#endif
}
i
int i
Definition cfEzgcd.cc:132

## myfread()

size_t myfread | ( | void * | ptr,
|  | size_t | size,
|  | size_t | nmemb,
|  | FILE * | stream )

Definition at line 195 of file feFopen.cc.

{
size_t got = fread(ptr, size, nmemb, stream) * size;
size_t i;
for (i=0; i<got; i++)
{
if ( ((char*) ptr)[i] == '\r')
{
if (i+1 < got && ((char*) ptr)[i+1] == '\n')
((char*) ptr)[i] = ' ';
else
((char*) ptr)[i] = '\n';
}
}
return got;
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600

## WerrorS()

void WerrorS | ( | const char * | s | ) |

Definition at line 24 of file feFopen.cc.

{
errorreported = 1;
if (WerrorS_callback == NULL)
{
fwrite(" ? ",1,5,stderr);
fwrite((char *)s,1,strlen((char *)s),stderr);
fwrite("\n",1,1,stderr);
fflush(stderr);
}
else
{
WerrorS_callback(s);
}
}
WerrorS_callback
VAR void(* WerrorS_callback)(const char *s)
Definition feFopen.cc:21
errorreported
VAR short errorreported
Definition feFopen.cc:23

## Variable Documentation

## errorreported

VAR short errorreported =0

Definition at line 23 of file feFopen.cc.

## PrintS_callback

VAR void(* PrintS_callback) (const char *s) | ( | const char * | s | ) | = NULL

Definition at line 22 of file feFopen.cc.

## WerrorS_callback

VAR void(* WerrorS_callback) (const char *s) | ( | const char * | s | ) | = NULL

Definition at line 21 of file feFopen.cc.