14 #define CHECK_DEST if (!dest) _errorr("destination is not allocated") 19 fprintf(stdin,
"\n%s", s);
20 if (expected ==
true) fprintf (stdin,
" (Y or n): ");
21 else fprintf (stdin,
" (y or N): ");
23 scanf(
"%*c"); printf(
"\n");
33 return ( ( C ==
' ' || C ==
'\t' || C ==
'\n' || C ==
'\0' || C ==
'\r' || C == EOF) ?
false :
true);
39 return ( ( C ==
'\n' || C ==
'\0' || C ==
'\r' || C == EOF) ?
false :
true);
45 return ( ( C ==
' ' || C ==
'\t' ) ?
true :
false);
50 return ( ( C < 48 || C > 57 ) ?
false :
true);
66 if (src==NULL)
return NULL;
67 long len = strlen (src) + 1;
68 char *dest =
new char[len];
69 return (
char *) memcpy (dest, src, len);
71 char*
strdupl (
const char *src1,
const char *src2)
73 char *aux =
new char[strlen(src1) + strlen(src2) + 1];
74 sprintf (aux,
"%s%s", src1, src2);
77 char*
strdupl (
const char *src1,
const char *src2,
const char *src3)
79 char *aux =
new char[strlen(src1) + strlen(src2) + strlen(src3) + 1];
80 sprintf (aux,
"%s%s%s", src1, src2, src3);
86 long len = strlen (src) + 2;
87 char *dest =
new char[len];
88 memcpy (dest, src, len);
110 for (
int i=1; i<argc; i++)
119 fprintf (stream,
"\n Command line:");
120 fprintf (stream,
"\n %s ",argv[0]);
121 for (
int i=1;i<argc;i++)
122 fprintf (stream,
" %c",argv[i][0]);
124 fprintf (stream,
"\n options: ");
125 for (
int i=1;i<argc;i++)
126 fprintf (stream,
" %s",argv[i]);
128 fprintf (stream,
"\n\n");
146 if (c == EOF) { ungetc(c, stream);
return false; }
149 else { ungetc(c, stream);
return true; }
159 while ((c = getc(stream)) ==
'#')
171 if (c ==
'\n')
continue;
173 while ( getc(stream) !=
'\n') ;
184 if (c ==
'\n')
break;
185 if (c == EOF ) { ungetc(c, stream);
return false; }
226 while ((c = getc(sour)) != EOF) putc (c,dest);
232 FILE *f1 =
_openFileN (
"r",
"The first compared file", file1);
233 FILE *f2 =
_openFileN (
"r",
"The second compared file", file2);
247 if (c1 == EOF)
break;
265 if (c == EOF)
return false;
281 c = fgetc (src); ungetc(c, src);
282 if (c == EOF)
return false;
286 if (cs)
while (expctd[n] !=
'\0') { c = getc(src); fprintf (dest,
"%c", c);
if ( c != expctd[n] )
break; n++; }
287 else while (expctd[n] !=
'\0') { c = getc(src); fprintf (dest,
"%c", c);
if (tolower(c) != tolower(expctd[n]))
break; n++; }
292 if (expctd[n] ==
'\0')
return true;
302 while ( (c = fgetc (stream)) != C )
304 if (c == EOF ) { ungetc(c, stream);
return false; }
305 else c = fgetc(stream);
313 bool FP_scan_array (FILE *stream,
int n,
int *dest) {
while (n--)
if (fscanf (stream,
"%d", dest++) == 0)
return false;
return true; }
314 bool FP_scan_array (FILE *stream,
int n,
long *dest) {
while (n--)
if (fscanf (stream,
"%ld", dest++) == 0)
return false;
return true; }
315 bool FP_scan_array (FILE *stream,
int n,
double *dest) {
while (n--)
if (fscanf (stream,
"%lf", dest++) == 0)
return false;
return true; }
325 while ((c = getc(stream)) != EOF)
342 long lines = 0, fp = 0;
344 if (rwd) fp = ftell(stream);
346 while ((c = getc(stream)) != EOF)
350 if (rwd) fseek(stream, fp, SEEK_SET);
366 while ((c = getc(stream)) != EOF)
379 while ((c = getc(stream)) != EOF)
412 while ((c = getc(stream)) ==
'#' || c ==
'\n')
426 if (dest[n] == EOF) {
431 if (dest[n] ==
'\r') getc(stream);
441 if (dest)
_errorr(
"allocated");
446 dest =
new char[n+1];
449 while (i--) dest[i] = aux[i];
480 if (cs)
while (expctd[n] !=
'\0') { c = getc(src);
if ( c != expctd[n] ) { ungetc (c, src);
break; } n++; }
481 else while (expctd[n] !=
'\0') { c = getc(src);
if (tolower(c) != tolower(expctd[n])) { ungetc (c, src);
break; } n++; }
483 return (expctd[n] ==
'\0');
510 if (c ==
'\r') c = getc(src);
511 if (c == EOF) ungetc(c, src);
512 if (c ==
'\n')
return true;
527 return (fscanf (src,
"%ld", &aux) == 1 && aux == expctd);
537 void errorr_expected (
const char* file,
int line,
const char *msg,
const char *expctd,
const char *src) {
errorr (file, line,
"%s, expected \"%s\" != \"%s\"", msg, expctd, src); }
538 void errorr_expected (
const char* file,
int line,
const char *msg,
int expctd,
const char *src) {
errorr (file, line,
"%s, expected \"%d\" != \"%s\"", msg, expctd, src); }
539 void errorr_expected (
const char* file,
int line,
const char *msg,
long expctd,
const char *src) {
errorr (file, line,
"%s, expected \"%ld\" != \"%s\"", msg, expctd, src); }
540 void errorr_expected (
const char* file,
int line,
const char *msg,
double expctd,
const char *src) {
errorr (file, line,
"%s, expected \"%lf\" != \"%s\"", msg, expctd, src); }
546 if (*src !=
'#') src++;
548 while (*(--src) ==
' ') ;
560 while (*str !=
'\0') {
579 while (src[-1]==
' ' || src[-1]==
'\t') src--;
586 while (src[0]==
' ' || src[0]==
'\t') src++;
596 if (src[0]==
'\n' || src[0]==
'\0')
return false;
609 if (src[0]==
'\n' || src[0]==
'\0')
return false;
612 if (src[0]==
'+' || src[0]==
'-') src++;
630 while (n--)
if (src[n] != w[n])
_errorr (
"unscan error");
640 if (src[0]==
'\n' || src[0]==
'\0' || src[0]==
'\r')
643 dest = src[0]; src++;
655 strncpy (dest, src, n);
680 if (dest)
_errorr(
"allocated");
686 dest =
new char[n+1];
689 while (i--) dest[i] = src[i];
703 if (cs) {
while (expctd[++n] !=
'\0')
if ( src[n] != expctd[n] )
return false; }
704 else {
while (expctd[++n] !=
'\0')
if (tolower(src[n]) != tolower(expctd[n]))
return false; }
709 void SP_scan_expected_word_FL (
const char* file,
int line,
const char *&src,
const char *expctd,
const char *msg,
bool cs) {
if ( !
SP_scan_expected_word (src, expctd, cs))
errorr_expected (file, line, msg, expctd, src); }
710 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) {
if ( !
SP_scan_expected_word (src, expctd2, cs) && !
SP_scan_expected_word (src, expctd1, cs))
errorr (file, line,
"%s, expected \"%s\" or \"%s\" != \"%s\"", msg, expctd1, expctd2, src); }
711 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) {
if (!
SP_scan_expected_word (src, expctd3, cs) && !
SP_scan_expected_word (src, expctd2, cs) && !
SP_scan_expected_word (src, expctd1, cs))
errorr (file, line,
"%s, expected \"%s\" or \"%s\" or \"%s\" != \"%s\"", msg, expctd1, expctd2, expctd2, src); }
723 _warningg2 (
"The length of array of doubles is not \"%d\"", L);
749 fprintf (stream,
"%c", src[0]);
760 fprintf (stream,
"%c", src[0]);
775 for (j=i+1; j<n; j++)
776 if (p[i]==p[j])
return i+1;
784 ; sprintf (strchr(s,
'\0'),
" ");
785 while (n--) sprintf (strchr(s,
'\0'),
" %s", *(argv-n));
796 while ((c = getc (stream)) !=
'*' ) ;
807 while ((c = getc (sour)) !=
'*') putc (c,dest);
814 while ((c = getc (sour)) !=
'\n') putc (c,dest);
821 const char *ss = strstr (s1,s2);
822 if (ss==NULL)
return 1;
824 sscanf (ss,
"%ld",&a);
831 const char *ss = strstr (s1,s2);
832 if (ss==NULL)
return 1;
834 sscanf (ss,
"%lf",&a);
840 const char *ss = strstr (s1,s2);
852 while ((c = getc(stream)) !=
'\n') ss[i++] = c;
bool isLineChar(char C)
return true if character C is "normal" char or "space" char –> C != ' ' '\0' ''
bool SP_print_word(const char *&src, FILE *stream)
... word
bool FP_skip_expected_string(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
bool SP_cutcomment(char *src)
cut of comment == end of line starting by '#'
void FP_skip_line_commented(FILE *stream)
move file descriptor to the start of the new noncommented line, without checking of EOF ...
void sprint_param(char *s, char *argv[], int n)
Dvctr * resize_ignore_vals(long newsize)
long giveLineLength(const char *src)
return length of line == sting compount of "line chars"
bool FP_skip_line(FILE *stream, int n)
move file descriptor to the start of the n-th new line //[former read_line]
int extract_long(const char *s1, const char *s2, long &a)
bool get_confirm(const char *s, bool expected)
#define _openFileN(_1, _2, _3)
bool isSpaceChar(char C)
return true if character C is "space" char –> C == ' ' ''
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
bool FP_scan_expected_line(FILE *src, const char *expctd, bool cs)
... line and compare with expected one
char * strdupl(const char *src)
standard strdup - Memory for the new string is obtained with malloc(3), and can be freed with free(3)...
void copy_to_end_line(FILE *sour, FILE *dest)
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
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
bool FP_skip_word(FILE *stream)
... word
void FP_copy_file(FILE *sour, FILE *dest)
[former copy_file]
bool isWordChar(char C)
*** *** *** *** GENERAL FUNCTIONS *** *** *** *** return true if character C is "normal" char –> C...
void extract_double_array(const char *s1, const char *s2, long n, double *a)
bool SP_skip_space(const char *&src)
... space == ' ' and '' characters
void AP_fprint_arguments(FILE *stream, int argc, char *argv[])
print arguments to stream
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 ...
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
bool FP_skip_comment(FILE *stream)
*** *** *** *** FILE PROCESSING *** *** *** *** general rules for file processing: ...
long FP_number_of_words(FILE *stream)
count number of words (see isWordChar) in file
long FP_scan_line(FILE *stream, char *dest)
scan/copy line == string without ' ' from stream
void read_star(FILE *stream)
void read_star_end(FILE *stream, int n)
bool FP_skip_space(FILE *stream)
... space
Structs Elem3D, PoinT and VectoR; classes Array, Array1d, Xscal, Dscal, Xvctr, Lvctr, Dvctr, Xmtrx, Lmtrx and Dmtrx.
long FP_scan_line_alloc(FILE *stream, char *&dest)
scan/copy line == string without ' ' from stream; dest is NULL and allocated here ...
bool SP_skip_int(const char *&src)
... word compound of digits and space before
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
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...
bool FP_scan_expected_word(FILE *src, const char *expctd, bool cs)
... word and compare with expected one
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
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 ...
#define _warningg2(_1, _2)
void SP_unscan_word(const char *&src, const char *w)
*** *** *** SCANNING *** *** *** unscan word == shift pointer back over word
long SP_scan_line(const char *&src, char *dest)
... line; return value is length of the line
long find_double(long n, long *p)
*** *** *** *** OBSOLETE FUNCTIONS *** *** *** ***
bool SP_scan_Dvctr_exit(const char *&src, int n, Dvctr *v)
long SP_scan_line_alloc(const char *&src, char *&dest)
... line; return value is length of the line; dest is NULL and allocated here
bool SP_unskip_space(const char *&src)
*** *** *** SKIPING *** *** *** (un)skiping == shift src pointer at the end(start) of ...
bool SP_replace_char(char *str, char s, char d)
replace src char to dest char
bool FP_cmp_files(const char *file1, const char *file2)
Return false if no differences.
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 ...
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.
bool SP_scan_array_L(const char *&src, int L, double *a)
bool SP_scan_character(const char *&src, char &dest)
scanning == scan ... to variable dest and shift src pointer at the end of ...
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 ...
long FP_scan_line_skip_emptyORcommented(FILE *stream, char *dest)
*** *** *** SCANNING *** *** *** scanning == scan ...
bool SP_print_space(const char *&src, FILE *stream)
*** *** *** PRINTING *** *** *** printing == print ...
void copy_star_end(FILE *sour, FILE *dest, int n)
read line of file until , no save, dava bacha na EOF
long FP_number_of_lines(FILE *stream, bool rwd)
count number of lines in file
bool FP_copy_behind_line(FILE *sour, FILE *dest, int n)
copy from file to file behind the line [former copy_line]
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
bool FP_skip_nonword(FILE *stream)
*** *** *** SKIPING *** *** *** skiping == shift stream pointer at the first char which is not ...
bool SP_scan_expected_number(const char *&src, ArgType expctd)
... number and compare with expected one
bool FP_scan_expected_number(FILE *src, long expctd)
... number and compare with expected one
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
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
double * give_ptr2val(long i=0)
return pointer to
void ad_line(FILE *stream, char *s)
void errorr(const char *file, int line, const char *format,...)
*** *** *** *** ERROR FCE *** *** *** ***
bool SP_skip_word(const char *&src, int n)
... word and space before
void copy_star(FILE *sour, FILE *dest)
char * pathstrdupl(const char *src)
bool SP_scan_expected_word(const char *&src, const char *expctd, bool cs)
... word and compare with expected one