00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "qs_config.h"
00026 #include "float128_format.h"
00027 #include "float128_qsopt.h"
00028 #include "float128_iqsutil.h"
00029
00030 int float128_ILLformat_error_create (
00031 float128_qsformat_error * error,
00032 int mode,
00033 const char *desc,
00034 int lineNum,
00035 const char *theLine,
00036 int atPos)
00037 {
00038 int len;
00039 int rval = 0;
00040
00041 error->theLine = NULL;
00042 error->desc = NULL;
00043 error->next = NULL;
00044
00045 ILL_FAILtrue (desc == NULL, "non empty error desc please");
00046 ILL_FAILtrue (mode >= QS_INPUT_NERROR
00047 || mode < 0, "0<= mode <=QS_INPUT_NERROR");
00048 error->type = mode;
00049 len = strlen (desc);
00050 ILL_SAFE_MALLOC (error->desc, len + 1, char);
00051
00052 strcpy (error->desc, desc);
00053 error->lineNumber = lineNum;
00054 if (theLine != NULL)
00055 {
00056 len = strlen (theLine);
00057 ILL_SAFE_MALLOC (error->theLine, len + 2, char);
00058
00059 strcpy (error->theLine, theLine);
00060 if (error->theLine[len - 1] != '\n')
00061 {
00062 error->theLine[len] = '\n';
00063 error->theLine[len + 1] = '\0';
00064 }
00065 }
00066 error->at = atPos;
00067 CLEANUP:
00068 if (rval)
00069 {
00070 float128_ILLformat_error_delete (error);
00071 }
00072 return rval;
00073 }
00074
00075 void float128_ILLformat_error_delete (
00076 float128_qsformat_error * error)
00077 {
00078 ILL_IFFREE (error->desc, char);
00079 ILL_IFFREE (error->theLine, char);
00080 }
00081
00082 void float128_ILLformat_error_print (
00083 EGioFile_t * out,
00084 float128_qsformat_error * error)
00085 {
00086 int at = error->at;
00087 int tp = error->type;
00088 const char *type = "Error";
00089 const char *line = NULL;
00090 int i;
00091
00092 type = float128_QSformat_error_type_string (tp);
00093
00094 EGioPrintf (out, "%s line %d pos %d\n",
00095 type, float128_QSerror_get_line_number (error), at);
00096 line = float128_QSerror_get_line (error);
00097 if (line != NULL)
00098 {
00099 EGioPrintf (out, "LINE %s", line);
00100 if (at >= 0)
00101 {
00102 EGioPrintf (out, ".....");
00103 for (i = 0; i <= (at - 1); i++)
00104 {
00105 if (line[i] == '\t')
00106 {
00107 EGioPrintf(out, "\t");
00108 }
00109 else
00110 {
00111 EGioPrintf(out, ".");
00112 }
00113 }
00114 EGioPrintf (out, "^\n");
00115 }
00116 }
00117 else
00118 {
00119 EGioPrintf (out, "NO LINE\n");
00120 }
00121 EGioPrintf (out, "MSG: %s\n", float128_QSerror_get_desc (error));
00122 }
00123
00124
00125 float128_qserror_collector *float128_ILLerror_collector_new (
00126 float128_qsadd_error_fct fct,
00127 void *dest)
00128 {
00129 int rval = 0;
00130 float128_qserror_collector *c = NULL;
00131
00132 ILL_SAFE_MALLOC (c, 1, float128_qserror_collector);
00133 c->add_error = fct;
00134 c->dest = dest;
00135
00136 CLEANUP:
00137 if (rval)
00138 {
00139 ILL_IFFREE (c, float128_qserror_collector);
00140 }
00141 return c;
00142 }
00143
00144 float128_qserror_collector *float128_ILLerror_memory_collector_new (
00145 float128_qserror_memory * dest)
00146 {
00147 return float128_ILLerror_collector_new (float128_ILLadd_error_to_memory, dest);
00148 }
00149
00150 void float128_ILLerror_collector_free (
00151 float128_qserror_collector * c)
00152 {
00153 ILL_IFFREE (c, float128_qserror_collector);
00154 }
00155
00156 float128_qserror_memory *float128_ILLerror_memory_create (
00157 int takeErrorLines)
00158 {
00159 int rval = 0, i;
00160 float128_qserror_memory *mem = NULL;
00161
00162 ILL_SAFE_MALLOC (mem, 1, float128_qserror_memory);
00163 for (i = 0; i < QS_INPUT_NERROR; i++)
00164 {
00165 mem->has_error[i] = 0;
00166 }
00167 mem->error_list = NULL;
00168 mem->nerror = 0;
00169 mem->hasErrorLines = takeErrorLines;
00170 CLEANUP:
00171 return mem;
00172 }
00173
00174 void float128_ILLerror_memory_free (
00175 float128_qserror_memory * mem)
00176 {
00177 float128_qsformat_error *ths, *nxt;
00178
00179 if (mem != NULL)
00180 {
00181 ths = mem->error_list;
00182 while (ths != NULL)
00183 {
00184 nxt = ths->next;
00185 ILL_IFFREE (ths, float128_qsformat_error);
00186 ths = nxt;
00187 }
00188 ILL_IFFREE (mem, float128_qserror_memory);
00189 }
00190 }
00191
00192 int float128_ILLadd_error_to_memory (
00193 void *dest,
00194 const float128_qsformat_error * error)
00195 {
00196 int rval = 0;
00197 float128_qserror_memory *mem = (float128_qserror_memory *) dest;
00198 float128_qsformat_error *e = 0;
00199
00200 ILL_CHECKnull (mem, "must give non NULL float128_qserror_memory");
00201
00202 ILL_SAFE_MALLOC (e, 1, float128_qsformat_error);
00203 rval = float128_ILLformat_error_create (e, error->type, error->desc,
00204 error->lineNumber,
00205 (mem->hasErrorLines) ? error->theLine : NULL,
00206 error->at);
00207 ILL_CLEANUP_IF (rval);
00208 e->next = mem->error_list;
00209 mem->error_list = e;
00210 mem->nerror++;
00211 mem->has_error[error->type]++;
00212
00213 CLEANUP:
00214 if (rval)
00215 {
00216 float128_ILLformat_error_delete (e);
00217 ILL_IFFREE (e, float128_qsformat_error);
00218 }
00219 return rval;
00220 }