FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
io_printer.c
Go to the documentation of this file.
1
/* dos printer driver */
2
3
#include "../fb.h"
4
5
/* DEV_LPT_INFO->driver_opaque := (FILE *) file_handle */
6
7
int
fb_PrinterOpen
(
DEV_LPT_INFO
*devInfo,
int
iPort,
const
char
*pszDevice )
8
{
9
int
result;
10
char
filename
[64];
11
FILE *fp;
12
13
if
( iPort==0 ) {
14
/* "LPT:" selects default "LPT1:" */
15
devInfo->
iPort
= 1;
16
}
else
{
17
devInfo->
iPort
= iPort;
18
}
19
20
sprintf(filename,
"LPT%d"
, devInfo->
iPort
);
21
fp = fopen(filename,
"wb"
);
22
23
devInfo->
driver_opaque
= fp;
24
25
if
( fp==
NULL
) {
26
result =
fb_ErrorSetNum
(
FB_RTERROR_FILENOTFOUND
);
27
}
else
{
28
result =
fb_ErrorSetNum
(
FB_RTERROR_OK
);
29
}
30
31
return
result;
32
}
33
34
int
fb_PrinterWrite
(
DEV_LPT_INFO
*devInfo,
const
void
*data,
size_t
length )
35
{
36
FILE *fp = (FILE*) devInfo->
driver_opaque
;
37
if
( fwrite( data, length, 1, fp ) != 1 ) {
38
return
fb_ErrorSetNum
(
FB_RTERROR_FILEIO
);
39
}
40
return
fb_ErrorSetNum
(
FB_RTERROR_OK
);
41
}
42
43
int
fb_PrinterWriteWstr
(
DEV_LPT_INFO
*devInfo,
const
FB_WCHAR
*data,
size_t
length )
44
{
45
/* !!!FIXME!!! no support for unicode output */
46
47
char
*temp = alloca( length + 1 );
48
49
if
( length > 0 )
50
fb_wstr_ConvToA
( temp, data, length );
51
else
52
*temp =
'\0'
;
53
54
return
fb_PrinterWrite
( devInfo, (
void
*)temp, length );
55
}
56
57
int
fb_PrinterClose
(
DEV_LPT_INFO
*devInfo )
58
{
59
FILE *fp = (FILE*) devInfo->
driver_opaque
;
60
61
fclose(fp);
62
devInfo->
driver_opaque
=
NULL
;
63
64
return
fb_ErrorSetNum
(
FB_RTERROR_OK
);
65
}
rtlib
dos
io_printer.c
Generated on Thu Jan 23 2014 19:40:09 for FreeBASIC by
1.8.4