MIDAS  0.75
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
librw.h
Go to the documentation of this file.
1 #ifndef MIDAS_IO_H
2 #define MIDAS_IO_H
3 
4 #include "gelib.h"
5 
6 #include <stdio.h>
7 
8 
15 namespace midaspace {
16 
17 class Dvctr;
18 
19 //* ********************************************************************************************
20 //* *** *** *** *** GENERAL FUNCTIONS *** *** *** ***
21 //* ********************************************************************************************
26 bool isWordChar (char C);
28 bool isLineChar (char C);
30 bool isSpaceChar (char C);
31 
33 long giveLineLength (const char *src);
34 
37 char* strdupl (const char *src);
38 char* strdupl (const char *src1, const char *src2);
39 char* strdupl (const char *src1, const char *src2, const char *src3);
40 char* pathstrdupl (const char *src);
41 
42 //* ********************************************************************************************
43 //* *** *** *** *** ARGUMENTS PROCESSING *** *** *** ***
44 //* ********************************************************************************************
46 long AP_find_option (int argc, char *argv[], const char *s);
48 void AP_fprint_arguments (FILE *stream, int argc, char *argv[]);
49 
50 
51 
52 //* ********************************************************************************************
53 //* *** *** *** *** FILE PROCESSING *** *** *** ***
54 //* ********************************************************************************************
56 bool FP_skip_comment (FILE *stream);
58 void FP_skip_line_commented (FILE *stream);
60 void FP_skip_line_fast_skip_commented (FILE *stream, int n=1);
62 bool FP_skip_line (FILE *stream, int n=1);
64 bool FP_skip_expected_string (FILE *src, const char *expctd, bool cs);
66 bool FP_skip_behind_line_starting_with (FILE *stream, const char *string, bool cs);
68 bool FP_skip_to_line_starting_with (FILE *stream, const char *string, bool cs);
70 bool FP_skip_to_line_starting_with (FILE *stream, char C);
71 
72 
74 bool FP_scan_array (FILE *stream, int n, int *dest);
75 bool FP_scan_array (FILE *stream, int n, long *dest);
76 bool FP_scan_array (FILE *stream, int n, double *dest);
77 
79 long FP_number_of_words (FILE *stream);
81 long FP_number_of_lines (FILE *stream, bool rwd=false);
82 
83 
85 bool FP_skip_nonword (FILE *stream);
86 
88 bool FP_skip_space (FILE *stream);
89 
91 long FP_scan_line_skip_emptyORcommented (FILE *stream, char *dest);
92 
94 long FP_scan_line (FILE *stream, char *dest);
95 
97 long FP_scan_line_alloc (FILE *stream, char *&dest);
98 
100 int FP_scan_word (FILE *stream, char *dest);
101 
103 bool FP_scan_expected_word (FILE *src, const char *expctd, bool cs=true);
104 
106 void FP_scan_expected_word_FL (const char* file, int line, FILE *src, const char *expctd, const char *msg, bool cs);
107 #define FP_scan_expected_word_exit(_1,_2,_3,_4) FP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4)
108 void FP_scan_expected_line_FL (const char* file, int line, FILE *src, const char *expctd, const char *msg, bool cs);
110 #define FP_scan_expected_line_exit(_1,_2,_3,_4) FP_scan_expected_line_FL (__FILE__, __LINE__, _1,_2,_3,_4)
111 
112 
113 
115 //bool FP_scan_expected_number (FILE *src, long expctd)
116 //{
117 // long aux;
118 // fscanf (src, "%ld", &aux);
119 // if (aux != expctd) return false;
120 // return true;
121 //}
122 //
124 //template <class ArgType>
125 //void FP_scan_expected_number_FL (const char* file, int line, FILE *src, ArgType expctd, const char *msg)
126 //{
127 // if (!FP_scan_expected_number (src, expctd))
128 // errorr_expected (file, line, msg, expctd, src);
129 //}
130 //#define FP_scan_expected_number_exit(_1,_2,_3) FP_scan_expected_number_FL (__FILE__, __LINE__, _1,_2,_3)
131 
132 
133 
134 
136 //void FP_scan_expected_long number (FILE *stream, ArgType expctd)
137 //{
138 // ArgType aux;
139 // SP_scan_number (src, aux);
140 // if (aux != expctd) return false;
141 // return true;
142 //
143 //fscanf (in, "%ld", &auxl); if ( auxl != -1) _errorr3 ("Invalid structure of the given UNV file: actual != expected -- %ld != %ld", -1, auxl);
144 //
145 //
146 //}
147 
148 
149 
150 //* ********************************************************************************************
151 //* *** *** *** *** STRING PROCESSING *** *** *** ***
152 //* ********************************************************************************************
153 void errorr_expected (const char* file, int line, const char *msg, const char *expctd, const char *src);
154 void errorr_expected (const char* file, int line, const char *msg, int expctd, const char *src);
155 void errorr_expected (const char* file, int line, const char *msg, long expctd, const char *src);
156 
158 bool SP_cutcomment (char *src);
159 
160 
161 //* *******************************************
162 //* *** *** *** SKIPING *** *** ***
163 //* *******************************************
165 
167 bool SP_skip_space (const char *&src);
169 bool SP_skip_word (const char *&src, int n=1);
171 bool SP_skip_int (const char *&src);
172 
173 
174 //* ********************************************
175 //* *** *** *** SCANNING *** *** ***
176 //* ********************************************
178 void SP_unscan_word (const char *&src, const char *w);
179 
181 
183 bool SP_scan_character (const char *&src, char &dest);
185 long SP_scan_word (const char *&src, char *dest);
187 long SP_scan_line (const char *&src, char *dest);
189 long SP_scan_line_alloc (const char *&src, char *&dest);
190 
192 bool SP_scan_expected_word (const char *&src, const char *expctd, bool cs=true);
193 
194 
195 
197 void SP_scan_expected_word_FL (const char* file, int line, const char *&src, const char *expctd, const char *msg, bool cs);
198 void SP_scan_expected_word_FL (const char* file, int line, const char *&src, const char *expctd1, const char *expctd2, const char *msg, bool cs);
199 void SP_scan_expected_word_FL (const char* file, int line, const char *&src, const char *expctd1, const char *expctd2, const char *expctd3, const char *msg, bool cs);
200 //
201 #define SP_scan_expected_word_exit( _1,_2,_3,_4) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4)
202 #define SP_scan_expected_word2_exit(_1,_2,_3,_4,_5) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4,_5)
203 #define SP_scan_expected_word3_exit(_1,_2,_3,_4,_5,_6) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4,_5,_6)
204 
205 
206 
208 bool SP_scan_number (const char *&src, int &dest);
209 bool SP_scan_number (const char *&src, long &dest);
210 bool SP_scan_number (const char *&src, double &dest);
211 
213 template <class ArgType>
214 bool SP_scan_expected_number (const char *&src, ArgType expctd)
215 {
216  ArgType aux;
217  SP_scan_number (src, aux);
218  if (aux != expctd) return false;
219  return true;
220 }
221 
223 template <class ArgType>
224 void SP_scan_expected_number_FL (const char* file, int line, const char *&src, ArgType expctd, const char *msg)
225 {
226  if (!SP_scan_expected_number (src, expctd))
227  errorr_expected (file, line, msg, expctd, src);
228 }
229 #define SP_scan_expected_number_exit(_1,_2,_3) SP_scan_expected_number_FL (__FILE__, __LINE__, _1,_2,_3)
230 
231 
233 template <class ArgType> bool SP_scan_array (const char *&src, int n, ArgType *a) { while (--n) SP_scan_number (src, (a++)[0]); return SP_scan_number (src, a[0]); }
234 template <class ArgType> bool SP_scan_array (const char *&src, long n, ArgType *a) { while (--n) SP_scan_number (src, (a++)[0]); return SP_scan_number (src, a[0]); }
235 
236 template <class ArgType>
237 bool SP_scan_array_alloc (const char *&src, long &n, ArgType *&a)
238 {
239  SP_scan_number (src, n);
240  a = new ArgType[n];
241  return SP_scan_array (src, n, a);
242 }
243 
245 bool SP_scan_array_L (const char *&src, int L, double *a);
247 
248 
249 bool SP_scan_Dvctr_exit (const char *&src, int n, Dvctr *dest);
251 template <class ArgType>
252 bool SP_scan_Xvctr (const char *&src, ArgType *dest)
253 {
254  long n;
255  SP_scan_number (src, n);
256  dest->resize_ignore_vals(n);
257  return SP_scan_array (src, n, dest->give_ptr2val());
258 }
259 
260 
261 
262 //* ********************************************
263 //* *** *** *** PRINTING *** *** ***
264 //* ********************************************
266 
268 bool SP_print_space (const char *&src, FILE *stream);
270 bool SP_print_word (const char *&src, FILE *stream);
271 
272 
273 //* ********************************************************************************************
274 //* *** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
275 //* ********************************************************************************************
276 long find_double (long n, long* p);
277 
278 void sprint_param (char *s, char *argv[], int n);
279 
280 void read_star_end (FILE *stream,int n=1);
281 void read_star (FILE *stream);
283 
284 void copy_star_end (FILE *sour,FILE *dest,int n=1);
285 void copy_star (FILE *sour,FILE *dest);
286 void copy_line (FILE *sour,FILE *dest,int n=1);
287 
288 void copy_to_end_line (FILE *sour,FILE *dest);
289 void copy_file (FILE *sour,FILE *dest);
290 
291 int extract_long (const char *s1, const char *s2, long &a);
292 int extract_double (const char *s1, const char *s2, double &a);
293 
294 void extract_double_array (const char *s1, const char *s2, long n, double *a);
295 
296 void give_line (FILE *stream,char *&s);
297 void ad_line (FILE *stream,char *s);
298 
299 } // namespace midaspace
300 
301 #endif // MIDAS_IO_H
char * strdupl(const char *src)
standard strdup - Memory for the new string is obtained with malloc(3), and can be freed with free(3)...
Definition: librw.cpp:53
bool FP_skip_to_line_starting_with(FILE *stream, const char *string, bool cs)
move file descriptor to the line starting with string, exactly behind the string
Definition: librw.cpp:190
void SP_unscan_word(const char *&src, const char *w)
*** *** *** SCANNING *** *** *** unscan word == shift pointer back over word
Definition: librw.cpp:504
void ad_line(FILE *stream, char *s)
Definition: librw.cpp:728
void give_line(FILE *stream, char *&s)
bool SP_print_word(const char *&src, FILE *stream)
... word
Definition: librw.cpp:635
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:356
bool SP_print_space(const char *&src, FILE *stream)
*** *** *** PRINTING *** *** *** printing == print ...
Definition: librw.cpp:625
void FP_skip_line_commented(FILE *stream)
move file descriptor to the start of the new noncommented line, without checking of EOF ...
Definition: librw.cpp:145
void FP_skip_line_fast_skip_commented(FILE *stream, int n)
move file descriptor to the start of the n-th new line, without checking of EOF
Definition: librw.cpp:155
bool SP_scan_expected_number(const char *&src, ArgType expctd)
... number and compare with expected one
Definition: librw.h:214
General functions.
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:528
long FP_number_of_lines(FILE *stream, bool rwd)
count number of lines in file
Definition: librw.cpp:240
long find_double(long n, long *p)
*** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
Definition: librw.cpp:649
void copy_star(FILE *sour, FILE *dest)
Definition: librw.cpp:683
long FP_scan_line_skip_emptyORcommented(FILE *stream, char *dest)
*** *** *** SCANNING *** *** *** scanning == scan ...
Definition: librw.cpp:309
void sprint_param(char *s, char *argv[], int n)
Definition: librw.cpp:661
bool SP_skip_word(const char *&src, int n)
... word and space before
Definition: librw.cpp:472
void errorr_expected(const char *file, int line, const char *msg, const char *expctd, const char *src)
*** *** *** *** STRING PROCESSING *** *** *** *** src pointer is always shifted over the skipped/sc...
Definition: librw.cpp:433
void read_star(FILE *stream)
Definition: librw.cpp:672
char * pathstrdupl(const char *src)
Definition: librw.cpp:73
bool isLineChar(char C)
return true if character C is "normal" char or "space" char –> C != ' ' '\0' '' ...
Definition: librw.cpp:26
long FP_number_of_words(FILE *stream)
count number of words (see isWordChar) in file
Definition: librw.cpp:220
long SP_scan_line(const char *&src, char *dest)
... line; return value is length of the line
Definition: librw.cpp:544
long SP_scan_line_alloc(const char *&src, char *&dest)
... line; return value is length of the line; dest is NULL and allocated here
Definition: librw.cpp:559
long giveLineLength(const char *src)
return length of line == sting compount of "line chars"
Definition: librw.cpp:43
void FP_scan_expected_word_FL(const char *file, int line, FILE *src, const char *expctd, const char *msg, bool cs)
... word and compare with expected one, exit if false
Definition: librw.cpp:398
void copy_file(FILE *sour, FILE *dest)
Definition: librw.cpp:702
bool isWordChar(char C)
*** *** *** *** GENERAL FUNCTIONS *** *** *** *** return true if character C is "normal" char –> C...
Definition: librw.cpp:20
bool SP_scan_Dvctr_exit(const char *&src, int n, Dvctr *v)
Definition: librw.cpp:611
bool FP_skip_line(FILE *stream, int n)
move file descriptor to the start of the n-th new line //[former read_line]
Definition: librw.cpp:167
long FP_scan_line(FILE *stream, char *dest)
scan/copy line == string without ' ' from stream
Definition: librw.cpp:321
bool SP_skip_space(const char *&src)
... space == ' ' and '' characters
Definition: librw.cpp:465
void copy_line(FILE *sour, FILE *dest, int n)
Definition: librw.cpp:689
void SP_scan_expected_word_FL(const char *file, int line, const char *&src, const char *expctd, const char *msg, bool cs)
... word and compare with expected one/two/three, exit if false
Definition: librw.cpp:590
bool SP_scan_character(const char *&src, char &dest)
scanning == scan ... to variable dest and shift src pointer at the end of ...
Definition: librw.cpp:517
void copy_star_end(FILE *sour, FILE *dest, int n)
read line of file until , no save, dava bacha na EOF
Definition: librw.cpp:679
bool FP_skip_expected_string(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:376
bool FP_skip_space(FILE *stream)
... space
Definition: librw.cpp:277
bool FP_skip_behind_line_starting_with(FILE *stream, const char *string, bool cs)
move file descriptor to the start of the new line after the one starting with string ...
Definition: librw.cpp:181
void read_star_end(FILE *stream, int n)
Definition: librw.cpp:668
bool SP_scan_array_L(const char *&src, int L, double *a)
Definition: librw.cpp:601
bool FP_skip_nonword(FILE *stream)
*** *** *** SKIPING *** *** *** skiping == shift stream pointer at the first char which is not ...
Definition: librw.cpp:264
bool SP_scan_expected_word(const char *&src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:580
void copy_to_end_line(FILE *sour, FILE *dest)
Definition: librw.cpp:695
bool SP_skip_int(const char *&src)
... word compound of digits and space before
Definition: librw.cpp:486
int extract_double(const char *s1, const char *s2, double &a)
v retezci s1 se najde key retezec s2 a za nim se precte double
Definition: librw.cpp:718
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:233
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
Definition: librw.cpp:595
int extract_long(const char *s1, const char *s2, long &a)
Definition: librw.cpp:708
bool SP_scan_array_alloc(const char *&src, long &n, ArgType *&a)
Definition: librw.h:237
long AP_find_option(int argc, char *argv[], const char *s)
*** *** *** *** ARGUMENTS PROCESSING *** *** *** *** terminology: tar -cz -f archiv.tgz archiv/ /// fce name | arguments /// fce name | options | parameters /// fce name | opt | opt | opt argum.
Definition: librw.cpp:97
void SP_scan_expected_number_FL(const char *file, int line, const char *&src, ArgType expctd, const char *msg)
... number and compare with expected one, exit if false
Definition: librw.h:224
long FP_scan_line_alloc(FILE *stream, char *&dest)
scan/copy line == string without ' ' from stream; dest is NULL and allocated here ...
Definition: librw.cpp:340
bool SP_cutcomment(char *src)
cut of comment == end of line starting by '#'
Definition: librw.cpp:438
bool SP_scan_Xvctr(const char *&src, ArgType *dest)
bool SP_scan_Dvctr (const char *&src, Dvctr *dest);
Definition: librw.h:252
void extract_double_array(const char *s1, const char *s2, long n, double *a)
bool FP_scan_array(FILE *stream, int n, int *dest)
scan/copy array of numbers from src to dest, src pointer is shifted over the field ...
Definition: librw.cpp:214
bool isSpaceChar(char C)
return true if character C is "space" char –> C == ' ' ''
Definition: librw.cpp:32
void FP_scan_expected_line_FL(const char *file, int line, FILE *src, const char *expctd, const char *msg, bool cs)
... line and compare with expected one, exit if false
Definition: librw.cpp:419
bool FP_scan_expected_word(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:388
void AP_fprint_arguments(FILE *stream, int argc, char *argv[])
print arguments to stream
Definition: librw.cpp:106
bool FP_skip_comment(FILE *stream)
*** *** *** *** FILE PROCESSING *** *** *** *** general rules for file processing: ...
Definition: librw.cpp:130