From: <svn...@op...> - 2009-04-15 20:48:44
|
Author: scriptor Date: Wed Apr 15 22:48:31 2009 New Revision: 5614 URL: http://www.opensync.org/changeset/5614 Log: Modified command line parsing in orientation towards http://www.opensync.org/ticket/853 Modified: plugins/ldap-sync/misc/ldap_format_convert.c plugins/ldap-sync/tests/check_do_convert_from_to.c Modified: plugins/ldap-sync/misc/ldap_format_convert.c ============================================================================== --- plugins/ldap-sync/misc/ldap_format_convert.c Tue Apr 14 20:27:12 2009 (r5613) +++ plugins/ldap-sync/misc/ldap_format_convert.c Wed Apr 15 22:48:31 2009 (r5614) @@ -942,9 +942,7 @@ program = argv[0]; - input_filename = argv[1]; - - for (i = 2; i < argc; i++) { + for (i = 1; i < argc; i++) { char *arg = argv[i]; @@ -996,6 +994,7 @@ } else if (!strcmp (arg, "--to-ldap-note")) { detection_type = TARGET_LDAP_NOTE; + } else if (!strcmp (arg, "--out")) { if (!strncmp(argv[i + 1], "--", 2)) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Output filename MUST NOT begin with \'--\'. Use --help, if necessary.", __FILE__, __LINE__); @@ -1012,6 +1011,7 @@ } else { output_filename = argv[i + 1]; i++; + continue; } } else if (!strcmp (arg, "--")) { @@ -1021,14 +1021,24 @@ osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: \"-\" is an invalid option. Use --help, if necessary.\n", __FILE__, __LINE__); goto error; - } else { - osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Unknown option.\n", __FILE__, __LINE__); + } else if (arg[0] == '-' && arg[1] != 0) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Unknown option\"%s\".\n", __FILE__, __LINE__, arg); goto error; + + } else { + input_filename = arg; + + } + } + if (i < argc && argv[i + 1]) { + if (argv[i + 1][0]) { + input_filename = argv[i + 1]; } } + // Check input_filename if (input_filename == NULL) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: input_filename = NULL. input_filename has not been set.", __FILE__, __LINE__); @@ -1036,6 +1046,10 @@ goto error; } + + osync_trace(TRACE_INTERNAL, "input_filename = \"%s\", i = %i, argc = %i\n", input_filename, i, argc); + + if (input_filename[0] == 0) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: input_filename[0] = 0. input_filename has not been set.", __FILE__, __LINE__); Modified: plugins/ldap-sync/tests/check_do_convert_from_to.c ============================================================================== --- plugins/ldap-sync/tests/check_do_convert_from_to.c Tue Apr 14 20:27:12 2009 (r5613) +++ plugins/ldap-sync/tests/check_do_convert_from_to.c Wed Apr 15 22:48:31 2009 (r5614) @@ -942,9 +942,7 @@ program = argv[0]; - input_filename = argv[1]; - - for (i = 2; i < argc; i++) { + for (i = 1; i < argc; i++) { char *arg = argv[i]; @@ -996,6 +994,7 @@ } else if (!strcmp (arg, "--to-ldap-note")) { detection_type = TARGET_LDAP_NOTE; + } else if (!strcmp (arg, "--out")) { if (!strncmp(argv[i + 1], "--", 2)) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Output filename MUST NOT begin with \'--\'. Use --help, if necessary.", __FILE__, __LINE__); @@ -1012,6 +1011,7 @@ } else { output_filename = argv[i + 1]; i++; + continue; } } else if (!strcmp (arg, "--")) { @@ -1021,14 +1021,24 @@ osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: \"-\" is an invalid option. Use --help, if necessary.\n", __FILE__, __LINE__); goto error; - } else { - osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Unknown option.\n", __FILE__, __LINE__); + } else if (arg[0] == '-' && arg[1] != 0) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Unknown option\"%s\".\n", __FILE__, __LINE__, arg); goto error; + + } else { + input_filename = arg; + + } + } + if (i < argc && argv[i + 1]) { + if (argv[i + 1][0]) { + input_filename = argv[i + 1]; } } + // Check input_filename if (input_filename == NULL) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: input_filename = NULL. input_filename has not been set.", __FILE__, __LINE__); @@ -1036,6 +1046,10 @@ goto error; } + + osync_trace(TRACE_INTERNAL, "input_filename = \"%s\", i = %i, argc = %i\n", input_filename, i, argc); + + if (input_filename[0] == 0) { osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: input_filename[0] = 0. input_filename has not been set.", __FILE__, __LINE__); |