1 #if !defined(lint) && !defined(DOS)
2 static char rcsid
[] = "$Id: print.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2020 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 "confscroll.h"
25 #include "../pith/state.h"
26 #include "../pith/mailcmd.h"
32 void set_def_printer_value(char *);
33 int print_select_tool(struct pine
*, int, CONF_S
**, unsigned);
34 int print_edit_tool(struct pine
*, int, CONF_S
**, unsigned);
37 static char **def_printer_line
;
38 static char no_ff
[] = "-no-formfeed";
44 * Information used to paint and maintain a line on the configuration screen
46 /*----------------------------------------------------------------------
47 The printer selection screen
49 Draws the screen and prompts for the printer number and the custom
50 command if so selected.
54 select_printer(struct pine
*ps
, int edit_exceptions
)
56 struct variable
*vtmp
;
57 CONF_S
*ctmpa
= NULL
, *ctmpb
= NULL
, *heading
= NULL
,
60 int i
, saved_printer_cat
, readonly_warning
= 0, no_ex
;
61 SAVED_CONFIG_S
*vsave
;
62 char *saved_printer
, **lval
;
67 q_status_message(SM_ORDER
, 3, 7,
68 _("Exception Setup not implemented for printer"));
72 if(fixed_var(&ps_global
->vars
[V_PRINTER
], "change", "printer"))
75 ew
= edit_exceptions
? ps_global
->ew_for_except_vars
: Main
;
77 no_ex
= (ps_global
->ew_for_except_vars
== Main
);
93 readonly_warning
= prc
? prc
->readonly
: 1;
94 if(prc
&& prc
->quit_to_edit
){
95 quit_to_edit_msg(prc
);
100 saved_printer
= cpystr(ps
->VAR_PRINTER
);
101 saved_printer_cat
= ps
->printer_category
;
103 new_confline(&ctmpa
);
104 ctmpa
->valoffset
= 2;
105 ctmpa
->keymenu
= &printer_select_keymenu
;
106 ctmpa
->help
= NO_HELP
;
107 ctmpa
->tool
= print_select_tool
;
108 ctmpa
->flags
|= CF_NOSELECT
;
111 = cpystr("\"Select\" a port or |pipe-command as your default printer.");
113 = cpystr(_("You may \"Select\" a print command as your default printer."));
116 new_confline(&ctmpa
);
117 ctmpa
->valoffset
= 2;
118 ctmpa
->keymenu
= &printer_select_keymenu
;
119 ctmpa
->help
= NO_HELP
;
120 ctmpa
->tool
= print_select_tool
;
121 ctmpa
->flags
|= CF_NOSELECT
;
124 = cpystr("You may also add alternative ports or !pipes to the list in the");
126 = cpystr(_("You may also add custom print commands to the list in the"));
129 new_confline(&ctmpa
);
130 ctmpa
->valoffset
= 2;
131 ctmpa
->keymenu
= &printer_select_keymenu
;
132 ctmpa
->help
= NO_HELP
;
133 ctmpa
->tool
= print_select_tool
;
134 ctmpa
->flags
|= CF_NOSELECT
;
137 = cpystr("\"Personally selected port or |pipe\" section below.");
139 = cpystr(_("\"Personally selected print command\" section below."));
142 new_confline(&ctmpa
);
143 ctmpa
->valoffset
= 2;
144 ctmpa
->keymenu
= &printer_select_keymenu
;
145 ctmpa
->help
= NO_HELP
;
146 ctmpa
->tool
= print_select_tool
;
147 ctmpa
->flags
|= CF_NOSELECT
| CF_B_LINE
;
149 new_confline(&ctmpa
);
150 ctmpa
->valoffset
= 4;
151 ctmpa
->keymenu
= &printer_select_keymenu
;
152 ctmpa
->help
= NO_HELP
;
153 ctmpa
->tool
= print_select_tool
;
154 ctmpa
->flags
|= CF_NOSELECT
;
155 def_printer_line
= &ctmpa
->value
;
156 set_def_printer_value(ps
->VAR_PRINTER
);
158 new_confline(&ctmpa
);
159 ctmpa
->valoffset
= 2;
160 ctmpa
->keymenu
= &printer_select_keymenu
;
161 ctmpa
->help
= NO_HELP
;
162 ctmpa
->tool
= print_select_tool
;
163 ctmpa
->flags
|= CF_NOSELECT
| CF_B_LINE
;
166 new_confline(&ctmpa
);
168 ctmpa
->keymenu
= &printer_select_keymenu
;
169 ctmpa
->help
= NO_HELP
;
170 ctmpa
->tool
= print_select_tool
;
172 = cpystr(_(" Printer attached to IBM PC or compatible, Macintosh"));
173 ctmpa
->flags
|= (CF_NOSELECT
| CF_STARTITEM
);
174 ctmpa
->value
= cpystr("");
175 ctmpa
->headingp
= heading
;
177 new_confline(&ctmpa
);
178 ctmpa
->valoffset
= 6;
179 ctmpa
->keymenu
= &printer_select_keymenu
;
180 ctmpa
->help
= NO_HELP
;
181 ctmpa
->tool
= print_select_tool
;
182 ctmpa
->flags
|= CF_NOSELECT
;
184 = cpystr(_("This may not work with all attached printers, and will depend on the"));
185 ctmpa
->headingp
= heading
;
187 new_confline(&ctmpa
);
188 ctmpa
->valoffset
= 6;
189 ctmpa
->keymenu
= &printer_select_keymenu
;
190 ctmpa
->help
= NO_HELP
;
191 ctmpa
->tool
= print_select_tool
;
192 ctmpa
->flags
|= CF_NOSELECT
;
194 = cpystr(_("terminal emulation/communications software in use. It is known to work"));
195 ctmpa
->headingp
= heading
;
197 new_confline(&ctmpa
);
198 ctmpa
->valoffset
= 6;
199 ctmpa
->keymenu
= &printer_select_keymenu
;
200 ctmpa
->help
= NO_HELP
;
201 ctmpa
->tool
= print_select_tool
;
202 ctmpa
->flags
|= CF_NOSELECT
;
204 = cpystr("with Kermit and the latest UW version of NCSA telnet on Macs and PCs,");
205 ctmpa
->headingp
= heading
;
207 new_confline(&ctmpa
);
208 ctmpa
->valoffset
= 6;
209 ctmpa
->keymenu
= &printer_select_keymenu
;
210 ctmpa
->help
= NO_HELP
;
211 ctmpa
->tool
= print_select_tool
;
212 ctmpa
->flags
|= CF_NOSELECT
;
214 = cpystr("Versaterm Pro on Macs, and WRQ Reflections on PCs.");
215 ctmpa
->headingp
= heading
;
217 new_confline(&ctmpa
);
218 start_line
= ctmpb
= ctmpa
; /* default start line */
219 ctmpa
->valoffset
= 17;
220 ctmpa
->keymenu
= &printer_select_keymenu
;
221 ctmpa
->help
= h_config_set_att_ansi
;
222 ctmpa
->tool
= print_select_tool
;
223 ctmpa
->flags
|= CF_NOHILITE
;
224 ctmpa
->varoffset
= 8;
225 ctmpa
->varname
= cpystr("Printer:");
226 ctmpa
->value
= cpystr(ANSI_PRINTER
);
227 ctmpa
->varnamep
= ctmpb
;
228 ctmpa
->headingp
= heading
;
230 new_confline(&ctmpa
);
231 ctmpa
->valoffset
= 17;
232 ctmpa
->keymenu
= &printer_select_keymenu
;
233 ctmpa
->help
= h_config_set_att_ansi2
;
234 ctmpa
->tool
= print_select_tool
;
235 ctmpa
->flags
|= CF_NOHILITE
;
236 ctmpa
->varoffset
= 8;
237 l
= strlen(ANSI_PRINTER
)+strlen(no_ff
);
238 ctmpa
->value
= (char *)fs_get((l
+1) * sizeof(char));
239 ctmpa
->varnamep
= ctmpb
;
240 ctmpa
->headingp
= heading
;
241 snprintf(ctmpa
->value
, l
+1, "%s%s", ANSI_PRINTER
, no_ff
);
242 ctmpa
->value
[l
] = '\0';
244 new_confline(&ctmpa
);
245 ctmpa
->valoffset
= 17;
246 ctmpa
->keymenu
= &printer_select_keymenu
;
247 ctmpa
->help
= h_config_set_att_wyse
;
248 ctmpa
->tool
= print_select_tool
;
249 ctmpa
->flags
|= CF_NOHILITE
;
250 ctmpa
->varoffset
= 8;
251 ctmpa
->value
= cpystr(WYSE_PRINTER
);
252 ctmpa
->varnamep
= ctmpb
;
253 ctmpa
->headingp
= heading
;
255 new_confline(&ctmpa
);
256 ctmpa
->valoffset
= 17;
257 ctmpa
->keymenu
= &printer_select_keymenu
;
258 ctmpa
->help
= h_config_set_att_wyse2
;
259 ctmpa
->tool
= print_select_tool
;
260 ctmpa
->flags
|= CF_NOHILITE
;
261 ctmpa
->varoffset
= 8;
262 l
= strlen(WYSE_PRINTER
)+strlen(no_ff
);
263 ctmpa
->value
= (char *)fs_get((l
+1) * sizeof(char));
264 ctmpa
->varnamep
= ctmpb
;
265 ctmpa
->headingp
= heading
;
266 snprintf(ctmpa
->value
, l
+1, "%s%s", WYSE_PRINTER
, no_ff
);
267 ctmpa
->value
[l
] = '\0';
270 new_confline(&ctmpa
);
271 ctmpa
->valoffset
= 0;
272 ctmpa
->keymenu
= &printer_select_keymenu
;
273 ctmpa
->help
= NO_HELP
;
274 ctmpa
->tool
= print_select_tool
;
275 ctmpa
->flags
|= CF_NOSELECT
| CF_B_LINE
;
276 ctmpa
->var
= &ps
->vars
[V_STANDARD_PRINTER
];
279 new_confline(&ctmpa
);
281 ctmpa
->valoffset
= 6;
282 ctmpa
->keymenu
= &printer_select_keymenu
;
283 ctmpa
->help
= NO_HELP
;
284 ctmpa
->tool
= print_select_tool
;
287 = cpystr(" Standard OS/2 printer port");
289 = cpystr(_(" Standard UNIX print command"));
291 ctmpa
->value
= cpystr("");
292 ctmpa
->flags
|= (CF_NOSELECT
| CF_STARTITEM
);
293 ctmpa
->headingp
= heading
;
294 ctmpa
->var
= &ps
->vars
[V_STANDARD_PRINTER
];
296 new_confline(&ctmpa
);
297 ctmpa
->valoffset
= 6;
298 ctmpa
->keymenu
= &printer_select_keymenu
;
299 ctmpa
->help
= NO_HELP
;
300 ctmpa
->tool
= print_select_tool
;
301 ctmpa
->flags
|= CF_NOSELECT
;
304 = cpystr("Using this option may require you to use the OS/2 \"MODE\" command to");
306 = cpystr(_("Using this option may require setting your \"PRINTER\" or \"LPDEST\""));
308 ctmpa
->headingp
= heading
;
309 ctmpa
->var
= &ps
->vars
[V_STANDARD_PRINTER
];
311 new_confline(&ctmpa
);
312 ctmpa
->valoffset
= 6;
313 ctmpa
->keymenu
= &printer_select_keymenu
;
314 ctmpa
->help
= NO_HELP
;
315 ctmpa
->tool
= print_select_tool
;
316 ctmpa
->flags
|= CF_NOSELECT
;
319 = cpystr("direct printer output to the correct port.");
321 = cpystr(_("environment variable using the standard UNIX utilities."));
323 ctmpa
->headingp
= heading
;
324 ctmpa
->var
= &ps
->vars
[V_STANDARD_PRINTER
];
326 vtmp
= &ps
->vars
[V_STANDARD_PRINTER
];
327 for(i
= 0; vtmp
->current_val
.l
[i
]; i
++){
328 new_confline(&ctmpa
);
329 ctmpa
->valoffset
= 22;
330 ctmpa
->keymenu
= &printer_select_keymenu
;
331 ctmpa
->help
= NO_HELP
;
332 ctmpa
->help
= h_config_set_stand_print
;
333 ctmpa
->tool
= print_select_tool
;
335 ctmpa
->varoffset
= 8;
336 ctmpa
->varname
= cpystr(_("Printer List:"));
337 ctmpa
->flags
|= CF_NOHILITE
|CF_PRINTER
;
339 start_line
= ctmpb
= ctmpa
; /* default start line */
345 ctmpa
->varnamep
= ctmpb
;
346 ctmpa
->headingp
= heading
;
349 ctmpa
->value
= printer_name(vtmp
->current_val
.l
[i
]);
352 new_confline(&ctmpa
);
353 ctmpa
->valoffset
= 0;
354 ctmpa
->keymenu
= &printer_select_keymenu
;
355 ctmpa
->help
= NO_HELP
;
356 ctmpa
->tool
= print_select_tool
;
357 ctmpa
->flags
|= CF_NOSELECT
| CF_B_LINE
;
359 new_confline(&ctmpa
);
361 ctmpa
->valoffset
= 0;
362 ctmpa
->keymenu
= &printer_edit_keymenu
;
363 ctmpa
->help
= NO_HELP
;
364 ctmpa
->tool
= print_edit_tool
;
367 = cpystr(" Personally selected port or |command");
369 = cpystr(_(" Personally selected print command"));
371 ctmpa
->flags
|= (CF_NOSELECT
| CF_STARTITEM
);
372 ctmpa
->value
= cpystr("");
373 ctmpa
->headingp
= heading
;
374 ctmpa
->var
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
377 new_confline(&ctmpa
);
378 ctmpa
->valoffset
= 6;
379 ctmpa
->keymenu
= &printer_edit_keymenu
;
380 ctmpa
->help
= NO_HELP
;
381 ctmpa
->tool
= print_edit_tool
;
382 ctmpa
->flags
|= CF_NOSELECT
;
385 = cpystr("The text to be printed will be sent to the printer or command given here.");
387 = cpystr(_("The text to be printed will be piped into the command given here. The"));
389 ctmpa
->headingp
= heading
;
390 ctmpa
->var
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
392 new_confline(&ctmpa
);
393 ctmpa
->valoffset
= 6;
394 ctmpa
->keymenu
= &printer_edit_keymenu
;
395 ctmpa
->help
= NO_HELP
;
396 ctmpa
->tool
= print_edit_tool
;
397 ctmpa
->flags
|= CF_NOSELECT
;
400 = cpystr("The printer port or |pipe is in the 2nd column, the printer name is in");
402 = cpystr(_("command is in the 2nd column, the printer name is in the first column. Some"));
404 ctmpa
->headingp
= heading
;
405 ctmpa
->var
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
407 new_confline(&ctmpa
);
408 ctmpa
->valoffset
= 6;
409 ctmpa
->keymenu
= &printer_edit_keymenu
;
410 ctmpa
->help
= NO_HELP
;
411 ctmpa
->tool
= print_edit_tool
;
412 ctmpa
->flags
|= CF_NOSELECT
;
415 = cpystr("the first column. Examples: \"LPT1\", \"COM2\", \"|enscript\". A command may");
417 = cpystr(_("examples are: \"prt\", \"lpr\", \"lp\", or \"enscript\". The command may be given"));
419 ctmpa
->headingp
= heading
;
420 ctmpa
->var
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
422 new_confline(&ctmpa
);
423 ctmpa
->valoffset
= 6;
424 ctmpa
->keymenu
= &printer_edit_keymenu
;
425 ctmpa
->help
= NO_HELP
;
426 ctmpa
->tool
= print_edit_tool
;
427 ctmpa
->flags
|= CF_NOSELECT
;
430 = cpystr("be given options, for example \"|ascii2ps -p LPT1\" or \"|txt2hplc -2\". Use");
432 = cpystr(_("with options, for example \"enscript -2 -r\" or \"lpr -Plpacc170\". The"));
434 ctmpa
->headingp
= heading
;
435 ctmpa
->var
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
437 new_confline(&ctmpa
);
438 ctmpa
->valoffset
= 6;
439 ctmpa
->keymenu
= &printer_edit_keymenu
;
440 ctmpa
->help
= NO_HELP
;
441 ctmpa
->tool
= print_edit_tool
;
442 ctmpa
->flags
|= CF_NOSELECT
;
445 = cpystr("the |command method for printers that require conversion from ASCII.");
447 = cpystr(_("commands and options on your system may be different from these examples."));
449 ctmpa
->headingp
= heading
;
450 ctmpa
->var
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
452 vtmp
= &ps
->vars
[V_PERSONAL_PRINT_COMMAND
];
453 lval
= no_ex
? vtmp
->current_val
.l
: LVAL(vtmp
, ew
);
455 for(i
= 0; lval
[i
]; i
++){
456 new_confline(&ctmpa
);
457 ctmpa
->valoffset
= 22;
458 ctmpa
->keymenu
= &printer_edit_keymenu
;
459 ctmpa
->help
= h_config_set_custom_print
;
460 ctmpa
->tool
= print_edit_tool
;
462 ctmpa
->varoffset
= 8;
463 ctmpa
->varname
= cpystr(_("Printer List:"));
464 ctmpa
->flags
|= CF_NOHILITE
|CF_PRINTER
;
468 ctmpa
->varnamep
= ctmpb
;
469 ctmpa
->headingp
= heading
;
472 ctmpa
->value
= printer_name(lval
[i
]);
476 new_confline(&ctmpa
);
477 ctmpa
->valoffset
= 22;
478 ctmpa
->keymenu
= &printer_edit_keymenu
;
479 ctmpa
->help
= h_config_set_custom_print
;
480 ctmpa
->tool
= print_edit_tool
;
481 ctmpa
->flags
|= CF_NOHILITE
;
482 ctmpa
->varoffset
= 8;
483 ctmpa
->varname
= cpystr(_("Printer List:"));
484 ctmpa
->varnamep
= ctmpa
;
485 ctmpa
->headingp
= heading
;
488 ctmpa
->value
= cpystr("");
491 memset(&screen
, 0, sizeof(screen
));
492 screen
.ro_warning
= readonly_warning
;
493 vsave
= save_config_vars(ps
, 0);
494 /* TRANSLATORS: SETUP... is a screen title
495 Print something1 using something2.
496 "printer config" is something1 */
497 switch(conf_scroll_screen(ps
, &screen
, start_line
,
498 edit_exceptions
? _("SETUP PRINTER EXCEPTIONS")
499 : _("SETUP PRINTER"),
500 _("printer config"), 0, NULL
)){
505 write_pinerc(ps
, ew
, WRP_NONE
);
509 revert_to_saved_config(ps
, vsave
, 0);
510 ps
->printer_category
= saved_printer_cat
;
511 set_variable(V_PRINTER
, saved_printer
, 1, 0, ew
);
512 set_variable(V_PERSONAL_PRINT_CATEGORY
, comatose(ps
->printer_category
),
515 prc
->outstanding_pinerc_changes
= 0;
520 def_printer_line
= NULL
;
521 free_saved_config(ps
, &vsave
, 0);
522 fs_give((void **)&saved_printer
);
529 set_def_printer_value(char *printer
)
531 char *p
, *nick
, *cmd
;
532 int set
, editing_norm_except_exists
;
535 if(!def_printer_line
)
538 editing_norm_except_exists
= ((ps_global
->ew_for_except_vars
!= Main
) &&
541 parse_printer(printer
, &nick
, &cmd
, NULL
, NULL
, NULL
, NULL
);
542 p
= *nick
? nick
: cmd
;
544 if(*def_printer_line
)
545 fs_give((void **)def_printer_line
);
548 *def_printer_line
= fs_get((l
+1) * sizeof(char));
549 snprintf(*def_printer_line
, l
+1, "Default printer %s%s%s%s%s",
550 set
? "set to \"" : "unset", set
? p
: "", set
? "\"" : "",
551 (set
&& editing_norm_except_exists
) ? " (in exception config)" : "",
553 (*def_printer_line
)[l
] = '\0';
555 fs_give((void **)&nick
);
556 fs_give((void **)&cmd
);
561 print_select_tool(struct pine
*ps
, int cmd
, CONF_S
**cl
, unsigned int flags
)
563 int rc
, retval
, no_ex
, printer_msg
= 0;
564 char *p
, **lval
, *printer_was
;
565 struct variable
*vtmp
;
567 no_ex
= (ps_global
->ew_for_except_vars
== Main
);
569 printer_was
= ps
->VAR_PRINTER
? cpystr(ps
->VAR_PRINTER
) : NULL
;
573 retval
= config_exit_cmd(flags
);
578 char aname
[100], wname
[100];
580 strncpy(aname
, ANSI_PRINTER
, sizeof(aname
)-1);
581 aname
[sizeof(aname
)-1] = '\0';
582 strncat(aname
, no_ff
, sizeof(aname
)-strlen(aname
)-1);
583 strncpy(wname
, WYSE_PRINTER
, sizeof(wname
)-1);
584 wname
[sizeof(wname
)-1] = '\0';
585 strncat(wname
, no_ff
, sizeof(wname
)-strlen(wname
)-1);
588 lval
= (no_ex
|| !vtmp
->is_user
) ? vtmp
->current_val
.l
590 rc
= set_variable(V_PRINTER
, lval
? lval
[(*cl
)->varmem
] : NULL
,
593 if(vtmp
== &ps
->vars
[V_STANDARD_PRINTER
])
594 ps
->printer_category
= 2;
595 else if(vtmp
== &ps
->vars
[V_PERSONAL_PRINT_COMMAND
])
596 ps
->printer_category
= 3;
598 set_variable(V_PERSONAL_PRINT_CATEGORY
,
599 comatose(ps
->printer_category
), 1, 0, ew
);
604 q_status_message(SM_ORDER
,3,5, _("Trouble setting default printer"));
608 else if(!strcmp((*cl
)->value
,ANSI_PRINTER
)){
609 rc
= set_variable(V_PRINTER
, ANSI_PRINTER
, 1, 0, ew
);
611 ps
->printer_category
= 1;
612 set_variable(V_PERSONAL_PRINT_CATEGORY
,
613 comatose(ps
->printer_category
), 1, 0, ew
);
617 q_status_message(SM_ORDER
,3,5, _("Trouble setting default printer"));
621 else if(!strcmp((*cl
)->value
,aname
)){
622 rc
= set_variable(V_PRINTER
, aname
, 1, 0, ew
);
624 ps
->printer_category
= 1;
625 set_variable(V_PERSONAL_PRINT_CATEGORY
,
626 comatose(ps
->printer_category
), 1, 0, ew
);
630 q_status_message(SM_ORDER
,3,5, _("Trouble setting default printer"));
634 else if(!strcmp((*cl
)->value
,WYSE_PRINTER
)){
635 rc
= set_variable(V_PRINTER
, WYSE_PRINTER
, 1, 0, ew
);
637 ps
->printer_category
= 1;
638 set_variable(V_PERSONAL_PRINT_CATEGORY
,
639 comatose(ps
->printer_category
), 1, 0, ew
);
643 q_status_message(SM_ORDER
,3,5, _("Trouble setting default printer"));
647 else if(!strcmp((*cl
)->value
,wname
)){
648 rc
= set_variable(V_PRINTER
, wname
, 1, 0, ew
);
650 ps
->printer_category
= 1;
651 set_variable(V_PERSONAL_PRINT_CATEGORY
,
652 comatose(ps
->printer_category
), 1, 0, ew
);
656 q_status_message(SM_ORDER
,3,5, _("Trouble setting default printer"));
667 ps
->mangled_body
= 1; /* BUG: redraw it all for now? */
668 set_def_printer_value(ps
->VAR_PRINTER
);
683 parse_printer(ps
->VAR_PRINTER
, &nick
, &q
,
684 NULL
, NULL
, NULL
, NULL
);
685 p
= cpystr(*nick
? nick
: q
);
686 fs_give((void **)&nick
);
687 fs_give((void **)&q
);
690 q_status_message4(SM_ORDER
, 0, 3,
691 "Default printer%s %s%s%s",
692 ((!printer_was
&& !ps
->VAR_PRINTER
) ||
693 (printer_was
&& ps
->VAR_PRINTER
&&
694 !strcmp(printer_was
,ps
->VAR_PRINTER
)))
696 p
? "set to \"" : "unset",
697 p
? p
: "", p
? "\"" : "");
700 fs_give((void **)&p
);
704 fs_give((void **)&printer_was
);
711 print_edit_tool(struct pine
*ps
, int cmd
, CONF_S
**cl
, unsigned int flags
)
713 char prompt
[81], sval
[MAXPATH
+1], name
[MAXPATH
+1];
714 char *nick
, *p
, *tmp
, **newval
= NULL
, **ltmp
= NULL
;
715 char **lval
, **nelval
;
716 int rv
= 0, skip_to_next
= 0, after
= 0, i
= 4, j
, k
= 0;
717 int oeflags
, changing_selected
= 0, no_ex
;
721 /* need this to preserve old behavior when no exception config file */
722 no_ex
= (ps_global
->ew_for_except_vars
== Main
);
725 return(print_select_tool(ps
, cmd
, cl
, flags
));
727 if(!(cl
&& *cl
&& (*cl
)->var
))
730 nelval
= no_ex
? (*cl
)->var
->current_val
.l
: LVAL((*cl
)->var
, ew
);
731 lval
= LVAL((*cl
)->var
, ew
);
734 case MC_ADD
: /* add to list */
736 if(!fixed_var((*cl
)->var
, "add to", NULL
)){
738 if(lval
&& (*cl
)->value
){
739 strncpy(prompt
, _("Enter printer name : "), sizeof(prompt
));
740 prompt
[sizeof(prompt
)-1] = '\0';
742 else if(!lval
&& nelval
){
743 /* Add to list which doesn't exist, but default does exist */
747 ekey
[0].label
= N_("Replace");
751 ekey
[1].label
= N_("Add To");
753 strncpy(prompt
, _("Replace or Add To default value ? "), sizeof(prompt
));
754 prompt
[sizeof(prompt
)-1] = '\0';
755 switch(i
= radio_buttons(prompt
, -FOOTER_ROWS(ps
), ekey
, 'a',
756 'x', h_config_replace_add
, RB_NORM
)){
758 /* Make a list of the default commands, leaving room for
759 the command we are about to add below. */
760 for(k
= 0; nelval
[k
]; k
++)
763 ltmp
= (char **)fs_get((k
+2) * sizeof(char *));
765 for(j
= 0; j
< k
; j
++)
766 ltmp
[j
] = cpystr(nelval
[j
]);
768 ltmp
[k
+ 1] = ltmp
[k
] = NULL
;
771 strncpy(prompt
, _("Enter name of printer to be added : "), sizeof(prompt
));
772 prompt
[sizeof(prompt
)-1] = '\0';
777 strncpy(prompt
, _("Enter the name for replacement printer : "), sizeof(prompt
));
778 prompt
[sizeof(prompt
)-1] = '\0';
782 cmd_cancelled("Add");
790 strncpy(prompt
, _("Enter name of printer to be added : "), sizeof(prompt
));
791 prompt
[sizeof(prompt
)-1] = '\0';
794 ps
->mangled_footer
= 1;
799 while(i
!= 0 && i
!= 1){
800 if(lval
&& (*cl
)->value
){
801 ekey
[0].ch
= ctrl('W');
804 ekey
[0].label
= after
? N_("InsertBefore") : N_("InsertAfter");
810 oeflags
= OE_APPEND_CURRENT
;
811 i
= optionally_enter(name
, -FOOTER_ROWS(ps
), 0, sizeof(name
),
813 (ekey
[0].ch
!= -1) ? ekey
: NULL
,
816 rv
= ps
->mangled_body
= 1;
817 removing_leading_and_trailing_white_space(name
);
820 cmd_cancelled("Add");
823 help
= (help
== NO_HELP
) ? h_config_insert_after
: NO_HELP
;
825 else if(i
== 4){ /* no redraw, yet */
827 else if(i
== 5){ /* change from/to prepend to/from append */
828 after
= after
? 0 : 1;
836 strncpy(prompt
, "Enter port or |command : ", sizeof(prompt
));
838 strncpy(prompt
, _("Enter command for printer : "), sizeof(prompt
));
840 prompt
[sizeof(prompt
)-1] = '\0';
841 while(i
!= 0 && i
!= 1){
842 oeflags
= OE_APPEND_CURRENT
;
843 i
= optionally_enter(sval
, -FOOTER_ROWS(ps
), 0, sizeof(sval
),
845 (ekey
[0].ch
!= -1) ? ekey
: NULL
,
848 rv
= ps
->mangled_body
= 1;
849 removing_leading_and_trailing_white_space(sval
);
852 for(tmp
= sval
; *tmp
; tmp
++)
854 i
++; /* conservative count of ,'s */
856 if(!i
){ /* only one item */
858 ltmp
= (char **)fs_get(2 * sizeof(char *));
865 l
= strlen(name
) + 4 + strlen(sval
);
866 ltmp
[k
] = (char *) fs_get((l
+1) * sizeof(char));
867 snprintf(ltmp
[k
], l
+1, "%s [] %s", name
, sval
);
871 ltmp
[k
] = cpystr(sval
);
875 * Don't allow input of multiple entries at once.
877 q_status_message(SM_ORDER
,3,5,
878 _("No commas allowed in command"));
883 config_add_list(ps
, cl
, ltmp
, &newval
, after
);
888 fs_give((void **)<mp
);
892 q_status_message1(SM_ORDER
, 0, 3,
893 _("Can't add %s to list"), empty_val
);
896 cmd_cancelled("Add");
899 help
= help
== NO_HELP
? h_config_print_cmd
: NO_HELP
;
901 else if(i
== 4){ /* no redraw, yet */
903 else if(i
== 5){ /* change from/to prepend to/from append */
904 after
= after
? 0 : 1;
911 case MC_DELETE
: /* delete */
912 if((*cl
)->var
->current_val
.l
913 && (*cl
)->var
->current_val
.l
[(*cl
)->varmem
]
914 && !strucmp(ps
->VAR_PRINTER
,(*cl
)->var
->current_val
.l
[(*cl
)->varmem
]))
915 changing_selected
= 1;
920 snprintf(pmt
, sizeof(pmt
), _("Override default with %s"), empty_val2
);
921 pmt
[sizeof(pmt
)-1] = '\0';
922 if(want_to(pmt
, 'n', 'n', NO_HELP
, WT_FLUSH_IN
) == 'y'){
926 ltmp
= (char **)fs_get(2 * sizeof(char *));
927 ltmp
[0] = cpystr(sval
);
929 config_add_list(ps
, cl
, ltmp
, &newval
, 0);
930 fs_give((void **)<mp
);
931 rv
= ps
->mangled_body
= 1;
935 q_status_message(SM_ORDER
, 0, 3, _("No set value to delete"));
938 if((*cl
)->var
->is_fixed
){
939 parse_printer(lval
[(*cl
)->varmem
],
940 &nick
, &p
, NULL
, NULL
, NULL
, NULL
);
941 snprintf(prompt
, sizeof(prompt
), _("Delete (unused) printer %s "),
942 *nick
? nick
: (!*p
) ? empty_val2
: p
);
943 fs_give((void **)&nick
);
944 fs_give((void **)&p
);
947 snprintf(prompt
, sizeof(prompt
), _("Really delete item %s from printer list "),
948 int2string((*cl
)->varmem
+ 1));
950 prompt
[sizeof(prompt
)-1] = '\0';
952 ps
->mangled_footer
= 1;
953 if(want_to(prompt
,'n','n',h_config_print_del
, WT_FLUSH_IN
) == 'y'){
954 rv
= ps
->mangled_body
= 1;
955 fs_give((void **)&lval
[(*cl
)->varmem
]);
956 config_del_list_item(cl
, &newval
);
959 q_status_message(SM_ORDER
, 0, 3, _("Printer not deleted"));
964 case MC_EDIT
: /* edit/change list option */
965 if((*cl
)->var
->current_val
.l
966 && (*cl
)->var
->current_val
.l
[(*cl
)->varmem
]
967 && !strucmp(ps
->VAR_PRINTER
,(*cl
)->var
->current_val
.l
[(*cl
)->varmem
]))
968 changing_selected
= 1;
970 if(fixed_var((*cl
)->var
, NULL
, "printer"))
972 else if(!lval
&& nelval
)
974 else if(!lval
&& !nelval
)
982 ekey
[0].label
= N_("Name");
986 ekey
[1].label
= N_("Command");
990 ekey
[2].label
= N_("Options");
992 /* TRANSLATORS: this is a question with three choices */
993 strncpy(prompt
, _("Change Name or Command or Options ? "), sizeof(prompt
));
994 prompt
[sizeof(prompt
)-1] = '\0';
995 i
= radio_buttons(prompt
, -FOOTER_ROWS(ps
), ekey
, 'c', 'x',
996 h_config_print_name_cmd
, RB_NORM
);
999 cmd_cancelled("Change");
1005 parse_printer(lval
[(*cl
)->varmem
],
1006 NULL
, &p
, NULL
, NULL
, NULL
, &all_but_cmd
);
1008 strncpy(prompt
, _("Change command : "), sizeof(prompt
));
1009 prompt
[sizeof(prompt
)-1] = '\0';
1010 strncpy(sval
, p
? p
: "", sizeof(sval
)-1);
1011 sval
[sizeof(sval
)-1] = '\0';
1012 fs_give((void **)&p
);
1014 ps
->mangled_footer
= 1;
1017 oeflags
= OE_APPEND_CURRENT
;
1018 i
= optionally_enter(sval
, -FOOTER_ROWS(ps
), 0,
1019 sizeof(sval
), prompt
, NULL
,
1022 removing_leading_and_trailing_white_space(sval
);
1023 rv
= ps
->mangled_body
= 1;
1024 if(lval
[(*cl
)->varmem
])
1025 fs_give((void **)&lval
[(*cl
)->varmem
]);
1028 for(tmp
= sval
; *tmp
; tmp
++)
1030 i
++; /* count of ,'s */
1032 if(!i
){ /* only one item */
1035 l
= strlen(all_but_cmd
) + strlen(sval
);
1036 lval
[(*cl
)->varmem
] = (char *)fs_get((l
+1) * sizeof(char));
1037 snprintf(lval
[(*cl
)->varmem
], l
+1, "%s%s", all_but_cmd
, sval
);
1038 lval
[(*cl
)->varmem
][l
] = '\0';
1040 newval
= &(*cl
)->value
;
1044 * Don't allow input of multiple entries at once.
1046 q_status_message(SM_ORDER
,3,5,
1047 _("No commas allowed in command"));
1052 cmd_cancelled("Change");
1055 help
= help
== NO_HELP
? h_config_change
: NO_HELP
;
1058 else if(i
== 4){ /* no redraw, yet */
1068 parse_printer(lval
[(*cl
)->varmem
],
1069 &p
, NULL
, NULL
, NULL
, &all_but_nick
, NULL
);
1071 strncpy(prompt
, _("Change name : "), sizeof(prompt
));
1072 prompt
[sizeof(prompt
)-1] = '\0';
1073 strncpy(name
, p
? p
: "", sizeof(name
));
1074 name
[sizeof(name
)-1] = '\0';
1076 fs_give((void **)&p
);
1078 ps
->mangled_footer
= 1;
1081 oeflags
= OE_APPEND_CURRENT
;
1082 i
= optionally_enter(name
, -FOOTER_ROWS(ps
), 0,
1083 sizeof(name
), prompt
, NULL
,
1088 rv
= ps
->mangled_body
= 1;
1089 removing_leading_and_trailing_white_space(name
);
1090 if(lval
[(*cl
)->varmem
])
1091 fs_give((void **)&lval
[(*cl
)->varmem
]);
1093 l
= strlen(name
) + 1 + ((*all_but_nick
== '[') ? 0 : 3) + strlen(all_but_nick
);
1094 lval
[(*cl
)->varmem
] = (char *)fs_get((l
+1) * sizeof(char));
1095 snprintf(lval
[(*cl
)->varmem
], l
+1,
1097 (*all_but_nick
== '[') ? "" : "[] ",
1099 lval
[(*cl
)->varmem
][l
] = '\0';
1101 newval
= &(*cl
)->value
;
1104 cmd_cancelled("Change");
1107 help
= help
== NO_HELP
? h_config_change
: NO_HELP
;
1110 else if(i
== 4){ /* no redraw, yet */
1117 fs_give((void **)&all_but_nick
);
1125 ekey
[0].label
= N_("Init");
1129 ekey
[1].label
= N_("Trailer");
1131 strncpy(prompt
, _("Change Init string or Trailer string ? "), sizeof(prompt
));
1132 prompt
[sizeof(prompt
)-1] = '\0';
1133 j
= radio_buttons(prompt
, -FOOTER_ROWS(ps
), ekey
, 'i', 'x',
1134 h_config_print_opt_choice
, RB_NORM
);
1137 cmd_cancelled("Change");
1141 char *init
, *trailer
;
1143 parse_printer(lval
[(*cl
)->varmem
],
1144 &nick
, &p
, &init
, &trailer
, NULL
, NULL
);
1147 snprintf(prompt
, sizeof(prompt
), _("Change INIT string : "));
1149 snprintf(prompt
, sizeof(prompt
), _("Change TRAILER string : "));
1151 strncpy(sval
, (j
== 'i') ? init
: trailer
, sizeof(sval
)-1);
1152 sval
[sizeof(sval
)-1] = '\0';
1154 tmp
= string_to_cstring(sval
);
1155 strncpy(sval
, tmp
, sizeof(sval
)-1);
1156 sval
[sizeof(sval
)-1] = '\0';
1157 fs_give((void **)&tmp
);
1159 ps
->mangled_footer
= 1;
1162 oeflags
= OE_APPEND_CURRENT
;
1163 i
= optionally_enter(sval
, -FOOTER_ROWS(ps
), 0,
1164 sizeof(sval
), prompt
, NULL
, help
, &oeflags
);
1168 removing_leading_and_trailing_white_space(sval
);
1170 if(lval
[(*cl
)->varmem
])
1171 fs_give((void **)&lval
[(*cl
)->varmem
]);
1173 init
= cstring_to_hexstring(sval
);
1174 tmp
= cstring_to_hexstring(trailer
);
1175 fs_give((void **)&trailer
);
1179 trailer
= cstring_to_hexstring(sval
);
1180 tmp
= cstring_to_hexstring(init
);
1181 fs_give((void **)&init
);
1185 l
= strlen(nick
) + 1 + 2 + strlen("INIT=") + strlen(init
) + 1 + strlen("TRAILER=") + strlen(trailer
)+ 1 + strlen(p
);
1186 lval
[(*cl
)->varmem
] = (char *)fs_get((l
+1) * sizeof(char));
1187 snprintf(lval
[(*cl
)->varmem
], l
+1,
1188 "%s%s%s%s%s%s%s%s%s%s%s",
1190 /* space */ *nick
? " " : "",
1191 /* [ */ (*nick
|| *init
|| *trailer
) ? "[" : "",
1192 /* INIT= */ *init
? "INIT=" : "",
1194 /* space */ (*init
&& *trailer
) ? " " : "",
1195 /* TRAILER= */ *trailer
? "TRAILER=" : "",
1196 /* trailer */ trailer
,
1197 /* ] */ (*nick
|| *init
|| *trailer
) ? "]" : "",
1198 /* space */ (*nick
|| *init
|| *trailer
) ? " " : "",
1200 lval
[(*cl
)->varmem
][l
] = '\0';
1202 newval
= &(*cl
)->value
;
1205 cmd_cancelled("Change");
1208 help
=(help
== NO_HELP
)?h_config_print_init
:NO_HELP
;
1211 else if(i
== 4){ /* no redraw, yet */
1218 fs_give((void **)&nick
);
1219 fs_give((void **)&p
);
1220 fs_give((void **)&init
);
1221 fs_give((void **)&trailer
);
1228 case MC_EXIT
: /* exit */
1229 rv
= config_exit_cmd(flags
);
1238 *cl
= next_confline(*cl
);
1241 * At this point, if changes occurred, var->user_val.X is set.
1242 * So, fix the current_val, and handle special cases...
1245 set_current_val((*cl
)->var
, TRUE
, FALSE
);
1246 fix_side_effects(ps
, (*cl
)->var
, 0);
1250 fs_give((void **)newval
);
1252 if((*cl
)->var
->current_val
.l
)
1253 *newval
= printer_name((*cl
)->var
->current_val
.l
[(*cl
)->varmem
]);
1255 *newval
= cpystr("");
1258 if(changing_selected
)
1259 print_select_tool(ps
, MC_CHOICE
, cl
, flags
);
1267 * Given a single printer string from the config file, returns an allocated
1268 * copy of the friendly printer name, which is
1269 * "Nickname" command
1272 printer_name(char *input
)
1277 parse_printer(input
, &nick
, &cmd
, NULL
, NULL
, NULL
, NULL
);
1278 ret
= (char *)fs_get((2+6*22+1+strlen(cmd
)) * sizeof(char));
1279 utf8_snprintf(ret
, 2+6*22+1+strlen(cmd
), "\"%.21w\"%*s%s",
1281 22 - MIN(utf8_width(nick
), 21),
1284 fs_give((void **) &nick
);
1285 fs_give((void **) &cmd
);