| 1 |
/* $Id: printer.c,v 1.11 2024/12/05 00:37:39 tom Exp $ */ |
| 2 |
|
| 3 |
#include <vttest.h> |
| 4 |
#include <esc.h> |
| 5 |
|
| 6 |
static int pex_mode; |
| 7 |
static int pff_mode; |
| 8 |
static int started; |
| 9 |
static int assigned; |
| 10 |
static int margin_lo; |
| 11 |
static int margin_hi; |
| 12 |
|
| 13 |
static void |
| 14 |
setup_printout(MENU_ARGS, int visible, const char *whole) |
| 15 |
{ |
| 16 |
margin_lo = 7; |
| 17 |
margin_hi = max_lines - 5; |
| 18 |
|
| 19 |
vt_clear(2); |
| 20 |
cup(1, 1); |
| 21 |
println(the_title); |
| 22 |
println("Test screen for printing. We will set scrolling margins at"); |
| 23 |
printxx("lines %d and %d, and write a test pattern there.\n", margin_lo, margin_hi); |
| 24 |
printxx("The test pattern should be %s.\n", visible |
| 25 |
? "visible" |
| 26 |
: "invisible"); |
| 27 |
printxx("The %s should be in the printer's output.\n", whole); |
| 28 |
decstbm(margin_lo, margin_hi); |
| 29 |
cup(margin_lo, 1); |
| 30 |
} |
| 31 |
|
| 32 |
static void |
| 33 |
test_printout(void) |
| 34 |
{ |
| 35 |
int row, col; |
| 36 |
vt_move(margin_hi, 1); |
| 37 |
for (row = 0; row < max_lines; row++) { |
| 38 |
tprintf("%3d:", row); |
| 39 |
for (col = 0; col < min_cols - 5; col++) { |
| 40 |
tprintf("%c", ((row + col) % 26) + 'a'); |
| 41 |
} |
| 42 |
tprintf("\n"); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
static void |
| 47 |
cleanup_printout(void) |
| 48 |
{ |
| 49 |
decstbm(0, 0); |
| 50 |
vt_move(max_lines - 2, 1); |
| 51 |
} |
| 52 |
|
| 53 |
static int |
| 54 |
tst_Assign(MENU_ARGS) |
| 55 |
{ |
| 56 |
mc_printer_assign(assigned = !assigned); |
| 57 |
return MENU_HOLD; |
| 58 |
} |
| 59 |
|
| 60 |
static int |
| 61 |
tst_DECPEX(MENU_ARGS) |
| 62 |
{ |
| 63 |
decpex(pex_mode = !pex_mode); |
| 64 |
return MENU_HOLD; |
| 65 |
} |
| 66 |
|
| 67 |
static int |
| 68 |
tst_DECPFF(MENU_ARGS) |
| 69 |
{ |
| 70 |
decpff(pff_mode = !pff_mode); |
| 71 |
return MENU_HOLD; |
| 72 |
} |
| 73 |
|
| 74 |
static int |
| 75 |
tst_Start(MENU_ARGS) |
| 76 |
{ |
| 77 |
mc_printer_start(started = !started); |
| 78 |
return MENU_HOLD; |
| 79 |
} |
| 80 |
|
| 81 |
static int |
| 82 |
tst_autoprint(MENU_ARGS) |
| 83 |
{ |
| 84 |
setup_printout(PASS_ARGS, TRUE, "scrolling region"); |
| 85 |
mc_autoprint(TRUE); |
| 86 |
test_printout(); |
| 87 |
mc_autoprint(FALSE); |
| 88 |
cleanup_printout(); |
| 89 |
return MENU_HOLD; |
| 90 |
} |
| 91 |
|
| 92 |
static int |
| 93 |
tst_printer_controller(MENU_ARGS) |
| 94 |
{ |
| 95 |
setup_printout(PASS_ARGS, FALSE, "scrolling region"); |
| 96 |
mc_printer_controller(TRUE); |
| 97 |
test_printout(); |
| 98 |
mc_printer_controller(FALSE); |
| 99 |
cleanup_printout(); |
| 100 |
return MENU_HOLD; |
| 101 |
} |
| 102 |
|
| 103 |
static int |
| 104 |
tst_print_all_pages(MENU_ARGS) |
| 105 |
{ |
| 106 |
setup_printout(PASS_ARGS, TRUE, "contents of all pages"); |
| 107 |
test_printout(); |
| 108 |
mc_print_all_pages(); |
| 109 |
cleanup_printout(); |
| 110 |
return MENU_HOLD; |
| 111 |
} |
| 112 |
|
| 113 |
static int |
| 114 |
tst_print_cursor(MENU_ARGS) |
| 115 |
{ |
| 116 |
int row; |
| 117 |
setup_printout(PASS_ARGS, TRUE, "reverse of the scrolling region"); |
| 118 |
test_printout(); |
| 119 |
for (row = margin_hi; row >= margin_lo; row--) { |
| 120 |
vt_move(row, 1); |
| 121 |
mc_print_cursor_line(); |
| 122 |
} |
| 123 |
cleanup_printout(); |
| 124 |
return MENU_HOLD; |
| 125 |
} |
| 126 |
|
| 127 |
static int |
| 128 |
tst_print_display(MENU_ARGS) |
| 129 |
{ |
| 130 |
setup_printout(PASS_ARGS, TRUE, "whole display"); |
| 131 |
test_printout(); |
| 132 |
mc_print_composed(); |
| 133 |
cleanup_printout(); |
| 134 |
return MENU_HOLD; |
| 135 |
} |
| 136 |
|
| 137 |
static int |
| 138 |
tst_print_page(MENU_ARGS) |
| 139 |
{ |
| 140 |
setup_printout(PASS_ARGS, TRUE, |
| 141 |
pex_mode |
| 142 |
? "whole page" |
| 143 |
: "scrolling region"); |
| 144 |
test_printout(); |
| 145 |
mc_print_page(); |
| 146 |
cleanup_printout(); |
| 147 |
return MENU_HOLD; |
| 148 |
} |
| 149 |
|
| 150 |
int |
| 151 |
tst_printing(MENU_ARGS) |
| 152 |
{ |
| 153 |
static char pex_mesg[80]; |
| 154 |
static char pff_mesg[80]; |
| 155 |
static char assign_mesg[80]; |
| 156 |
static char start_mesg[80]; |
| 157 |
/* *INDENT-OFF* */ |
| 158 |
static MENU my_menu[] = { |
| 159 |
{ "Exit", NULL }, |
| 160 |
{ assign_mesg, tst_Assign }, |
| 161 |
{ start_mesg, tst_Start }, |
| 162 |
{ pex_mesg, tst_DECPEX }, |
| 163 |
{ pff_mesg, tst_DECPFF }, |
| 164 |
{ "Test Auto-print mode (MC - DEC private mode)", tst_autoprint }, |
| 165 |
{ "Test Printer-controller mode (MC)", tst_printer_controller }, |
| 166 |
{ "Test Print-page (MC)", tst_print_page }, |
| 167 |
{ "Test Print composed main-display (MC)", tst_print_display }, |
| 168 |
{ "Test Print all pages (MC)", tst_print_all_pages }, |
| 169 |
{ "Test Print cursor line (MC)", tst_print_cursor }, |
| 170 |
{ "", NULL } |
| 171 |
}; |
| 172 |
/* *INDENT-ON* */ |
| 173 |
|
| 174 |
do { |
| 175 |
sprintf(pex_mesg, "%s Printer-Extent mode (DECPEX)", STR_ENABLE(pex_mode)); |
| 176 |
sprintf(pff_mesg, "%s Print Form Feed Mode (DECPFF)", STR_ENABLE(pff_mode)); |
| 177 |
strcpy(assign_mesg, assigned |
| 178 |
? "Release printer (MC)" |
| 179 |
: "Assign printer to active session (MC)"); |
| 180 |
sprintf(start_mesg, "%s printer-to-host session (MC)", STR_START(started)); |
| 181 |
vt_clear(2); |
| 182 |
__(title(0), printxx("Printing-Control Tests")); |
| 183 |
__(title(2), println("Choose test type:")); |
| 184 |
} while (menu(my_menu)); |
| 185 |
|
| 186 |
if (pex_mode) { |
| 187 |
pex_mode = 0; |
| 188 |
decpex(pex_mode); |
| 189 |
} |
| 190 |
|
| 191 |
if (pff_mode) { |
| 192 |
pff_mode = 0; |
| 193 |
decpex(pff_mode); |
| 194 |
} |
| 195 |
|
| 196 |
if (assigned) { |
| 197 |
assigned = 0; |
| 198 |
mc_printer_start(assigned); |
| 199 |
} |
| 200 |
|
| 201 |
if (started) { |
| 202 |
started = 0; |
| 203 |
mc_printer_start(started); |
| 204 |
} |
| 205 |
|
| 206 |
return MENU_NOHOLD; |
| 207 |
} |