[6bec10c] | 1 | /* cavernlog.cc |
---|
| 2 | * Run cavern inside an Aven window |
---|
| 3 | * |
---|
[b3ee5f5] | 4 | * Copyright (C) 2005,2006,2010,2011,2012,2014,2015 Olly Betts |
---|
[6bec10c] | 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #ifdef HAVE_CONFIG_H |
---|
| 22 | # include <config.h> |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #include "aven.h" |
---|
| 26 | #include "cavernlog.h" |
---|
| 27 | #include "filename.h" |
---|
[fb5887c] | 28 | #include "mainfrm.h" |
---|
[6bec10c] | 29 | #include "message.h" |
---|
| 30 | |
---|
[baeae66] | 31 | #include <errno.h> |
---|
[6bec10c] | 32 | #include <stdio.h> |
---|
[a90632c] | 33 | #include <stdlib.h> |
---|
[6bec10c] | 34 | |
---|
| 35 | // For select(): |
---|
| 36 | #ifdef HAVE_SYS_SELECT_H |
---|
| 37 | #include <sys/select.h> |
---|
| 38 | #endif |
---|
| 39 | #include <sys/time.h> |
---|
| 40 | #include <sys/types.h> |
---|
| 41 | #include <unistd.h> |
---|
| 42 | |
---|
[81e1aa4] | 43 | enum { LOG_REPROCESS = 1234 }; |
---|
[fb5887c] | 44 | |
---|
| 45 | BEGIN_EVENT_TABLE(CavernLogWindow, wxHtmlWindow) |
---|
[81e1aa4] | 46 | EVT_BUTTON(LOG_REPROCESS, CavernLogWindow::OnReprocess) |
---|
[fb5887c] | 47 | EVT_BUTTON(wxID_OK, CavernLogWindow::OnOK) |
---|
| 48 | END_EVENT_TABLE() |
---|
| 49 | |
---|
[6bec10c] | 50 | static wxString escape_for_shell(wxString s, bool protect_dash = false) |
---|
| 51 | { |
---|
| 52 | size_t p = 0; |
---|
| 53 | #ifdef __WXMSW__ |
---|
| 54 | bool needs_quotes = false; |
---|
| 55 | while (p < s.size()) { |
---|
[eff69a7] | 56 | wxChar ch = s[p]; |
---|
| 57 | if (ch < 127) { |
---|
| 58 | if (ch == wxT('"')) { |
---|
[6baad4a] | 59 | s.insert(p, 1, wxT('\\')); |
---|
[eff69a7] | 60 | ++p; |
---|
| 61 | needs_quotes = true; |
---|
| 62 | } else if (strchr(" <>&|^", ch)) { |
---|
| 63 | needs_quotes = true; |
---|
| 64 | } |
---|
[6bec10c] | 65 | } |
---|
| 66 | ++p; |
---|
| 67 | } |
---|
| 68 | if (needs_quotes) { |
---|
[6baad4a] | 69 | s.insert(0u, 1, wxT('"')); |
---|
[15322f2] | 70 | s += wxT('"'); |
---|
[6bec10c] | 71 | } |
---|
| 72 | #else |
---|
| 73 | if (protect_dash && !s.empty() && s[0u] == '-') { |
---|
| 74 | // If the filename starts with a '-', protect it from being |
---|
| 75 | // treated as an option by prepending "./". |
---|
[5627cbb] | 76 | s.insert(0, wxT("./")); |
---|
[6bec10c] | 77 | p = 2; |
---|
| 78 | } |
---|
| 79 | while (p < s.size()) { |
---|
| 80 | // Exclude a few safe characters which are common in filenames |
---|
| 81 | if (!isalnum(s[p]) && strchr("/._-", s[p]) == NULL) { |
---|
[6baad4a] | 82 | s.insert(p, 1, wxT('\\')); |
---|
[6bec10c] | 83 | ++p; |
---|
| 84 | } |
---|
| 85 | ++p; |
---|
| 86 | } |
---|
| 87 | #endif |
---|
| 88 | return s; |
---|
| 89 | } |
---|
| 90 | |
---|
[fb5887c] | 91 | CavernLogWindow::CavernLogWindow(MainFrm * mainfrm_, wxWindow * parent) |
---|
| 92 | : wxHtmlWindow(parent), mainfrm(mainfrm_) |
---|
| 93 | { |
---|
[93ff5cc] | 94 | int fsize = parent->GetFont().GetPointSize(); |
---|
| 95 | int sizes[7] = { fsize, fsize, fsize, fsize, fsize, fsize, fsize }; |
---|
[5627cbb] | 96 | SetFonts(wxString(), wxString(), sizes); |
---|
[93ff5cc] | 97 | } |
---|
| 98 | |
---|
[6bec10c] | 99 | void |
---|
| 100 | CavernLogWindow::OnLinkClicked(const wxHtmlLinkInfo &link) |
---|
| 101 | { |
---|
| 102 | wxString href = link.GetHref(); |
---|
| 103 | wxString title = link.GetTarget(); |
---|
[5627cbb] | 104 | size_t colon = href.rfind(wxT(':')); |
---|
[3d3fb6c] | 105 | if (colon == wxString::npos) |
---|
| 106 | return; |
---|
| 107 | size_t colon2 = href.rfind(wxT(':'), colon - 1); |
---|
| 108 | if (colon2 != wxString::npos) swap(colon, colon2); |
---|
[6bec10c] | 109 | #ifdef __WXMSW__ |
---|
[3d3fb6c] | 110 | wxString cmd = wxT("notepad $f"); |
---|
[89a1b72] | 111 | #elif defined __WXMAC__ |
---|
[3d3fb6c] | 112 | wxString cmd = wxT("open -t $f"); |
---|
[6bec10c] | 113 | #else |
---|
[3d3fb6c] | 114 | wxString cmd = wxT("x-terminal-emulator -title $t -e vim +'call cursor($l,$c)' $f"); |
---|
| 115 | // wxString cmd = wxT("gedit -b $f +$l:$c $f"); |
---|
| 116 | // wxString cmd = wxT("x-terminal-emulator -title $t -e emacs +$l $f"); |
---|
| 117 | // wxString cmd = wxT("x-terminal-emulator -title $t -e nano +$l $f"); |
---|
| 118 | // wxString cmd = wxT("x-terminal-emulator -title $t -e jed -g $l $f"); |
---|
[6bec10c] | 119 | #endif |
---|
[3d3fb6c] | 120 | const char * p = getenv("SURVEXEDITOR"); |
---|
| 121 | if (p) { |
---|
| 122 | cmd = wxString(p, wxConvUTF8); |
---|
| 123 | if (!cmd.find(wxT("$f"))) { |
---|
| 124 | cmd += wxT(" $f"); |
---|
[6bec10c] | 125 | } |
---|
[3d3fb6c] | 126 | } |
---|
| 127 | size_t i = 0; |
---|
| 128 | while ((i = cmd.find(wxT('$'), i)) != wxString::npos) { |
---|
| 129 | if (++i >= cmd.size()) break; |
---|
| 130 | switch ((int)cmd[i]) { |
---|
| 131 | case wxT('$'): |
---|
| 132 | cmd.erase(i, 1); |
---|
| 133 | break; |
---|
| 134 | case wxT('f'): { |
---|
| 135 | wxString f = escape_for_shell(href.substr(0, colon), true); |
---|
| 136 | cmd.replace(i - 1, 2, f); |
---|
| 137 | i += f.size() - 1; |
---|
| 138 | break; |
---|
| 139 | } |
---|
| 140 | case wxT('t'): { |
---|
| 141 | wxString t = escape_for_shell(title); |
---|
| 142 | cmd.replace(i - 1, 2, t); |
---|
| 143 | i += t.size() - 1; |
---|
| 144 | break; |
---|
| 145 | } |
---|
| 146 | case wxT('l'): { |
---|
| 147 | wxString l = escape_for_shell(href.substr(colon + 1, colon2 - colon - 1)); |
---|
| 148 | cmd.replace(i - 1, 2, l); |
---|
| 149 | i += l.size() - 1; |
---|
| 150 | break; |
---|
[1d71195] | 151 | } |
---|
[3d3fb6c] | 152 | case wxT('c'): { |
---|
| 153 | wxString l; |
---|
| 154 | if (colon2 == wxString::npos) |
---|
| 155 | l = wxT("0"); |
---|
| 156 | else |
---|
| 157 | l = escape_for_shell(href.substr(colon2 + 1)); |
---|
| 158 | cmd.replace(i - 1, 2, l); |
---|
| 159 | i += l.size() - 1; |
---|
| 160 | break; |
---|
| 161 | } |
---|
| 162 | default: |
---|
| 163 | ++i; |
---|
[6bec10c] | 164 | } |
---|
[3d3fb6c] | 165 | } |
---|
[fc364dc] | 166 | #ifdef __WXMSW__ |
---|
[3d3fb6c] | 167 | if (_wsystem(cmd.c_str()) >= 0) |
---|
| 168 | return; |
---|
[fc364dc] | 169 | #else |
---|
[3d3fb6c] | 170 | if (system(cmd.mb_str()) >= 0) |
---|
| 171 | return; |
---|
[fc364dc] | 172 | #endif |
---|
[3d3fb6c] | 173 | wxString m; |
---|
[736f7df] | 174 | // TRANSLATORS: %s is replaced by the command we attempted to run. |
---|
[3d3fb6c] | 175 | m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str()); |
---|
| 176 | m += wxT(" ("); |
---|
| 177 | m += wxString(strerror(errno), wxConvUTF8); |
---|
| 178 | m += wxT(')'); |
---|
| 179 | wxGetApp().ReportError(m); |
---|
[6bec10c] | 180 | } |
---|
| 181 | |
---|
[5627cbb] | 182 | int |
---|
[6bec10c] | 183 | CavernLogWindow::process(const wxString &file) |
---|
| 184 | { |
---|
[fb5887c] | 185 | SetFocus(); |
---|
| 186 | filename = file; |
---|
| 187 | |
---|
[6bec10c] | 188 | #ifdef __WXMSW__ |
---|
[15322f2] | 189 | SetEnvironmentVariable(wxT("SURVEX_UTF8"), wxT("1")); |
---|
[6bec10c] | 190 | #else |
---|
[06b1227] | 191 | setenv("SURVEX_UTF8", "1", 1); |
---|
[6bec10c] | 192 | #endif |
---|
[93ff5cc] | 193 | |
---|
[6bec10c] | 194 | wxString escaped_file = escape_for_shell(file, true); |
---|
[a90632c] | 195 | #ifdef __WXMSW__ |
---|
| 196 | wxString cmd; |
---|
[9e50f755] | 197 | { |
---|
[6baad4a] | 198 | DWORD len = 256; |
---|
[6f8cb1c] | 199 | wchar_t *buf = NULL; |
---|
[6baad4a] | 200 | while (1) { |
---|
| 201 | DWORD got; |
---|
| 202 | buf = (wchar_t*)osrealloc(buf, len * 2); |
---|
| 203 | got = GetModuleFileNameW(NULL, buf, len); |
---|
| 204 | if (got < len) break; |
---|
| 205 | len += len; |
---|
| 206 | } |
---|
| 207 | /* Strange Win32 nastiness - strip prefix "\\?\" if present */ |
---|
| 208 | if (wcsncmp(buf, L"\\\\?\\", 4) == 0) buf += 4; |
---|
| 209 | wchar_t * slash = wcsrchr(buf, L'\\'); |
---|
[9e50f755] | 210 | if (slash) { |
---|
[6baad4a] | 211 | cmd.assign(buf, slash - buf + 1); |
---|
[9e50f755] | 212 | } |
---|
[a90632c] | 213 | } |
---|
| 214 | cmd += L"cavern"; |
---|
[9e50f755] | 215 | cmd = escape_for_shell(cmd, false); |
---|
[a90632c] | 216 | #else |
---|
| 217 | char *cavern = use_path(msg_exepth(), "cavern"); |
---|
[2e4b8cd] | 218 | wxString cmd = escape_for_shell(wxString(cavern, wxConvUTF8), false); |
---|
[08b4401] | 219 | osfree(cavern); |
---|
[a90632c] | 220 | #endif |
---|
[5627cbb] | 221 | cmd += wxT(" -o "); |
---|
[6bec10c] | 222 | cmd += escaped_file; |
---|
[5627cbb] | 223 | cmd += wxT(' '); |
---|
[6bec10c] | 224 | cmd += escaped_file; |
---|
| 225 | |
---|
[fc364dc] | 226 | #ifdef __WXMSW__ |
---|
| 227 | FILE * cavern_out = _wpopen(cmd.c_str(), L"r"); |
---|
| 228 | #else |
---|
[ffe7efe4] | 229 | FILE * cavern_out = popen(cmd.mb_str(), "r"); |
---|
[fc364dc] | 230 | #endif |
---|
[6bec10c] | 231 | if (!cavern_out) { |
---|
[5627cbb] | 232 | wxString m; |
---|
[3d3fb6c] | 233 | m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str()); |
---|
[5627cbb] | 234 | m += wxT(" ("); |
---|
[2e4b8cd] | 235 | m += wxString(strerror(errno), wxConvUTF8); |
---|
[5627cbb] | 236 | m += wxT(')'); |
---|
[6bec10c] | 237 | wxGetApp().ReportError(m); |
---|
[5627cbb] | 238 | return -2; |
---|
[6bec10c] | 239 | } |
---|
| 240 | |
---|
| 241 | int cavern_fd; |
---|
| 242 | #ifdef __WXMSW__ |
---|
| 243 | cavern_fd = _fileno(cavern_out); |
---|
| 244 | #else |
---|
| 245 | cavern_fd = fileno(cavern_out); |
---|
| 246 | #endif |
---|
| 247 | assert(cavern_fd < FD_SETSIZE); // FIXME we shouldn't just assert, but what else to do? |
---|
| 248 | wxString cur; |
---|
[5627cbb] | 249 | int link_count = 0; |
---|
[b3ee5f5] | 250 | unsigned char buf[1024]; |
---|
| 251 | unsigned char * end = buf; |
---|
| 252 | while (true) { |
---|
[6bec10c] | 253 | fd_set rfds, efds; |
---|
| 254 | FD_ZERO(&rfds); |
---|
| 255 | FD_SET(cavern_fd, &rfds); |
---|
| 256 | FD_ZERO(&efds); |
---|
| 257 | FD_SET(cavern_fd, &efds); |
---|
[b3ee5f5] | 258 | // Timeout instantly the first time, and call Update() so the window |
---|
| 259 | // contents get updated. If we're still waiting for output after that, |
---|
| 260 | // wait for output for 0.1 seconds, then call wxYield() so that the UI |
---|
| 261 | // doesn't block. |
---|
[6bec10c] | 262 | struct timeval timeout; |
---|
| 263 | timeout.tv_sec = 0; |
---|
[1e2499c] | 264 | timeout.tv_usec = 0; |
---|
[b3ee5f5] | 265 | bool first = true; |
---|
| 266 | while (select(cavern_fd + 1, &rfds, NULL, &efds, &timeout) == 0) { |
---|
| 267 | if (first) { |
---|
| 268 | first = false; |
---|
| 269 | Update(); |
---|
| 270 | } else { |
---|
| 271 | wxYield(); |
---|
| 272 | } |
---|
[1e2499c] | 273 | FD_SET(cavern_fd, &rfds); |
---|
| 274 | FD_SET(cavern_fd, &efds); |
---|
| 275 | // Set timeout to 0.1 seconds. |
---|
| 276 | timeout.tv_sec = 0; |
---|
| 277 | timeout.tv_usec = 100000; |
---|
[6bec10c] | 278 | } |
---|
[6b088f6] | 279 | if (!FD_ISSET(cavern_fd, &rfds)) { |
---|
[6bec10c] | 280 | // Error, which pclose() should report. |
---|
| 281 | break; |
---|
| 282 | } |
---|
[b3ee5f5] | 283 | |
---|
| 284 | ssize_t r = read(cavern_fd, end, sizeof(buf) - (end - buf)); |
---|
| 285 | if (r <= 0) { |
---|
| 286 | if (r == 0 && buf != end) { |
---|
| 287 | // FIXME: Truncated UTF-8 sequence. |
---|
| 288 | } |
---|
| 289 | break; |
---|
[6bec10c] | 290 | } |
---|
[b3ee5f5] | 291 | end += r; |
---|
| 292 | |
---|
| 293 | const unsigned char * p = buf; |
---|
| 294 | |
---|
| 295 | while (p != end) { |
---|
| 296 | int ch = *p++; |
---|
| 297 | if (ch >= 0x80) { |
---|
| 298 | // Decode multi-byte UTF-8 sequence. |
---|
| 299 | if (ch < 0xc0) { |
---|
| 300 | // FIXME: Invalid UTF-8 sequence. |
---|
| 301 | goto abort; |
---|
| 302 | } else if (ch < 0xe0) { |
---|
| 303 | /* 2 byte sequence */ |
---|
| 304 | if (p == end) { |
---|
| 305 | // Incomplete UTF-8 sequence - try to read more. |
---|
| 306 | break; |
---|
| 307 | } |
---|
| 308 | int ch1 = *p++; |
---|
| 309 | if ((ch1 & 0xc0) != 0x80) { |
---|
| 310 | // FIXME: Invalid UTF-8 sequence. |
---|
| 311 | goto abort; |
---|
| 312 | } |
---|
| 313 | ch = ((ch & 0x1f) << 6) | (ch1 & 0x3f); |
---|
| 314 | } else if (ch < 0xf0) { |
---|
| 315 | /* 3 byte sequence */ |
---|
| 316 | if (end - p <= 1) { |
---|
| 317 | // Incomplete UTF-8 sequence - try to read more. |
---|
| 318 | break; |
---|
| 319 | } |
---|
| 320 | int ch1 = *p++; |
---|
| 321 | ch = ((ch & 0x1f) << 12) | ((ch1 & 0x3f) << 6); |
---|
| 322 | if ((ch1 & 0xc0) != 0x80) { |
---|
| 323 | // FIXME: Invalid UTF-8 sequence. |
---|
| 324 | goto abort; |
---|
| 325 | } |
---|
| 326 | int ch2 = *p++; |
---|
| 327 | if ((ch2 & 0xc0) != 0x80) { |
---|
| 328 | // FIXME: Invalid UTF-8 sequence. |
---|
| 329 | goto abort; |
---|
| 330 | } |
---|
| 331 | ch |= (ch2 & 0x3f); |
---|
[6bec10c] | 332 | } else { |
---|
[b3ee5f5] | 333 | // FIXME: Overlong UTF-8 sequence. |
---|
| 334 | goto abort; |
---|
[6bec10c] | 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
[b3ee5f5] | 338 | switch (ch) { |
---|
| 339 | case '\r': |
---|
| 340 | // Ignore. |
---|
| 341 | break; |
---|
| 342 | case '\n': { |
---|
| 343 | if (cur.empty()) continue; |
---|
[a07ee70] | 344 | #ifndef __WXMSW__ |
---|
[b3ee5f5] | 345 | size_t colon = cur.find(':'); |
---|
[a07ee70] | 346 | #else |
---|
[b3ee5f5] | 347 | // If the path is "C:\path\to\file.svx" then don't split at the |
---|
| 348 | // : after the drive letter! FIXME: better to look for ": "? |
---|
| 349 | size_t colon = cur.find(':', 2); |
---|
[6bec10c] | 350 | #endif |
---|
[b3ee5f5] | 351 | if (colon != wxString::npos && colon < cur.size() - 2) { |
---|
| 352 | ++colon; |
---|
| 353 | size_t i = colon; |
---|
| 354 | while (i < cur.size() - 2 && |
---|
| 355 | cur[i] >= wxT('0') && cur[i] <= wxT('9')) { |
---|
| 356 | ++i; |
---|
| 357 | } |
---|
| 358 | if (i > colon && cur[i] == wxT(':') ) { |
---|
[da96015] | 359 | colon = i; |
---|
[b3ee5f5] | 360 | // Check for column number. |
---|
| 361 | while (++i < cur.size() - 2 && |
---|
| 362 | cur[i] >= wxT('0') && cur[i] <= wxT('9')) { } |
---|
| 363 | if (i > colon + 1 && cur[i] == wxT(':') ) { |
---|
| 364 | colon = i; |
---|
| 365 | } |
---|
| 366 | wxString tag = wxT("<a href=\""); |
---|
| 367 | tag.append(cur, 0, colon); |
---|
| 368 | while (cur[++i] == wxT(' ')) { } |
---|
| 369 | tag += wxT("\" target=\""); |
---|
| 370 | tag.append(cur, i, wxString::npos); |
---|
| 371 | tag += wxT("\">"); |
---|
| 372 | cur.insert(0, tag); |
---|
| 373 | cur.insert(colon + tag.size(), wxT("</a>")); |
---|
| 374 | ++link_count; |
---|
[da96015] | 375 | } |
---|
[6bec10c] | 376 | } |
---|
[93ff5cc] | 377 | |
---|
[b3ee5f5] | 378 | // Save the scrollbar positions. |
---|
| 379 | int scroll_x = 0, scroll_y = 0; |
---|
| 380 | GetViewStart(&scroll_x, &scroll_y); |
---|
[93ff5cc] | 381 | |
---|
[b3ee5f5] | 382 | cur += wxT("<br>\n"); |
---|
| 383 | AppendToPage(cur); |
---|
[93ff5cc] | 384 | |
---|
[b3ee5f5] | 385 | if (!link_count) { |
---|
| 386 | // Auto-scroll the window until we've reported a warning or |
---|
| 387 | // error. |
---|
| 388 | int x, y; |
---|
| 389 | GetVirtualSize(&x, &y); |
---|
| 390 | int xs, ys; |
---|
| 391 | GetClientSize(&xs, &ys); |
---|
| 392 | y -= ys; |
---|
| 393 | int xu, yu; |
---|
| 394 | GetScrollPixelsPerUnit(&xu, &yu); |
---|
| 395 | Scroll(scroll_x, y / yu); |
---|
| 396 | } else { |
---|
| 397 | // Restore the scrollbar positions. |
---|
| 398 | Scroll(scroll_x, scroll_y); |
---|
| 399 | } |
---|
[a75f5a1] | 400 | |
---|
[b3ee5f5] | 401 | cur.clear(); |
---|
| 402 | break; |
---|
[6bec10c] | 403 | } |
---|
[b3ee5f5] | 404 | case '<': |
---|
| 405 | cur += wxT("<"); |
---|
| 406 | break; |
---|
| 407 | case '>': |
---|
| 408 | cur += wxT(">"); |
---|
| 409 | break; |
---|
| 410 | case '&': |
---|
| 411 | cur += wxT("&"); |
---|
| 412 | break; |
---|
| 413 | case '"': |
---|
| 414 | cur += wxT(""); |
---|
| 415 | continue; |
---|
| 416 | default: |
---|
| 417 | if (ch >= 128) { |
---|
| 418 | cur += wxString::Format(wxT("&#%u;"), ch); |
---|
| 419 | } else { |
---|
| 420 | cur += (char)ch; |
---|
| 421 | } |
---|
| 422 | } |
---|
[6bec10c] | 423 | } |
---|
[b3ee5f5] | 424 | |
---|
| 425 | size_t left = end - p; |
---|
| 426 | end = buf + left; |
---|
| 427 | if (left) memmove(buf, p, left); |
---|
[6bec10c] | 428 | } |
---|
[b3ee5f5] | 429 | abort: |
---|
[fb5887c] | 430 | |
---|
[93ff5cc] | 431 | int retval = pclose(cavern_out); |
---|
| 432 | if (retval) { |
---|
[736f7df] | 433 | /* TRANSLATORS: Label for button in aven’s cavern log window which |
---|
| 434 | * causes the survey data to be reprocessed. */ |
---|
[2341559] | 435 | AppendToPage(wxString::Format(wxT("<avenbutton default id=1234 name=\"%s\">"), |
---|
| 436 | wmsg(/*Reprocess*/184).c_str())); |
---|
[93ff5cc] | 437 | if (retval == -1) { |
---|
[5627cbb] | 438 | wxString m = wxT("Problem running cavern: "); |
---|
| 439 | m += wxString(strerror(errno), wxConvUTF8); |
---|
[93ff5cc] | 440 | wxGetApp().ReportError(m); |
---|
[5627cbb] | 441 | return -2; |
---|
[93ff5cc] | 442 | } |
---|
[5627cbb] | 443 | return -1; |
---|
[6bec10c] | 444 | } |
---|
[fb5887c] | 445 | if (link_count) { |
---|
[2341559] | 446 | AppendToPage(wxString::Format(wxT("<avenbutton id=1234 name=\"%s\">"), |
---|
| 447 | wmsg(/*Reprocess*/184).c_str())); |
---|
[fb5887c] | 448 | AppendToPage(wxString::Format(wxT("<avenbutton default id=%d>"), (int)wxID_OK)); |
---|
| 449 | Update(); |
---|
| 450 | } |
---|
[5627cbb] | 451 | return link_count; |
---|
[6bec10c] | 452 | } |
---|
[fb5887c] | 453 | |
---|
| 454 | void |
---|
[81e1aa4] | 455 | CavernLogWindow::OnReprocess(wxCommandEvent & e) |
---|
[fb5887c] | 456 | { |
---|
| 457 | SetPage(wxString()); |
---|
| 458 | if (process(filename) == 0) { |
---|
| 459 | OnOK(e); |
---|
| 460 | } |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | void |
---|
| 464 | CavernLogWindow::OnOK(wxCommandEvent &) |
---|
| 465 | { |
---|
| 466 | mainfrm->InitialiseAfterLoad(filename); |
---|
| 467 | } |
---|