summaryrefslogtreecommitdiff
path: root/clients/zleave/zleave.c
diff options
context:
space:
mode:
authorGravatar Robert S. French <rfrench@mit.edu>1987-08-06 18:45:58 +0000
committerGravatar Robert S. French <rfrench@mit.edu>1987-08-06 18:45:58 +0000
commit963a0fad2d5cac207488a584781a2ec099167cac (patch)
treef1c256684b63e9aff037ec6c688506d542613c88 /clients/zleave/zleave.c
parent041f719cbb8d31ada6b5e087e4cd04d7d59c827d (diff)
Added automatic subscriptions
Diffstat (limited to 'clients/zleave/zleave.c')
-rw-r--r--clients/zleave/zleave.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/clients/zleave/zleave.c b/clients/zleave/zleave.c
index 0cd73b3..66d82f4 100644
--- a/clients/zleave/zleave.c
+++ b/clients/zleave/zleave.c
@@ -59,16 +59,48 @@ main(argc, argv)
char **argv;
{
long when, tod, now, diff, hours, minutes;
- char *cp;
+ char *cp,*envptr,buf[64];
+ FILE *fp;
int *nv;
int atoi();
int ret;
-
+ int port;
+ ZSubscription_t sub;
+
if ((ret = ZInitialize()) != ZERR_NONE) {
- printf("No Zephyr! Will write directly to terminal.\n");
+ fprintf(stderr,"No Zephyr! Will write directly to terminal.\n");
use_zephyr = 0;
}
strcpy(origlogin, getlogin());
+
+ if (use_zephyr) {
+ envptr = (char *)getenv("WGFILE");
+ if (!envptr) {
+ sprintf(buf,"/tmp/wg.%d",getuid());
+ envptr = buf;
+ }
+ if (!(fp = fopen(envptr,"r"))) {
+ fprintf(stderr,"Can't find WindowGram subscription port.\n");
+ fprintf(stderr,"Will write directly to terminal.\n");
+ use_zephyr = 0;
+ }
+ else {
+ fscanf(fp,"%d",&port);
+ fclose(fp);
+ }
+ }
+
+ if (use_zephyr) {
+ sub.class = MESSAGE_CLASS;
+ sub.classinst = INSTANCE;
+ sub.recipient = ZGetSender();
+ printf("Using port %d\n",port);
+ if (ZSubscribeTo(&sub,1,(u_short)port) != ZERR_NONE) {
+ fprintf(stderr,"Subscription error! Writing to your terminal...\n");
+ use_zephyr = 0;
+ }
+ }
+
if (argc < 2) {
printf("When do you have to leave? ");
fflush(stdout);
@@ -117,6 +149,7 @@ char **argv;
printf("That time has already passed!\n");
exit(1);
}
+
doalarm(diff);
exit(0);
}
@@ -203,7 +236,7 @@ char *msg;
notice.z_port = 0;
notice.z_class = MESSAGE_CLASS;
notice.z_class_inst = INSTANCE;
- notice.z_recipient = origlogin;
+ notice.z_recipient = ZGetSender();
notice.z_opcode = "";
notice.z_sender = 0;
notice.z_default_format = "\n$1";