diff options
author | James Booth <boothj5@gmail.com> | 2012-02-12 22:09:07 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-02-12 22:09:07 +0000 |
commit | 7aa1d931a0e5578b7f7e3cc526b72031a3d8f8eb (patch) | |
tree | f4581b38a9385c60d21faf3f48ebe2ce0c78366f | |
parent | b71f61d400a6ca52a64093b2917db267e1bfab6c (diff) | |
download | profani-tty-7aa1d931a0e5578b7f7e3cc526b72031a3d8f8eb.tar.gz |
Naming of statics
-rw-r--r-- | command.c | 58 | ||||
-rw-r--r-- | jabber.c | 8 | ||||
-rw-r--r-- | profanity.c | 52 | ||||
-rw-r--r-- | title_bar.c | 4 | ||||
-rw-r--r-- | windows.c | 162 | ||||
-rw-r--r-- | windows.h | 30 |
6 files changed, 164 insertions, 150 deletions
diff --git a/command.c b/command.c index c223cdda..fea201ec 100644 --- a/command.c +++ b/command.c @@ -4,12 +4,12 @@ #include "jabber.h" #include "windows.h" -static int cmd_quit(void); -static int cmd_help(void); -static int cmd_who(void); -static int cmd_msg(char *cmd); -static int cmd_close(char *cmd); -static int cmd_default(char *cmd); +static int _cmd_quit(void); +static int _cmd_help(void); +static int _cmd_who(void); +static int _cmd_msg(char *cmd); +static int _cmd_close(char *cmd); +static int _cmd_default(char *cmd); int handle_start_command(char *cmd) { @@ -18,7 +18,7 @@ int handle_start_command(char *cmd) if (strcmp(cmd, "/quit") == 0) { result = QUIT_PROF; } else if (strncmp(cmd, "/help", 5) == 0) { - cons_help(); + win_cons_help(); result = AWAIT_COMMAND; } else if (strncmp(cmd, "/connect ", 9) == 0) { char *user; @@ -32,7 +32,7 @@ int handle_start_command(char *cmd) jabber_connect(user, passwd); result = START_MAIN; } else { - cons_bad_command(cmd); + win_cons_bad_command(cmd); result = AWAIT_COMMAND; } @@ -45,17 +45,17 @@ int handle_command(char *cmd) { int result = FALSE; if (strcmp(cmd, "/quit") == 0) { - result = cmd_quit(); + result = _cmd_quit(); } else if (strncmp(cmd, "/help", 5) == 0) { - result = cmd_help(); + result = _cmd_help(); } else if (strncmp(cmd, "/who", 4) == 0) { - result = cmd_who(); + result = _cmd_who(); } else if (strncmp(cmd, "/msg ", 5) == 0) { - result = cmd_msg(cmd); + result = _cmd_msg(cmd); } else if (strncmp(cmd, "/close", 6) == 0) { - result = cmd_close(cmd); + result = _cmd_close(cmd); } else { - result = cmd_default(cmd); + result = _cmd_default(cmd); } inp_clear(); @@ -64,26 +64,26 @@ int handle_command(char *cmd) } -static int cmd_quit(void) +static int _cmd_quit(void) { return FALSE; } -static int cmd_help(void) +static int _cmd_help(void) { - cons_help(); + win_cons_help(); return TRUE; } -static int cmd_who(void) +static int _cmd_who(void) { jabber_roster_request(); return TRUE; } -static int cmd_msg(char *cmd) +static int _cmd_msg(char *cmd) { char *usr_msg = 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)); if (msg != NULL) { jabber_send(msg, usr); - show_outgoing_msg("me", usr, msg); + win_show_outgoing_msg("me", usr, msg); } } return TRUE; } -static int cmd_close(char *cmd) +static int _cmd_close(char *cmd) { - if (in_chat()) { - close_win(); + if (win_in_chat()) { + win_close_win(); } else { - cons_bad_command(cmd); + win_cons_bad_command(cmd); } return TRUE; } -static int cmd_default(char *cmd) +static int _cmd_default(char *cmd) { - if (in_chat()) { + if (win_in_chat()) { char recipient[100] = ""; - get_recipient(recipient); + win_get_recipient(recipient); jabber_send(cmd, recipient); - show_outgoing_msg("me", recipient, cmd); + win_show_outgoing_msg("me", recipient, cmd); } else { - cons_bad_command(cmd); + win_cons_bad_command(cmd); } return TRUE; diff --git a/jabber.c b/jabber.c index 65e09677..4c9d65fe 100644 --- a/jabber.c +++ b/jabber.c @@ -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")); char *from = xmpp_stanza_get_attribute(stanza, "from"); - show_incomming_msg(from, message); + win_show_incomming_msg(from, message); 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"); else { query = xmpp_stanza_get_child_by_name(stanza, "query"); - cons_show("Roster:"); + win_cons_show("Roster:"); for (item = xmpp_stanza_get_children(query); item; item = xmpp_stanza_get_next(item)) { if ((name = xmpp_stanza_get_attribute(item, "name"))) { char line[200]; sprintf(line, " %s (%s)", name, xmpp_stanza_get_attribute(item, "jid")); - cons_show(line); + win_cons_show(line); } else { char line[200]; sprintf(line, " %s", xmpp_stanza_get_attribute(item, "jid")); - cons_show(line); + win_cons_show(line); } } } diff --git a/profanity.c b/profanity.c index e34b6106..ddbef953 100644 --- a/profanity.c +++ b/profanity.c @@ -9,8 +9,8 @@ #include "jabber.h" #include "command.h" -static void profanity_main(void); -static void profanity_event_loop(int *ch, char *cmd, int *size); +static void _profanity_main(void); +static void _profanity_event_loop(int *ch, char *cmd, int *size); void profanity_start(void) { @@ -23,11 +23,11 @@ void profanity_start(void) } if (cmd_result == START_MAIN) { - profanity_main(); + _profanity_main(); } } -static void profanity_main(void) +static void _profanity_main(void) { int cmd_result = TRUE; @@ -38,7 +38,7 @@ static void profanity_main(void) int size = 0; while(ch != '\n') - profanity_event_loop(&ch, cmd, &size); + _profanity_event_loop(&ch, cmd, &size); cmd[size++] = '\0'; cmd_result = handle_command(cmd); @@ -47,7 +47,7 @@ static void profanity_main(void) 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); @@ -58,35 +58,35 @@ static void profanity_event_loop(int *ch, char *cmd, int *size) // determine if they changed windows if (*ch == KEY_F(1)) { - if (is_active(0)) - switch_to(0); + if (win_is_active(0)) + win_switch_to(0); } else if (*ch == KEY_F(2)) { - if (is_active(1)) - switch_to(1); + if (win_is_active(1)) + win_switch_to(1); } else if (*ch == KEY_F(3)) { - if (is_active(2)) - switch_to(2); + if (win_is_active(2)) + win_switch_to(2); } else if (*ch == KEY_F(4)) { - if (is_active(3)) - switch_to(3); + if (win_is_active(3)) + win_switch_to(3); } else if (*ch == KEY_F(5)) { - if (is_active(4)) - switch_to(4); + if (win_is_active(4)) + win_switch_to(4); } else if (*ch == KEY_F(6)) { - if (is_active(5)) - switch_to(5); + if (win_is_active(5)) + win_switch_to(5); } else if (*ch == KEY_F(7)) { - if (is_active(6)) - switch_to(6); + if (win_is_active(6)) + win_switch_to(6); } else if (*ch == KEY_F(8)) { - if (is_active(7)) - switch_to(7); + if (win_is_active(7)) + win_switch_to(7); } else if (*ch == KEY_F(9)) { - if (is_active(8)) - switch_to(8); + if (win_is_active(8)) + win_switch_to(8); } else if (*ch == KEY_F(10)) { - if (is_active(9)) - switch_to(9); + if (win_is_active(9)) + win_switch_to(9); } // get another character from the command box diff --git a/title_bar.c b/title_bar.c index 27b2855e..57235b71 100644 --- a/title_bar.c +++ b/title_bar.c @@ -12,10 +12,10 @@ void create_title_bar(void) title_bar = newwin(1, cols, 0, 0); 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); mvwprintw(title_bar, 0, 0, " %s", title); diff --git a/windows.c b/windows.c index 8725a7d7..b8ecd799 100644 --- a/windows.c +++ b/windows.c @@ -3,10 +3,10 @@ #include "windows.h" #include "util.h" -static struct prof_win wins[10]; -static int curr_win = 0; +static struct prof_win _wins[10]; +static int _curr_win = 0; -static void create_windows(void); +static void _create_windows(void); void gui_init(void) { @@ -31,7 +31,7 @@ void gui_init(void) create_input_bar(); create_input_window(); - create_windows(); + _create_windows(); } void gui_close(void) @@ -39,54 +39,54 @@ void gui_close(void) 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; else return TRUE; } -void switch_to(int i) +void win_switch_to(int i) { - touchwin(wins[i].win); - wrefresh(wins[i].win); - curr_win = i; + touchwin(_wins[i].win); + wrefresh(_wins[i].win); + _curr_win = i; if (i == 0) { - title_bar_show("Console, type /help for help information"); + win_title_bar_show("Console, type /help for help information"); } 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 - strcpy(wins[curr_win].from, ""); - wclear(wins[curr_win].win); + strcpy(_wins[_curr_win].from, ""); + wclear(_wins[_curr_win].win); // set it as inactive in the status bar - inp_bar_inactive(curr_win); + inp_bar_inactive(_curr_win); // go back to console window - touchwin(wins[0].win); - wrefresh(wins[0].win); + touchwin(_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]; strcpy(from_cpy, from); @@ -101,47 +101,47 @@ void show_incomming_msg(char *from, char *message) // find the chat window for sender int i; for (i = 1; i < 10; i++) - if (strcmp(wins[i].from, short_from) == 0) + if (strcmp(_wins[i].from, short_from) == 0) break; // if we didn't find a window if (i == 10) { // find the first unused one for (i = 1; i < 10; i++) - if (strcmp(wins[i].from, "") == 0) + if (strcmp(_wins[i].from, "") == 0) break; // set it up and print the message to it - strcpy(wins[i].from, short_from); - wclear(wins[i].win); - wprintw(wins[i].win, line); + strcpy(_wins[i].from, short_from); + wclear(_wins[i].win); + wprintw(_wins[i].win, line); // signify active window in status bar inp_bar_active(i); // if its the current window, draw it - if (curr_win == i) { - touchwin(wins[i].win); - wrefresh(wins[i].win); + if (_curr_win == i) { + touchwin(_wins[i].win); + wrefresh(_wins[i].win); } } // otherwise else { // add the line to the senders window - wprintw(wins[i].win, line); + wprintw(_wins[i].win, line); // signify active window in status bar inp_bar_active(i); // if its the current window, draw it - if (curr_win == i) { - touchwin(wins[i].win); - wrefresh(wins[i].win); + if (_curr_win == i) { + touchwin(_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 tstmp[80]; @@ -151,98 +151,108 @@ void show_outgoing_msg(char *from, char *to, char *message) // find the chat window for recipient int i; for (i = 1; i < 10; i++) - if (strcmp(wins[i].from, to) == 0) + if (strcmp(_wins[i].from, to) == 0) break; // if we didn't find a window if (i == 10) { // find the first unused one for (i = 1; i < 10; i++) - if (strcmp(wins[i].from, "") == 0) + if (strcmp(_wins[i].from, "") == 0) break; // set it up and print the message to it - strcpy(wins[i].from, to); - wclear(wins[i].win); - wprintw(wins[i].win, line); + strcpy(_wins[i].from, to); + wclear(_wins[i].win); + wprintw(_wins[i].win, line); // signify active window in status bar inp_bar_active(i); // if its the current window, draw it - if (curr_win == i) { - touchwin(wins[i].win); - wrefresh(wins[i].win); + if (_curr_win == i) { + touchwin(_wins[i].win); + wrefresh(_wins[i].win); } } // otherwise else { // add the line to the senders window - wprintw(wins[i].win, line); + wprintw(_wins[i].win, line); // signify active window in status bar inp_bar_active(i); // if its the current window, draw it - if (curr_win == i) { - touchwin(wins[i].win); - wrefresh(wins[i].win); + if (_curr_win == i) { + touchwin(_wins[i].win); + wrefresh(_wins[i].win); } } } -void cons_help(void) +void win_cons_help(void) { char tstmp[80]; get_time(tstmp); - wprintw(wins[0].win, " [%s] Help:\n", tstmp); - wprintw(wins[0].win, " [%s] Commands:\n", tstmp); - wprintw(wins[0].win, " [%s] /help : This help.\n", tstmp); - wprintw(wins[0].win, " [%s] /connect <username@host> : Login to jabber.\n", tstmp); - wprintw(wins[0].win, " [%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); + wprintw(_wins[0].win, + " [%s] Help:\n", tstmp); + wprintw(_wins[0].win, + " [%s] Commands:\n", tstmp); + wprintw(_wins[0].win, + " [%s] /help : This help.\n", tstmp); + wprintw(_wins[0].win, + " [%s] /connect <username@host> : Login to jabber.\n", tstmp); + wprintw(_wins[0].win, + " [%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 (curr_win == 0) { - touchwin(wins[0].win); - wrefresh(wins[0].win); + if (_curr_win == 0) { + touchwin(_wins[0].win); + wrefresh(_wins[0].win); } } -void cons_show(char *msg) +void win_cons_show(char *msg) { char tstmp[80]; 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 (curr_win == 0) { - touchwin(wins[0].win); - wrefresh(wins[0].win); + if (_curr_win == 0) { + touchwin(_wins[0].win); + wrefresh(_wins[0].win); } } -void cons_bad_command(char *cmd) +void win_cons_bad_command(char *cmd) { char tstmp[80]; 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 (curr_win == 0) { - touchwin(wins[0].win); - wrefresh(wins[0].win); + if (_curr_win == 0) { + touchwin(_wins[0].win); + wrefresh(_wins[0].win); } } -static void create_windows(void) +static void _create_windows(void) { int rows, cols; getmaxyx(stdscr, rows, cols); @@ -259,7 +269,7 @@ static void create_windows(void) wprintw(cons.win, " [%s] Welcome to Profanity.\n", tstmp); touchwin(cons.win); wrefresh(cons.win); - wins[0] = cons; + _wins[0] = cons; // create the chat windows int i; @@ -268,6 +278,6 @@ static void create_windows(void) strcpy(chat.from, ""); chat.win = newwin(rows-3, cols, 1, 0); scrollok(chat.win, TRUE); - wins[i] = chat; + _wins[i] = chat; } } diff --git a/windows.h b/windows.h index 37d5f1c9..33581a0d 100644 --- a/windows.h +++ b/windows.h @@ -8,6 +8,10 @@ struct prof_win { WINDOW *win; }; +// gui startup and shutdown +void gui_init(void); +void gui_close(void); + // create windows void create_title_bar(void); void create_input_bar(void); @@ -29,17 +33,17 @@ void inp_put_back(void); void inp_non_block(void); void inp_get_password(char *passwd); -void gui_init(void); -void gui_close(void); -void title_bar_show(char *title); -int is_active(int i); -void switch_to(int i); -void close_win(void); -int in_chat(void); -void get_recipient(char *recipient); -void show_incomming_msg(char *from, char *message); -void show_outgoing_msg(char *from, char *to, char *message); -void cons_help(void); -void cons_bad_command(char *cmd); -void cons_show(char *cmd); +// main window actions +void win_title_bar_show(char *title); +int win_is_active(int i); +void win_switch_to(int i); +void win_close_win(void); +int win_in_chat(void); +void win_get_recipient(char *recipient); +void win_show_incomming_msg(char *from, char *message); +void win_show_outgoing_msg(char *from, char *to, char *message); +void win_cons_help(void); +void win_cons_bad_command(char *cmd); +void win_cons_show(char *cmd); + #endif |