ref: 06cce7c189e5c3f0cf1e51b74ea7a3176dd0ea8f
parent: 2ca228ddf3befc5feb0d980ec9efc867ad296c7e
author: Sigrid Haflínudóttir <[email protected]>
date: Tue May 19 13:36:27 EDT 2020
9gc: don't print 'JOINED ...' by default
--- a/9gc.c
+++ b/9gc.c
@@ -37,9 +37,11 @@
uint32_t wroff;
uint32_t wrend;
uint64_t chatoff;
- const char *nick;
};
+static const char *nick;
+static int printjoin;
+
static uint8_t *
ctxread(C9ctx *ctx, uint32_t size, int *err)
{
@@ -187,8 +189,8 @@
write(1, r->read.data, r->read.size);
a->chatoff += r->read.size;
case Ropen:
- if ((a->flags & Joined) == 0) {
- c9write(ctx, &tag, Chatfid, 0, buf, snprintf(buf, sizeof(buf), "JOIN %s to chat\n", a->nick));
+ if ((a->flags & Joined) == 0 && printjoin) {
+ c9write(ctx, &tag, Chatfid, 0, buf, snprintf(buf, sizeof(buf), "JOIN %s to chat\n", nick));
a->flags |= Joined;
}
c9read(ctx, &tag, Chatfid, a->chatoff, Msize);
@@ -345,7 +347,7 @@
c9proc(ctx);
if (FD_ISSET(0, &r)) {
s = (char*)a->rdbuf;
- sz = sprintf(s, "%s → ", a->nick);
+ sz = sprintf(s, "%s → ", nick);
for (;;) {
if ((n = read(0, s+sz, sizeof(a->rdbuf)-sz)) > 0)
sz += n;
@@ -366,12 +368,10 @@
{
struct parg_state ps;
C9aux *a;
- const char *nick;
int c;
parg_init(&ps);
- nick = NULL;
while ((c = parg_getopt(&ps, argc, argv, "dh")) >= 0) {
switch (c) {
case 1:
@@ -381,6 +381,9 @@
}
nick = ps.optarg;
break;
+ case 'j':
+ printjoin = 1;
+ break;
case 'h':
fprintf(stderr, "usage: 9gc NICKNAME\n");
return 0;
@@ -403,7 +406,6 @@
if ((a = registry()) == NULL)
return 1;
- a->nick = nick;
while (chatrw(a) == 0 && wrsend(a) == 0);
return 0;