[3670] in SIPB bug reports
some xzwrite features
daemon@ATHENA.MIT.EDU (svalente@Athena.MIT.EDU)
Thu Apr 15 02:36:01 1993
From: svalente@Athena.MIT.EDU
Date: Thu, 15 Apr 93 02:35:20 -0400
To: bugs@Athena.MIT.EDU, bug-sipb@Athena.MIT.EDU
Cc: bjaspan@Athena.MIT.EDU, svalente@Athena.MIT.EDU
Reply-To: svalente@Athena.MIT.EDU
Hello. I've made a few (unrelated) little hacks to xzwrite. In case
anybody cares, I'm sending in this patch. There is no bug fix here,
just a few little features.
1) *columns option: Regardless of the font, the editor defaults to be
80 columns wide. The number of columns can be changed by starting
with the -columns option or with the xzwrite*columns resource. This
is very important to me, since I always start xzwrite on login, and
the number of columns I get on the RS6k is quite annoying.
2) *clearOnSend option: I tried to convince a friend to use xzwrite
and she said that it was annoying that she didn't know when a message
had been successfully sent, and that it should clear the editor when
sent, so I added this option.
3) *randomZsigFile option: The resource xzwrite*randomZsigFile can be
set to the name of a text file to be read on startup. Then, with each
zephyr sent, a line from that file will be randomly chosen and used as
the zsig.
4) *logFile option: The resource xzwrite*logFile can be set to the
name of a text file to which it will log all zephyrs sent.
Well, that's it for now.
Have a nice day.
-Sal.
-------------- cut here and you will damage your monitor -------------
*** /mit/zephyr/src/clients/xzwrite/XZwrite Sat Dec 1 17:44:55 1990
--- ./XZwrite Sun Apr 4 16:05:37 1993
***************
*** 30,36 ****
*sendClose.bottom: ChainTop
*sendClose.left: ChainLeft
*sendClose.right: ChainRight
- *sendClose.width: 671
*sendClose.translations:#override\
<BtnDown>: set() \n\
<BtnUp>: CloseSend() unset() \n\
--- 30,35 ----
***************
*** 41,47 ****
*editPane.left: ChainLeft
*editTitle.showGrip: false
- *editTitle.width: 480
*editTitle.borderWidth: 0
*editForm.showGrip: false
--- 40,45 ----
***************
*** 73,79 ****
<BtnDown>: set() \n\
<BtnUp>: YankNext() unset() \n\
- *editor.width: 480
*editor.height: 130
*editor*editType: edit
*editor*wrap: never
--- 71,76 ----
***************
*** 98,104 ****
*destScroll.bottom: ChainBottom
*destScroll.left: ChainLeft
*destScroll.right: ChainRight
- *destScroll.width: 190
*destScroll.height: 178
*destScroll.resizable: false
*destScroll.allowVert: true
--- 95,100 ----
***************
*** 132,139 ****
<BtnDown>: set() \n\
<BtnUp>: Signature()
*closeOnSend.label: Close On Send
! *closeOnSend.fromVert: signature
*closeOnSend.left: ChainLeft
*closeOnSend.right: ChainRight
*closeOnSend.width: 200
--- 128,143 ----
<BtnDown>: set() \n\
<BtnUp>: Signature()
+ *clearOnSend.label: Clear On Send
+ *clearOnSend.fromVert: signature
+ *clearOnSend.left: ChainLeft
+ *clearOnSend.right: ChainRight
+ *clearOnSend.width: 200
+ *clearOnSend.translations: #override\
+ <BtnDown>,<BtnUp>: toggle() ToggleOption()
+
*closeOnSend.label: Close On Send
! *closeOnSend.fromVert: clearOnSend
*closeOnSend.left: ChainLeft
*closeOnSend.right: ChainRight
*closeOnSend.width: 200
*** /mit/zephyr/src/clients/xzwrite/associate.c Fri Nov 16 11:15:01 1990
--- ./associate.c Fri Apr 2 18:55:01 1993
***************
*** 40,46 ****
AElementRec *a;
int i;
! a = DynGet((char *) array, 0);
for (i=0; i < DynSize(array); i++)
if (strcmp(a[i].index, index) == 0)
return (a[i].value);
--- 40,46 ----
AElementRec *a;
int i;
! a = (AElementRec *) DynGet((char *) array, 0);
for (i=0; i < DynSize(array); i++)
if (strcmp(a[i].index, index) == 0)
return (a[i].value);
*** /mit/zephyr/src/clients/xzwrite/edit_window.c Sat Mar 23 11:06:01 1991
--- ./edit_window.c Fri Apr 2 14:25:12 1993
***************
*** 45,50 ****
--- 45,53 ----
/* Only the second argument matters */
if (defs.close_on_send)
XtCallActionProc(toplevel, "CloseSend", NULL, NULL, 0);
+
+ if (defs.clear_on_send)
+ XtCallActionProc(toplevel, "ClearEditor", NULL, NULL, 0);
}
void edit_set_title(dest)
*** /mit/zephyr/src/clients/xzwrite/interface.c Fri Nov 15 17:54:21 1991
--- ./interface.c Sun Apr 4 16:05:02 1993
***************
*** 26,31 ****
--- 26,32 ----
* menuForm - the form holding the menu list/button
* menuClose - the Close Window button for the dest list
* signature - button to change signature
+ * clearOnSend
* closeOnSend
* pings
* verbose
***************
*** 69,74 ****
--- 70,77 ----
DeleteDest(), HighlightDest(), SelectDest(), OpenMenu(),
ToggleOption(), Signature(), CloseMenu(), CreateDest();
+ static void set_editor_width(), set_sendclose_width();
+
static XtActionsRec actionTable[] = {
/* sendWindow actions */
{"OpenSend", (XtActionProc) OpenSend},
***************
*** 111,118 ****
Widget editPane, editTitle, editForm, editSend, editClear,
editPrev, editNext, editor;
Widget menuWindow, menuForm, menuClose, signature,
! closeOnSend, pings, verbose, authentic, yankDest, addGlobals,
! classInst, commandMask, exitProgram;
void go()
{
--- 114,121 ----
Widget editPane, editTitle, editForm, editSend, editClear,
editPrev, editNext, editor;
Widget menuWindow, menuForm, menuClose, signature,
! clearOnSend, closeOnSend, pings, verbose, authentic,
! yankDest, addGlobals, classInst, commandMask, exitProgram;
void go()
{
***************
*** 162,169 ****
XtAppAddActions(app_con, actionTable, XtNumber(actionTable));
/* Create the icon */
! icon = XtVaCreateManagedWidget("icon", commandWidgetClass, toplevel,
! NULL);
/* Create the menu */
menuWindow = XtVaCreatePopupShell("menuWindow", transientShellWidgetClass,
--- 165,171 ----
XtAppAddActions(app_con, actionTable, XtNumber(actionTable));
/* Create the icon */
! icon = XVCMW("icon", commandWidgetClass, toplevel, NULL);
/* Create the menu */
menuWindow = XtVaCreatePopupShell("menuWindow", transientShellWidgetClass,
***************
*** 171,176 ****
--- 173,179 ----
menuForm = XVCMW("menuForm", formWidgetClass, menuWindow, NULL);
menuClose = XVCMW("menuClose", commandWidgetClass, menuForm, NULL);
signature = XVCMW("signature", commandWidgetClass, menuForm, NULL);
+ clearOnSend = XVCMW("clearOnSend", toggleWidgetClass, menuForm, NULL);
closeOnSend = XVCMW("closeOnSend", toggleWidgetClass, menuForm, NULL);
pings = XVCMW("pings", toggleWidgetClass, menuForm, NULL);
verbose = XVCMW("verbose", toggleWidgetClass, menuForm, NULL);
***************
*** 208,213 ****
--- 211,218 ----
XtAppAddWorkProc(app_con, login_scan_work, NULL);
}
+ set_editor_width();
+ set_sendclose_width();
XtRealizeWidget(toplevel);
}
***************
*** 381,384 ****
--- 386,421 ----
Cardinal *n;
{
XtPopdown(menuWindow);
+ }
+
+ static void set_editor_width (void)
+ {
+ int w, c; char m = 'm';
+ XFontStruct *fs = (XFontStruct *) NULL;
+
+ c = defs.columns;
+ /* get the font structure. */
+ XtVaGetValues(editor, XtNfont, &fs, NULL);
+ if (c < 1 || fs == (XFontStruct *) NULL) return;
+
+ /* set the editor width */
+ w = c * XTextWidth(fs, &m, 1);
+ XtVaSetValues(editor, XtNwidth, (Dimension)w, NULL);
+
+ /* set the destList to have 3/8ths the width of the editor */
+ /* an other idea would be to make it have 3/8ths as many characters,
+ which makes a difference when the editor and destList are in
+ different fonts.
+ however, I prefer this way. */
+ XtVaSetValues(destForm, XtNwidth, (Dimension)(w*3/8), NULL);
+ }
+
+ static void set_sendclose_width (void)
+ {
+ /* make the Close Window button the width of the form */
+ Dimension wi = 0;
+ XtRealizeWidget (sendWindow);
+ XtVaGetValues(sendForm, XtNwidth, &wi, NULL);
+ XtUnrealizeWidget (sendWindow);
+ XtVaSetValues(sendClose, XtNwidth, wi, NULL);
}
*** /mit/zephyr/src/clients/xzwrite/menu_window.c Fri Nov 16 11:15:29 1990
--- ./menu_window.c Fri Apr 2 14:25:13 1993
***************
*** 7,14 ****
#include "xzwrite.h"
#include "GetString.h"
! extern Widget getString, closeOnSend, pings, verbose, authentic, yankDest,
! addGlobals, classInst;
extern Defaults defs;
#define toggle(v) (v = !v)
--- 7,14 ----
#include "xzwrite.h"
#include "GetString.h"
! extern Widget getString, clearOnSend, closeOnSend, pings, verbose,
! authentic, yankDest, addGlobals, classInst;
extern Defaults defs;
#define toggle(v) (v = !v)
***************
*** 15,21 ****
void menu_toggle(w)
Widget w;
{
! if (w == closeOnSend)
toggle(defs.close_on_send);
else if (w == pings)
toggle(defs.ping);
--- 15,23 ----
void menu_toggle(w)
Widget w;
{
! if (w == clearOnSend)
! toggle(defs.clear_on_send);
! else if (w == closeOnSend)
toggle(defs.close_on_send);
else if (w == pings)
toggle(defs.ping);
***************
*** 37,42 ****
--- 39,45 ----
#define set(w, i) XtVaSetValues(w, XtNstate, i ? True : False, NULL)
void menu_match_defs()
{
+ set(clearOnSend, defs.clear_on_send);
set(closeOnSend, defs.close_on_send);
set(pings, defs.ping);
set(verbose, defs.verbose);
*** /mit/zephyr/src/clients/xzwrite/resource.c Fri Nov 16 11:15:41 1990
--- ./resource.c Fri Apr 2 14:25:16 1993
***************
*** 17,22 ****
--- 17,24 ----
{"-v","*verbose", XrmoptionNoArg, (caddr_t) "false"},
{"-close","*closeOnSend", XrmoptionNoArg, (caddr_t) "false"},
{"+close","*closeOnSend", XrmoptionNoArg, (caddr_t) "true"},
+ {"-clear","*clearOnSend", XrmoptionNoArg, (caddr_t) "false"},
+ {"+clear","*clearOnSend", XrmoptionNoArg, (caddr_t) "true"},
{"+n","*ping", XrmoptionNoArg, (caddr_t) "true"},
{"-n","*ping", XrmoptionNoArg, (caddr_t) "false"},
{"+yd","*yankDest", XrmoptionNoArg, (caddr_t) "true"},
***************
*** 43,48 ****
--- 45,53 ----
{"-pong", "*pongScan", XrmoptionNoArg, (caddr_t) "false"},
{"+reply", "*autoReply", XrmoptionNoArg, (caddr_t) "true"},
{"-reply", "*autoReply", XrmoptionNoArg, (caddr_t) "false"},
+ {"-columns", "*columns", XrmoptionSepArg, (caddr_t) 80},
+ {"-zsigs", "*randomZsigFile", XrmoptionSepArg, (caddr_t) "*"},
+ {"-logfile", "*logFile", XrmoptionSepArg, (caddr_t) "*"},
};
#define offset(field) XtOffset(Defaults *, field)
***************
*** 65,70 ****
--- 70,78 ----
{"closeOnSend", "Close", XtRBoolean, sizeof(Boolean),
offset(close_on_send), XtRString, "false"},
+ {"clearOnSend", "Close", XtRBoolean, sizeof(Boolean),
+ offset(clear_on_send), XtRString, "false"},
+
{"ping", "Ping", XtRBoolean, sizeof(Boolean),
offset(ping), XtRString, "true"},
***************
*** 103,108 ****
--- 111,125 ----
{"autoReply", "AutoReply", XtRBoolean, sizeof(Boolean),
offset(auto_reply), XtRString, "false"},
+
+ {"columns", "Columns", XtRInt, sizeof(int),
+ offset(columns), XtRString, "80"},
+
+ {"randomZsigFile", "RandomZsigFile", XtRString, sizeof(String),
+ offset(zsigfile), XtRString, "*"},
+
+ {"logFile", "LogFile", XtRString, sizeof(String),
+ offset(logfile), XtRString, "*"},
};
#undef offset
*** /mit/zephyr/src/clients/xzwrite/xzwrite-proto.h Sat Mar 23 10:57:44 1991
--- ./xzwrite-proto.h Fri Apr 2 14:25:16 1993
***************
*** 65,70 ****
--- 65,71 ----
int zeph_ping P((Dest dest ));
int zeph_pong P((Dest dest ));
char *zeph_get_signature P((void ));
+ void log_message P((Dest dest , char *msg ));
/* GetString.c */
Widget InitGetString P((Widget parent , char *name ));
*** /mit/zephyr/src/clients/xzwrite/xzwrite.c Fri Nov 15 18:26:03 1991
--- ./xzwrite.c Thu Apr 8 17:03:08 1993
***************
*** 1,16 ****
#include <stdio.h>
#include <pwd.h>
#include "xzwrite.h"
extern Defaults defs;
main(argc, argv)
int argc;
char **argv;
{
! char sigbfr[BUFSIZ];
!
zeph_init();
build_interface(&argc, argv);
--- 1,24 ----
#include <stdio.h>
+ #include <string.h>
#include <pwd.h>
+ #include <dyn.h>
#include "xzwrite.h"
+ extern int srandom(), time();
extern Defaults defs;
+ DynObject zsigs = NULL;
+ #define islower(foo) ((foo) >= 'a' && (foo) <= 'z')
+ #define toupper(foo) ((foo)+'A'-'a')
+
+ Boolean set_random_zsigs();
+
main(argc, argv)
int argc;
char **argv;
{
! srandom(time(NULL));
zeph_init();
build_interface(&argc, argv);
***************
*** 38,43 ****
--- 46,55 ----
char *sig, sigbfr[BUFSIZ];
/* Do magic with signature */
+ if (defs.zsigfile)
+ if (strcmp(defs.zsigfile, "*"))
+ if (set_random_zsigs()) return;
+
if (*defs.signature)
return;
***************
*** 80,83 ****
--- 92,125 ----
{
fprintf(stderr, "Usage: xzwrite [ -toolkitoption ... ] [-s signature] [+d | -d] [+n | -n]\n\t[+v | -v] [+yd | -yd] [+av | -av] [+ci | -ci] [-my yanks]\n\t[+l | -l] [+a | -a] [+x | -x] [+z | -z] [+pong | -pong] [+reply | -reply]\n");
exit(1);
+ }
+
+ #define BUF_SIZE 1024
+
+ Boolean set_random_zsigs()
+ { int x, n;
+ char z[BUF_SIZE], *z2;
+ FILE *fp;
+
+ fp = fopen(defs.zsigfile, "r");
+ if (!fp) {
+ fprintf(stderr, "xzwrite: cant open file \"%s\".\n", defs.zsigfile);
+ return False; }
+
+ zsigs = DynCreate(sizeof(char*), 5);
+
+ while ( fgets(z, BUF_SIZE, fp) != NULL) {
+ if (z[0] == '#' || z[0] == 0) continue;
+ n = strlen(z);
+ z2 = (char *) calloc (sizeof(char), n);
+ if (!z2) {
+ fprintf(stderr, "xzwrite: out of memory.\n"); exit(1); }
+ if (z[n-1] == '\n') { n--; z[n] = 0; }
+ for (x = 0; x <= n; x++) {
+ if (z[x] != '\\') z2[x] = z[x];
+ else z2[x] = '\n'; }
+ DynAdd(zsigs, (DynPtr) &z2); }
+
+ fclose(fp);
+ return True;
}
*** /mit/zephyr/src/clients/xzwrite/xzwrite.h Fri Nov 16 11:15:56 1990
--- ./xzwrite.h Fri Apr 2 14:25:16 1993
***************
*** 32,38 ****
Boolean debug;
Boolean pong_scan;
Boolean auto_reply;
! int max_yanks, command_mask;
} Defaults;
/* Structure to contain a legal zephyr triple */
--- 32,40 ----
Boolean debug;
Boolean pong_scan;
Boolean auto_reply;
! int max_yanks, command_mask, columns;
! String zsigfile;
! String logfile;
} Defaults;
/* Structure to contain a legal zephyr triple */
*** /mit/zephyr/src/clients/xzwrite/zephyr.c Fri Nov 15 18:10:38 1991
--- ./zephyr.c Sun Apr 4 14:18:15 1993
***************
*** 2,10 ****
--- 2,13 ----
#include "xzwrite.h"
#include <strings.h>
+ #include <dyn.h>
static int zeph_send_notice();
extern Defaults defs;
+ extern DynObject zsigs;
+ extern int random();
/* ARGSUSED */
void zeph_dispatch(client_data, source, input_id)
***************
*** 127,139 ****
{
ZNotice_t notice;
int msglen, siglen, ret;
! char *sig_msg;
msglen = strlen(msg);
! siglen = strlen(defs.signature);
sig_msg = (char *) Malloc(msglen + siglen + 2, "while sending message",
NULL);
! sprintf(sig_msg, "%s%c%s", defs.signature, '\0', msg);
bzero((char *) ¬ice, sizeof(ZNotice_t));
notice.z_kind = ACKED;
--- 130,148 ----
{
ZNotice_t notice;
int msglen, siglen, ret;
! char *sig_msg, *sig;
+ if (!zsigs) sig = defs.signature;
+ else {
+ char **tmp;
+ tmp = (char **) DynGet (zsigs, random() % DynSize(zsigs));
+ sig = *tmp; }
+
msglen = strlen(msg);
! siglen = strlen(sig);
sig_msg = (char *) Malloc(msglen + siglen + 2, "while sending message",
NULL);
! sprintf(sig_msg, "%s%c%s", sig, '\0', msg);
bzero((char *) ¬ice, sizeof(ZNotice_t));
notice.z_kind = ACKED;
***************
*** 148,160 ****
/* This really gross looking mess is brought to you by zwrite.c */
if (defs.auth) {
! if (*defs.signature)
notice.z_default_format = "Class $class, Instance $instance:\nTo: @bold($recipient)\n@bold($1) <$sender>\n\n$2";
else
notice.z_default_format = "Class $class, Instance $instance:\nTo: @bold($recipient)\n$message";
}
else {
! if (*defs.signature)
notice.z_default_format = "@bold(UNAUTHENTIC) Class $class, Instance $instance:\n@bold($1) <$sender>\n\n$2";
else
notice.z_default_format = "@bold(UNAUTHENTIC) Class $class, Instance $instance:\n$message";
--- 157,169 ----
/* This really gross looking mess is brought to you by zwrite.c */
if (defs.auth) {
! if (*sig)
notice.z_default_format = "Class $class, Instance $instance:\nTo: @bold($recipient)\n@bold($1) <$sender>\n\n$2";
else
notice.z_default_format = "Class $class, Instance $instance:\nTo: @bold($recipient)\n$message";
}
else {
! if (*sig)
notice.z_default_format = "@bold(UNAUTHENTIC) Class $class, Instance $instance:\n@bold($1) <$sender>\n\n$2";
else
notice.z_default_format = "@bold(UNAUTHENTIC) Class $class, Instance $instance:\n$message";
***************
*** 162,167 ****
--- 171,182 ----
ret = zeph_send_notice(¬ice, (defs.auth) ? ZAUTH : ZNOAUTH);
free(sig_msg);
+
+ /* log to file */
+ if (defs.logfile)
+ if (strcmp(defs.logfile, "*"))
+ log_message (dest, msg);
+
return ret;
}
***************
*** 267,269 ****
--- 282,311 ----
}
}
#endif
+
+ extern char *currentdate();
+
+ void log_message(dest, msg)
+ Dest dest;
+ char *msg;
+ {
+ FILE *fp; int i;
+
+ fp = fopen(defs.logfile, "a");
+ if (!fp) {
+ fp = fopen(defs.logfile, "w");
+ if (!fp) {
+ fprintf(stderr, "xzwrite: could not open log file \"%s\".\n",
+ defs.logfile);
+ return; }
+ }
+
+ fprintf(fp, "To: %s, %s, %s\n", dest->zclass, dest->zinst, dest->zrecip);
+ fprintf(fp, "Date: %s\n", currentdate());
+
+ i = strlen(msg)-1;
+ while (msg[i] == '\n' && i > 0) i--;
+ if (msg[i] != '\n') i++; msg[i] = 0;
+ fputs(msg, fp); fprintf(fp, "\n\n");
+ fclose(fp);
+ }
*** /mit/zephyr/src/clients/xzwrite/Imakefile Mon Sep 2 18:58:33 1991
--- ./Imakefile Sun Apr 4 15:53:38 1993
***************
*** 15,25 ****
SRCS = interface.c resource.c destlist.c util.c bfgets.c \
gethomedir.c dest_window.c xzwrite.c edit_window.c zephyr.c\
! GetString.c Popup.c yank.c menu_window.c logins.c
OBJS = interface.o resource.o destlist.o util.o bfgets.o \
gethomedir.o dest_window.o xzwrite.o edit_window.o zephyr.o\
! GetString.o Popup.o yank.o menu_window.o logins.o
HDRS = GetString.h associate.h xzwrite.h xzwrite-proto.h
--- 15,25 ----
SRCS = interface.c resource.c destlist.c util.c bfgets.c \
gethomedir.c dest_window.c xzwrite.c edit_window.c zephyr.c\
! GetString.c Popup.c yank.c menu_window.c logins.c currentdate.c
OBJS = interface.o resource.o destlist.o util.o bfgets.o \
gethomedir.o dest_window.o xzwrite.o edit_window.o zephyr.o\
! GetString.o Popup.o yank.o menu_window.o logins.o currentdate.o
HDRS = GetString.h associate.h xzwrite.h xzwrite-proto.h
*** ./currentdate.c~ Thu Apr 15 02:32:03 1993
--- ./currentdate.c Fri Apr 9 12:21:17 1993
***************
*** 0 ****
--- 1,29 ----
+ /*
+ * currentdate.c by sal valente <svalente@athena.mit.edu>
+ */
+
+ #include <stdio.h>
+ #include <time.h>
+
+ char *currentdate ();
+
+ /*
+ * returns the current date in a user readable form, with a newline at
+ * the end.
+ *
+ * this is intensely un-portable.
+ */
+
+ #if defined(unix) && ( defined(vax) || defined(ibm032) )
+ #define _BSD_SOURCE
+ #endif
+ #if defined(_BSD_SOURCE) && !defined(_POSIX_SOURCE)
+ typedef long time_t;
+ #endif
+
+ char *currentdate ()
+ {
+ time_t t;
+ t = time (NULL);
+ return asctime (localtime (&t));
+ }