00001 #include <stdio.h>
00002 #include "vapiTypes.h"
00003 #include "vapiResult.h"
00004 #include "vapiAux.h"
00005 #include "vapiMacro.h"
00006 vMacroResult *
00007 vapiMacroResultInit ()
00008 {
00009 vMacroResult *PreviousResult;
00010 PreviousResult = malloc (sizeof (vMacroResult));
00011 PreviousResult->Decision = vFALSE;
00012 PreviousResult->End = vFALSE;
00013 PreviousResult->JumpTo = -1;
00014 PreviousResult->intsNumber = 0;
00015 PreviousResult->floatsNumber = 0;
00016 PreviousResult->pointsNumber = 0;
00017 PreviousResult->charsNumber = 0;
00018 PreviousResult->macroTag = NULL;
00019 return PreviousResult;
00020
00021 }
00022
00023 void
00024 vapiResultAddInt (vMacroResult * PreviousResult, int value)
00025 {
00026 int *intsPtr;
00027
00028 if (PreviousResult->intsNumber == 0)
00029 {
00030 PreviousResult->ints =
00031 malloc ((++PreviousResult->intsNumber) *
00032 sizeof (int));
00033
00034 }
00035 else
00036 {
00037 intsPtr =
00038 realloc (PreviousResult->ints,
00039 (++PreviousResult->intsNumber) *
00040 sizeof (int));
00041
00042 PreviousResult->ints = intsPtr;
00043 }
00044 PreviousResult->ints[PreviousResult->intsNumber - 1] = value;
00045
00046 }
00047
00048 void
00049 vapiResultAddPoint (vMacroResult * PreviousResult, int x, int y)
00050 {
00051 vPoint *PointPtr;
00052
00053 if (PreviousResult->pointsNumber == 0)
00054 {
00055 PreviousResult->pointsNumber++;
00056
00057 PreviousResult->points =
00058 malloc (PreviousResult->pointsNumber *
00059 sizeof (vPoint));
00060
00061 }
00062 else
00063 {
00064 PointPtr =
00065 realloc (PreviousResult->points,
00066 (++PreviousResult->pointsNumber) *
00067 sizeof (vPoint));
00068 PreviousResult->points = PointPtr;
00069 }
00070 PreviousResult->points[PreviousResult->pointsNumber - 1].x = x;
00071 PreviousResult->points[PreviousResult->pointsNumber - 1].y = y;
00072 }
00073
00074 void
00075 vapiResultAddFloat (vMacroResult * PreviousResult, double value)
00076 {
00077 double *floatsPtr;
00078
00079 if (PreviousResult->floatsNumber == 0)
00080 {
00081 PreviousResult->floats =
00082 malloc ((++PreviousResult->floatsNumber) *
00083 sizeof (double));
00084
00085 }
00086 else
00087 {
00088 floatsPtr =
00089 realloc (PreviousResult->floats,
00090 (++PreviousResult->floatsNumber) *
00091 sizeof (double));
00092
00093 PreviousResult->floats = floatsPtr;
00094 }
00095 PreviousResult->floats[PreviousResult->floatsNumber - 1] = value;
00096
00097 }
00098
00099 void
00100 vapiResultAddChar (vMacroResult * PreviousResult, const char *string)
00101 {
00102 vChar *charsPtr;
00103
00104 if (PreviousResult->charsNumber == 0)
00105 {
00106 PreviousResult->charsNumber++;
00107 PreviousResult->chars =
00108 malloc ((PreviousResult->charsNumber) *
00109 sizeof (vChar));
00110
00111 }
00112 else
00113 {
00114 PreviousResult->charsNumber++;
00115 charsPtr =
00116 realloc (PreviousResult->chars,
00117 (PreviousResult->charsNumber) *
00118 sizeof (vChar));
00119
00120 PreviousResult->chars = charsPtr;
00121 }
00122 PreviousResult->chars[PreviousResult->charsNumber - 1].ch =
00123 vapiReturnStringPointer (string);
00124
00125 }
00126
00127 char *
00128 vapiResultGetChar (vMacroResult * PreviousResult, int position)
00129 {
00130 if (PreviousResult->charsNumber > 0
00131 && position < PreviousResult->charsNumber)
00132 {
00133 return PreviousResult->chars[position].ch;
00134 }
00135 else
00136 {
00137 return " ";
00138 }
00139 }
00140
00141 int
00142 vapiResultGetInt (vMacroResult * PreviousResult, int position)
00143 {
00144 if (PreviousResult->intsNumber > 0
00145 && position < PreviousResult->intsNumber)
00146 {
00147 return PreviousResult->ints[position];
00148 }
00149 else
00150 {
00151 return 0;
00152 }
00153 }
00154
00155 double
00156 vapiResultGetFloat (vMacroResult * PreviousResult, int position)
00157 {
00158 if (PreviousResult->floatsNumber > 0
00159 && position < PreviousResult->floatsNumber)
00160 {
00161 return PreviousResult->floats[position];
00162 }
00163 else
00164 {
00165 return 0.0;
00166 }
00167 }
00168
00169 vPoint
00170 vapiResultGetPoint (vMacroResult * PreviousResult, int position)
00171 {
00172 vPoint point = { 0, 0 };
00173
00174 if (PreviousResult->pointsNumber > 0
00175 && position < PreviousResult->pointsNumber)
00176 {
00177 return PreviousResult->points[position];
00178 }
00179 else
00180 {
00181 return point;
00182 }
00183 }
00184
00185 int
00186 vapiResultGetIntsNumber (vMacroResult * PreviousResult)
00187 {
00188 return PreviousResult->intsNumber;
00189 }
00190
00191 int
00192 vapiResultGetFloatsNumber (vMacroResult * PreviousResult)
00193 {
00194 return PreviousResult->floatsNumber;
00195 }
00196
00197 int
00198 vapiResultGetCharsNumber (vMacroResult * PreviousResult)
00199 {
00200 return PreviousResult->charsNumber;
00201 }
00202
00203 int
00204 vapiResultGetPointsNumber (vMacroResult * PreviousResult)
00205 {
00206 return PreviousResult->pointsNumber;
00207 }
00208
00209 void
00210 vapiResultSetEnd (vMacroResult * PreviousResult)
00211 {
00212 PreviousResult->End = vTRUE;
00213 }
00214
00215 void
00216 vapiResultSetJumpTo (vMacroResult * PreviousResult, int OperationOrder)
00217 {
00218 PreviousResult->JumpTo = OperationOrder;
00219 }
00220
00221 int
00222 vapiResultGetJumpTo (vMacroResult * PreviousResult)
00223 {
00224 return PreviousResult->JumpTo;
00225 }
00226
00227 void
00228 vapiResultSetDecision (vMacroResult * PreviousResult, vBoolean Decision)
00229 {
00230 PreviousResult->Decision = Decision;
00231 }
00232
00233 vBoolean
00234 vapiResultGetDecision (vMacroResult * PreviousResult)
00235 {
00236 return PreviousResult->Decision;
00237 }
00238
00239
00240 void
00241 vResultResetInts (vMacroResult * PreviousResult)
00242 {
00243 if (PreviousResult->intsNumber)
00244 {
00245 free (PreviousResult->ints);
00246 PreviousResult->intsNumber = 0;
00247 }
00248 }
00249
00250 void
00251 vResultResetChars (vMacroResult * PreviousResult)
00252 {
00253 int i;
00254 if (PreviousResult->charsNumber)
00255 {
00256 for (i = 0; i < PreviousResult->charsNumber; i++)
00257 {
00258 free (PreviousResult->chars[i].ch);
00259 }
00260 free (PreviousResult->chars);
00261 PreviousResult->charsNumber = 0;
00262 }
00263 }
00264
00265 void
00266 vResultResetPoints (vMacroResult * PreviousResult)
00267 {
00268 if (PreviousResult->pointsNumber)
00269 {
00270 free (PreviousResult->points);
00271 PreviousResult->pointsNumber = 0;
00272 }
00273 }
00274
00275 void
00276 vResultReset (vMacroResult * PreviousResult)
00277 {
00278 vResultResetInts (PreviousResult);
00279 vResultResetPoints (PreviousResult);
00280 vResultResetChars (PreviousResult);
00281 PreviousResult->Decision = vFALSE;
00282 PreviousResult->End = vFALSE;
00283 PreviousResult->JumpTo = -1;
00284 if (PreviousResult->macroTag != NULL)
00285 {
00286 free (PreviousResult->macroTag);
00287 PreviousResult->macroTag = NULL;
00288 }
00289 }
00290
00291 void
00292 vResultFree (vMacroResult * PreviousResult)
00293 {
00294 vResultReset (PreviousResult);
00295 free (PreviousResult);
00296 }
00297
00307 char *
00308 vapiResultPrintf (const char *inString, vMacroResult * PreviousResult)
00309 {
00320 int inStringLen, i;
00321 char parsedString[255], *outString;
00322 inStringLen = strlen (inString);
00323
00324
00335 strcpy (parsedString, "");
00336 for (i = 0; i < inStringLen; i++)
00337 {
00338 if (inString[i] == '\\')
00339 {
00340 i++;
00341 continue;
00342 }
00343 if (inString[i] == '%')
00344 {
00345 switch (inString[++i])
00346 {
00347 case 'r':
00348 {
00349 switch (inString[++i])
00350 {
00351 case 'd':
00352 {
00353 if (PreviousResult->intsNumber == 0)
00354 {
00355 ++i;
00356 continue;
00357 break;
00358
00359 }
00360 sprintf (parsedString, "%s%d",
00361 parsedString,
00362 PreviousResult->
00363 ints[atoi (&inString[++i])]);
00364 continue;
00365 break;
00366
00367 }
00368 case 'p':
00369 {
00370 if (PreviousResult->pointsNumber == 0)
00371 {
00372 ++i;
00373 continue;
00374 break;
00375
00376 }
00377 ++i;
00378 sprintf (parsedString,
00379 "%s (%d,%d)",
00380 parsedString,
00381 PreviousResult->
00382 points[atoi
00383 (&inString
00384 [i])].x,
00385 PreviousResult->
00386 points[atoi (&inString[i])].
00387 y);
00388 continue;
00389 break;
00390
00391 }
00392 case 's':
00393 {
00394 if (PreviousResult->charsNumber == 0)
00395 {
00396 ++i;
00397 continue;
00398 break;
00399
00400 }
00401 ++i;
00402 sprintf (parsedString,
00403 "%s (%d,%s)",
00404 parsedString,
00405 PreviousResult->
00406 points[atoi
00407 (&inString
00408 [i])].x,
00409 PreviousResult->
00410 chars[atoi (&inString[i])].
00411 ch);
00412 continue;
00413 break;
00414
00415 }
00416
00417 }
00418 }
00419
00420
00421 }
00422 }
00423 sprintf (parsedString, "%s%c", parsedString, inString[i]);
00424 }
00425
00426 outString = vapiReturnStringPointer (parsedString);
00427
00428 return outString;
00429 }
00430
00431 char *
00432 vapiResultCheckMacroTag (vMacroResult * PreviousResult)
00433 {
00434 if (PreviousResult->macroTag == NULL)
00435 {
00436 return v_printf ("0");
00437 }
00438 else
00439 {
00440 return v_printf ("%s", PreviousResult->macroTag);
00441 }
00442 }
00443
00444 void
00445 vapiResultSetCurrentMacroTag (vMacroResult * PreviousResult,
00446 const char *previousMacroTag, int Operation)
00447 {
00448 if (PreviousResult->macroTag != NULL)
00449 {
00450 free (PreviousResult->macroTag);
00451 }
00452 PreviousResult->macroTag = vapiMacroTag (previousMacroTag, Operation);
00453 }