1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Split log into module

This commit is contained in:
James Booth 2012-02-05 15:10:10 +00:00
parent 10bc41239f
commit 5eaf687d98
5 changed files with 50 additions and 108 deletions

View File

@ -1,12 +1,15 @@
CC = gcc
CFLAGS = -O3 -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
LIBS = -lxml2 -lssl -lresolv -lncurses -lstrophe
CFLAGS = -O3 $(WARNS) $(LIBS)
OBJS = log.o profanity.o
profanity: clean
$(CC) profanity.c $(LIBS) -o profanity
$(CC) curses_example.c -lncurses -o curses_example
profanity: $(OBJS)
$(CC) -o profanity $(OBJS) $(LIBS)
log.o: log.h
profanity.o: log.h
.PHONY: clean
clean:
rm -f profanity
rm -f curses_example

View File

@ -1,76 +0,0 @@
#include <ncurses.h>
#include <string.h>
void init()
{
initscr();
raw();
keypad(stdscr, TRUE);
start_color();
init_color(COLOR_WHITE, 1000, 1000, 1000);
init_pair(1, COLOR_WHITE, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_color(COLOR_BLUE, 0, 0, 250);
init_pair(3, COLOR_WHITE, COLOR_BLUE);
attron(A_BOLD);
attron(COLOR_PAIR(1));
}
void print_title()
{
int rows, cols;
char *title = "PROFANITY";
getmaxyx(stdscr, rows, cols);
attron(COLOR_PAIR(3));
mvprintw(1, (cols - strlen(title))/2, title);
attroff(COLOR_PAIR(3));
}
void close()
{
int rows, cols;
char *exit_msg = "< HIT ANY KEY TO EXIT >";
getmaxyx(stdscr, rows, cols);
attron(A_BLINK);
curs_set(0);
mvprintw(rows-10, (cols - strlen(exit_msg))/2, exit_msg);
refresh();
getch();
endwin();
}
int main()
{
int ypos = 2;
int xpos = 2;
int ch;
char name[20];
init();
print_title();
ypos += 2;
mvprintw(ypos, xpos, "Enter your name: ");
echo();
getstr(name);
noecho();
ypos += 2;
mvprintw(ypos, xpos, "Shit, ");
attron(COLOR_PAIR(2));
printw("%s", name);
attroff(COLOR_PAIR(2));
printw("\n");
close();
return 0;
}

23
log.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <strophe/strophe.h>
#include "log.h"
extern FILE *logp;
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
const char * const area, const char * const msg);
static const xmpp_log_t file_log = { &xmpp_file_logger, XMPP_LEVEL_DEBUG };
xmpp_log_t *xmpp_get_file_logger()
{
return (xmpp_log_t*) &file_log;
}
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
const char * const area, const char * const msg)
{
fprintf(logp, "%s DEBUG %s\n", area, msg);
}

9
log.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef LOG_H
#define LOG_H
// log
FILE *logp;
xmpp_log_t *xmpp_get_file_logger();
#endif

View File

@ -4,7 +4,12 @@
#include <string.h>
#include <strophe/strophe.h>
static FILE *logp;
#include "log.h"
// refernce to log
extern FILE *logp;
// chat windows
static WINDOW *incoming_border;
static WINDOW *outgoing_border;
static WINDOW *incoming;
@ -12,27 +17,21 @@ static WINDOW *outgoing;
static int incoming_ypos = 0;
static int inc_scroll_max = 0;
xmpp_log_t *xmpp_get_file_logger();
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
const char * const area, const char * const msg);
static const xmpp_log_t file_log = { &xmpp_file_logger, XMPP_LEVEL_DEBUG };
// message handlers
int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata);
int out_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata);
// connection handler
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
const int error, xmpp_stream_error_t * const stream_error,
void * const userdata);
// curses functions
void init(void);
void print_title(void);
void close(void);
WINDOW *create_win(int, int, int, int, int);
@ -42,7 +41,6 @@ int main(void)
{
int ypos = 2;
int xpos = 2;
int ch;
char user[50];
char passwd[50];
@ -103,11 +101,7 @@ int main(void)
int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
void * const userdata)
{
char *append_reply = ", recieved";
xmpp_stanza_t *reply, *body, *text;
char *intext, *replytext;
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
char *intext;
if(!xmpp_stanza_get_child_by_name(stanza, "body"))
return 1;
@ -166,17 +160,6 @@ int out_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
}
xmpp_log_t *xmpp_get_file_logger()
{
return (xmpp_log_t*) &file_log;
}
void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
const char * const area, const char * const msg)
{
fprintf(logp, "%s %s %s\n", area, XMPP_LEVEL_DEBUG, msg);
}
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
const int error, xmpp_stream_error_t * const stream_error,
void * const userdata)