28 if ( *s ==
'\\' ) *s =
'/';
36 if ( *s ==
'/' ) *s =
'\\';
45 while ( a = fgetc( stream ) , ( a !=
'\n' && a != EOF && a != 0xD ) );
46 if( a == EOF )
return EOF;
52 unsigned char ucRes = 1;
55 char ch = fgetc(stream);
70 fscanf( stream, Format, Par );
74int IOFUN::ReadPar( FILE *stream,
const char *Format,
void *Par1,
void *Par2 )
77 fscanf( stream, Format, Par1, Par2 );
81int IOFUN::ReadPar( FILE *stream,
const char *Format,
void *Par1,
void *Par2,
void *Par3 )
84 fscanf( stream, Format, Par1, Par2, Par3 );
88int IOFUN::ReadPar( FILE * stream,
const char * Format,
void *Par1,
void *Par2,
void *Par3,
void *Par4 )
91 fscanf( stream, Format, Par1, Par2, Par3, Par4 );
103 for( i=0; i<n; i++ ) ierr = fscanf( stream,
"%lf", Par+i );
104 if( ierr == -1 )
return -1;
106 for( i=0; i<n; i++ ) Par[i] *= dScal;
113 for( i=0; i<n; i++ ) ierr = fscanf( stream,
"%f", Par+i );
114 if( ierr == -1 )
return -1;
116 for( i=0; i<n; i++ ) Par[i] *= fScal;
123 for( i=0; i<n; i++ ) ierr = fscanf( stream,
"%ld", Par+i );
124 if( ierr == -1 )
return -1;
126 for( i=0; i<n; i++ ) Par[i] *= lScal;
133 for( i=0; i<n; i++ ) ierr = fscanf( stream,
"%d", Par+i );
134 if( ierr == -1 )
return -1;
136 for( i=0; i<n; i++ ) Par[i] *= iScal;
145 return ReadVect( stream, Par, 3, dScal );
149 return ReadVect( stream, Par, 3, fScal );
153 return ReadVect( stream, Par, 3, lScal );
157 return ReadVect( stream, Par, 3, iScal );
170 cc = fgetc( stream );
172 while ( cc !=
'\n' && cc != EOF && cc != 0xD )
180 cc = fgetc( stream );
181 if( cc != 0xA )ungetc( cc, stream );
187 for( j=i-1; j>0; j-- )
189 if( isblank(Par[j]) )
195 char *cRob =
new char[j+2];
196 std::strcpy( cRob, Par );
198 for(
int i=0; i<j+1; i++ )
200 if( isblank(cRob[i]) )
205 strcpy( Par, cRob+i0 );
208 if( cc == EOF )
return EOF;
209 return strlen( Par );
221 cc = fgetc( stream );
223 while ( cc !=
'\n' && cc != EOF && cc != 0xD )
231 cc = fgetc( stream );
232 if( cc != 0xA )ungetc(cc,stream);
236 if( cc == EOF )Par[i+1]=EOF;
246 while( !( isspace(
string[i] ) ||
string[i] ==
'#' ||
string[i] ==
'\0' ) ) i++;
252 int len = strlen(
string );
254 while( !(
string[i] ==
'#' ||
string[i] ==
'\0' ) ) i++;
256 while( isspace(
string[i] ) )i--;
259 for(
int ii=i; ii<len; ii++ )
string[ii] =
'\0';
272 char tmp1[256], tmp2[256];
274 for( i=0; i<(int)strlen(str1); i++ ) tmp1[i] = tolower( str1[i] ); tmp1[i] =
'\0';
275 for( i=0; i<(int)strlen(str2); i++ ) tmp2[i] = tolower( str2[i] ); tmp2[i] =
'\0';
276 if( strcmp( tmp1, tmp2 ) == 0 )
287 if (!name)
return (0);
288 for ( p = q = name ; *p ; )
290 if ( ( p[0] ==
':' ) && ( p[1] ==
':' ) )
295 else if (p[0] ==
'/' || p[0]==
'\\' )
308 if (*p ==
'/') q = 0;
310 else if (*p ==
'\\') q = 0;
312 else if (*p ==
'.') q = p;
321 strlcpy(q,ext,buflen - (q - buf));
330 FILE *fc =
fopen( name,
"r" );
342 int ilen = strlen(name);
343 if( ilen == 0 )
return 0;
345 while( name[i] !=
'/' && name[i] !=
'\\' && name[i] !=
':' && i >= 0 )
361 int fn_len_s = strlen(filename);
362 int m_len_s = strlen(mode);
363 if( fn_len_s == 0 )
return NULL;
364 if( m_len_s == 0 )
return NULL;
365 wchar_t path[MAX_PATH];
366 wchar_t wmode[MAX_PATH];
368 int new_Len_f = MultiByteToWideChar(CP_UTF8, 0, filename, fn_len_s, path, fn_len_s);
369 if( new_Len_f >= MAX_PATH )
return NULL;
370 path[new_Len_f] = L
'\0';
372 int new_Len_m = MultiByteToWideChar(CP_UTF8, 0, mode, m_len_s, wmode, m_len_s);
373 if( new_Len_m >= MAX_PATH )
return NULL;
374 wmode[new_Len_m] = L
'\0';
376 return _wfopen(path, wmode);
378 return ::fopen(filename, mode);
385 int fn_len_s = strlen(f);
386 if( fn_len_s == 0 )
return 0;
387 wchar_t path[MAX_PATH];
389 int new_Len_f = MultiByteToWideChar(CP_UTF8, 0, f, fn_len_s, path, fn_len_s);
390 if( new_Len_f >= MAX_PATH )
return 0;
391 path[new_Len_f] = L
'\0';
393 return _wstat(path, (
struct _stat*)b);
401 static char date[100];
403 if( !
stat( name, & b ) )
405 strftime( date, 100,
"%d/%m/%Y %H:%M:%S", localtime( & b.st_mtime ) );
410 fprintf( stderr,
"filename_date Error\n" );
417 if (size <= 0)
return 0;
418 size_t len = strlen(s);
420 if (len >= size) len = size-1;
428 long lPos = ftell( stream );
439 while( iLen > 0 || cc[iLen+1] != EOF );
442 fseek( stream, lPos, SEEK_SET );
449 char cc , cc_old =
' ';
451 cc = fgetc( stream );
454 while ( cc !=
'\n' && cc != EOF && cc != 0xD )
456 if( ( isblank(cc_old) && !isblank(cc) ) )
463 else if( !isblank(cc) )
471 if( cc == 0xD) cc = fgetc( stream);
481 for(
int i=0; i<iLen; i++ )
483 if( !isblank(cc[i]) )
512 fscanf( ff,
"%s", value_x );
563 fscanf( ff,
"%s", value_x );
569 fscanf( ff,
"%d", value_x );
575 fscanf( ff,
"%ld", value_x );
581 fscanf( ff,
"%f", value_x );
587 fscanf( ff,
"%lf", value_x );
593 fscanf( ff,
"%Lf", value_x);
599 fscanf( ff,
"%lf%lf%lf", &vec->
x, &vec->
y, &vec->
z );
static void ReadStrL(FILE *stream, char *Par, int *len)
Function to read the string (Par) from FILE "stream". It reads from current pointer of FILE to the en...
static int ReadVect(FILE *stream, double *Par, int n, double dScal=1.)
Function to read double vector "Par" of "n" dimension from FILE "stream". The read values are scaled ...
static FILE * fopen(const char *filename, const char *mode)
Cross-platform function to fopen function that supports UTF-8 encoded name.
static void ClipFileName(char *string)
Clipping of the ending blanc characters of "string".
static const char * filename_date(const char *name)
Returns pointer to the string that contains the date of last file modification/creation.
static void Win2Unix(char *s)
conversion of directory separators - MS Windows to Unix
static int isstrblank(char *cc, int iLen)
Checks if string (cc) is blank (1/0)
static const char * filename_name(const char *name)
Returns pointer to filename without path.
static int nColumns(FILE *stream, char Par[][32])
Returns number of columns of text file (number of strings in the first line). Names of columns are st...
static int read(FILE *ff, char *value_x)
Pascal style "read" function to read string.
static char * filename_setext(char *buf, int buflen, const char *ext)
set/change filename extension
static int readln(FILE *ff, char *value_x)
Pascal style "readln" function to read string.
static int filename_dir(char *name)
returns the length of the path in (path)name
static int file_exist(const char *name)
Returns true (1) if file "name" does exist, 0 otherwise.
static int nLines(FILE *stream)
Returns number of lines of text file from current pointer to EOF.
static int stat(const char *f, struct stat *b)
Cross-platform function to stat() a file using a UTF-8 encoded name or value.
static int ReadComm(FILE *stream)
Function to read of a comment till the end of line. It returns 0 or EOF if it is performed.
static void ReadDummy(FILE *stream)
Function to read a comment line.
static int ReadVect3(FILE *stream, double *Par, double dScal=1.)
Function to read double vector "Par" of "3" dimension from FILE "stream". The read values are scaled ...
static void ClipString(char *string)
Clipping of the "string" up to the first blanc character or comment "#" character.
static int ReadStr(FILE *stream, char *Par)
Function to read the new line from FILE "stream" and to store it in table of char "Par"....
static int ReadPar(FILE *stream, const char *Format, void *Par)
Function to read one variable. The type of variable depends on Format, compatible with stdio library.
static void Unix2Win(char *s)
conversion of directory separators - Unix to MS Windows
static const char * filename_ext(const char *buf)
Returns pointer to filename extension.
static size_t strlcpy(char *d, const char *s, size_t bufsize)
The implementation of nonstandard strlcpy function.
static bool CompareStrings(char *str1, char *str2)
Compares two strings (str1 and str2). Returns true if they match, false otherwise.
Vector 3D class - vector manipulation.
void GetFrom(double xp, double yp, double zp)
sets coordinates from three variables
This file contains some smart I/O functions.