1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
/* $EPIC: output.c,v 1.12 2008/03/17 03:42:46 jnelson Exp $ */
/*
* output.c: handles a variety of tasks dealing with the output from the irc
* program
*
* Copyright (c) 1990 Michael Sandroff.
* Copyright (c) 1991, 1992 Troy Rollo.
* Copyright (c) 1992-1996 Matthew Green.
* Copyright 1997, 2002 EPIC Software Labs.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notices, the above paragraph (the one permitting redistribution),
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The names of the author(s) may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "irc.h"
#include "output.h"
#include "vars.h"
#include "input.h"
#include "termx.h"
#include "lastlog.h"
#include "window.h"
#include "screen.h"
#include "hook.h"
#include "ctcp.h"
#include "log.h"
#include "ircaux.h"
#include "alias.h"
/* make this buffer *much* bigger than needed */
#define OBNOXIOUS_BUFFER_SIZE BIG_BUFFER_SIZE * 10
static char putbuf[OBNOXIOUS_BUFFER_SIZE + 1];
/*
* unflash: sends a ^[c to the screen
* Must be defined to be useful, cause some vt100s really *do* reset when
* sent this command. >;-)
* Now that you can send ansi sequences, this is much less inportant..
*/
static void unflash (void)
{
#ifdef HARD_UNFLASH
fwrite("\033c", 2, 1, stdout); /* hard reset */
#else
fwrite("\033)0", 3, 1, stdout); /* soft reset */
#endif
}
/* sig_refresh_screen: the signal-callable version of refresh_screen */
SIGNAL_HANDLER(sig_refresh_screen)
{
need_redraw = 1;
#if 0
refresh_a_screen(main_screen);
#endif
}
/*
* refresh_screen: Whenever the REFRESH_SCREEN function is activated, this
* swoops into effect
*/
void refresh_screen (char dumb, char *dumber)
{
if (current_window && current_window->screen)
refresh_a_screen(current_window->screen);
else
refresh_a_screen(main_screen);
}
void refresh_a_screen (Screen *screen)
{
unflash();
term_clear_screen();
if (screen != main_screen || term_resize())
recalculate_windows(screen);
else
redraw_all_windows();
if (need_redraw)
need_redraw = 0;
update_all_windows();
update_input(UPDATE_ALL);
}
/* extern_write -- controls whether others may write to our terminal or not. */
/* This is basically stolen from bsd -- so its under the bsd copyright */
BUILT_IN_COMMAND(extern_write)
{
char *tty;
Stat sbuf;
const int OTHER_WRITE = 020;
if (!(tty = ttyname(2)))
{
yell("Could not figure out the name of your tty device!");
return;
}
if (stat(tty, &sbuf) < 0)
{
yell("Could not get the information about your tty device!");
return;
}
if (!args || !*args)
{
if (sbuf.st_mode & 020)
say("Mesg is 'y'");
else
say("Mesg is 'n'");
return;
}
switch (args[0])
{
case 'y' :
{
if (chmod(tty, sbuf.st_mode | OTHER_WRITE) < 0)
{
yell("Could not set your tty's mode!");
return;
}
break;
}
case 'n' :
{
if (chmod(tty, sbuf.st_mode &~ OTHER_WRITE) < 0)
{
yell("Could not set your tty's mode!");
return;
}
break;
}
default :
say("Usage: /%s [Y|N]", command);
}
}
/* init_windows: */
int init_screen (void)
{
/*
* System dependant stuff
*/
if (term_init())
return -1;
term_clear_screen();
term_resize();
/*
* System independant stuff
*/
create_new_screen();
new_window(main_screen);
update_all_windows();
term_move_cursor(0, 0);
return 0;
}
/*
* put_echo: a display routine for echo that doesnt require an snprintf,
* so it doesnt have that overhead, and it also doesnt have any size
* limitations. The sky's the limit!
*/
void put_echo (const unsigned char *str)
{
add_to_log(irclog_fp, -1, str, 0, NULL);
add_to_screen(str);
}
/*
* put_it: the primary irc display routine. This routine can be used to
* display output to a user window. Its ok to have newlines or tabs in
* the output, but you should be careful not to overflow the 10k buffer
* used to hold the output (use put_echo if you just want to output an
* unbounded string).
*
* Some systems (notorously Ultrix) cannot gracefully convert float
* variables through "..." into va_list, and attempting to do so will
* cause a crash on dereference (in vsnprintf()), so don't do that. You'll
* have to snprintf() the floats into strings and then pass the string
* in with %s. Ugh. This is not a bug on our part.
*/
void put_it (const char *format, ...)
{
if (window_display && format)
{
va_list args;
va_start (args, format);
vsnprintf(putbuf, sizeof putbuf, format, args);
va_end(args);
put_echo(putbuf);
}
}
void file_put_it (FILE *fp, const char *format, ...)
{
if (format)
{
va_list args;
va_start (args, format);
vsnprintf(putbuf, sizeof putbuf, format, args);
va_end(args);
if (fp)
{
fputs(putbuf, fp);
fputs("\n", fp);
}
else if (window_display)
put_echo(putbuf);
}
}
/*
* This is an alternative form of put_it which writes three asterisks
* before actually putting things out.
*/
static void vsay (const char *format, va_list args)
{
if (window_display && format)
{
char *str;
*putbuf = 0;
if ((str = get_string_var(BANNER_VAR)))
{
if (get_int_var(BANNER_EXPAND_VAR))
{
int af;
char *foo;
foo = expand_alias(str, empty_string, &af, NULL);
strlcpy(putbuf, foo, sizeof putbuf);
new_free(&foo);
}
else
strlcpy(putbuf, str, sizeof putbuf);
strlcat(putbuf, " ", sizeof putbuf);
}
vsnprintf(putbuf + strlen(putbuf),
sizeof(putbuf) - strlen(putbuf) - 1,
format, args);
put_echo(putbuf);
}
}
void say (const char *format, ...)
{
va_list args;
va_start(args, format);
vsay(format, args);
va_end(args);
}
void yell (const char *format, ...)
{
if (format)
{
va_list args;
va_start (args, format);
vsnprintf(putbuf, sizeof putbuf, format, args);
va_end(args);
if (do_hook(YELL_LIST, "%s", putbuf))
put_echo(putbuf);
}
}
void privileged_yell (const char *format, ...)
{
if (format)
{
va_list args;
va_start (args, format);
vsnprintf(putbuf, sizeof putbuf, format, args);
va_end(args);
privileged_output++;
put_echo(putbuf);
privileged_output--;
}
}
/*
* Error is exactly like yell, except that if the error occured while
* you were loading a script, it tells you where it happened.
*/
void error (const char *format, ...)
{
dump_load_stack(0);
if (format)
{
va_list args;
va_start (args, format);
vsnprintf(putbuf, sizeof putbuf, format, args);
va_end(args);
do_hook(YELL_LIST, "%s", putbuf);
put_echo(putbuf);
}
}
|