Category : C Source Code
Archive   : ECSTR.ZIP
Filename : STRTRIM.C

 
Output of file : STRTRIM.C contained in archive : ECSTR.ZIP
/* File : strtrim.c
Author : Richard A. O'Keefe.
Updated: 20 April 1984
Defines: strtrim()

strtrim(dst, src, set, ends)
copies src to dst, but will skip leading characters in set if "ends"
is <= 0, and will skip trailing characters in set if ends is >= 0.
Thus there are three cases:
ends < 0 : trim a prefix
ends = 0 : trim a prefix and a suffix both
ends > 0 : trim a suffix
To compress internal runs, see strpack. The normal use of this is
strtrim(buffer, buffer, " \t", 0); The result is the address of the
NUL which now terminates dst.
*/

#include "strings.h"
#include "_str2set.h"

char *strtrim(dst, src, set, ends)
register char *dst, *src;
char *set;
int ends;
{
_str2set(set);
if (ends <= 0) {
while (_set_vec[*src] == _set_ctr) src++;
}
if (ends >= 0) {
register int chr;
register char *save = dst;
while (chr = *src++) {
*dst++ = chr;
if (_set_vec[chr] != _set_ctr) save = dst;
}
dst = save, *dst = NUL;
} else {
while (*dst++ = *src++) ;
--dst;
}
return dst;
}



  3 Responses to “Category : C Source Code
Archive   : ECSTR.ZIP
Filename : STRTRIM.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/