]>
cygwin.com Git - cygwin-apps/cygutils.git/blob - src/lpr/lpr.cc
2 * lpr for cygwin/windows
4 * Copyright (C) 2000-2003 Rick Rankin
5 * http://www.cygwin.com/ml/cygwin/2000-07/msg00320.html
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation in version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/cygwin.h>
31 #include "src/lpr/Printer.hh"
37 string
getProgramName(const string
& str
)
39 string::size_type lastSlashPos
= str
.find_last_of("\\/");
40 if (lastSlashPos
== string::npos
)
44 string::size_type dotPos
= str
.find_last_of(".");
45 if (dotPos
== string::npos
|| dotPos
< lastSlashPos
)
46 dotPos
= str
.length();
47 return str
.substr(lastSlashPos
, dotPos
- lastSlashPos
);
50 const char * usageMessage
=
51 " [-h] [-D] [-d device] [-l] [-P device]\n"
55 " -h does nothing. Accepted for compatibility.\n"
56 " -d device spools to the specified device.\n"
57 " -D enable debugging output.\n"
58 " -l prevent <LF> -> <CR><LF> processing. By default, standalone"
59 " <LF> characters are converted to <CR><LF>."
60 " -P device spools to the specified device.\n"
64 "-d and -P are aliases of each other and perform the same function.\n"
65 "Device names may take the form of DOS devices (e.g., lpt1:) if the printer\n"
66 "is connected locally. Network printers can be accessed using the form\n"
67 "'\\\\server\\printer_name'. Forward slashes can be used as well, e.g.,\n"
68 "'//server/printer_name'.\n"
70 "The environment variable PRINTER can be used to set the default printer\n"
73 void usage(const string
& msg
= "")
76 cerr
<< progName
<< ": " << msg
<< endl
<< endl
;
78 cerr
<< "Usage: " << progName
<< usageMessage
;
82 int main(int argc
, char *argv
[])
84 progName
= getProgramName(argv
[0]);
85 string printerName
= "";
87 // Is the printer specified in the environment?
88 const char *p
= getenv("PRINTER");
92 bool debugFlag
= false;
96 while ((optionChar
= getopt(argc
, argv
, ":Dd:hlP:")) != EOF
)
101 // accept for compatibility
108 printerName
= optarg
;
114 usage(string("unknown option: -") + char(optionChar
));
118 // Can't proceed without a printer name.
119 if (printerName
== "")
121 cerr
<< progName
<< ": no printer specified" << endl
;
125 char winPrinter
[MAX_PATH
];
126 cygwin_conv_to_win32_path(printerName
.c_str(), winPrinter
);
128 cout
<< "Windows printer name = '" << winPrinter
<< "'" << endl
;
132 Printer
pr(winPrinter
, debugFlag
);
133 pr
.setRawFlag(rawFlag
);
136 pr
.print(cin
, "stdin");
139 for (int ii
= optind
; ii
< argc
; ++ii
)
141 ifstream
in (argv
[ii
]);
143 cerr
<< progName
<< ": can't open '" << argv
[ii
] << "' for input."
146 pr
.print(in
, argv
[ii
]);
151 catch (const PrinterException
& ex
)
153 cerr
<< progName
<< ": printer error: " << ex
<< endl
;
This page took 0.041349 seconds and 5 git commands to generate.