home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume03 / welcome < prev    next >
Encoding:
Text File  |  1991-08-27  |  10.2 KB  |  352 lines

  1. Path: uunet!husc6!necntc!ncoast!allbery
  2. From: pulsar@lsrhs.UUCP (Jim King)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i017: Welcome program for Ultrix
  5. Message-ID: <8805142352.AA17718@EDDIE.MIT.EDU>
  6. Date: 14 May 88 19:27:25 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: pulsar@lsrhs.UUCP (Jim King)
  9. Lines: 340
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. comp.sources.misc: Volume 3, Issue 17
  13. Submitted-By: "Jim King" <pulsar@lsrhs.UUCP>
  14. Archive-Name: welcome
  15.  
  16. #!/bin/sh
  17. # shar:    Shell Archiver  (v1.22)
  18. #
  19. #    Run the following text with /bin/sh to create:
  20. #      README
  21. #      Makefile
  22. #      welcome.1
  23. #      welcome.c
  24. #      cpu.h
  25. #
  26. sed 's/^X//' << 'SHAR_EOF' > README &&
  27. XDisclaimer: I originally found this program for VAX/VMS systems in
  28. Xthe March 1988 issue of Hardcopy magazine (page 83).  I do not credit
  29. Xthe idea to me, but since the actual program was in VMS command form,
  30. XI deided it would be nice to put it on an Ultrix compatible system.
  31. XThis program is intended to be shareware.
  32. X
  33. XWelcome prints out a nice welcome message for the user.
  34. X
  35. XVersion 1: Initial program translated, debugged.  At this time there is only
  36. Xa set message in the middle box.  Future copies should work so that it will
  37. Xnlist the kernel and find the type of VAX and version of Ultrix.
  38. X
  39. XVersion 2: Added load average box and LOAD define in cpu.h
  40. X
  41. XVersion 3: Added CPU type and CPU define, along with Ultrix version and
  42. Xhostname.
  43. X
  44. X** This program translated from VMS command language by Jim King at lsrhs
  45. X** (And added a few extra features...)
  46. X
  47. XNOTES --
  48. X
  49. XDefine LOAD if you want the little load average box
  50. X
  51. XDefine CPU If you want to know the type of CPU you are using.
  52. X
  53. XDefine LIGHT if you want the messages in the box highlighted.
  54. X
  55. XDefine UVERS If you want to know the version of Ultrix.
  56. X    NOTE: This program assumes that /etc/motd is a known file
  57. X          produced by /etc/rc.
  58. SHAR_EOF
  59. chmod 1711 README || echo "restore of README fails"
  60. set `wc -c README`;Sum=$1
  61. if test "$Sum" != "1183"
  62. then echo original size 1183, current size $Sum;fi
  63. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  64. X#    
  65. X#    Makefile for welcome
  66. X#
  67. XDESTDIR= /u/pulsar/Utilities/Welcome
  68. XCFLAGS= -g
  69. XPROGRAM=    welcome
  70. XSRCS=        welcome.c
  71. XLIBS=
  72. X
  73. X${PROGRAM}:    ${SRCS}
  74. X    ${CC} ${CFLAGS} -o $@ $@.c ${LIBS}
  75. X
  76. Xinstall:
  77. X    install ${PROGRAM} ${DESTDIR}/welcome
  78. X
  79. Xtags:
  80. X    ctags -tdw *.c
  81. X
  82. Xclean:
  83. X    rm -f a.out core *.o made
  84. X
  85. Xdepend:
  86. X    echo 'Welcome Compiled.'
  87. SHAR_EOF
  88. chmod 1711 Makefile || echo "restore of Makefile fails"
  89. set `wc -c Makefile`;Sum=$1
  90. if test "$Sum" != "315"
  91. then echo original size 315, current size $Sum;fi
  92. sed 's/^X//' << 'SHAR_EOF' > welcome.1 &&
  93. X.TH welcome 1
  94. X.SH NAME
  95. Xwelcome \- prints out a nice welcome message with useful statistics
  96. X.SH SYNTAX
  97. X.B welcome
  98. X.SH DESCRIPTION
  99. XThe
  100. X.PN welcome
  101. Xcommand makes a graphic box over box and prints out the time, 
  102. Xday, 
  103. Xand system stats
  104. X.PP
  105. X.PN welcome
  106. Xassumes that the file /etc/motd exists.
  107. X.SH SEE ALSO
  108. X/etc/motd
  109. X.SH AUTHOR
  110. XJim King (pulsar) Lincoln-Sudbury Regional High '88.
  111. SHAR_EOF
  112. chmod 1711 welcome.1 || echo "restore of welcome.1 fails"
  113. set `wc -c welcome.1`;Sum=$1
  114. if test "$Sum" != "374"
  115. then echo original size 374, current size $Sum;fi
  116. sed 's/^X//' << 'SHAR_EOF' > welcome.c &&
  117. X#include <time.h>
  118. X#include <stdio.h>
  119. X#include "cpu.h"
  120. X#include <nlist.h>
  121. X
  122. Xextern    struct nlist    namelist[];
  123. Xextern    struct nlist    nl[];
  124. X
  125. Xstruct nlist    nl[] = { { "_cpu" }, { "" } };
  126. Xdouble loadavg[4];
  127. Xint kmem;
  128. X
  129. Xstruct nlist    namelist[] = {
  130. X    { "_avenrun" },
  131. X    { 0 }
  132. X};
  133. X
  134. Xchar *days[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
  135. X         "Thursday", "Friday", "Saturday" };
  136. X
  137. Xchar *mons[] = { "January", "February", "March", "April",
  138. X         "May", "June", "July", "August",
  139. X         "September", "October", "November", "December" };
  140. X
  141. Xchar *ttime[] = { "morning ", "afternoon ", "evening " };
  142. X
  143. Xmain()
  144. X{
  145. X    register struct tm *det;
  146. X    int a, b, x, y, num, cpu;
  147. X    long secs;
  148. X    char    bot[100], *foo, goo[50], ap;
  149. X    time(&secs);
  150. X#ifdef    LOAD
  151. X    nlist("/vmunix", namelist);
  152. X    if (namelist[0].n_type == 1)
  153. X        puts("/vmunix no namelist\n"), exit(1);
  154. X    kmem = open("/dev/kmem", 0);
  155. X    if (kmem <= 0)
  156. X        printf("cannot open /dev/kmem\n"), exit(1);
  157. X    lseek(kmem, (long)namelist[0].n_value, 0);
  158. X    read(kmem, &loadavg[0], sizeof loadavg);
  159. X    close(kmem);
  160. X#endif    LOAD
  161. X#ifdef CPU
  162. X    nlist("/vmunix", nl);
  163. X    if (nl[0].n_type == 1)
  164. X        puts("/vmunix no namelist\n"), exit(1);
  165. X    kmem = open("/dev/kmem", 0);
  166. X    if (kmem <= 0)
  167. X        printf("cannot open /dev/kmem\n"), exit(1);
  168. X    lseek(kmem, nl[0].n_value, 0);
  169. X    read(kmem, &cpu, sizeof(cpu));
  170. X    close(kmem);
  171. X#endif CPU
  172. X    ap = "AP"[(det = localtime(&secs))->tm_hour >= 12];
  173. X    if (det->tm_hour > 0 && det->tm_hour < 12)
  174. X        foo = ttime[0];
  175. X    else if (det->tm_hour > 11 && det->tm_hour < 18)
  176. X        foo = ttime[1];
  177. X    else if (det->tm_hour > 17 && det->tm_hour < 24)
  178. X        foo = ttime[2];
  179. X    if ((det->tm_hour %= 12) == 0)
  180. X        det->tm_hour = 12;
  181. X    fflush(stdout);
  182. X    printf("\033[2J\033(0\033)0\033[m");
  183. X#ifdef    LOAD
  184. X    printf("\033[3;11H\033(B\033)B   Load Average\033(0\033)0");
  185. X    printf("\033[4;11Hlqqqqqqqqqqqqqqqqk");
  186. X    printf("\033[5;11Hx                x");
  187. X    printf("\033[6;11Hmqqqqqqqqqqqqqqwqj");
  188. X    printf("\033[5;13H%4.2f %4.2f %4.2f", loadavg[0], loadavg[1], loadavg[2]);
  189. X    printf("\033[7;16Hlqqqqqqqqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
  190. X#else   LOAD
  191. X    printf("\033[7;16Hlqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk");
  192. X#endif    LOAD
  193. X    printf("\033[8;16Hx                                        x");
  194. X    printf("\033[9;13Hlqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqk");
  195. X    printf("\033[10;10Hlqqvqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvqqk");
  196. X    printf("\033[11;10Hx\033[11;63Hx\033[12;10Hx\033[12;63Hx\033[13;10Hx\033[13;63Hx");
  197. X    printf("\033[14;10Hmqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqj");
  198. X    printf("\033[15;13Hmqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqj");
  199. X    printf("\033[16;16Hx                                        x");
  200. X    printf("\033[17;16Hmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj");
  201. X    printf("\033(B\033)B");
  202. X#ifdef  LIGHT
  203. X    printf("\033[11;13H\033[7m                                                ");
  204. X#endif  LIGHT
  205. X    printf("\033[11;13H    Good %s%s,", foo, getenv("USER"));
  206. X    gethostname(goo, sizeof(goo));
  207. X#ifdef  LIGHT
  208. X    printf("\033[12;13H\033[7m                                                ");
  209. X    printf("\033[12;13H\033[7m        You have connected to %s", goo);
  210. X#else   LIGHT
  211. X    printf("\033[12;13H        You have connected to %s", goo);
  212. X#endif
  213. X#ifdef  LIGHT
  214. X    printf("\033[13;13H\033[7m                                                ");
  215. X#endif  LIGHT
  216. X#ifdef  CPU
  217. X    printf("\033[m");
  218. X    switch(cpu) {
  219. X        case VAX_780:
  220. X#ifdef LIGHT
  221. X            printf("\033[13;13H\033[7m        A VAX 11/780 running Ultrix");
  222. X#else LIGHT
  223. X            printf("\033[13;13H        A VAX 11/780 running Ultrix");
  224. X#endif LIGHT
  225. X            break;
  226. X        case VAX_750:
  227. X#ifdef LIGHT
  228. X            printf("\033[13;13H\033[7m        A VAX 11/750 running Ultrix");
  229. X#else LIGHT
  230. X            printf("\033[13;13H        A VAX 11/750 runing Ultrix");
  231. X#endif LIGHT
  232. X            break;
  233. X        case VAX_730:
  234. X#ifdef LIGHT
  235. X            printf("\033[13;13H\033[7m        A VAX 11/730 running Ultrix");
  236. X#else LIGHT
  237. X            printf("\033[13;13H        A VAX 11/730 runing Ultrix");
  238. X#endif LIGHT
  239. X            break;
  240. X        case VAX_8600:
  241. X#ifdef LIGHT
  242. X            printf("\033[13;13H\033[7m        A VAX 8600 running Ultrix");
  243. X#else LIGHT
  244. X            printf("\033[13;13H        A VAX 8600 runing Ultrix");
  245. X#endif LIGHT
  246. X            break;
  247. X        case VAX_8200:
  248. X#ifdef LIGHT
  249. X            printf("\033[13;13H\033[7m        A VAX 8200 running Ultrix");
  250. X#else LIGHT
  251. X            printf("\033[13;13H        A VAX 8200 runing Ultrix");
  252. X#endif LIGHT
  253. X            break;
  254. X        case VAX_8800:
  255. X#ifdef LIGHT
  256. X            printf("\033[13;13H\033[7m        A VAX 8800 running Ultrix");
  257. X#else LIGHT
  258. X            printf("\033[13;13H        A VAX 8800 runing Ultrix");
  259. X#endif LIGHT
  260. X            break;
  261. X        case MVAX_I:
  262. X#ifdef LIGHT
  263. X            printf("\033[13;13H\033[7m        A MicroVAX I running Ultrix");
  264. X#else LIGHT
  265. X            printf("\033[13;13H        A MicroVAX I runing Ultrix");
  266. X#endif LIGHT
  267. X            break;
  268. X        case MVAX_II:
  269. X#ifdef LIGHT
  270. X            printf("\033[13;13H\033[7m        A MicroVAX II running Ultrix");
  271. X#else LIGHT
  272. X            printf("\033[13;13H        A MicroVAX II runing Ultrix");
  273. X#endif LIGHT
  274. X            break;
  275. X        default:
  276. X            printf("\033[13;13H        CPU ident error");
  277. X            break;
  278. X    }
  279. X#else   CPU
  280. X#ifdef LIGHT
  281. X    printf("\033[13;13H\033[7m        A system running Ultrix");
  282. X#else  LIGHT
  283. X    printf("\033[13;13H        A system running Ultrix");
  284. X#endif LIGHT
  285. X#endif  CPU
  286. X#ifdef    UVERS
  287. X    fp = fopen("/etc/motd", "r");
  288. X    fscanf(fp, "%s%s", poo, doo);
  289. X    printf(" V%c.%c", doo[1], doo[3]);
  290. X    fclose(fp);
  291. X    unlink("/tmp/foo");
  292. X#endif    UVERS
  293. X#ifdef    LIGHT
  294. X    printf("\033[8;18H                                      ");
  295. X    printf("\033[16;18H                                      ");
  296. X#endif    LIGHT
  297. X    x = 40 - (strlen(days[det->tm_wday]) / 2);
  298. X    y = (69 - x);
  299. X    printf("\033[8;%dH%s", y, days[det->tm_wday]);
  300. X    sprintf(bot, "%s %d, 19%d %d:%02d %cM", mons[det->tm_mon],
  301. X            det->tm_mday, det->tm_year, det->tm_hour,
  302. X        det->tm_min, ap);
  303. X    a = 40 -(strlen(bot) / 2);
  304. X    b = (54 - a);
  305. X    printf("\033[m");
  306. X#ifdef LIGHT
  307. X    printf("\033[7m");
  308. X#endif LIGHT
  309. X    printf("\033[16;%dH%s", b, bot);
  310. X    printf("\033[23;1H");
  311. X    printf("\033[m");
  312. X    exit(0);
  313. X}
  314. SHAR_EOF
  315. chmod 0755 welcome.c || echo "restore of welcome.c fails"
  316. set `wc -c welcome.c`;Sum=$1
  317. if test "$Sum" != "5802"
  318. then echo original size 5802, current size $Sum;fi
  319. sed 's/^X//' << 'SHAR_EOF' > cpu.h &&
  320. Xint    i;
  321. Xchar    doo[100];
  322. Xchar    poo[100];
  323. XFILE    *fp;
  324. X
  325. X#define    VAX_780        1
  326. X#define    VAX_750        2
  327. X#define    VAX_730        3
  328. X#define VAX_8600    4
  329. X#define VAX_8200    5
  330. X#define VAX_8800    6
  331. X#define MVAX_I        7
  332. X#define MVAX_II        8
  333. X
  334. X/* System defines to be changed-- */
  335. X
  336. X#define    LOAD    /* If you want the load average box, keep this defined. */
  337. X#define CPU    /* If you want to know what type CPU you are using, keep
  338. X           this defined.  NOTE: This option has only been tested for
  339. X           Ultrix V2.0, nothing else.  Please... Try it and mail
  340. X           me back! */
  341. X#define UVERS    /* If you want to know the version of Ultrix, keep this
  342. X           defined. This will work for any system with /etc/motd.
  343. X#define LIGHT    /* If you want the stuff inside the welcome box inversed,
  344. X           keep this defined. To make it dark, just comment it out. */
  345. X           
  346. SHAR_EOF
  347. chmod 1711 cpu.h || echo "restore of cpu.h fails"
  348. set `wc -c cpu.h`;Sum=$1
  349. if test "$Sum" != "791"
  350. then echo original size 791, current size $Sum;fi
  351. exit 0
  352.