| [123] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: strips.c 793 2007-08-21 02:53:38Z gyoung $ | 
|---|
|  | 5 |  | 
|---|
|  | 6 | String strippers | 
|---|
|  | 7 |  | 
|---|
|  | 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
|  | 9 | Copyright (c) 2004 Steven H.Levine | 
|---|
|  | 10 |  | 
|---|
| [371] | 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage | 
|---|
|  | 12 | 26 Jul 06 SHL Add chop_at_crnl | 
|---|
| [793] | 13 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| [123] | 14 |  | 
|---|
|  | 15 | ***********************************************************************/ | 
|---|
|  | 16 |  | 
|---|
| [2] | 17 | #include <os2.h> | 
|---|
|  | 18 | #include <stdlib.h> | 
|---|
|  | 19 | #include <string.h> | 
|---|
|  | 20 | #include <ctype.h> | 
|---|
|  | 21 |  | 
|---|
| [371] | 22 | VOID chop_at_crnl(PSZ pszSrc) | 
|---|
|  | 23 | { | 
|---|
|  | 24 | // Chop line at CR or NL | 
|---|
|  | 25 | PSZ psz = strchr(pszSrc, '\r'); | 
|---|
| [551] | 26 |  | 
|---|
| [371] | 27 | if (psz) | 
|---|
|  | 28 | *psz = 0; | 
|---|
|  | 29 | psz = strchr(pszSrc, '\n'); | 
|---|
|  | 30 | if (psz) | 
|---|
|  | 31 | *psz = 0; | 
|---|
|  | 32 | } | 
|---|
| [2] | 33 |  | 
|---|
| [371] | 34 | PSZ convert_nl_to_nul(PSZ pszSrc) | 
|---|
|  | 35 | { | 
|---|
|  | 36 | // Convert newline to nul, return pointer to next or NULL | 
|---|
|  | 37 | PSZ psz = strchr(pszSrc, '\n'); | 
|---|
| [551] | 38 |  | 
|---|
| [371] | 39 | if (psz) { | 
|---|
|  | 40 | *psz = 0; | 
|---|
|  | 41 | psz++; | 
|---|
|  | 42 | } | 
|---|
|  | 43 | return psz; | 
|---|
|  | 44 | } | 
|---|
|  | 45 |  | 
|---|
| [551] | 46 | void strip_trail_char(char *pszStripChars, char *pszSrc) | 
|---|
| [371] | 47 | { | 
|---|
| [123] | 48 | char *psz; | 
|---|
| [2] | 49 |  | 
|---|
| [551] | 50 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) { | 
|---|
| [123] | 51 | psz = pszSrc + strlen(pszSrc) - 1; | 
|---|
|  | 52 | // while not empty and tail char in strip list | 
|---|
| [551] | 53 | while (*pszSrc && strchr(pszStripChars, *psz) != NULL) { | 
|---|
| [123] | 54 | *psz = 0; | 
|---|
|  | 55 | psz--; | 
|---|
| [2] | 56 | } | 
|---|
|  | 57 | } | 
|---|
|  | 58 | } | 
|---|
|  | 59 |  | 
|---|
| [551] | 60 | void strip_lead_char(char *pszStripChars, char *pszSrc) | 
|---|
| [371] | 61 | { | 
|---|
| [123] | 62 | char *psz = pszSrc; | 
|---|
| [2] | 63 |  | 
|---|
| [551] | 64 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) { | 
|---|
| [123] | 65 | // while lead char in strip list | 
|---|
| [551] | 66 | while (*psz && strchr(pszStripChars, *psz) != NULL) | 
|---|
| [123] | 67 | psz++; | 
|---|
| [551] | 68 | if (psz != pszSrc) | 
|---|
|  | 69 | memmove(pszSrc, psz, strlen(psz) + 1); | 
|---|
| [2] | 70 | } | 
|---|
|  | 71 | } | 
|---|
| [793] | 72 |  | 
|---|
|  | 73 | #pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char) | 
|---|