mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-26 00:12:31 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
315
WINGs/string.c
315
WINGs/string.c
@@ -7,8 +7,6 @@
|
||||
|
||||
#include "WUtil.h"
|
||||
|
||||
|
||||
|
||||
#define PRC_ALPHA 0
|
||||
#define PRC_BLANK 1
|
||||
#define PRC_ESCAPE 2
|
||||
@@ -17,234 +15,211 @@
|
||||
#define PRC_SQUOTE 5
|
||||
|
||||
typedef struct {
|
||||
short nstate;
|
||||
short output;
|
||||
short nstate;
|
||||
short output;
|
||||
} DFA;
|
||||
|
||||
|
||||
static DFA mtable[9][6] = {
|
||||
{{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
|
||||
{{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
|
||||
{{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
|
||||
{{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
|
||||
{{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
|
||||
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
|
||||
{{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
|
||||
{{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
|
||||
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
|
||||
{{3, 1}, {0, 0}, {4, 0}, {1, 0}, {8, 0}, {6, 0}},
|
||||
{{1, 1}, {1, 1}, {2, 0}, {3, 0}, {5, 0}, {1, 1}},
|
||||
{{1, 1}, {1, 1}, {1, 1}, {1, 1}, {5, 0}, {1, 1}},
|
||||
{{3, 1}, {5, 0}, {4, 0}, {1, 0}, {5, 0}, {6, 0}},
|
||||
{{3, 1}, {3, 1}, {3, 1}, {3, 1}, {5, 0}, {3, 1}},
|
||||
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */
|
||||
{{6, 1}, {6, 1}, {7, 0}, {6, 1}, {5, 0}, {3, 0}},
|
||||
{{6, 1}, {6, 1}, {6, 1}, {6, 1}, {5, 0}, {6, 1}},
|
||||
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */
|
||||
};
|
||||
|
||||
char*
|
||||
wtokennext(char *word, char **next)
|
||||
char *wtokennext(char *word, char **next)
|
||||
{
|
||||
char *ptr;
|
||||
char *ret, *t;
|
||||
int state, ctype;
|
||||
char *ptr;
|
||||
char *ret, *t;
|
||||
int state, ctype;
|
||||
|
||||
t = ret = wmalloc(strlen(word)+1);
|
||||
ptr = word;
|
||||
t = ret = wmalloc(strlen(word) + 1);
|
||||
ptr = word;
|
||||
|
||||
state = 0;
|
||||
*t = 0;
|
||||
while (1) {
|
||||
if (*ptr==0)
|
||||
ctype = PRC_EOS;
|
||||
else if (*ptr=='\\')
|
||||
ctype = PRC_ESCAPE;
|
||||
else if (*ptr=='"')
|
||||
ctype = PRC_DQUOTE;
|
||||
else if (*ptr=='\'')
|
||||
ctype = PRC_SQUOTE;
|
||||
else if (*ptr==' ' || *ptr=='\t')
|
||||
ctype = PRC_BLANK;
|
||||
else
|
||||
ctype = PRC_ALPHA;
|
||||
state = 0;
|
||||
*t = 0;
|
||||
while (1) {
|
||||
if (*ptr == 0)
|
||||
ctype = PRC_EOS;
|
||||
else if (*ptr == '\\')
|
||||
ctype = PRC_ESCAPE;
|
||||
else if (*ptr == '"')
|
||||
ctype = PRC_DQUOTE;
|
||||
else if (*ptr == '\'')
|
||||
ctype = PRC_SQUOTE;
|
||||
else if (*ptr == ' ' || *ptr == '\t')
|
||||
ctype = PRC_BLANK;
|
||||
else
|
||||
ctype = PRC_ALPHA;
|
||||
|
||||
if (mtable[state][ctype].output) {
|
||||
*t = *ptr; t++;
|
||||
*t = 0;
|
||||
}
|
||||
state = mtable[state][ctype].nstate;
|
||||
ptr++;
|
||||
if (mtable[state][0].output<0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mtable[state][ctype].output) {
|
||||
*t = *ptr;
|
||||
t++;
|
||||
*t = 0;
|
||||
}
|
||||
state = mtable[state][ctype].nstate;
|
||||
ptr++;
|
||||
if (mtable[state][0].output < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*ret==0)
|
||||
t = NULL;
|
||||
else
|
||||
t = wstrdup(ret);
|
||||
if (*ret == 0)
|
||||
t = NULL;
|
||||
else
|
||||
t = wstrdup(ret);
|
||||
|
||||
wfree(ret);
|
||||
wfree(ret);
|
||||
|
||||
if (ctype==PRC_EOS)
|
||||
*next = NULL;
|
||||
else
|
||||
*next = ptr;
|
||||
if (ctype == PRC_EOS)
|
||||
*next = NULL;
|
||||
else
|
||||
*next = ptr;
|
||||
|
||||
return t;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/* separate a string in tokens, taking " and ' into account */
|
||||
void
|
||||
wtokensplit(char *command, char ***argv, int *argc)
|
||||
void wtokensplit(char *command, char ***argv, int *argc)
|
||||
{
|
||||
char *token, *line;
|
||||
int count;
|
||||
char *token, *line;
|
||||
int count;
|
||||
|
||||
count = 0;
|
||||
line = command;
|
||||
do {
|
||||
token = wtokennext(line, &line);
|
||||
if (token) {
|
||||
if (count == 0)
|
||||
*argv = wmalloc(sizeof(char**));
|
||||
else
|
||||
*argv = wrealloc(*argv, (count+1)*sizeof(char**));
|
||||
(*argv)[count++] = token;
|
||||
}
|
||||
} while (token!=NULL && line!=NULL);
|
||||
count = 0;
|
||||
line = command;
|
||||
do {
|
||||
token = wtokennext(line, &line);
|
||||
if (token) {
|
||||
if (count == 0)
|
||||
*argv = wmalloc(sizeof(char **));
|
||||
else
|
||||
*argv = wrealloc(*argv, (count + 1) * sizeof(char **));
|
||||
(*argv)[count++] = token;
|
||||
}
|
||||
} while (token != NULL && line != NULL);
|
||||
|
||||
*argc = count;
|
||||
*argc = count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
char*
|
||||
wtokenjoin(char **list, int count)
|
||||
char *wtokenjoin(char **list, int count)
|
||||
{
|
||||
int i, j;
|
||||
char *flat_string, *wspace;
|
||||
int i, j;
|
||||
char *flat_string, *wspace;
|
||||
|
||||
j = 0;
|
||||
for (i=0; i<count; i++) {
|
||||
if (list[i]!=NULL && list[i][0]!=0) {
|
||||
j += strlen(list[i]);
|
||||
if (strpbrk(list[i], " \t"))
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
j = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (list[i] != NULL && list[i][0] != 0) {
|
||||
j += strlen(list[i]);
|
||||
if (strpbrk(list[i], " \t"))
|
||||
j += 2;
|
||||
}
|
||||
}
|
||||
|
||||
flat_string = wmalloc(j+count+1);
|
||||
flat_string = wmalloc(j + count + 1);
|
||||
|
||||
*flat_string = 0;
|
||||
for (i=0; i<count; i++) {
|
||||
if (list[i]!=NULL && list[i][0]!=0) {
|
||||
if (i>0)
|
||||
strcat(flat_string, " ");
|
||||
wspace = strpbrk(list[i], " \t");
|
||||
if (wspace)
|
||||
strcat(flat_string, "\"");
|
||||
strcat(flat_string, list[i]);
|
||||
if (wspace)
|
||||
strcat(flat_string, "\"");
|
||||
}
|
||||
}
|
||||
*flat_string = 0;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (list[i] != NULL && list[i][0] != 0) {
|
||||
if (i > 0)
|
||||
strcat(flat_string, " ");
|
||||
wspace = strpbrk(list[i], " \t");
|
||||
if (wspace)
|
||||
strcat(flat_string, "\"");
|
||||
strcat(flat_string, list[i]);
|
||||
if (wspace)
|
||||
strcat(flat_string, "\"");
|
||||
}
|
||||
}
|
||||
|
||||
return flat_string;
|
||||
return flat_string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
wtokenfree(char **tokens, int count)
|
||||
void wtokenfree(char **tokens, int count)
|
||||
{
|
||||
while (--count) wfree(tokens[count]);
|
||||
wfree(tokens);
|
||||
while (--count)
|
||||
wfree(tokens[count]);
|
||||
wfree(tokens);
|
||||
}
|
||||
|
||||
|
||||
|
||||
char*
|
||||
wtrimspace(char *s)
|
||||
char *wtrimspace(char *s)
|
||||
{
|
||||
char *t;
|
||||
char *c;
|
||||
char *t;
|
||||
char *c;
|
||||
|
||||
while (isspace(*s) && *s) s++;
|
||||
t = s+strlen(s)-1;
|
||||
while (t > s && isspace(*t)) t--;
|
||||
while (isspace(*s) && *s)
|
||||
s++;
|
||||
t = s + strlen(s) - 1;
|
||||
while (t > s && isspace(*t))
|
||||
t--;
|
||||
|
||||
c = wmalloc(t-s+2);
|
||||
memcpy(c, s, t-s+1);
|
||||
c[t-s+1] = 0;
|
||||
c = wmalloc(t - s + 2);
|
||||
memcpy(c, s, t - s + 1);
|
||||
c[t - s + 1] = 0;
|
||||
|
||||
return c;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wstrdup(char *str)
|
||||
char *wstrdup(char *str)
|
||||
{
|
||||
assert(str!=NULL);
|
||||
assert(str != NULL);
|
||||
|
||||
return strcpy(wmalloc(strlen(str)+1), str);
|
||||
return strcpy(wmalloc(strlen(str) + 1), str);
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wstrndup(char *str, size_t len)
|
||||
char *wstrndup(char *str, size_t len)
|
||||
{
|
||||
char *copy;
|
||||
char *copy;
|
||||
|
||||
assert(str!=NULL);
|
||||
assert(str != NULL);
|
||||
|
||||
len = WMIN(len, strlen(str));
|
||||
copy = strncpy(wmalloc(len+1), str, len);
|
||||
copy[len] = 0;
|
||||
len = WMIN(len, strlen(str));
|
||||
copy = strncpy(wmalloc(len + 1), str, len);
|
||||
copy[len] = 0;
|
||||
|
||||
return copy;
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wstrconcat(char *str1, char *str2)
|
||||
char *wstrconcat(char *str1, char *str2)
|
||||
{
|
||||
char *str;
|
||||
char *str;
|
||||
|
||||
if (!str1)
|
||||
return wstrdup(str2);
|
||||
else if (!str2)
|
||||
return wstrdup(str1);
|
||||
if (!str1)
|
||||
return wstrdup(str2);
|
||||
else if (!str2)
|
||||
return wstrdup(str1);
|
||||
|
||||
str = wmalloc(strlen(str1)+strlen(str2)+1);
|
||||
strcpy(str, str1);
|
||||
strcat(str, str2);
|
||||
str = wmalloc(strlen(str1) + strlen(str2) + 1);
|
||||
strcpy(str, str1);
|
||||
strcat(str, str2);
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
wstrappend(char *dst, char *src)
|
||||
char *wstrappend(char *dst, char *src)
|
||||
{
|
||||
if (!dst)
|
||||
return wstrdup(src);
|
||||
else if (!src || *src==0)
|
||||
return dst;
|
||||
if (!dst)
|
||||
return wstrdup(src);
|
||||
else if (!src || *src == 0)
|
||||
return dst;
|
||||
|
||||
dst = wrealloc(dst, strlen(dst)+strlen(src)+1);
|
||||
strcat(dst, src);
|
||||
dst = wrealloc(dst, strlen(dst) + strlen(src) + 1);
|
||||
strcat(dst, src);
|
||||
|
||||
return dst;
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
#ifndef HAVE_STRCASECMP
|
||||
int
|
||||
strcasecmp(const char *s1, const char *s2)
|
||||
int strcasecmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && (tolower(*s1)==tolower(*s2))) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
while (*s1 && *s2 && (tolower(*s1) == tolower(*s2))) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (tolower(*s1) - tolower(*s2));
|
||||
return (tolower(*s1) - tolower(*s2));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user