version 1.19, 2001/11/20 20:50:00 |
version 1.20, 2001/11/21 15:26:39 |
|
|
|
|
#ifndef lint |
#ifndef lint |
#if 0 |
#if 0 |
static char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93"; |
static const char sccsid[] = "@(#)aux.c 8.1 (Berkeley) 6/6/93"; |
#else |
#else |
static char rcsid[] = "$OpenBSD$"; |
static const char rcsid[] = "$OpenBSD$"; |
#endif |
#endif |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
* |
* |
* Auxiliary functions. |
* Auxiliary functions. |
*/ |
*/ |
static char *save2str __P((char *, char *)); |
static char *save2str(char *, char *); |
|
|
/* |
/* |
* Return a pointer to a dynamic copy of the argument. |
* Return a pointer to a dynamic copy of the argument. |
*/ |
*/ |
char * |
char * |
savestr(str) |
savestr(char *str) |
char *str; |
|
{ |
{ |
char *new; |
char *new; |
int size = strlen(str) + 1; |
int size = strlen(str) + 1; |
|
|
* Make a copy of new argument incorporating old one. |
* Make a copy of new argument incorporating old one. |
*/ |
*/ |
static char * |
static char * |
save2str(str, old) |
save2str(char *str, char *old) |
char *str, *old; |
|
{ |
{ |
char *new; |
char *new; |
int newsize = strlen(str) + 1; |
int newsize = strlen(str) + 1; |
|
|
* back to the system mailbox on exit. |
* back to the system mailbox on exit. |
*/ |
*/ |
void |
void |
touch(mp) |
touch(struct message *mp) |
struct message *mp; |
|
{ |
{ |
|
|
mp->m_flag |= MTOUCH; |
mp->m_flag |= MTOUCH; |
|
|
* Return true if it is. |
* Return true if it is. |
*/ |
*/ |
int |
int |
isdir(name) |
isdir(char *name) |
char name[]; |
|
{ |
{ |
struct stat sbuf; |
struct stat sbuf; |
|
|
|
|
* Count the number of arguments in the given string raw list. |
* Count the number of arguments in the given string raw list. |
*/ |
*/ |
int |
int |
argcount(argv) |
argcount(char **argv) |
char **argv; |
|
{ |
{ |
char **ap; |
char **ap; |
|
|
|
|
* pointer (or NULL if the desired header field is not available). |
* pointer (or NULL if the desired header field is not available). |
*/ |
*/ |
char * |
char * |
hfield(field, mp) |
hfield(char *field, struct message *mp) |
char field[]; |
|
struct message *mp; |
|
{ |
{ |
FILE *ibuf; |
FILE *ibuf; |
char linebuf[LINESIZE]; |
char linebuf[LINESIZE]; |
|
|
* Must deal with \ continuations & other such fraud. |
* Must deal with \ continuations & other such fraud. |
*/ |
*/ |
int |
int |
gethfield(f, linebuf, rem, colon) |
gethfield(FILE *f, char *linebuf, int rem, char **colon) |
FILE *f; |
|
char linebuf[]; |
|
int rem; |
|
char **colon; |
|
{ |
{ |
char line2[LINESIZE]; |
char line2[LINESIZE]; |
char *cp, *cp2; |
char *cp, *cp2; |
|
|
*/ |
*/ |
|
|
char* |
char* |
ishfield(linebuf, colon, field) |
ishfield(char *linebuf, char *colon, char *field) |
char linebuf[], field[]; |
|
char *colon; |
|
{ |
{ |
char *cp = colon; |
char *cp = colon; |
|
|
|
|
|
|
/* |
/* |
* Copy a string, lowercasing it as we go. ``dsize'' should be |
* Copy a string, lowercasing it as we go. ``dsize'' should be |
* the real size (not len) of the dest string (guarantee NULL term). |
* the real size (not len) of the dest string (guarantee NUL term). |
*/ |
*/ |
void |
size_t |
istrncpy(dest, src, dsize) |
istrlcpy(char *dst, const char *src, size_t dsize) |
char *dest, *src; |
|
size_t dsize; |
|
{ |
{ |
|
char *d = dst; |
|
const char *s = src; |
|
size_t n = dsize; |
|
|
if (dsize != 0) { |
/* Copy as many bytes as will fit */ |
while (--dsize != 0 && *src != '\0') { |
if (n != 0 && --n != 0) { |
if (isupper(*src)) |
do { |
*dest++ = tolower(*src++); |
if (isupper(*s)) |
else |
*d++ = tolower(*s++); |
*dest++ = *src++; |
else if ((*d++ = *s++) == 0) |
} |
break; |
*dest = '\0'; |
} while (--n != 0); |
} |
} |
|
|
|
/* Not enough room in dst, add NUL and traverse rest of src */ |
|
if (n == 0) { |
|
if (dsize != 0) |
|
*d = '\0'; /* NUL-terminate dst */ |
|
while (*s++) |
|
; |
|
} |
|
|
|
return(s - src - 1); /* count does not include NUL */ |
} |
} |
|
|
/* |
/* |
|
|
* commands. All but the current file pointer are saved on |
* commands. All but the current file pointer are saved on |
* the stack. |
* the stack. |
*/ |
*/ |
|
|
static int ssp; /* Top of file stack */ |
static int ssp; /* Top of file stack */ |
struct sstack { |
struct sstack { |
FILE *s_file; /* File we were in. */ |
FILE *s_file; /* File we were in. */ |
|
|
* that they are no longer reading from a tty (in all probability). |
* that they are no longer reading from a tty (in all probability). |
*/ |
*/ |
int |
int |
source(v) |
source(void *v) |
void *v; |
|
{ |
{ |
char **arglist = v; |
char **arglist = v; |
FILE *fi; |
FILE *fi; |
|
|
* Update the "sourcing" flag as appropriate. |
* Update the "sourcing" flag as appropriate. |
*/ |
*/ |
int |
int |
unstack() |
unstack(void) |
{ |
{ |
|
|
if (ssp <= 0) { |
if (ssp <= 0) { |
puts("\"Source\" stack over-pop."); |
puts("\"Source\" stack over-pop."); |
sourcing = 0; |
sourcing = 0; |
|
|
* This is nifty for the shell. |
* This is nifty for the shell. |
*/ |
*/ |
void |
void |
alter(name) |
alter(char *name) |
char *name; |
|
{ |
{ |
struct stat sb; |
struct stat sb; |
struct timeval tv[2]; |
struct timeval tv[2]; |
|
|
* return true if it is all blanks and tabs. |
* return true if it is all blanks and tabs. |
*/ |
*/ |
int |
int |
blankline(linebuf) |
blankline(char *linebuf) |
char linebuf[]; |
|
{ |
{ |
char *cp; |
char *cp; |
|
|
|
|
* before returning it. |
* before returning it. |
*/ |
*/ |
char * |
char * |
nameof(mp, reptype) |
nameof(struct message *mp, int reptype) |
struct message *mp; |
|
int reptype; |
|
{ |
{ |
char *cp, *cp2; |
char *cp, *cp2; |
|
|
|
|
* Ignore it. |
* Ignore it. |
*/ |
*/ |
char * |
char * |
skip_comment(cp) |
skip_comment(char *cp) |
char *cp; |
|
{ |
{ |
int nesting = 1; |
int nesting = 1; |
|
|
|
|
* of "host-phrase." |
* of "host-phrase." |
*/ |
*/ |
char * |
char * |
skin(name) |
skin(char *name) |
char *name; |
|
{ |
{ |
char *nbuf, *bufend, *cp, *cp2; |
char *nbuf, *bufend, *cp, *cp2; |
int c, gotlt, lastsp; |
int c, gotlt, lastsp; |
|
|
* 2 -- get sender's name for Reply |
* 2 -- get sender's name for Reply |
*/ |
*/ |
char * |
char * |
name1(mp, reptype) |
name1(struct message *mp, int reptype) |
struct message *mp; |
|
int reptype; |
|
{ |
{ |
char namebuf[LINESIZE]; |
char namebuf[LINESIZE]; |
char linebuf[LINESIZE]; |
char linebuf[LINESIZE]; |
|
|
first = 0; |
first = 0; |
} else |
} else |
cp2 = strrchr(namebuf, '!') + 1; |
cp2 = strrchr(namebuf, '!') + 1; |
strncpy(cp2, cp, sizeof(namebuf) - (cp2 - namebuf) - 2); |
strlcpy(cp2, cp, sizeof(namebuf) - (cp2 - namebuf) - 1); |
namebuf[sizeof(namebuf) - 2] = '\0'; |
strlcat(namebuf, "!", sizeof(namebuf)); |
strcat(namebuf, "!"); |
|
goto newname; |
goto newname; |
} |
} |
cp++; |
cp++; |
|
|
* Count the occurances of c in str |
* Count the occurances of c in str |
*/ |
*/ |
int |
int |
charcount(str, c) |
charcount(char *str, int c) |
char *str; |
|
int c; |
|
{ |
{ |
char *cp; |
char *cp; |
int i; |
int i; |
|
|
} |
} |
|
|
/* |
/* |
* Are any of the characters in the two strings the same? |
|
*/ |
|
int |
|
anyof(s1, s2) |
|
char *s1, *s2; |
|
{ |
|
|
|
while (*s1) |
|
if (strchr(s2, *s1++)) |
|
return(1); |
|
return(0); |
|
} |
|
|
|
/* |
|
* Convert c to upper case |
* Convert c to upper case |
*/ |
*/ |
int |
int |
raise(c) |
raise(int c) |
int c; |
|
{ |
{ |
|
|
if (islower(c)) |
if (islower(c)) |
|
|
* Copy s1 to s2, return pointer to null in s2. |
* Copy s1 to s2, return pointer to null in s2. |
*/ |
*/ |
char * |
char * |
copy(s1, s2) |
copy(char *s1, char *s2) |
char *s1, *s2; |
|
{ |
{ |
|
|
while ((*s2++ = *s1++) != '\0') |
while ((*s2++ = *s1++) != '\0') |
|
|
* See if the given header field is supposed to be ignored. |
* See if the given header field is supposed to be ignored. |
*/ |
*/ |
int |
int |
isign(field, ignore) |
isign(char *field, struct ignoretab ignore[2]) |
char *field; |
|
struct ignoretab ignore[2]; |
|
{ |
{ |
char realfld[LINESIZE]; |
char realfld[LINESIZE]; |
|
|
|
|
* Lower-case the string, so that "Status" and "status" |
* Lower-case the string, so that "Status" and "status" |
* will hash to the same place. |
* will hash to the same place. |
*/ |
*/ |
istrncpy(realfld, field, sizeof(realfld)); |
istrlcpy(realfld, field, sizeof(realfld)); |
if (ignore[1].i_count > 0) |
if (ignore[1].i_count > 0) |
return(!member(realfld, ignore + 1)); |
return(!member(realfld, ignore + 1)); |
else |
else |
|
|
} |
} |
|
|
int |
int |
member(realfield, table) |
member(char *realfield, struct ignoretab *table) |
char *realfield; |
|
struct ignoretab *table; |
|
{ |
{ |
struct ignore *igp; |
struct ignore *igp; |
|
|
|
|
} |
} |
|
|
void |
void |
clearnew() |
clearnew(void) |
{ |
{ |
struct message *mp; |
struct message *mp; |
|
|