[2841] in Release_Engineering
new xlogin code
daemon@ATHENA.MIT.EDU (Mark Rosenstein)
Tue May 19 18:04:16 1992
Date: Tue, 19 May 92 18:04:00 -0400
From: Mark Rosenstein <mar@MIT.EDU>
To: rel-eng@MIT.EDU
This is the new code to properly do the MOTD, refreshing it at
reactivate time. The updated resource file includes changing the grey
back to black in the login window.
-Mark
*** xlogin.c.orig Fri May 8 12:58:19 1992
--- xlogin.c Tue May 19 17:40:30 1992
***************
*** 5,10 ****
--- 5,11 ----
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
+ #include <sys/stat.h>
#include <utmp.h>
#include <X11/Intrinsic.h>
#include <ctype.h>
***************
*** 92,100 ****
String loginName;
Boolean blankAll;
Boolean showMotd;
- #ifdef MOTD_TEST
String motdFile;
- #endif
} XLoginResources;
/*
--- 93,99 ----
***************
*** 272,300 ****
XtGetApplicationResources(appShell, (caddr_t) &resources,
my_resources, XtNumber(my_resources),
NULL, (Cardinal) 0);
- /*
- * merge in the motd file, if one exists, and the "showMotd" resource
- * is true...
- */
- if (resources.showMotd
- #ifdef MOTD_TEST
- && resources.motdFile != NULL
- #endif
- )
- {
- XrmDatabase motd_rdb, cur_rdb;
- #ifdef MOTD_TEST
- if ((motd_rdb = XrmGetFileDatabase(resources.motdFile)) != NULL )
- #else
- if ((motd_rdb = XrmGetFileDatabase(MOTD_FILENAME)) != NULL )
- #endif
- {
- cur_rdb = XtDatabase(dpy);
- XrmMergeDatabases (motd_rdb, &cur_rdb);
- }
- }
-
WcRegisterCallback(app, "UnsetFocus", unfocusACT, NULL);
WcRegisterCallback(app, "runCB", runCB, NULL);
WcRegisterCallback(app, "setfocusCB", focusCB, NULL);
--- 271,277 ----
***************
*** 438,449 ****
XtMainLoop ( );
}
static void
move_instructions(data, timerid)
XtPointer data;
XtIntervalId *timerid;
{
- static Dimension x_max = 0, y_max = 0;
Position x, y;
Window wins[2];
--- 415,427 ----
XtMainLoop ( );
}
+ static Dimension x_max = 0, y_max = 0;
+
static void
move_instructions(data, timerid)
XtPointer data;
XtIntervalId *timerid;
{
Position x, y;
Window wins[2];
***************
*** 489,494 ****
--- 467,474 ----
exit(0);
}
+ do_motd();
+
if ((file = open(UTMPF, O_RDONLY, 0)) >= 0) {
while (read(file, (char *) &utmp, sizeof(utmp)) > 0) {
if (utmp.ut_name[0] != 0
***************
*** 579,584 ****
--- 559,565 ----
for (i=0; i < num_screens; i++)
XtPopup(savershell[i], XtGrabNone);
+ do_motd();
XtPopup(ins, XtGrabNone);
XRaiseWindow(XtDisplay(ins), XtWindow(ins));
unfocusACT(appShell, NULL, NULL, NULL);
***************
*** 614,619 ****
--- 595,666 ----
react_timerid = XtAddTimeOut(resources.reactivate_timeout * 1000,
start_reactivate, NULL);
}
+
+
+ /* Check the motd file and update the contents of the widget if necessary */
+
+ do_motd()
+ {
+ static Widget motdtext = NULL;
+ static time_t modtime = 0;
+ struct stat stbuf;
+ Arg args[1];
+ char buf[10000], *temp, *s, *d;
+ int fid, len;
+
+ if (!motdtext) {
+ motdtext = WcFullNameToWidget(appShell, "*motd");
+ #ifndef MOTD_TEST
+ resources.motdFile = MOTD_FILENAME;
+ #endif
+ }
+
+ if (resources.showMotd && resources.motdFile != NULL) {
+ if (!stat(resources.motdFile, &stbuf) &&
+ stbuf.st_mtime > modtime) {
+ /* time to update the motd */
+ modtime = stbuf.st_mtime;
+ /* read the new motd */
+ if ((fid = open(resources.motdFile, O_RDONLY)) < 0) return;
+ len = read(fid, buf, sizeof(buf));
+ close(fid);
+ buf[len] = 0;
+
+ /* de-tabbify the motd (label widgets don't do tabs) */
+ for (s = buf; *s; s++)
+ if (*s == '\t') len += 7;
+ d = temp = malloc(len+1);
+ len = 0;
+ for (s = buf; *s; s++) {
+ switch (*s) {
+ case '\t':
+ *d++ = ' ';
+ len++;
+ while (len++ % 8 != 0)
+ *d++ = ' ';
+ len--;
+ break;
+ case '\n':
+ len = 0;
+ *d++ = *s;
+ break;
+ default:
+ *d++ = *s;
+ len++;
+ }
+ }
+
+ /* now set the text */
+ XtSetArg(args[0], XtNlabel, temp);
+ XtSetValues(motdtext, args, 1);
+ free(temp);
+
+ /* force move_instructions() to recompute size */
+ x_max = 0;
+ }
+ }
+ }
+
static void
unsave(w, popdown, event, bool)
*** Xlogin.presed Tue May 19 17:53:13 1992
--- Xlogin.presed.orig Mon Apr 27 19:14:17 1992
***************
*** 30,40 ****
*instructions.wcConstructor: XtCreateTransientShell
*instructions.wcChildren: hitanykey
- *instructions.allowShellResize: true
*hitanykey.wcClassName: Form
*hitanykey.wcChildren: version, logo, welcome, host, clock, mesg, \
! logo2, motd
*warningShell.wcConstructor: XtCreateTransientShell
*warningShell.wcChildren: warning
--- 30,39 ----
*instructions.wcConstructor: XtCreateTransientShell
*instructions.wcChildren: hitanykey
*hitanykey.wcClassName: Form
*hitanykey.wcChildren: version, logo, welcome, host, clock, mesg, \
! logo2
*warningShell.wcConstructor: XtCreateTransientShell
*warningShell.wcChildren: warning
***************
*** 151,163 ****
*mesg.font: -adobe-new century schoolbook-bold-r-*-240-*
*mesg.label: Press any key to start . . .
- *motd.wcClassName: Label
- *motd.fromHoriz: *logo
- *motd.horizDistance: 5
- *motd.vertDistance: 10
- *motd.fromVert: *mesg
- *motd*resizable: true
-
*userName.wcClassName: Label
*userName.fromVert: *welcome
*userName.width: 110
--- 150,155 ----
***************
*** 647,653 ****
!
*login*background: white
! *login*foreground: black,gray55,black
*login.logo.foreground: black,gray15,red
*login.eyes.foreground: black,gray15,red
--- 639,645 ----
!
*login*background: white
! *login*foreground: black,gray55,gray55
*login.logo.foreground: black,gray15,red
*login.eyes.foreground: black,gray15,red