00001 #include "vapiTypes.h"
00002 #include "vapiOptions.h"
00003 #include "vapiMemory.h"
00004 #include "vapiAux.h"
00005
00010 vOptions *
00011 vapiOptionsInit (vOptionsSettings * OptionsSettings)
00012 {
00013 int i;
00014 vOptions *Options = malloc (sizeof (vOptions));
00015
00016
00017
00018
00019
00020 Options->floatsNumber = OptionsSettings->floatsNumber;
00021 Options->intsNumber = OptionsSettings->intsNumber;
00022 Options->charsNumber = OptionsSettings->charsNumber;
00023 Options->booleansNumber = OptionsSettings->booleansNumber;
00024 Options->choicesNumber = OptionsSettings->chooseNumber;
00025
00026
00027
00028
00029
00030 if (OptionsSettings->floatsNumber)
00031 {
00032 Options->floats =
00033 malloc (OptionsSettings->floatsNumber *
00034 sizeof (double));
00035 for (i = 0; i < OptionsSettings->floatsNumber; i++)
00036 {
00037 Options->floats[i] =
00038 OptionsSettings->floats[i].defaultValue;
00039 }
00040 }
00041 if (OptionsSettings->intsNumber)
00042 {
00043 Options->ints =
00044 malloc (OptionsSettings->intsNumber * sizeof (int));
00045 for (i = 0; i < OptionsSettings->intsNumber; i++)
00046 {
00047 Options->ints[i] =
00048 OptionsSettings->ints[i].defaultValue;
00049 }
00050 }
00051
00052 if (OptionsSettings->charsNumber)
00053 {
00054 Options->chars =
00055 malloc (OptionsSettings->charsNumber *
00056 sizeof (vChar));
00057 for (i = 0; i < OptionsSettings->charsNumber; i++)
00058 {
00059 Options->chars[i].ch = "";
00060 }
00061 }
00062 if (OptionsSettings->chooseNumber)
00063 {
00064 Options->choices =
00065 malloc (OptionsSettings->chooseNumber * sizeof (int));
00066 for (i = 0; i < OptionsSettings->chooseNumber; i++)
00067 {
00068 Options->choices[i] =
00069 OptionsSettings->choose[i].defaultOption;
00070 }
00071 }
00072 if (OptionsSettings->booleansNumber)
00073 {
00074 Options->booleans =
00075 malloc (OptionsSettings->booleansNumber *
00076 sizeof (vBoolean));
00077 for (i = 0; i < OptionsSettings->booleansNumber; i++)
00078 {
00079 Options->booleans[i] =
00080 OptionsSettings->booleans[i].defaultValue;
00081 }
00082 }
00083 return Options;
00084 }
00091 int
00092 vapiOptionsGetInts (vOptions * Options, int position)
00093 {
00094 if (Options->intsNumber > 0 && position < Options->intsNumber)
00095 {
00096 return Options->ints[position];
00097 }
00098 else
00099 {
00100 return 0;
00101 }
00102 }
00109 double
00110 vapiOptionsGetFloats (vOptions * Options, int position)
00111 {
00112 if (Options->floatsNumber > 0 && position < Options->floatsNumber)
00113 {
00114 return Options->floats[position];
00115 }
00116 else
00117 {
00118 return 0;
00119 }
00120 }
00130 char *
00131 vapiOptionsGetChars (vOptions * Options, int position)
00132 {
00133 if (Options->charsNumber > 0 && position < Options->charsNumber)
00134 {
00135 return Options->chars[position].ch;
00136 }
00137 else
00138 {
00139 return " ";
00140 }
00141 }
00148 vBoolean
00149 vapiOptionsGetBooleans (vOptions * Options, int position)
00150 {
00151 if (Options->booleansNumber > 0 && position < Options->booleansNumber)
00152 {
00153 return Options->booleans[position];
00154 }
00155 else
00156 {
00157 return vFALSE;
00158 }
00159 }
00166 int
00167 vapiOptionsGetChoices (vOptions * Options, int position)
00168 {
00169 if (Options->choicesNumber > 0 && position < Options->choicesNumber)
00170 {
00171 return Options->choices[position];
00172 }
00173 else
00174 {
00175 return 0;
00176 }
00177 }
00184 int
00185 vapiOptionsGetTimes (vOptions * Options)
00186 {
00187 vEffectOptions *CustomOptions = Options->CustomOptions;
00188 return CustomOptions->times;
00189 }
00196 void
00197 vOptionsFree (vOptions * Options, vOptionsSettings * OptionsSettings,
00198 vOptionsFreeCustom FreeCustom)
00199 {
00200 int i;
00201
00202 if (OptionsSettings->floatsNumber)
00203 {
00204 free (Options->floats);
00205 }
00206 if (OptionsSettings->intsNumber)
00207 {
00208 free (Options->ints);
00209 }
00210 if (OptionsSettings->charsNumber)
00211 {
00212 for (i = 0; i < OptionsSettings->charsNumber; i++)
00213 {
00214 if (strlen (Options->chars[i].ch) > 0)
00215 {
00216 vCharFreeChar (&Options->chars[i]);
00217 }
00218 }
00219 free (Options->chars);
00220 }
00221 if (OptionsSettings->chooseNumber)
00222 {
00223 free (Options->choices);
00224 }
00225 if (OptionsSettings->booleansNumber)
00226 {
00227 free (Options->booleans);
00228 }
00229 if (FreeCustom != NULL)
00230 {
00231 FreeCustom (Options, OptionsSettings);
00232 }
00233 free (Options);
00234 }
00235
00241 vBoolean
00242 vapiOptionsCheck (vOptionsSettings * OptionsSettings, vOptions * Options)
00243 {
00244
00245 int i;
00246 if (OptionsSettings->intsNumber)
00247 {
00248 for (i = 0; i < OptionsSettings->intsNumber; i++)
00249 {
00250
00251 if (Options->ints[i] <
00252 OptionsSettings->ints[i].min
00253 || Options->ints[i] >
00254 OptionsSettings->ints[i].max)
00255 {
00256 Options->ints[i] =
00257 OptionsSettings->ints[i].defaultValue;
00258
00259 }
00260 }
00261 }
00262 if (OptionsSettings->floatsNumber)
00263 {
00264 for (i = 0; i < OptionsSettings->floatsNumber; i++)
00265 {
00266
00267 if (Options->floats[i] <
00268 OptionsSettings->floats[i].min
00269 || Options->floats[i] >
00270 OptionsSettings->floats[i].max)
00271 {
00272 Options->floats[i] =
00273 OptionsSettings->floats[i].
00274 defaultValue;
00275
00276 }
00277 }
00278 }
00279 if (OptionsSettings->charsNumber)
00280 {
00281 for (i = 0; i < OptionsSettings->charsNumber; i++)
00282 {
00283
00284 if (strlen (Options->chars[i].ch) == 0)
00285 {
00286 return vTRUE;
00287
00288 }
00289 }
00290 }
00291 return vFALSE;
00292 }
00299 void
00300 vOptionsSettingsFree (vOptionsSettings * OptionsSettings,
00301 vOptionsSettingsFreeCustom FreeCustom)
00302 {
00303 if (FreeCustom != NULL)
00304 {
00305 FreeCustom (OptionsSettings);
00306 }
00307 free (OptionsSettings);
00308
00309 }
00313 vOptionsSettings *
00314 vapiOptionsSettingsInit ()
00315 {
00316 vOptionsSettings *OptionsSettings =
00317 malloc (sizeof (vOptionsSettings));
00318 OptionsSettings->floatsNumber = 0;
00319 OptionsSettings->intsNumber = 0;
00320 OptionsSettings->charsNumber = 0;
00321 OptionsSettings->chooseNumber = 0;
00322 OptionsSettings->booleansNumber = 0;
00323 return OptionsSettings;
00324 }