diff options
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 50 |
1 files changed, 17 insertions, 33 deletions
@@ -1467,15 +1467,12 @@ struct formatter size_t items_alloc; ///< Items allocated }; -static void -formatter_init (struct formatter *self, - struct app_context *ctx, struct server *s) +static struct formatter +formatter_make (struct app_context *ctx, struct server *s) { - memset (self, 0, sizeof *self); - self->ctx = ctx; - self->s = s; - self->items = xcalloc (sizeof *self->items, (self->items_alloc = 16)); - self->items_len = 0; + struct formatter self = { .ctx = ctx, .s = s }; + self.items = xcalloc (sizeof *self.items, (self.items_alloc = 16)); + return self; } static void @@ -3749,8 +3746,7 @@ buffer_update_time (struct app_context *ctx, time_t now, FILE *stream, return; } - struct formatter f; - formatter_init (&f, ctx, NULL); + struct formatter f = formatter_make (ctx, NULL); formatter_add (&f, "#a#s\n", ATTR_DATE_CHANGE, buf); formatter_flush (&f, stream, flush_opts); // Flush the trailing formatting reset item @@ -3805,8 +3801,7 @@ buffer_line_display (struct app_context *ctx, CALL (ctx->input, hide); - struct formatter f; - formatter_init (&f, ctx, NULL); + struct formatter f = formatter_make (ctx, NULL); buffer_line_write_time (&f, line, stdout, 0); // Ignore all formatting for messages coming from other buffers, that is @@ -3827,8 +3822,7 @@ static void buffer_line_write_to_backlog (struct app_context *ctx, struct buffer_line *line, FILE *log_file, int flush_opts) { - struct formatter f; - formatter_init (&f, ctx, NULL); + struct formatter f = formatter_make (ctx, NULL); buffer_line_write_time (&f, line, log_file, flush_opts); buffer_line_flush (line, &f, log_file, flush_opts); } @@ -3840,9 +3834,7 @@ buffer_line_write_to_log (struct app_context *ctx, if (line->flags & BUFFER_LINE_SKIP_FILE) return; - struct formatter f; - formatter_init (&f, ctx, NULL); - + struct formatter f = formatter_make (ctx, NULL); struct tm current; char buf[20]; if (!gmtime_r (&line->when, ¤t)) @@ -3922,8 +3914,7 @@ log_full (struct app_context *ctx, struct server *s, struct buffer *buffer, va_list ap; va_start (ap, format); - struct formatter f; - formatter_init (&f, ctx, s); + struct formatter f = formatter_make (ctx, s); formatter_addv (&f, format, &ap); log_formatter (ctx, buffer, flags, &f); @@ -4105,8 +4096,7 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer) static void buffer_print_read_marker (struct app_context *ctx, FILE *stream, int flush_opts) { - struct formatter f; - formatter_init (&f, ctx, NULL); + struct formatter f = formatter_make (ctx, NULL); formatter_add (&f, "#a-- -- -- ---\n", ATTR_READ_MARKER); formatter_flush (&f, stream, flush_opts); // Flush the trailing formatting reset item @@ -6020,8 +6010,7 @@ irc_is_highlight (struct server *s, const char *message) // Strip formatting from the message so that it doesn't interfere // with nickname detection (color sequences in particular) - struct formatter f; - formatter_init (&f, s->ctx, NULL); + struct formatter f = formatter_make (s->ctx, NULL); formatter_parse_mirc (&f, message); struct str stripped = str_make (); @@ -6576,8 +6565,7 @@ irc_handle_kick (struct server *s, const struct irc_message *msg) if (buffer) { - struct formatter f; - formatter_init (&f, s->ctx, s); + struct formatter f = formatter_make (s->ctx, s); formatter_add (&f, "#a<--#r #N #a#s#r #n", ATTR_PART, msg->prefix, ATTR_PART, "has kicked", target); if (message) @@ -6844,8 +6832,7 @@ irc_handle_part (struct server *s, const struct irc_message *msg) if (buffer) { - struct formatter f; - formatter_init (&f, s->ctx, s); + struct formatter f = formatter_make (s->ctx, s); formatter_add (&f, "#a<--#r #N #a#s#r #S", ATTR_PART, msg->prefix, ATTR_PART, "has left", channel_name); if (message) @@ -6907,8 +6894,7 @@ irc_handle_ctcp_request (struct server *s, return; } - struct formatter f; - formatter_init (&f, s->ctx, s); + struct formatter f = formatter_make (s->ctx, s); formatter_add (&f, "CTCP requested by #n", msg->prefix); if (irc_is_channel (s, irc_skip_statusmsg (s, target))) formatter_add (&f, " (to #S)", target); @@ -7001,8 +6987,7 @@ static void log_quit (struct server *s, struct buffer *buffer, const char *prefix, const char *reason) { - struct formatter f; - formatter_init (&f, s->ctx, s); + struct formatter f = formatter_make (s->ctx, s); formatter_add (&f, "#a<--#r #N #a#s#r", ATTR_PART, prefix, ATTR_PART, "has quit"); if (reason) @@ -13868,8 +13853,7 @@ format_input_and_die (struct app_context *ctx) char buf[513]; while (fgets (buf, sizeof buf, stdin)) { - struct formatter f; - formatter_init (&f, ctx, NULL); + struct formatter f = formatter_make (ctx, NULL); formatter_add (&f, "#m", buf); formatter_flush (&f, stdout, FLUSH_OPT_NOWRAP); formatter_free (&f); |