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 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 #ifdef HAVE_CONFIG_H
00039 #include "config.h"
00040 #endif
00041 
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045 
00046 #include "getopt.h"
00047 
00048 #include "CameraInfoOpt.h"
00049 
00050 const char *CameraInfoParserInfo_purpose = "";
00051 
00052 const char *CameraInfoParserInfo_usage = "Usage: inversePerspectiveMapping [OPTIONS]...";
00053 
00054 const char *CameraInfoParserInfo_help[] = {
00055   "  -h, --help                   Print help and exit",
00056   "  -V, --version                Print version and exit",
00057   "      --focalLengthX=DOUBLE    Focal lenght in horizontal direction in pixels",
00058   "      --focalLengthY=DOUBLE    Focal lenght in vertical direction in pixels",
00059   "      --opticalCenterX=DOUBLE  X-coordinate of optical center in pixels",
00060   "      --opticalCenterY=DOUBLE  Y-coordinate of optical center in pixels",
00061   "      --cameraHeight=DOUBLE    Height of camera above ground in mm",
00062   "      --pitch=DOUBLE           pitch of camera in degrees (+ve downwards)",
00063   "      --yaw=DOUBLE             yaw of camera in degrees (+ve clockwise)",
00064   "      --imageWidth=DOUBLE      width of image in pixels",
00065   "      --imageHeight=DOUBLE     height of image in pixels",
00066     0
00067 };
00068 
00069 static
00070 void clear_given (struct CameraInfoParserInfo *args_info);
00071 static
00072 void clear_args (struct CameraInfoParserInfo *args_info);
00073 
00074 static int
00075 cameraInfoParser_internal (int argc, char * const *argv, struct CameraInfoParserInfo *args_info, int override, int initialize, int check_required, const char *additional_error);
00076 
00077 static int
00078 cameraInfoParser_required2 (struct CameraInfoParserInfo *args_info, const char *prog_name, const char *additional_error);
00079 struct line_list
00080 {
00081   char * string_arg;
00082   struct line_list * next;
00083 };
00084 
00085 static struct line_list *cmd_line_list = 0;
00086 static struct line_list *cmd_line_list_tmp = 0;
00087 
00088 static void
00089 free_cmd_list(void)
00090 {
00091   
00092   if (cmd_line_list)
00093     {
00094       while (cmd_line_list) {
00095         cmd_line_list_tmp = cmd_line_list;
00096         cmd_line_list = cmd_line_list->next;
00097         free (cmd_line_list_tmp->string_arg);
00098         free (cmd_line_list_tmp);
00099       }
00100     }
00101 }
00102 
00103 
00104 static char *
00105 gengetopt_strdup (const char *s);
00106 
00107 static
00108 void clear_given (struct CameraInfoParserInfo *args_info)
00109 {
00110   args_info->help_given = 0 ;
00111   args_info->version_given = 0 ;
00112   args_info->focalLengthX_given = 0 ;
00113   args_info->focalLengthY_given = 0 ;
00114   args_info->opticalCenterX_given = 0 ;
00115   args_info->opticalCenterY_given = 0 ;
00116   args_info->cameraHeight_given = 0 ;
00117   args_info->pitch_given = 0 ;
00118   args_info->yaw_given = 0 ;
00119   args_info->imageWidth_given = 0 ;
00120   args_info->imageHeight_given = 0 ;
00121 }
00122 
00123 static
00124 void clear_args (struct CameraInfoParserInfo *args_info)
00125 {
00126   args_info->focalLengthX_orig = NULL;
00127   args_info->focalLengthY_orig = NULL;
00128   args_info->opticalCenterX_orig = NULL;
00129   args_info->opticalCenterY_orig = NULL;
00130   args_info->cameraHeight_orig = NULL;
00131   args_info->pitch_orig = NULL;
00132   args_info->yaw_orig = NULL;
00133   args_info->imageWidth_orig = NULL;
00134   args_info->imageHeight_orig = NULL;
00135   
00136 }
00137 
00138 static
00139 void init_args_info(struct CameraInfoParserInfo *args_info)
00140 {
00141   args_info->help_help = CameraInfoParserInfo_help[0] ;
00142   args_info->version_help = CameraInfoParserInfo_help[1] ;
00143   args_info->focalLengthX_help = CameraInfoParserInfo_help[2] ;
00144   args_info->focalLengthY_help = CameraInfoParserInfo_help[3] ;
00145   args_info->opticalCenterX_help = CameraInfoParserInfo_help[4] ;
00146   args_info->opticalCenterY_help = CameraInfoParserInfo_help[5] ;
00147   args_info->cameraHeight_help = CameraInfoParserInfo_help[6] ;
00148   args_info->pitch_help = CameraInfoParserInfo_help[7] ;
00149   args_info->yaw_help = CameraInfoParserInfo_help[8] ;
00150   args_info->imageWidth_help = CameraInfoParserInfo_help[9] ;
00151   args_info->imageHeight_help = CameraInfoParserInfo_help[10] ;
00152   
00153 }
00154 
00155 void
00156 cameraInfoParser_print_version (void)
00157 {
00158   printf ("%s %s\n", CAMERAINFOPARSER_PACKAGE, CAMERAINFOPARSER_VERSION);
00159 }
00160 
00161 void
00162 cameraInfoParser_print_help (void)
00163 {
00164   int i = 0;
00165   cameraInfoParser_print_version ();
00166 
00167   if (strlen(CameraInfoParserInfo_purpose) > 0)
00168     printf("\n%s\n", CameraInfoParserInfo_purpose);
00169 
00170   printf("\n%s\n\n", CameraInfoParserInfo_usage);
00171   while (CameraInfoParserInfo_help[i])
00172     printf("%s\n", CameraInfoParserInfo_help[i++]);
00173 }
00174 
00175 void
00176 cameraInfoParser_init (struct CameraInfoParserInfo *args_info)
00177 {
00178   clear_given (args_info);
00179   clear_args (args_info);
00180   init_args_info (args_info);
00181 }
00182 
00183 static void
00184 cameraInfoParser_release (struct CameraInfoParserInfo *args_info)
00185 {
00186   
00187   if (args_info->focalLengthX_orig)
00188     {
00189       free (args_info->focalLengthX_orig); 
00190       args_info->focalLengthX_orig = 0;
00191     }
00192   if (args_info->focalLengthY_orig)
00193     {
00194       free (args_info->focalLengthY_orig); 
00195       args_info->focalLengthY_orig = 0;
00196     }
00197   if (args_info->opticalCenterX_orig)
00198     {
00199       free (args_info->opticalCenterX_orig); 
00200       args_info->opticalCenterX_orig = 0;
00201     }
00202   if (args_info->opticalCenterY_orig)
00203     {
00204       free (args_info->opticalCenterY_orig); 
00205       args_info->opticalCenterY_orig = 0;
00206     }
00207   if (args_info->cameraHeight_orig)
00208     {
00209       free (args_info->cameraHeight_orig); 
00210       args_info->cameraHeight_orig = 0;
00211     }
00212   if (args_info->pitch_orig)
00213     {
00214       free (args_info->pitch_orig); 
00215       args_info->pitch_orig = 0;
00216     }
00217   if (args_info->yaw_orig)
00218     {
00219       free (args_info->yaw_orig); 
00220       args_info->yaw_orig = 0;
00221     }
00222   if (args_info->imageWidth_orig)
00223     {
00224       free (args_info->imageWidth_orig); 
00225       args_info->imageWidth_orig = 0;
00226     }
00227   if (args_info->imageHeight_orig)
00228     {
00229       free (args_info->imageHeight_orig); 
00230       args_info->imageHeight_orig = 0;
00231     }
00232   
00233   clear_given (args_info);
00234 }
00235 
00236 int
00237 cameraInfoParser_file_save(const char *filename, struct CameraInfoParserInfo *args_info)
00238 {
00239   FILE *outfile;
00240   int i = 0;
00241 
00242   outfile = fopen(filename, "w");
00243 
00244   if (!outfile)
00245     {
00246       fprintf (stderr, "%s: cannot open file for writing: %s\n", CAMERAINFOPARSER_PACKAGE, filename);
00247       return EXIT_FAILURE;
00248     }
00249 
00250   if (args_info->help_given) {
00251     fprintf(outfile, "%s\n", "help");
00252   }
00253   if (args_info->version_given) {
00254     fprintf(outfile, "%s\n", "version");
00255   }
00256   if (args_info->focalLengthX_given) {
00257     if (args_info->focalLengthX_orig) {
00258       fprintf(outfile, "%s=\"%s\"\n", "focalLengthX", args_info->focalLengthX_orig);
00259     } else {
00260       fprintf(outfile, "%s\n", "focalLengthX");
00261     }
00262   }
00263   if (args_info->focalLengthY_given) {
00264     if (args_info->focalLengthY_orig) {
00265       fprintf(outfile, "%s=\"%s\"\n", "focalLengthY", args_info->focalLengthY_orig);
00266     } else {
00267       fprintf(outfile, "%s\n", "focalLengthY");
00268     }
00269   }
00270   if (args_info->opticalCenterX_given) {
00271     if (args_info->opticalCenterX_orig) {
00272       fprintf(outfile, "%s=\"%s\"\n", "opticalCenterX", args_info->opticalCenterX_orig);
00273     } else {
00274       fprintf(outfile, "%s\n", "opticalCenterX");
00275     }
00276   }
00277   if (args_info->opticalCenterY_given) {
00278     if (args_info->opticalCenterY_orig) {
00279       fprintf(outfile, "%s=\"%s\"\n", "opticalCenterY", args_info->opticalCenterY_orig);
00280     } else {
00281       fprintf(outfile, "%s\n", "opticalCenterY");
00282     }
00283   }
00284   if (args_info->cameraHeight_given) {
00285     if (args_info->cameraHeight_orig) {
00286       fprintf(outfile, "%s=\"%s\"\n", "cameraHeight", args_info->cameraHeight_orig);
00287     } else {
00288       fprintf(outfile, "%s\n", "cameraHeight");
00289     }
00290   }
00291   if (args_info->pitch_given) {
00292     if (args_info->pitch_orig) {
00293       fprintf(outfile, "%s=\"%s\"\n", "pitch", args_info->pitch_orig);
00294     } else {
00295       fprintf(outfile, "%s\n", "pitch");
00296     }
00297   }
00298   if (args_info->yaw_given) {
00299     if (args_info->yaw_orig) {
00300       fprintf(outfile, "%s=\"%s\"\n", "yaw", args_info->yaw_orig);
00301     } else {
00302       fprintf(outfile, "%s\n", "yaw");
00303     }
00304   }
00305   if (args_info->imageWidth_given) {
00306     if (args_info->imageWidth_orig) {
00307       fprintf(outfile, "%s=\"%s\"\n", "imageWidth", args_info->imageWidth_orig);
00308     } else {
00309       fprintf(outfile, "%s\n", "imageWidth");
00310     }
00311   }
00312   if (args_info->imageHeight_given) {
00313     if (args_info->imageHeight_orig) {
00314       fprintf(outfile, "%s=\"%s\"\n", "imageHeight", args_info->imageHeight_orig);
00315     } else {
00316       fprintf(outfile, "%s\n", "imageHeight");
00317     }
00318   }
00319   
00320   fclose (outfile);
00321 
00322   i = EXIT_SUCCESS;
00323   return i;
00324 }
00325 
00326 void
00327 cameraInfoParser_free (struct CameraInfoParserInfo *args_info)
00328 {
00329   cameraInfoParser_release (args_info);
00330 }
00331 
00332 
00333 
00334 
00335 char *
00336 gengetopt_strdup (const char *s)
00337 {
00338   char *result = NULL;
00339   if (!s)
00340     return result;
00341 
00342   result = (char*)malloc(strlen(s) + 1);
00343   if (result == (char*)0)
00344     return (char*)0;
00345   strcpy(result, s);
00346   return result;
00347 }
00348 
00349 int
00350 cameraInfoParser (int argc, char * const *argv, struct CameraInfoParserInfo *args_info)
00351 {
00352   return cameraInfoParser2 (argc, argv, args_info, 0, 1, 1);
00353 }
00354 
00355 int
00356 cameraInfoParser2 (int argc, char * const *argv, struct CameraInfoParserInfo *args_info, int override, int initialize, int check_required)
00357 {
00358   int result;
00359 
00360   result = cameraInfoParser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
00361 
00362   if (result == EXIT_FAILURE)
00363     {
00364       cameraInfoParser_free (args_info);
00365       exit (EXIT_FAILURE);
00366     }
00367   
00368   return result;
00369 }
00370 
00371 int
00372 cameraInfoParser_required (struct CameraInfoParserInfo *args_info, const char *prog_name)
00373 {
00374   int result = EXIT_SUCCESS;
00375 
00376   if (cameraInfoParser_required2(args_info, prog_name, NULL) > 0)
00377     result = EXIT_FAILURE;
00378 
00379   if (result == EXIT_FAILURE)
00380     {
00381       cameraInfoParser_free (args_info);
00382       exit (EXIT_FAILURE);
00383     }
00384   
00385   return result;
00386 }
00387 
00388 int
00389 cameraInfoParser_required2 (struct CameraInfoParserInfo *args_info, const char *prog_name, const char *additional_error)
00390 {
00391   int error = 0;
00392 
00393   
00394   if (! args_info->focalLengthX_given)
00395     {
00396       fprintf (stderr, "%s: '--focalLengthX' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00397       error = 1;
00398     }
00399   
00400   if (! args_info->focalLengthY_given)
00401     {
00402       fprintf (stderr, "%s: '--focalLengthY' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00403       error = 1;
00404     }
00405   
00406   if (! args_info->opticalCenterX_given)
00407     {
00408       fprintf (stderr, "%s: '--opticalCenterX' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00409       error = 1;
00410     }
00411   
00412   if (! args_info->opticalCenterY_given)
00413     {
00414       fprintf (stderr, "%s: '--opticalCenterY' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00415       error = 1;
00416     }
00417   
00418   if (! args_info->cameraHeight_given)
00419     {
00420       fprintf (stderr, "%s: '--cameraHeight' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00421       error = 1;
00422     }
00423   
00424   if (! args_info->pitch_given)
00425     {
00426       fprintf (stderr, "%s: '--pitch' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00427       error = 1;
00428     }
00429   
00430   if (! args_info->yaw_given)
00431     {
00432       fprintf (stderr, "%s: '--yaw' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00433       error = 1;
00434     }
00435   
00436   if (! args_info->imageWidth_given)
00437     {
00438       fprintf (stderr, "%s: '--imageWidth' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00439       error = 1;
00440     }
00441   
00442   if (! args_info->imageHeight_given)
00443     {
00444       fprintf (stderr, "%s: '--imageHeight' option required%s\n", prog_name, (additional_error ? additional_error : ""));
00445       error = 1;
00446     }
00447   
00448   
00449   
00450 
00451   return error;
00452 }
00453 
00454 int
00455 cameraInfoParser_internal (int argc, char * const *argv, struct CameraInfoParserInfo *args_info, int override, int initialize, int check_required, const char *additional_error)
00456 {
00457   int c;        
00458 
00459   int error = 0;
00460   struct CameraInfoParserInfo local_args_info;
00461 
00462   if (initialize)
00463     cameraInfoParser_init (args_info);
00464 
00465   cameraInfoParser_init (&local_args_info);
00466 
00467   optarg = 0;
00468   optind = 0;
00469   opterr = 1;
00470   optopt = '?';
00471 
00472   while (1)
00473     {
00474       int option_index = 0;
00475       char *stop_char;
00476 
00477       static struct option long_options[] = {
00478         { "help",       0, NULL, 'h' },
00479         { "version",    0, NULL, 'V' },
00480         { "focalLengthX",       1, NULL, 0 },
00481         { "focalLengthY",       1, NULL, 0 },
00482         { "opticalCenterX",     1, NULL, 0 },
00483         { "opticalCenterY",     1, NULL, 0 },
00484         { "cameraHeight",       1, NULL, 0 },
00485         { "pitch",      1, NULL, 0 },
00486         { "yaw",        1, NULL, 0 },
00487         { "imageWidth", 1, NULL, 0 },
00488         { "imageHeight",        1, NULL, 0 },
00489         { NULL, 0, NULL, 0 }
00490       };
00491 
00492       stop_char = 0;
00493       c = getopt_long (argc, argv, "hV", long_options, &option_index);
00494 
00495       if (c == -1) break;       
00496 
00497       switch (c)
00498         {
00499         case 'h':       
00500           cameraInfoParser_print_help ();
00501           cameraInfoParser_free (&local_args_info);
00502           exit (EXIT_SUCCESS);
00503 
00504         case 'V':       
00505           cameraInfoParser_print_version ();
00506           cameraInfoParser_free (&local_args_info);
00507           exit (EXIT_SUCCESS);
00508 
00509 
00510         case 0: 
00511           
00512           if (strcmp (long_options[option_index].name, "focalLengthX") == 0)
00513           {
00514             if (local_args_info.focalLengthX_given)
00515               {
00516                 fprintf (stderr, "%s: `--focalLengthX' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00517                 goto failure;
00518               }
00519             if (args_info->focalLengthX_given && ! override)
00520               continue;
00521             local_args_info.focalLengthX_given = 1;
00522             args_info->focalLengthX_given = 1;
00523             args_info->focalLengthX_arg = strtod (optarg, &stop_char);
00524             if (!(stop_char && *stop_char == '\0')) {
00525               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00526               goto failure;
00527             }
00528             if (args_info->focalLengthX_orig)
00529               free (args_info->focalLengthX_orig); 
00530             args_info->focalLengthX_orig = gengetopt_strdup (optarg);
00531           }
00532           
00533           else if (strcmp (long_options[option_index].name, "focalLengthY") == 0)
00534           {
00535             if (local_args_info.focalLengthY_given)
00536               {
00537                 fprintf (stderr, "%s: `--focalLengthY' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00538                 goto failure;
00539               }
00540             if (args_info->focalLengthY_given && ! override)
00541               continue;
00542             local_args_info.focalLengthY_given = 1;
00543             args_info->focalLengthY_given = 1;
00544             args_info->focalLengthY_arg = strtod (optarg, &stop_char);
00545             if (!(stop_char && *stop_char == '\0')) {
00546               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00547               goto failure;
00548             }
00549             if (args_info->focalLengthY_orig)
00550               free (args_info->focalLengthY_orig); 
00551             args_info->focalLengthY_orig = gengetopt_strdup (optarg);
00552           }
00553           
00554           else if (strcmp (long_options[option_index].name, "opticalCenterX") == 0)
00555           {
00556             if (local_args_info.opticalCenterX_given)
00557               {
00558                 fprintf (stderr, "%s: `--opticalCenterX' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00559                 goto failure;
00560               }
00561             if (args_info->opticalCenterX_given && ! override)
00562               continue;
00563             local_args_info.opticalCenterX_given = 1;
00564             args_info->opticalCenterX_given = 1;
00565             args_info->opticalCenterX_arg = strtod (optarg, &stop_char);
00566             if (!(stop_char && *stop_char == '\0')) {
00567               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00568               goto failure;
00569             }
00570             if (args_info->opticalCenterX_orig)
00571               free (args_info->opticalCenterX_orig); 
00572             args_info->opticalCenterX_orig = gengetopt_strdup (optarg);
00573           }
00574           
00575           else if (strcmp (long_options[option_index].name, "opticalCenterY") == 0)
00576           {
00577             if (local_args_info.opticalCenterY_given)
00578               {
00579                 fprintf (stderr, "%s: `--opticalCenterY' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00580                 goto failure;
00581               }
00582             if (args_info->opticalCenterY_given && ! override)
00583               continue;
00584             local_args_info.opticalCenterY_given = 1;
00585             args_info->opticalCenterY_given = 1;
00586             args_info->opticalCenterY_arg = strtod (optarg, &stop_char);
00587             if (!(stop_char && *stop_char == '\0')) {
00588               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00589               goto failure;
00590             }
00591             if (args_info->opticalCenterY_orig)
00592               free (args_info->opticalCenterY_orig); 
00593             args_info->opticalCenterY_orig = gengetopt_strdup (optarg);
00594           }
00595           
00596           else if (strcmp (long_options[option_index].name, "cameraHeight") == 0)
00597           {
00598             if (local_args_info.cameraHeight_given)
00599               {
00600                 fprintf (stderr, "%s: `--cameraHeight' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00601                 goto failure;
00602               }
00603             if (args_info->cameraHeight_given && ! override)
00604               continue;
00605             local_args_info.cameraHeight_given = 1;
00606             args_info->cameraHeight_given = 1;
00607             args_info->cameraHeight_arg = strtod (optarg, &stop_char);
00608             if (!(stop_char && *stop_char == '\0')) {
00609               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00610               goto failure;
00611             }
00612             if (args_info->cameraHeight_orig)
00613               free (args_info->cameraHeight_orig); 
00614             args_info->cameraHeight_orig = gengetopt_strdup (optarg);
00615           }
00616           
00617           else if (strcmp (long_options[option_index].name, "pitch") == 0)
00618           {
00619             if (local_args_info.pitch_given)
00620               {
00621                 fprintf (stderr, "%s: `--pitch' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00622                 goto failure;
00623               }
00624             if (args_info->pitch_given && ! override)
00625               continue;
00626             local_args_info.pitch_given = 1;
00627             args_info->pitch_given = 1;
00628             args_info->pitch_arg = strtod (optarg, &stop_char);
00629             if (!(stop_char && *stop_char == '\0')) {
00630               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00631               goto failure;
00632             }
00633             if (args_info->pitch_orig)
00634               free (args_info->pitch_orig); 
00635             args_info->pitch_orig = gengetopt_strdup (optarg);
00636           }
00637           
00638           else if (strcmp (long_options[option_index].name, "yaw") == 0)
00639           {
00640             if (local_args_info.yaw_given)
00641               {
00642                 fprintf (stderr, "%s: `--yaw' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00643                 goto failure;
00644               }
00645             if (args_info->yaw_given && ! override)
00646               continue;
00647             local_args_info.yaw_given = 1;
00648             args_info->yaw_given = 1;
00649             args_info->yaw_arg = strtod (optarg, &stop_char);
00650             if (!(stop_char && *stop_char == '\0')) {
00651               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00652               goto failure;
00653             }
00654             if (args_info->yaw_orig)
00655               free (args_info->yaw_orig); 
00656             args_info->yaw_orig = gengetopt_strdup (optarg);
00657           }
00658           
00659           else if (strcmp (long_options[option_index].name, "imageWidth") == 0)
00660           {
00661             if (local_args_info.imageWidth_given)
00662               {
00663                 fprintf (stderr, "%s: `--imageWidth' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00664                 goto failure;
00665               }
00666             if (args_info->imageWidth_given && ! override)
00667               continue;
00668             local_args_info.imageWidth_given = 1;
00669             args_info->imageWidth_given = 1;
00670             args_info->imageWidth_arg = strtod (optarg, &stop_char);
00671             if (!(stop_char && *stop_char == '\0')) {
00672               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00673               goto failure;
00674             }
00675             if (args_info->imageWidth_orig)
00676               free (args_info->imageWidth_orig); 
00677             args_info->imageWidth_orig = gengetopt_strdup (optarg);
00678           }
00679           
00680           else if (strcmp (long_options[option_index].name, "imageHeight") == 0)
00681           {
00682             if (local_args_info.imageHeight_given)
00683               {
00684                 fprintf (stderr, "%s: `--imageHeight' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
00685                 goto failure;
00686               }
00687             if (args_info->imageHeight_given && ! override)
00688               continue;
00689             local_args_info.imageHeight_given = 1;
00690             args_info->imageHeight_given = 1;
00691             args_info->imageHeight_arg = strtod (optarg, &stop_char);
00692             if (!(stop_char && *stop_char == '\0')) {
00693               fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
00694               goto failure;
00695             }
00696             if (args_info->imageHeight_orig)
00697               free (args_info->imageHeight_orig); 
00698             args_info->imageHeight_orig = gengetopt_strdup (optarg);
00699           }
00700           
00701           break;
00702         case '?':       
00703           
00704           goto failure;
00705 
00706         default:        
00707           fprintf (stderr, "%s: option unknown: %c%s\n", CAMERAINFOPARSER_PACKAGE, c, (additional_error ? additional_error : ""));
00708           abort ();
00709         } 
00710     } 
00711 
00712 
00713 
00714   if (check_required)
00715     {
00716       error += cameraInfoParser_required2 (args_info, argv[0], additional_error);
00717     }
00718 
00719   cameraInfoParser_release (&local_args_info);
00720 
00721   if ( error )
00722     return (EXIT_FAILURE);
00723 
00724   return 0;
00725 
00726 failure:
00727   
00728   cameraInfoParser_release (&local_args_info);
00729   return (EXIT_FAILURE);
00730 }
00731 
00732 #ifndef CONFIG_FILE_LINE_SIZE
00733 #define CONFIG_FILE_LINE_SIZE 2048
00734 #endif
00735 #define ADDITIONAL_ERROR " in configuration file "
00736 
00737 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
00738 
00739 
00740 char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
00741 
00742 int
00743 cameraInfoParser_configfile (char * const filename, struct CameraInfoParserInfo *args_info, int override, int initialize, int check_required)
00744 {
00745   FILE* file;
00746   char linebuf[CONFIG_FILE_LINE_SIZE];
00747   int line_num = 0;
00748   int i, result, equal;
00749   char *fopt, *farg;
00750   char *str_index;
00751   size_t len, next_token;
00752   char delimiter;
00753   int my_argc = 0;
00754   char **my_argv_arg;
00755   char *additional_error;
00756 
00757   
00758   cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
00759   cmd_line_list_tmp->next = cmd_line_list;
00760   cmd_line_list = cmd_line_list_tmp;
00761   cmd_line_list->string_arg = gengetopt_strdup (CAMERAINFOPARSER_PACKAGE);
00762 
00763   if ((file = fopen(filename, "r")) == NULL)
00764     {
00765       fprintf (stderr, "%s: Error opening configuration file '%s'\n",
00766                CAMERAINFOPARSER_PACKAGE, filename);
00767       result = EXIT_FAILURE;
00768       goto conf_failure;
00769     }
00770 
00771   while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
00772     {
00773       ++line_num;
00774       my_argv[0] = '\0';
00775       len = strlen(linebuf);
00776       if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
00777         {
00778           fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
00779                    CAMERAINFOPARSER_PACKAGE, filename, line_num);
00780           result = EXIT_FAILURE;
00781           goto conf_failure;
00782         }
00783 
00784       
00785       next_token = strspn ( linebuf, " \t\r\n");
00786       str_index  = linebuf + next_token;
00787 
00788       if ( str_index[0] == '\0' || str_index[0] == '#')
00789         continue; 
00790 
00791       fopt = str_index;
00792 
00793       
00794       next_token = strcspn (fopt, " \t\r\n=");
00795 
00796       if (fopt[next_token] == '\0') 
00797         {
00798           farg  = NULL;
00799           equal = 0;
00800           goto noarg;
00801         }
00802 
00803       
00804       equal = (fopt[next_token] == '=');
00805       fopt[next_token++] = '\0';
00806 
00807       
00808       next_token += strspn (fopt + next_token, " \t\r\n");
00809       
00810       if ( !equal )
00811         if ((equal = (fopt[next_token] == '=')))
00812           {
00813             next_token++;
00814             next_token += strspn (fopt + next_token, " \t\r\n");
00815           }
00816       str_index  += next_token;
00817 
00818       
00819       farg = str_index;
00820       if ( farg[0] == '\"' || farg[0] == '\'' )
00821         { 
00822           str_index = strchr (++farg, str_index[0] ); 
00823           if (! str_index)
00824             {
00825               fprintf
00826                 (stderr,
00827                  "%s:%s:%d: unterminated string in configuration file\n",
00828                  CAMERAINFOPARSER_PACKAGE, filename, line_num);
00829               result = EXIT_FAILURE;
00830               goto conf_failure;
00831             }
00832         }
00833       else
00834         { 
00835           next_token = strcspn (farg, " \t\r\n#\'\"");
00836           str_index += next_token;
00837         }
00838 
00839       
00840       delimiter = *str_index, *str_index++ = '\0';
00841 
00842       
00843       if (delimiter != '\0' && delimiter != '#')
00844         {
00845           str_index += strspn(str_index, " \t\r\n");
00846           if (*str_index != '\0' && *str_index != '#')
00847             {
00848               fprintf
00849                 (stderr,
00850                  "%s:%s:%d: malformed string in configuration file\n",
00851                  CAMERAINFOPARSER_PACKAGE, filename, line_num);
00852               result = EXIT_FAILURE;
00853               goto conf_failure;
00854             }
00855         }
00856 
00857     noarg:
00858       ++my_argc;
00859       len = strlen(fopt);
00860 
00861       strcat (my_argv, len > 1 ? "--" : "-");
00862       strcat (my_argv, fopt);
00863       if (len > 1 && ((farg &&*farg) || equal))
00864           strcat (my_argv, "=");
00865       if (farg && *farg)
00866           strcat (my_argv, farg);
00867 
00868       cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
00869       cmd_line_list_tmp->next = cmd_line_list;
00870       cmd_line_list = cmd_line_list_tmp;
00871       cmd_line_list->string_arg = gengetopt_strdup(my_argv);
00872     } 
00873 
00874   ++my_argc; 
00875   my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
00876   cmd_line_list_tmp = cmd_line_list;
00877   for (i = my_argc - 1; i >= 0; --i) {
00878     my_argv_arg[i] = cmd_line_list_tmp->string_arg;
00879     cmd_line_list_tmp = cmd_line_list_tmp->next;
00880   }
00881   my_argv_arg[my_argc] = 0;
00882 
00883   additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
00884   strcpy (additional_error, ADDITIONAL_ERROR);
00885   strcat (additional_error, filename);
00886   result =
00887     cameraInfoParser_internal (my_argc, my_argv_arg, args_info, override, initialize, check_required, additional_error);
00888 
00889   free (additional_error);
00890   free (my_argv_arg);
00891 
00892 conf_failure:
00893   if (file)
00894     fclose(file);
00895 
00896   free_cmd_list();
00897   if (result == EXIT_FAILURE)
00898     {
00899       cameraInfoParser_free (args_info);
00900       exit (EXIT_FAILURE);
00901     }
00902   
00903   return result;
00904 }