* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)aux.c 5.14 (Berkeley) %G%";
* Return a pointer to a dynamic copy of the argument.
register char *cp
, *cp2
, *top
;
for (cp
= str
; *cp
; cp
++)
top
= salloc(cp
-str
+ 1);
for (cp
= str
, cp2
= top
; *cp
; cp
++)
* 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 (mesg
< 1 || mesg
> msgCount
)
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
) < 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
)) <= 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
)) < 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 (!icequal(linebuf
, field
)) {
for (cp
++; *cp
== ' ' || *cp
== '\t'; cp
++)
* Compare two strings, ignoring case.
if ((c1
= (unsigned char)*s1
++) !=
(c2
= (unsigned char)*s2
++)) {
* 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.
if (stat(name
, &statb
) < 0)
time_p
[0] = time((long *) 0) + 1;
time_p
[1] = statb
.st_mtime
;
* 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
!= '!')
* 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 (*cp
!= ',' && *cp
!= 0)
* 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
) < 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
) < 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
))