1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Naming of statics

This commit is contained in:
James Booth 2012-02-12 22:09:07 +00:00
parent b71f61d400
commit 7aa1d931a0
6 changed files with 164 additions and 150 deletions

View File

@ -4,12 +4,12 @@
#include "jabber.h" #include "jabber.h"
#include "windows.h" #include "windows.h"
static int cmd_quit(void); static int _cmd_quit(void);
static int cmd_help(void); static int _cmd_help(void);
static int cmd_who(void); static int _cmd_who(void);
static int cmd_msg(char *cmd); static int _cmd_msg(char *cmd);
static int cmd_close(char *cmd); static int _cmd_close(char *cmd);
static int cmd_default(char *cmd); static int _cmd_default(char *cmd);
int handle_start_command(char *cmd) int handle_start_command(char *cmd)
{ {
@ -18,7 +18,7 @@ int handle_start_command(char *cmd)
if (strcmp(cmd, "/quit") == 0) { if (strcmp(cmd, "/quit") == 0) {
result = QUIT_PROF; result = QUIT_PROF;
} else if (strncmp(cmd, "/help", 5) == 0) { } else if (strncmp(cmd, "/help", 5) == 0) {
cons_help(); win_cons_help();
result = AWAIT_COMMAND; result = AWAIT_COMMAND;
} else if (strncmp(cmd, "/connect ", 9) == 0) { } else if (strncmp(cmd, "/connect ", 9) == 0) {
char *user; char *user;
@ -32,7 +32,7 @@ int handle_start_command(char *cmd)
jabber_connect(user, passwd); jabber_connect(user, passwd);
result = START_MAIN; result = START_MAIN;
} else { } else {
cons_bad_command(cmd); win_cons_bad_command(cmd);
result = AWAIT_COMMAND; result = AWAIT_COMMAND;
} }
@ -45,17 +45,17 @@ int handle_command(char *cmd)
{ {
int result = FALSE; int result = FALSE;
if (strcmp(cmd, "/quit") == 0) { if (strcmp(cmd, "/quit") == 0) {
result = cmd_quit(); result = _cmd_quit();
} else if (strncmp(cmd, "/help", 5) == 0) { } else if (strncmp(cmd, "/help", 5) == 0) {
result = cmd_help(); result = _cmd_help();
} else if (strncmp(cmd, "/who", 4) == 0) { } else if (strncmp(cmd, "/who", 4) == 0) {
result = cmd_who(); result = _cmd_who();
} else if (strncmp(cmd, "/msg ", 5) == 0) { } else if (strncmp(cmd, "/msg ", 5) == 0) {
result = cmd_msg(cmd); result = _cmd_msg(cmd);
} else if (strncmp(cmd, "/close", 6) == 0) { } else if (strncmp(cmd, "/close", 6) == 0) {
result = cmd_close(cmd); result = _cmd_close(cmd);
} else { } else {
result = cmd_default(cmd); result = _cmd_default(cmd);
} }
inp_clear(); inp_clear();
@ -64,26 +64,26 @@ int handle_command(char *cmd)
} }
static int cmd_quit(void) static int _cmd_quit(void)
{ {
return FALSE; return FALSE;
} }
static int cmd_help(void) static int _cmd_help(void)
{ {
cons_help(); win_cons_help();
return TRUE; return TRUE;
} }
static int cmd_who(void) static int _cmd_who(void)
{ {
jabber_roster_request(); jabber_roster_request();
return TRUE; return TRUE;
} }
static int cmd_msg(char *cmd) static int _cmd_msg(char *cmd)
{ {
char *usr_msg = NULL; char *usr_msg = NULL;
char *usr = NULL; char *usr = NULL;
@ -95,33 +95,33 @@ static int cmd_msg(char *cmd)
msg = strndup(cmd+5+strlen(usr)+1, strlen(cmd)-(5+strlen(usr)+1)); msg = strndup(cmd+5+strlen(usr)+1, strlen(cmd)-(5+strlen(usr)+1));
if (msg != NULL) { if (msg != NULL) {
jabber_send(msg, usr); jabber_send(msg, usr);
show_outgoing_msg("me", usr, msg); win_show_outgoing_msg("me", usr, msg);
} }
} }
return TRUE; return TRUE;
} }
static int cmd_close(char *cmd) static int _cmd_close(char *cmd)
{ {
if (in_chat()) { if (win_in_chat()) {
close_win(); win_close_win();
} else { } else {
cons_bad_command(cmd); win_cons_bad_command(cmd);
} }
return TRUE; return TRUE;
} }
static int cmd_default(char *cmd) static int _cmd_default(char *cmd)
{ {
if (in_chat()) { if (win_in_chat()) {
char recipient[100] = ""; char recipient[100] = "";
get_recipient(recipient); win_get_recipient(recipient);
jabber_send(cmd, recipient); jabber_send(cmd, recipient);
show_outgoing_msg("me", recipient, cmd); win_show_outgoing_msg("me", recipient, cmd);
} else { } else {
cons_bad_command(cmd); win_cons_bad_command(cmd);
} }
return TRUE; return TRUE;

View File

@ -101,7 +101,7 @@ static int _jabber_message_handler(xmpp_conn_t * const conn,
message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
char *from = xmpp_stanza_get_attribute(stanza, "from"); char *from = xmpp_stanza_get_attribute(stanza, "from");
show_incomming_msg(from, message); win_show_incomming_msg(from, message);
return 1; return 1;
} }
@ -141,19 +141,19 @@ static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
log_msg(CONN, "ERROR: query failed"); log_msg(CONN, "ERROR: query failed");
else { else {
query = xmpp_stanza_get_child_by_name(stanza, "query"); query = xmpp_stanza_get_child_by_name(stanza, "query");
cons_show("Roster:"); win_cons_show("Roster:");
for (item = xmpp_stanza_get_children(query); item; for (item = xmpp_stanza_get_children(query); item;
item = xmpp_stanza_get_next(item)) { item = xmpp_stanza_get_next(item)) {
if ((name = xmpp_stanza_get_attribute(item, "name"))) { if ((name = xmpp_stanza_get_attribute(item, "name"))) {
char line[200]; char line[200];
sprintf(line, " %s (%s)", name, sprintf(line, " %s (%s)", name,
xmpp_stanza_get_attribute(item, "jid")); xmpp_stanza_get_attribute(item, "jid"));
cons_show(line); win_cons_show(line);
} else { } else {
char line[200]; char line[200];
sprintf(line, " %s", sprintf(line, " %s",
xmpp_stanza_get_attribute(item, "jid")); xmpp_stanza_get_attribute(item, "jid"));
cons_show(line); win_cons_show(line);
} }
} }
} }

View File

@ -9,8 +9,8 @@
#include "jabber.h" #include "jabber.h"
#include "command.h" #include "command.h"
static void profanity_main(void); static void _profanity_main(void);
static void profanity_event_loop(int *ch, char *cmd, int *size); static void _profanity_event_loop(int *ch, char *cmd, int *size);
void profanity_start(void) void profanity_start(void)
{ {
@ -23,11 +23,11 @@ void profanity_start(void)
} }
if (cmd_result == START_MAIN) { if (cmd_result == START_MAIN) {
profanity_main(); _profanity_main();
} }
} }
static void profanity_main(void) static void _profanity_main(void)
{ {
int cmd_result = TRUE; int cmd_result = TRUE;
@ -38,7 +38,7 @@ static void profanity_main(void)
int size = 0; int size = 0;
while(ch != '\n') while(ch != '\n')
profanity_event_loop(&ch, cmd, &size); _profanity_event_loop(&ch, cmd, &size);
cmd[size++] = '\0'; cmd[size++] = '\0';
cmd_result = handle_command(cmd); cmd_result = handle_command(cmd);
@ -47,7 +47,7 @@ static void profanity_main(void)
jabber_disconnect(); jabber_disconnect();
} }
static void profanity_event_loop(int *ch, char *cmd, int *size) static void _profanity_event_loop(int *ch, char *cmd, int *size)
{ {
usleep(1); usleep(1);
@ -58,35 +58,35 @@ static void profanity_event_loop(int *ch, char *cmd, int *size)
// determine if they changed windows // determine if they changed windows
if (*ch == KEY_F(1)) { if (*ch == KEY_F(1)) {
if (is_active(0)) if (win_is_active(0))
switch_to(0); win_switch_to(0);
} else if (*ch == KEY_F(2)) { } else if (*ch == KEY_F(2)) {
if (is_active(1)) if (win_is_active(1))
switch_to(1); win_switch_to(1);
} else if (*ch == KEY_F(3)) { } else if (*ch == KEY_F(3)) {
if (is_active(2)) if (win_is_active(2))
switch_to(2); win_switch_to(2);
} else if (*ch == KEY_F(4)) { } else if (*ch == KEY_F(4)) {
if (is_active(3)) if (win_is_active(3))
switch_to(3); win_switch_to(3);
} else if (*ch == KEY_F(5)) { } else if (*ch == KEY_F(5)) {
if (is_active(4)) if (win_is_active(4))
switch_to(4); win_switch_to(4);
} else if (*ch == KEY_F(6)) { } else if (*ch == KEY_F(6)) {
if (is_active(5)) if (win_is_active(5))
switch_to(5); win_switch_to(5);
} else if (*ch == KEY_F(7)) { } else if (*ch == KEY_F(7)) {
if (is_active(6)) if (win_is_active(6))
switch_to(6); win_switch_to(6);
} else if (*ch == KEY_F(8)) { } else if (*ch == KEY_F(8)) {
if (is_active(7)) if (win_is_active(7))
switch_to(7); win_switch_to(7);
} else if (*ch == KEY_F(9)) { } else if (*ch == KEY_F(9)) {
if (is_active(8)) if (win_is_active(8))
switch_to(8); win_switch_to(8);
} else if (*ch == KEY_F(10)) { } else if (*ch == KEY_F(10)) {
if (is_active(9)) if (win_is_active(9))
switch_to(9); win_switch_to(9);
} }
// get another character from the command box // get another character from the command box

View File

@ -12,10 +12,10 @@ void create_title_bar(void)
title_bar = newwin(1, cols, 0, 0); title_bar = newwin(1, cols, 0, 0);
wbkgd(title_bar, COLOR_PAIR(3)); wbkgd(title_bar, COLOR_PAIR(3));
title_bar_show(title); win_title_bar_show(title);
} }
void title_bar_show(char *title) void win_title_bar_show(char *title)
{ {
wclear(title_bar); wclear(title_bar);
mvwprintw(title_bar, 0, 0, " %s", title); mvwprintw(title_bar, 0, 0, " %s", title);

162
windows.c
View File

@ -3,10 +3,10 @@
#include "windows.h" #include "windows.h"
#include "util.h" #include "util.h"
static struct prof_win wins[10]; static struct prof_win _wins[10];
static int curr_win = 0; static int _curr_win = 0;
static void create_windows(void); static void _create_windows(void);
void gui_init(void) void gui_init(void)
{ {
@ -31,7 +31,7 @@ void gui_init(void)
create_input_bar(); create_input_bar();
create_input_window(); create_input_window();
create_windows(); _create_windows();
} }
void gui_close(void) void gui_close(void)
@ -39,54 +39,54 @@ void gui_close(void)
endwin(); endwin();
} }
int is_active(int i) int win_is_active(int i)
{ {
if (strcmp(wins[i].from, "") == 0) if (strcmp(_wins[i].from, "") == 0)
return FALSE; return FALSE;
else else
return TRUE; return TRUE;
} }
void switch_to(int i) void win_switch_to(int i)
{ {
touchwin(wins[i].win); touchwin(_wins[i].win);
wrefresh(wins[i].win); wrefresh(_wins[i].win);
curr_win = i; _curr_win = i;
if (i == 0) { if (i == 0) {
title_bar_show("Console, type /help for help information"); win_title_bar_show("Console, type /help for help information");
} else { } else {
title_bar_show(wins[i].from); win_title_bar_show(_wins[i].from);
} }
} }
void close_win(void) void win_close_win(void)
{ {
// reset the chat win to unused // reset the chat win to unused
strcpy(wins[curr_win].from, ""); strcpy(_wins[_curr_win].from, "");
wclear(wins[curr_win].win); wclear(_wins[_curr_win].win);
// set it as inactive in the status bar // set it as inactive in the status bar
inp_bar_inactive(curr_win); inp_bar_inactive(_curr_win);
// go back to console window // go back to console window
touchwin(wins[0].win); touchwin(_wins[0].win);
wrefresh(wins[0].win); wrefresh(_wins[0].win);
title_bar_show("Console, type /help for help information"); win_title_bar_show("Console, type /help for help information");
} }
int in_chat(void) int win_in_chat(void)
{ {
return ((curr_win != 0) && (strcmp(wins[curr_win].from, "") != 0)); return ((_curr_win != 0) && (strcmp(_wins[_curr_win].from, "") != 0));
} }
void get_recipient(char *recipient) void win_get_recipient(char *recipient)
{ {
strcpy(recipient, wins[curr_win].from); strcpy(recipient, _wins[_curr_win].from);
} }
void show_incomming_msg(char *from, char *message) void win_show_incomming_msg(char *from, char *message)
{ {
char from_cpy[100]; char from_cpy[100];
strcpy(from_cpy, from); strcpy(from_cpy, from);
@ -101,47 +101,47 @@ void show_incomming_msg(char *from, char *message)
// find the chat window for sender // find the chat window for sender
int i; int i;
for (i = 1; i < 10; i++) for (i = 1; i < 10; i++)
if (strcmp(wins[i].from, short_from) == 0) if (strcmp(_wins[i].from, short_from) == 0)
break; break;
// if we didn't find a window // if we didn't find a window
if (i == 10) { if (i == 10) {
// find the first unused one // find the first unused one
for (i = 1; i < 10; i++) for (i = 1; i < 10; i++)
if (strcmp(wins[i].from, "") == 0) if (strcmp(_wins[i].from, "") == 0)
break; break;
// set it up and print the message to it // set it up and print the message to it
strcpy(wins[i].from, short_from); strcpy(_wins[i].from, short_from);
wclear(wins[i].win); wclear(_wins[i].win);
wprintw(wins[i].win, line); wprintw(_wins[i].win, line);
// signify active window in status bar // signify active window in status bar
inp_bar_active(i); inp_bar_active(i);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == i) { if (_curr_win == i) {
touchwin(wins[i].win); touchwin(_wins[i].win);
wrefresh(wins[i].win); wrefresh(_wins[i].win);
} }
} }
// otherwise // otherwise
else { else {
// add the line to the senders window // add the line to the senders window
wprintw(wins[i].win, line); wprintw(_wins[i].win, line);
// signify active window in status bar // signify active window in status bar
inp_bar_active(i); inp_bar_active(i);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == i) { if (_curr_win == i) {
touchwin(wins[i].win); touchwin(_wins[i].win);
wrefresh(wins[i].win); wrefresh(_wins[i].win);
} }
} }
} }
void show_outgoing_msg(char *from, char *to, char *message) void win_show_outgoing_msg(char *from, char *to, char *message)
{ {
char line[100]; char line[100];
char tstmp[80]; char tstmp[80];
@ -151,98 +151,108 @@ void show_outgoing_msg(char *from, char *to, char *message)
// find the chat window for recipient // find the chat window for recipient
int i; int i;
for (i = 1; i < 10; i++) for (i = 1; i < 10; i++)
if (strcmp(wins[i].from, to) == 0) if (strcmp(_wins[i].from, to) == 0)
break; break;
// if we didn't find a window // if we didn't find a window
if (i == 10) { if (i == 10) {
// find the first unused one // find the first unused one
for (i = 1; i < 10; i++) for (i = 1; i < 10; i++)
if (strcmp(wins[i].from, "") == 0) if (strcmp(_wins[i].from, "") == 0)
break; break;
// set it up and print the message to it // set it up and print the message to it
strcpy(wins[i].from, to); strcpy(_wins[i].from, to);
wclear(wins[i].win); wclear(_wins[i].win);
wprintw(wins[i].win, line); wprintw(_wins[i].win, line);
// signify active window in status bar // signify active window in status bar
inp_bar_active(i); inp_bar_active(i);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == i) { if (_curr_win == i) {
touchwin(wins[i].win); touchwin(_wins[i].win);
wrefresh(wins[i].win); wrefresh(_wins[i].win);
} }
} }
// otherwise // otherwise
else { else {
// add the line to the senders window // add the line to the senders window
wprintw(wins[i].win, line); wprintw(_wins[i].win, line);
// signify active window in status bar // signify active window in status bar
inp_bar_active(i); inp_bar_active(i);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == i) { if (_curr_win == i) {
touchwin(wins[i].win); touchwin(_wins[i].win);
wrefresh(wins[i].win); wrefresh(_wins[i].win);
} }
} }
} }
void cons_help(void) void win_cons_help(void)
{ {
char tstmp[80]; char tstmp[80];
get_time(tstmp); get_time(tstmp);
wprintw(wins[0].win, " [%s] Help:\n", tstmp); wprintw(_wins[0].win,
wprintw(wins[0].win, " [%s] Commands:\n", tstmp); " [%s] Help:\n", tstmp);
wprintw(wins[0].win, " [%s] /help : This help.\n", tstmp); wprintw(_wins[0].win,
wprintw(wins[0].win, " [%s] /connect <username@host> : Login to jabber.\n", tstmp); " [%s] Commands:\n", tstmp);
wprintw(wins[0].win, " [%s] /who : Get roster.\n", tstmp); wprintw(_wins[0].win,
wprintw(wins[0].win, " [%s] /close : Close a chat window.\n", tstmp); " [%s] /help : This help.\n", tstmp);
wprintw(wins[0].win, " [%s] /quit : Quits Profanity.\n", tstmp); wprintw(_wins[0].win,
wprintw(wins[0].win, " [%s] Shortcuts:\n", tstmp); " [%s] /connect <username@host> : Login to jabber.\n", tstmp);
wprintw(wins[0].win, " [%s] F1 : Console window.\n", tstmp); wprintw(_wins[0].win,
wprintw(wins[0].win, " [%s] F2-10 : Chat windows.\n", tstmp); " [%s] /who : Get roster.\n", tstmp);
wprintw(_wins[0].win,
" [%s] /close : Close a chat window.\n", tstmp);
wprintw(_wins[0].win,
" [%s] /quit : Quits Profanity.\n", tstmp);
wprintw(_wins[0].win,
" [%s] Shortcuts:\n", tstmp);
wprintw(_wins[0].win,
" [%s] F1 : Console window.\n", tstmp);
wprintw(_wins[0].win,
" [%s] F2-10 : Chat windows.\n", tstmp);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == 0) { if (_curr_win == 0) {
touchwin(wins[0].win); touchwin(_wins[0].win);
wrefresh(wins[0].win); wrefresh(_wins[0].win);
} }
} }
void cons_show(char *msg) void win_cons_show(char *msg)
{ {
char tstmp[80]; char tstmp[80];
get_time(tstmp); get_time(tstmp);
wprintw(wins[0].win, " [%s] %s\n", tstmp, msg); wprintw(_wins[0].win, " [%s] %s\n", tstmp, msg);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == 0) { if (_curr_win == 0) {
touchwin(wins[0].win); touchwin(_wins[0].win);
wrefresh(wins[0].win); wrefresh(_wins[0].win);
} }
} }
void cons_bad_command(char *cmd) void win_cons_bad_command(char *cmd)
{ {
char tstmp[80]; char tstmp[80];
get_time(tstmp); get_time(tstmp);
wprintw(wins[0].win, " [%s] Unknown command: %s\n", tstmp, cmd); wprintw(_wins[0].win, " [%s] Unknown command: %s\n", tstmp, cmd);
// if its the current window, draw it // if its the current window, draw it
if (curr_win == 0) { if (_curr_win == 0) {
touchwin(wins[0].win); touchwin(_wins[0].win);
wrefresh(wins[0].win); wrefresh(_wins[0].win);
} }
} }
static void create_windows(void) static void _create_windows(void)
{ {
int rows, cols; int rows, cols;
getmaxyx(stdscr, rows, cols); getmaxyx(stdscr, rows, cols);
@ -259,7 +269,7 @@ static void create_windows(void)
wprintw(cons.win, " [%s] Welcome to Profanity.\n", tstmp); wprintw(cons.win, " [%s] Welcome to Profanity.\n", tstmp);
touchwin(cons.win); touchwin(cons.win);
wrefresh(cons.win); wrefresh(cons.win);
wins[0] = cons; _wins[0] = cons;
// create the chat windows // create the chat windows
int i; int i;
@ -268,6 +278,6 @@ static void create_windows(void)
strcpy(chat.from, ""); strcpy(chat.from, "");
chat.win = newwin(rows-3, cols, 1, 0); chat.win = newwin(rows-3, cols, 1, 0);
scrollok(chat.win, TRUE); scrollok(chat.win, TRUE);
wins[i] = chat; _wins[i] = chat;
} }
} }

View File

@ -8,6 +8,10 @@ struct prof_win {
WINDOW *win; WINDOW *win;
}; };
// gui startup and shutdown
void gui_init(void);
void gui_close(void);
// create windows // create windows
void create_title_bar(void); void create_title_bar(void);
void create_input_bar(void); void create_input_bar(void);
@ -29,17 +33,17 @@ void inp_put_back(void);
void inp_non_block(void); void inp_non_block(void);
void inp_get_password(char *passwd); void inp_get_password(char *passwd);
void gui_init(void); // main window actions
void gui_close(void); void win_title_bar_show(char *title);
void title_bar_show(char *title); int win_is_active(int i);
int is_active(int i); void win_switch_to(int i);
void switch_to(int i); void win_close_win(void);
void close_win(void); int win_in_chat(void);
int in_chat(void); void win_get_recipient(char *recipient);
void get_recipient(char *recipient); void win_show_incomming_msg(char *from, char *message);
void show_incomming_msg(char *from, char *message); void win_show_outgoing_msg(char *from, char *to, char *message);
void show_outgoing_msg(char *from, char *to, char *message); void win_cons_help(void);
void cons_help(void); void win_cons_bad_command(char *cmd);
void cons_bad_command(char *cmd); void win_cons_show(char *cmd);
void cons_show(char *cmd);
#endif #endif