MIDAS  0.75
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
gelib.cpp
Go to the documentation of this file.
1 #include "gelib.h"
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 
7 
8 namespace midaspace {
9 
10 void errorr (const char* file, int line, const char *format, ...)
11 {
12  char buffer[MAX_MSG_LENGTH];
13  va_list args;
14 
15  va_start(args, format);
16  vsprintf(buffer, format, args);
17  va_end(args);
18 
19  fflush (stdout);
20  CHANGE_CONSOLE_COLOUR(stderr, TC_D_RED); fprintf (stderr,"\n\n ERROR: %s", buffer);
21  CHANGE_CONSOLE_COLOUR(stderr, TC_DEFAULT); fprintf (stderr," (%s:%d). !!!\n\n", file, line);
22 
23  throw (201);
24 }
25 
26 void warningg (const char* file, int line, const char *format, ...)
27 {
28  char buffer[MAX_MSG_LENGTH];
29  va_list args;
30 
31  va_start(args, format);
32  vsprintf(buffer, format, args);
33  va_end(args);
34 
35  fflush (stdout);
36  CHANGE_CONSOLE_COLOUR(stderr, TC_D_VIOLET); fprintf (stderr,"\n\n WARNING: %s", buffer);
37  CHANGE_CONSOLE_COLOUR(stderr, TC_DEFAULT); fprintf (stderr," (%s:%d). !!!\n\n", file, line);
38 }
39 
40 // void error (const char *fil, const long lin, const char *str)
41 // {
42 // fprintf (stderr,"\n\n !!! %s (%s, line %ld). !!!\n",str,fil,lin);
43 // exit (1001);
44 // }
45 //
46 // void error2 (const char *fil, const long lin, const char *str, const long l, const int ex)
47 // {
48 // fprintf (stderr,"\n\n !!! %s %ld (%s, line %ld). !!!\n\n",str,l,fil,lin);
49 // if (ex) exit (1002);
50 // }
51 //
52 // void warning (const char *fil, const long lin, const char *str)
53 // {
54 // fprintf (stderr,"\n\n WARNING: %s (%s, line %ld). !!!\n",str,fil,lin);
55 // }
56 
57 //* ********************************************************************************************
58 //* *** *** *** *** FILE FCE *** *** *** ***
59 //* ********************************************************************************************
60 
61 void openFileTest (const FILE *stream,const char *name)
62 {
63  if (stream == NULL)
64  _errorr2 ("File has not been opened: %s\n Try it again", name);
65 }
66 
67 FILE* openFileN (const char* File, int Line, const char *mode, const char *key, const char *name)
68 {
69  FILE *f = fopen (name, mode);
70 
71  if (f == NULL) errorr (File, Line, "\"%s\" file has not been opened: %s\n Try it again", key, name);
72 
73  return f;
74 }
75 
76 
77 FILE* openFilePN (const char* File, int Line, const char *mode, const char *key, const char *path, const char *name)
78 {
79  char file[255];
80  if (path) sprintf (file, "%s%s", path, name);
81  else sprintf (file, "%s", name);
82 
83  return openFileN (File, Line, mode, key, file);
84 }
85 
86 FILE* openFilePNS (const char* File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff)
87 {
88  char file[255];
89  if (path) sprintf (file, "%s%s%s", path, name, suff);
90  else sprintf (file, "%s%s", name, suff);
91 
92  return openFileN (File, Line, mode, key, file);
93 }
94 
95 FILE* openFilePNSS (const char* File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff, const char *suff2)
96 {
97  char file[255];
98  if (path) sprintf (file, "%s%s%s%s", path, name, suff, suff2);
99  else sprintf (file, "%s%s%s", name, suff, suff2);
100 
101  return openFileN (File, Line, mode, key, file);
102 }
103 
104 } // namespace midaspace
void errorr(const char *file, int line, const char *format,...)
*** *** *** *** ERROR FCE *** *** *** ***
Definition: gelib.cpp:10
#define CHANGE_CONSOLE_COLOUR(_1, _2)
Definition: gelib.h:126
#define TC_D_RED
Definition: gelib.h:71
#define TC_D_VIOLET
Definition: gelib.h:79
General functions.
#define MAX_MSG_LENGTH
Definition: gelib.h:20
FILE * openFilePNSS(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff, const char *suff2)
Definition: gelib.cpp:95
FILE * openFileN(const char *File, int Line, const char *mode, const char *key, const char *name)
Definition: gelib.cpp:67
#define _errorr2(_1, _2)
Definition: gelib.h:145
void openFileTest(const FILE *stream, const char *name)
*** *** *** *** FILE FCE *** *** *** ***
Definition: gelib.cpp:61
#define TC_DEFAULT
Definition: gelib.h:85
FILE * openFilePNS(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff)
Definition: gelib.cpp:86
FILE * openFilePN(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name)
Definition: gelib.cpp:77
void warningg(const char *file, int line, const char *format,...)
Definition: gelib.cpp:26