[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Windows port: using Windows' default printer
From: |
Peter 'Luna' Runestig |
Subject: |
Re: Windows port: using Windows' default printer |
Date: |
25 Sep 2003 15:26:47 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
"Eli Zaretskii" <address@hidden> writes:
> > Isn't this what my patch does?
>
> Yes, but why did you need to test for default-printer-name to be
> fboundp? It should simply be called unconditionally, and we should
> have some provision for the user to override that with printer-name.
Yes, you're right of course, no need for fboundp in dos-w32.el. The
original idea was that you could have defined a `default-printer-name'
function for any given platform, thus the general idea of the fboundp
test. But since dos-w32.el belongs to the same platform as the rest of
my code, that test is silly. And `default-printer-name' is only called
if printer-name/ps-printer-name is nil.
> > I also tampered with the following files, but maybe that isn't necessary:
> >
> > lpr.el: Add `default-printer-name' stuff to `print-region-1'.
> > ps-print.el: Add `default-printer-name' stuff to `ps-do-despool'.
> > play/handwrite.el: Add `default-printer-name' stuff to `handwrite'.
>
> This shouldn't be necessary.
The reason for me messing with those files, was the line of thinking
from the original idea, described above.
> I still think that, even for Windows, it's overhead to call
> default-printer-name each time we print something. But that's me.
I did a profiling test on my 750 MHz PentiumIII, it takes about 5
ms. Anyway, here is a stripped down, "w32-only" version:
diff -bur emacs-cvs-20030904.orig/lisp/ChangeLog
emacs-cvs-20030904/lisp/ChangeLog
--- emacs-cvs-20030904.orig/lisp/ChangeLog 2003-09-03 10:14:52.000000000
+0200
+++ emacs-cvs-20030904/lisp/ChangeLog 2003-09-08 09:01:53.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05 Peter Runestig <address@hidden>
+
+ * dos-w32.el: Added support for the `default-printer-name' function.
+
2003-09-02 Jason Rumney <address@hidden>
* international/titdic-cnv.el (tsang-quick-converter): Fix broken
diff -bur emacs-cvs-20030904.orig/lisp/dos-w32.el
emacs-cvs-20030904/lisp/dos-w32.el
--- emacs-cvs-20030904.orig/lisp/dos-w32.el 2003-09-03 10:14:55.000000000
+0200
+++ emacs-cvs-20030904/lisp/dos-w32.el 2003-09-05 22:50:41.000000000 +0200
@@ -378,7 +378,8 @@
(printer (or (and (boundp 'dos-printer)
(stringp (symbol-value 'dos-printer))
(symbol-value 'dos-printer))
- printer-name)))
+ printer-name
+ (default-printer-name))))
(or (eq coding-system-for-write 'no-conversion)
(setq coding-system-for-write
(aref eol-type 1))) ; force conversion to DOS EOLs
@@ -411,7 +413,8 @@
(let ((printer (or (and (boundp 'dos-ps-printer)
(stringp (symbol-value 'dos-ps-printer))
(symbol-value 'dos-ps-printer))
- ps-printer-name)))
+ ps-printer-name
+ (default-printer-name))))
(direct-print-region-helper printer start end lpr-prog
delete-text buf display rest)))
diff -bur emacs-cvs-20030904.orig/nt/ChangeLog emacs-cvs-20030904/nt/ChangeLog
--- emacs-cvs-20030904.orig/nt/ChangeLog 2003-09-04 09:19:35.000000000
+0200
+++ emacs-cvs-20030904/nt/ChangeLog 2003-09-08 09:04:42.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05 Peter Runestig <address@hidden>
+
+ * gmake.defs, nmake.defs: Add linking to ``winspool.lib''.
+
2003-09-03 Peter Runestig <address@hidden>
* configure.bat: Create ``makefile'' in directories man, lispref
diff -bur emacs-cvs-20030904.orig/nt/gmake.defs emacs-cvs-20030904/nt/gmake.defs
--- emacs-cvs-20030904.orig/nt/gmake.defs 2003-09-03 10:15:31.000000000
+0200
+++ emacs-cvs-20030904/nt/gmake.defs 2003-09-05 22:50:41.000000000 +0200
@@ -177,6 +177,7 @@
USER32 = -luser32
WSOCK32 = -lwsock32
WINMM = -lwinmm
+WINSPOOL = -lwinspool
ifdef NOOPT
DEBUG_CFLAGS = -DEMACSDEBUG
diff -bur emacs-cvs-20030904.orig/nt/nmake.defs emacs-cvs-20030904/nt/nmake.defs
--- emacs-cvs-20030904.orig/nt/nmake.defs 2003-09-03 10:15:31.000000000
+0200
+++ emacs-cvs-20030904/nt/nmake.defs 2003-09-05 22:50:41.000000000 +0200
@@ -124,6 +124,7 @@
USER32 = user32.lib
WSOCK32 = wsock32.lib
WINMM = winmm.lib
+WINSPOOL = winspool.lib
!ifdef NOOPT
DEBUG_CFLAGS = -DEMACSDEBUG
diff -bur emacs-cvs-20030904.orig/src/ChangeLog emacs-cvs-20030904/src/ChangeLog
--- emacs-cvs-20030904.orig/src/ChangeLog 2003-09-03 10:15:33.000000000
+0200
+++ emacs-cvs-20030904/src/ChangeLog 2003-09-08 09:06:20.000000000 +0200
@@ -1,3 +1,7 @@
+2003-09-05 Peter Runestig <address@hidden>
+
+ * makefile.w32-in, w32fns.c: Add `default-printer-name' function.
+
2003-09-03 Kim F. Storm <address@hidden>
* xdisp.c (get_window_cursor_type): Partially undo 2002-03-01
diff -bur emacs-cvs-20030904.orig/src/makefile.w32-in
emacs-cvs-20030904/src/makefile.w32-in
--- emacs-cvs-20030904.orig/src/makefile.w32-in 2003-09-03 10:15:39.000000000
+0200
+++ emacs-cvs-20030904/src/makefile.w32-in 2003-09-06 01:50:36.000000000
+0200
@@ -141,6 +141,7 @@
$(USER32) \
$(MPR) \
$(SHELL32) \
+ $(WINSPOOL) \
$(libc)
#
diff -bur emacs-cvs-20030904.orig/src/w32fns.c emacs-cvs-20030904/src/w32fns.c
--- emacs-cvs-20030904.orig/src/w32fns.c 2003-09-03 10:15:41.000000000
+0200
+++ emacs-cvs-20030904/src/w32fns.c 2003-09-05 23:41:01.000000000 +0200
@@ -51,6 +51,7 @@
#include <commdlg.h>
#include <shellapi.h>
#include <ctype.h>
+#include <winspool.h>
#include <dlgs.h>
#define FILE_NAME_TEXT_FIELD edt1
@@ -13925,6 +13926,76 @@
return value;
}
+DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
+ 0, 0, 0, doc: /* Return the name of Windows default printer device. */)
+ ()
+{
+ static char pname_buf[256];
+ int err;
+ HANDLE hPrn;
+ PRINTER_INFO_2 *ppi2 = NULL;
+ DWORD dwNeeded = 0, dwReturned = 0;
+
+ /* Retrieve the default string from Win.ini (the registry).
+ * String will be in form "printername,drivername,portname".
+ * This is the most portable way to get the default printer. */
+ if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof
(pname_buf)) <= 0)
+ return Qnil;
+ /* printername precedes first "," character */
+ strtok (pname_buf, ",");
+ /* We want to know more than the printer name */
+ if (!OpenPrinter (pname_buf, &hPrn, NULL))
+ return Qnil;
+ GetPrinter (hPrn, 2, NULL, 0, &dwNeeded);
+ if (dwNeeded == 0)
+ {
+ ClosePrinter (hPrn);
+ return Qnil;
+ }
+ /* Allocate memory for the PRINTER_INFO_2 struct */
+ ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded);
+ if (!ppi2)
+ {
+ ClosePrinter (hPrn);
+ return Qnil;
+ }
+ /* Call GetPrinter() again with big enouth memory block */
+ err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned);
+ ClosePrinter (hPrn);
+ if (!err)
+ {
+ xfree(ppi2);
+ return Qnil;
+ }
+
+ if (ppi2)
+ {
+ if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName)
+ {
+ /* a remote printer */
+ if (*ppi2->pServerName == '\\')
+ _snprintf(pname_buf, sizeof (pname_buf), "%s\\%s",
ppi2->pServerName,
+ ppi2->pShareName);
+ else
+ _snprintf(pname_buf, sizeof (pname_buf), "\\\\%s\\%s",
ppi2->pServerName,
+ ppi2->pShareName);
+ pname_buf[sizeof (pname_buf) - 1] = '\0';
+ }
+ else
+ {
+ /* a local printer */
+ strncpy(pname_buf, ppi2->pPortName, sizeof (pname_buf));
+ pname_buf[sizeof (pname_buf) - 1] = '\0';
+ /* `pPortName' can include several ports, delimited by ','.
+ * we only use the first one. */
+ strtok(pname_buf, ",");
+ }
+ xfree(ppi2);
+ }
+
+ return build_string (pname_buf);
+}
+
/***********************************************************************
Initialization
***********************************************************************/
@@ -14377,6 +14448,7 @@
defsubr (&Sw32_find_bdf_fonts);
defsubr (&Sfile_system_info);
+ defsubr (&Sdefault_printer_name);
/* Setting callback functions for fontset handler. */
get_font_info_func = w32_get_font_info;
--
Peter 'Luna' Runestig (fd. Altberg), Sweden <address@hidden>
PGP Key ID: 0xD07BBE13
Fingerprint: 7B5C 1F48 2997 C061 DE4B 42EA CB99 A35C D07B BE13
AOL Instant Messenger Screen name: PRunestig
Yahoo! Messenger profile name: altberg
- Re: Windows port: using Windows' default printer, (continued)
- Re: Windows port: using Windows' default printer, Stefan Monnier, 2003/09/15
- Re: Windows port: using Windows' default printer, Eli Zaretskii, 2003/09/21
- Re: Windows port: using Windows' default printer, Stefan Monnier, 2003/09/21
- Re: Windows port: using Windows' default printer, Eli Zaretskii, 2003/09/22
- Re: Windows port: using Windows' default printer, Peter 'Luna' Runestig, 2003/09/23
- Re: Windows port: using Windows' default printer, Eli Zaretskii, 2003/09/24
- Re: Windows port: using Windows' default printer, Luc Teirlinck, 2003/09/24
- Re: Windows port: using Windows' default printer,
Peter 'Luna' Runestig <=