bin/csh/csh.c
/*
 * Check for mail.
 * If we are a login shell, then we don't want to tell
 * about any mail file unless its been modified
 * after the time we started.
 * This prevents us from telling the user things he already
 * knows, since the login program insists on saying
 * "You have mail."
 */
Check for mail.
If we are a login shell, then we don't want to tell
about any mail file unless its been modified
after the time we started.
This prevents us from telling the user things he already
knows, since the login program insists on saying
"You have mail."
Check for mail . If we are a login shell then we don ' t want to tell about any mail file unless its been modified after the time we started . This prevents us from telling the user things he already knows since the login program insists on saying " You have mail . "
static void
mailchk()
{
    register struct varent *v;
    register Char **vp;
    time_t  t;
    int     intvl, cnt;
    struct stat stb;
    bool    new;
    v = adrof(STRmail);
    if (v == 0)
	return;
    (void) time(&t);
    vp = v->vec;
    cnt = blklen(vp);
    intvl = (cnt && number(*vp)) ? (--cnt, getn(*vp++)) : MAILINTVL;
    if (intvl < 1)
	intvl = 1;
    if (chktim + intvl > t)
	return;
    for (; *vp; vp++) {
	if (stat(short2str(*vp), &stb) < 0)
	    continue;
	new = stb.st_mtime > time0.tv_sec;
	if (stb.st_size == 0 || stb.st_atime > stb.st_mtime ||
	    (stb.st_atime < chktim && stb.st_mtime < chktim) ||
	    (loginsh && !new))
	    continue;
	if (cnt == 1)
	    (void) fprintf(cshout, "You have %smail.\n", new ? "new " : "");
	else
	    (void) fprintf(cshout, "%s in %s.\n", new ? "New mail" : "Mail",
			   vis_str(*vp));
    }
    chktim = t;
}
static void mailchk ( ) { register struct varent * v ; register Char * * vp ; time_t t ; int intvl , cnt ; struct stat stb ; bool new ; v = adrof ( STRmail ) ; if ( v == 0 ) return ; ( void ) time ( & t ) ; vp = v -> vec ; cnt = blklen ( vp ) ; intvl = ( cnt && number ( * vp ) ) ? ( -- cnt , getn ( * vp ++ ) ) : MAILINTVL ; if ( intvl < 1 ) intvl = 1 ; if ( chktim + intvl > t ) return ; for ( ; * vp ; vp ++ ) { if ( stat ( short2str ( * vp ) , & stb ) < 0 ) continue ; new = stb . st_mtime > time0 . tv_sec ; if ( stb . st_size == 0 || stb . st_atime > stb . st_mtime || ( stb . st_atime < chktim && stb . st_mtime < chktim ) || ( loginsh && ! new ) ) continue ; if ( cnt == 1 ) ( void ) fprintf ( cshout , " \n " , new ? " " : " " ) ; else ( void ) fprintf ( cshout , " \n " , new ? " " : " " , vis_str ( * vp ) ) ; } chktim = t ; }
Check for mail.
Check for mail .