CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
iofun.h
Go to the documentation of this file.
1/*********************************************************************/
2/* */
3/* Config files library - (C) TGG 2015 */
4/* */
5/*********************************************************************/
6/* Warszawa, 2015 */
7/*********************************************************************/
8/* */
9/* File: iofun.h */
10/* */
11/* Author: T.Grabowski */
12/* */
13/* Contents - simple I/O functions class */
14/* */
15/* */
16/*********************************************************************/
17/* */
18/* */
19
24#ifndef _IOFUN_H_
25#define _IOFUN_H_
26
27#include <ctime>
28#include <cstdio>
29#include <cctype>
30#include <cstring>
31#include <sys/stat.h>
32
33#ifdef _WIN32
34#include <windows.h>
35#endif
36
37#include "vector3d.h"
38
40
41class IOFUN
42{
43 public:
44
46 static void Win2Unix(char *s);
48 static void Unix2Win(char *s);
49
51 static int ReadComm( FILE *stream );
53 static void ReadDummy( FILE *stream );
55 static int ReadPar( FILE *stream, const char *Format, void *Par );
57 static int ReadPar( FILE *stream, const char *Format, void *Par1, void *Par2);
59 static int ReadPar( FILE *stream, const char *Format, void *Par1, void *Par2, void *Par3);
61 static int ReadPar( FILE *stream, const char *Format, void *Par1, void *Par2, void *Par3, void *Par4 );
62
64 static int ReadVect3( FILE *stream, double *Par, double dScal = 1. );
66 static int ReadVect3( FILE *stream, float *Par, float fScal = 1. );
68 static int ReadVect3( FILE *stream, long *Par, long lScal = 1 );
70 static int ReadVect3( FILE *stream, int *Par, int iScal = 1 );
71
73 static int ReadVect( FILE *stream, double *Par, int n, double dScal = 1. );
75 static int ReadVect( FILE *stream, float *Par, int n, float fScal = 1. );
77 static int ReadVect( FILE *stream, long *Par, int n, long lScal = 1 );
79 static int ReadVect( FILE *stream, int *Par, int n, int iScal = 1 );
80
82 static int ReadStr( FILE *stream, char *Par );
84 static void ReadStrL( FILE *stream, char *Par, int *len );
86 static void ClipString( char *string );
88 static void ClipFileName( char* string );
90 static bool CompareStrings( char* str1, char* str2 );
91
93 static int file_exist( const char *name );
95 static const char* filename_name( const char *name );
97 static const char* filename_ext( const char *buf );
99 static char* filename_setext(char *buf, int buflen, const char *ext);
101 static int filename_dir( char *name );
103 static const char* filename_date( const char *name );
105 static FILE* fopen( const char*filename, const char*mode );
107 static int stat(const char* f, struct stat *b);
108
110 static size_t strlcpy(char *d, const char *s, size_t bufsize);
111
113 static int nLines( FILE * stream );
115 static int nColumns( FILE * stream, char Par[][32] );
117 static int isstrblank( char *cc, int iLen );
118
120 static void ReadVect3( FILE *stream, VECTOR_3D *Vec, double dScal = 1. );
121
123//
124// Pascal style "readln" and "read" functions
125// by P.Blaszczyk - modif. by TGG (2002)
126//
128
129// Pascal style "readln" functions
130
132 static int readln( FILE *ff, char *value_x );
134 static int readln( FILE *ff, int *value_x );
136 static int readln( FILE *ff, long *value_x );
138 static int readln( FILE *ff, float *value_x );
140 static int readln( FILE *ff, double *value_x );
142 static int readln( FILE *ff, long double *value_x );
144 static int readln( FILE *ff );
146 static int readln( FILE *ff, VECTOR_3D *vec );
147
148// Pascal style "read" functions
149
151 static int read( FILE *ff, char *value_x );
153 static int read( FILE *ff, int *value_x );
155 static int read( FILE *ff, long *value_x );
157 static int read( FILE *ff, float *value_x );
159 static int read( FILE *ff, double *value_x );
161 static int read( FILE *ff, long double *value_x );
163 static int read( FILE *ff, VECTOR_3D *vec );
164
165};
166
167#endif /*_IOFUN_H_*/
Simple I/O functions class.
Definition iofun.h:42
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...
Definition iofun.cpp:216
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 ...
Definition iofun.cpp:99
static FILE * fopen(const char *filename, const char *mode)
Cross-platform function to fopen function that supports UTF-8 encoded name.
Definition iofun.cpp:358
static void ClipFileName(char *string)
Clipping of the ending blanc characters of "string".
Definition iofun.cpp:250
static const char * filename_date(const char *name)
Returns pointer to the string that contains the date of last file modification/creation.
Definition iofun.cpp:399
static void Win2Unix(char *s)
conversion of directory separators - MS Windows to Unix
Definition iofun.cpp:25
static int isstrblank(char *cc, int iLen)
Checks if string (cc) is blank (1/0)
Definition iofun.cpp:476
static const char * filename_name(const char *name)
Returns pointer to filename without path.
Definition iofun.cpp:284
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...
Definition iofun.cpp:447
static int read(FILE *ff, char *value_x)
Pascal style "read" function to read string.
Definition iofun.cpp:561
static char * filename_setext(char *buf, int buflen, const char *ext)
set/change filename extension
Definition iofun.cpp:317
static int readln(FILE *ff, char *value_x)
Pascal style "readln" function to read string.
Definition iofun.cpp:510
static int filename_dir(char *name)
returns the length of the path in (path)name
Definition iofun.cpp:340
static int file_exist(const char *name)
Returns true (1) if file "name" does exist, 0 otherwise.
Definition iofun.cpp:327
static int nLines(FILE *stream)
Returns number of lines of text file from current pointer to EOF.
Definition iofun.cpp:426
static int stat(const char *f, struct stat *b)
Cross-platform function to stat() a file using a UTF-8 encoded name or value.
Definition iofun.cpp:382
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.
Definition iofun.cpp:42
static void ReadDummy(FILE *stream)
Function to read a comment line.
Definition iofun.cpp:50
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 ...
Definition iofun.cpp:143
static void ClipString(char *string)
Clipping of the "string" up to the first blanc character or comment "#" character.
Definition iofun.cpp:243
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"....
Definition iofun.cpp:163
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.
Definition iofun.cpp:67
static void Unix2Win(char *s)
conversion of directory separators - Unix to MS Windows
Definition iofun.cpp:33
static const char * filename_ext(const char *buf)
Returns pointer to filename extension.
Definition iofun.cpp:302
static size_t strlcpy(char *d, const char *s, size_t bufsize)
The implementation of nonstandard strlcpy function.
Definition iofun.cpp:415
static bool CompareStrings(char *str1, char *str2)
Compares two strings (str1 and str2). Returns true if they match, false otherwise.
Definition iofun.cpp:270
Vector 3D class - vector manipulation.
Definition vector3d.h:34
Vector 3D class and functions.