/*
* 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.
*/
/*
* 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;
/*
* 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;