]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/table.cpp
applied patch for compilation with gcc 3.0
[wxWidgets.git] / utils / tex2rtf / src / table.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: table.cpp
3 // Purpose: Utilities for manipulating tables
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/01/99
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27
28 #include <wx/hash.h>
29
30 #if wxUSE_IOSTREAMH
31 #include <iostream.h>
32 #include <fstream.h>
33 #else
34 #include <iostream>
35 #include <fstream>
36 #endif
37
38 #include <ctype.h>
39 #include "tex2any.h"
40 #include "table.h"
41
42 ColumnData TableData[40];
43 bool inTabular = FALSE;
44
45 bool startRows = FALSE;
46 bool tableVerticalLineLeft = FALSE;
47 bool tableVerticalLineRight = FALSE;
48 int noColumns = 0; // Current number of columns in table
49 int ruleTop = 0;
50 int ruleBottom = 0;
51 int currentRowNumber = 0;
52
53 /*
54 * Parse table argument
55 *
56 */
57
58 bool ParseTableArgument(char *value)
59 {
60 noColumns = 0;
61 int i = 0;
62 int len = strlen(value);
63 bool isBorder = FALSE;
64 while (i < len)
65 {
66 int ch = value[i];
67 if (ch == '|')
68 {
69 i ++;
70 isBorder = TRUE;
71 }
72 else if (ch == 'l')
73 {
74 TableData[noColumns].leftBorder = isBorder;
75 TableData[noColumns].rightBorder = FALSE;
76 TableData[noColumns].justification = 'l';
77 TableData[noColumns].width = 2000; // Estimate
78 TableData[noColumns].absWidth = FALSE;
79 // TableData[noColumns].spacing = ??
80 noColumns ++;
81 i ++;
82 isBorder = FALSE;
83 }
84 else if (ch == 'c')
85 {
86 TableData[noColumns].leftBorder = isBorder;
87 TableData[noColumns].rightBorder = FALSE;
88 TableData[noColumns].justification = 'c';
89 TableData[noColumns].width = defaultTableColumnWidth; // Estimate
90 TableData[noColumns].absWidth = FALSE;
91 // TableData[noColumns].spacing = ??
92 noColumns ++;
93 i ++;
94 isBorder = FALSE;
95 }
96 else if (ch == 'r')
97 {
98 TableData[noColumns].leftBorder = isBorder;
99 TableData[noColumns].rightBorder = FALSE;
100 TableData[noColumns].justification = 'r';
101 TableData[noColumns].width = 2000; // Estimate
102 TableData[noColumns].absWidth = FALSE;
103 // TableData[noColumns].spacing = ??
104 noColumns ++;
105 i ++;
106 isBorder = FALSE;
107 }
108 else if (ch == 'p')
109 {
110 i ++;
111 int j = 0;
112 char numberBuf[50];
113 ch = value[i];
114 if (ch == '{')
115 {
116 i++;
117 ch = value[i];
118 }
119
120 while ((i < len) && (isdigit(ch) || ch == '.'))
121 {
122 numberBuf[j] = ch;
123 j ++;
124 i ++;
125 ch = value[i];
126 }
127 // Assume we have 2 characters for units
128 numberBuf[j] = value[i];
129 j ++; i++;
130 numberBuf[j] = value[i];
131 j ++; i++;
132 numberBuf[j] = 0;
133 if (value[i] == '}') i++;
134
135 TableData[noColumns].leftBorder = isBorder;
136 TableData[noColumns].rightBorder = FALSE;
137 TableData[noColumns].justification = 'l';
138 TableData[noColumns].width = 20*ParseUnitArgument(numberBuf);
139 TableData[noColumns].absWidth = TRUE;
140 // TableData[noColumns].spacing = ??
141 noColumns ++;
142 isBorder = FALSE;
143 }
144 else
145 {
146 char *buf = new char[strlen(value) + 80];
147 sprintf(buf, "Tabular first argument \"%s\" too complex!", value);
148 OnError(buf);
149 delete[] buf;
150 return FALSE;
151 }
152 }
153 if (isBorder)
154 TableData[noColumns-1].rightBorder = TRUE;
155 return TRUE;
156 }