2012-02-20 15:07:38 -05:00
|
|
|
/*
|
|
|
|
* profanity.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Profanity is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-09 17:24:03 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <ncurses.h>
|
|
|
|
|
|
|
|
#include "profanity.h"
|
2012-02-05 10:10:10 -05:00
|
|
|
#include "log.h"
|
2012-02-05 18:08:15 -05:00
|
|
|
#include "windows.h"
|
2012-02-09 17:24:03 -05:00
|
|
|
#include "jabber.h"
|
2012-02-09 18:15:53 -05:00
|
|
|
#include "command.h"
|
2012-02-26 20:44:09 -05:00
|
|
|
#include "history.h"
|
2012-02-09 17:24:03 -05:00
|
|
|
|
2012-02-26 20:48:51 -05:00
|
|
|
static void _profanity_init(int disable_tls);
|
2012-02-12 17:09:07 -05:00
|
|
|
static void _profanity_event_loop(int *ch, char *cmd, int *size);
|
2012-02-09 17:24:03 -05:00
|
|
|
|
2012-02-26 12:59:04 -05:00
|
|
|
void profanity_main(int disable_tls)
|
2012-02-09 17:50:19 -05:00
|
|
|
{
|
2012-02-09 18:15:53 -05:00
|
|
|
int cmd_result = TRUE;
|
2012-02-09 17:50:19 -05:00
|
|
|
|
2012-02-26 20:48:51 -05:00
|
|
|
_profanity_init(disable_tls);
|
2012-02-26 12:59:04 -05:00
|
|
|
|
2012-02-09 17:50:19 -05:00
|
|
|
inp_non_block();
|
2012-02-09 18:15:53 -05:00
|
|
|
while(cmd_result == TRUE) {
|
2012-02-09 17:50:19 -05:00
|
|
|
int ch = ERR;
|
2012-02-19 20:42:29 -05:00
|
|
|
char inp[100];
|
2012-02-09 17:50:19 -05:00
|
|
|
int size = 0;
|
|
|
|
|
2012-02-19 20:42:29 -05:00
|
|
|
while(ch != '\n')
|
|
|
|
_profanity_event_loop(&ch, inp, &size);
|
2012-02-16 19:42:41 -05:00
|
|
|
|
2012-02-19 20:42:29 -05:00
|
|
|
inp[size++] = '\0';
|
|
|
|
cmd_result = process_input(inp);
|
2012-02-09 17:50:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
jabber_disconnect();
|
|
|
|
}
|
|
|
|
|
2012-02-26 20:48:51 -05:00
|
|
|
static void _profanity_init(int disable_tls)
|
|
|
|
{
|
|
|
|
jabber_init(disable_tls);
|
|
|
|
history_init();
|
|
|
|
}
|
|
|
|
|
2012-02-12 17:09:07 -05:00
|
|
|
static void _profanity_event_loop(int *ch, char *cmd, int *size)
|
2012-02-09 17:50:19 -05:00
|
|
|
{
|
|
|
|
usleep(1);
|
2012-02-12 20:25:47 -05:00
|
|
|
gui_refresh();
|
2012-02-09 17:50:19 -05:00
|
|
|
jabber_process_events();
|
2012-02-26 21:01:19 -05:00
|
|
|
win_handle_switch(ch);
|
2012-02-12 17:53:53 -05:00
|
|
|
inp_poll_char(ch, cmd, size);
|
|
|
|
}
|