use gnu indent to enforce coding style and adapt source

- indent options are listed in ./.indent.pro
 - use test case to run indent
This commit is contained in:
josch
2014-09-20 10:59:54 +02:00
parent d8e00119b4
commit 097a855751
43 changed files with 1325 additions and 1278 deletions

View File

@@ -16,74 +16,72 @@
*
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "stringv.h"
size_t
stringv_len(char **array)
size_t stringv_len(char **array)
{
size_t count = 0;
char **pos;
size_t count = 0;
char **pos;
if(array == NULL) return 0;
if (array == NULL)
return 0;
pos = array;
while(pos[0] != NULL)
{
while (pos[0] != NULL) {
pos++;
count++;
}
return count;
return count;
}
void
stringv_free(char **array,int b_free)
void stringv_free(char **array, int b_free)
{
char **pos;
char **pos;
if(array == NULL) return;
if (array == NULL)
return;
pos = array;
pos = array;
while((*pos) != NULL)
{
free(*pos);
++pos;
}
while ((*pos) != NULL) {
free(*pos);
++pos;
}
if(b_free == STRINGV_FREE_ALL) free(array);
if (b_free == STRINGV_FREE_ALL)
free(array);
return;
}
char**
stringv_copy(char **array)
char **stringv_copy(char **array)
{
uint32_t array_len;
char **array_pos;
uint32_t array_len;
char **array_pos;
char **dup_array;
char **dup_pos;
char **dup_array;
char **dup_pos;
if(array == NULL) return (char**)NULL;
if (array == NULL)
return (char **)NULL;
array_pos = array;
array_len = stringv_len(array);
if(array_len > UINT32_MAX - 1) array_len = UINT32_MAX -1;
if (array_len > UINT32_MAX - 1)
array_len = UINT32_MAX - 1;
dup_array = (char**)calloc(array_len,sizeof(char*));
dup_array = (char **)calloc(array_len, sizeof(char *));
dup_pos = dup_array;
while((*array_pos) != NULL)
{
*dup_pos = strdup((const char*)*array_pos);
while ((*array_pos) != NULL) {
*dup_pos = strdup((const char *)*array_pos);
array_pos++;
dup_pos++;
@@ -92,82 +90,89 @@ stringv_copy(char **array)
return dup_array;
}
char**
stringv_find(char *string,char *token,int limit)
char **stringv_find(char *string, char *token, int limit)
{
char **results = NULL;
char *pos = NULL;
int count = 0;
char **results = NULL;
char *pos = NULL;
int count = 0;
if(string == NULL) return (char**)NULL;
if(token == NULL) return (char**)NULL;
if(limit == 0) return (char**)NULL;
if (string == NULL)
return (char **)NULL;
if (token == NULL)
return (char **)NULL;
if (limit == 0)
return (char **)NULL;
pos = string;
if(strlen(token) > strlen(string)) return (char**)NULL;
if (strlen(token) > strlen(string))
return (char **)NULL;
while(count != limit)
{
pos = strstr(pos,token);
if(pos == NULL) break;
while (count != limit) {
pos = strstr(pos, token);
if (pos == NULL)
break;
count++;
results = (char**)realloc((void*)results,sizeof(char*) * count + 1);
results = (char **)realloc((void *)results, sizeof(char *) * count + 1);
results[count - 1] = pos;
}
if(count == 0) return (char**)NULL;
if (count == 0)
return (char **)NULL;
results[count] = (char*)NULL;
results[count] = (char *)NULL;
return results;
}
char**
stringv_split(char *string,char *token,int limit)
char **stringv_split(char *string, char *token, int limit)
{
char **results = NULL;
char *curr = NULL;
char *next = NULL;
int count = 0;
unsigned int len;
size_t copy_len = 0;
char **results = NULL;
char *curr = NULL;
char *next = NULL;
int count = 0;
unsigned int len;
size_t copy_len = 0;
if(string == NULL) return (char**)NULL;
if(token == NULL) return (char**)NULL;
if(limit == 0) return (char**)NULL;
if (string == NULL)
return (char **)NULL;
if (token == NULL)
return (char **)NULL;
if (limit == 0)
return (char **)NULL;
len = strlen(string);
if(strlen(token) > len) return (char**)NULL;
if (strlen(token) > len)
return (char **)NULL;
curr = string;
do
{
do {
// alloc space for current item plus NULL vector terminator
results = (char**)realloc(results,sizeof(char*) * (count + 2));
results = (char **)realloc(results, sizeof(char *) * (count + 2));
// find the next occurrence
next = strstr(curr,token);
next = strstr(curr, token);
if(next != NULL)
if (next != NULL)
copy_len = next - curr;
else
copy_len = strlen(curr);
results[count] = (char*)calloc(copy_len + 1,sizeof(char));
memcpy(results[count],curr,copy_len);
results[count] = (char *)calloc(copy_len + 1, sizeof(char));
memcpy(results[count], curr, copy_len);
count++;
if(next == NULL) break;
if (next == NULL)
break;
curr = next;
curr++;
}
while(count < limit);
while (count < limit);
results[count] = NULL;