1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: termout.gen.c 380 2007-01-23 00:09:18Z hubert@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006-2007 University of Washington
9
* Licensed under the Apache License, Version 2.0 (the "License");
10
* you may not use this file except in compliance with the License.
11
* You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
20
#include "../../c-client/mail.h" /* for MAILSTREAM and friends */
21
#include "../../c-client/osdep.h"
22
#include "../../c-client/rfc822.h" /* for soutr_t and such */
23
#include "../../c-client/misc.h" /* for cpystr proto */
24
#include "../../c-client/utf8.h" /* for CHARSET and such*/
25
#include "../../c-client/imap4r1.h"
27
#include "../../pith/osdep/color.h"
28
#include "../../pith/charconv/filesys.h"
30
#include "../../pith/debug.h"
31
#include "../../pith/newmail.h"
32
#include "../../pith/filter.h"
33
#include "../../pith/handle.h"
34
#include "../../pith/conf.h"
36
#include "../../pico/estruct.h"
37
#include "../../pico/pico.h"
38
#include "../../pico/keydefs.h"
40
#include "../status.h"
42
#include "../folder.h"
43
#include "../keymenu.h"
46
#include "termout.gen.h"
49
#define PUTLINE_BUFLEN 256
56
* Generic tty output routines...
59
/*----------------------------------------------------------------------
60
Printf style output line to the screen at given position, 0 args
62
Args: x -- column position on the screen
63
y -- row position on the screen
64
line -- line of text to output
66
Result: text is output
67
cursor position is update
70
PutLine0(int x, int y, register char *line)
73
Write_to_screen(line);
78
/*----------------------------------------------------------------------
79
Output line of length len to the display observing embedded attributes
81
Args: x -- column position on the screen
82
y -- column position on the screen
83
line -- text to be output
84
length -- length of text to be output
86
Result: text is output
87
cursor position is updated
88
----------------------------------------------------------------------*/
90
PutLine0n8b(int x, int y, register char *line, int length, HANDLE_S *handles)
93
int is_inv = 0, is_bold = 0, is_uline = 0, is_fg = 0, is_bg = 0;
102
c = (unsigned char) *line++;
104
if(c == (unsigned char) TAG_EMBED && length){
129
case TAG_ITALICON : /* express italic as uline in terminal */
135
case TAG_ITALICOFF : /* express italic as uline in terminal */
142
length -= *line + 1; /* key length plus length tag */
144
int key, n, current_key = 0;
146
for(key = 0, n = *line++; n; n--) /* forget Horner? */
147
key = (key * 10) + (*line++ - '0');
153
if(handles->using_is_used){
156
for(h = handles; h; h = h->next)
161
current_key = h->key;
164
current_key = handles->key;
166
if(key == current_key){
167
if(pico_usingcolor() &&
168
ps_global->VAR_SLCTBL_FORE_COLOR &&
169
ps_global->VAR_SLCTBL_BACK_COLOR){
170
pico_set_normal_color();
189
"FGCOLOR not proper length, ignoring\n"));
194
(void)pico_set_fg_color(line);
203
"BGCOLOR not proper length, ignoring\n"));
208
(void)pico_set_bg_color(line);
214
case TAG_EMBED: /* literal "embed" char */
215
Writechar(TAG_EMBED, 0);
218
case TAG_STRIKEON : /* unsupported text markup */
224
default : /* Eat unrecognized tag - TAG_BIGON, etc */
226
} /* tag with handle, skip it */
235
char *tmp_file = NULL, ext[32], mtype[128];
237
extern HANDLE_S *get_handle (HANDLE_S *, int);
239
if((h = get_handle(handles, hkey)) && h->type == Attach){
241
strncpy(mtype, body_type_names(h->h.attach->body->type), sizeof(mtype));
242
mtype[sizeof(mtype)-1] = '\0';
243
if (h->h.attach->body->subtype) {
244
strncat (mtype, "/", sizeof(mtype)-strlen(mtype));
245
mtype[sizeof(mtype)-1] = '\0';
246
strncat (mtype, h->h.attach->body->subtype, sizeof(mtype)-strlen(mtype));
247
mtype[sizeof(mtype)-1] = '\0';
250
if(!set_mime_extension_by_type(ext, mtype)){
251
char *namep, *dotp, *p;
253
if(namep = rfc2231_get_param(h->h.attach->body->parameter,
254
"name", NULL, NULL)){
255
for(dotp = NULL, p = namep; *p; p++)
259
if(dotp && strlen(dotp) < sizeof(ext) - 1){
260
strncpy(ext, dotp, sizeof(ext));
261
ext[sizeof(ext)-1] = '\0';
264
fs_give((void **) &namep);
268
if(ext[0] && (tmp_file = temp_nam_ext(NULL, "im", 0, ext))){
269
FILE *f = our_fopen(tmp_file, "w");
271
mswin_registericon(x, h->key, tmp_file);
274
our_unlink(tmp_file);
275
fs_give((void **)&tmp_file);
282
"INVERSE left on at end of line, turning off now\n"));
287
"BOLD left on at end of line, turning off now\n"));
292
"UNDERLINE left on at end of line, turning off now\n"));
296
pico_set_normal_color();
301
/*----------------------------------------------------------------------
302
Printf style output line to the screen at given position, 1 arg
304
Input: position on the screen
305
line of text to output
307
Result: text is output
308
cursor position is update
309
----------------------------------------------------------------------*/
312
PutLine1(int x, int y, char *line, void *arg1)
314
char buffer[PUTLINE_BUFLEN];
316
snprintf(buffer, sizeof(buffer), line, arg1);
317
buffer[sizeof(buffer)-1] = '\0';
318
PutLine0(x, y, buffer);
322
/*----------------------------------------------------------------------
323
Printf style output line to the screen at given position, 2 args
325
Input: position on the screen
326
line of text to output
328
Result: text is output
329
cursor position is update
330
----------------------------------------------------------------------*/
333
PutLine2(int x, int y, char *line, void *arg1, void *arg2)
335
char buffer[PUTLINE_BUFLEN];
337
snprintf(buffer, sizeof(buffer), line, arg1, arg2);
338
buffer[sizeof(buffer)-1] = '\0';
339
PutLine0(x, y, buffer);
343
/*----------------------------------------------------------------------
344
Printf style output line to the screen at given position, 3 args
346
Input: position on the screen
347
line of text to output
349
Result: text is output
350
cursor position is update
351
----------------------------------------------------------------------*/
354
PutLine3(int x, int y, char *line, void *arg1, void *arg2, void *arg3)
356
char buffer[PUTLINE_BUFLEN];
358
snprintf(buffer, sizeof(buffer), line, arg1, arg2, arg3);
359
buffer[sizeof(buffer)-1] = '\0';
360
PutLine0(x, y, buffer);
364
/*----------------------------------------------------------------------
365
Printf style output line to the screen at given position, 4 args
367
Args: x -- column position on the screen
368
y -- column position on the screen
369
line -- printf style line of text to output
371
Result: text is output
372
cursor position is update
373
----------------------------------------------------------------------*/
376
PutLine4(int x, int y, char *line, void *arg1, void *arg2, void *arg3, void *arg4)
378
char buffer[PUTLINE_BUFLEN];
380
snprintf(buffer, sizeof(buffer), line, arg1, arg2, arg3, arg4);
381
buffer[sizeof(buffer)-1] = '\0';
382
PutLine0(x, y, buffer);
387
/*----------------------------------------------------------------------
388
Printf style output line to the screen at given position, 5 args
390
Args: x -- column position on the screen
391
y -- column position on the screen
392
line -- printf style line of text to output
394
Result: text is output
395
cursor position is update
396
----------------------------------------------------------------------*/
399
PutLine5(int x, int y, char *line, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5)
401
char buffer[PUTLINE_BUFLEN];
403
snprintf(buffer, sizeof(buffer), line, arg1, arg2, arg3, arg4, arg5);
404
buffer[sizeof(buffer)-1] = '\0';
405
PutLine0(x, y, buffer);
409
/*----------------------------------------------------------------------
410
Output a UTF-8 line to the screen, centered
412
Input: Line number to print on, string to output
414
Result: String is output to screen
415
Returns column number line is output on
416
----------------------------------------------------------------------*/
418
Centerline(int line, char *string)
422
width = (int) utf8_width(string);
424
if (width > ps_global->ttyo->screen_cols)
427
col = (ps_global->ttyo->screen_cols - width) / 2;
429
PutLine0(line, col, string);
436
/*----------------------------------------------------------------------
437
Clear specified line on the screen
439
Result: The line is blanked and the cursor is left at column 0.
445
if(ps_global->in_init_seq)
454
/*----------------------------------------------------------------------
455
Clear specified lines on the screen
457
Result: The lines starting at 'x' and ending at 'y' are blanked
458
and the cursor is left at row 'x', column 0
462
ClearLines(int x, int y)
466
for(i = x; i <= y; i++)
474
/*----------------------------------------------------------------------
475
Indicate to the screen painting here that the position of the cursor
476
has been disturbed and isn't where these functions might think.
479
clear_cursor_pos(void)
486
/*----------------------------------------------------------------------
487
Write a character to the screen, keeping track of cursor position
489
Args: ch -- character to output. The stream of characters coming to
490
this function is expected to be UTF-8. State is kept between
491
calls in order to collect up the octets needed for a single
494
Result: character output
495
cursor position variables updated
498
Writechar(register unsigned int ch, int new_esc_len)
500
static unsigned char cbuf[6];
501
static unsigned char *cbufp = cbuf;
502
int printable_ascii = 0;
504
if(cbufp < cbuf+sizeof(cbuf)){
505
unsigned char *inputp;
506
unsigned long remaining_octets;
509
*cbufp++ = (unsigned char) ch;
511
remaining_octets = (cbufp - cbuf) * sizeof(unsigned char);
512
if(remaining_octets == 1 && isascii(*cbuf)
513
&& (isprint(*cbuf) || *cbuf == LINE_FEED
514
|| *cbuf == RETURN || *cbuf == BACKSPACE
515
|| *cbuf == BELL || *cbuf == TAB)){
516
/* shortcut common case */
519
printable_ascii++; /* just for efficiency */
523
* we could use mbtow(utf8_charset, ...)
524
* here to lend an air of portability, then use the CCONV_
525
* constants for the return values. However, we know we are
526
* dealing with UTF-8 so we can skip straight to the
527
* correct function instead.
529
ucs = (UCS) utf8_get(&inputp, &remaining_octets);
532
case U8G_BADCONT: /* continuation at start of char */
533
case U8G_NOTUTF8: /* invalid character */
534
case U8G_INCMPLT: /* incomplete character */
537
* None of these cases is supposed to happen. If it
538
* does happen then the input stream isn't UTF-8
539
* so something is wrong. Treat each character in the
540
* input buffer as a separate error character and
541
* print a '?' for each.
543
for(inputp = cbuf; inputp < cbufp; inputp++){
546
if(_col + width < ps_global->ttyo->screen_cols){
552
cbufp = cbuf; /* start over */
555
case U8G_ENDSTRG: /* incomplete character, wait */
556
case U8G_ENDSTRI: /* incomplete character, wait */
560
/* got a character */
563
/* update the input buffer */
564
if(inputp >= cbufp) /* this should be the case */
566
else{ /* extra chars for some reason? */
567
unsigned char *q, *newcbufp;
569
newcbufp = (cbufp - inputp) + cbuf;
571
while(inputp < cbufp)