muMECH  1.0
librw.h
Go to the documentation of this file.
1 #ifndef GELIB_IO_H
2 #define GELIB_IO_H
3 
4 #include "gelib.h"
5 
6 #include <stdio.h>
7 
8 
15 #define _ARRAYS
16 
17 namespace gelibspace {
18 
19 class Dvctr;
20 
21 
23 bool get_confirm (const char *s, bool expected);
24 
25 
26 //* ********************************************************************************************
27 //* *** *** *** *** GENERAL FUNCTIONS *** *** *** ***
28 //* ********************************************************************************************
33 bool isWordChar (char C);
35 bool isLineChar (char C);
37 bool isSpaceChar (char C);
38 
40 long giveLineLength (const char *src);
41 
44 char* strdupl (const char *src);
45 char* strdupl (const char *src1, const char *src2);
46 char* strdupl (const char *src1, const char *src2, const char *src3);
47 char* pathstrdupl (const char *src);
48 
49 
50 void errorr_expected (const char* file, int line, const char *msg, const char *expctd, const char *src);
51 void errorr_expected (const char* file, int line, const char *msg, int expctd, const char *src);
52 void errorr_expected (const char* file, int line, const char *msg, long expctd, const char *src);
53 void errorr_expected (const char* file, int line, const char *msg, double expctd, const char *src);
54 
55 
56 
57 //* ********************************************************************************************
58 //* *** *** *** *** ARGUMENTS PROCESSING *** *** *** ***
59 //* ********************************************************************************************
61 long AP_find_option (int argc, char *argv[], const char *s);
63 void AP_fprint_arguments (FILE *stream, int argc, char *argv[]);
64 
65 
66 
67 //* ********************************************************************************************
68 //* *** *** *** *** FILE PROCESSING *** *** *** ***
69 //* ********************************************************************************************
71 bool FP_skip_comment (FILE *stream);
73 void FP_skip_line_commented (FILE *stream);
75 void FP_skip_line_fast_skip_commented (FILE *stream, int n=1);
77 bool FP_skip_line (FILE *stream, int n=1);
79 bool FP_skip_expected_string (FILE *src, const char *expctd, bool cs);
81 bool FP_skip_behind_line_starting_with (FILE *stream, const char *string, bool cs);
82 
84 bool FP_skip_to_line_starting_with (FILE *stream, const char *string, bool cs);
86 bool FP_skip_to_line_starting_With (FILE *stream, const char *string, bool cs);
87 
89 bool FP_skip_to_line_starting_with (FILE *stream, char C);
90 
92 void FP_copy_file (FILE *sour,FILE *dest);
94 bool FP_cmp_files (const char *file1, const char *file2);
95 
97 bool FP_copy_behind_line (FILE *sour, FILE *dest, int n=1);
99 bool FP_copy_behind_line_starting_with (FILE *src, FILE *dest, const char *expctd, bool cs);
100 
101 
102 
104 bool FP_scan_array (FILE *stream, int n, int *dest);
105 bool FP_scan_array (FILE *stream, int n, long *dest);
106 bool FP_scan_array (FILE *stream, int n, double *dest);
107 
109 long FP_number_of_words (FILE *stream);
111 long FP_number_of_lines (FILE *stream, bool rwd=false);
112 
113 
115 bool FP_skip_nonword (FILE *stream);
116 
118 bool FP_skip_space (FILE *stream);
119 
121 long FP_scan_line_skip_emptyORcommented (FILE *stream, char *dest);
122 
124 long FP_scan_line (FILE *stream, char *dest);
125 
127 long FP_scan_line_alloc (FILE *stream, char *&dest);
128 
130 int FP_scan_word (FILE *stream, char *dest);
131 
133 bool FP_scan_expected_word (FILE *src, const char *expctd, bool cs=true);
134 
136 void FP_scan_expected_word_FL (const char* file, int line, FILE *src, const char *expctd, const char *msg, bool cs);
137 #define FP_scan_expected_word_exit(_1,_2,_3,_4) FP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4)
138 void FP_scan_expected_line_FL (const char* file, int line, FILE *src, const char *expctd, const char *msg, bool cs);
140 #define FP_scan_expected_line_exit(_1,_2,_3,_4) FP_scan_expected_line_FL (__FILE__, __LINE__, _1,_2,_3,_4)
141 
142 
144 bool FP_scan_expected_number (FILE *src, long expctd);
145 
147 template <class ArgType>
148 void FP_scan_expected_number_FL (const char* file, int line, FILE *src, ArgType expctd, const char *msg)
149 {
150  if (!FP_scan_expected_number (src, expctd))
151  errorr_expected (file, line, msg, expctd, ""); // misto "" by tam mel byt retezec s prectenym cislem, casem to dodelej, asi budes muset predelat errorr_expected
152 }
153 #define FP_scan_expected_number_exit(_1,_2,_3) FP_scan_expected_number_FL (__FILE__, __LINE__, _1,_2,_3)
154 
155 
156 
157 
159 //void FP_scan_expected_long number (FILE *stream, ArgType expctd)
160 //{
161 // ArgType aux;
162 // SP_scan_number (src, aux);
163 // if (aux != expctd) return false;
164 // return true;
165 //
166 //fscanf (in, "%ld", &auxl); if ( auxl != -1) _errorr3 ("Invalid structure of the given UNV file: actual != expected -- %ld != %ld", -1, auxl);
167 //
168 //
169 //}
170 
171 
172 
173 //* ********************************************************************************************
174 //* *** *** *** *** STRING PROCESSING *** *** *** ***
175 //* ********************************************************************************************
176 
178 bool SP_cutcomment (char *src);
179 
181 bool SP_replace_char (char *str, char s, char d);
182 
183 //* *******************************************
184 //* *** *** *** SKIPING *** *** ***
185 //* *******************************************
187 
189 bool SP_skip_space (const char *&src);
191 bool SP_skip_word (const char *&src, int n=1);
193 bool SP_skip_int (const char *&src);
194 
195 
196 //* ********************************************
197 //* *** *** *** SCANNING *** *** ***
198 //* ********************************************
200 void SP_unscan_word (const char *&src, const char *w);
201 
203 
205 bool SP_scan_character (const char *&src, char &dest);
207 long SP_scan_word (const char *&src, char *dest);
209 long SP_scan_line (const char *&src, char *dest);
211 long SP_scan_line_alloc (const char *&src, char *&dest);
212 
214 bool SP_scan_expected_word (const char *&src, const char *expctd, bool cs=true);
215 
216 
217 
219 void SP_scan_expected_word_FL (const char* file, int line, const char *&src, const char *expctd, const char *msg, bool cs);
220 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);
221 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);
222 //
223 #define SP_scan_expected_word_exit( _1,_2,_3,_4) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4)
224 #define SP_scan_expected_word2_exit(_1,_2,_3,_4,_5) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4,_5)
225 #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)
226 
227 
228 
230 bool SP_scan_number (const char *&src, int &dest);
231 bool SP_scan_number (const char *&src, long &dest);
232 bool SP_scan_number (const char *&src, double &dest);
233 
235 template <class ArgType>
236 bool SP_scan_expected_number (const char *&src, ArgType expctd)
237 {
238  ArgType aux;
239  return (SP_scan_number (src, aux) && aux == expctd);
240 }
241 
243 template <class ArgType>
244 void SP_scan_expected_number_FL (const char* file, int line, const char *&src, ArgType expctd, const char *msg)
245 {
246  if (!SP_scan_expected_number (src, expctd))
247  errorr_expected (file, line, msg, expctd, src);
248 }
249 #define SP_scan_expected_number_exit(_1,_2,_3) SP_scan_expected_number_FL (__FILE__, __LINE__, _1,_2,_3)
250 
251 
253 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]); }
254 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]); }
255 
256 template <class ArgType>
257 bool SP_scan_array_alloc (const char *&src, long &n, ArgType *&a)
258 {
259  SP_scan_number (src, n);
260  a = new ArgType[n];
261  return SP_scan_array (src, n, a);
262 }
263 
265 bool SP_scan_array_L (const char *&src, int L, double *a);
267 
268 #ifdef _ARRAYS
269 bool SP_scan_Dvctr_exit (const char *&src, int n, Dvctr *v);
270 #endif
271 
272 
274 template <class ArgType>
275 bool SP_scan_Xvctr (const char *&src, ArgType *dest)
276 {
277  long n;
278  SP_scan_number (src, n);
279  dest->resize_ignore_vals(n);
280  return SP_scan_array (src, n, dest->give_ptr2val());
281 }
282 
283 
284 
285 //* ********************************************
286 //* *** *** *** PRINTING *** *** ***
287 //* ********************************************
289 
291 bool SP_print_space (const char *&src, FILE *stream);
293 bool SP_print_word (const char *&src, FILE *stream);
294 
295 
296 //* ********************************************************************************************
297 //* *** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
298 //* ********************************************************************************************
299 long find_double (long n, long* p);
300 
301 void sprint_param (char *s, char *argv[], int n);
302 
303 void read_star_end (FILE *stream,int n=1);
304 void read_star (FILE *stream);
306 
307 void copy_star_end (FILE *sour,FILE *dest,int n=1);
308 void copy_star (FILE *sour,FILE *dest);
309 
310 void copy_to_end_line (FILE *sour,FILE *dest);
311 
312 
313 int extract_long (const char *s1, const char *s2, long &a);
314 int extract_double (const char *s1, const char *s2, double &a);
315 
316 void extract_double_array (const char *s1, const char *s2, long n, double *a);
317 
318 void give_line (FILE *stream,char *&s);
319 void ad_line (FILE *stream,char *s);
320 
321 } // namespace gelibspace
322 
323 #endif // GELIB_IO_H
bool isLineChar(char C)
return true if character C is "normal" char or "space" char –> C != &#39; &#39; &#39;\0&#39; &#39;&#39;
Definition: librw.cpp:37
bool SP_print_word(const char *&src, FILE *stream)
... word
Definition: librw.cpp:756
void give_line(FILE *stream, char *&s)
bool FP_skip_expected_string(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:475
bool SP_cutcomment(char *src)
cut of comment == end of line starting by &#39;#&#39;
Definition: librw.cpp:543
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:156
void sprint_param(char *s, char *argv[], int n)
Definition: librw.cpp:782
long giveLineLength(const char *src)
return length of line == sting compount of "line chars"
Definition: librw.cpp:54
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:178
int extract_long(const char *s1, const char *s2, long &a)
Definition: librw.cpp:819
bool get_confirm(const char *s, bool expected)
Definition: librw.cpp:17
General functions.
bool isSpaceChar(char C)
return true if character C is "space" char –> C == &#39; &#39; &#39;&#39;
Definition: librw.cpp:43
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:518
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:64
void copy_to_end_line(FILE *sour, FILE *dest)
Definition: librw.cpp:811
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:829
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:244
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:647
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:253
void FP_copy_file(FILE *sour, FILE *dest)
[former copy_file]
Definition: librw.cpp:223
void FP_scan_expected_number_FL(const char *file, int line, FILE *src, ArgType expctd, const char *msg)
... number and compare with expected one, exit if false
Definition: librw.h:148
bool isWordChar(char C)
*** *** *** *** GENERAL FUNCTIONS *** *** *** *** return true if character C is "normal" char –> C...
Definition: librw.cpp:31
void extract_double_array(const char *s1, const char *s2, long n, double *a)
Definition: librw.cpp:838
bool SP_skip_space(const char *&src)
... space == &#39; &#39; and &#39;&#39; characters
Definition: librw.cpp:584
void AP_fprint_arguments(FILE *stream, int argc, char *argv[])
print arguments to stream
Definition: librw.cpp:117
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:313
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:709
bool FP_skip_comment(FILE *stream)
*** *** *** *** FILE PROCESSING *** *** *** *** general rules for file processing: ...
Definition: librw.cpp:141
long FP_number_of_words(FILE *stream)
count number of words (see isWordChar) in file
Definition: librw.cpp:319
long FP_scan_line(FILE *stream, char *dest)
scan/copy line == string without &#39; &#39; from stream
Definition: librw.cpp:420
void read_star(FILE *stream)
Definition: librw.cpp:793
void read_star_end(FILE *stream, int n)
Definition: librw.cpp:789
bool FP_skip_space(FILE *stream)
... space
Definition: librw.cpp:376
long FP_scan_line_alloc(FILE *stream, char *&dest)
scan/copy line == string without &#39; &#39; from stream; dest is NULL and allocated here ...
Definition: librw.cpp:439
bool SP_skip_int(const char *&src)
... word compound of digits and space before
Definition: librw.cpp:605
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
Definition: librw.cpp:714
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:537
bool FP_scan_expected_word(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:487
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:166
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; NO white space can ...
Definition: librw.cpp:212
void SP_unscan_word(const char *&src, const char *w)
*** *** *** SCANNING *** *** *** unscan word == shift pointer back over word
Definition: librw.cpp:623
long SP_scan_line(const char *&src, char *dest)
... line; return value is length of the line
Definition: librw.cpp:663
long find_double(long n, long *p)
*** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
Definition: librw.cpp:770
bool SP_scan_Dvctr_exit(const char *&src, int n, Dvctr *v)
Definition: librw.cpp:731
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:678
bool SP_replace_char(char *str, char s, char d)
replace src char to dest char
Definition: librw.cpp:556
bool SP_scan_Xvctr(const char *&src, ArgType *dest)
bool SP_scan_Dvctr (const char *&src, Dvctr *dest);
Definition: librw.h:275
bool FP_cmp_files(const char *file1, const char *file2)
Return false if no differences.
Definition: librw.cpp:230
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:192
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:108
bool SP_scan_array_L(const char *&src, int L, double *a)
Definition: librw.cpp:720
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:636
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; white space can be ...
Definition: librw.cpp:202
long FP_scan_line_skip_emptyORcommented(FILE *stream, char *dest)
*** *** *** SCANNING *** *** *** scanning == scan ...
Definition: librw.cpp:408
bool SP_print_space(const char *&src, FILE *stream)
*** *** *** PRINTING *** *** *** printing == print ...
Definition: librw.cpp:746
void copy_star_end(FILE *sour, FILE *dest, int n)
read line of file until , no save, dava bacha na EOF
Definition: librw.cpp:800
long FP_number_of_lines(FILE *stream, bool rwd)
count number of lines in file
Definition: librw.cpp:339
bool SP_scan_array_alloc(const char *&src, long &n, ArgType *&a)
Definition: librw.h:257
bool FP_copy_behind_line(FILE *sour, FILE *dest, int n)
copy from file to file behind the line [former copy_line]
Definition: librw.cpp:259
bool FP_copy_behind_line_starting_with(FILE *src, FILE *dest, const char *expctd, bool cs)
copy from file to file behind the line starting with string
Definition: librw.cpp:276
bool FP_skip_nonword(FILE *stream)
*** *** *** SKIPING *** *** *** skiping == shift stream pointer at the first char which is not ...
Definition: librw.cpp:363
bool SP_scan_expected_number(const char *&src, ArgType expctd)
... number and compare with expected one
Definition: librw.h:236
bool FP_scan_expected_number(FILE *src, long expctd)
... number and compare with expected one
Definition: librw.cpp:524
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:497
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:455
void ad_line(FILE *stream, char *s)
Definition: librw.cpp:846
bool SP_skip_word(const char *&src, int n)
... word and space before
Definition: librw.cpp:591
void copy_star(FILE *sour, FILE *dest)
Definition: librw.cpp:804
char * pathstrdupl(const char *src)
Definition: librw.cpp:84
bool SP_scan_expected_word(const char *&src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:699