1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 08:53:26 +01:00

allow line_info_add to take formatted strings with variable # of args

This commit is contained in:
Jfreegman 2014-07-24 22:43:32 -04:00
parent 8d8df585ad
commit b68deef6db
16 changed files with 199 additions and 207 deletions

View File

@ -98,9 +98,9 @@ void callback_media_change ( void* av, int32_t call_index, void *arg );
int stop_transmission(int call_index);
void write_device_callback(ToxAv* av, int32_t call_index, int16_t* data, int size);
static void print_err (ToxWindow *self, char *error_str)
static void print_err (ToxWindow *self, const char *error_str)
{
line_info_add(self, NULL, NULL, NULL, error_str, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, error_str);
}
ToxAv *init_audio(ToxWindow *self, Tox *tox)
@ -123,7 +123,7 @@ ToxAv *init_audio(ToxWindow *self, Tox *tox)
}
if ( init_devices(ASettins.av) == de_InternalError ) {
line_info_add(self, NULL, NULL, NULL, "Failed to init devices", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");
toxav_kill(ASettins.av);
return ASettins.av = NULL;
}
@ -183,7 +183,7 @@ int start_transmission(ToxWindow *self)
/* Don't provide support for video */
if ( 0 != toxav_prepare_transmission(ASettins.av, self->call_idx, &ASettins.cs, 0) ) {
line_info_add(self, NULL, NULL, NULL, "Could not prepare transmission", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Could not prepare transmission");
}
if ( !toxav_capability_supported(ASettins.av, self->call_idx, AudioDecoding) ||
@ -194,16 +194,16 @@ int start_transmission(ToxWindow *self)
if ( open_primary_device(input, &ASettins.calls[self->call_idx].in_idx,
av_DefaultSettings.audio_sample_rate, av_DefaultSettings.audio_frame_duration) != de_None )
line_info_add(self, NULL, NULL, NULL, "Failed to open input device!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open input device!");
if ( register_device_callback(self->call_idx, ASettins.calls[self->call_idx].in_idx,
read_device_callback, &self->call_idx, _True) != de_None)
/* Set VAD as true for all; TODO: Make it more dynamic */
line_info_add(self, NULL, NULL, NULL, "Failed to register input handler!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to register input handler!");
if ( open_primary_device(output, &ASettins.calls[self->call_idx].out_idx,
av_DefaultSettings.audio_sample_rate, av_DefaultSettings.audio_frame_duration) != de_None ) {
line_info_add(self, NULL, NULL, NULL, "Failed to open output device!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to open output device!");
ASettins.calls[self->call_idx].has_output = 0;
}
@ -259,7 +259,7 @@ void callback_recv_starting ( void* av, int32_t call_index, void* arg )
if (windows[i].onStarting != NULL && windows[i].call_idx == call_index) {
windows[i].onStarting(&windows[i], ASettins.av, call_index);
if ( 0 != start_transmission(&windows[i]) ) {/* YEAH! */
line_info_add(&windows[i], NULL, NULL, NULL, "Error starting transmission!", SYS_MSG, 0, 0);
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0 , "Error starting transmission!");
}
return;
}
@ -278,7 +278,7 @@ void callback_call_started ( void* av, int32_t call_index, void* arg )
if (windows[i].onStart != NULL && windows[i].call_idx == call_index) {
windows[i].onStart(&windows[i], ASettins.av, call_index);
if ( 0 != start_transmission(&windows[i]) ) {/* YEAH! */
line_info_add(&windows[i], NULL, NULL, NULL, "Error starting transmission!", SYS_MSG, 0, 0);
line_info_add(&windows[i], NULL, NULL, NULL, SYS_MSG, 0, 0, "Error starting transmission!");
return;
}
}
@ -327,8 +327,8 @@ void callback_media_change(void* av, int32_t call_index, void* arg)
*/
void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char msg[MAX_STR_SIZE];
char *error_str;
const char *msg;
const char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -354,18 +354,17 @@ void cmd_call(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
goto on_error;
}
snprintf(msg, sizeof(msg), "Calling... idx: %d", self->call_idx);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Calling... idx: %d";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, self->call_idx);
return;
on_error:
snprintf(msg, sizeof(msg), "%s", error_str);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
print_err(self, error_str);
}
void cmd_answer(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *error_str;
const char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -396,7 +395,7 @@ on_error:
void cmd_reject(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *error_str;
const char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -427,7 +426,7 @@ on_error:
void cmd_hangup(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *error_str;
const char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -456,7 +455,7 @@ on_error:
void cmd_cancel(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *error_str;
const char *error_str;
if (argc != 0) {
error_str = "Invalid syntax!";
@ -493,8 +492,8 @@ on_error:
void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char msg[MAX_STR_SIZE];
char *error_str;
const char *msg;
const char *error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -512,8 +511,8 @@ void cmd_list_devices(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*
type = output;
else {
snprintf(msg, sizeof(msg), "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Invalid type: %s";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return;
}
@ -527,8 +526,8 @@ on_error:
/* This changes primary device only */
void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char msg[MAX_STR_SIZE];
char *error_str;
const char *msg;
const char *error_str;
if ( argc != 2 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -547,8 +546,8 @@ void cmd_change_device(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
type = output;
else {
snprintf(msg, sizeof(msg), "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Invalid type: %s";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return;
}
@ -573,8 +572,8 @@ on_error:
void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char msg[MAX_STR_SIZE];
char *error_str;
const char *msg;
const char *error_str;
if ( argc != 2 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -593,8 +592,8 @@ void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (
type = output;
else {
snprintf(msg, sizeof(msg), "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Invalid type: %s";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return;
}
@ -644,8 +643,8 @@ void cmd_ccur_device(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (
void cmd_mute(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char msg[MAX_STR_SIZE];
char *error_str;
const char *msg;
const char *error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Type must be specified!";
@ -663,8 +662,8 @@ void cmd_mute(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[
type = output;
else {
snprintf(msg, sizeof(msg), "Invalid type: %s", argv[1]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Invalid type: %s";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, argv[1]);
return;
}
@ -692,7 +691,7 @@ void cmd_mute(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[
void cmd_sense(WINDOW * window, ToxWindow * self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *error_str;
const char *error_str;
if ( argc != 1 ) {
if ( argc < 1 ) error_str = "Must have value!";

View File

@ -46,9 +46,9 @@ static void print_matches(ToxWindow *self, Tox *m, const void *list, int n_items
int i;
for (i = 0; i < n_items; ++i)
line_info_add(self, NULL, NULL, NULL, &L[i * size], SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, &L[i * size]);
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0); /* formatting */
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, ""); /* formatting */
}
/* puts match in match buffer. if more than one match, add first n chars that are identical.

View File

@ -160,7 +160,7 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int32_t num, const char *msg
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, 0);
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, 0, msg);
write_to_log(msg, nick, ctx->log, false);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
@ -205,7 +205,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *acti
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, action);
write_to_log(action, nick, ctx->log, true);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOFOCUS);
}
@ -255,8 +255,8 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
if (self->num != num)
return;
char msg[MAX_STR_SIZE * 2];
char *errmsg;
const char *msg;
const char *errmsg;
/* holds the filename appended to the user specified path */
char filename_path[MAX_STR_SIZE] = {0};
@ -266,13 +266,12 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
get_file_name(filename_nopath, sizeof(filename_nopath), pathname);
int len = strlen(filename_nopath);
snprintf(msg, sizeof(msg), "File transfer request for '%s' (%llu bytes).", filename_nopath,
(long long unsigned int)filesize);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "File transfer request for '%s' (%llu bytes).";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, filename_nopath, (long long unsigned int) filesize);
if (filenum >= MAX_FILES) {
errmsg = "Too many pending file requests; discarding.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -284,7 +283,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
if (len >= sizeof(friends[num].file_receiver.filenames[filenum])) {
errmsg = "File name too long; discarding.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -315,13 +314,13 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t
if (count > 999) {
errmsg = "Error saving file to disk.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
}
snprintf(msg, sizeof(msg), "Type '/savefile %d' to accept the file transfer.", filenum);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Type '/savefile %d' to accept the file transfer.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, filenum);
friends[num].file_receiver.pending[filenum] = true;
friends[num].file_receiver.size[filenum] = filesize;
@ -390,7 +389,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, int32_t num, uint8_t rec
break;
}
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, const char *data,
@ -403,7 +402,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
if (fp) {
if (fwrite(data, length, 1, fp) != 1) {
line_info_add(self, NULL, NULL, NULL, " * Error writing to file.", SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Error writing to file.");
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
chat_close_file_receiver(num, filenum);
}
@ -430,14 +429,14 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, co
if (self->num != friendnumber)
return;
char msg[MAX_STR_SIZE + TOX_MAX_NAME_LENGTH];
const char *msg;
char name[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, name, friendnumber);
snprintf(msg, sizeof(msg), "%s has invited you to a group chat.", name);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, "Type \"/join\" to join the chat.", SYS_MSG, 0, 0);
msg = "%s has invited you to a group chat.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
memcpy(friends[friendnumber].groupchat_key, group_pub_key,
sizeof(friends[friendnumber].groupchat_key));
@ -458,7 +457,7 @@ void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
/* call_index is set here and reset on call end */
self->call_idx = call_index;
line_info_add(self, NULL, NULL, NULL, "Incoming audio call! Type: \"/answer\" or \"/reject\"", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Incoming audio call! Type: \"/answer\" or \"/reject\"");
#ifdef _SOUND_NOTIFY
if (self->active_sound == -1)
@ -471,7 +470,7 @@ void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
return;
line_info_add(self, NULL, NULL, NULL, "Ringing...\"cancel\" ?", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ringing...\"cancel\" ?");
#ifdef _SOUND_NOTIFY
if (self->active_sound == -1)
@ -486,7 +485,7 @@ void chat_onStarting (ToxWindow *self, ToxAv *av, int call_index)
init_infobox(self);
line_info_add(self, NULL, NULL, NULL, "Call started! Type: \"/hangup\" to end it.", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -501,7 +500,7 @@ void chat_onEnding (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Call ended!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call ended!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -515,7 +514,7 @@ void chat_onError (ToxWindow *self, ToxAv *av, int call_index)
return;
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Error!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -530,7 +529,7 @@ void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
init_infobox(self);
line_info_add(self, NULL, NULL, NULL, "Call started! Type: \"/hangup\" to end it.", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -545,7 +544,7 @@ void chat_onCancel (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Call canceled!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call canceled!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -559,7 +558,7 @@ void chat_onReject (ToxWindow *self, ToxAv *av, int call_index)
return;
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Rejected!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Rejected!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -574,7 +573,7 @@ void chat_onEnd (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Call ended!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call ended!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -588,7 +587,7 @@ void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
return;
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "No answer!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No answer!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -603,7 +602,7 @@ void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
kill_infobox(self);
self->call_idx = -1;
line_info_add(self, NULL, NULL, NULL, "Peer disconnected; call ended!", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer disconnected; call ended!");
#ifdef _SOUND_NOTIFY
stop_sound(self->active_sound);
@ -709,11 +708,11 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, action, ACTION, 0, 0);
line_info_add(self, timefrmt, selfname, NULL, ACTION, 0, 0, action);
if (tox_send_action(m, self->num, (uint8_t *) action, strlen(action)) == 0) {
char *errmsg = " * Failed to send action.";
line_info_add(self, NULL, selfname, NULL, errmsg, SYS_MSG, 0, RED);
const char *errmsg = " * Failed to send action.";
line_info_add(self, NULL, selfname, NULL, SYS_MSG, 0, RED, errmsg);
} else {
write_to_log(action, selfname, ctx->log, true);
}
@ -797,10 +796,10 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, line, OUT_MSG, 0, 0);
line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, line);
if (!statusbar->is_online || tox_send_message(m, self->num, (uint8_t *) line, strlen(line)) == 0) {
line_info_add(self, NULL, NULL, NULL, " * Failed to send message.", SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message.");
} else {
write_to_log(line, selfname, ctx->log, false);
}

View File

@ -40,11 +40,11 @@ extern uint8_t max_file_senders_index;
void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *errmsg;
const char *errmsg;
if (argc < 1) {
errmsg = "Invalid syntax";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -52,36 +52,35 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
if (groupnum == 0 && strcmp(argv[1], "0")) { /* atoi returns 0 value on invalid input */
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
if (tox_invite_friend(m, self->num, groupnum) == -1) {
errmsg = "Failed to invite contact to group.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Invited contact to Group %d.", groupnum);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
const char *msg = "Invited contact to Group %d.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, groupnum);
}
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *errmsg;
const char *errmsg;
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
errmsg = " * Warning: Too many windows are open.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
return;
}
char *groupkey = friends[self->num].groupchat_key;
const char *groupkey = friends[self->num].groupchat_key;
if (!friends[self->num].groupchat_pending) {
errmsg = "No pending group chat invite.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -89,13 +88,13 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
if (groupnum == -1) {
errmsg = "Group chat instance failed to initialize.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
if (init_groupchat_win(prompt, m, groupnum) == -1) {
errmsg = "Group chat window failed to initialize.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
tox_del_groupchat(m, groupnum);
return;
}
@ -103,11 +102,11 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *errmsg;
const char *errmsg;
if (argc != 1) {
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -115,32 +114,31 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
if ((filenum == 0 && strcmp(argv[1], "0")) || filenum >= MAX_FILES) {
errmsg = "No pending file transfers with that number.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
if (!friends[self->num].file_receiver.pending[filenum]) {
errmsg = "No pending file transfers with that number.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
char *filename = friends[self->num].file_receiver.filenames[filenum];
const char *filename = friends[self->num].file_receiver.filenames[filenum];
if (tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0) == 0) {
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1f%%)", filename, 0.0);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
const char *msg = "Saving file as: '%s' (%.1f%%)";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, filename, 0.0);
friends[self->num].file_receiver.line_id[filenum] = self->chatwin->hst->line_end->id + 1;
if ((friends[self->num].file_receiver.files[filenum] = fopen(filename, "a")) == NULL) {
errmsg = "* Error writing to file.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
tox_file_send_control(m, self->num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
}
} else {
errmsg = "File transfer failed.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
}
friends[self->num].file_receiver.pending[filenum] = false;
@ -148,17 +146,17 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char *errmsg;
const char *errmsg;
if (max_file_senders_index >= (MAX_FILES - 1)) {
errmsg = "Please wait for some of your outgoing file transfers to complete.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
if (argc < 1) {
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -166,7 +164,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
if (path[0] != '\"') {
errmsg = "File path must be enclosed in quotes.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -176,7 +174,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
if (path_len > MAX_STR_SIZE) {
errmsg = "File path exceeds character limit.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -184,7 +182,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
if (file_to_send == NULL) {
errmsg = "File not found.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -198,7 +196,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
if (filenum == -1) {
errmsg = "Error sending file.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -217,9 +215,8 @@ void cmd_sendfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_file_data_size(m, self->num), file_to_send);
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Sending file: '%s'", path);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
const char *msg = "Sending file: '%s'";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, path);
if (i == max_file_senders_index)
++max_file_senders_index;

View File

@ -439,12 +439,9 @@ void* thread_poll (void* arg) // TODO: maybe use thread for every input source
void print_devices(ToxWindow* self, DeviceType type)
{
int i = 0;
for ( ; i < size[type]; i ++) {
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "%d: %s", i, devices_names[type][i]);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
}
for ( ; i < size[type]; i ++)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%d: %s", i, devices_names[type][i]);
return;
}

View File

@ -49,7 +49,7 @@ extern struct _Winthread Winthread;
/* TODO: process keys from key file instead of hard-coding like a noob */
static struct dns3_server {
char *name;
const char *name;
char key[DNS3_KEY_SZ];
} dns3_servers[] = {
{
@ -83,13 +83,12 @@ static struct _dns_thread {
} dns_thread;
static int dns_error(ToxWindow *self, char *errmsg)
static int dns_error(ToxWindow *self, const char *errmsg)
{
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "User lookup failed: %s", errmsg);
const char *msg = "User lookup failed: %s";
pthread_mutex_lock(&Winthread.lock);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, errmsg);
pthread_mutex_unlock(&Winthread.lock);
return -1;
@ -174,7 +173,7 @@ static int parse_dns_response(ToxWindow *self, u_char *answer, int ans_len, char
and the domain in dombuf.
return length of username on success, -1 on failure */
static int parse_addr(char *addr, char *namebuf, char *dombuf)
static int parse_addr(const char *addr, char *namebuf, char *dombuf)
{
char tmpaddr[MAX_STR_SIZE];
char *tmpname, *tmpdom;
@ -209,8 +208,8 @@ void *dns3_lookup_thread(void *data)
}
/* get domain name/pub key */
char *DNS_pubkey = NULL;
char *domname = NULL;
const char *DNS_pubkey = NULL;
const char *domname = NULL;
int i;
for (i = 0; i < NUM_DNS3_SERVERS; ++i) {
@ -293,8 +292,8 @@ void *dns3_lookup_thread(void *data)
void dns3_lookup(ToxWindow *self, Tox *m, char *id_bin, char *addr, char *msg)
{
if (t_data.busy) {
char *err = "Please wait for previous user lookup to finish.";
line_info_add(self, NULL, NULL, NULL, err, SYS_MSG, 0, 0);
const char *err = "Please wait for previous user lookup to finish.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, err);
return;
}

View File

@ -100,7 +100,7 @@ static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*a
if (cmd[i] == '\0') {
char *errmsg = "Invalid argument. Did you forget a closing \"?";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
free(cmd);
return -1;
}

View File

@ -50,7 +50,7 @@ static void set_max_file_senders_index(void)
static void close_file_sender(ToxWindow *self, Tox *m, int i, char *msg, int CTRL, int filenum, int32_t friendnum)
{
if (self->chatwin != NULL)
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
tox_file_send_control(m, friendnum, 0, filenum, CTRL, 0, 0);

View File

@ -114,10 +114,10 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, const cha
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(prompt, timefrmt, nick, NULL, str, IN_MSG, 0, 0);
line_info_add(prompt, timefrmt, nick, NULL, IN_MSG, 0, 0, str);
char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
const char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
notify(prompt, error, NT_WNDALERT_1);
}
}
@ -223,9 +223,8 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* File transfer from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
const char *msg = "* File transfer from %s failed: too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick);
notify(prompt, error, NT_WNDALERT_1);
}
@ -246,9 +245,8 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, const
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* Group chat invite from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
const char *msg = "* Group chat invite from %s failed: too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg, nick);
notify(prompt, error, NT_WNDALERT_1);
}
@ -351,8 +349,8 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
set_active_window(friends[f].chatwin);
} else {
char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
const char *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
notify(prompt, error, NT_WNDALERT_1);
}
@ -571,12 +569,11 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, friends[id].num);
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Audio action from: %s!", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
const char *msg = "Audio action from: %s!";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, nick);
char *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
const char *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
notify(prompt, error, NT_WNDALERT_1);
}

View File

@ -50,7 +50,7 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
if (argc != 1) {
msg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
}
@ -58,13 +58,13 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
if ((req == 0 && strcmp(argv[1], "0")) || req >= MAX_FRIENDS_NUM) {
msg = "No pending friend request with that number.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
}
if (!strlen(pending_frnd_requests[req])) {
msg = "No pending friend request with that number.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
}
@ -87,7 +87,7 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
}
num_frnd_requests = i;
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg)
@ -130,7 +130,7 @@ void cmd_add_helper(ToxWindow *self, Tox *m, char *id_bin, char *msg)
break;
}
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
}
void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -139,7 +139,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
if (argc < 1) {
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -151,7 +151,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
if (temp[0] != '\"') {
errmsg = "Message must be enclosed in quotes.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -181,7 +181,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
if (sscanf(xx, "%02x", &x) != 1) {
errmsg = "Invalid ID.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -209,7 +209,7 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
/* check arguments */
if (argc != 3) {
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -219,7 +219,7 @@ void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
if (atoi(port) == 0) {
errmsg = "Invalid syntax.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -234,7 +234,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
errmsg = " * Warning: Too many windows are open.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
return;
}
@ -242,20 +242,19 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
if (groupnum == -1) {
errmsg = "Group chat instance failed to initialize.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
if (init_groupchat_win(prompt, m, groupnum) == -1) {
errmsg = "Group chat window failed to initialize.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
tox_del_groupchat(m, groupnum);
return;
}
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Group chat created as %d.", groupnum);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
const char *msg = "Group chat created as %d.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, groupnum);
}
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -269,7 +268,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
else
msg = "Logging for this window is OFF. Type \"/log on\" to enable.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
}
@ -289,7 +288,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
}
msg = "Logging enabled";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
if (self->is_chat)
@ -298,12 +297,12 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
log_disable(log);
msg = "Logging disabled";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
}
msg = "Invalid option. Use \"/log on\" and \"/log off\" to toggle logging.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -320,7 +319,7 @@ void cmd_myid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
strcat(id, xx);
}
line_info_add(self, NULL, NULL, NULL, id, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, id);
}
void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -330,7 +329,7 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
/* check arguments */
if (argc < 1) {
errmsg = "Invalid name.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -345,7 +344,7 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
if (!valid_nick(nick)) {
errmsg = "Invalid name.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -364,7 +363,7 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
if (argc < 1) {
errmsg = "Wrong number of arguments.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -372,7 +371,7 @@ void cmd_note(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
if (msg[0] != '\"') {
errmsg = "Note must be enclosed in quotes.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -403,12 +402,12 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
if (msg[0] != '\"') {
errmsg = "Note must be enclosed in quotes.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
} else if (argc != 1) {
errmsg = "Wrong number of arguments.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}
@ -425,7 +424,7 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
status_kind = TOX_USERSTATUS_BUSY;
else {
errmsg = "Invalid status. Valid statuses are: online, busy and away.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
return;
}

View File

@ -152,7 +152,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, nick_clr);
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, nick_clr, msg);
write_to_log(msg, nick, ctx->log, false);
}
@ -181,7 +181,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
line_info_add(self, timefrmt, nick, NULL, ACTION, 0, 0, action);
write_to_log(action, nick, ctx->log, true);
}
@ -280,13 +280,13 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
switch (change) {
case TOX_CHAT_CHANGE_PEER_ADD:
event = "has joined the room";
line_info_add(self, timefrmt, (char *) peername, NULL, event, CONNECTION, 0, GREEN);
line_info_add(self, timefrmt, (char *) peername, NULL, CONNECTION, 0, GREEN, event);
write_to_log(event, (char *) peername, ctx->log, true);
break;
case TOX_CHAT_CHANGE_PEER_DEL:
event = "has left the room";
line_info_add(self, timefrmt, (char *) oldpeername, NULL, event, CONNECTION, 0, 0);
line_info_add(self, timefrmt, (char *) oldpeername, NULL, CONNECTION, 0, 0, event);
if (groupchats[self->num].side_pos > 0)
--groupchats[self->num].side_pos;
@ -296,7 +296,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
case TOX_CHAT_CHANGE_PEER_NAME:
event = " is now known as ";
line_info_add(self, timefrmt, (char *) oldpeername, (char *) peername, event, NAME_CHANGE, 0, 0);
line_info_add(self, timefrmt, (char *) oldpeername, (char *) peername, NAME_CHANGE, 0, 0, event);
char tmp_event[TOXIC_MAX_NAME_LENGTH * 2 + 32];
snprintf(tmp_event, sizeof(tmp_event), "is now known as %s", (char *) peername);
@ -316,7 +316,7 @@ static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *a
if (tox_group_action_send(m, self->num, (uint8_t *) action, strlen(action)) == -1) {
char *errmsg = " * Failed to send action.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
}
}
@ -399,7 +399,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else if (!string_is_empty(line)) {
if (tox_group_message_send(m, self->num, (uint8_t *) line, strlen(line)) == -1) {
char *errmsg = " * Failed to send message.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
}
}

View File

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include "toxic.h"
#include "windows.h"
@ -133,8 +134,8 @@ static struct line_info *line_info_ret_queue(struct history *hst)
}
/* creates new line_info line and puts it in the queue */
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, const char *msg, uint8_t type,
uint8_t bold, uint8_t colour)
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, uint8_t type, uint8_t bold,
uint8_t colour, const char *msg, ...)
{
struct history *hst = self->chatwin->hst;
struct line_info *new_line = calloc(1, sizeof(struct line_info));
@ -142,6 +143,13 @@ void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, cons
if (new_line == NULL)
exit_toxic_err("failed in line_info_add", FATALERR_MEMORY);
char frmt_msg[MAX_STR_SIZE] = {0};
va_list args;
va_start(args, msg);
vsnprintf(frmt_msg, sizeof(frmt_msg), msg, args);
va_end(args);
int len = 1; /* there will always be a newline */
/* for type-specific formatting in print function */
@ -163,14 +171,14 @@ void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, cons
break;
}
if (msg) {
snprintf(new_line->msg, sizeof(new_line->msg), "%s", msg);
if (frmt_msg[0]) {
snprintf(new_line->msg, sizeof(new_line->msg), "%s", frmt_msg);
len += strlen(new_line->msg);
int i;
for (i = 0; msg[i]; ++i) {
if (msg[i] == '\n')
for (i = 0; frmt_msg[i]; ++i) {
if (frmt_msg[i] == '\n')
++new_line->newlines;
}
}

View File

@ -68,8 +68,8 @@ struct history {
};
/* creates new line_info line and puts it in the queue */
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, const char *msg,
uint8_t type, uint8_t bold, uint8_t colour);
void line_info_add(ToxWindow *self, char *tmstmp, char *name1, char *name2, uint8_t type, uint8_t bold,
uint8_t colour, const char *msg, ...);
/* Prints a section of history starting at line_start */
void line_info_print(ToxWindow *self);

View File

@ -66,9 +66,7 @@ void init_logging_session(char *name, char *key, struct chatlog *log)
}
char log_path[MAX_STR_SIZE];
snprintf(log_path, MAX_STR_SIZE, "%s%s%s-%s.log",
user_config_dir, CONFIGDIR, name, ident);
snprintf(log_path, MAX_STR_SIZE, "%s%s%s-%s.log", user_config_dir, CONFIGDIR, name, ident);
free(user_config_dir);

View File

@ -201,7 +201,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
if (!string_is_empty(line))
add_line_to_hist(ctx);
line_info_add(self, NULL, NULL, NULL, line, PROMPT, 0, 0);
line_info_add(self, NULL, NULL, NULL, PROMPT, 0, 0, line);
execute(ctx->history, self, m, line, GLOBAL_COMMAND_MODE);
wclear(ctx->linewin);
@ -306,7 +306,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
if (status == 1) {
msg = "has come online";
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, GREEN);
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, GREEN, msg);
write_to_log(msg, nick, ctx->log, true);
#ifdef _SOUND_NOTIFY
@ -316,7 +316,7 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum
#endif /* _SOUND_NOTIFY */
} else {
msg = "has gone offline";
line_info_add(self, timefrmt, nick, NULL, msg, CONNECTION, 0, RED);
line_info_add(self, timefrmt, nick, NULL, CONNECTION, 0, RED, msg);
write_to_log(msg, nick, ctx->log, true);
#ifdef _SOUND_NOTIFY
@ -335,22 +335,21 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, const char *key, con
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
char msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Friend request with the message '%s'", data);
line_info_add(self, timefrmt, NULL, NULL, msg, SYS_MSG, 0, 0);
const char *msg = "Friend request with the message '%s'";
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, 0, msg, data);
write_to_log(msg, "", ctx->log, true);
int n = add_friend_request(key);
if (n == -1) {
char *errmsg = "Friend request queue is full. Discarding request.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, errmsg);
write_to_log(errmsg, "", ctx->log, true);
return;
}
snprintf(msg, sizeof(msg), "Type \"/accept %d\" to accept it.", n);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
msg = "Type \"/accept %d\" to accept it.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg, n);
notify(self, generic_message, NT_WNDALERT_1 | NT_NOTIFWND);
}
@ -398,18 +397,18 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
static void print_welcome_msg(ToxWindow *self)
{
line_info_add(self, NULL, NULL, NULL, " _____ _____ _____ ____ ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " |_ _/ _ \\ \\/ /_ _/ ___|", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " | || | | \\ / | | | ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " | || |_| / \\ | | |___ ", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, " |_| \\___/_/\\_\\___\\____|", SYS_MSG, 1, BLUE);
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, " _____ _____ _____ ____ ");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, " |_ _/ _ \\ \\/ /_ _/ ___|");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, " | || | | \\ / | | | ");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, " | || |_| / \\ | | |___ ");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, " |_| \\___/_/\\_\\___\\____|");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
char *msg = "Welcome to Toxic, a free, open source Tox-based instant messenging client.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, CYAN, msg);
msg = "Type \"/help\" for assistance. Further help may be found via the man page.";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
line_info_add(self, NULL, NULL, NULL, "", SYS_MSG, 0, 0);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, CYAN, msg);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
}
static void prompt_onInit(ToxWindow *self, Tox *m)

View File

@ -361,7 +361,7 @@ static void do_connection(Tox *m, ToxWindow *prompt)
}
if (msg[0])
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
static void load_friendlist(Tox *m)
@ -630,7 +630,7 @@ int main(int argc, char *argv[])
set_primary_device(output, user_settings_->audio_out_dev);
#elif _SOUND_NOTIFY
if ( init_devices() == de_InternalError )
line_info_add(prompt, NULL, NULL, NULL, "Failed to init devices", SYS_MSG, 0, 0);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to init devices");
#endif /* _AUDIO */
@ -644,12 +644,12 @@ int main(int argc, char *argv[])
if (config_err) {
msg = "Unable to determine configuration directory. Defaulting to 'data' for a keyfile...";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
if (settings_err == -1) {
msg = "Failed to load user settings";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
}
sort_friendlist_index();