Compare commits
1 Commits
b810ba0f77
...
17c0ec4f33
Author | SHA1 | Date | |
---|---|---|---|
|
17c0ec4f33 |
19
src/line.c
19
src/line.c
@ -16,6 +16,8 @@
|
||||
#include "line.h"
|
||||
#include "util.h"
|
||||
|
||||
char *_irc_line_to_string(struct line *l, int skip_first);
|
||||
|
||||
// TODO resolve assuming signed overflow does not occur when changing X +- C1
|
||||
// cmp C2 to X cmp C2 -+ C1
|
||||
#pragma GCC diagnostic ignored "-Wstrict-overflow"
|
||||
@ -76,6 +78,19 @@ void irc_line_append(struct line *l, const char *s)
|
||||
}
|
||||
|
||||
char *irc_line_to_string(struct line *l)
|
||||
{
|
||||
return _irc_line_to_string(l, 0);
|
||||
}
|
||||
|
||||
char *irc_line_to_string_skip(struct line *l, int skip_first)
|
||||
{
|
||||
if (skip_first >= irc_line_count(l)) {
|
||||
return NULL;
|
||||
}
|
||||
return _irc_line_to_string(l, skip_first);
|
||||
}
|
||||
|
||||
char *_irc_line_to_string(struct line *l, int skip_first)
|
||||
{
|
||||
size_t len = 0;
|
||||
int i;
|
||||
@ -83,7 +98,7 @@ char *irc_line_to_string(struct line *l)
|
||||
|
||||
if (l->origin)
|
||||
len = strlen(l->origin) + 2;
|
||||
for (i = 0; i < array_count(&l->words); i++)
|
||||
for (i = skip_first; i < array_count(&l->words); i++)
|
||||
len += strlen(array_get(&l->words, i)) + 1;
|
||||
len += 1; /* remove one trailing space and add \r\n */
|
||||
len++; /* last args ":" */
|
||||
@ -95,7 +110,7 @@ char *irc_line_to_string(struct line *l)
|
||||
strcat(ret, l->origin);
|
||||
strcat(ret, " ");
|
||||
}
|
||||
for (i = 0; i < array_count(&l->words) - 1; i++) {
|
||||
for (i = skip_first; i < array_count(&l->words) - 1; i++) {
|
||||
strcat(ret, array_get(&l->words, i));
|
||||
strcat(ret, " ");
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ void irc_line_write(struct line *l, connection_t *c);
|
||||
void irc_line_append(struct line *l, const char *s);
|
||||
struct line *irc_line_new_from_string(char *str);
|
||||
char *irc_line_to_string(struct line *l);
|
||||
char *irc_line_to_string_skip(struct line *l, int skip_first);
|
||||
char *irc_line_to_string_to(struct line *line, char *nick);
|
||||
void irc_line_free(struct line *l);
|
||||
struct line *irc_line_dup(struct line *line);
|
||||
|
Loading…
Reference in New Issue
Block a user