Skip to content

Commit 5e54e4f

Browse files
committed
possible fix for garbage printing with ':m'
README: fix usage for password 2nd attempt to fix garbage printing fix typo 2nd fix cleanup guard against accidental WAIT_SIG read move WAIT_SIG check after garbage cleanup experiment with disabling echo update update update enable backspace in stdin from virtual terminal update
1 parent cdabee7 commit 5e54e4f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ usage: kirc [-s hostname] [-p port] [-c channel] [-n nick] [-k password] [-v|V]
5050
-p server port (default: '6667')
5151
-c channel name (default: '#kisslinux')
5252
-n user nickname
53-
-n user password
53+
-k user password
5454
-v version information
5555
-V verbose output (e.g. raw stream)

kirc.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ kbhit(void) {
2929

3030
int byteswaiting;
3131
struct termios term;
32+
term.c_cc[VERASE] = 127;
33+
tcgetattr(0, &term);
3234
fd_set fds;
3335
struct timespec ts = {0};
34-
tcgetattr(0, &term);
3536

3637
struct termios term2 = term;
3738

@@ -54,7 +55,7 @@ raw(char *fmt, ...) {
5455
vsnprintf(sbuf, BUFF, fmt, ap);
5556
va_end(ap);
5657

57-
if (verb) printf("<< %s", sbuf);
58+
if (verb) printf("<< \x1b[33m%s\x1b[0m", sbuf);
5859

5960
write(conn, sbuf, strlen(sbuf));
6061
}
@@ -127,7 +128,7 @@ pars(int sl, char *buf) {
127128
buf_c[o + 1] = '\0';
128129
o = -1;
129130

130-
if (verb) printf(">> %s", buf_c);
131+
if (verb) printf(">> \x1b[33m%s\x1b[0m", buf_c);
131132

132133
if (!strncmp(buf_c, "PING", 4)) {
133134
buf_c[1] = 'O';
@@ -164,7 +165,7 @@ main(int argc, char **argv) {
164165

165166
while ((cval = getopt(argc, argv, "s:p:n:k:c:vV")) != -1) {
166167
switch (cval) {
167-
case 'v' : printf("kirc 0.0.1\n"); break;
168+
case 'v' : puts("kirc 0.0.1"); break;
168169
case 'V' : verb = 1; break;
169170
case 's' : host = optarg; break;
170171
case 'p' : port = optarg; break;
@@ -188,15 +189,17 @@ main(int argc, char **argv) {
188189
pid_t pid = fork();
189190

190191
if (pid == 0) {
191-
int sl;
192+
int sl, i, j;
192193
char u[CMAX];
193194

194195
con();
195196

196197
while ((sl = read(conn, sbuf, BUFF))) {
197198
pars(sl, sbuf);
198-
if ((read(fd[0], u, CMAX) > 0) && !strstr(u, "WAIT_SIG")) {
199-
raw("%s\r\n", u);
199+
if (read(fd[0], u, CMAX) > 0) {
200+
for (i = 0; u[i] != '\n'; i++) continue;
201+
for (j = i; j < CMAX; j++) u[j] = ' ';
202+
if (!strstr(u, "WAIT_SIG")) raw("%-*.*s\r\n", i, i, u);
200203
}
201204
}
202205
printf("(press <ENTER> to quit)\n");
@@ -216,12 +219,11 @@ main(int argc, char **argv) {
216219

217220
switch (usrin[1]) {
218221
case 'q':
219-
write(fd[1], "quit", sizeof("quit"));
222+
dprintf(fd[1],"quit\n");
220223
break;
221224
case 'm':
222225
while (isspace(*cmd_val)) cmd_val++;
223-
dprintf(fd[1], "privmsg #%s :%-*s", \
224-
chan, CMAX - strlen(chan) - 11, cmd_val);
226+
dprintf(fd[1], "privmsg #%s :%s", chan, cmd_val);
225227
break;
226228
}
227229
}

0 commit comments

Comments
 (0)