static char *SccsId
= "@(#)aux.c 2.4 %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
++)
* Copy the name from the passed header line into the passed
* name buffer. Null pad the name buffer.
for (cp
= linebuf
+ 5, cp2
= nbuf
; *cp
!= ' ' && cp2
-nbuf
< 8; cp
++)
* Announce a fatal error and die.
* Catch stdio errors and report them more nicely.
* Print a string on diagnostic output.
* 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
);
* Compute the size in characters of the passed message
register struct message
*mp
;
* Count the number of arguments in the given string raw list.
for (ap
= argv
; *ap
!= NOSTR
; ap
++)
* Given a file address, determine the
* block number it represents.
* Take a file address, and determine
* its offset in the current block.
* Determine if the passed file is actually a tty, via a call to
* gtty. This is not totally reliable, but . . .
* 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
) <= 0)
if (readline(ibuf
, linebuf
) < 0)
lc
= gethfield(ibuf
, linebuf
, lc
);
if (ishfield(linebuf
, field
))
return(savestr(hcontents(linebuf
)));
* Return the next header field found in the given message.
* Return > 0 if something found, <= 0 elsewise.
* Must deal with \ continuations & other such fraud.
gethfield(f
, linebuf
, rem
)
if (readline(f
, linebuf
) < 0)
if (strlen(linebuf
) == 0)
cp
= index(linebuf
, ':');
for (cp2
= linebuf
; cp2
< cp
; cp2
++)
* I guess we got a headline.
if (readline(f
, line2
) < 0)
if (!isspace(line2
[0])) {
if (!isspace(c
) || c
== '\n')
if (readline(f
, line2
) < 0)
for (cp2
= line2
; *cp2
!= 0 && isspace(*cp2
); cp2
++)
if (strlen(linebuf
) + strlen(cp2
) >= LINESIZE
-2)
cp
= &linebuf
[strlen(linebuf
)];
(isspace(cp
[-1]) || cp
[-1] == '\\'))
for (cp2
= line2
; *cp2
!= 0 && isspace(*cp2
); cp2
++)
if ((c
= strlen(linebuf
)) > 0) {
while (cp
> linebuf
&& isspace(*cp
))
* Check whether the passed line is a header line of
if ((cp
= index(linebuf
, ':')) == NOSTR
)
while (cp
> linebuf
&& isspace(*cp
))
if (icequal(linebuf
,field
)) {
* Extract the non label information from the given header field
if ((cp
= index(hfield
, ':')) == NOSTR
)
while (*cp
&& isspace(*cp
))
* Compare two strings, ignoring case.
while (raise(*s1
++) == raise(*s2
))
* The following code deals with input stacking to do source
* commands. All but the current file pointer are saved on
static int ssp
= -1; /* 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(name
)) == 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
;
* Source a file, but do nothing if the file cannot be opened.
if ((f
= open(name
, 0)) < 0)
* 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 we have the utime() system call, this is better served
* by using that, since it will work for empty files.
* On non-utime systems, we must sleep a second, then read.
if (stat(name
, &statb
) < 0)
time_p
[0] = time((long *) 0) + 1;
time_p
[1] = statb
.st_mtime
;
if ((f
= open(name
, 0)) < 0)
* Examine the passed line buffer and
* return true if it is all blanks and tabs.
for (cp
= linebuf
; *cp
; cp
++)
* 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 733 interpretation
if (index(name
, '(') == NOSTR
&& index(name
, '<') == NOSTR
)
for (cp
= name
, cp2
= nbuf
, c
= *cp
++; *cp
; c
= *cp
++) {
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
++)
for (cp2
= &namebuf
[strlen(namebuf
)]; *cp
&& !any(*cp
, " \t") &&
cp2
-namebuf
< LINESIZE
-1; *cp2
++ = *cp
++)
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
++)
* Find the rightmost pointer to an instance of the
* character in the string and return it.
for (cp
= str
, cp2
= NOSTR
; *cp
; cp
++)
* See if the string is a number.
* Are any of the characters in the two strings the same?
* Determine the leftmost index of the character
for (c
= ch
, cp
= str
; *cp
; cp
++)
* String compare two strings of bounded length.
while (--n
>= 0 && *s1
== *s2
++)
return(n
<0 ? 0 : *s1
- *--s2
);