1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Usage of const

This commit is contained in:
James Booth 2012-03-09 01:06:55 +00:00
parent ea3a09ac26
commit f533c6c162
14 changed files with 94 additions and 84 deletions

View File

@ -30,15 +30,15 @@
#include "windows.h"
#include "util.h"
static int _handle_command(char *command, char *inp);
static int _handle_command(const char * const command, const char * const inp);
static int _cmd_quit(void);
static int _cmd_help(void);
static int _cmd_who(void);
static int _cmd_ros(void);
static int _cmd_connect(char *inp);
static int _cmd_msg(char *inp);
static int _cmd_close(char *inp);
static int _cmd_default(char *inp);
static int _cmd_connect(const char * const inp);
static int _cmd_msg(const char * const inp);
static int _cmd_close(const char * const inp);
static int _cmd_default(const char * const inp);
int process_input(char *inp)
{
@ -64,7 +64,7 @@ int process_input(char *inp)
return result;
}
static int _handle_command(char *command, char *inp)
static int _handle_command(const char * const command, const char * const inp)
{
int result = FALSE;
@ -89,7 +89,7 @@ static int _handle_command(char *command, char *inp)
return result;
}
static int _cmd_connect(char *inp)
static int _cmd_connect(const char * const inp)
{
int result = FALSE;
jabber_status_t conn_status = jabber_connection_status();
@ -160,7 +160,7 @@ static int _cmd_who(void)
return TRUE;
}
static int _cmd_msg(char *inp)
static int _cmd_msg(const char * const inp)
{
char *usr = NULL;
char *msg = NULL;
@ -178,6 +178,7 @@ static int _cmd_msg(char *inp)
strtok(inp_cpy, " ");
usr = strtok(NULL, " ");
if ((usr != NULL) && (strlen(inp) > (5 + strlen(usr) + 1))) {
// get message
msg = strndup(inp+5+strlen(usr)+1, strlen(inp)-(5+strlen(usr)+1));
if (msg != NULL) {
jabber_send(msg, usr);
@ -193,7 +194,7 @@ static int _cmd_msg(char *inp)
return TRUE;
}
static int _cmd_close(char *inp)
static int _cmd_close(const char * const inp)
{
if (!win_close_win())
cons_bad_command(inp);
@ -201,7 +202,7 @@ static int _cmd_close(char *inp)
return TRUE;
}
static int _cmd_default(char *inp)
static int _cmd_default(const char * const inp)
{
if (win_in_chat()) {
char *recipient = win_get_recipient();

View File

@ -20,7 +20,6 @@
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -35,7 +34,7 @@ struct _contact_t {
// the contact list
static struct _contact_t *_contact_list = NULL;
static struct _contact_t * _make_contact(char *contact);
static struct _contact_t * _make_contact(const char * const contact);
void contact_list_clear(void)
{
@ -52,7 +51,7 @@ void contact_list_clear(void)
}
}
int contact_list_remove(char *contact)
int contact_list_remove(const char * const contact)
{
if (!_contact_list) {
return 0;
@ -81,7 +80,7 @@ int contact_list_remove(char *contact)
}
}
int contact_list_add(char *contact)
int contact_list_add(const char * const contact)
{
if (!_contact_list) {
_contact_list = _make_contact(contact);
@ -136,7 +135,7 @@ struct contact_list *get_contact_list(void)
return list;
}
static struct _contact_t * _make_contact(char *contact)
static struct _contact_t * _make_contact(const char * const contact)
{
struct _contact_t *new = (struct _contact_t *) malloc(sizeof(struct _contact_t));
new->contact = (char *) malloc((strlen(contact) + 1) * sizeof(char));

View File

@ -29,8 +29,8 @@ struct contact_list {
};
void contact_list_clear(void);
int contact_list_add(char *contact);
int contact_list_remove(char *contact);
int contact_list_add(const char * const contact);
int contact_list_remove(const char * const contact);
struct contact_list *get_contact_list(void);
#endif

View File

@ -39,7 +39,8 @@ void history_init(void)
_pos = -1;
}
void history_append(char *inp)
// FIXME: Roll history when full
void history_append(const char * const inp)
{
if (_size < MAX_HISTORY) {
_history[_size] = (char*) malloc(strlen(inp) * sizeof(char));

View File

@ -25,7 +25,7 @@
#define HISTORY_H
void history_init(void);
void history_append(char *inp);
void history_append(const char * const inp);
char *history_previous(void);
char *history_next(void);

View File

@ -43,9 +43,9 @@
static WINDOW *inp_win;
static int _handle_edit(int ch, char *input, int *size);
static int _printable(int ch);
static void _replace_input(char *input, char *new_input, int *size);
static int _handle_edit(const int ch, char *input, int *size);
static int _printable(const int ch);
static void _replace_input(char *input, const char * const new_input, int *size);
void create_input_window(void)
{
@ -133,7 +133,7 @@ void inp_put_back(void)
* key press: up, down, left, right or backspace
* return 0 if it wasnt
*/
static int _handle_edit(int ch, char *input, int *size)
static int _handle_edit(const int ch, char *input, int *size)
{
int i;
char *prev = NULL;
@ -196,7 +196,7 @@ static int _handle_edit(int ch, char *input, int *size)
}
}
static int _printable(int ch)
static int _printable(const int ch)
{
return (ch != ERR && ch != '\n' && ch != KEY_PPAGE && ch != KEY_NPAGE &&
ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) &&
@ -205,7 +205,7 @@ static int _printable(int ch)
ch != KEY_F(10));
}
static void _replace_input(char *input, char *new_input, int *size)
static void _replace_input(char *input, const char * const new_input, int *size)
{
int i;

View File

@ -65,15 +65,15 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
static int _jabber_message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata);
static int _roster_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _jabber_presence_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata);
void jabber_init(int disable_tls)
void jabber_init(const int disable_tls)
{
jabber_conn.conn_status = JABBER_STARTED;
jabber_conn.tls_disabled = disable_tls;
@ -84,7 +84,7 @@ jabber_status_t jabber_connection_status(void)
return (jabber_conn.conn_status);
}
jabber_status_t jabber_connect(char *user, char *passwd)
jabber_status_t jabber_connect(const char * const user, const char * const passwd)
{
xmpp_initialize();
@ -126,7 +126,7 @@ void jabber_process_events(void)
xmpp_run_once(jabber_conn.ctx, 10);
}
void jabber_send(char *msg, char *recipient)
void jabber_send(const char * const msg, const char * const recipient)
{
xmpp_stanza_t *reply, *body, *text;
@ -224,8 +224,8 @@ static void _jabber_conn_handler(xmpp_conn_t * const conn,
}
}
static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
static int _roster_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
xmpp_stanza_t *query, *item;
char *type, *name, *jid;

View File

@ -30,12 +30,12 @@ typedef enum {
JABBER_DISCONNECTED
} jabber_status_t;
void jabber_init(int disable_tls);
void jabber_init(const int disable_tls);
jabber_status_t jabber_connection_status(void);
jabber_status_t jabber_connect(char *user, char *passwd);
jabber_status_t jabber_connect(const char * const user, const char * const passwd);
void jabber_disconnect(void);
void jabber_roster_request(void);
void jabber_process_events(void);
void jabber_send(char *msg, char *recipient);
void jabber_send(const char * const msg, const char * const recipient);
#endif

View File

@ -58,7 +58,7 @@ void profanity_run(void)
}
void profanity_init(int disable_tls)
void profanity_init(const int disable_tls)
{
log_init();
gui_init();

View File

@ -23,7 +23,7 @@
#ifndef PROFANITY_H
#define PROFANITY_H
void profanity_init(int disable_tls);
void profanity_init(const int disable_tls);
void profanity_run(void);
void profanity_shutdown(void);

View File

@ -67,7 +67,7 @@ void status_bar_refresh(void)
}
}
void status_bar_inactive(int win)
void status_bar_inactive(const int win)
{
int active_pos = 1 + ((win -1) * 3);
@ -81,7 +81,7 @@ void status_bar_inactive(int win)
dirty = TRUE;
}
void status_bar_active(int win)
void status_bar_active(const int win)
{
int active_pos = 1 + ((win -1) * 3);
@ -103,7 +103,7 @@ void status_bar_get_password(void)
dirty = TRUE;
}
void status_bar_print_message(const char *msg)
void status_bar_print_message(const char * const msg)
{
mvwprintw(status_bar, 0, 9, msg);

View File

@ -38,7 +38,7 @@ void create_title_bar(void)
dirty = TRUE;
}
void title_bar_title()
void title_bar_title(void)
{
char *title = "Profanity. Type /help for help information.";
title_bar_show(title);
@ -90,7 +90,7 @@ void title_bar_refresh(void)
}
}
void title_bar_show(char *title)
void title_bar_show(const char * const title)
{
wmove(title_bar, 0, 0);
int i;

View File

@ -43,16 +43,18 @@ static WINDOW * _cons_win = NULL;
static int dirty;
static void _create_windows(void);
static int _find_prof_win_index(char *contact);
static int _new_prof_win(char *contact);
static void _current_window_refresh();
static void _win_switch_if_active(int i);
static int _find_prof_win_index(const char * const contact);
static int _new_prof_win(const char * const contact);
static void _current_window_refresh(void);
static void _win_switch_if_active(const int i);
static void _win_show_time(WINDOW *win);
static void _win_show_user(WINDOW *win, char *user, int colour);
static void _win_show_message(WINDOW *win, char *message);
static void _show_status_string(WINDOW *win, char *from, char *show, char *status,
char *pre, char *default_show);
static void _cons_show_incoming_message(char *short_from, int win_index);
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
static void _win_show_message(WINDOW *win, const char * const message);
static void _show_status_string(WINDOW *win, const char * const from,
const char * const show, const char * const status, const char * const pre,
const char * const default_show);
static void _cons_show_incoming_message(const char * const short_from,
const int win_index);
void gui_init(void)
{
@ -139,7 +141,7 @@ char *win_get_recipient(void)
return recipient;
}
void win_show_incomming_msg(char *from, char *message)
void win_show_incomming_msg(const char * const from, const char * const message)
{
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
@ -161,7 +163,8 @@ void win_show_incomming_msg(char *from, char *message)
dirty = TRUE;
}
void win_show_outgoing_msg(char *from, char *to, char *message)
void win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message)
{
int win_index = _find_prof_win_index(to);
if (win_index == NUM_WINS)
@ -178,7 +181,8 @@ void win_show_outgoing_msg(char *from, char *to, char *message)
dirty = TRUE;
}
void win_contact_online(char *from, char *show, char *status)
void win_contact_online(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(_cons_win, from, show, status, "++", "online");
@ -192,7 +196,8 @@ void win_contact_online(char *from, char *show, char *status)
dirty = TRUE;
}
void win_contact_offline(char *from, char *show, char *status)
void win_contact_offline(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(_cons_win, from, show, status, "--", "offline");
@ -228,7 +233,7 @@ void cons_help(void)
dirty = TRUE;
}
void cons_show_online_contacts(struct contact_list *list)
void cons_show_online_contacts(const struct contact_list * const list)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "Online contacts:\n");
@ -244,7 +249,7 @@ void cons_show_online_contacts(struct contact_list *list)
}
void cons_bad_show(char *msg)
void cons_bad_show(const char * const msg)
{
_win_show_time(_cons_win);
wattron(_cons_win, COLOR_PAIR(6));
@ -255,7 +260,7 @@ void cons_bad_show(char *msg)
dirty = TRUE;
}
void cons_show(char *msg)
void cons_show(const char * const msg)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "%s\n", msg);
@ -264,7 +269,7 @@ void cons_show(char *msg)
dirty = TRUE;
}
void cons_bad_command(char *cmd)
void cons_bad_command(const char * const cmd)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "Unknown command: %s\n", cmd);
@ -293,7 +298,7 @@ void cons_bad_message(void)
cons_show("Usage: /msg user@host message");
}
void win_handle_switch(int *ch)
void win_handle_switch(const int * const ch)
{
if (*ch == KEY_F(1)) {
_win_switch_if_active(0);
@ -336,7 +341,7 @@ void win_page_off(void)
dirty = TRUE;
}
void win_handle_page(int *ch)
void win_handle_page(const int * const ch)
{
int rows, cols, y, x;
getmaxyx(stdscr, rows, cols);
@ -410,7 +415,7 @@ static void _create_windows(void)
}
}
static int _find_prof_win_index(char *contact)
static int _find_prof_win_index(const char * const contact)
{
// find the chat window for recipient
int i;
@ -421,7 +426,7 @@ static int _find_prof_win_index(char *contact)
return i;
}
static int _new_prof_win(char *contact)
static int _new_prof_win(const char * const contact)
{
int i;
// find the first unused one
@ -435,7 +440,7 @@ static int _new_prof_win(char *contact)
return i;
}
static void _win_switch_if_active(int i)
static void _win_switch_if_active(const int i)
{
win_page_off();
if (strcmp(_wins[i].from, "") != 0) {
@ -458,7 +463,7 @@ static void _win_show_time(WINDOW *win)
wprintw(win, "%s - ", tstmp);
}
static void _win_show_user(WINDOW *win, char *user, int colour)
static void _win_show_user(WINDOW *win, const char * const user, const int colour)
{
if (colour)
wattron(win, COLOR_PAIR(2));
@ -467,7 +472,7 @@ static void _win_show_user(WINDOW *win, char *user, int colour)
wattroff(win, COLOR_PAIR(2));
}
static void _win_show_message(WINDOW *win, char *message)
static void _win_show_message(WINDOW *win, const char * const message)
{
wattroff(win, A_BOLD);
wprintw(win, "%s\n", message);
@ -483,8 +488,9 @@ static void _current_window_refresh()
prefresh(current, _wins[_curr_prof_win].y_pos, 0, 1, 0, rows-3, cols-1);
}
static void _show_status_string(WINDOW *win, char *from, char *show, char *status,
char *pre, char *default_show)
static void _show_status_string(WINDOW *win, const char * const from,
const char * const show, const char * const status, const char * const pre,
const char * const default_show)
{
_win_show_time(win);
if (strcmp(default_show, "online") == 0) {
@ -515,7 +521,7 @@ static void _show_status_string(WINDOW *win, char *from, char *show, char *statu
}
static void _cons_show_incoming_message(char *short_from, int win_index)
static void _cons_show_incoming_message(const char * const short_from, const int win_index)
{
_win_show_time(_cons_win);
wattron(_cons_win, COLOR_PAIR(8));

View File

@ -45,7 +45,7 @@ void create_input_window(void);
// title bar actions
void title_bar_refresh(void);
void title_bar_show(char *title);
void title_bar_show(const char * const title);
void title_bar_title(void);
void title_bar_connected(void);
void title_bar_disconnected(void);
@ -54,33 +54,36 @@ void title_bar_disconnected(void);
int win_close_win(void);
int win_in_chat(void);
char *win_get_recipient(void);
void win_show_incomming_msg(char *from, char *message);
void win_show_outgoing_msg(char *from, char *to, char *message);
void win_handle_switch(int *ch);
void win_handle_page(int *ch);
void win_show_incomming_msg(const char * const from, const char * const message);
void win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message);
void win_handle_switch(const int * const ch);
void win_handle_page(const int * const ch);
void win_page_off(void);
void win_contact_online(char *from, char *show, char *status);
void win_contact_offline(char *from, char *show, char *status);
void win_contact_online(const char * const from, const char * const show,
const char * const status);
void win_contact_offline(const char * const from, const char * const show,
const char * const status);
// console window actions
void cons_help(void);
void cons_bad_command(char *cmd);
void cons_bad_command(const char * const cmd);
void cons_bad_connect(void);
void cons_not_disconnected(void);
void cons_not_connected(void);
void cons_bad_message(void);
void cons_show(char *cmd);
void cons_bad_show(char *cmd);
void cons_highlight_show(char *cmd);
void cons_show_online_contacts(struct contact_list *list);
void cons_show(const char * const cmd);
void cons_bad_show(const char * const cmd);
void cons_highlight_show(const char * const cmd);
void cons_show_online_contacts(const struct contact_list * const list);
// status bar actions
void status_bar_refresh(void);
void status_bar_clear(void);
void status_bar_get_password(void);
void status_bar_print_message(const char *msg);
void status_bar_inactive(int win);
void status_bar_active(int win);
void status_bar_print_message(const char * const msg);
void status_bar_inactive(const int win);
void status_bar_active(const int win);
void status_bar_update_time(void);
// input window actions