printing from nedit

Michael Goffioul kde-print@mail.kde.org
Wed, 20 Mar 2002 14:03:43 +0100


This is a multi-part message in MIME format.
--------------4CF375E787D2BA0D71CAF3E0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Thomas Siegmund wrote:
> 
> Hi,
> 
> I noticed a problem with printing from Nedit (5.2) with current KDE3 (rc3):
> 
> My nedit printer command before KDE3 was
> 
> kprinter  -J"Untitled"
> 
> Under KDE2.2 this brought up the kprinter dialog and everything worked as
> expected. Now the dialog comes up completely frozen (no input, no redraw),
> and when killed it takes the editor down too.
> 
> kprinter --stdin -J"Untitled" does the same. Only
> 
> kprinter --stdin --nodialog -J"Untitled"
> 
> works, but in this case I miss the comfort of kprinter. You get used to it :-)
> 
> Of course I am not sure if this is a problem of kprinter or of nedit, all I
> can tell is that it worked in KDE2.2.

I looked into nedit codes, and IMO this is a problem in nedit (for example it
works with Netscape). The technical explanation is the following. Nedit starts
the print command as a child process and retrieve the debug output using a pipe.
The problem is that it only reads the 1024 first bytes, and then tries to close
the pipe. On the kprinter side, it continues to print debug output, until the
buffer of the pipe is full, and then hangs up (what really hangs up is not the
kprinter code, but some kind of printf call).
What nedit should do is read the kprinter output, and just discard everything
after the 1024 bytes (eventually, closing the pipe prematurely can also cause
a SIGPIPE signal in kprinter and crash it). The attached patch modify nedit
so that you can use kprinter safely (tested with nedit-5.2).
Another solution is to disable all debug output of KDE, such that you're sure
that the kprinter output is smaller than 1024 bytes. This is probably what
happened with KDE-2.2.2 (in Linux distros, debug output are usually completely
disabled in regular packages).
IMO, kprinter does the things right, and the problem is nedit.

Bye.
Michael.

-- 
------------------------------------------------------------------
Michael Goffioul		IMEC-DESICS-MIRA
e-mail: goffioul@imec.be	(Mixed-Signal and RF Applications)
Tel:    +32/16/28-8510		Kapeldreef, 75
Fax:    +32/16/28-1515		3001 HEVERLEE, BELGIUM
------------------------------------------------------------------
--------------4CF375E787D2BA0D71CAF3E0
Content-Type: text/plain; charset=us-ascii;
 name="nedit.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="nedit.patch"

--- printUtils.c	Wed Mar 20 13:51:56 2002
+++ ../../nedit-5.2/util/printUtils.c	Tue Aug 14 10:37:16 2001
@@ -708,9 +708,9 @@
     }
 #else
     int nRead;
     FILE *pipe;
-    char errorString[MAX_PRINT_ERROR_LENGTH], dummyBuffer[MAX_PRINT_ERROR_LENGTH];
+    char errorString[MAX_PRINT_ERROR_LENGTH];
 
     /* get the print command from the command text area */
     str = XmTextGetString(Text4);
 
@@ -727,9 +727,8 @@
 	return;
     }
     errorString[0] = 0;
     nRead = fread(errorString, sizeof(char), MAX_PRINT_ERROR_LENGTH-1, pipe);
-    while (fread(dummyBuffer, sizeof(char), MAX_PRINT_ERROR_LENGTH, pipe) > 0) ;
     if (!ferror(pipe))
 	errorString[nRead] = '\0';
     if (pclose(pipe)) {
 	DialogF(DF_WARN, widget, 1, "Unable to Print:\n%s",

--------------4CF375E787D2BA0D71CAF3E0--