XALM  1.0
 Vše Třídy Prostory jmen Soubory Funkce Proměnné Výčty Hodnoty výčtu Friends Definice maker
librw.h
Zobrazit dokumentaci tohoto souboru.
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 //* ********************************************************************************************
22 //* *** *** *** *** GENERAL FUNCTIONS *** *** *** ***
23 //* ********************************************************************************************
28 bool isWordChar (char C);
30 bool isLineChar (char C);
32 bool isSpaceChar (char C);
33 
35 long giveLineLength (const char *src);
36 
39 char* strdupl (const char *src);
40 char* strdupl (const char *src1, const char *src2);
41 char* strdupl (const char *src1, const char *src2, const char *src3);
42 char* pathstrdupl (const char *src);
43 
44 
45 void errorr_expected (const char* file, int line, const char *msg, const char *expctd, const char *src);
46 void errorr_expected (const char* file, int line, const char *msg, int expctd, const char *src);
47 void errorr_expected (const char* file, int line, const char *msg, long expctd, const char *src);
48 void errorr_expected (const char* file, int line, const char *msg, double expctd, const char *src);
49 
50 
51 
52 //* ********************************************************************************************
53 //* *** *** *** *** ARGUMENTS PROCESSING *** *** *** ***
54 //* ********************************************************************************************
56 long AP_find_option (int argc, char *argv[], const char *s);
58 void AP_fprint_arguments (FILE *stream, int argc, char *argv[]);
59 
60 
61 
62 //* ********************************************************************************************
63 //* *** *** *** *** FILE PROCESSING *** *** *** ***
64 //* ********************************************************************************************
66 bool FP_skip_comment (FILE *stream);
68 void FP_skip_line_commented (FILE *stream);
70 void FP_skip_line_fast_skip_commented (FILE *stream, int n=1);
72 bool FP_skip_line (FILE *stream, int n=1);
74 bool FP_skip_expected_string (FILE *src, const char *expctd, bool cs);
76 bool FP_skip_behind_line_starting_with (FILE *stream, const char *string, bool cs);
77 
79 bool FP_skip_to_line_starting_with (FILE *stream, const char *string, bool cs);
81 bool FP_skip_to_line_starting_With (FILE *stream, const char *string, bool cs);
82 
84 bool FP_skip_to_line_starting_with (FILE *stream, char C);
85 
87 void FP_copy_file (FILE *sour,FILE *dest);
88 
90 bool FP_copy_behind_line (FILE *sour, FILE *dest, int n=1);
92 bool FP_copy_behind_line_starting_with (FILE *src, FILE *dest, const char *expctd, bool cs);
93 
94 
95 
97 bool FP_scan_array (FILE *stream, int n, int *dest);
98 bool FP_scan_array (FILE *stream, int n, long *dest);
99 bool FP_scan_array (FILE *stream, int n, double *dest);
100 
102 long FP_number_of_words (FILE *stream);
104 long FP_number_of_lines (FILE *stream, bool rwd=false);
105 
106 
108 bool FP_skip_nonword (FILE *stream);
109 
111 bool FP_skip_space (FILE *stream);
112 
114 long FP_scan_line_skip_emptyORcommented (FILE *stream, char *dest);
115 
117 long FP_scan_line (FILE *stream, char *dest);
118 
120 long FP_scan_line_alloc (FILE *stream, char *&dest);
121 
123 int FP_scan_word (FILE *stream, char *dest);
124 
126 bool FP_scan_expected_word (FILE *src, const char *expctd, bool cs=true);
127 
129 void FP_scan_expected_word_FL (const char* file, int line, FILE *src, const char *expctd, const char *msg, bool cs);
130 #define FP_scan_expected_word_exit(_1,_2,_3,_4) FP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4)
131 void FP_scan_expected_line_FL (const char* file, int line, FILE *src, const char *expctd, const char *msg, bool cs);
133 #define FP_scan_expected_line_exit(_1,_2,_3,_4) FP_scan_expected_line_FL (__FILE__, __LINE__, _1,_2,_3,_4)
134 
135 
137 bool FP_scan_expected_number (FILE *src, long expctd);
138 
140 template <class ArgType>
141 void FP_scan_expected_number_FL (const char* file, int line, FILE *src, ArgType expctd, const char *msg)
142 {
143  if (!FP_scan_expected_number (src, expctd))
144  errorr_expected (file, line, msg, expctd, ""); // misto "" by tam mel byt retezec s prectenym cislem, casem to dodelej, asi budes muset predelat errorr_expected
145 }
146 #define FP_scan_expected_number_exit(_1,_2,_3) FP_scan_expected_number_FL (__FILE__, __LINE__, _1,_2,_3)
147 
148 
149 
150 
152 //void FP_scan_expected_long number (FILE *stream, ArgType expctd)
153 //{
154 // ArgType aux;
155 // SP_scan_number (src, aux);
156 // if (aux != expctd) return false;
157 // return true;
158 //
159 //fscanf (in, "%ld", &auxl); if ( auxl != -1) _errorr3 ("Invalid structure of the given UNV file: actual != expected -- %ld != %ld", -1, auxl);
160 //
161 //
162 //}
163 
164 
165 
166 //* ********************************************************************************************
167 //* *** *** *** *** STRING PROCESSING *** *** *** ***
168 //* ********************************************************************************************
169 
171 bool SP_cutcomment (char *src);
172 
174 bool SP_replace_char (char *str, char s, char d);
175 
176 //* *******************************************
177 //* *** *** *** SKIPING *** *** ***
178 //* *******************************************
180 
182 bool SP_skip_space (const char *&src);
184 bool SP_skip_word (const char *&src, int n=1);
186 bool SP_skip_int (const char *&src);
187 
188 
189 //* ********************************************
190 //* *** *** *** SCANNING *** *** ***
191 //* ********************************************
193 void SP_unscan_word (const char *&src, const char *w);
194 
196 
198 bool SP_scan_character (const char *&src, char &dest);
200 long SP_scan_word (const char *&src, char *dest);
202 long SP_scan_line (const char *&src, char *dest);
204 long SP_scan_line_alloc (const char *&src, char *&dest);
205 
207 bool SP_scan_expected_word (const char *&src, const char *expctd, bool cs=true);
208 
209 
210 
212 void SP_scan_expected_word_FL (const char* file, int line, const char *&src, const char *expctd, const char *msg, bool cs);
213 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);
214 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);
215 //
216 #define SP_scan_expected_word_exit( _1,_2,_3,_4) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4)
217 #define SP_scan_expected_word2_exit(_1,_2,_3,_4,_5) SP_scan_expected_word_FL (__FILE__, __LINE__, _1,_2,_3,_4,_5)
218 #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)
219 
220 
221 
223 bool SP_scan_number (const char *&src, int &dest);
224 bool SP_scan_number (const char *&src, long &dest);
225 bool SP_scan_number (const char *&src, double &dest);
226 
228 template <class ArgType>
229 bool SP_scan_expected_number (const char *&src, ArgType expctd)
230 {
231  ArgType aux;
232  return (SP_scan_number (src, aux) && aux == expctd);
233 }
234 
236 template <class ArgType>
237 void SP_scan_expected_number_FL (const char* file, int line, const char *&src, ArgType expctd, const char *msg)
238 {
239  if (!SP_scan_expected_number (src, expctd))
240  errorr_expected (file, line, msg, expctd, src);
241 }
242 #define SP_scan_expected_number_exit(_1,_2,_3) SP_scan_expected_number_FL (__FILE__, __LINE__, _1,_2,_3)
243 
244 
246 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]); }
247 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]); }
248 
249 template <class ArgType>
250 bool SP_scan_array_alloc (const char *&src, long &n, ArgType *&a)
251 {
252  SP_scan_number (src, n);
253  a = new ArgType[n];
254  return SP_scan_array (src, n, a);
255 }
256 
258 bool SP_scan_array_L (const char *&src, int L, double *a);
260 
261 #ifdef _ARRAYS
262 bool SP_scan_Dvctr_exit (const char *&src, int n, Dvctr *v);
263 #endif
264 
265 
267 template <class ArgType>
268 bool SP_scan_Xvctr (const char *&src, ArgType *dest)
269 {
270  long n;
271  SP_scan_number (src, n);
272  dest->resize_ignore_vals(n);
273  return SP_scan_array (src, n, dest->give_ptr2val());
274 }
275 
276 
277 
278 //* ********************************************
279 //* *** *** *** PRINTING *** *** ***
280 //* ********************************************
282 
284 bool SP_print_space (const char *&src, FILE *stream);
286 bool SP_print_word (const char *&src, FILE *stream);
287 
288 
289 //* ********************************************************************************************
290 //* *** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
291 //* ********************************************************************************************
292 long find_double (long n, long* p);
293 
294 void sprint_param (char *s, char *argv[], int n);
295 
296 void read_star_end (FILE *stream,int n=1);
297 void read_star (FILE *stream);
299 
300 void copy_star_end (FILE *sour,FILE *dest,int n=1);
301 void copy_star (FILE *sour,FILE *dest);
302 
303 void copy_to_end_line (FILE *sour,FILE *dest);
304 
305 
306 int extract_long (const char *s1, const char *s2, long &a);
307 int extract_double (const char *s1, const char *s2, double &a);
308 
309 void extract_double_array (const char *s1, const char *s2, long n, double *a);
310 
311 void give_line (FILE *stream,char *&s);
312 void ad_line (FILE *stream,char *s);
313 
314 } // namespace gelibspace
315 
316 #endif // GELIB_IO_H
bool isLineChar(char C)
return true if character C is "normal" char or "space" char –> C != ' ' '\0' ''
Definition: librw.cpp:26
bool SP_print_word(const char *&src, FILE *stream)
... word
Definition: librw.cpp:717
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:436
bool SP_cutcomment(char *src)
cut of comment == end of line starting by '#'
Definition: librw.cpp:504
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 sprint_param(char *s, char *argv[], int n)
Definition: librw.cpp:743
long giveLineLength(const char *src)
return length of line == sting compount of "line chars"
Definition: librw.cpp:43
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
int extract_long(const char *s1, const char *s2, long &a)
Definition: librw.cpp:780
General functions.
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:479
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
void copy_to_end_line(FILE *sour, FILE *dest)
Definition: librw.cpp:772
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:790
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:237
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:608
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:246
void FP_copy_file(FILE *sour, FILE *dest)
[former copy_file]
Definition: librw.cpp:212
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:141
bool isWordChar(char C)
*** *** *** *** GENERAL FUNCTIONS *** *** *** *** return true if character C is "normal" char –> C...
Definition: librw.cpp:20
void extract_double_array(const char *s1, const char *s2, long n, double *a)
Definition: librw.cpp:799
bool SP_skip_space(const char *&src)
... space == ' ' and '' characters
Definition: librw.cpp:545
void AP_fprint_arguments(FILE *stream, int argc, char *argv[])
print arguments to stream
Definition: librw.cpp:106
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:274
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:670
bool FP_skip_comment(FILE *stream)
*** *** *** *** FILE PROCESSING *** *** *** *** general rules for file processing: ...
Definition: librw.cpp:130
long FP_number_of_words(FILE *stream)
count number of words (see isWordChar) in file
Definition: librw.cpp:280
long FP_scan_line(FILE *stream, char *dest)
scan/copy line == string without ' ' from stream
Definition: librw.cpp:381
void read_star(FILE *stream)
Definition: librw.cpp:754
void read_star_end(FILE *stream, int n)
Definition: librw.cpp:750
bool FP_skip_space(FILE *stream)
... space
Definition: librw.cpp:337
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:400
bool SP_skip_int(const char *&src)
... word compound of digits and space before
Definition: librw.cpp:566
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
Definition: librw.cpp:675
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:498
bool FP_scan_expected_word(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:448
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 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:201
void SP_unscan_word(const char *&src, const char *w)
*** *** *** SCANNING *** *** *** unscan word == shift pointer back over word
Definition: librw.cpp:584
long SP_scan_line(const char *&src, char *dest)
... line; return value is length of the line
Definition: librw.cpp:624
long find_double(long n, long *p)
*** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
Definition: librw.cpp:731
bool SP_scan_Dvctr_exit(const char *&src, int n, Dvctr *v)
Definition: librw.cpp:692
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:639
bool SP_replace_char(char *str, char s, char d)
replace src char to dest char
Definition: librw.cpp:517
bool SP_scan_Xvctr(const char *&src, ArgType *dest)
bool SP_scan_Dvctr (const char *&src, Dvctr *dest);
Definition: librw.h:268
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
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
bool SP_scan_array_L(const char *&src, int L, double *a)
Definition: librw.cpp:681
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:597
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:191
long FP_scan_line_skip_emptyORcommented(FILE *stream, char *dest)
*** *** *** SCANNING *** *** *** scanning == scan ...
Definition: librw.cpp:369
bool SP_print_space(const char *&src, FILE *stream)
*** *** *** PRINTING *** *** *** printing == print ...
Definition: librw.cpp:707
void copy_star_end(FILE *sour, FILE *dest, int n)
read line of file until , no save, dava bacha na EOF
Definition: librw.cpp:761
long FP_number_of_lines(FILE *stream, bool rwd)
count number of lines in file
Definition: librw.cpp:300
bool SP_scan_array_alloc(const char *&src, long &n, ArgType *&a)
Definition: librw.h:250
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:220
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:237
bool FP_skip_nonword(FILE *stream)
*** *** *** SKIPING *** *** *** skiping == shift stream pointer at the first char which is not ...
Definition: librw.cpp:324
bool SP_scan_expected_number(const char *&src, ArgType expctd)
... number and compare with expected one
Definition: librw.h:229
bool FP_scan_expected_number(FILE *src, long expctd)
... number and compare with expected one
Definition: librw.cpp:485
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:458
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:416
void ad_line(FILE *stream, char *s)
Definition: librw.cpp:807
bool SP_skip_word(const char *&src, int n)
... word and space before
Definition: librw.cpp:552
void copy_star(FILE *sour, FILE *dest)
Definition: librw.cpp:765
char * pathstrdupl(const char *src)
Definition: librw.cpp:73
bool SP_scan_expected_word(const char *&src, const char *expctd, bool cs)
... word and compare with expected one
Definition: librw.cpp:660