]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbtableparser.cpp
Create archivedir
[bacula/bacula] / bacula / src / wx-console / wxbtableparser.cpp
1 /*
2  *
3  *   Class used to parse tables received from director in this format :
4  *
5  *  +---------+---------+-------------------+
6  *  | Header1 | Header2 | ...               |
7  *  +---------+---------+-------------------+
8  *  |  Data11 | Data12  | ...               |
9  *  |  ....   | ...     | ...               |
10  *  +---------+---------+-------------------+
11  *
12  *    Nicolas Boichat, April 2004
13  *
14  *    Version $Id$
15  */
16 /*
17    Bacula® - The Network Backup Solution
18
19    Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
20
21    The main author of Bacula is Kern Sibbald, with contributions from
22    many others, a complete list can be found in the file AUTHORS.
23    This program is Free Software; you can redistribute it and/or
24    modify it under the terms of version two of the GNU General Public
25    License as published by the Free Software Foundation and included
26    in the file LICENSE.
27
28    This program is distributed in the hope that it will be useful, but
29    WITHOUT ANY WARRANTY; without even the implied warranty of
30    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31    General Public License for more details.
32
33    You should have received a copy of the GNU General Public License
34    along with this program; if not, write to the Free Software
35    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36    02110-1301, USA.
37
38    Bacula® is a registered trademark of Kern Sibbald.
39    The licensor of Bacula is the Free Software Foundation Europe
40    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
41    Switzerland, email:ftf@fsfeurope.org.
42 */
43
44 /*  Windows debug builds set _DEBUG which is used by wxWidgets to select their
45  *  debug memory allocator.  Unfortunately it conflicts with Bacula's SmartAlloc.
46  * So we turn _DEBUG off since we aren't interested in things it enables.
47  */
48
49 #undef _DEBUG
50
51 #include "bacula.h"
52
53 #include "wxbtableparser.h" // class's header file
54
55 #include "csprint.h"
56
57 #include <wx/tokenzr.h>
58
59 #include "wxbmainframe.h"
60
61 #include <wx/arrimpl.cpp>
62
63 WX_DEFINE_OBJARRAY(wxbTable);
64
65 wxbArrayString::wxbArrayString(int n) : wxArrayString(), wxObject() {
66    Alloc(n);
67 }
68
69 wxbArrayString::~wxbArrayString() {
70    
71 }
72
73 /*
74  *   wxbTableParser constructor
75  */
76 wxbTableParser::wxbTableParser(bool header) : wxbTable(), wxbDataParser(true) {
77    separatorNum = header ? 0 : 2;
78    tableHeader = wxbArrayString();
79 }
80
81 /*
82  *   wxbTableParser destructor
83  */
84 wxbTableParser::~wxbTableParser() {
85
86 }
87
88 /*
89  *   Returns table header as an array of wxStrings.
90  */
91 const wxbArrayString& wxbTableParser::GetHeader() {
92    return tableHeader;
93 }
94
95 /*
96  *   Receives data to analyse.
97  */
98 bool wxbTableParser::Analyse(wxString str, int status) {
99    if ((status == CS_END) && (separatorNum > 0)) {
100       separatorNum = 3;
101    }
102
103    if (separatorNum == 3) return false;
104
105    if (str.Length() > 4) {
106       if ((str.GetChar(0) == '+') && (str.GetChar(str.Length()-2) == '+') && (str.GetChar(str.Length()-1) == '\n')) {
107          separatorNum++;
108          return false;
109       }
110
111       if ((str.GetChar(0) == '|') && (str.GetChar(str.Length()-2) == '|') && (str.GetChar(str.Length()-1) == '\n')) {
112          str.RemoveLast();
113          wxStringTokenizer tkz(str, wxT("|"), wxTOKEN_STRTOK);
114
115          if (separatorNum == 1) {
116             while ( tkz.HasMoreTokens() ) {
117                tableHeader.Add(tkz.GetNextToken().Trim(true).Trim(false));
118             }
119          }
120          else if (separatorNum == 2) {
121             wxbArrayString tablerow(tableHeader.GetCount());
122             while ( tkz.HasMoreTokens() ) {
123                tablerow.Add(tkz.GetNextToken().Trim(true).Trim(false));
124             }
125             Add(tablerow);
126          }
127       }
128    }
129    return false;
130 }
131
132 /*
133  *   Return true table parsing has finished.
134  */
135 bool wxbTableParser::hasFinished() {
136    return (separatorNum == 3);
137 }