/* X-Chat
* Copyright (C) 1998 Peter Zelezny.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef WIN32
#include <io.h>
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#else
#include <unistd.h>
#include <sys/time.h>
#endif
#include <sys/types.h>
#include <ctype.h>
#include <glib-object.h>
#include "../common/hexchat.h"
#include "../common/hexchatc.h"
#include "../common/cfgfiles.h"
#include "../common/outbound.h"
#include "../common/util.h"
#include "../common/fe.h"
#include "fe-text.h"
static int done = FALSE; /* finished ? */
static void
send_command (char *cmd)
{
handle_multiline (current_tab, cmd, TRUE, FALSE);
}
static gboolean
handle_line (GIOChannel *channel, GIOCondition cond, gpointer data)
{
gchar *str_return;
gsize length, terminator_pos;
GError *error = NULL;
GIOStatus result;
result = g_io_channel_read_line(channel, &str_return, &length, &terminator_pos, &error);
if (result == G_IO_STATUS_ERROR || result == G_IO_STATUS_EOF) {
return FALSE;
}
else {
send_command(str_return);
g_free(str_return);
return TRUE;
}
}
static int done_intro = 0;
void
fe_new_window (struct session *sess, int focus)
{
char buf[512];
current_sess = sess;
if (!sess->server->front_session)
sess->server->front_session = sess;
if (!sess->server->server_session)
sess->server->server_session = sess;
if (!current_tab || focus)
current_tab = sess;
if (done_intro)
return;
done_intro = 1;
g_snprintf (buf, sizeof (buf),
"\n"
" \017HexChat-Text \00310"PACKAGE_VERSION"\n"
" \017Running on \00310%s\n",
get_sys_str (1));
fe_print_text (sess, buf, 0, FALSE);
fe_print_text (sess, "\n\nCompiled in Features\0032:\017 "
#ifdef USE_PLUGIN
"Plugin "
#endif
#ifdef ENABLE_NLS
"NLS "
#endif
#ifdef USE_OPENSSL
"OpenSSL "
#endif
"\n\n", 0, FALSE);
fflush (stdout);
}
static int
get_stamp_str (time_t tim, char *dest, int size)
{
return strftime_validated (dest, size, prefs.hex_stamp_text_format, localtime (&tim));
}
static int
timecat (char *buf, time_t stamp)
{
char stampbuf[64];
/* set the stamp to the current time if not provided */
if (!stamp)
stamp = time (0);
get_stamp_str (stamp, stampbuf, sizeof (stampbuf));
strcat (buf, stampbuf);
return strlen (stampbuf);
}
/* Windows doesn't handle ANSI codes in cmd.exe, need to not display them */
#ifndef WIN32
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
static const short colconv[] = { 0, 7, 4, 2, 1, 3, 5, 11, 13, 12, 6, 16, 14, 15, 10, 7 };
void
fe_print_text (struct session *sess, char *text, time_t stamp,
gboolean no_activity)
{
int dotime = FALSE;
char num[8];
int reverse = 0, under = 0, bold = 0,
comma, k, i = 0, j = 0, len = strlen (text);
unsigned char *newtext = g_malloc (len + 1024);
if (prefs.hex_stamp_text)
{
newtext[0] = 0;
j += timecat (newtext, stamp);
}
while (i < len)
{
if (dotime && text[i] != 0)
{
dotime = FALSE;
newtext[j] = 0;
j += timecat (newtext, stamp);
}
switch (text[i])
{
case 3:
i++;
if (!isdigit (text[i]))