head 1.11; access; symbols; locks; strict; comment @ * @; 1.11 date 94.03.12.00.06.47; author paul; state Exp; branches; next 1.10; 1.10 date 94.03.10.20.55.49; author paul; state Exp; branches; next 1.9; 1.9 date 94.01.07.17.37.43; author paul; state Exp; branches; next 1.8; 1.8 date 92.07.29.04.11.26; author paul; state Exp; branches; next 1.7; 1.7 date 92.07.23.14.13.44; author paul; state Exp; branches; next 1.6; 1.6 date 90.12.18.08.41.02; author dorner; state Exp; branches; next 1.5; 1.5 date 90.05.16.09.18.11; author dorner; state Exp; branches; next 1.4; 1.4 date 89.03.20.15.14.23; author dorner; state Exp; branches; next 1.3; 1.3 date 88.12.02.14.44.46; author dorner; state Exp; branches; next 1.2; 1.2 date 88.11.15.13.34.51; author dorner; state Exp; branches; next 1.1; 1.1 date 87.12.08.10.45.00; author dorner; state Exp; branches; next ; desc @@ 1.11 log @New copyright statement. @ text @/* * Copyright (c) 1985 Corporation for Research and Educational Networking * Copyright (c) 1988 University of Illinois Board of Trustees, Steven * Dorner, and Paul Pomes * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Corporation for * Research and Educational Networking (CREN), the University of * Illinois at Urbana, and their contributors. * 4. Neither the name of CREN, the University nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE TRUSTEES AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint static char RcsId[] = "@@(#)$Id$"; #endif #include "protos.h" /*LINTLIBRARY*/ #define to_lower(a) (((a)>='A'&&(a)<='Z')?((a)|040):(a)) /* * Just like strcmp but case independent. */ int stricmp(s1, s2) char *s1, *s2; { register char c1, c2; for (c1 = *s1, c2 = *s2; to_lower(c1) == to_lower(c2); c1 = *s1, c2 = *s2) { s2++; if (*s1++ == '\0') return (0); } return (to_lower(c1) - to_lower(c2)); } /* * Just like strncmp, but case independent. */ int strincmp(s1, s2, n) char *s1, *s2; int n; { while (--n >= 0 && to_lower(*s1) == to_lower(*s2)) { s2++; if (*s1++ == '\0') return (0); } return (n < 0 ? 0 : to_lower(*s1) - to_lower(*s2)); } /* * Return true iff the given string is a blank line. */ int blankline(str) char *str; { while (isspace(*str)) str++; return ((*str == '\0') ? 1 : 0); } /* * Get rid of trailing spaces (and newlines and tabs ) as well as * beginning ones. This routine just truncates the line in place. */ char * ltrunc(str) char *str; { register char *ptr; ptr = str; while (*ptr) ptr++; while (isspace(*--ptr)) if (ptr < str) break; ptr[1] = '\0'; while (isspace(*str)) str++; return (str); } /* * Return true iff character (c) occurs in the string (list). */ int any(c, list) char c, *list; { while (*list) { if (c == *list) return 1; list++; } return 0; } void mkargv(argc, argv, line) int *argc; char **argv, *line; { int count, instring; char *ptr; count = 0; instring = 0; for (ptr = line; *ptr; ptr++) { if (isspace(*ptr)) { instring = 0; *ptr = '\0'; } else if (!instring) { argv[count++] = ptr; instring = 1; } } argv[count] = 0; *argc = count; } /* * Just like strcat, except return a ptr to the null byte at the end of * cat'ed string. */ char * strecat(s1, s2) char *s1, *s2; { while (*s1) s1++; while (*s1++ = *s2++) ; return (--s1); } /* * Just like strcpy, except return a ptr to the null byte at the end of * cpy'ed string. */ char * strecpy(s1, s2) char *s1, *s2; { while (*s1++ = *s2++) ; return (--s1); } /* * is one string a subset of another? */ int issub(string, sub) char *string, *sub; { int len; len = strlen(sub); for (; *string; string++) if (!strncmp(string, sub, len)) return (1); return (0); } /* * copy a string, return the # of chars copied */ int strcpc(to, from) char *to, *from; { char *old; old = to; while (*to++ = *from++) ; return (to - old - 1); } /* * count the occurrences of a character in a string */ int countc(string, c) char *string, c; { register int count; count = 0; while (*string) if (*string++ == c) count++; return (count); } /* * concatenate strings, handling escaped newlines and tabs */ int strcate(to, from) char *to, *from; { int escaped; char *orig; while (*to) to++; orig = to; for (escaped = 0; *from; from++) { if (escaped) { switch (*from) { case 'n': *to++ = '\n'; break; case 't': *to++ = '\t'; break; default: *to++ = *from; break; } escaped = 0; } else if (!(escaped = (*from == '\\'))) *to++ = *from; } *to = '\0'; return (to - orig); } /* * Make a string of control chars legible */ char * Visible(s, n) char *s; int n; { static char scratch[4096]; char *Spot; unsigned char c; static char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; int wasHex = 0; for (Spot = scratch; n--; s++) { c = *((unsigned char *) s); if (c > 127) { if (!wasHex) *Spot++ = '<'; *Spot++ = hexDigit[(c >> 4) & 0xf]; *Spot++ = hexDigit[c & 0xf]; wasHex = 1; } else { if (wasHex) *Spot++ = '>'; wasHex = 0; if (c == '^') { *Spot++ = '\\'; *Spot++ = c; } else if (' ' <= c && c <= '~') *Spot++ = c; else if (c == 127) { *Spot++ = '^'; *Spot++ = '?'; } else { *Spot++ = '^'; *Spot++ = c + '@@'; } } } if (wasHex) *Spot++ = '>'; *Spot = 0; return (scratch); } /* * is a string all metacharacters? */ int AllMeta(s) char *s; { for (; *s; s++) if (!any(*s, "[]?*")) return (0); return (1); } /* * copy a string, converting to lower case */ char * strlcpy(to, from) char *to, *from; { char *save = to; while (*to++ = isupper(*from) ? tolower(*from) : *from) from++; return (save); } /* * Remove special characters from a string */ int RemoveSpecials(str) char *str; { for (; *str; str++) if (strchr("()$&<>|;/`", *str)) *str = ' '; } @ 1.10 log @Deleted isblank. @ text @a0 2 #include "protos.h" d2 33 a34 5 * This software is Copyright (C) 1988 by Steven Dorner and the * University of Illinois Board of Trustees, and by CSNET. No warranties of * any kind are expressed or implied. No support will be provided. * This software may not be redistributed without prior consent of CSNET. * You may direct questions to nameserv@@uiuc.edu d36 6 @ 1.9 log @*** empty log message *** @ text @a126 13 /* * true iff the argument is a null or whitespace filled string */ int isblank(str) char *str; { while (*str && isspace(*str)) str++; return (*str == '\0'); } @ 1.8 log @*** empty log message *** @ text @d346 1 a346 1 if (index("()$&<>|;/`", *str)) @ 1.7 log @Re-formatted for clarity. @ text @a11 1 #include @ 1.6 log @No help here. @ text @a1 8 /***********************************************************************/ /********************************************************************* * This software is Copyright (C) 1988 by Steven Dorner and the * University of Illinois Board of Trustees, and by CSNET. No warranties of * any kind are expressed or implied. No support will be provided. * This software may not be redistributed without prior consent of CSNET. * You may direct questions to dorner@@garcon.cso.uiuc.edu. **********************************************************************/ d3 8 d17 19 a35 1 * * Just like strcmp but case independent. d37 4 a40 1 int stricmp(char *s1,char *s2) d42 21 a62 1 register char c1, c2; d64 20 a83 7 for (c1 = *s1, c2 = *s2; to_lower(c1) == to_lower(c2); c1 = *s1, c2 = *s2) { s2++; if (*s1++ == '\0') return (0); } return (to_lower(c1) - to_lower(c2)); d87 1 a87 1 * * Just like strncmp, but case independent. d89 39 a127 2 int strincmp(char *s1, char *s2,int n) { d129 10 a138 7 while (--n >= 0 && to_lower(*s1) == to_lower(*s2)) { s2++; if (*s1++ == '\0') return (0); } return (n < 0 ? 0 : to_lower(*s1) - to_lower(*s2)); d142 2 a143 1 * * Return true iff the given string is a blank line. d145 9 a153 5 int blankline(char *str) { while (isspace(*str)) str++; return ((*str == '\0') ? 1 : 0); d157 2 a158 2 * * Get rid of trailing spaces (and newlines and tabs ) * as well as * beginning ones. This routine just truncates the line in * place. d160 8 a167 3 char *ltrunc(char *str) { register char *ptr; d169 14 a182 10 ptr = str; while (*ptr) ptr++; while (isspace(*--ptr)) if (ptr < str) break; ptr[1] = '\0'; while (isspace(*str)) str++; return (str); d186 1 a186 1 * * Return true iff character (c) occurs in the string (list). d188 3 a190 1 int any(char c,char *list) d192 6 a197 7 while (*list) { if (c == *list) return 1; list++; } return 0; d200 6 a205 1 void mkargv(int *argc,char *argv[],char *line) d207 3 a209 2 int count, instring; char *ptr; d211 5 a215 18 count = 0; instring = 0; for (ptr = line; *ptr; ptr++) { if (isspace(*ptr)) { instring = 0; *ptr = '\0'; } else if (!instring) { argv[count++] = ptr; instring = 1; } } argv[count] = 0; *argc = count; d218 37 d257 1 a257 1 * * true iff the argument is a null or whitespace filled string d259 49 a307 5 int isblank(char *str) { while (*str && isspace(*str)) str++; return (*str == '\0'); d311 1 a311 2 * * Just like strcat, except return a ptr to the null byte at the end of * * cat'ed string. d313 8 a320 7 char *strecat(char *s1, char *s2) { while (*s1) s1++; while (*s1++ = *s2++) ; return (--s1); d324 1 a324 2 * * Just like strcpy, except return a ptr to the null byte at the end of * * cpy'ed string. d326 3 a328 1 char *strecpy(char *s1,char *s2) d330 6 a335 3 while (*s1++ = *s2++) ; return (--s1); a337 6 /************************************************************************ * is one string a subset of another? ************************************************************************/ int issub(char *string,char *sub) { int len; d339 10 a348 161 len = strlen(sub); for (; *string; string++) if (!strncmp(string, sub, len)) return (1); return (0); } /*********************************************************************** * copy a string, return the # of chars copied ***********************************************************************/ int strcpc(register char *to,register char *from) { char *old; old = to; while (*to++ = *from++); return (to - old - 1); } /*********************************************************************** * count the occurrences of a character in a string ***********************************************************************/ int countc(char *string,char c) { register int count; count = 0; while (*string) if (*string++ == c) count++; return (count); } /*********************************************************************** * concatenate strings, handling escaped newlines and tabs ***********************************************************************/ int strcate(char *to,char *from) { int escaped; char *orig; while (*to) to++; orig = to; for (escaped = 0; *from; from++) { if (escaped) { switch (*from) { case 'n': *to++ = '\n'; break; case 't': *to++ = '\t'; break; default: *to++ = *from; break; } escaped = 0; } else if (!(escaped = (*from == '\\'))) *to++ = *from; } *to = '\0'; return (to - orig); } /*********************************************************************** * Make a string of control chars legible ***********************************************************************/ char *Visible(char *s,int n) { static char scratch[4096]; char *theSpot; unsigned char c; static char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; int wasHex = 0; for (theSpot = scratch; n--; s++) { c = *((unsigned char *) s); if (c > 127) { if (!wasHex) *theSpot++ = '<'; *theSpot++ = hexDigit[(c >> 4) & 0xf]; *theSpot++ = hexDigit[c & 0xf]; wasHex = 1; } else { if (wasHex) *theSpot++ = '>'; wasHex = 0; if (c == '^') { *theSpot++ = '\\'; *theSpot++ = c; } else if (' ' <= c && c <= '~') *theSpot++ = c; else if (c == 127) { *theSpot++ = '^'; *theSpot++ = '?'; } else { *theSpot++ = '^'; *theSpot++ = c + '@@'; } } } if (wasHex) *theSpot++ = '>'; *theSpot = 0; return (scratch); } /*********************************************************************** * is a string all metacharacters? ***********************************************************************/ int AllMeta(char *s) { for (; *s; s++) if (!any(*s, "[]?*")) return (0); return (1); } /*********************************************************************** * copy a string, converting to lower case ***********************************************************************/ char *strlcpy(char *to,char *from) { char *save = to; while (*to++ = isupper(*from) ? tolower(*from) : *from) from++; return (save); } /*********************************************************************** * Remove special characters from a string ***********************************************************************/ int RemoveSpecials(char *theString) { for (; *theString; theString++) if (index("()$&<>|;/`", *theString)) *theString = ' '; @ 1.5 log @No help here. @ text @d1 1 d19 1 a19 2 stricmp(s1, s2) register char *s1, *s2; d35 1 a35 3 strincmp(s1, s2, n) register char *s1, *s2; register n; d50 1 a50 2 blankline(str) char *str; d61 1 a61 3 char * ltrunc(str) register char *str; d80 1 a80 3 any(c, list) char c; char *list; d91 1 a91 6 mkargv(argc, argv, line) int *argc; char *argv[]; char *line; d120 1 a120 2 isblank(str) register char *str; d131 1 a131 3 char * strecat(s1, s2) register char *s1, *s2; d144 1 a144 3 char * strecpy(s1, s2) register char *s1, *s2; d154 1 a154 3 issub(string, sub) char *string; char *sub; d167 1 a167 3 strcpc(to, from) register char *to; register char *from; d180 1 a180 3 countc(string, c) register char *string; register char c; d196 1 a196 3 strcate(to, from) register char *to; register char *from; d234 1 a234 4 char * Visible(s, n) int n; char *s; d289 1 a289 2 AllMeta(s) register char *s; d300 1 a300 3 char * strlcpy(to, from) register char *to, *from; d314 1 a314 2 RemoveSpecials(theString) char *theString; a315 2 char *index(); d317 1 a317 1 if (index("()$&<>|;`", *theString)) @ 1.4 log @No help here. @ text @d168 15 d339 14 @ 1.3 log @No help here. @ text @d1 9 a10 8 /*********************************************************************** * Portions of this software Copyright (C) 1988 by Steven Dorner and the * University of Illinois Board of Trustees. Portions of this software * orginally written for CSNET; copyright status unclear at this time. No * warranties expressed or implied, no support provided. Please do not * redistribute it in its present form. Contact me for details * (dorner@@garcon.cso.uiuc.edu). ***********************************************************************/ @ 1.2 log @No help here. @ text @d1 1 d20 1 a20 1 register char c1, c2; d22 7 a28 7 for (c1 = *s1, c2 = *s2; to_lower(c1) == to_lower(c2); c1 = *s1, c2 = *s2) { s2++; if (*s1++ == '\0') return (0); } return (to_lower(c1) - to_lower(c2)); d39 7 a45 7 while (--n >= 0 && to_lower(*s1) == to_lower(*s2)) { s2++; if (*s1++ == '\0') return (0); } return (n < 0 ? 0 : to_lower(*s1) - to_lower(*s2)); d54 3 a56 3 while (isspace(*str)) str++; return ((*str == '\0') ? 1 : 0); d60 1 a60 1 * * Get rid of trailing spaces (and newlines and tabs ) * as well as d67 1 a67 1 register char *ptr; d69 10 a78 10 ptr = str; while (*ptr) ptr++; while (isspace(*--ptr)) if (ptr < str) break; ptr[1] = '\0'; while (isspace(*str)) str++; return (str); d85 1 a85 1 char c; d88 7 a94 7 while (*list) { if (c == *list) return 1; list++; } return 0; d99 1 a99 1 int *argc; d104 2 a105 2 int count, instring; char *ptr; d107 5 a111 3 count = 0; instring = 0; for (ptr = line; *ptr; ptr++) d113 2 a114 11 if (isspace(*ptr)) { instring = 0; *ptr = '\0'; } else if (!instring) { argv[count++] = ptr; instring = 1; } d116 9 a124 2 argv[count] = 0; *argc = count; d134 3 a136 3 while (*str && isspace(*str)) str++; return (*str == '\0'); d147 5 a151 5 while (*s1) s1++; while (*s1++ = *s2++) ; return (--s1); d162 3 a164 3 while (*s1++ = *s2++) ; return (--s1); d174 1 a174 1 char *old; d176 2 a177 2 old = to; while (*to++ = *from++); d179 1 a179 1 return (to - old - 1); d189 1 a189 1 register int count; d191 1 a191 1 count = 0; d193 3 a195 3 while (*string) if (*string++ == c) count++; d197 1 a197 1 return (count); d207 2 a208 2 int escaped; char *orig; d210 3 a212 3 while (*to) to++; orig = to; d214 3 a216 1 for (escaped = 0; *from; from++) d218 13 a230 19 if (escaped) { switch (*from) { case 'n': *to++ = '\n'; break; case 't': *to++ = '\t'; break; default: *to++ = *from; break; } escaped = 0; } else if (!(escaped = (*from == '\\'))) *to++ = *from; d232 6 a237 2 *to = '\0'; return (to - orig); d245 1 a245 1 int n; d248 6 a253 7 static char scratch[4096]; char *theSpot; unsigned char c; char hex; static char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; int wasHex = 0; d255 4 a258 1 for (theSpot = scratch; n--; s++) d260 5 a264 34 c = *((unsigned char *) s); if (c > 127) { if (!wasHex) *theSpot++ = '<'; *theSpot++ = hexDigit[(c >> 4) & 0xf]; *theSpot++ = hexDigit[c & 0xf]; wasHex = 1; } else { if (wasHex) *theSpot++ = '>'; wasHex = 0; if (c == '^') { *theSpot++ = '\\'; *theSpot++ = c; } else if (' ' <= c && c <= '~') *theSpot++ = c; else if (c == 127) { *theSpot++ = '^'; *theSpot++ = '?'; } else { *theSpot++ = '^'; *theSpot++ = c + '@@'; } } d266 3 a268 1 if (wasHex) d270 26 a295 2 *theSpot = 0; return (scratch); d304 4 a307 4 for (; *s; s++) if (!any(*s, "[]?*")) return (0); return (1); d317 1 a317 1 char *save = to; d319 2 a320 2 while (*to++ = isupper(*from) ? tolower(*from) : *from) from++; d322 1 a322 1 return (save); @ 1.1 log @Initial revision @ text @d1 8 d14 2 a15 2 ** Just like strcmp but case independent. */ d21 1 a21 1 for (c1= *s1,c2= *s2; to_lower(c1)==to_lower(c2);c1= *s1,c2= *s2) d31 2 a32 2 ** Just like strncmp, but case independent. */ d48 2 a49 2 ** Return true iff the given string is a blank line. */ d51 1 a51 1 char *str; d59 4 a62 5 ** Get rid of trailing spaces (and newlines and tabs ) ** as well as beginning ones. This routine just truncates the line in ** place. */ char * d81 2 a82 2 ** Return true iff character (c) occurs in the string (list). */ d84 2 a85 2 char c; char *list; d98 3 a100 3 int *argc; char *argv[]; char *line; d103 2 a104 2 int count, instring; char *ptr; d128 2 a129 2 ** true iff the argument is a null or whitespace filled string */ d139 4 a142 4 ** Just like strcat, except return a ptr to the null byte at the end of ** cat'ed string. */ char * d154 4 a157 4 ** Just like strcpy, except return a ptr to the null byte at the end of ** cpy'ed string. */ char * d173 1 a173 1 char *old; d184 1 a184 1 countc(string,c) d193 2 a194 1 if (*string++ == c) count++; d196 1 a196 1 return(count); d202 1 a202 1 strcate(to,from) d206 2 a207 2 int escaped; char *orig; d209 2 a210 1 while (*to) to++; d213 1 a213 1 for (escaped=0;*from;from++) d219 9 a227 9 case 'n': *to++ = '\n'; break; case 't': *to++ = '\t'; break; default: *to++ = *from; break; d231 2 a232 1 else if (!(escaped=(*from=='\\'))) d236 1 a236 1 return(to - orig); d238 1 d242 4 a245 3 char *Visible(s,n) int n; char *s; d248 1 a248 1 char *theSpot; d250 4 a253 4 char hex; static char hexDigit[]={'0','1','2','3','4','5','6','7', '8','9','a','b','c','d','e','f'}; int wasHex=0; d255 1 a255 1 for (theSpot=scratch;n--;s++) d257 2 a258 2 c = *((unsigned char *)s); if (c>127) d261 4 a264 4 *theSpot++='<'; *theSpot++=hexDigit[(c>>4)&0xf]; *theSpot++=hexDigit[c&0xf]; wasHex=1; d268 4 a271 3 if (wasHex) *theSpot++='>'; wasHex=0; if (c=='^') d273 2 a274 2 *theSpot++='\\'; *theSpot++=c; d276 5 a280 3 else if (' '<=c && c <= '~') *theSpot++=c; else if (c==127) d282 2 a283 2 *theSpot++='^'; *theSpot++='?'; d287 2 a288 2 *theSpot++='^'; *theSpot++=c+'@@'; d292 4 a295 3 if (wasHex) *theSpot++='>'; *theSpot=0; return(scratch); d304 2 a305 2 for (;*s;s++) if (!any(*s,"[]?*")) d307 16 a322 1 return(1); @