v03i017: Welcome program for Ultrix
Jim King
pulsar at lsrhs.UUCP
Sun May 15 05:27:25 AEST 1988
comp.sources.misc: Volume 3, Issue 17
Submitted-By: "Jim King" <pulsar at lsrhs.UUCP>
Archive-Name: welcome
#!/bin/sh
# shar: Shell Archiver (v1.22)
#
# Run the following text with /bin/sh to create:
# README
# Makefile
# welcome.1
# welcome.c
# cpu.h
#
sed 's/^X//' << 'SHAR_EOF' > README &&
XDisclaimer: I originally found this program for VAX/VMS systems in
Xthe March 1988 issue of Hardcopy magazine (page 83). I do not credit
Xthe idea to me, but since the actual program was in VMS command form,
XI deided it would be nice to put it on an Ultrix compatible system.
XThis program is intended to be shareware.
X
XWelcome prints out a nice welcome message for the user.
X
XVersion 1: Initial program translated, debugged. At this time there is only
Xa set message in the middle box. Future copies should work so that it will
Xnlist the kernel and find the type of VAX and version of Ultrix.
X
XVersion 2: Added load average box and LOAD define in cpu.h
X
XVersion 3: Added CPU type and CPU define, along with Ultrix version and
Xhostname.
X
X** This program translated from VMS command language by Jim King at lsrhs
X** (And added a few extra features...)
X
XNOTES --
X
XDefine LOAD if you want the little load average box
X
XDefine CPU If you want to know the type of CPU you are using.
X
XDefine LIGHT if you want the messages in the box highlighted.
X
XDefine UVERS If you want to know the version of Ultrix.
X NOTE: This program assumes that /etc/motd is a known file
X produced by /etc/rc.
SHAR_EOF
chmod 1711 README || echo "restore of README fails"
set `wc -c README`;Sum=$1
if test "$Sum" != "1183"
then echo original size 1183, current size $Sum;fi
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#
X# Makefile for welcome
X#
XDESTDIR= /u/pulsar/Utilities/Welcome
XCFLAGS= -g
XPROGRAM= welcome
XSRCS= welcome.c
XLIBS=
X
X${PROGRAM}: ${SRCS}
X ${CC} ${CFLAGS} -o $@ $@.c ${LIBS}
X
Xinstall:
X install ${PROGRAM} ${DESTDIR}/welcome
X
Xtags:
X ctags -tdw *.c
X
Xclean:
X rm -f a.out core *.o made
X
Xdepend:
X echo 'Welcome Compiled.'
SHAR_EOF
chmod 1711 Makefile || echo "restore of Makefile fails"
set `wc -c Makefile`;Sum=$1
if test "$Sum" != "315"
then echo original size 315, current size $Sum;fi
sed 's/^X//' << 'SHAR_EOF' > welcome.1 &&
X.TH welcome 1
X.SH NAME
Xwelcome \- prints out a nice welcome message with useful statistics
X.SH SYNTAX
X.B welcome
X.SH DESCRIPTION
XThe
X.PN welcome
Xcommand makes a graphic box over box and prints out the time,
Xday,
Xand system stats
X.PP
X.PN welcome
Xassumes that the file /etc/motd exists.
X.SH SEE ALSO
X/etc/motd
X.SH AUTHOR
XJim King (pulsar) Lincoln-Sudbury Regional High '88.
SHAR_EOF
chmod 1711 welcome.1 || echo "restore of welcome.1 fails"
set `wc -c welcome.1`;Sum=$1
if test "$Sum" != "374"
then echo original size 374, current size $Sum;fi
sed 's/^X//' << 'SHAR_EOF' > welcome.c &&
X#include <time.h>
X#include <stdio.h>
X#include "cpu.h"
X#include <nlist.h>
X
Xextern struct nlist namelist[];
Xextern struct nlist nl[];
X
Xstruct nlist nl[] = { { "_cpu" }, { "" } };
Xdouble loadavg[4];
Xint kmem;
X
Xstruct nlist namelist[] = {
X { "_avenrun" },
X { 0 }
X};
X
Xchar *days[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
X "Thursday", "Friday", "Saturday" };
X
Xchar *mons[] = { "January", "February", "March", "April",
X "May", "June", "July", "August",
X "September", "October", "November", "December" };
X
Xchar *ttime[] = { "morning ", "afternoon ", "evening " };
X
Xmain()
X{
X register struct tm *det;
X int a, b, x, y, num, cpu;
X long secs;
X char bot[100], *foo, goo[50], ap;
X time(&secs);
X#ifdef LOAD
X nlist("/vmunix", namelist);
X if (namelist[0].n_type == 1)
X puts("/vmunix no namelist\n"), exit(1);
X kmem = open("/dev/kmem", 0);
X if (kmem <= 0)
X printf("cannot open /dev/kmem\n"), exit(1);
X lseek(kmem, (long)namelist[0].n_value, 0);
X read(kmem, &loadavg[0], sizeof loadavg);
X close(kmem);
X#endif LOAD
X#ifdef CPU
X nlist("/vmunix", nl);
X if (nl[0].n_type == 1)
X puts("/vmunix no namelist\n"), exit(1);
X kmem = open("/dev/kmem", 0);
X if (kmem <= 0)
X printf("cannot open /dev/kmem\n"), exit(1);
X lseek(kmem, nl[0].n_value, 0);
X read(kmem, &cpu, sizeof(cpu));
X close(kmem);
X#endif CPU
X ap = "AP"[(det = localtime(&secs))->tm_hour >= 12];
X if (det->tm_hour > 0 && det->tm_hour < 12)
X foo = ttime[0];
X else if (det->tm_hour > 11 && det->tm_hour < 18)
X foo = ttime[1];
X else if (det->tm_hour > 17 && det->tm_hour < 24)
X foo = ttime[2];
X if ((det->tm_hour %= 12) == 0)
X det->tm_hour = 12;
X fflush(stdout);
X printf("\033[2J\033(0\033)0\033[m");
X#ifdef LOAD
X printf("\033[3;11H\033(B\033)B Load Average\033(0\033)0");
X printf("\033[4;11Hlqqqqqqqqqqqqqqqqk");
X printf("\033[5;11Hx x");
X printf("\033[6;11Hmqqqqqqqqqqqqqqwqj");
X printf("\033[5;13H%4.2f %4.2f %4.2f", loadavg[0], loadavg[1], loadavg[2]);
X printf("\033[7;16Hlqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
X#else LOAD
X printf("\033[7;16Hlqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
X#endif LOAD
X printf("\033[8;16Hx x");
X printf("\033[9;13Hlqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqk");
X printf("\033[10;10Hlqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqk");
X printf("\033[11;10Hx\033[11;63Hx\033[12;10Hx\033[12;63Hx\033[13;10Hx\033[13;63Hx");
X printf("\033[14;10Hmqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqj");
X printf("\033[15;13Hmqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqj");
X printf("\033[16;16Hx x");
X printf("\033[17;16Hmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj");
X printf("\033(B\033)B");
X#ifdef LIGHT
X printf("\033[11;13H\033[7m ");
X#endif LIGHT
X printf("\033[11;13H Good %s%s,", foo, getenv("USER"));
X gethostname(goo, sizeof(goo));
X#ifdef LIGHT
X printf("\033[12;13H\033[7m ");
X printf("\033[12;13H\033[7m You have connected to %s", goo);
X#else LIGHT
X printf("\033[12;13H You have connected to %s", goo);
X#endif
X#ifdef LIGHT
X printf("\033[13;13H\033[7m ");
X#endif LIGHT
X#ifdef CPU
X printf("\033[m");
X switch(cpu) {
X case VAX_780:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A VAX 11/780 running Ultrix");
X#else LIGHT
X printf("\033[13;13H A VAX 11/780 running Ultrix");
X#endif LIGHT
X break;
X case VAX_750:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A VAX 11/750 running Ultrix");
X#else LIGHT
X printf("\033[13;13H A VAX 11/750 runing Ultrix");
X#endif LIGHT
X break;
X case VAX_730:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A VAX 11/730 running Ultrix");
X#else LIGHT
X printf("\033[13;13H A VAX 11/730 runing Ultrix");
X#endif LIGHT
X break;
X case VAX_8600:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A VAX 8600 running Ultrix");
X#else LIGHT
X printf("\033[13;13H A VAX 8600 runing Ultrix");
X#endif LIGHT
X break;
X case VAX_8200:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A VAX 8200 running Ultrix");
X#else LIGHT
X printf("\033[13;13H A VAX 8200 runing Ultrix");
X#endif LIGHT
X break;
X case VAX_8800:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A VAX 8800 running Ultrix");
X#else LIGHT
X printf("\033[13;13H A VAX 8800 runing Ultrix");
X#endif LIGHT
X break;
X case MVAX_I:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A MicroVAX I running Ultrix");
X#else LIGHT
X printf("\033[13;13H A MicroVAX I runing Ultrix");
X#endif LIGHT
X break;
X case MVAX_II:
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A MicroVAX II running Ultrix");
X#else LIGHT
X printf("\033[13;13H A MicroVAX II runing Ultrix");
X#endif LIGHT
X break;
X default:
X printf("\033[13;13H CPU ident error");
X break;
X }
X#else CPU
X#ifdef LIGHT
X printf("\033[13;13H\033[7m A system running Ultrix");
X#else LIGHT
X printf("\033[13;13H A system running Ultrix");
X#endif LIGHT
X#endif CPU
X#ifdef UVERS
X fp = fopen("/etc/motd", "r");
X fscanf(fp, "%s%s", poo, doo);
X printf(" V%c.%c", doo[1], doo[3]);
X fclose(fp);
X unlink("/tmp/foo");
X#endif UVERS
X#ifdef LIGHT
X printf("\033[8;18H ");
X printf("\033[16;18H ");
X#endif LIGHT
X x = 40 - (strlen(days[det->tm_wday]) / 2);
X y = (69 - x);
X printf("\033[8;%dH%s", y, days[det->tm_wday]);
X sprintf(bot, "%s %d, 19%d %d:%02d %cM", mons[det->tm_mon],
X det->tm_mday, det->tm_year, det->tm_hour,
X det->tm_min, ap);
X a = 40 -(strlen(bot) / 2);
X b = (54 - a);
X printf("\033[m");
X#ifdef LIGHT
X printf("\033[7m");
X#endif LIGHT
X printf("\033[16;%dH%s", b, bot);
X printf("\033[23;1H");
X printf("\033[m");
X exit(0);
X}
SHAR_EOF
chmod 0755 welcome.c || echo "restore of welcome.c fails"
set `wc -c welcome.c`;Sum=$1
if test "$Sum" != "5802"
then echo original size 5802, current size $Sum;fi
sed 's/^X//' << 'SHAR_EOF' > cpu.h &&
Xint i;
Xchar doo[100];
Xchar poo[100];
XFILE *fp;
X
X#define VAX_780 1
X#define VAX_750 2
X#define VAX_730 3
X#define VAX_8600 4
X#define VAX_8200 5
X#define VAX_8800 6
X#define MVAX_I 7
X#define MVAX_II 8
X
X/* System defines to be changed-- */
X
X#define LOAD /* If you want the load average box, keep this defined. */
X#define CPU /* If you want to know what type CPU you are using, keep
X this defined. NOTE: This option has only been tested for
X Ultrix V2.0, nothing else. Please... Try it and mail
X me back! */
X#define UVERS /* If you want to know the version of Ultrix, keep this
X defined. This will work for any system with /etc/motd.
X#define LIGHT /* If you want the stuff inside the welcome box inversed,
X keep this defined. To make it dark, just comment it out. */
X
SHAR_EOF
chmod 1711 cpu.h || echo "restore of cpu.h fails"
set `wc -c cpu.h`;Sum=$1
if test "$Sum" != "791"
then echo original size 791, current size $Sum;fi
exit 0
More information about the Comp.sources.misc
mailing list