]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/wxbtableparser.cpp
Strip pathname portion off all message routines that print filename:line.
[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    Copyright (C) 2004-2005 Kern Sibbald
18
19    This program is free software; you can redistribute it and/or
20    modify it under the terms of the GNU General Public License
21    version 2 as amended with additional clauses defined in the
22    file LICENSE in the main source directory.
23
24    This program is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
27    the file LICENSE for additional details.
28
29  */
30
31 #include "bacula.h"
32
33 #include "wxbtableparser.h" // class's header file
34
35 #include "csprint.h"
36
37 #include <wx/tokenzr.h>
38
39 #include "wxbmainframe.h"
40
41 #include <wx/arrimpl.cpp>
42
43 WX_DEFINE_OBJARRAY(wxbTable);
44
45 wxbArrayString::wxbArrayString(int n) : wxArrayString(), wxObject() {
46    Alloc(n);
47 }
48
49 wxbArrayString::~wxbArrayString() {
50    
51 }
52
53 /*
54  *   wxbTableParser constructor
55  */
56 wxbTableParser::wxbTableParser(bool header) : wxbTable(), wxbDataParser(true) {
57    separatorNum = header ? 0 : 2;
58    tableHeader = wxbArrayString();
59 }
60
61 /*
62  *   wxbTableParser destructor
63  */
64 wxbTableParser::~wxbTableParser() {
65
66 }
67
68 /*
69  *   Returns table header as an array of wxStrings.
70  */
71 const wxbArrayString& wxbTableParser::GetHeader() {
72    return tableHeader;
73 }
74
75 /*
76  *   Receives data to analyse.
77  */
78 bool wxbTableParser::Analyse(wxString str, int status) {
79    if ((status == CS_END) && (separatorNum > 0)) {
80       separatorNum = 3;
81    }
82
83    if (separatorNum == 3) return false;
84
85    if (str.Length() > 4) {
86       if ((str.GetChar(0) == '+') && (str.GetChar(str.Length()-2) == '+') && (str.GetChar(str.Length()-1) == '\n')) {
87          separatorNum++;
88          return false;
89       }
90
91       if ((str.GetChar(0) == '|') && (str.GetChar(str.Length()-2) == '|') && (str.GetChar(str.Length()-1) == '\n')) {
92          str.RemoveLast();
93          wxStringTokenizer tkz(str, wxT("|"), wxTOKEN_STRTOK);
94
95          if (separatorNum == 1) {
96             while ( tkz.HasMoreTokens() ) {
97                tableHeader.Add(tkz.GetNextToken().Trim(true).Trim(false));
98             }
99          }
100          else if (separatorNum == 2) {
101             wxbArrayString tablerow(tableHeader.GetCount());
102             while ( tkz.HasMoreTokens() ) {
103                tablerow.Add(tkz.GetNextToken().Trim(true).Trim(false));
104             }
105             Add(tablerow);
106          }
107       }
108    }
109    return false;
110 }
111
112 /*
113  *   Return true table parsing has finished.
114  */
115 bool wxbTableParser::hasFinished() {
116    return (separatorNum == 3);
117 }