00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <stdio.h>
00013 #include <stdlib.h>
00014 #include <string.h>
00015
00016 #ifdef HAVE_CONFIG_H
00017 #include "config.h"
00018 #endif
00019
00020 #ifndef HAVE_GETOPT_LONG
00021 #include "getopt.h"
00022 #else
00023 #include <getopt.h>
00024 #endif
00025
00026 #ifndef HAVE_STRDUP
00027 #define strdup gengetopt_strdup
00028 #endif
00029
00030 #include "cmdline.h"
00031
00032
00033 void
00034 cmdline_parser_print_version (void)
00035 {
00036 printf ("%s %s\n", PACKAGE, VERSION);
00037 }
00038
00039 void
00040 cmdline_parser_print_help (void)
00041 {
00042 cmdline_parser_print_version ();
00043 printf("\n"
00044 "Purpose:\n"
00045 " MrProjext is a MrProject-Databasefile-Extractor and -Converter:\n"
00046 " It can search the tasks belonging to a specific timeslot or recource. \n"
00047 " And (as converter) it can rewrite the extracted result as MrProject-, \n"
00048 " Evolution-, Yank- or Pilot-File\n"
00049 "\n"
00050 "Usage: %s [OPTIONS]...\n", PACKAGE);
00051 printf(" -h --help Print help and exit\n");
00052 printf(" -V --version Print version and exit\n");
00053 printf(" -fSTRING --dbFile=STRING read from mrproject-xml-dbfile (default='stdin')\n");
00054 printf(" -sSTRING --timeSlotStart=STRING extract tasks not ending before ... (iso8601str) (default='19700101T000000')\n");
00055 printf(" -eSTRING --timeSlotEnd=STRING extract tasks not starting after ... (iso8601str) (default='21001231T240000')\n");
00056 printf(" -pSTRING --person=STRING extract tasks being handled by ... (default='all')\n");
00057 printf(" -gSTRING --group=STRING extract tasks being handled by ... (default='all')\n");
00058 printf(" -o --onlyOpenTasks extract only unfullfilled tasks (default=off)\n");
00059 printf(" --only-open extract only unfullfilled tasks (default=off)\n");
00060 printf(" -i --rwIso8601 rewrite iso8601 date-strings instead of german form (default=off)\n");
00061 printf(" --iso-dates rewrite iso8601 date-strings instead of german form (default=off)\n");
00062 printf(" -l --rwOnlyLeafs rewrite only the extracted most embedded tasks (default=off)\n");
00063 printf(" --only-leafs rewrite only the extracted most embedded tasks (default=off)\n");
00064 printf(" -X --rwMrPrjFile rewrite the extracted tasks as new mrproject-xml-dbfile (default=off)\n");
00065 printf(" --output-mrproject rewrite the extracted tasks as new mrproject-xml-dbfile (default=off)\n");
00066 printf(" -M --rwMemoFile rewrite the extracted tasks as text-memo (default=off)\n");
00067 printf(" --output-memo rewrite the extracted tasks as text-memo (default=off)\n");
00068 printf(" -P --rwPilotFile rewrite the extracted tasks as pilot-todo-file (default=off)\n");
00069 printf(" --output-pilot rewrite the extracted tasks as pilot-todo-file (default=off)\n");
00070 printf(" -v --rwVcardFile rewrite the extracted tasks as vcard-todo-file (default=off)\n");
00071 printf(" --output-vcard rewrite the extracted tasks as vcard-todo-file (default=off)\n");
00072 printf(" -Y --rwYankFile rewrite the extracted tasks as yank-todo-file (default=off)\n");
00073 printf(" --output-yank rewrite the extracted tasks as yank-todo-file (default=off)\n");
00074 printf(" -C --rwCslFile rewrite the extracted tasks as comma seperated todo-line-list (default=off)\n");
00075 printf(" --output-csl rewrite the extracted tasks as comma seperated todo-line-list (default=off)\n");
00076 printf(" -H --rwHtmlSurvey rewrite a total task survey as htmlpage (default=off)\n");
00077 printf(" --output-html rewrite a total task survey as htmlpage (default=off)\n");
00078 printf(" -DSTRING --evaluationDate=STRING build task fullfilling survey with respect to this date (iso8601str)\n");
00079 printf(" -d --debug print debugMessages (default=off)\n");
00080 }
00081
00082
00083 #ifndef HAVE_STRDUP
00084
00085
00086 static char *
00087 gengetopt_strdup (const char *s)
00088 {
00089 char *result = (char*)malloc(strlen(s) + 1);
00090 if (result == (char*)0)
00091 return (char*)0;
00092 strcpy(result, s);
00093 return result;
00094 }
00095 #endif
00096
00097 int
00098 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
00099 {
00100 int c;
00101 int missing_required_options = 0;
00102
00103 args_info->help_given = 0 ;
00104 args_info->version_given = 0 ;
00105 args_info->dbFile_given = 0 ;
00106 args_info->timeSlotStart_given = 0 ;
00107 args_info->timeSlotEnd_given = 0 ;
00108 args_info->person_given = 0 ;
00109 args_info->group_given = 0 ;
00110 args_info->onlyOpenTasks_given = 0 ;
00111 args_info->only_open_given = 0 ;
00112 args_info->rwIso8601_given = 0 ;
00113 args_info->iso_dates_given = 0 ;
00114 args_info->rwOnlyLeafs_given = 0 ;
00115 args_info->only_leafs_given = 0 ;
00116 args_info->rwMrPrjFile_given = 0 ;
00117 args_info->output_mrproject_given = 0 ;
00118 args_info->rwMemoFile_given = 0 ;
00119 args_info->output_memo_given = 0 ;
00120 args_info->rwPilotFile_given = 0 ;
00121 args_info->output_pilot_given = 0 ;
00122 args_info->rwVcardFile_given = 0 ;
00123 args_info->output_vcard_given = 0 ;
00124 args_info->rwYankFile_given = 0 ;
00125 args_info->output_yank_given = 0 ;
00126 args_info->rwCslFile_given = 0 ;
00127 args_info->output_csl_given = 0 ;
00128 args_info->rwHtmlSurvey_given = 0 ;
00129 args_info->output_html_given = 0 ;
00130 args_info->evaluationDate_given = 0 ;
00131 args_info->debug_given = 0 ;
00132 #define clear_args() { \
00133 args_info->dbFile_arg = strdup("stdin") ;\
00134 args_info->timeSlotStart_arg = strdup("19700101T000000") ;\
00135 args_info->timeSlotEnd_arg = strdup("21001231T240000") ;\
00136 args_info->person_arg = strdup("all") ;\
00137 args_info->group_arg = strdup("all") ;\
00138 args_info->onlyOpenTasks_flag = 0;\
00139 args_info->only_open_flag = 0;\
00140 args_info->rwIso8601_flag = 0;\
00141 args_info->iso_dates_flag = 0;\
00142 args_info->rwOnlyLeafs_flag = 0;\
00143 args_info->only_leafs_flag = 0;\
00144 args_info->rwMrPrjFile_flag = 0;\
00145 args_info->output_mrproject_flag = 0;\
00146 args_info->rwMemoFile_flag = 0;\
00147 args_info->output_memo_flag = 0;\
00148 args_info->rwPilotFile_flag = 0;\
00149 args_info->output_pilot_flag = 0;\
00150 args_info->rwVcardFile_flag = 0;\
00151 args_info->output_vcard_flag = 0;\
00152 args_info->rwYankFile_flag = 0;\
00153 args_info->output_yank_flag = 0;\
00154 args_info->rwCslFile_flag = 0;\
00155 args_info->output_csl_flag = 0;\
00156 args_info->rwHtmlSurvey_flag = 0;\
00157 args_info->output_html_flag = 0;\
00158 args_info->evaluationDate_arg = NULL; \
00159 args_info->debug_flag = 0;\
00160 }
00161
00162 clear_args();
00163
00164 optarg = 0;
00165 optind = 1;
00166 opterr = 1;
00167 optopt = '?';
00168
00169 while (1)
00170 {
00171 int option_index = 0;
00172 char *stop_char;
00173 static struct option long_options[] = {
00174 { "help", 0, NULL, 'h' },
00175 { "version", 0, NULL, 'V' },
00176 { "dbFile", 1, NULL, 'f' },
00177 { "timeSlotStart", 1, NULL, 's' },
00178 { "timeSlotEnd", 1, NULL, 'e' },
00179 { "person", 1, NULL, 'p' },
00180 { "group", 1, NULL, 'g' },
00181 { "onlyOpenTasks", 0, NULL, 'o' },
00182 { "only-open", 0, NULL, 0 },
00183 { "rwIso8601", 0, NULL, 'i' },
00184 { "iso-dates", 0, NULL, 0 },
00185 { "rwOnlyLeafs", 0, NULL, 'l' },
00186 { "only-leafs", 0, NULL, 0 },
00187 { "rwMrPrjFile", 0, NULL, 'X' },
00188 { "output-mrproject", 0, NULL, 0 },
00189 { "rwMemoFile", 0, NULL, 'M' },
00190 { "output-memo", 0, NULL, 0 },
00191 { "rwPilotFile", 0, NULL, 'P' },
00192 { "output-pilot", 0, NULL, 0 },
00193 { "rwVcardFile", 0, NULL, 'v' },
00194 { "output-vcard", 0, NULL, 0 },
00195 { "rwYankFile", 0, NULL, 'Y' },
00196 { "output-yank", 0, NULL, 0 },
00197 { "rwCslFile", 0, NULL, 'C' },
00198 { "output-csl", 0, NULL, 0 },
00199 { "rwHtmlSurvey", 0, NULL, 'H' },
00200 { "output-html", 0, NULL, 0 },
00201 { "evaluationDate", 1, NULL, 'D' },
00202 { "debug", 0, NULL, 'd' },
00203 { NULL, 0, NULL, 0 }
00204 };
00205
00206 c = getopt_long (argc, argv, "hVf:s:e:p:g:oilXMPvYCHD:d", long_options, &option_index);
00207
00208 if (c == -1) break;
00209
00210 switch (c)
00211 {
00212 case 'h':
00213 clear_args ();
00214 cmdline_parser_print_help ();
00215 exit (EXIT_SUCCESS);
00216
00217 case 'V':
00218 clear_args ();
00219 cmdline_parser_print_version ();
00220 exit (EXIT_SUCCESS);
00221
00222 case 'f':
00223 if (args_info->dbFile_given)
00224 {
00225 fprintf (stderr, "%s: `--dbFile' (`-f') option given more than once\n", PACKAGE);
00226 clear_args ();
00227 exit (EXIT_FAILURE);
00228 }
00229 args_info->dbFile_given = 1;
00230 args_info->dbFile_arg = strdup (optarg);
00231 break;
00232
00233 case 's':
00234 if (args_info->timeSlotStart_given)
00235 {
00236 fprintf (stderr, "%s: `--timeSlotStart' (`-s') option given more than once\n", PACKAGE);
00237 clear_args ();
00238 exit (EXIT_FAILURE);
00239 }
00240 args_info->timeSlotStart_given = 1;
00241 args_info->timeSlotStart_arg = strdup (optarg);
00242 break;
00243
00244 case 'e':
00245 if (args_info->timeSlotEnd_given)
00246 {
00247 fprintf (stderr, "%s: `--timeSlotEnd' (`-e') option given more than once\n", PACKAGE);
00248 clear_args ();
00249 exit (EXIT_FAILURE);
00250 }
00251 args_info->timeSlotEnd_given = 1;
00252 args_info->timeSlotEnd_arg = strdup (optarg);
00253 break;
00254
00255 case 'p':
00256 if (args_info->person_given)
00257 {
00258 fprintf (stderr, "%s: `--person' (`-p') option given more than once\n", PACKAGE);
00259 clear_args ();
00260 exit (EXIT_FAILURE);
00261 }
00262 args_info->person_given = 1;
00263 args_info->person_arg = strdup (optarg);
00264 break;
00265
00266 case 'g':
00267 if (args_info->group_given)
00268 {
00269 fprintf (stderr, "%s: `--group' (`-g') option given more than once\n", PACKAGE);
00270 clear_args ();
00271 exit (EXIT_FAILURE);
00272 }
00273 args_info->group_given = 1;
00274 args_info->group_arg = strdup (optarg);
00275 break;
00276
00277 case 'o':
00278 if (args_info->onlyOpenTasks_given)
00279 {
00280 fprintf (stderr, "%s: `--onlyOpenTasks' (`-o') option given more than once\n", PACKAGE);
00281 clear_args ();
00282 exit (EXIT_FAILURE);
00283 }
00284 args_info->onlyOpenTasks_given = 1;
00285 args_info->onlyOpenTasks_flag = !(args_info->onlyOpenTasks_flag);
00286 break;
00287
00288 case 'i':
00289 if (args_info->rwIso8601_given)
00290 {
00291 fprintf (stderr, "%s: `--rwIso8601' (`-i') option given more than once\n", PACKAGE);
00292 clear_args ();
00293 exit (EXIT_FAILURE);
00294 }
00295 args_info->rwIso8601_given = 1;
00296 args_info->rwIso8601_flag = !(args_info->rwIso8601_flag);
00297 break;
00298
00299 case 'l':
00300 if (args_info->rwOnlyLeafs_given)
00301 {
00302 fprintf (stderr, "%s: `--rwOnlyLeafs' (`-l') option given more than once\n", PACKAGE);
00303 clear_args ();
00304 exit (EXIT_FAILURE);
00305 }
00306 args_info->rwOnlyLeafs_given = 1;
00307 args_info->rwOnlyLeafs_flag = !(args_info->rwOnlyLeafs_flag);
00308 break;
00309
00310 case 'X':
00311 if (args_info->rwMrPrjFile_given)
00312 {
00313 fprintf (stderr, "%s: `--rwMrPrjFile' (`-X') option given more than once\n", PACKAGE);
00314 clear_args ();
00315 exit (EXIT_FAILURE);
00316 }
00317 args_info->rwMrPrjFile_given = 1;
00318 args_info->rwMrPrjFile_flag = !(args_info->rwMrPrjFile_flag);
00319 break;
00320
00321 case 'M':
00322 if (args_info->rwMemoFile_given)
00323 {
00324 fprintf (stderr, "%s: `--rwMemoFile' (`-M') option given more than once\n", PACKAGE);
00325 clear_args ();
00326 exit (EXIT_FAILURE);
00327 }
00328 args_info->rwMemoFile_given = 1;
00329 args_info->rwMemoFile_flag = !(args_info->rwMemoFile_flag);
00330 break;
00331
00332 case 'P':
00333 if (args_info->rwPilotFile_given)
00334 {
00335 fprintf (stderr, "%s: `--rwPilotFile' (`-P') option given more than once\n", PACKAGE);
00336 clear_args ();
00337 exit (EXIT_FAILURE);
00338 }
00339 args_info->rwPilotFile_given = 1;
00340 args_info->rwPilotFile_flag = !(args_info->rwPilotFile_flag);
00341 break;
00342
00343 case 'v':
00344 if (args_info->rwVcardFile_given)
00345 {
00346 fprintf (stderr, "%s: `--rwVcardFile' (`-v') option given more than once\n", PACKAGE);
00347 clear_args ();
00348 exit (EXIT_FAILURE);
00349 }
00350 args_info->rwVcardFile_given = 1;
00351 args_info->rwVcardFile_flag = !(args_info->rwVcardFile_flag);
00352 break;
00353
00354 case 'Y':
00355 if (args_info->rwYankFile_given)
00356 {
00357 fprintf (stderr, "%s: `--rwYankFile' (`-Y') option given more than once\n", PACKAGE);
00358 clear_args ();
00359 exit (EXIT_FAILURE);
00360 }
00361 args_info->rwYankFile_given = 1;
00362 args_info->rwYankFile_flag = !(args_info->rwYankFile_flag);
00363 break;
00364
00365 case 'C':
00366 if (args_info->rwCslFile_given)
00367 {
00368 fprintf (stderr, "%s: `--rwCslFile' (`-C') option given more than once\n", PACKAGE);
00369 clear_args ();
00370 exit (EXIT_FAILURE);
00371 }
00372 args_info->rwCslFile_given = 1;
00373 args_info->rwCslFile_flag = !(args_info->rwCslFile_flag);
00374 break;
00375
00376 case 'H':
00377 if (args_info->rwHtmlSurvey_given)
00378 {
00379 fprintf (stderr, "%s: `--rwHtmlSurvey' (`-H') option given more than once\n", PACKAGE);
00380 clear_args ();
00381 exit (EXIT_FAILURE);
00382 }
00383 args_info->rwHtmlSurvey_given = 1;
00384 args_info->rwHtmlSurvey_flag = !(args_info->rwHtmlSurvey_flag);
00385 break;
00386
00387 case 'D':
00388 if (args_info->evaluationDate_given)
00389 {
00390 fprintf (stderr, "%s: `--evaluationDate' (`-D') option given more than once\n", PACKAGE);
00391 clear_args ();
00392 exit (EXIT_FAILURE);
00393 }
00394 args_info->evaluationDate_given = 1;
00395 args_info->evaluationDate_arg = strdup (optarg);
00396 break;
00397
00398 case 'd':
00399 if (args_info->debug_given)
00400 {
00401 fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
00402 clear_args ();
00403 exit (EXIT_FAILURE);
00404 }
00405 args_info->debug_given = 1;
00406 args_info->debug_flag = !(args_info->debug_flag);
00407 break;
00408
00409
00410 case 0:
00411
00412 if (strcmp (long_options[option_index].name, "only-open") == 0)
00413 {
00414 if (args_info->only_open_given)
00415 {
00416 fprintf (stderr, "%s: `--only-open' option given more than once\n", PACKAGE);
00417 clear_args ();
00418 exit (EXIT_FAILURE);
00419 }
00420 args_info->only_open_given = 1;
00421 args_info->only_open_flag = !(args_info->only_open_flag);
00422 break;
00423 }
00424
00425 else if (strcmp (long_options[option_index].name, "iso-dates") == 0)
00426 {
00427 if (args_info->iso_dates_given)
00428 {
00429 fprintf (stderr, "%s: `--iso-dates' option given more than once\n", PACKAGE);
00430 clear_args ();
00431 exit (EXIT_FAILURE);
00432 }
00433 args_info->iso_dates_given = 1;
00434 args_info->iso_dates_flag = !(args_info->iso_dates_flag);
00435 break;
00436 }
00437
00438 else if (strcmp (long_options[option_index].name, "only-leafs") == 0)
00439 {
00440 if (args_info->only_leafs_given)
00441 {
00442 fprintf (stderr, "%s: `--only-leafs' option given more than once\n", PACKAGE);
00443 clear_args ();
00444 exit (EXIT_FAILURE);
00445 }
00446 args_info->only_leafs_given = 1;
00447 args_info->only_leafs_flag = !(args_info->only_leafs_flag);
00448 break;
00449 }
00450
00451 else if (strcmp (long_options[option_index].name, "output-mrproject") == 0)
00452 {
00453 if (args_info->output_mrproject_given)
00454 {
00455 fprintf (stderr, "%s: `--output-mrproject' option given more than once\n", PACKAGE);
00456 clear_args ();
00457 exit (EXIT_FAILURE);
00458 }
00459 args_info->output_mrproject_given = 1;
00460 args_info->output_mrproject_flag = !(args_info->output_mrproject_flag);
00461 break;
00462 }
00463
00464 else if (strcmp (long_options[option_index].name, "output-memo") == 0)
00465 {
00466 if (args_info->output_memo_given)
00467 {
00468 fprintf (stderr, "%s: `--output-memo' option given more than once\n", PACKAGE);
00469 clear_args ();
00470 exit (EXIT_FAILURE);
00471 }
00472 args_info->output_memo_given = 1;
00473 args_info->output_memo_flag = !(args_info->output_memo_flag);
00474 break;
00475 }
00476
00477 else if (strcmp (long_options[option_index].name, "output-pilot") == 0)
00478 {
00479 if (args_info->output_pilot_given)
00480 {
00481 fprintf (stderr, "%s: `--output-pilot' option given more than once\n", PACKAGE);
00482 clear_args ();
00483 exit (EXIT_FAILURE);
00484 }
00485 args_info->output_pilot_given = 1;
00486 args_info->output_pilot_flag = !(args_info->output_pilot_flag);
00487 break;
00488 }
00489
00490 else if (strcmp (long_options[option_index].name, "output-vcard") == 0)
00491 {
00492 if (args_info->output_vcard_given)
00493 {
00494 fprintf (stderr, "%s: `--output-vcard' option given more than once\n", PACKAGE);
00495 clear_args ();
00496 exit (EXIT_FAILURE);
00497 }
00498 args_info->output_vcard_given = 1;
00499 args_info->output_vcard_flag = !(args_info->output_vcard_flag);
00500 break;
00501 }
00502
00503 else if (strcmp (long_options[option_index].name, "output-yank") == 0)
00504 {
00505 if (args_info->output_yank_given)
00506 {
00507 fprintf (stderr, "%s: `--output-yank' option given more than once\n", PACKAGE);
00508 clear_args ();
00509 exit (EXIT_FAILURE);
00510 }
00511 args_info->output_yank_given = 1;
00512 args_info->output_yank_flag = !(args_info->output_yank_flag);
00513 break;
00514 }
00515
00516 else if (strcmp (long_options[option_index].name, "output-csl") == 0)
00517 {
00518 if (args_info->output_csl_given)
00519 {
00520 fprintf (stderr, "%s: `--output-csl' option given more than once\n", PACKAGE);
00521 clear_args ();
00522 exit (EXIT_FAILURE);
00523 }
00524 args_info->output_csl_given = 1;
00525 args_info->output_csl_flag = !(args_info->output_csl_flag);
00526 break;
00527 }
00528
00529 else if (strcmp (long_options[option_index].name, "output-html") == 0)
00530 {
00531 if (args_info->output_html_given)
00532 {
00533 fprintf (stderr, "%s: `--output-html' option given more than once\n", PACKAGE);
00534 clear_args ();
00535 exit (EXIT_FAILURE);
00536 }
00537 args_info->output_html_given = 1;
00538 args_info->output_html_flag = !(args_info->output_html_flag);
00539 break;
00540 }
00541
00542 case '?':
00543
00544 exit (EXIT_FAILURE);
00545
00546 default:
00547 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
00548 abort ();
00549 }
00550 }
00551
00552
00553 if ( missing_required_options )
00554 exit (EXIT_FAILURE);
00555
00556 return 0;
00557 }