|
Packit |
1fb8d4 |
/*
|
|
Packit |
1fb8d4 |
* String List Utils
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Copyright 2018 Pascal Bourguignon <pjb@informatimago.com>
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit |
1fb8d4 |
* you may not use this file except in compliance with the License.
|
|
Packit |
1fb8d4 |
* You may obtain a copy of the License at
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
1fb8d4 |
*
|
|
Packit |
1fb8d4 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
1fb8d4 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
1fb8d4 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
1fb8d4 |
* See the License for the specific language governing permissions and
|
|
Packit |
1fb8d4 |
* limitations under the License.
|
|
Packit |
1fb8d4 |
*/
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
1fb8d4 |
#include "config.h"
|
|
Packit |
1fb8d4 |
#endif
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <stdio.h>
|
|
Packit |
1fb8d4 |
#include <stdlib.h>
|
|
Packit |
1fb8d4 |
#include <string.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
#include <winpr/strlst.h>
|
|
Packit Service |
5a9772 |
#include <winpr/string.h>
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void string_list_free(char** string_list)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
int i;
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
for (i = 0; string_list[i]; i++)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
free(string_list[i]);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
free(string_list);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
int string_list_length(const char* const* string_list)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
int i;
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
for (i = 0; string_list[i]; i++)
|
|
Packit Service |
5a9772 |
;
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
return i;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
char** string_list_copy(const char* const* string_list)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
int i;
|
|
Packit |
1fb8d4 |
int length = string_list_length(string_list);
|
|
Packit Service |
5a9772 |
char** copy = calloc(length + 1, sizeof(char*));
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
if (!copy)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
return 0;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
for (i = 0; i < length; i++)
|
|
Packit |
1fb8d4 |
{
|
|
Packit Service |
5a9772 |
copy[i] = _strdup(string_list[i]);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
copy[length] = 0;
|
|
Packit |
1fb8d4 |
return copy;
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
void string_list_print(FILE* out, const char* const* string_list)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
int j;
|
|
Packit |
1fb8d4 |
|
|
Packit Service |
5a9772 |
for (j = 0; string_list[j]; j++)
|
|
Packit |
1fb8d4 |
{
|
|
Packit |
1fb8d4 |
fprintf(out, "[%2d]: %s\n", j, string_list[j]);
|
|
Packit |
1fb8d4 |
}
|
|
Packit |
1fb8d4 |
|
|
Packit |
1fb8d4 |
fflush(out);
|
|
Packit |
1fb8d4 |
}
|