Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
static GQueue *split_message(const struct session *sess, const gchar *text, const gchar *event) { GQueue *list = g_queue_new(); gchar *nick = g_strdup(sess->server->nick); gchar *target = g_strdup(sess->channel); gchar *host, *temp; gchar *tempstr = "\0"; gint len; gchar *note_stop = g_strdup(prefs.text_overflow_stop); gint stop_len = strlen(note_stop); /* * build the base string so we know how many bytes to subtract from the * absolute maximum imposed by the IRC standard */ if (sess->me && sess->me->hostname) { host = g_strdup(sess->me->hostname); temp = g_strdup_printf(":%s!%s@%s %s %s :", nick, prefs.username, host, event, target); len = strlen(temp) + 9; /* this is for CTCP ACTION */ } else { /* * we don't have a hostname, for some reason, so just assume * it's a maximum of 64 chars */ temp = g_strdup_printf(":%s!%s@%s %s %s :", nick, prefs.username, "", event, target); len = strlen(temp) + 9 + 64; /* this is for CTCP ACTION */ } g_free(temp); /* * iterate through the string and push each segment onto a list so we can * later send them out one at a time. */ while ((strlen(text) + len + stop_len) > IRC_MAX_LENGTH-1) { tempstr = g_strrstr_len(text, IRC_MAX_LENGTH - (len + stop_len), " "); temp = g_strndup(text, tempstr-text); g_queue_push_tail(list, g_strconcat(temp, " ", note_stop, NULL)); text = tempstr; } g_queue_push_tail(list, g_strdup(text)); return list; }
This paste will be private.
From the Design Piracy series on my blog: