Skip to content

Commit

Permalink
0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpcpc authored Dec 18, 2020
1 parent 9370902 commit 4d0d71f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# - run: git checkout HEAD^2
# if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 0 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<a href="https://www.codacy.com/manual/mcpcpc/kirc/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=mcpcpc/kirc&amp;utm_campaign=Badge_Grade"><img src="https://app.codacy.com/project/badge/Grade/5616c0ed4b2f4209826038dbc270dbf5" alt="Codacy status"></a>
</p>

<p align="center">
<img src="https://raw.githubusercontent.com/mcpcpc/kirc/gh-pages/tty.gif" width="550">
</p>

## Features

* Excellent cross-platform compatibility.
Expand Down
44 changes: 16 additions & 28 deletions kirc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <termios.h>
#include <sys/ioctl.h>

#define VERSION "0.2.2" /* version */
#define VERSION "0.2.3" /* version */
#define AUTHORS "Michael Czigler" /* authors */
#define MSG_MAX 512 /* max message length */
#define CHA_MAX 200 /* max channel length */
Expand Down Expand Up @@ -162,22 +162,9 @@ static void abFree(struct abuf * ab) {
free(ab->b);
}

static size_t pstrlen(const char * s) {
size_t len = 0, i = 0;
while (s[i] != '\0') {
if (s[i] == '\033') {
i = strpbrk(s + i, "m") - s + 1;
continue;
}
len++;
i++;
}
return len;
}

static void refreshLine(struct State * l) {
char seq[64];
size_t plen = pstrlen(l->prompt) + 2;
size_t plen = strlen(l->prompt) + 2;
int fd = STDOUT_FILENO;
char * buf = l->buf;
size_t len = l->len;
Expand Down Expand Up @@ -378,23 +365,33 @@ static int edit(struct State * l) {
}

static void stateReset(struct State * l) {
l->plen = pstrlen(l->prompt);
l->plen = strlen(l->prompt);
l->oldpos = 0;
l->pos = 0;
l->len = 0;
l->buf[0] = '\0';
l->buflen--;
}

static char * ctime_now(char buf[26]) {
struct tm tm_;
time_t now = time(NULL);
if (!asctime_r(localtime_r (&now, &tm_), buf))
return NULL;
*strchr(buf, '\n') = '\0';
return buf;
}

static void logAppend(char * str, char * path) {
FILE * out;
char buf[26];

if ((out = fopen(path, "a")) == NULL) {
perror("fopen");
exit(1);
}

fprintf(out, "%s\n", str);
ctime_now(buf);
fprintf(out, "%s:%s", buf, str);
fclose(out);
}

Expand Down Expand Up @@ -502,15 +499,6 @@ static void paramPrintJoin(struct Param * p) {
printf(" [\x1b[33m%s\x1b[0m] ", p->channel);
}

static char * ctime_now (char buf[26]) {
struct tm tm_;
time_t now = time(NULL);
if (!asctime_r(localtime_r (&now, &tm_), buf))
return NULL;
*strchr(buf, '\n') = '\0';
return buf;
}

static void handleCTCP(const char * nickname, char * message) {
if (message[0] != '\001' && strncmp(message, "ACTION", 6))
return;
Expand Down Expand Up @@ -555,7 +543,7 @@ static void paramPrintChan(struct Param * p) {
s = p->nicklen - strnlen(p->nickname, MSG_MAX);
printf("%*s\x1b[33;1m%-.*s\x1b[0m ", s, "", p->nicklen, p->nickname);
if (p->params) {
printf(p->params);
printf("%s", p->params);
p->offset += strnlen(p->params, CHA_MAX);
}
}
Expand Down

0 comments on commit 4d0d71f

Please sign in to comment.