]>
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] [-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 " -P device spools to the specified device.\n"
62 "-d and -P are aliases of each other and perform the same function.\n"
63 "Device names may take the form of DOS devices (e.g., lpt1:) if the printer\n"
64 "is connected locally. Network printers can be accessed using the form\n"
65 "'\\\\server\\printer_name'. Forward slashes can be used as well, e.g.,\n"
66 "'//server/printer_name'.\n"
68 "The environment variable PRINTER can be used to set the default printer\n"
71 void usage(const string
& msg
= "")
74 cerr
<< progName
<< ": " << msg
<< endl
<< endl
;
76 cerr
<< "Usage: " << progName
<< usageMessage
;
80 int main(int argc
, char *argv
[])
82 progName
= getProgramName(argv
[0]);
83 string printerName
= "";
85 // Is the printer specified in the environment?
86 const char *p
= getenv("PRINTER");
90 bool debugFlag
= false;
93 while ((optionChar
= getopt(argc
, argv
, ":hDd:P:")) != EOF
)
98 // accept for compatibility
105 printerName
= optarg
;
108 usage(string("unknown option: -") + char(optionChar
));
112 // Can't proceed without a printer name.
113 if (printerName
== "")
115 cerr
<< progName
<< ": no printer specified" << endl
;
119 char winPrinter
[MAX_PATH
];
120 cygwin_conv_to_win32_path(printerName
.c_str(), winPrinter
);
122 cout
<< "Windows printer name = '" << winPrinter
<< "'" << endl
;
126 Printer
pr(winPrinter
, debugFlag
);
129 pr
.print(cin
, "stdin");
132 for (int ii
= optind
; ii
< argc
; ++ii
)
134 ifstream
in (argv
[ii
]);
136 cerr
<< progName
<< ": can't open '" << argv
[ii
] << "' for input."
139 pr
.print(in
, argv
[ii
]);
144 catch (const PrinterException
& ex
)
146 cerr
<< progName
<< ": printer error: " << ex
<< endl
;
This page took 0.041945 seconds and 5 git commands to generate.