20 #include "printcapreader.h"
21 #include "printcapentry.h"
26 void PrintcapReader::setPrintcapFile(TQFile *f)
30 m_stream.setDevice(f);
31 m_buffer = TQString::null;
35 bool PrintcapReader::nextLine(TQString& line)
37 if (m_stream.atEnd() && m_buffer.isEmpty())
39 else if (!m_buffer.isEmpty())
42 m_buffer = TQString::null;
45 line = m_stream.readLine().stripWhiteSpace();
47 if (line[line.length()-1] ==
'\\')
48 line = line.left(line.length()-1).stripWhiteSpace();
52 void PrintcapReader::unputLine(
const TQString& s)
57 PrintcapEntry* PrintcapReader::nextEntry()
59 if (!m_stream.device())
62 TQString line, comment, name, fields, buf;
68 else if (line.isEmpty())
70 else if (line[0] ==
'#')
84 if (!nextLine(line) || line.isEmpty())
87 else if (line[0] ==
'#')
90 else if (line[0] ==
':' || line[0] ==
'|')
102 kdDebug() <<
"COMMENT: " << comment << endl;
103 kdDebug() <<
"LINE: " << buf << endl;
104 int p = buf.find(
':');
110 fields = buf.right(buf.length()-p-1);
116 PrintcapEntry *entry =
new PrintcapEntry;
117 TQStringList l = TQStringList::split(
'|', name,
false);
119 entry->comment = comment;
122 for (uint i=1; i<l.count(); i++)
124 entry->aliases << l[i];
127 if (!fields.isEmpty())
131 l = TQStringList::split(
':', fields,
false);
132 for (TQStringList::ConstIterator it=l.begin(); it!=l.end(); ++it)
135 int p = (*it).find(
'=');
141 f.type = Field::Boolean;
150 f.name = (*it).left(p);
156 f.type = Field::Integer;
157 f.name = (*it).left(p);
158 f.value = (*it).mid(p+1);
163 f.type = Field::String;
164 f.name = (*it).left(p);
165 f.value = (*it).mid(p+1);
166 if (f.value.startsWith(
"\""))
167 f.value = f.value.mid(1, f.value.length()-2);
169 entry->fields[f.name] = f;