- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
92
trim.c
92
trim.c
@ -11,58 +11,52 @@
|
||||
|
||||
char *trim(char *str)
|
||||
{
|
||||
char *ibuf = str, *obuf = str;
|
||||
int i = 0, cnt = 0;
|
||||
char *ibuf = str, *obuf = str;
|
||||
int i = 0, cnt = 0;
|
||||
|
||||
/*
|
||||
** Trap NULL
|
||||
*/
|
||||
/*
|
||||
** Trap NULL
|
||||
*/
|
||||
|
||||
if (str)
|
||||
{
|
||||
/*
|
||||
** Remove leading spaces (from RMLEAD.C)
|
||||
*/
|
||||
if (str) {
|
||||
/*
|
||||
** Remove leading spaces (from RMLEAD.C)
|
||||
*/
|
||||
|
||||
for (ibuf = str; *ibuf && isspace(*ibuf); ++ibuf)
|
||||
;
|
||||
if (str != ibuf)
|
||||
memmove(str, ibuf, ibuf - str);
|
||||
for (ibuf = str; *ibuf && isspace(*ibuf); ++ibuf);
|
||||
if (str != ibuf)
|
||||
memmove(str, ibuf, ibuf - str);
|
||||
|
||||
/*
|
||||
** Collapse embedded spaces (from LV1WS.C)
|
||||
*/
|
||||
/*
|
||||
** Collapse embedded spaces (from LV1WS.C)
|
||||
*/
|
||||
|
||||
while (*ibuf)
|
||||
{
|
||||
if (isspace(*ibuf) && cnt)
|
||||
ibuf++;
|
||||
else
|
||||
{
|
||||
if (!isspace(*ibuf))
|
||||
cnt = 0;
|
||||
else
|
||||
{
|
||||
*ibuf = ' ';
|
||||
cnt = 1;
|
||||
}
|
||||
obuf[i++] = *ibuf++;
|
||||
}
|
||||
}
|
||||
obuf[i] = NUL;
|
||||
|
||||
/*
|
||||
** Remove trailing spaces (from RMTRAIL.C)
|
||||
*/
|
||||
|
||||
while (--i >= 0)
|
||||
{
|
||||
if (!isspace(obuf[i]))
|
||||
break;
|
||||
}
|
||||
obuf[++i] = NUL;
|
||||
while (*ibuf) {
|
||||
if (isspace(*ibuf) && cnt)
|
||||
ibuf++;
|
||||
else {
|
||||
if (!isspace(*ibuf))
|
||||
cnt = 0;
|
||||
else {
|
||||
*ibuf = ' ';
|
||||
cnt = 1;
|
||||
}
|
||||
obuf[i++] = *ibuf++;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
obuf[i] = NUL;
|
||||
|
||||
/*
|
||||
** Remove trailing spaces (from RMTRAIL.C)
|
||||
*/
|
||||
|
||||
while (--i >= 0) {
|
||||
if (!isspace(obuf[i]))
|
||||
break;
|
||||
}
|
||||
obuf[++i] = NUL;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
@ -71,8 +65,8 @@ char *trim(char *str)
|
||||
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
printf("trim(\"%s\") ", argv[1]);
|
||||
printf("returned \"%s\"\n", trim(argv[1]));
|
||||
printf("trim(\"%s\") ", argv[1]);
|
||||
printf("returned \"%s\"\n", trim(argv[1]));
|
||||
}
|
||||
|
||||
#endif /* TEST */
|
||||
#endif /* TEST */
|
||||
|
Reference in New Issue
Block a user