parent
19464369c3
commit
1232ce451d
1
chat.h
1
chat.h
|
@ -45,6 +45,7 @@ enum { TAGS_LEN = 256 };
|
||||||
const struct Tag TAG_NONE;
|
const struct Tag TAG_NONE;
|
||||||
const struct Tag TAG_STATUS;
|
const struct Tag TAG_STATUS;
|
||||||
const struct Tag TAG_VERBOSE;
|
const struct Tag TAG_VERBOSE;
|
||||||
|
struct Tag tagFind(const char *name);
|
||||||
struct Tag tagFor(const char *name);
|
struct Tag tagFor(const char *name);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|
39
input.c
39
input.c
|
@ -37,6 +37,13 @@ static void privmsg(struct Tag tag, bool action, const char *mesg) {
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *param(const char *command, char **params, const char *name) {
|
||||||
|
char *param = strsep(params, " ");
|
||||||
|
if (param) return param;
|
||||||
|
uiFmt(TAG_STATUS, "%s requires a %s", command, name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
typedef void (*Handler)(struct Tag tag, char *params);
|
typedef void (*Handler)(struct Tag tag, char *params);
|
||||||
|
|
||||||
static void inputMe(struct Tag tag, char *params) {
|
static void inputMe(struct Tag tag, char *params) {
|
||||||
|
@ -45,31 +52,25 @@ static void inputMe(struct Tag tag, char *params) {
|
||||||
|
|
||||||
static void inputNick(struct Tag tag, char *params) {
|
static void inputNick(struct Tag tag, char *params) {
|
||||||
(void)tag;
|
(void)tag;
|
||||||
char *nick = strsep(¶ms, " ");
|
char *nick = param("/nick", ¶ms, "name");
|
||||||
if (nick) {
|
if (!nick) return;
|
||||||
ircFmt("NICK %s\r\n", nick);
|
ircFmt("NICK %s\r\n", nick);
|
||||||
} else {
|
|
||||||
uiLog(TAG_STATUS, L"/nick requires a name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inputJoin(struct Tag tag, char *params) {
|
static void inputJoin(struct Tag tag, char *params) {
|
||||||
(void)tag;
|
(void)tag;
|
||||||
char *chan = strsep(¶ms, " ");
|
char *chan = param("/join", ¶ms, "channel");
|
||||||
if (chan) {
|
if (!chan) return;
|
||||||
ircFmt("JOIN %s\r\n", chan);
|
ircFmt("JOIN %s\r\n", chan);
|
||||||
} else {
|
|
||||||
uiLog(TAG_STATUS, L"/join requires a channel");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inputWho(struct Tag tag, char *params) {
|
static void inputWho(struct Tag tag, char *params) {
|
||||||
(void)params; // TODO
|
(void)params;
|
||||||
ircFmt("WHO %s\r\n", tag.name);
|
ircFmt("WHO %s\r\n", tag.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inputTopic(struct Tag tag, char *params) {
|
static void inputTopic(struct Tag tag, char *params) {
|
||||||
if (params) { // TODO
|
if (params) {
|
||||||
ircFmt("TOPIC %s :%s\r\n", tag.name, params);
|
ircFmt("TOPIC %s :%s\r\n", tag.name, params);
|
||||||
} else {
|
} else {
|
||||||
ircFmt("TOPIC %s\r\n", tag.name);
|
ircFmt("TOPIC %s\r\n", tag.name);
|
||||||
|
@ -96,13 +97,19 @@ static void inputOpen(struct Tag tag, char *params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inputView(struct Tag tag, char *params) {
|
static void inputView(struct Tag tag, char *params) {
|
||||||
char *view = strsep(¶ms, " ");
|
(void)tag;
|
||||||
|
char *view = param("/view", ¶ms, "name or number");
|
||||||
if (!view) return;
|
if (!view) return;
|
||||||
int num = strtol(view, &view, 0);
|
int num = strtol(view, &view, 0);
|
||||||
if (view[0]) {
|
if (!view[0]) {
|
||||||
uiViewTag(tagFor(view));
|
|
||||||
} else {
|
|
||||||
uiViewNum(num);
|
uiViewNum(num);
|
||||||
|
} else {
|
||||||
|
struct Tag tag = tagFind(view);
|
||||||
|
if (tag.id != TAG_NONE.id) {
|
||||||
|
uiViewTag(tag);
|
||||||
|
} else {
|
||||||
|
uiFmt(TAG_STATUS, "No view for %s", view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
tag.c
8
tag.c
|
@ -37,11 +37,17 @@ static struct Tag Tag(size_t id) {
|
||||||
return (struct Tag) { id, tags.name[id] };
|
return (struct Tag) { id, tags.name[id] };
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Tag tagFor(const char *name) {
|
struct Tag tagFind(const char *name) {
|
||||||
for (size_t id = 0; id < tags.len; ++id) {
|
for (size_t id = 0; id < tags.len; ++id) {
|
||||||
if (strcmp(tags.name[id], name)) continue;
|
if (strcmp(tags.name[id], name)) continue;
|
||||||
return Tag(id);
|
return Tag(id);
|
||||||
}
|
}
|
||||||
|
return TAG_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Tag tagFor(const char *name) {
|
||||||
|
struct Tag tag = tagFind(name);
|
||||||
|
if (tag.id != TAG_NONE.id) return tag;
|
||||||
if (tags.len == TAGS_LEN) return TAG_STATUS;
|
if (tags.len == TAGS_LEN) return TAG_STATUS;
|
||||||
size_t id = tags.len++;
|
size_t id = tags.len++;
|
||||||
tags.name[id] = strdup(name);
|
tags.name[id] = strdup(name);
|
||||||
|
|
Loading…
Reference in New Issue