Thread View: news.software.readers
12 messages
12 total messages
Started by root
Tue, 26 May 1998 00:00
Windows 16/32 printer code for slrn
Author: root
Date: Tue, 26 May 1998 00:00
Date: Tue, 26 May 1998 00:00
51 lines
1644 bytes
1644 bytes
The following sample code should work for Windows 3.x printing from
the slrn program, and will even work for Windows 95/98 printing when
used on a personal computer not connected to a network. To use this
code, insert it into slrn/src/print.c, with appropriate modifications:
#ifdef USE_WIN16_PRINT_CODE /*{{{*/
typedef struct _Slrn_Print_Type
{
FILE *fp;
int error_status;
} Slrn_Print_Type;
static Slrn_Print_Type p;
Slrn_Print_Type *win16_open_printer (void)
{
p.fp = fopen("prn", "w");
if (!p.fp)
{
p.error_status = 1;
slrn_error ("Printer not supported");
return NULL;
}
else
{
p.error_status = 0;
return (Slrn_Print_Type *)&p;
};
}
int win16_write_to_printer (Slrn_Print_Type *p, char *buf, unsigned int len)
{
char huge *p_buf = buf;
while (len--)
if (fputc(*p_buf++, p->fp) == EOF)
{
p->error_status = 1;
return -1;
};
return 0;
}
int win16_close_printer (Slrn_Print_Type *p)
{
return fclose(p->fp);
}
/*}}}*/
#endif /* USE_WIN16_PRINT_CODE */
Re: Windows 16/32 printer code for slrn
Author: root
Date: Wed, 27 May 1998 00:00
Date: Wed, 27 May 1998 00:00
41 lines
2049 bytes
2049 bytes
In article <6kefal$6pn$1@gte1.gte.net>, you say...
>
>The following sample code should work for Windows 3.x printing from
>the slrn program, and will even work for Windows 95/98 printing when
>used on a personal computer not connected to a network. To use this
>code, insert it into slrn/src/print.c, with appropriate modifications:
>
>#ifdef USE_WIN16_PRINT_CODE /*{{{*/
>typedef struct _Slrn_Print_Type
>{
> FILE *fp;
> int error_status;
>} Slrn_Print_Type;
>static Slrn_Print_Type p;
>
There is a problem with defining a local variable and passing it
back to the calling functions, even when the variable is not static,
as defined here. This is probably why the pipe to printer code uses
malloc to generate a pointer to the structure,
>Slrn_Print_Type *win16_open_printer (void)
>{
> p.fp = fopen("prn", "w");
> if (!p.fp)
Using prn, rather than specific printer port files like lpt1, might
just work on a PC connected to a network. Does anyone have any
information about how the system interprets prn when the installed
printer is the network printer?
With the few changes indicated above, my experimental 16-bit version
of slrn.952 is communicating with my Lexmark printer, which, however,
isn't entirely happy doing buffered printing from fputc(), something
which I verified by writing a test program.
BTW, does anyone know where in the slrn code the information about
article numbers > 32KB (for integer variables) is stored?
Re: Windows 16/32 printer code for slrn
Author: root
Date: Wed, 27 May 1998 00:00
Date: Wed, 27 May 1998 00:00
20 lines
1349 bytes
1349 bytes
On 26 May 1998 13:16:05 GMT, root@gte.net <root@gte.net> wrote:
>The following sample code should work for Windows 3.x printing from
>the slrn program, and will even work for Windows 95/98 printing when
>used on a personal computer not connected to a network. To use this
>code, insert it into slrn/src/print.c, with appropriate modifications:
>
>#ifdef USE_WIN16_PRINT_CODE /*{{{*/
>typedef struct _Slrn_Print_Type
>{
> FILE *fp;
> int error_status;
This is coming from a first debug version of 0.9.5.2 slrn ported to
16-bit windows. I just tried the `y' key to print the article, and
no response. Hopefully, that is just a program bug, or my use of
an earlier version of art.c, because the current version kept on
crashing in qsort.
Re: Windows 16/32 printer code for slrn
Author: root
Date: Wed, 27 May 1998 00:00
Date: Wed, 27 May 1998 00:00
25 lines
1671 bytes
1671 bytes
On 27 May 1998 10:56:02 GMT, root@gte.net <root@gte.net> wrote:
>On 26 May 1998 13:16:05 GMT, root@gte.net <root@gte.net> wrote:
>>The following sample code should work for Windows 3.x printing from
>>the slrn program, and will even work for Windows 95/98 printing when
>>used on a personal computer not connected to a network. To use this
>>code, insert it into slrn/src/print.c, with appropriate modifications:
>>
>>#ifdef USE_WIN16_PRINT_CODE /*{{{*/
>>typedef struct _Slrn_Print_Type
>>{
>> FILE *fp;
>> int error_status;
>
>This is coming from a first debug version of 0.9.5.2 slrn ported to
>16-bit windows. I just tried the `y' key to print the article, and
>no response. Hopefully, that is just a program bug, or my use of
>an earlier version of art.c, because the current version kept on
>crashing in qsort.
There is definitely something about the 952 version of art.c that
causes qsort to crash. Substituting earlier versions of the functions
that use qsort into the recent code doesn't stop qsort from crashing.
Re: Windows 16/32 printer code for slrn
Author: John E. Davis
Date: Thu, 28 May 1998 00:00
Date: Thu, 28 May 1998 00:00
24 lines
1247 bytes
1247 bytes
On 28 May 1998 13:14:55 GMT, root@gte.net <root@gte.net>
wrote:
>article numbers that occurs in a number of news readers. Have you
>checked whether your network considers the file "prn" to be the
>network printer?
It does not:
copy con: prn:
test
^Z
Write fault error writing device PRN
Abort, Retry, Ignore, Fail?
Fail on INT 24 - prn
0 files(s) copied
This is the reason I coded the printer interface in C instead of a
macro that opened prn: and wrote out the article to that.
--John
Re: Windows 16/32 printer code for slrn
Author: John E. Davis
Date: Thu, 28 May 1998 00:00
Date: Thu, 28 May 1998 00:00
12 lines
954 bytes
954 bytes
On 27 May 1998 23:46:58 GMT, root <vtailor@gte.net> wrote: >BTW, does anyone know where in the slrn code the information about >article numbers > 32KB (for integer variables) is stored? Nowhere. I wrote it with the assumption that sizeof(int) >= 4, and on such a system, ints can can be larger than 2 billion. --John
Re: Windows 16/32 printer code for slrn
Author: root
Date: Thu, 28 May 1998 00:00
Date: Thu, 28 May 1998 00:00
72 lines
2917 bytes
2917 bytes
On 28 May 1998 06:05:11 GMT, John E. Davis <davis@space.mit.edu> wrote:
>On 27 May 1998 23:46:58 GMT, root <vtailor@gte.net>
>wrote:
>>BTW, does anyone know where in the slrn code the information about
>>article numbers > 32KB (for integer variables) is stored?
>
>Nowhere. I wrote it with the assumption that sizeof(int) >= 4, and on
>such a system, ints can can be larger than 2 billion.
>
Well, sizeof(int) == 2 on 16-bit systems, therefore the problem with
article numbers that occurs in a number of news readers. Have you
checked whether your network considers the file "prn" to be the
network printer?
========================================================================
Corrected and tested 16-bit printer code for slrn:
#ifdef USE_WIN16_PRINT_CODE /*{{{*/
/* stdio fopen will work, but printer errors with stdio calls */
/* cause the system to crash. _lopen, _hwrite, and _lclose do */
/* not cause system crashes. Note that this works with Dos- */
/* compatible printers, such as pin printers, and most, but */
/* not all inkjets (IBM Lexmark has problems with file I/O). */
/* Using "prn" as the printer forces the system to select the */
/* currently-installed system printer. The 16-bit Windows family */
/* of _lopen calls is considered obsolete, but still supported, */
/* in Windows 95/98 and Windows NT. */
int win16_write_to_printer (Slrn_Print_Type *p, char *buf, unsigned int len)
{
if ((p == NULL) || (p->h == NULL) || (p->error_status))
return -1;
if (len != _hwrite(p->h, buf, (long)len))
{
p->error_status = 1;
slrn_error ("Error writing to print process");
return -1;
};
return 0;
}
int win16_close_printer (Slrn_Print_Type *p)
{
int nRval;
nRval = _lclose(p->h);
slrn_free ((char *) p);
return nRval;
}
Slrn_Print_Type *win16_open_printer ( )
{
Slrn_Print_Type *p;
if (NULL == (p = (Slrn_Print_Type *)SLmalloc(sizeof (Slrn_Print_Type))))
return NULL;
memset((char *)p, 0, sizeof(Slrn_Print_Type));
if (HFILE_ERROR == (p->h = _lopen ("prn", OF_SHARE_DENY_WRITE | WRITE)))
{
slrn_error ("Printer not supported");
return NULL;
}
else
return p;
}
/*}}}*/
#endif /* USE_WIN16_PRINT_CODE */
Re: Windows 16/32 printer code for slrn
Author: root
Date: Thu, 28 May 1998 00:00
Date: Thu, 28 May 1998 00:00
24 lines
1393 bytes
1393 bytes
On 28 May 1998 18:08:38 GMT, John E. Davis <davis@space.mit.edu> wrote: >On 28 May 1998 13:14:55 GMT, root@gte.net <root@gte.net> >wrote: >>article numbers that occurs in a number of news readers. Have you >>checked whether your network considers the file "prn" to be the >>network printer? > >It does not: > > copy con: prn: > test > ^Z > Write fault error writing device PRN > Abort, Retry, Ignore, Fail? > Fail on INT 24 - prn > 0 files(s) copied > >This is the reason I coded the printer interface in C instead of a >macro that opened prn: and wrote out the article to that. > It was worth a try. C'est la guerre.
Re: Windows 16/32 printer code for slrn
Author: root
Date: Fri, 29 May 1998 00:00
Date: Fri, 29 May 1998 00:00
37 lines
2245 bytes
2245 bytes
On 29 May 1998 15:12:40 GMT, root@gte.net <root@gte.net> wrote: >On 28 May 1998 20:13:07 GMT, root@gte.net <root@gte.net> wrote: >>On 28 May 1998 18:08:38 GMT, John E. Davis <davis@space.mit.edu> wrote: >>>On 28 May 1998 13:14:55 GMT, root@gte.net <root@gte.net> >>>wrote: >>>>article numbers that occurs in a number of news readers. Have you >>>>checked whether your network considers the file "prn" to be the >>>>network printer? >>> >>>It does not: >>> >>> copy con: prn: >>> test >>> ^Z >>> Write fault error writing device PRN >>> Abort, Retry, Ignore, Fail? >>> Fail on INT 24 - prn >>> 0 files(s) copied >>> >>>This is the reason I coded the printer interface in C instead of a >>>macro that opened prn: and wrote out the article to that. >>> >>It was worth a try. C'est la guerre. > >The next ploy will be to use the Windows 3.x `escape' printing functions >that are obsolescent, but supported in the latest NT/98 releases. Talk >about sullying oneself with dirty code that is not part of the C mainstream. If this were an academic environment, the notion of using a C compiler that didn't implement the right things when you open a printer as a file under Windows would be derisible. You can see the heavy hand of Microsoft in this piece of nonsense. I am leaning towards implementing a version of fprintf that knows how to use the Windows `textout' command for the right file pointers.
Re: Windows 16/32 printer code for slrn
Author: root
Date: Fri, 29 May 1998 00:00
Date: Fri, 29 May 1998 00:00
29 lines
1734 bytes
1734 bytes
On 28 May 1998 20:13:07 GMT, root@gte.net <root@gte.net> wrote: >On 28 May 1998 18:08:38 GMT, John E. Davis <davis@space.mit.edu> wrote: >>On 28 May 1998 13:14:55 GMT, root@gte.net <root@gte.net> >>wrote: >>>article numbers that occurs in a number of news readers. Have you >>>checked whether your network considers the file "prn" to be the >>>network printer? >> >>It does not: >> >> copy con: prn: >> test >> ^Z >> Write fault error writing device PRN >> Abort, Retry, Ignore, Fail? >> Fail on INT 24 - prn >> 0 files(s) copied >> >>This is the reason I coded the printer interface in C instead of a >>macro that opened prn: and wrote out the article to that. >> >It was worth a try. C'est la guerre. The next ploy will be to use the Windows 3.x `escape' printing functions that are obsolescent, but supported in the latest NT/98 releases. Talk about sullying oneself with dirty code that is not part of the C mainstream.
Re: Windows 16/32 printer code for slrn
Author: root
Date: Sat, 30 May 1998 00:00
Date: Sat, 30 May 1998 00:00
115 lines
3630 bytes
3630 bytes
On 28 May 1998 18:08:38 GMT, John E. Davis <davis@space.mit.edu> wrote:
>On 28 May 1998 13:14:55 GMT, root@gte.net <root@gte.net>
>wrote:
>>article numbers that occurs in a number of news readers. Have you
>>checked whether your network considers the file "prn" to be the
>>network printer?
>
>It does not:
>
> copy con: prn:
> test
> ^Z
> Write fault error writing device PRN
> Abort, Retry, Ignore, Fail?
> Fail on INT 24 - prn
> 0 files(s) copied
>
>This is the reason I coded the printer interface in C instead of a
>macro that opened prn: and wrote out the article to that.
>
The following is (roughly and approximately) what your code would
look like if it didn't rely on winspool.lib and was upwardly
compatible with everything from Windows 3 up to the latest NT
and 98:
typedef struct
{
FILE *fp;
int error_status;
int nLines;
} Slrn_Print_Type;
int win16_write_to_printer (Slrn_Print_Type *p, char *buf, unsigned int len)
{
PRINTDLG *pd;
if ((p == NULL) || (p->fp == NULL) || (p->error_status))
return -1;
pd = (PRINTDLG *)(p->fp);
/* Send the next line to the printer's driver: */
if (TextOut(pd->hDC, 50, 50 * p->nLines, buf, len) == 0)
{
p->error_status = 1;
return -1;
};
/* End of page? */
if ((p->nLines = p->nLines % 50) == 0)
Escape(pd->hDC, NEWFRAME, 0, NULL, NULL);
p->nLines++;
return 0;
}
int win16_close_printer (Slrn_Print_Type *p)
{
int nRval;
PRINTDLG *pd = (PRINTDLG *)(p->fp);
nRval = Escape(pd->hDC, ENDDOC, 0, NULL, NULL);
DeleteDC(pd->hDC);
if (pd->hDevMode != NULL)
GlobalFree(pd->hDevMode);
if (pd->hDevNames != NULL)
GlobalFree(pd->hDevNames);
slrn_free ((char *) p);
slrn_free ((char *)pd);
return nRval;
}
Slrn_Print_Type *win16_open_printer ( )
{
Slrn_Print_Type *p;
PRINTDLG *pd;
/* This is a the wstdio library name for the main text */
/* window, but could be gotten through a Get....() call: */
extern HWND hWndCurrent;
if (NULL == (p = (Slrn_Print_Type *)SLmalloc(sizeof (Slrn_Print_Type))))
return NULL;
memset((char *)p, 0, sizeof(Slrn_Print_Type));
if ((pd = (PRINTDLG *)SLmalloc(sizeof(PRINTDLG))) == NULL)
return NULL;
/* Set all structure members to zero. */
memset((char *)pd, 0, sizeof(PRINTDLG));
p->fp = (FILE *)pd;
p->nLines = 5; /* Leave 5 blank lines at top of page. */
pd->lStructSize = sizeof(PRINTDLG);
pd->hwndOwner = hWndCurrent;
pd->Flags = PD_RETURNDC;
/* This calls a commdlg dialog that connects to the system */
/* printer and initializes the device context: */
if (PrintDlg(pd) == 0)
{
_message_error("Missing commdlg.dll file, or printer not connected.", NULL);
return NULL;
}
else
{
Escape(pd->hDC, STARTDOC, 8, "Article-Doc", NULL);
return p;
};
}
Re: Windows 16/32 printer code for slrn
Author: root
Date: Sun, 31 May 1998 00:00
Date: Sun, 31 May 1998 00:00
47 lines
2576 bytes
2576 bytes
On 30 May 1998 00:39:03 GMT, root@gte.net <root@gte.net> wrote: >On 28 May 1998 18:08:38 GMT, John E. Davis <davis@space.mit.edu> wrote: >>On 28 May 1998 13:14:55 GMT, root@gte.net <root@gte.net> >>wrote: >>>article numbers that occurs in a number of news readers. Have you >>>checked whether your network considers the file "prn" to be the >>>network printer? >> >>It does not: >> >> copy con: prn: >> test >> ^Z >> Write fault error writing device PRN >> Abort, Retry, Ignore, Fail? >> Fail on INT 24 - prn >> 0 files(s) copied >> >>This is the reason I coded the printer interface in C instead of a >>macro that opened prn: and wrote out the article to that. >> >The following is (roughly and approximately) what your code would >look like if it didn't rely on winspool.lib and was upwardly >compatible with everything from Windows 3 up to the latest NT >and 98: Actually, your reason for using the winspool.lib code in slrn is not that other methods fail. It is simply that Microsoft's Dos window doesn't permit any other method for printing from the console, if the printer won't accept character output directly via stdio calls. I've been checking, and the PrintDlg() call fails from the WIndows 32 console, using CreateDC and getting the printer and driver info from the win.ini file also fails to get the printer running. The question comes down to consistency then: If you rely on a separate sendmail or sendsmtp program from slrn, then why not simply make the printer code a separate, and WinMain, type of program? You could call it WinLpr or something like that. Then slrn wouldn't be constrained by the narrow architecture of the Win32 console. Oh well, I've got a little spare time. Maybe I'll implement a Win32Lpr.exe program.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads