* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)aux.c 5.20 (Berkeley) 6/25/90";
* Return a pointer to a dynamic copy of the argument.
int size
= strlen(str
) + 1;
if ((new = salloc(size
)) != NOSTR
)
* Announce a fatal error and die.
fprintf(stderr
, "panic: ");
fprintf(stderr
, fmt
, a
, b
);
* Touch the named message by setting its MTOUCH flag.
* Touched messages have the effect of not being sent
* back to the system mailbox on exit.
register struct message
*mp
;
if ((mp
->m_flag
& MREAD
) == 0)
mp
->m_flag
|= MREAD
|MSTATUS
;
* Test to see if the passed file name is a directory.
if (stat(name
, &sbuf
) < 0)
return((sbuf
.st_mode
& S_IFMT
) == S_IFDIR
);
* Count the number of arguments in the given string raw list.
for (ap
= argv
; *ap
++ != NOSTR
;)
* Return the desired header line from the passed message
* pointer (or NOSTR if the desired header field is not available).
if ((lc
= mp
->m_lines
- 1) < 0)
if (readline(ibuf
, linebuf
, LINESIZE
) < 0)
if ((lc
= gethfield(ibuf
, linebuf
, lc
, &colon
)) < 0)
if (hfield
= ishfield(linebuf
, colon
, field
))
* Return the next header field found in the given message.
* Return >= 0 if something found, < 0 elsewise.
* "colon" is set to point to the colon in the header.
* Must deal with \ continuations & other such fraud.
gethfield(f
, linebuf
, rem
, colon
)
if ((c
= readline(f
, linebuf
, LINESIZE
)) <= 0)
for (cp
= linebuf
; isprint(*cp
) && *cp
!= ' ' && *cp
!= ':';
if (*cp
!= ':' || cp
== linebuf
)
* I guess we got a headline.
while (--cp
>= linebuf
&& (*cp
== ' ' || *cp
== '\t'))
if (c
!= ' ' && c
!= '\t')
if ((c
= readline(f
, line2
, LINESIZE
)) < 0)
for (cp2
= line2
; *cp2
== ' ' || *cp2
== '\t'; cp2
++)
if (cp
+ c
>= linebuf
+ LINESIZE
- 2)
* Check whether the passed line is a header line of
* the desired breed. Return the field body, or 0.
ishfield(linebuf
, colon
, field
)
register char *cp
= colon
;
if (strcasecmp(linebuf
, field
) != 0) {
for (cp
++; *cp
== ' ' || *cp
== '\t'; cp
++)
* Copy a string, lowercasing it as we go.
register char *dest
, *src
;
* The following code deals with input stacking to do source
* commands. All but the current file pointer are saved on
static int ssp
; /* Top of file stack */
FILE *s_file
; /* File we were in. */
int s_cond
; /* Saved state of conditionals */
int s_loading
; /* Loading .mailrc, etc. */
* Pushdown current input file and switch to a new one.
* Set the global flag "sourcing" so that others will realize
* that they are no longer reading from a tty (in all probability).
if ((cp
= expand(*arglist
)) == NOSTR
)
if ((fi
= Fopen(cp
, "r")) == NULL
) {
printf("Too much \"sourcing\" going on.\n");
sstack
[ssp
].s_file
= input
;
sstack
[ssp
].s_cond
= cond
;
sstack
[ssp
].s_loading
= loading
;
* Pop the current input back to the previous level.
* Update the "sourcing" flag as appropriate.
printf("\"Source\" stack over-pop.\n");
printf("Unmatched \"if\"\n");
cond
= sstack
[ssp
].s_cond
;
loading
= sstack
[ssp
].s_loading
;
input
= sstack
[ssp
].s_file
;
* Touch the indicated file.
* This is nifty for the shell.
tv
[0].tv_sec
= time((time_t *)0) + 1;
tv
[1].tv_sec
= sb
.st_mtime
;
tv
[0].tv_usec
= tv
[1].tv_usec
= 0;
* Examine the passed line buffer and
* return true if it is all blanks and tabs.
for (cp
= linebuf
; *cp
; cp
++)
if (*cp
!= ' ' && *cp
!= '\t')
* Get sender's name from this message. If the message has
* a bunch of arpanet stuff in it, we may have to skin the name
register struct message
*mp
;
cp
= skin(name1(mp
, reptype
));
if (reptype
!= 0 || charcount(cp
, '!') < 2)
while (cp2
> cp
&& *cp2
!= '!')
for (; nesting
> 0 && *cp
; cp
++) {
* Skin an arpa net address according to the RFC 822 interpretation
if (index(name
, '(') == NOSTR
&& index(name
, '<') == NOSTR
&& index(name
, ' ') == NOSTR
)
for (cp
= name
, cp2
= bufend
; c
= *cp
++; ) {
* Start of a "quoted-string".
* Copy it in its entirety.
if (cp
[0] == 'a' && cp
[1] == 't' && cp
[2] == ' ')
if (cp
[0] == '@' && cp
[1] == ' ')
while ((c
= *cp
) && c
!= ',') {
if (c
== ',' && !gotlt
) {
* Fetch the sender's name from the passed message.
* 0 -- get sender's name for display purposes
* 1 -- get sender's name for reply
* 2 -- get sender's name for Reply
register struct message
*mp
;
if ((cp
= hfield("from", mp
)) != NOSTR
)
if (reptype
== 0 && (cp
= hfield("sender", mp
)) != NOSTR
)
if (readline(ibuf
, linebuf
, LINESIZE
) < 0)
return(savestr(namebuf
));
for (cp
= linebuf
; *cp
&& *cp
!= ' '; cp
++)
for (; *cp
== ' ' || *cp
== '\t'; cp
++)
for (cp2
= &namebuf
[strlen(namebuf
)];
*cp
&& *cp
!= ' ' && *cp
!= '\t' && cp2
< namebuf
+ LINESIZE
- 1;)
if (readline(ibuf
, linebuf
, LINESIZE
) < 0)
return(savestr(namebuf
));
if ((cp
= index(linebuf
, 'F')) == NULL
)
return(savestr(namebuf
));
if (strncmp(cp
, "From", 4) != 0)
return(savestr(namebuf
));
while ((cp
= index(cp
, 'r')) != NULL
) {
if (strncmp(cp
, "remote", 6) == 0) {
if ((cp
= index(cp
, 'f')) == NULL
)
if (strncmp(cp
, "from", 4) != 0)
if ((cp
= index(cp
, ' ')) == NULL
)
strcpy(rindex(namebuf
, '!')+1, cp
);
return(savestr(namebuf
));
* Count the occurances of c in str
for (i
= 0, cp
= str
; *cp
; cp
++)
* Are any of the characters in the two strings the same?
* Convert c to upper case
* Copy s1 to s2, return pointer to null in s2.
* See if the given header field is supposed to be ignored.
struct ignoretab ignore
[2];
* Lower-case the string, so that "Status" and "status"
* will hash to the same place.
if (ignore
[1].i_count
> 0)
return (!member(realfld
, ignore
+ 1));
return (member(realfld
, ignore
));
register char *realfield
;
register struct ignore
*igp
;
for (igp
= table
->i_head
[hash(realfield
)]; igp
!= 0; igp
= igp
->i_link
)
if (*igp
->i_field
== *realfield
&&
equal(igp
->i_field
, realfield
))