diff options
author | Avuton Olrich <avuton@gmail.com> | 2006-07-20 16:02:40 +0000 |
---|---|---|
committer | Avuton Olrich <avuton@gmail.com> | 2006-07-20 16:02:40 +0000 |
commit | 29a25b9933b32800f58dd73d5d1fc21993071c92 (patch) | |
tree | 4f456a6f8e44d42acc289c35534ea3e59c0aa96f /src/buffer2array.c | |
parent | 099f0e103f7591eef81183292d704b3a77a99018 (diff) | |
download | mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.tar.gz mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.tar.xz mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.zip |
Add mpd-indent.sh
Indent the entire tree, hopefully we can keep
it indented.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/buffer2array.c')
-rw-r--r-- | src/buffer2array.c | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/src/buffer2array.c b/src/buffer2array.c index 0d8170260..4a0751eae 100644 --- a/src/buffer2array.c +++ b/src/buffer2array.c @@ -22,79 +22,74 @@ #include <stdlib.h> #include <string.h> -int buffer2array(char * origBuffer, char *** array) { +int buffer2array(char *origBuffer, char ***array) +{ int quotes = 0; int count = 0; int i; int curr; - int * beginArray; - char * buffer = strdup(origBuffer); + int *beginArray; + char *buffer = strdup(origBuffer); int bufferLength = strlen(buffer); - char * markArray = malloc(sizeof(char)*(bufferLength+1)); + char *markArray = malloc(sizeof(char) * (bufferLength + 1)); - for(curr=0;curr<bufferLength;curr++) { - if(!quotes && (buffer[curr]==' ' || buffer[curr]=='\t') ) { + for (curr = 0; curr < bufferLength; curr++) { + if (!quotes && (buffer[curr] == ' ' || buffer[curr] == '\t')) { markArray[curr] = '0'; - } - else if(buffer[curr] == '\"') { - if(curr>0 && buffer[curr-1]!='\\') { - quotes = quotes?0:1; + } else if (buffer[curr] == '\"') { + if (curr > 0 && buffer[curr - 1] != '\\') { + quotes = quotes ? 0 : 1; markArray[curr] = '0'; - } - else { + } else { markArray[curr] = '1'; } - } - else { + } else { markArray[curr] = '1'; } - if(markArray[curr]=='1') { - if(curr>0) { - if(markArray[curr-1]=='0') { + if (markArray[curr] == '1') { + if (curr > 0) { + if (markArray[curr - 1] == '0') { count++; } - } - else { + } else { count++; } } } markArray[bufferLength] = '\0'; - if(!count) { + if (!count) { free(buffer); free(markArray); return count; } - beginArray = malloc(sizeof(int)*count); - (*array) = malloc(sizeof(char *)*count); + beginArray = malloc(sizeof(int) * count); + (*array) = malloc(sizeof(char *) * count); count = 0; - - for(curr=0;curr<bufferLength;curr++) { - if(markArray[curr]=='1') { - if(curr>0) { - if(markArray[curr-1]=='0') { + + for (curr = 0; curr < bufferLength; curr++) { + if (markArray[curr] == '1') { + if (curr > 0) { + if (markArray[curr - 1] == '0') { beginArray[count++] = curr; } - } - else { + } else { beginArray[count++] = curr; } - } - else { + } else { buffer[curr] = '\0'; } } - for(i=0;i<count;i++) { - int len = strlen(buffer+beginArray[i])+1; + for (i = 0; i < count; i++) { + int len = strlen(buffer + beginArray[i]) + 1; int arrayCurr = 0; - (*array)[i] = malloc(sizeof(char)*len); - for(curr=beginArray[i];buffer[curr]!='\0';curr++) { - if(buffer[curr]=='\\') { - if(buffer[curr+1]!='\0') { + (*array)[i] = malloc(sizeof(char) * len); + for (curr = beginArray[i]; buffer[curr] != '\0'; curr++) { + if (buffer[curr] == '\\') { + if (buffer[curr + 1] != '\0') { curr++; } } @@ -110,12 +105,14 @@ int buffer2array(char * origBuffer, char *** array) { return count; } -void freeArgArray(char ** array, int argArrayLength) { +void freeArgArray(char **array, int argArrayLength) +{ int i; - if(argArrayLength==0) return; + if (argArrayLength == 0) + return; - for(i=0;i<argArrayLength;i++) { + for (i = 0; i < argArrayLength; i++) { free(array[i]); } free(array); |