Changeset 103906 in git
- Timestamp:
- May 5, 2010, 4:59:31 PM (13 years ago)
- Branches:
- (u'spielwiese', '0d6b7fcd9813a1ca1ed4220cfa2b104b97a0a003')
- Children:
- 46395adbff400b36355a33ababfad210868c806a
- Parents:
- 371bc5f2b1adfa76d36a0242eb9c7d7cb44b9b92
- git-author:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2010-05-05 16:59:31+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:52:51+01:00
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
coeffs/Makefile.in
r371bc5f r103906 1 1 ################################################################# 2 2 ### 3 3 ### Makefile for Singular -
kernel/febase.cc
r371bc5f r103906 675 675 return p; 676 676 } 677 /*****************************************************************678 *679 * File handling680 *681 *****************************************************************/682 683 FILE * feFopen(const char *path, const char *mode, char *where,684 int useWerror, int path_only)685 {686 char longpath[MAXPATHLEN];687 if (path[0]=='~')688 {689 if (path[1] == DIR_SEP)690 {691 const char* home = getenv("HOME");692 #ifdef ix86_Win693 if ((home==NULL)||(!access(home,X_OK)))694 home = getenv("SINGHOME");695 #endif696 if (home != NULL)697 {698 strcpy(longpath, home);699 strcat(longpath, &(path[1]));700 path = longpath;701 }702 }703 #if defined(HAVE_PWD_H) && defined(HAVE_GETPWNAM)704 else705 {706 char* dir_sep;707 struct passwd *pw_entry;708 strcpy (longpath, path);709 dir_sep = strchr(longpath, DIR_SEP);710 if (dir_sep==NULL)711 {712 Werror(" illegal ~ in filename >>%s<<",longpath);713 return NULL;714 }715 *dir_sep = '\0';716 pw_entry = getpwnam(&longpath[1]);717 if (pw_entry != NULL)718 {719 strcpy(longpath, pw_entry->pw_dir);720 dir_sep = strchr((char *)path, DIR_SEP);721 strcat(longpath, dir_sep);722 path = longpath;723 }724 }725 #endif726 }727 FILE * f=NULL;728 if (! path_only)729 {730 struct stat statbuf;731 if ((stat(path,&statbuf)==0)732 && (S_ISREG(statbuf.st_mode)))733 f = myfopen(path,mode);734 }735 if (where!=NULL) strcpy(where,path);736 if ((*mode=='r') &&737 (path[0]!=DIR_SEP) &&738 ! (path[0] == '.' && path[1] == DIR_SEP) &&739 (f==NULL))740 {741 char found = 0;742 char* spath = feResource('s');743 char *s;744 745 if (where==NULL) s=(char *)omAlloc(250);746 else s=where;747 748 if (spath!=NULL)749 {750 char *p,*q;751 p = spath;752 while( (q=strchr(p, fePathSep)) != NULL)753 {754 *q = '\0';755 strcpy(s,p);756 *q = fePathSep;757 strcat(s, DIR_SEPP);758 strcat(s, path);759 if(!access(s, R_OK)) { found++; break; }760 p = q+1;761 }762 if(!found)763 {764 strcpy(s,p);765 strcat(s, DIR_SEPP);766 strcat(s, path);767 }768 f=myfopen(s,mode);769 if (f!=NULL)770 {771 if (where==NULL) omFree((ADDRESS)s);772 return f;773 }774 }775 else776 {777 if (where!=NULL) strcpy(s/*where*/,path);778 f=myfopen(path,mode);779 }780 if (where==NULL) omFree((ADDRESS)s);781 }782 if ((f==NULL)&&(useWerror))783 Werror("cannot open `%s`",path);784 return f;785 }786 677 787 678 static char * feBufferStart; … … 1157 1048 #endif 1158 1049 1159 #ifdef ix86_Win1160 // Make sure that mode contains binary option1161 FILE* myfopen(const char *path, const char *mode)1162 {1163 char mmode[4];1164 int i;1165 int done = 0;1166 1167 for (i=0;;i++)1168 {1169 mmode[i] = mode[i];1170 if (mode[i] == '\0') break;1171 if (mode[i] == 'w') done = 1;1172 if (mode[i] == 'a') done = 1;1173 if (mode[i] == 'b') done = 1;1174 }1175 1176 if (! done)1177 {1178 mmode[i] = 'b';1179 mmode[i+1] = '\0';1180 }1181 return fopen(path, mmode);1182 }1183 #endif1184 // replace "\r\n" by " \n" and "\r" by "\n"1185 1186 size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)1187 {1188 size_t got = fread(ptr, size, nmemb, stream) * size;1189 size_t i;1190 1191 for (i=0; i<got; i++)1192 {1193 if ( ((char*) ptr)[i] == '\r')1194 {1195 if (i+1 < got && ((char*) ptr)[i+1] == '\n')1196 ((char*) ptr)[i] = ' ';1197 else1198 ((char*) ptr)[i] = '\n';1199 }1200 }1201 return got;1202 } -
kernel/febase.h
r371bc5f r103906 62 62 #undef HAVE_FEREAD 63 63 #endif 64 65 /*66 // These are our versions of fopen and fread They are very similar to67 // the usual fopen and fread, except that on reading, they always68 // convert "\r\n" into " \n" and "\r" into "\n".69 //70 // IMPORTANT: do only use myfopen and myfread when reading text,71 // do never use fopen and fread72 */73 #ifdef ix86_Win74 FILE *myfopen(const char *path, const char *mode);75 #else76 #define myfopen fopen77 #endif78 79 size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream);80 64 81 65 enum noeof_t … … 230 214 /***************************************************************** 231 215 * 232 * Resource management (feResources.cc)233 *234 *****************************************************************/235 // returns value of Resource as read-only string, or NULL236 // if Resource not found237 // issues warning, if explicitely requested (warn > 0), or238 // if warn < 0 and Resource is gotten for the first time239 // Always quiet if warn == 0240 char* feResource(const char id, int warn = -1);241 char* feResource(const char* key, int warn = -1);242 // This needs to be called before the first call to feResource243 // Initializes Resources, SearchPath, and extends PATH244 void feInitResources(char* argv0);245 // Re-inits resources, should be called after changing env. variables246 void feReInitResources();247 // Prints resources into string with StringAppend, etc248 void feStringAppendResources(int warn = -1);249 250 /*****************************************************************251 *252 216 * help system (fehelp.cc) 253 217 * … … 273 237 /* extern unsigned long feVersionId; */ 274 238 275 /*****************************************************************276 *277 * File Stuff278 *279 *****************************************************************/280 FILE * feFopen(const char *path, const char *mode, char *where=NULL,281 int useWerror=FALSE, int path_only=FALSE);282 283 239 char * StringAppend(const char *fmt, ...); 284 240 char * StringAppendS(const char *s);
Note: See TracChangeset
for help on using the changeset viewer.