|
| |||||||||||||
#include "mit-copyright.h"#include "main.h"#include "new_string.h"#include "string_dictionary_aux.h"#include "formatter.h"#include "error.h"Go to the source code of this file.
Data Structures | |
| struct | _tty_str_info |
Defines | |
| #define | TD_SET(k, v) |
| #define | EXPAND(k) |
| #define | max(a, b) ((a)>(b)?(a):(b)) |
Typedefs | |
| typedef _tty_str_info | tty_str_info |
Functions | |
| int | tgetent () |
| char * | tgetstr () |
| char ** | getenv () |
| void | tputs () |
| int | tty_filter_init (char *drivername, char notfirst, int *pargc, char **argv) |
| string | tty_filter (string text, int use_fonts) |
Variables | |
| short | ospeed |
| char | PC |
|
|
Value: Definition at line 61 of file tty_filter.c. Referenced by tty_filter_init(). |
|
|
Definition at line 382 of file tty_filter.c. Referenced by fixup_and_draw(). |
|
|
Value: (string_dictionary_Define(termcap_dict, (k), &ex)->value \ = (v)) Definition at line 59 of file tty_filter.c. Referenced by tty_filter_init(). |
|
|
Referenced by tty_filter(). |
|
|
|
Referenced by tty_filter_init(). |
|
|
Referenced by tty_filter_init(). |
|
|
|
|
||||||||||||
|
Definition at line 441 of file tty_filter.c. References _tty_str_info::alignment, _tty_str_info::bold_p, desctype, disp_get_cmds(), dOutput, dprintf(), free_desc(), _tty_str_info::ignore, _tty_str_info::italic_p, _tty_str_info::len, _tty_str_info::next, _tty_str_info::str, string, string_Concat2, string_Copy, string_CreateFromData, string_dictionary_Fetch(), string_Length, and tty_str_info. 00444 {
00445 string text_copy = string_Copy(text);
00446 string result_so_far = string_Copy("");
00447 desctype *desc;
00448 int number_of_strs;
00449 int number_of_lines;
00450 tty_str_info *info;
00451 int max_line_width;
00452
00453 desc = disp_get_cmds(text_copy, &number_of_strs, &number_of_lines);
00454 info = convert_desc_to_tty_str_info(desc);
00455 free_desc(desc);
00456
00457 max_line_width = calc_max_line_width(info);
00458 dprintf(dOutput, "max width = %d\n", max_line_width);
00459
00460 while (info) {
00461 string left, center, right;
00462 int left_width, center_width, right_width;
00463 char *temp;
00464
00465 left_width = center_width = right_width = 0;
00466 left = string_Copy("");
00467 center = string_Copy("");
00468 right = string_Copy("");
00469
00470 for (; info && info->alignment != ' '; info = info->next) {
00471 string item;
00472
00473 if (info->ignore)
00474 continue;
00475
00476 item = string_Copy("");
00477
00478 if (info->bold_p && use_fonts) {
00479 if ((temp = string_dictionary_Fetch(termcap_dict, "B.bold")))
00480 item = string_Concat2(item, temp);
00481 }
00482 else if (info->italic_p && use_fonts) {
00483 if ((temp = string_dictionary_Fetch(termcap_dict, "B.u")))
00484 item = string_Concat2(item, temp);
00485 }
00486 temp = string_CreateFromData(info->str, info->len);
00487 item = string_Concat2(item, temp);
00488 free(temp);
00489
00490 if (info->bold_p && use_fonts) {
00491 if ((temp = string_dictionary_Fetch(termcap_dict, "E.bold")))
00492 item = string_Concat2(item, temp);
00493 }
00494 else if (info->italic_p && use_fonts) {
00495 if ((temp = string_dictionary_Fetch(termcap_dict, "E.u")))
00496 item = string_Concat2(item, temp);
00497 }
00498
00499 switch (info->alignment) {
00500 default:
00501 case 'l':
00502 left = string_Concat2(left, item);
00503 left_width += info->len;
00504 break;
00505
00506 case 'c':
00507 center = string_Concat2(center, item);
00508 center_width += info->len;
00509 break;
00510
00511 case 'r':
00512 right = string_Concat2(right, item);
00513 right_width += info->len;
00514 break;
00515 }
00516 free(item);
00517 }
00518
00519 result_so_far = string_Concat2(result_so_far, left);
00520 if (center_width)
00521 while (left_width < (max_line_width - center_width) / 2) {
00522 result_so_far = string_Concat2(result_so_far, " ");
00523 left_width++;
00524 }
00525 result_so_far = string_Concat2(result_so_far, center);
00526 left_width += center_width;
00527
00528 if (right_width)
00529 while (left_width < max_line_width - right_width) {
00530 result_so_far = string_Concat2(result_so_far, " ");
00531 left_width++;
00532 }
00533 result_so_far = string_Concat2(result_so_far, right);
00534 free(left);
00535 free(center);
00536 free(right);
00537
00538 if (info && info->alignment == ' ') {
00539 info = info->next;
00540 result_so_far = string_Concat2(result_so_far, "\r\n");
00541 }
00542 }
00543
00544 free_info(info);
00545 free(text_copy);
00546 if (number_of_lines &&
00547 (result_so_far[string_Length(result_so_far) - 1] != '\n'))
00548 /* CRLF-terminate all results */
00549 result_so_far = string_Concat2(result_so_far, "\r\n");
00550 return (result_so_far);
00551 }
|
|
||||||||||||||||||||
|
Definition at line 74 of file tty_filter.c. References ERROR, EXPAND, getenv(), NULL, ospeed, PC, string_dictionary, string_dictionary_binding, string_dictionary_Create(), string_dictionary_Lookup(), string_Eq, TD_SET, tgetent(), tgetstr(), and _string_dictionary_binding::value. 00079 {
00080 static char st_buf[128];
00081 char tc_buf[1024], *p = st_buf, *tmp, *term;
00082 int ex;
00083 string_dictionary_binding *b;
00084 int isrealtty = string_Eq(drivername, "tty");
00085 #ifdef HAVE_TERMIOS_H
00086 struct termios tbuf;
00087
00088 ospeed = (tcgetattr(STDIN_FILENO, &tbuf) == 0) ? cfgetospeed(&tbuf) : 2400;
00089 #else
00090 struct sgttyb sgttyb;
00091
00092 ospeed = (ioctl(0, TIOCGETP, &sgttyb) == 0) ? sgttyb.sg_ospeed : 2400;
00093 #endif
00094
00095 if (termcap_dict == (string_dictionary) NULL)
00096 termcap_dict = string_dictionary_Create(7);
00097
00098 if (!(term = getenv("TERM"))) { /* Only use termcap if $TERM. */
00099 if (isrealtty && !notfirst)
00100 /*
00101 * only complain if initializing tty mode, and would
00102 * be first available port
00103 */
00104 ERROR("$TERM not set. tty mode will be plain.\n");
00105 }
00106 #ifdef _AIX
00107 /*
00108 * This is a temporary KLUDGE to get around the problem where some
00109 * people might start jwgc in their ~/.startup.X and it hangs on the
00110 * RISC/6000. Apparently, the call to tgetent() with the Athena
00111 * console window causes the process to get stopped on tty access.
00112 * Since the terminal type is "dumb" (set by tcsh), we can pretty
00113 * much assume there isn't anything to setup from the termcap
00114 * information.
00115 */
00116 else if (!strcmp(term, "dumb")) {
00117 }
00118 #endif
00119 else {
00120 tgetent(tc_buf, term);
00121
00122 /*
00123 * Step 1: get all of {rv,bold,u,bell,blink} that are
00124 * available.
00125 */
00126
00127 /*
00128 * We cheat here, and ignore the padding (if any) specified
00129 * for the mode-change strings (it's a real pain to do
00130 * "right")
00131 */
00132
00133 tmp = tgetstr("pc", &p);
00134 PC = (tmp) ? *tmp : 0;
00135 if ((tmp = tgetstr("md", &p))) { /* bold ? */
00136 EXPAND("B.bold");
00137 tmp = tgetstr("me", &p);
00138 EXPAND("E.bold");
00139 }
00140 if ((tmp = tgetstr("mr", &p))) { /* reverse video? */
00141 EXPAND("B.rw");
00142 tmp = tgetstr("me", &p);
00143 EXPAND("E.rw");
00144 }
00145 if ((tmp = tgetstr("bl", &p))) { /* Bell ? */
00146 EXPAND("B.bell");
00147 TD_SET("E.bell", NULL);
00148 }
00149 if ((tmp = tgetstr("mb", &p))) { /* Blink ? */
00150 EXPAND("B.blink");
00151 tmp = tgetstr("me", &p);
00152 EXPAND("E.blink");
00153 }
00154 if ((tmp = tgetstr("us", &p))) { /* Underline ? */
00155 EXPAND("B.u");
00156 tmp = tgetstr("ue", &p);
00157 EXPAND("E.u");
00158 }
00159 if ((tmp = tgetstr("so", &p))) { /* Standout ? */
00160 EXPAND("B.so");
00161 tmp = tgetstr("se", &p);
00162 EXPAND("E.so");
00163 }
00164 }
00165 /* Step 2: alias others to the nearest substitute */
00166
00167 /* Bold = so, else rv, else ul */
00168 if (NULL == string_dictionary_Lookup(termcap_dict, "B.bold")) {
00169 if ((b = string_dictionary_Lookup(termcap_dict, "B.so"))) {
00170 TD_SET("B.bold", b->value);
00171 TD_SET("E.bold",
00172 string_dictionary_Lookup(termcap_dict, "E.so")->value);
00173 }
00174 else if ((b = string_dictionary_Lookup(termcap_dict, "B.rv"))) {
00175 TD_SET("B.bold", b->value);
00176 TD_SET("E.bold",
00177 string_dictionary_Lookup(termcap_dict, "E.rv")->value);
00178 }
00179 else if ((b = string_dictionary_Lookup(termcap_dict, "B.u"))) {
00180 TD_SET("B.bold", b->value);
00181 TD_SET("E.bold",
00182 string_dictionary_Lookup(termcap_dict, "E.u")->value);
00183 }
00184 }
00185
00186 /* Bell = ^G */
00187 if (NULL == string_dictionary_Lookup(termcap_dict, "B.bell")) {
00188 TD_SET("B.bell", "\007");
00189 TD_SET("E.bell", NULL);
00190 }
00191
00192 /* Underline -> nothing */
00193 /* Blink -> nothing */
00194
00195 return (0);
00196 }
|
|
|
Definition at line 28 of file tty_filter.c. Referenced by tty_filter_init(). |
|
|
Definition at line 29 of file tty_filter.c. Referenced by tty_filter_init(). |
| Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |