1
1

* adjust the ompi_argv_delete() function so that it shortens the passed

argv array to match the deletion of elements in the array.

This commit was SVN r3722.
Этот коммит содержится в:
Brian Barrett 2004-12-07 02:42:17 +00:00
родитель 555b261129
Коммит 785c3d1408
4 изменённых файлов: 25 добавлений и 17 удалений

Просмотреть файл

@ -265,16 +265,17 @@ char **ompi_argv_copy(char **argv)
}
int ompi_argv_delete(char **argv, int start, int num_to_delete)
int ompi_argv_delete(int *argc, char ***argv, int start, int num_to_delete)
{
int i;
int count;
int suffix_count;
char **tmp;
/* Check for the bozo cases */
count = ompi_argv_count(argv);
if (NULL == argv || start > count || 0 == num_to_delete) {
count = ompi_argv_count(*argv);
if (NULL == argv || NULL == *argv || start > count || 0 == num_to_delete) {
return OMPI_SUCCESS;
} else if (start < 0 || num_to_delete < 0) {
return OMPI_ERR_BAD_PARAM;
@ -291,18 +292,22 @@ int ompi_argv_delete(char **argv, int start, int num_to_delete)
/* Free all items that are being deleted */
for (i = start; i < count && i < start + num_to_delete; ++i) {
free(argv[i]);
free(*argv[i]);
}
/* Copy the suffix over the deleted items */
for (i = start; i < start + suffix_count; ++i) {
argv[i] = argv[i + num_to_delete];
*argv[i] = *argv[i + num_to_delete];
}
/* Add the trailing NULL */
argv[i] = NULL;
*argv[i] = NULL;
/* adjust the argv array */
tmp = realloc(*argv, sizeof(char**) * (i + 1));
if (NULL != tmp) *argv = tmp;
return OMPI_SUCCESS;
}

Просмотреть файл

@ -155,7 +155,8 @@ OMPI_DECLSPEC char **ompi_argv_copy(char **argv);
*
* Delete some tokens from within an existing argv. The start
* parameter specifies the first token to delete, and will delete
* (num_to_delete-1) tokens following it.
* (num_to_delete-1) tokens following it. argv will be realloc()ed
* to *argc - num_deleted size.
*
* If start is beyond the end of the argv array, this function is
* a no-op.
@ -168,7 +169,8 @@ OMPI_DECLSPEC char **ompi_argv_copy(char **argv);
* free()ed (it is assumed that the argv "owns" the memory that
* the pointer points to).
*/
OMPI_DECLSPEC int ompi_argv_delete(char **argv, int start, int num_to_delete);
OMPI_DECLSPEC int ompi_argv_delete(int *argc, char ***argv,
int start, int num_to_delete);
/**
* Insert one argv array into the middle of another

Просмотреть файл

@ -265,7 +265,8 @@ int ompi_cmd_line_parse(ompi_cmd_line_t *cmd, bool ignore_unknown,
option = find_option(cmd, shortsv[0] + 1);
if (NULL != option) {
ompi_argv_delete(cmd->lcl_argv, i,
ompi_argv_delete(&cmd->lcl_argc,
&cmd->lcl_argv, i,
1 + num_args_used);
ompi_argv_insert(&cmd->lcl_argv, i, shortsv);
cmd->lcl_argc = ompi_argv_count(cmd->lcl_argv);

Просмотреть файл

@ -372,7 +372,7 @@ static bool test9(void)
a = NULL;
argc = 0;
ompi_argv_append(&argc, &a, "foo");
if (OMPI_SUCCESS != ompi_argv_delete(a, 7, 1) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 7, 1) ||
1 != ompi_argv_count(a)) {
return false;
}
@ -381,7 +381,7 @@ static bool test9(void)
a = NULL;
argc = 0;
ompi_argv_append(&argc, &a, "foo");
if (OMPI_SUCCESS != ompi_argv_delete(a, 0, 0) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 0, 0) ||
1 != ompi_argv_count(a)) {
return false;
}
@ -398,7 +398,7 @@ static bool test9(void)
ompi_argv_append(&argc, &a, "d");
ompi_argv_append(&argc, &a, "e");
ompi_argv_append(&argc, &a, "f");
if (OMPI_SUCCESS != ompi_argv_delete(a, 0, 1) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 0, 1) ||
5 != ompi_argv_count(a) ||
0 != strcmp(a[0], "b") ||
0 != strcmp(a[1], "c") ||
@ -419,7 +419,7 @@ static bool test9(void)
ompi_argv_append(&argc, &a, "d");
ompi_argv_append(&argc, &a, "e");
ompi_argv_append(&argc, &a, "f");
if (OMPI_SUCCESS != ompi_argv_delete(a, 0, 2) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 0, 2) ||
4 != ompi_argv_count(a) ||
0 != strcmp(a[0], "c") ||
0 != strcmp(a[1], "d") ||
@ -439,7 +439,7 @@ static bool test9(void)
ompi_argv_append(&argc, &a, "d");
ompi_argv_append(&argc, &a, "e");
ompi_argv_append(&argc, &a, "f");
if (OMPI_SUCCESS != ompi_argv_delete(a, 1, 1) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 1, 1) ||
5 != ompi_argv_count(a) ||
0 != strcmp(a[0], "a") ||
0 != strcmp(a[1], "c") ||
@ -460,7 +460,7 @@ static bool test9(void)
ompi_argv_append(&argc, &a, "d");
ompi_argv_append(&argc, &a, "e");
ompi_argv_append(&argc, &a, "f");
if (OMPI_SUCCESS != ompi_argv_delete(a, 1, 2) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 1, 2) ||
4 != ompi_argv_count(a) ||
0 != strcmp(a[0], "a") ||
0 != strcmp(a[1], "d") ||
@ -476,7 +476,7 @@ static bool test9(void)
argc = 0;
ompi_argv_append(&argc, &a, "a");
ompi_argv_append(&argc, &a, "b");
if (OMPI_SUCCESS != ompi_argv_delete(a, 0, 99) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 0, 99) ||
0 != ompi_argv_count(a)) {
return false;
}
@ -488,7 +488,7 @@ static bool test9(void)
argc = 0;
ompi_argv_append(&argc, &a, "a");
ompi_argv_append(&argc, &a, "b");
if (OMPI_SUCCESS != ompi_argv_delete(a, 1, 99) ||
if (OMPI_SUCCESS != ompi_argv_delete(&argc, &a, 1, 99) ||
1 != ompi_argv_count(a) ||
0 != strcmp(a[0], "a")) {
return false;