• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • lpr
printcapreader.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "printcapreader.h"
21 #include "printcapentry.h"
22 
23 #include <tqfile.h>
24 #include <kdebug.h>
25 
26 void PrintcapReader::setPrintcapFile(TQFile *f)
27 {
28  if (f->isOpen())
29  {
30  m_stream.setDevice(f);
31  m_buffer = TQString::null;
32  }
33 }
34 
35 bool PrintcapReader::nextLine(TQString& line)
36 {
37  if (m_stream.atEnd() && m_buffer.isEmpty())
38  return false;
39  else if (!m_buffer.isEmpty())
40  {
41  line = m_buffer;
42  m_buffer = TQString::null;
43  }
44  else
45  line = m_stream.readLine().stripWhiteSpace();
46  // strip any '\' at the end
47  if (line[line.length()-1] == '\\')
48  line = line.left(line.length()-1).stripWhiteSpace();
49  return true;
50 }
51 
52 void PrintcapReader::unputLine(const TQString& s)
53 {
54  m_buffer = s;
55 }
56 
57 PrintcapEntry* PrintcapReader::nextEntry()
58 {
59  if (!m_stream.device())
60  return NULL;
61 
62  TQString line, comment, name, fields, buf;
63  // skip comments, keep last one
64  while (1)
65  {
66  if (!nextLine(line))
67  return NULL;
68  else if (line.isEmpty())
69  continue;
70  else if (line[0] == '#')
71  comment = line;
72  else
73  {
74  buf = line;
75  break;
76  }
77  }
78 
79  // look for the complete entry
80  while (1)
81  {
82  // we found the entry if we reached the end of file or
83  // found an empty line
84  if (!nextLine(line) || line.isEmpty())
85  break;
86  // just skip comments
87  else if (line[0] == '#')
88  continue;
89  // lines starting with ':' or '|' are appended
90  else if (line[0] == ':' || line[0] == '|')
91  buf += line;
92  // otherwise it's another entry, put it back in the
93  // buffer
94  else
95  {
96  unputLine(line);
97  break;
98  }
99  }
100 
101  // now parse the entry
102  kdDebug() << "COMMENT: " << comment << endl;
103  kdDebug() << "LINE: " << buf << endl;
104  int p = buf.find(':');
105  if (p == -1)
106  name = buf;
107  else
108  {
109  name = buf.left(p);
110  fields = buf.right(buf.length()-p-1);
111  }
112 
113  // construct the printcap entry
114  if (!name.isEmpty())
115  {
116  PrintcapEntry *entry = new PrintcapEntry;
117  TQStringList l = TQStringList::split('|', name, false);
118  entry->name = l[0];
119  entry->comment = comment;
120  // kdDebug() << "Printer: " << entry->name << endl;
121  // kdDebug() << "Aliases:" << endl;
122  for (uint i=1; i<l.count(); i++)
123  {
124  entry->aliases << l[i];
125  // kdDebug() << " " << l[i] << endl;
126  }
127  if (!fields.isEmpty())
128  {
129  // kdDebug() << "Fields:" << endl;
130  // kdDebug() << "(" << fields << ")" << endl;
131  l = TQStringList::split(':', fields, false);
132  for (TQStringList::ConstIterator it=l.begin(); it!=l.end(); ++it)
133  {
134  Field f;
135  int p = (*it).find('=');
136  if (p == -1)
137  {
138  p = (*it).find('#');
139  if (p == -1)
140  {
141  f.type = Field::Boolean;
142  p = (*it).find('@');
143  if (p == -1)
144  {
145  f.name = (*it);
146  f.value = "1";
147  }
148  else
149  {
150  f.name = (*it).left(p);
151  f.value = "0";
152  }
153  }
154  else
155  {
156  f.type = Field::Integer;
157  f.name = (*it).left(p);
158  f.value = (*it).mid(p+1);
159  }
160  }
161  else
162  {
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);
168  }
169  entry->fields[f.name] = f;
170  }
171  }
172  // kdDebug() << endl;
173  return entry;
174  }
175  return NULL;
176 }

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.