|
13 | 13 | #include <termios.h>
|
14 | 14 | #include <sys/ioctl.h>
|
15 | 15 |
|
16 |
| -#define VERSION "0.2.2" /* version */ |
| 16 | +#define VERSION "0.2.3" /* version */ |
17 | 17 | #define AUTHORS "Michael Czigler" /* authors */
|
18 | 18 | #define MSG_MAX 512 /* max message length */
|
19 | 19 | #define CHA_MAX 200 /* max channel length */
|
@@ -162,22 +162,9 @@ static void abFree(struct abuf * ab) {
|
162 | 162 | free(ab->b);
|
163 | 163 | }
|
164 | 164 |
|
165 |
| -static size_t pstrlen(const char * s) { |
166 |
| - size_t len = 0, i = 0; |
167 |
| - while (s[i] != '\0') { |
168 |
| - if (s[i] == '\033') { |
169 |
| - i = strpbrk(s + i, "m") - s + 1; |
170 |
| - continue; |
171 |
| - } |
172 |
| - len++; |
173 |
| - i++; |
174 |
| - } |
175 |
| - return len; |
176 |
| -} |
177 |
| - |
178 | 165 | static void refreshLine(struct State * l) {
|
179 | 166 | char seq[64];
|
180 |
| - size_t plen = pstrlen(l->prompt) + 2; |
| 167 | + size_t plen = strlen(l->prompt) + 2; |
181 | 168 | int fd = STDOUT_FILENO;
|
182 | 169 | char * buf = l->buf;
|
183 | 170 | size_t len = l->len;
|
@@ -378,23 +365,33 @@ static int edit(struct State * l) {
|
378 | 365 | }
|
379 | 366 |
|
380 | 367 | static void stateReset(struct State * l) {
|
381 |
| - l->plen = pstrlen(l->prompt); |
| 368 | + l->plen = strlen(l->prompt); |
382 | 369 | l->oldpos = 0;
|
383 | 370 | l->pos = 0;
|
384 | 371 | l->len = 0;
|
385 | 372 | l->buf[0] = '\0';
|
386 | 373 | l->buflen--;
|
387 | 374 | }
|
388 | 375 |
|
| 376 | +static char * ctime_now(char buf[26]) { |
| 377 | + struct tm tm_; |
| 378 | + time_t now = time(NULL); |
| 379 | + if (!asctime_r(localtime_r (&now, &tm_), buf)) |
| 380 | + return NULL; |
| 381 | + *strchr(buf, '\n') = '\0'; |
| 382 | + return buf; |
| 383 | +} |
| 384 | + |
389 | 385 | static void logAppend(char * str, char * path) {
|
390 | 386 | FILE * out;
|
| 387 | + char buf[26]; |
391 | 388 |
|
392 | 389 | if ((out = fopen(path, "a")) == NULL) {
|
393 | 390 | perror("fopen");
|
394 | 391 | exit(1);
|
395 | 392 | }
|
396 |
| - |
397 |
| - fprintf(out, "%s\n", str); |
| 393 | + ctime_now(buf); |
| 394 | + fprintf(out, "%s:%s", buf, str); |
398 | 395 | fclose(out);
|
399 | 396 | }
|
400 | 397 |
|
@@ -502,15 +499,6 @@ static void paramPrintJoin(struct Param * p) {
|
502 | 499 | printf(" [\x1b[33m%s\x1b[0m] ", p->channel);
|
503 | 500 | }
|
504 | 501 |
|
505 |
| -static char * ctime_now (char buf[26]) { |
506 |
| - struct tm tm_; |
507 |
| - time_t now = time(NULL); |
508 |
| - if (!asctime_r(localtime_r (&now, &tm_), buf)) |
509 |
| - return NULL; |
510 |
| - *strchr(buf, '\n') = '\0'; |
511 |
| - return buf; |
512 |
| -} |
513 |
| - |
514 | 502 | static void handleCTCP(const char * nickname, char * message) {
|
515 | 503 | if (message[0] != '\001' && strncmp(message, "ACTION", 6))
|
516 | 504 | return;
|
@@ -555,7 +543,7 @@ static void paramPrintChan(struct Param * p) {
|
555 | 543 | s = p->nicklen - strnlen(p->nickname, MSG_MAX);
|
556 | 544 | printf("%*s\x1b[33;1m%-.*s\x1b[0m ", s, "", p->nicklen, p->nickname);
|
557 | 545 | if (p->params) {
|
558 |
| - printf(p->params); |
| 546 | + printf("%s", p->params); |
559 | 547 | p->offset += strnlen(p->params, CHA_MAX);
|
560 | 548 | }
|
561 | 549 | }
|
|
0 commit comments