+static char *sccsid = "@(#)write.c 4.2 (Berkeley) 11/10/80";
/*
* write to another user
*/
#include <sys/stat.h>
#include <signal.h>
#include <utmp.h>
+#include <time.h>
+
+#define NMAX sizeof(ubuf.ut_name)
+#define LMAX sizeof(ubuf.ut_line)
char *strcat();
char *strcpy();
int eof();
int timout();
FILE *tf;
+char *getenv();
main(argc, argv)
char *argv[];
register i;
register FILE *uf;
int c1, c2;
+ long clock = time( 0 );
+ struct tm *localtime();
+ struct tm *localclock = localtime( &clock );
if(argc < 2) {
printf("usage: write user [ttyname]\n");
strcat(histty, histtya);
}
while (fread((char *)&ubuf, sizeof(ubuf), 1, uf) == 1) {
+ if (ubuf.ut_name[0] == '\0')
+ continue;
if (strcmp(ubuf.ut_line, mytty)==0) {
- for(i=0; i<8; i++) {
+ for(i=0; i<NMAX; i++) {
c1 = ubuf.ut_name[i];
if(c1 == ' ')
c1 = 0;
}
}
if(him[0] != '-' || him[1] != 0)
- for(i=0; i<8; i++) {
+ for(i=0; i<NMAX; i++) {
c1 = him[i];
c2 = ubuf.ut_name[i];
if(c1 == 0)
if ((stbuf.st_mode&02) == 0)
goto perm;
sigs(eof);
- fprintf(tf, "Message from ");
+ fprintf(tf, "\r\nMessage from ");
#ifdef interdata
fprintf(tf, "(Interdata) " );
#endif
- fprintf(tf, "%s %s...\n\a\a\a", me, mytty);
+ fprintf(tf, "%s on %s at %d:%02d ...\r\n\a\a\a"
+ , me, mytty , localclock -> tm_hour , localclock -> tm_min );
fflush(tf);
for(;;) {
char buf[128];
continue;
}
write(fileno(tf), buf, i);
+ if ( buf[ i - 1 ] == '\n' )
+ write( fileno( tf ) , "\r" , 1 );
}
perm:
timout()
{
- printf("Timeout opening his tty\n");
+ printf("Timeout opening their tty\n");
exit(1);
}
eof()
{
- fprintf(tf, "EOF\n");
+ fprintf(tf, "EOF\r\n");
exit(0);
}
}
if(i == 0) {
sigs((int (*)())0);
- execl("/bin/sh", "sh", "-c", bp+1, 0);
+ execl(getenv("SHELL") ? getenv("SHELL") : "/bin/sh", "sh", "-c", bp+1, 0);
exit(0);
}
while(wait((int *)NULL) != i)