|
13 | 13 | #include "stdafx.h" |
14 | 14 | #include "FRED.h" |
15 | 15 | #include "TextViewDlg.h" |
16 | | -#include "cfile/cfile.h" |
| 16 | +#include "utils/table_viewer.h" |
17 | 17 |
|
18 | 18 | #ifdef _DEBUG |
19 | 19 | #undef THIS_FILE |
@@ -74,181 +74,18 @@ void TextViewDlg::OnClose() |
74 | 74 |
|
75 | 75 | void TextViewDlg::LoadShipsTblText(const ship_info *sip) |
76 | 76 | { |
77 | | - char line[256], line2[256], file_text[82]; |
78 | | - int i, j, n, found = 0, comment = 0, num_files = 0; |
79 | | - SCP_vector<SCP_string> tbl_file_names; |
80 | | - CFILE *fp; |
81 | | - |
82 | 77 | SetCaption("Ship Table Data"); |
83 | 78 |
|
84 | 79 | if (!sip) |
85 | 80 | return; |
86 | 81 |
|
87 | | - fp = cfopen("ships.tbl", "r"); |
88 | | - Assert(fp); |
89 | | - |
90 | | - |
91 | | - while (cfgets(line, 255, fp)) { |
92 | | - while (line[strlen(line) - 1] == '\n') |
93 | | - line[strlen(line) - 1] = 0; |
94 | | - |
95 | | - for (i=j=0; line[i]; i++) { |
96 | | - if (line[i] == '/' && line[i+1] == '/') |
97 | | - break; |
98 | | - |
99 | | - if (line[i] == '/' && line[i+1] == '*') { |
100 | | - comment = 1; |
101 | | - i++; |
102 | | - continue; |
103 | | - } |
104 | | - |
105 | | - if (line[i] == '*' && line[i+1] == '/') { |
106 | | - comment = 0; |
107 | | - i++; |
108 | | - continue; |
109 | | - } |
110 | | - |
111 | | - if (!comment) |
112 | | - line2[j++] = line[i]; |
113 | | - } |
114 | | - |
115 | | - line2[j] = 0; |
116 | | - if (!strnicmp(line2, "$Name:", 6)) { |
117 | | - drop_trailing_white_space(line2); |
118 | | - found = 0; |
119 | | - i = 6; |
120 | | - |
121 | | - while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@') |
122 | | - i++; |
123 | | - |
124 | | - if (!stricmp(line2 + i, sip->name)) { |
125 | | - m_edit += "-- ships.tbl -------------------------------\r\n"; |
126 | | - found = 1; |
127 | | - } |
128 | | - } |
129 | | - |
130 | | - if (found) { |
131 | | - m_edit += line; |
132 | | - m_edit += "\r\n"; |
133 | | - } |
134 | | - } |
135 | | - |
136 | | - cfclose(fp); |
137 | | - |
138 | | - |
139 | | - // done with ships.tbl, so now check all modular ship tables... |
140 | | - num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-shp.tbm"), CF_SORT_REVERSE); |
141 | | - |
142 | | - for (n = 0; n < num_files; n++){ |
143 | | - tbl_file_names[n] += ".tbm"; |
144 | | - |
145 | | - fp = cfopen(tbl_file_names[n].c_str(), "r"); |
146 | | - Assert(fp); |
147 | | - |
148 | | - memset( line, 0, sizeof(line) ); |
149 | | - memset( line2, 0, sizeof(line2) ); |
150 | | - found = 0; |
151 | | - comment = 0; |
152 | | - |
153 | | - while (cfgets(line, 255, fp)) { |
154 | | - while (line[strlen(line) - 1] == '\n') |
155 | | - line[strlen(line) - 1] = 0; |
156 | | - |
157 | | - for (i=j=0; line[i]; i++) { |
158 | | - if (line[i] == '/' && line[i+1] == '/') |
159 | | - break; |
160 | | - |
161 | | - if (line[i] == '/' && line[i+1] == '*') { |
162 | | - comment = 1; |
163 | | - i++; |
164 | | - continue; |
165 | | - } |
166 | | - |
167 | | - if (line[i] == '*' && line[i+1] == '/') { |
168 | | - comment = 0; |
169 | | - i++; |
170 | | - continue; |
171 | | - } |
172 | | - |
173 | | - if (!comment) |
174 | | - line2[j++] = line[i]; |
175 | | - } |
176 | | - |
177 | | - line2[j] = 0; |
178 | | - if (!strnicmp(line2, "$Name:", 6)) { |
179 | | - drop_trailing_white_space(line2); |
180 | | - found = 0; |
181 | | - i = 6; |
182 | | - |
183 | | - while (line2[i] == ' ' || line2[i] == '\t' || line2[i] == '@') |
184 | | - i++; |
185 | | - |
186 | | - if (!stricmp(line2 + i, sip->name)) { |
187 | | - memset( file_text, 0, sizeof(file_text) ); |
188 | | - snprintf(file_text, sizeof(file_text)-1, "-- %s -------------------------------\r\n", tbl_file_names[n].c_str()); |
189 | | - m_edit += file_text; |
190 | | - found = 1; |
191 | | - } |
192 | | - } |
193 | | - |
194 | | - if (found) { |
195 | | - m_edit += line; |
196 | | - m_edit += "\r\n"; |
197 | | - } |
198 | | - } |
199 | | - |
200 | | - cfclose(fp); |
201 | | - } |
| 82 | + m_edit += table_viewer::get_table_entry_text("ships.tbl", "*-shp.tbm", sip->name).c_str(); |
202 | 83 | } |
203 | 84 |
|
204 | 85 | void TextViewDlg::LoadMusicTblText() |
205 | 86 | { |
206 | | - char line[256]; |
207 | | - CFILE* fp; |
208 | | - |
209 | 87 | SetCaption("Music Table Data"); |
210 | | - |
211 | | - fp = cfopen("music.tbl", "r"); |
212 | | - Assert(fp); |
213 | | - |
214 | | - // print the header |
215 | | - m_edit += "-- music.tbl -------------------------------\r\n"; |
216 | | - |
217 | | - // now get the file content |
218 | | - while (cfgets(line, 255, fp)) { |
219 | | - m_edit += line; |
220 | | - m_edit += "\r\n"; |
221 | | - } |
222 | | - |
223 | | - cfclose(fp); |
224 | | - |
225 | | - SCP_vector<SCP_string> tbl_file_names; |
226 | | - |
227 | | - // done with music.tbl, so now check all modular music tables... |
228 | | - int num_files = cf_get_file_list(tbl_file_names, CF_TYPE_TABLES, NOX("*-mus.tbm"), CF_SORT_REVERSE); |
229 | | - |
230 | | - for (int n = 0; n < num_files; n++) { |
231 | | - tbl_file_names[n] += ".tbm"; |
232 | | - |
233 | | - fp = cfopen(tbl_file_names[n].c_str(), "r"); |
234 | | - Assert(fp); |
235 | | - |
236 | | - memset(line, 0, sizeof(line)); |
237 | | - |
238 | | - // get the name of the current file and print it |
239 | | - char file_text[82]; |
240 | | - memset(file_text, 0, sizeof(file_text)); |
241 | | - snprintf(file_text, sizeof(file_text) - 1, "-- %s -------------------------------\r\n", tbl_file_names[n].c_str()); |
242 | | - m_edit += file_text; |
243 | | - |
244 | | - // now get the file content |
245 | | - while (cfgets(line, 255, fp)) { |
246 | | - m_edit += line; |
247 | | - m_edit += "\r\n"; |
248 | | - } |
249 | | - |
250 | | - cfclose(fp); |
251 | | - } |
| 88 | + m_edit += table_viewer::get_complete_table_text("music.tbl", "*-mus.tbm").c_str(); |
252 | 89 | } |
253 | 90 |
|
254 | 91 | void TextViewDlg::OnSetfocusEdit1() |
|
0 commit comments