1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: termout.gen.c 1012 2008-03-26 00:44:22Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2006-2008 University of Washington
8 * Copyright 2013-2016 Eduardo Chappa
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
21 #include "../../c-client/mail.h" /* for MAILSTREAM and friends */
22 #include "../../c-client/osdep.h"
23 #include "../../c-client/rfc822.h" /* for soutr_t and such */
24 #include "../../c-client/misc.h" /* for cpystr proto */
25 #include "../../c-client/utf8.h" /* for CHARSET and such*/
26 #include "../../c-client/imap4r1.h"
28 #include "../../pith/osdep/color.h"
29 #include "../../pith/charconv/filesys.h"
31 #include "../../pith/debug.h"
32 #include "../../pith/newmail.h"
33 #include "../../pith/filter.h"
34 #include "../../pith/handle.h"
35 #include "../../pith/conf.h"
36 #include "../../pith/mimedesc.h"
38 #include "../../pico/estruct.h"
39 #include "../../pico/pico.h"
40 #include "../../pico/keydefs.h"
41 #include "../../pico/osdep/color.h"
43 #include "../status.h"
45 #include "../folder.h"
46 #include "../keymenu.h"
48 #include "../mailindx.h"
53 #include "termout.gen.h"
56 #define PUTLINE_BUFLEN 256
61 * Generic tty output routines...
64 /*----------------------------------------------------------------------
65 Printf style output line to the screen at given position, 0 args
67 Args: x -- column position on the screen
68 y -- row position on the screen
69 line -- line of text to output
71 Result: text is output
72 cursor position is update
75 PutLine0(int x
, int y
, register char *line
)
78 Write_to_screen(line
);
83 /*----------------------------------------------------------------------
84 Output line of length len to the display observing embedded attributes
86 Args: x -- column position on the screen
87 y -- column position on the screen
88 line -- text to be output
89 length -- length of text to be output
91 Result: text is output
92 cursor position is updated
93 ----------------------------------------------------------------------*/
95 PutLine0n8b(int x
, int y
, register char *line
, int length
, HANDLE_S
*handles
)
98 int is_inv
= 0, is_bold
= 0, is_uline
= 0, is_fg
= 0, is_bg
= 0;
107 c
= (unsigned char) *line
++;
109 if(c
== (unsigned char) TAG_EMBED
&& length
){
134 case TAG_ITALICON
: /* express italic as uline in terminal */
140 case TAG_ITALICOFF
: /* express italic as uline in terminal */
147 length
-= *line
+ 1; /* key length plus length tag */
149 int key
, n
, current_key
= 0;
151 for(key
= 0, n
= *line
++; n
; n
--) /* forget Horner? */
152 key
= (key
* 10) + (*line
++ - '0');
158 if(handles
->using_is_used
){
161 for(h
= handles
; h
; h
= h
->next
)
166 current_key
= h
->key
;
169 current_key
= handles
->key
;
171 if(key
== current_key
){
172 COLOR_PAIR
*curcolor
= NULL
;
173 COLOR_PAIR
*revcolor
= NULL
;
175 if(handles
->color_unseen
176 && (curcolor
= pico_get_cur_color())
177 && (colorcmp(curcolor
->fg
, ps_global
->VAR_NORM_FORE_COLOR
)
178 || colorcmp(curcolor
->bg
, ps_global
->VAR_NORM_BACK_COLOR
))
179 && (revcolor
= apply_rev_color(curcolor
,
180 ps_global
->index_color_style
)))
181 (void) pico_set_colorp(revcolor
, PSC_NONE
);
184 if(pico_usingcolor() &&
185 ps_global
->VAR_SLCTBL_FORE_COLOR
&&
186 ps_global
->VAR_SLCTBL_BACK_COLOR
){
187 pico_set_normal_color();
197 free_color_pair(&curcolor
);
200 free_color_pair(&revcolor
);
213 "FGCOLOR not proper length, ignoring\n"));
218 (void)pico_set_fg_color(line
);
227 "BGCOLOR not proper length, ignoring\n"));
232 (void)pico_set_bg_color(line
);
238 case TAG_EMBED
: /* literal "embed" char */
239 Writechar(TAG_EMBED
, 0);
242 case TAG_STRIKEON
: /* unsupported text markup */
248 default : /* Eat unrecognized tag - TAG_BIGON, etc */
250 } /* tag with handle, skip it */
259 char *tmp_file
= NULL
, ext
[32], mtype
[128];
261 extern HANDLE_S
*get_handle (HANDLE_S
*, int);
263 if((h
= get_handle(handles
, hkey
)) && h
->type
== Attach
){
265 strncpy(mtype
, body_type_names(h
->h
.attach
->body
->type
), sizeof(mtype
));
266 mtype
[sizeof(mtype
)-1] = '\0';
267 if (h
->h
.attach
->body
->subtype
) {
268 strncat (mtype
, "/", sizeof(mtype
)-strlen(mtype
)-1);
269 mtype
[sizeof(mtype
)-1] = '\0';
270 strncat (mtype
, h
->h
.attach
->body
->subtype
, sizeof(mtype
)-strlen(mtype
)-1);
271 mtype
[sizeof(mtype
)-1] = '\0';
274 if(!set_mime_extension_by_type(ext
, mtype
)){
275 char *p
, *extp
= NULL
;
277 if((p
= get_filename_parameter(NULL
, 0, h
->h
.attach
->body
, &extp
)) != NULL
){
279 strncpy(ext
, extp
, sizeof(ext
));
280 ext
[sizeof(ext
)-1] = '\0';
283 fs_give((void **) &p
);
287 if(ext
[0] && (tmp_file
= temp_nam_ext(NULL
, "im", ext
))){
288 FILE *f
= our_fopen(tmp_file
, "w");
290 mswin_registericon(x
, h
->key
, tmp_file
);
293 our_unlink(tmp_file
);
294 fs_give((void **)&tmp_file
);
301 "INVERSE left on at end of line, turning off now\n"));
306 "BOLD left on at end of line, turning off now\n"));
311 "UNDERLINE left on at end of line, turning off now\n"));
315 pico_set_normal_color();
320 /*----------------------------------------------------------------------
321 Printf style output line to the screen at given position, 1 arg
323 Input: position on the screen
324 line of text to output
326 Result: text is output
327 cursor position is update
328 ----------------------------------------------------------------------*/
331 PutLine1(int x
, int y
, char *line
, void *arg1
)
333 char buffer
[PUTLINE_BUFLEN
];
335 snprintf(buffer
, sizeof(buffer
), line
, arg1
);
336 buffer
[sizeof(buffer
)-1] = '\0';
337 PutLine0(x
, y
, buffer
);
341 /*----------------------------------------------------------------------
342 Printf style output line to the screen at given position, 2 args
344 Input: position on the screen
345 line of text to output
347 Result: text is output
348 cursor position is update
349 ----------------------------------------------------------------------*/
352 PutLine2(int x
, int y
, char *line
, void *arg1
, void *arg2
)
354 char buffer
[PUTLINE_BUFLEN
];
356 snprintf(buffer
, sizeof(buffer
), line
, arg1
, arg2
);
357 buffer
[sizeof(buffer
)-1] = '\0';
358 PutLine0(x
, y
, buffer
);
362 /*----------------------------------------------------------------------
363 Printf style output line to the screen at given position, 3 args
365 Input: position on the screen
366 line of text to output
368 Result: text is output
369 cursor position is update
370 ----------------------------------------------------------------------*/
373 PutLine3(int x
, int y
, char *line
, void *arg1
, void *arg2
, void *arg3
)
375 char buffer
[PUTLINE_BUFLEN
];
377 snprintf(buffer
, sizeof(buffer
), line
, arg1
, arg2
, arg3
);
378 buffer
[sizeof(buffer
)-1] = '\0';
379 PutLine0(x
, y
, buffer
);
383 /*----------------------------------------------------------------------
384 Printf style output line to the screen at given position, 4 args
386 Args: x -- column position on the screen
387 y -- column position on the screen
388 line -- printf style line of text to output
390 Result: text is output
391 cursor position is update
392 ----------------------------------------------------------------------*/
395 PutLine4(int x
, int y
, char *line
, void *arg1
, void *arg2
, void *arg3
, void *arg4
)
397 char buffer
[PUTLINE_BUFLEN
];
399 snprintf(buffer
, sizeof(buffer
), line
, arg1
, arg2
, arg3
, arg4
);
400 buffer
[sizeof(buffer
)-1] = '\0';
401 PutLine0(x
, y
, buffer
);
406 /*----------------------------------------------------------------------
407 Printf style output line to the screen at given position, 5 args
409 Args: x -- column position on the screen
410 y -- column position on the screen
411 line -- printf style line of text to output
413 Result: text is output
414 cursor position is update
415 ----------------------------------------------------------------------*/
418 PutLine5(int x
, int y
, char *line
, void *arg1
, void *arg2
, void *arg3
, void *arg4
, void *arg5
)
420 char buffer
[PUTLINE_BUFLEN
];
422 snprintf(buffer
, sizeof(buffer
), line
, arg1
, arg2
, arg3
, arg4
, arg5
);
423 buffer
[sizeof(buffer
)-1] = '\0';
424 PutLine0(x
, y
, buffer
);
428 /*----------------------------------------------------------------------
429 Output a UTF-8 line to the screen, centered
431 Input: Line number to print on, string to output
433 Result: String is output to screen
434 Returns column number line is output on
435 ----------------------------------------------------------------------*/
437 Centerline(int line
, char *string
)
441 width
= (int) utf8_width(string
);
443 if (width
> ps_global
->ttyo
->screen_cols
)
446 col
= (ps_global
->ttyo
->screen_cols
- width
) / 2;
448 PutLine0(line
, col
, string
);
455 /*----------------------------------------------------------------------
456 Clear specified line on the screen
458 Result: The line is blanked and the cursor is left at column 0.
464 if(ps_global
->in_init_seq
)
473 /*----------------------------------------------------------------------
474 Clear specified lines on the screen
476 Result: The lines starting at 'x' and ending at 'y' are blanked
477 and the cursor is left at row 'x', column 0
481 ClearLines(int x
, int y
)
485 for(i
= x
; i
<= y
; i
++)
493 /*----------------------------------------------------------------------
494 Indicate to the screen painting here that the position of the cursor
495 has been disturbed and isn't where these functions might think.
498 clear_cursor_pos(void)
505 /*----------------------------------------------------------------------
506 Write a character to the screen, keeping track of cursor position
508 Args: ch -- character to output. The stream of characters coming to
509 this function is expected to be UTF-8. State is kept between
510 calls in order to collect up the octets needed for a single
513 Result: character output
514 cursor position variables updated
517 Writechar(unsigned int ch
, int new_esc_len
)
519 static unsigned char cbuf
[6];
520 static unsigned char *cbufp
= cbuf
;
522 if(cbufp
< cbuf
+sizeof(cbuf
)){
523 unsigned char *inputp
;
524 unsigned long remaining_octets
;
527 *cbufp
++ = (unsigned char) ch
;
529 remaining_octets
= (cbufp
- cbuf
) * sizeof(unsigned char);
530 ucs
= (UCS
) utf8_get(&inputp
, &remaining_octets
);
533 case U8G_ENDSTRG
: /* incomplete character, wait */
534 case U8G_ENDSTRI
: /* incomplete character, wait */
538 if(ucs
& U8G_ERROR
|| ucs
== UBOGON
){
540 * None of these cases is supposed to happen. If it
541 * does happen then the input stream isn't UTF-8
542 * so something is wrong. Treat each character in the
543 * input buffer as a separate error character and
544 * print a '?' for each.
546 for(inputp
= cbuf
; inputp
< cbufp
; inputp
++){
549 if(_col
+ width
<= ps_global
->ttyo
->screen_cols
){
555 cbufp
= cbuf
; /* start over */
559 /* got a good character */
562 /* update the input buffer */
563 if(inputp
>= cbufp
) /* this should be the case */
565 else{ /* extra chars for some reason? */
566 unsigned char *q
, *newcbufp
;
568 newcbufp
= (cbufp
- inputp
) + cbuf
;
570 while(inputp
< cbufp
)
582 cbufp
= cbuf
; /* start over */