File: output.c

package info (click to toggle)
ircii-pana 1%3A1.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,048 kB
  • ctags: 14,567
  • sloc: ansic: 130,654; sql: 6,041; makefile: 4,313; cpp: 1,270; tcl: 1,230; sh: 638; java: 151
file content (344 lines) | stat: -rw-r--r-- 7,750 bytes parent folder | download
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
 * output.c: handles a variety of tasks dealing with the output from the irc
 * program 
 *
 * Written By Michael Sandrof
 *
 * Copyright(c) 1990 
 *
 * See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT 
 */

#include "irc.h"
static char cvsrevision[] = "$Id: output.c,v 1.1.1.1 2003/04/11 01:09:07 dan Exp $";
CVS_REVISION(output_c)
#include "struct.h"              
#include <sys/stat.h>

#include <stdarg.h>

#include "output.h"
#include "vars.h"
#include "input.h"
#include "ircaux.h"
#include "ircterm.h"
#include "lastlog.h"
#include "window.h"
#include "screen.h"
#include "server.h"
#include "hook.h"
#include "ctcp.h"
#include "log.h"
#include "misc.h"
#define MAIN_SOURCE
#include "modval.h"

	int	in_help = 0;

/* make this buffer *much* bigger than needed */

#define LARGE_BIG_BUFFER_SIZE BIG_BUFFER_SIZE * 10

static	char	*putbuf = NULL; /*[LARGE_BIG_BUFFER_SIZE + 1];*/
extern	LastMsg	last_servermsg[];

char three_stars[4] = "***";

/* unflash: sends a ^[c to the screen */
/* Must be defined to be useful, cause some vt100s really *do* reset when
   sent this command. >;-) */

/* functions which switch the character set on the console */
/* ibmpc is not available on the xterm */

void charset_ibmpc (void)
{
	fwrite("\033(U", 3, 1, current_ftarget);	/* switch to IBM code page 437 */
}

void charset_lat1 (void)
{
	fwrite("\033(B", 3, 1, current_ftarget);	/* switch to Latin-1 (ISO 8859-1) */
}

void charset_cst(void)
{
	fwrite("\033(K", 3, 1, current_ftarget); /* switch too user-defined */
}

/* currently not used. */


/* Now that you can send ansi sequences, this is much less inportant.. */
void unflash (void)
{
#if !defined(WINNT) && !defined(__EMX__)

#if defined(HARD_UNFLASH) && !defined(CHARSET_CUSTOM)
	fwrite("\033c", 5, 1, current_ftarget);		/* hard reset */
#else
	fwrite("\033)0", 6, 1, current_ftarget);		/* soft reset */
#endif

#ifndef ONLY_STD_CHARS
#if defined(LATIN1)
	charset_lat1();
#elif defined(CHARSET_CUSTOM)
	charset_cst();
#else
	charset_ibmpc();
#endif
#endif

#endif
}

/*
 * refresh_screen: Whenever the REFRESH_SCREEN function is activated, this
 * swoops into effect 
 */
void refresh_screen (unsigned char dumb, char *dumber)
{
extern int need_redraw;

#if !defined(WINNT) && !defined(__EMX__)
	term_clear_screen();
	unflash();
#else
	xterm_settitle();
	term_clear_screen();
#endif

#if 0
	for (tmp = screen_list; tmp; tmp = tmp->next)
		tmp->co = TI_cols, tmp->li = TI_lines;
#endif
	if (term_resize())
		recalculate_windows(current_window->screen);
	else
		redraw_all_windows();
	if (need_redraw)
		need_redraw = 0;
	update_all_windows();
	update_input(UPDATE_ALL);
}

/*
 * refresh_window_screen: Updates and redraws only the window's 
 * screen that was passed as a parameter. 
 */

#ifdef GUI
void refresh_window_screen(Window *window)
{
   xterm_settitle();
   recalculate_windows(current_window->screen);
   update_all_windows();
   update_input(UPDATE_ALL);
}
#endif

int init_output(void)
{
	if (!putbuf)
		putbuf = new_malloc(LARGE_BIG_BUFFER_SIZE+1);
	return 0;
}

/* init_windows:  */
int init_screen (void)
{
extern int term_initialized;
	term_initialized = 1;
	term_clear_screen();
	term_resize();
	create_new_screen();
	new_window(main_screen);
	update_all_windows();
	term_move_cursor(0, 0);
	return 0;
}

void put_echo (char *str)
{
	add_to_log(irclog_fp, 0, str, logfile_line_mangler);
	add_to_screen(str);
}


/*
 * put_it: the irc display routine.  Use this routine to display anything to
 * the main irc window.  It handles sending text to the display or stdout as
 * needed, add stuff to the lastlog and log file, etc.  Things NOT to do:
 * Dont send any text that contains \n, very unpredictable.  Tabs will also
 * screw things up.  The calling routing is responsible for not overwriting
 * the 1K buffer allocated.  
 *
 * For Ultrix machines, you can't call put_it() with floating point arguements.
 * It just doesn't work.  - phone, jan 1993.
 */
void BX_put_it(const char *format, ...)
{
	if (window_display && format)
	{
		va_list args;
		memset(putbuf, 0, 200);
		va_start (args, format);
		vsnprintf(putbuf, LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);
		if (*putbuf)
			put_echo(putbuf);
	}
}

/* This is an alternative form of put_it which writes three asterisks
 * before actually putting things out.
 */
void say (const char *format, ...)
{
int len = 0;
	if (window_display && format)
	{
		va_list args;
		va_start (args, format);
		if (thing_ansi)
			len = strlen(thing_ansi);
		else
			len = 3;
		vsnprintf(&(putbuf[len+1]), LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);
		strcpy(putbuf, thing_ansi?thing_ansi:three_stars);
		putbuf[len] = ' ';
		if (strip_ansi_in_echo) 
		{
			register char *ptr;
			for (ptr = putbuf + len; *ptr; ptr++)
				if (*ptr < 31 && *ptr > 13)
					if (*ptr != 15 && *ptr != 22)
						*ptr = (*ptr & 127) | 64;
		}
		put_echo(putbuf);
	}
}

void BX_bitchsay (const char *format, ...)
{
int len;
	if (window_display && format)
	{
		va_list args;
		va_start (args, format);
		sprintf(putbuf, "%s \002%s\002: ", thing_ansi?thing_ansi:three_stars, version);
		len = strlen(putbuf);
		vsnprintf(&(putbuf[len]), LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);
		if (strip_ansi_in_echo) 
		{
			register char *ptr;
			for (ptr = putbuf+len; *ptr; ptr++)
				if (*ptr < 31 && *ptr > 13)
					if (*ptr != 15 && *ptr != 22)
						*ptr = (*ptr & 127) | 64;
		}
		put_echo(putbuf);
	}
}

void	BX_yell(const char *format, ...)
{
	if (format)
	{
		va_list args;
		va_start (args, format);
		*putbuf = 0;
		vsnprintf(putbuf, LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);
		if (*putbuf && do_hook(YELL_LIST, "%s", putbuf))
			put_echo(putbuf);
	}
}


void	log_put_it (const char *topic, const char *format, ...)
{
	if (format)
	{
		va_list args;
		va_start (args, format);
		vsnprintf(putbuf, LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);

		in_help = 1;
		set_display_target(NULL, LOG_CURRENT);
		if (window_display)
			put_echo(putbuf);
		reset_display_target();
		in_help = 0;
	}
}

char *ov_server(int server)
{
	char *c;
	char *d;
	static char tmpstr[61];
	char *string = get_server_itsname(server);
	    
	if (!string || !*string)
		string = get_server_name(server);
	if (!string || !*string)
		return  empty_string;
	strmcpy(tmpstr, string, 60);
	if (!(c = strrchr(tmpstr,'.')))
		return(string);
	*c = 0;
	if (!(d = strrchr(tmpstr, '.'))) 
		d = ++c; /* Extract domain */
	d++;
	return(d);
}

void serversay(int save, int from_server, const char *format, ...)
{
	Window	*old_target_window = target_window;
	char 	servername[200];
	int	len = 0;	
	char	*out = NULL;
	if (get_int_var(OV_VAR))
		target_window = get_window_by_name("OPER_VIEW");
        if (window_display && format)
        {
		va_list args;
		va_start (args, format);
		vsnprintf(putbuf, LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);
		strmcpy(servername, convert_output_format(get_string_var(SERVER_PROMPT_VAR), "%s", ov_server(from_server)?ov_server(from_server):empty_string), 79);
		len = strlen(putbuf);
		out = alloca(strlen(servername)+len+5);
		len = strlen(servername);
		strcpy(out, servername); out[len] = ' '; out[len+1] = 0;
		strcat(out, putbuf);
		if (*out)
			put_echo(out);
	}
	target_window = old_target_window;
	if (save && out)
		add_last_type(&last_servermsg[0], MAX_LAST_MSG, NULL, NULL, NULL, out);
}
/*
 * 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, LARGE_BIG_BUFFER_SIZE, format, args);
		va_end(args);
		do_hook(YELL_LIST, "%s", putbuf);
		put_echo(putbuf);
	}
}