// this function support LPRng piping feature, it defaults to // /etc/printcap in any other cases (basic support) QString getPrintcapFileName() { // check if LPRng system QString printcap("/etc/printcap"); QFile f("/etc/lpd.conf"); if (f.exists() && f.open(IO_ReadOnly)) { kdDebug() << "/etc/lpd.conf found: probably LPRng system" << endl; QTextStream t(&f); QString line; while (!t.eof()) { line = t.readLine().stripWhiteSpace(); if (line.startsWith("printcap_path=")) { kdDebug() << "printcap_path entry found: " << line << endl; QString pcentry = line.mid(14).stripWhiteSpace(); kdDebug() << "printcap_path value: " << pcentry << endl; if (pcentry[0] == '|') { // printcap through pipe printcap = locateLocal("tmp","printcap"); QString cmd = QString::fromLatin1("echo \"all\" | %1 > %2").arg(pcentry.mid(1)).arg(printcap); kdDebug() << "printcap obtained through pipe" << endl << "executing: " << cmd << endl; ::system(cmd.local8Bit()); } break; } } } kdDebug() << "printcap file returned: " << printcap << endl; return printcap; }
int qt_parsePrintcap(QList<QPrinterDescription> *printers, const QString& fileName) { QFile printcap(fileName); if (!printcap.open(QIODevice::ReadOnly)) return NotFound; char *line_ascii = new char[1025]; line_ascii[1024] = '\0'; QString printerDesc; bool atEnd = false; while (!atEnd) { if (printcap.atEnd() || printcap.readLine(line_ascii, 1024) <= 0) atEnd = true; QString line = QString::fromLocal8Bit(line_ascii); line = line.trimmed(); if (line.length() >= 1 && line[int(line.length()) - 1] == QLatin1Char('\\')) line.chop(1); if (line[0] == QLatin1Char('#')) { if (!atEnd) continue; } else if (line[0] == QLatin1Char('|') || line[0] == QLatin1Char(':') || line.isEmpty()) { printerDesc += line; if (!atEnd) continue; } qt_parsePrinterDesc(printerDesc, printers); // add the first line of the new printer definition printerDesc = line; } delete[] line_ascii; return Success; }
void printcaplist (Capture *cap, Capture *limit) { printf(">======\n"); for (; cap->s && (limit == NULL || cap < limit); cap++) printcap(cap); printf("=======\n"); }