main.cpp 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /* main.cpp
  2. *
  3. * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
  4. *
  5. * This file is part of Slop.
  6. *
  7. * Slop is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Slop is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Slop. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <unistd.h>
  21. #include <time.h>
  22. #include <cstdio>
  23. #include <sstream>
  24. #include <stdexcept>
  25. #ifdef __MACH__
  26. #include <mach/clock.h>
  27. #include <mach/mach.h>
  28. #endif
  29. #include "x.hpp"
  30. #include "selectrectangle.hpp"
  31. #ifdef OPENGL_ENABLED
  32. #include "glselectrectangle.hpp"
  33. #endif //OPENGL_ENABLED
  34. #include "xselectrectangle.hpp"
  35. #include "cmdline.h"
  36. // Work around lack of clock_gettime in OSX
  37. // https://gist.github.com/jbenet/1087739
  38. void current_utc_time(struct timespec *ts) {
  39. #ifdef __MACH__
  40. // OS X does not have clock_gettime, use clock_get_time
  41. clock_serv_t cclock;
  42. mach_timespec_t mts;
  43. host_get_clock_service( mach_host_self(), CALENDAR_CLOCK, &cclock );
  44. clock_get_time( cclock, &mts );
  45. mach_port_deallocate( mach_task_self(), cclock );
  46. ts->tv_sec = mts.tv_sec;
  47. ts->tv_nsec = mts.tv_nsec;
  48. #else
  49. clock_gettime( CLOCK_REALTIME, ts );
  50. #endif
  51. }
  52. int printSelection( std::string format, bool cancelled, int x, int y, int w, int h, int window ) {
  53. size_t pos = 0;
  54. while ( ( pos = format.find( "%", pos ) ) != std::string::npos ) {
  55. if ( pos + 1 > format.size() ) {
  56. fprintf( stderr, "Format error: %% found at the end of format string.\n" );
  57. return EXIT_FAILURE;
  58. }
  59. std::stringstream foo;
  60. switch( format[ pos + 1 ] ) {
  61. case '%':
  62. format.replace( pos, 2, "%" );
  63. pos += 1;
  64. break;
  65. case 'x':
  66. case 'X':
  67. foo << x;
  68. format.replace( pos, 2, foo.str() );
  69. break;
  70. case 'y':
  71. case 'Y':
  72. foo << y;
  73. format.replace( pos, 2, foo.str() );
  74. break;
  75. case 'w':
  76. case 'W':
  77. foo << w;
  78. format.replace( pos, 2, foo.str() );
  79. break;
  80. case 'h':
  81. case 'H':
  82. foo << h;
  83. format.replace( pos, 2, foo.str() );
  84. break;
  85. case 'g':
  86. case 'G':
  87. foo << w << 'x' << h << '+' << x << '+' << y;
  88. format.replace( pos, 2, foo.str() );
  89. break;
  90. case 'i':
  91. case 'I':
  92. foo << window;
  93. format.replace( pos, 2, foo.str() );
  94. break;
  95. case 'c':
  96. case 'C':
  97. format.replace( pos, 2, cancelled ? "true" : "false" );
  98. break;
  99. default:
  100. fprintf( stderr, "Format error: %%%c is an unknown replacement identifier.\n", format[ pos + 1 ] );
  101. fprintf( stderr, "Valid replacements: %%x, %%y, %%w, %%h, %%i, %%c, %%.\n" );
  102. return EXIT_FAILURE;
  103. break;
  104. }
  105. }
  106. pos = 0;
  107. while ( ( pos = format.find( "\\", pos ) ) != std::string::npos ) {
  108. if ( pos + 1 > format.size() ) {
  109. break;
  110. }
  111. if ( format[ pos + 1 ] == 'n' ) {
  112. format.replace( pos, 2, "\n" );
  113. }
  114. pos = pos + 1;
  115. }
  116. printf( "%s", format.c_str() );
  117. return EXIT_SUCCESS;
  118. }
  119. int parseColor( std::string arg, float* r, float* g, float* b, float* a ) {
  120. std::string copy = arg;
  121. int find = copy.find( "," );
  122. while( find != (int)copy.npos ) {
  123. copy.at( find ) = ' ';
  124. find = copy.find( "," );
  125. }
  126. // Just in case we didn't include an alpha value
  127. *a = 1;
  128. int num = sscanf( copy.c_str(), "%f %f %f %f", r, g, b, a );
  129. if ( num != 3 && num != 4 ) {
  130. return EXIT_FAILURE;
  131. }
  132. return EXIT_SUCCESS;
  133. }
  134. void constrain( int sx, int sy, int ex, int ey, int padding, int minimumsize, int maximumsize, int* rsx, int* rsy, int* rex, int* rey ) {
  135. if ( minimumsize > maximumsize && maximumsize > 0 ) {
  136. fprintf( stderr, "Error: minimumsize is greater than maximumsize.\n" );
  137. exit( 1 );
  138. }
  139. int x = std::min( sx, ex );
  140. int y = std::min( sy, ey );
  141. // We add one to make sure we select the pixel under the mouse.
  142. int w = std::max( sx, ex ) - x + 1;
  143. int h = std::max( sy, ey ) - y + 1;
  144. // Make sure we don't turn inside out...
  145. if ( w + padding*2 >= 0 ) {
  146. x -= padding;
  147. w += padding*2;
  148. }
  149. if ( h + padding*2 >= 0 ) {
  150. y -= padding;
  151. h += padding*2;
  152. }
  153. if ( w < minimumsize ) {
  154. int diff = minimumsize - w;
  155. w = minimumsize;
  156. x -= diff/2;
  157. }
  158. if ( h < minimumsize ) {
  159. int diff = minimumsize - h;
  160. h = minimumsize;
  161. y -= diff/2;
  162. }
  163. if ( maximumsize > 0 ) {
  164. if ( w > maximumsize ) {
  165. int diff = w;
  166. w = maximumsize;
  167. x += diff/2 - maximumsize/2;
  168. }
  169. if ( h > maximumsize ) {
  170. int diff = h;
  171. h = maximumsize;
  172. y += diff/2 - maximumsize/2;
  173. }
  174. }
  175. // Center around mouse if we have a fixed size.
  176. if ( maximumsize == minimumsize && w == maximumsize && h == maximumsize ) {
  177. x = ex - maximumsize/2;
  178. y = ey - maximumsize/2;
  179. }
  180. *rsx = x;
  181. *rsy = y;
  182. *rex = x + w;
  183. *rey = y + h;
  184. }
  185. // Some complicated key detection to replicate key repeating
  186. bool keyRepeat( KeySym key, double curtime, double repeatdelay, double* time, bool* memory ) {
  187. if ( xengine->keyPressed( key ) != *memory ) {
  188. if ( xengine->keyPressed( key ) ) {
  189. *memory = true;
  190. *time = curtime;
  191. return true;
  192. } else {
  193. *memory = false;
  194. }
  195. }
  196. if ( xengine->keyPressed( key ) && curtime - *time > repeatdelay ) {
  197. return true;
  198. }
  199. return false;
  200. }
  201. int app( int argc, char** argv ) {
  202. gengetopt_args_info options;
  203. int err = cmdline_parser( argc, argv, &options );
  204. if ( err != EXIT_SUCCESS ) {
  205. return EXIT_FAILURE;
  206. }
  207. int state = 0;
  208. bool running = true;
  209. bool opengl = options.opengl_flag;
  210. slop::SelectRectangle* selection = NULL;
  211. Window window = None;
  212. Window windowmemory = None;
  213. std::string xdisplay;
  214. if ( options.xdisplay_given ) {
  215. xdisplay = options.xdisplay_arg;
  216. } else {
  217. // If we weren't specifically given a xdisplay, we try
  218. // to parse it from environment variables
  219. char* display = getenv( "DISPLAY" );
  220. if ( display ) {
  221. xdisplay = display;
  222. } else {
  223. fprintf( stderr, "Warning: Failed to parse environment variable: DISPLAY. Using \":0\" instead.\n" );
  224. xdisplay = ":0";
  225. }
  226. }
  227. int padding = options.padding_arg;
  228. int borderSize = options.bordersize_arg;
  229. int tolerance = options.tolerance_arg;
  230. float r, g, b, a;
  231. err = parseColor( options.color_arg, &r, &g, &b, &a );
  232. if ( err != EXIT_SUCCESS ) {
  233. fprintf( stderr, "Error parsing color %s\n", options.color_arg );
  234. return EXIT_FAILURE;
  235. }
  236. float gracetime;
  237. err = sscanf( options.gracetime_arg, "%f", &gracetime );
  238. if ( err != 1 ) {
  239. fprintf( stderr, "Error parsing %s as a float for gracetime!\n", options.gracetime_arg );
  240. return EXIT_FAILURE;
  241. }
  242. bool highlight = options.highlight_flag;
  243. bool keyboard = !options.nokeyboard_flag;
  244. bool decorations = !options.nodecorations_flag;
  245. bool themeon = (bool)options.theme_given;
  246. std::string theme = options.theme_arg;
  247. #ifdef OPENGL_ENABLED
  248. bool shadergiven = (bool)options.shader_given;
  249. #endif
  250. std::string shader = options.shader_arg;
  251. struct timespec start, time;
  252. int xoffset = 0;
  253. int yoffset = 0;
  254. int cx = 0;
  255. int cy = 0;
  256. int xmem = 0;
  257. int ymem = 0;
  258. int wmem = 0;
  259. int hmem = 0;
  260. int minimumsize = options.min_arg;
  261. int maximumsize = options.max_arg;
  262. bool pressedMemory[4];
  263. double pressedTime[4];
  264. for ( int i=0;i<4;i++ ) {
  265. pressedMemory[ i ] = false;
  266. pressedTime[ i ] = 0;
  267. }
  268. std::string format = options.format_arg;
  269. bool magenabled = options.magnify_flag;
  270. #ifdef OPENGL_ENABLED
  271. float magstrength = options.magstrength_arg;
  272. if ( options.magpixels_arg < 0 ) {
  273. fprintf( stderr, "Error: --magpixels < 0, it's an unsigned integer you twat. Stop trying to underflow me!\n" );
  274. return EXIT_FAILURE;
  275. }
  276. unsigned int magpixels = (unsigned int)options.magpixels_arg;
  277. #endif
  278. cmdline_parser_free( &options );
  279. #ifndef OPENGL_ENABLED
  280. if ( opengl || themeon || magenabled ) {
  281. throw std::runtime_error( "Slop wasn't compiled with OpenGL support, so themes, magnifications, and shaders are disabled! Try compiling it with the CMAKE_OPENGL_SUPPORT set to true." );
  282. }
  283. #else // OPENGL_ENABLED
  284. if ( ( themeon || magenabled || shadergiven ) && !opengl ) {
  285. throw std::runtime_error( "Slop needs --opengl enabled to use themes, shaders, or magnifications." );
  286. }
  287. #endif
  288. // First we set up the x interface and grab the mouse,
  289. // if we fail for either we exit immediately.
  290. err = xengine->init( xdisplay.c_str() );
  291. if ( err != EXIT_SUCCESS ) {
  292. printSelection( format, true, 0, 0, 0, 0, None );
  293. return EXIT_FAILURE;
  294. }
  295. if ( !slop::isSelectRectangleSupported() ) {
  296. fprintf( stderr, "Error: Your X server doesn't support the XShape extension. There's nothing slop can do about this!\n" );
  297. fprintf( stderr, " Try updating X and making sure you have XExtensions installed. (/usr/lib/libXext.so, /usr/include/X11/extensions/shape.h)\n" );
  298. return EXIT_FAILURE;
  299. }
  300. err = xengine->grabCursor( slop::Cross, gracetime );
  301. if ( err != EXIT_SUCCESS ) {
  302. printSelection( format, true, 0, 0, 0, 0, None );
  303. return EXIT_FAILURE;
  304. }
  305. if ( keyboard ) {
  306. err = xengine->grabKeyboard();
  307. if ( err ) {
  308. fprintf( stderr, "Warning: Failed to grab the keyboard. This is non-fatal, keyboard presses might fall through to other applications.\n" );
  309. }
  310. }
  311. current_utc_time( &start );
  312. double deltatime = 0;
  313. double curtime = double( start.tv_sec*1000000000L + start.tv_nsec )/1000000000.f;
  314. while ( running ) {
  315. current_utc_time( &time );
  316. // "ticking" the xengine makes it process all queued events.
  317. xengine->tick();
  318. // If the user presses any key on the keyboard, exit the application.
  319. // Make sure at least gracetime has passed before allowing canceling
  320. double newtime = double( time.tv_sec*1000000000L + time.tv_nsec )/1000000000.f;
  321. deltatime = newtime-curtime;
  322. curtime = newtime;
  323. double starttime = double( start.tv_sec*1000000000L + start.tv_nsec )/1000000000.f;
  324. if ( curtime - starttime > gracetime ) {
  325. if ( keyRepeat( XK_Up, curtime, 0.5, &pressedTime[ 0 ], &pressedMemory[ 0 ] ) ) {
  326. yoffset -= 1;
  327. }
  328. if ( keyRepeat( XK_Down, curtime, 0.5, &pressedTime[ 1 ], &pressedMemory[ 1 ] ) ) {
  329. yoffset += 1;
  330. }
  331. if ( keyRepeat( XK_Left, curtime, 0.5, &pressedTime[ 2 ], &pressedMemory[ 2 ] ) ) {
  332. xoffset -= 1;
  333. }
  334. if ( keyRepeat( XK_Right, curtime, 0.5, &pressedTime[ 3 ], &pressedMemory[ 3 ] ) ) {
  335. xoffset += 1;
  336. }
  337. // If we pressed enter we move the state onward.
  338. if ( xengine->keyPressed( XK_Return ) ) {
  339. // If we're highlight windows, just select the active window.
  340. if ( state == 0 ) {
  341. state = 1;
  342. // If we're making a custom selection, select the custom selection.
  343. } else if ( state == 2 ) {
  344. state = 3;
  345. }
  346. }
  347. // If we press any key other than the arrow keys or enter key, we shut down!
  348. if ( !( xengine->keyPressed( XK_Up ) || xengine->keyPressed( XK_Down ) || xengine->keyPressed( XK_Left ) || xengine->keyPressed( XK_Right ) ) &&
  349. !( xengine->keyPressed( XK_Return ) ) &&
  350. ( ( xengine->anyKeyPressed() && keyboard ) || xengine->mouseDown( 3 ) ) ) {
  351. printSelection( format, true, 0, 0, 0, 0, None );
  352. fprintf( stderr, "User pressed key. Canceled selection.\n" );
  353. state = -1;
  354. running = false;
  355. }
  356. }
  357. // Our adorable little state manager will handle what state we're in.
  358. switch ( state ) {
  359. default: {
  360. break;
  361. }
  362. case 0: {
  363. // If xengine has found a window we're hovering over (or if it changed)
  364. // create a rectangle around it so the user knows he/she can click on it.
  365. // --but only if the user wants us to
  366. if ( window != xengine->m_hoverWindow && tolerance > 0 ) {
  367. slop::WindowRectangle t;
  368. t.setGeometry( xengine->m_hoverWindow, decorations );
  369. t.applyPadding( padding );
  370. t.applyMinMaxSize( minimumsize, maximumsize );
  371. // Make sure we only apply offsets to windows that we've forcibly removed decorations on.
  372. if ( !selection ) {
  373. #ifdef OPENGL_ENABLED
  374. if ( opengl ) {
  375. selection = new slop::GLSelectRectangle( t.m_x, t.m_y,
  376. t.m_x + t.m_width,
  377. t.m_y + t.m_height,
  378. borderSize,
  379. highlight,
  380. r, g, b, a );
  381. // Haha why is this so hard to cast?
  382. ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
  383. ((slop::GLSelectRectangle*)(selection))->setTheme( themeon, theme );
  384. ((slop::GLSelectRectangle*)(selection))->setShader( shader );
  385. } else {
  386. #endif // OPENGL_ENABLED
  387. selection = new slop::XSelectRectangle( t.m_x, t.m_y,
  388. t.m_x + t.m_width,
  389. t.m_y + t.m_height,
  390. borderSize,
  391. highlight,
  392. r, g, b, a );
  393. #ifdef OPENGL_ENABLED
  394. }
  395. #endif // OPENGL_ENABLED
  396. } else {
  397. selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
  398. }
  399. //window = xengine->m_hoverWindow;
  400. // Since WindowRectangle can select different windows depending on click location...
  401. window = t.getWindow();
  402. }
  403. if ( selection ) {
  404. selection->update( deltatime );
  405. }
  406. // If the user clicked we move on to the next state.
  407. if ( xengine->mouseDown( 1 ) ) {
  408. state++;
  409. }
  410. break;
  411. }
  412. case 1: {
  413. // Set the mouse position of where we clicked, used so that click tolerance doesn't affect the rectangle's position.
  414. cx = xengine->m_mousex;
  415. cy = xengine->m_mousey;
  416. // Make sure we don't have un-seen applied offsets.
  417. xoffset = 0;
  418. yoffset = 0;
  419. // Also remember where the original selection was
  420. if ( selection ) {
  421. xmem = selection->m_x;
  422. ymem = selection->m_y;
  423. wmem = selection->m_width;
  424. hmem = selection->m_height;
  425. } else {
  426. xmem = cx;
  427. ymem = cy;
  428. }
  429. state++;
  430. break;
  431. }
  432. case 2: {
  433. // It's possible that our selection doesn't exist still, lets make sure it actually gets created here.
  434. if ( !selection ) {
  435. int sx, sy, ex, ey;
  436. constrain( cx, cy, xengine->m_mousex, xengine->m_mousey, padding, minimumsize, maximumsize, &sx, &sy, &ex, &ey );
  437. #ifdef OPENGL_ENABLED
  438. if ( opengl ) {
  439. selection = new slop::GLSelectRectangle( sx, sy,
  440. ex, ey,
  441. borderSize,
  442. highlight,
  443. r, g, b, a );
  444. // Haha why is this so hard to cast?
  445. ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
  446. ((slop::GLSelectRectangle*)(selection))->setTheme( themeon, theme );
  447. ((slop::GLSelectRectangle*)(selection))->setShader( shader );
  448. } else {
  449. #endif // OPENGL_ENABLED
  450. selection = new slop::XSelectRectangle( sx, sy,
  451. ex, ey,
  452. borderSize,
  453. highlight,
  454. r, g, b, a );
  455. #ifdef OPENGL_ENABLED
  456. }
  457. #endif // OPENGL_ENABLED
  458. }
  459. windowmemory = window;
  460. // If the user has let go of the mouse button, we'll just
  461. // continue to the next state.
  462. if ( !xengine->mouseDown( 1 ) ) {
  463. state++;
  464. break;
  465. }
  466. // Check to make sure the user actually wants to drag for a selection before moving things around.
  467. int w = xengine->m_mousex - cx;
  468. int h = xengine->m_mousey - cy;
  469. if ( ( std::abs( w ) < tolerance && std::abs( h ) < tolerance ) ) {
  470. // We make sure the selection rectangle stays on the window we had selected
  471. selection->setGeo( xmem, ymem, xmem + wmem, ymem + hmem );
  472. selection->update( deltatime );
  473. xengine->setCursor( slop::Left );
  474. // Make sure
  475. window = windowmemory;
  476. continue;
  477. }
  478. // If we're not selecting a window.
  479. windowmemory = window;
  480. window = None;
  481. // We also detect which way the user is pulling and set the mouse icon accordingly.
  482. bool x = cx > xengine->m_mousex;
  483. bool y = cy > xengine->m_mousey;
  484. if ( ( selection->m_width <= 1 && selection->m_height <= 1 ) || ( minimumsize == maximumsize && minimumsize != 0 && maximumsize != 0 ) ) {
  485. xengine->setCursor( slop::Cross );
  486. } else if ( !x && !y ) {
  487. xengine->setCursor( slop::LowerRightCorner );
  488. } else if ( x && !y ) {
  489. xengine->setCursor( slop::LowerLeftCorner );
  490. } else if ( !x && y ) {
  491. xengine->setCursor( slop::UpperRightCorner );
  492. } else if ( x && y ) {
  493. xengine->setCursor( slop::UpperLeftCorner );
  494. }
  495. // Apply padding and minimum size adjustments.
  496. int sx, sy, ex, ey;
  497. constrain( cx, cy, xengine->m_mousex, xengine->m_mousey, padding, minimumsize, maximumsize, &sx, &sy, &ex, &ey );
  498. // Set the selection rectangle's dimensions to mouse movement.
  499. selection->setGeo( sx + xoffset, sy + yoffset, ex, ey );
  500. selection->update( deltatime );
  501. break;
  502. }
  503. case 3: {
  504. int x, y, w, h;
  505. // Exit the utility after this state runs once.
  506. running = false;
  507. // We pull the dimensions and positions from the selection rectangle.
  508. // The selection rectangle automatically converts the positions and
  509. // dimensions to absolute coordinates when we set them earilier.
  510. x = selection->m_x;
  511. y = selection->m_y;
  512. w = selection->m_width;
  513. h = selection->m_height;
  514. // Delete the rectangle, which will remove it from the screen.
  515. delete selection;
  516. // Make sure if no window was specifically specified, that we output the root window.
  517. Window temp = window;
  518. if ( temp == None ) {
  519. temp = xengine->m_root;
  520. }
  521. // Print the selection :)
  522. printSelection( format, false, x, y, w, h, temp );
  523. break;
  524. }
  525. }
  526. // This sleep is required because drawing the rectangles is a very expensive task that acts really weird with Xorg when called as fast as possible.
  527. // 0.01 seconds
  528. usleep( 10000 );
  529. }
  530. xengine->releaseCursor();
  531. xengine->releaseKeyboard();
  532. // Try to process any last-second requests.
  533. //xengine->tick();
  534. // Clean up global classes.
  535. delete xengine;
  536. // Sleep for 0.05 seconds to ensure everything was cleaned up. (Without this, slop's window often shows up in screenshots.)
  537. usleep( 50000 );
  538. // If we canceled the selection, return error.
  539. if ( state == -1 ) {
  540. return EXIT_FAILURE;
  541. }
  542. return EXIT_SUCCESS;
  543. }
  544. int main( int argc, char** argv ) {
  545. try {
  546. return app( argc, argv );
  547. } catch( std::bad_alloc const& exception ) {
  548. fprintf( stderr, "Couldn't allocate enough memory! No space left in RAM." );
  549. } catch( std::exception const& exception ) {
  550. fprintf( stderr, "Unhandled Exception Thrown: %s\n", exception.what() );
  551. } catch( std::string err ) {
  552. fprintf( stderr, "Unhandled Exception Thrown: %s\n", err.c_str() );
  553. } catch( char* err ) {
  554. fprintf( stderr, "Unhandled Exception Thrown: %s\n", err );
  555. } catch( ... ) {
  556. fprintf( stderr, "Unknown Exception Thrown!\n" );
  557. }
  558. return EXIT_FAILURE;
  559. }