Hi! I send for you patch for print support (it contains small fix relatively has previously). But have problem with a2ps + utf-8, details in source Apart patch I attach *.c & *.h files, which contains in patch. If need correct it, please write me. -- good luck! Vadim Likhota <vadim-lvv yandex ru>
Attachment:
patch-mc-4.6.1-prn
Description: Binary data
#ifndef __MC_DLG_PRN_H #define __MC_DLG_PRN_H #ifdef HAVE_PRINT #define PRINTCAP "/etc/printcap" int show_print_dlg (void); void print_file (const char *fname); #endif /* HAVE_PRINT */ #endif /* __MC_DLG_PRN_H */
/* Print dialog module for the Midnight Commander Copyright (C) 2005 Likhota Vadim <vadim-lvv yandex ru> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* 2005 09 small fix add a2ps 2005 06 orig */ #include <config.h> #ifdef HAVE_PRINT #include <stdio.h> #include <errno.h> #include "global.h" #include "tty.h" #include "execute.h" #include "color.h" #include "widget.h" #include "wtools.h" #ifdef HAVE_CHARSET #include "charsets.h" #endif #include "dlg_prn.h" #define TEMP_BUF_LEN 1024 #define DLG_PRN_H 11 #define DLG_PRN_W 72 static char printer[32] = N_("default printer"); static char codepgf[32] = N_("default charset"); static char codepgt[32] = N_("default charset"); static int nprinter = 0, ncodepgf = 0, ncodepgt = 0; static int sel_pln = 1, sel_prn = 0, sel_enc = 0; static WCheck *check_pln, *check_prn, *check_enc; static WButton *but_prn, *but_en1, *but_en2; static void prn_enter (Dlg_head * h, const int f_pos) { Dlg_head *chl_dlg = 0; WListbox *chl_list; int prnbox = ( f_pos == 2 ? 1 : 0 ); // 1 - printers, 0 - charsets int lxx = (COLS - DLG_PRN_W) / 2 + (f_pos == 7 ? 50 : 25); int lyy = (LINES - DLG_PRN_H) / 2 + (prnbox ? 0 : 2 ); char *title = ( prnbox ? _("printers") : _("charsets") ); if ( !(chl_dlg = create_dlg (lyy, lxx, 9, 20, dialog_colors, NULL, "[print option]", title, DLG_COMPACT))) { message (1, MSG_ERROR, "Can't create child window."); return; } if ( !(chl_list = listbox_new (1, 1, 18, 7, NULL))) { message (1, MSG_ERROR, "Can't create child lisbox."); destroy_dlg (chl_dlg); return; } listbox_add_item (chl_list, 0, 0, (prnbox ? N_("default printer") : N_("default charset")), NULL); // read printcap file if ( prnbox ) { char *p = PRINTCAP; char buf[TEMP_BUF_LEN], *bufi; FILE *f; f = (FILE *) fopen (p, "r"); if (f) { while ( fgets(buf, TEMP_BUF_LEN - 1, f) ) { int prflag = 0; if (*buf != '#') { bufi = buf; while ( *bufi != '\0' and (*bufi >= '0' and *bufi <= '9' or *bufi >= 'A' and *bufi <= 'Z' or *bufi >= 'a' and *bufi <= 'z' or *bufi == '|' or *bufi == '_') { if ( *bufi == '|' ) { *bufi = '\0'; prflag = 1; break; } else bufi++; } if ( prflag ) { listbox_add_item (chl_list, 0, 0, buf, NULL); prflag = 0; } } } if (fclose (f) > 0) message (1, MSG_ERROR, "Error while close file: %s.", p); } else { message (1, MSG_ERROR, "Can't open file for reading: %s.", p); destroy_dlg (chl_dlg); return; } } #ifdef HAVE_CHARSET else { int i = 0; for ( ; i < n_codepages; i++) listbox_add_item (chl_list, 0, 0, codepages[i].name, NULL); } #endif add_widget (chl_dlg, chl_list); run_dlg (chl_dlg); switch (f_pos) { case 2: strncpy(printer, chl_list->current->text, 32); strncpy(but_prn->text, printer, 32); nprinter = chl_list->pos; break; case 5: strncpy(codepgf, chl_list->current->text, 32); strncpy(but_en1->text, codepgf, 32); ncodepgf = chl_list->pos; break; case 7: strncpy(codepgt, chl_list->current->text, 32); strncpy(but_en2->text, codepgt, 32); ncodepgt = chl_list->pos; break; } destroy_dlg (chl_dlg); } static cb_ret_t print_block_callback (struct Dlg_head *h, dlg_msg_t Msg, int Par) { int f_pos = h->current->dlg_id; if (Msg == DLG_KEY) { switch (Par) { case '\n': if ( f_pos < 8 ) { switch (f_pos) { case 2: if ( check_prn->state ) prn_enter (h, f_pos); break; case 7: if ( !strcmp(but_en1->text, N_("default charset")) ) break; case 5: if ( check_enc->state ) prn_enter (h, f_pos); break; } return MSG_HANDLED; } break; } } else return default_dlg_callback (h, Msg, Par); return MSG_NOT_HANDLED; } /* Return 0 on success */ int show_print_dlg (void) { Dlg_head *prn_dlg; prn_dlg = create_dlg (0, 0, DLG_PRN_H, DLG_PRN_W, dialog_colors, print_block_callback, "[print dlg]", _(" Print options "), DLG_CENTER); // 0 add_widget (prn_dlg, check_pln = check_new (DLG_PRN_H - 9, 3, sel_pln, N_("plain text"))); // 1 add_widget (prn_dlg, check_prn = check_new (DLG_PRN_H - 7, 3, sel_prn, N_("select printer"))); // 2 add_widget (prn_dlg, but_prn = button_new(DLG_PRN_H - 7, 25, B_USER+1, NORMAL_BUTTON, "default_printer_XXXXXXXXXXXXXXX", NULL)); // 3 add_widget (prn_dlg, check_enc = check_new (DLG_PRN_H - 5, 3, sel_enc, N_("encoding"))); // 4 add_widget (prn_dlg, label_new (DLG_PRN_H - 5, 20, N_("from"))); // 5 add_widget (prn_dlg, but_en1 = button_new(DLG_PRN_H - 5, 25, B_USER+2, NORMAL_BUTTON, "default_charset_XXXXXXXXXXXXXXX", NULL)); // 6 add_widget (prn_dlg, label_new (DLG_PRN_H - 5, 45, N_("to"))); // 7 add_widget (prn_dlg, but_en2 = button_new(DLG_PRN_H - 5, 48, B_USER+3, NORMAL_BUTTON, "default_charset_XXXXXXXXXXXXXXX", NULL)); // 8 add_widget (prn_dlg, button_new(DLG_PRN_H - 3, 20, B_ENTER, NORMAL_BUTTON, N_("Print"), NULL)); // 9 add_widget (prn_dlg, button_new(DLG_PRN_H - 3, 40, B_CANCEL, NORMAL_BUTTON, N_("Cancel"), NULL)); strncpy(but_en1->text, codepgf, 32); strncpy(but_en2->text, codepgt, 32); strncpy(but_prn->text, printer, 32); run_dlg (prn_dlg); sel_enc = check_enc->state; sel_prn = check_prn->state; sel_pln = check_pln->state; if (prn_dlg->ret_value == B_CANCEL) { destroy_dlg (prn_dlg); return 1; } destroy_dlg (prn_dlg); return 0; } #define CMD_BUF 256 void print_file (const char *fname) { char cmd[CMD_BUF]; char *lpr; /* for cyrillic if (text in koi8-r) lpr -l == a2ps -1m -X koi8-r -B --border=no, but many matrix printer use cp866 */ if ( !sel_pln ) { lpr = g_strdup("lpr -l"); #ifdef HAVE_CHARSET if ( ncodepgf && ncodepgt) if ( nprinter ) snprintf(cmd, CMD_BUF, "iconv -f %s -t %s %s | %s -p %s", codepages[ncodepgf-1].id, codepages[ncodepgt-1].id, fname, lpr, printer); else snprintf(cmd, CMD_BUF, "iconv -f %s -t %s %s | %s", codepages[ncodepgf-1].id, codepages[ncodepgt-1].id, fname, lpr); else #endif if ( nprinter ) snprintf(cmd, CMD_BUF, "%s -p %s %s", lpr, printer, fname); else snprintf(cmd, CMD_BUF, "%s %s", lpr, fname); } else { #ifdef FIX_a2ps_and_utf8 /* see bottom */ lpr = g_strdup("a2ps -1m -X utf-8 -f7 -B --border=no"); #ifdef HAVE_CHARSET if ( ncodepgf ) if ( nprinter ) snprintf(cmd, CMD_BUF, "iconv -f %s -t utf-8 %s | %s -P %s", codepages[ncodepgf-1].id, codepages[ncodepgt-1].id, fname, lpr, printer, codepages[ncodepgt-1].id); else snprintf(cmd, CMD_BUF, "iconv -f %s -t %s %s | %s -d", codepages[ncodepgf-1].id, codepages[ncodepgt-1].id, fname, lpr, codepages[ncodepgt-1].id); else #endif if ( nprinter ) snprintf(cmd, CMD_BUF, "%s -P %s %s", lpr, printer, fname); else snprintf(cmd, CMD_BUF, "%s -d %s", lpr, fname); #else /* not FIX_a2ps_and_utf8 */ lpr = g_strdup("a2ps -1m -X koi8-r -f8 -B --border=no"); /* FIXME: ^^^ my printers (hp dj 845 and hp lj 1010) cann't work with "-X utf-8" or a2ps don't normally support utf-8 */ #ifdef HAVE_CHARSET if ( ncodepgf ) if ( nprinter ) snprintf(cmd, CMD_BUF, "iconv -f %s -t koi8-r %s | %s -P %s", codepages[ncodepgf-1].id, fname, lpr, printer); else snprintf(cmd, CMD_BUF, "iconv -f %s -t koi8-r %s | %s -d", codepages[ncodepgf-1].id, fname, lpr); else #endif if ( nprinter ) snprintf(cmd, CMD_BUF, "%s -P %s %s", lpr, printer, fname); else snprintf(cmd, CMD_BUF, "%s -d %s", lpr, fname); #endif /* FIX_a2ps_and_utf8 */ } g_free(lpr); shell_execute(cmd, 0); } #undef CMD_BUFF #endif /* HAVE_PRINT */