main.cpp 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. bool shadergiven = (bool)options.shader_given;
  248. std::string shader = options.shader_arg;
  249. struct timespec start, time;
  250. int xoffset = 0;
  251. int yoffset = 0;
  252. int cx = 0;
  253. int cy = 0;
  254. int xmem = 0;
  255. int ymem = 0;
  256. int wmem = 0;
  257. int hmem = 0;
  258. int minimumsize = options.min_arg;
  259. int maximumsize = options.max_arg;
  260. bool pressedMemory[4];
  261. double pressedTime[4];
  262. for ( int i=0;i<4;i++ ) {
  263. pressedMemory[ i ] = false;
  264. pressedTime[ i ] = 0;
  265. }
  266. std::string format = options.format_arg;
  267. bool magenabled = options.magnify_flag;
  268. float magstrength = options.magstrength_arg;
  269. if ( options.magpixels_arg < 0 ) {
  270. fprintf( stderr, "Error: --magpixels < 0, it's an unsigned integer you twat. Stop trying to underflow me!\n" );
  271. return EXIT_FAILURE;
  272. }
  273. unsigned int magpixels = (unsigned int)options.magpixels_arg;
  274. cmdline_parser_free( &options );
  275. #ifndef OPENGL_ENABLED
  276. if ( opengl || themeon || magenabled ) {
  277. 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_ENABLED set to true." );
  278. }
  279. #else // OPENGL_ENABLED
  280. if ( ( themeon || magenabled || shadergiven ) && !opengl ) {
  281. throw std::runtime_error( "Slop needs --opengl enabled to use themes, shaders, or magnifications." );
  282. }
  283. #endif
  284. // First we set up the x interface and grab the mouse,
  285. // if we fail for either we exit immediately.
  286. err = xengine->init( xdisplay.c_str() );
  287. if ( err != EXIT_SUCCESS ) {
  288. printSelection( format, true, 0, 0, 0, 0, None );
  289. return EXIT_FAILURE;
  290. }
  291. if ( !slop::isSelectRectangleSupported() ) {
  292. fprintf( stderr, "Error: Your X server doesn't support the XShape extension. There's nothing slop can do about this!\n" );
  293. fprintf( stderr, " Try updating X and making sure you have XExtensions installed. (/usr/lib/libXext.so, /usr/include/X11/extensions/shape.h)\n" );
  294. return EXIT_FAILURE;
  295. }
  296. err = xengine->grabCursor( slop::Cross, gracetime );
  297. if ( err != EXIT_SUCCESS ) {
  298. printSelection( format, true, 0, 0, 0, 0, None );
  299. return EXIT_FAILURE;
  300. }
  301. if ( keyboard ) {
  302. err = xengine->grabKeyboard();
  303. if ( err ) {
  304. fprintf( stderr, "Warning: Failed to grab the keyboard. This is non-fatal, keyboard presses might fall through to other applications.\n" );
  305. }
  306. }
  307. current_utc_time( &start );
  308. double deltatime = 0;
  309. double curtime = double( start.tv_sec*1000000000L + start.tv_nsec )/1000000000.f;
  310. while ( running ) {
  311. current_utc_time( &time );
  312. // "ticking" the xengine makes it process all queued events.
  313. xengine->tick();
  314. // If the user presses any key on the keyboard, exit the application.
  315. // Make sure at least gracetime has passed before allowing canceling
  316. double newtime = double( time.tv_sec*1000000000L + time.tv_nsec )/1000000000.f;
  317. deltatime = newtime-curtime;
  318. curtime = newtime;
  319. double starttime = double( start.tv_sec*1000000000L + start.tv_nsec )/1000000000.f;
  320. if ( curtime - starttime > gracetime ) {
  321. if ( keyRepeat( XK_Up, curtime, 0.5, &pressedTime[ 0 ], &pressedMemory[ 0 ] ) ) {
  322. yoffset -= 1;
  323. }
  324. if ( keyRepeat( XK_Down, curtime, 0.5, &pressedTime[ 1 ], &pressedMemory[ 1 ] ) ) {
  325. yoffset += 1;
  326. }
  327. if ( keyRepeat( XK_Left, curtime, 0.5, &pressedTime[ 2 ], &pressedMemory[ 2 ] ) ) {
  328. xoffset -= 1;
  329. }
  330. if ( keyRepeat( XK_Right, curtime, 0.5, &pressedTime[ 3 ], &pressedMemory[ 3 ] ) ) {
  331. xoffset += 1;
  332. }
  333. // If we pressed enter we move the state onward.
  334. if ( xengine->keyPressed( XK_Return ) ) {
  335. // If we're highlight windows, just select the active window.
  336. if ( state == 0 ) {
  337. state = 1;
  338. // If we're making a custom selection, select the custom selection.
  339. } else if ( state == 2 ) {
  340. state = 3;
  341. }
  342. }
  343. // If we press any key other than the arrow keys or enter key, we shut down!
  344. if ( !( xengine->keyPressed( XK_Up ) || xengine->keyPressed( XK_Down ) || xengine->keyPressed( XK_Left ) || xengine->keyPressed( XK_Right ) ) &&
  345. !( xengine->keyPressed( XK_Return ) ) &&
  346. ( ( xengine->anyKeyPressed() && keyboard ) || xengine->mouseDown( 3 ) ) ) {
  347. printSelection( format, true, 0, 0, 0, 0, None );
  348. fprintf( stderr, "User pressed key. Canceled selection.\n" );
  349. state = -1;
  350. running = false;
  351. }
  352. }
  353. // Our adorable little state manager will handle what state we're in.
  354. switch ( state ) {
  355. default: {
  356. break;
  357. }
  358. case 0: {
  359. // If xengine has found a window we're hovering over (or if it changed)
  360. // create a rectangle around it so the user knows he/she can click on it.
  361. // --but only if the user wants us to
  362. if ( window != xengine->m_hoverWindow && tolerance > 0 ) {
  363. slop::WindowRectangle t;
  364. t.setGeometry( xengine->m_hoverWindow, decorations );
  365. t.applyPadding( padding );
  366. t.applyMinMaxSize( minimumsize, maximumsize );
  367. // Make sure we only apply offsets to windows that we've forcibly removed decorations on.
  368. if ( !selection ) {
  369. #ifdef OPENGL_ENABLED
  370. if ( opengl ) {
  371. selection = new slop::GLSelectRectangle( t.m_x, t.m_y,
  372. t.m_x + t.m_width,
  373. t.m_y + t.m_height,
  374. borderSize,
  375. highlight,
  376. r, g, b, a );
  377. // Haha why is this so hard to cast?
  378. ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
  379. ((slop::GLSelectRectangle*)(selection))->setTheme( themeon, theme );
  380. ((slop::GLSelectRectangle*)(selection))->setShader( shader );
  381. } else {
  382. #endif // OPENGL_ENABLED
  383. selection = new slop::XSelectRectangle( t.m_x, t.m_y,
  384. t.m_x + t.m_width,
  385. t.m_y + t.m_height,
  386. borderSize,
  387. highlight,
  388. r, g, b, a );
  389. #ifdef OPENGL_ENABLED
  390. }
  391. #endif // OPENGL_ENABLED
  392. } else {
  393. selection->setGeo( t.m_x, t.m_y, t.m_x + t.m_width, t.m_y + t.m_height );
  394. }
  395. //window = xengine->m_hoverWindow;
  396. // Since WindowRectangle can select different windows depending on click location...
  397. window = t.getWindow();
  398. }
  399. if ( selection ) {
  400. selection->update( deltatime );
  401. }
  402. // If the user clicked we move on to the next state.
  403. if ( xengine->mouseDown( 1 ) ) {
  404. state++;
  405. }
  406. break;
  407. }
  408. case 1: {
  409. // Set the mouse position of where we clicked, used so that click tolerance doesn't affect the rectangle's position.
  410. cx = xengine->m_mousex;
  411. cy = xengine->m_mousey;
  412. // Make sure we don't have un-seen applied offsets.
  413. xoffset = 0;
  414. yoffset = 0;
  415. // Also remember where the original selection was
  416. if ( selection ) {
  417. xmem = selection->m_x;
  418. ymem = selection->m_y;
  419. wmem = selection->m_width;
  420. hmem = selection->m_height;
  421. } else {
  422. xmem = cx;
  423. ymem = cy;
  424. }
  425. state++;
  426. break;
  427. }
  428. case 2: {
  429. // It's possible that our selection doesn't exist still, lets make sure it actually gets created here.
  430. if ( !selection ) {
  431. int sx, sy, ex, ey;
  432. constrain( cx, cy, xengine->m_mousex, xengine->m_mousey, padding, minimumsize, maximumsize, &sx, &sy, &ex, &ey );
  433. #ifdef OPENGL_ENABLED
  434. if ( opengl ) {
  435. selection = new slop::GLSelectRectangle( sx, sy,
  436. ex, ey,
  437. borderSize,
  438. highlight,
  439. r, g, b, a );
  440. // Haha why is this so hard to cast?
  441. ((slop::GLSelectRectangle*)(selection))->setMagnifySettings( magenabled, magstrength, magpixels );
  442. ((slop::GLSelectRectangle*)(selection))->setTheme( themeon, theme );
  443. ((slop::GLSelectRectangle*)(selection))->setShader( shader );
  444. } else {
  445. #endif // OPENGL_ENABLED
  446. selection = new slop::XSelectRectangle( sx, sy,
  447. ex, ey,
  448. borderSize,
  449. highlight,
  450. r, g, b, a );
  451. #ifdef OPENGL_ENABLED
  452. }
  453. #endif // OPENGL_ENABLED
  454. }
  455. windowmemory = window;
  456. // If the user has let go of the mouse button, we'll just
  457. // continue to the next state.
  458. if ( !xengine->mouseDown( 1 ) ) {
  459. state++;
  460. break;
  461. }
  462. // Check to make sure the user actually wants to drag for a selection before moving things around.
  463. int w = xengine->m_mousex - cx;
  464. int h = xengine->m_mousey - cy;
  465. if ( ( std::abs( w ) < tolerance && std::abs( h ) < tolerance ) ) {
  466. // We make sure the selection rectangle stays on the window we had selected
  467. selection->setGeo( xmem, ymem, xmem + wmem, ymem + hmem );
  468. selection->update( deltatime );
  469. xengine->setCursor( slop::Left );
  470. // Make sure
  471. window = windowmemory;
  472. continue;
  473. }
  474. // If we're not selecting a window.
  475. windowmemory = window;
  476. window = None;
  477. // We also detect which way the user is pulling and set the mouse icon accordingly.
  478. bool x = cx > xengine->m_mousex;
  479. bool y = cy > xengine->m_mousey;
  480. if ( ( selection->m_width <= 1 && selection->m_height <= 1 ) || ( minimumsize == maximumsize && minimumsize != 0 && maximumsize != 0 ) ) {
  481. xengine->setCursor( slop::Cross );
  482. } else if ( !x && !y ) {
  483. xengine->setCursor( slop::LowerRightCorner );
  484. } else if ( x && !y ) {
  485. xengine->setCursor( slop::LowerLeftCorner );
  486. } else if ( !x && y ) {
  487. xengine->setCursor( slop::UpperRightCorner );
  488. } else if ( x && y ) {
  489. xengine->setCursor( slop::UpperLeftCorner );
  490. }
  491. // Apply padding and minimum size adjustments.
  492. int sx, sy, ex, ey;
  493. constrain( cx, cy, xengine->m_mousex, xengine->m_mousey, padding, minimumsize, maximumsize, &sx, &sy, &ex, &ey );
  494. // Set the selection rectangle's dimensions to mouse movement.
  495. selection->setGeo( sx + xoffset, sy + yoffset, ex-1, ey-1 );
  496. selection->update( deltatime );
  497. break;
  498. }
  499. case 3: {
  500. int x, y, w, h;
  501. // Exit the utility after this state runs once.
  502. running = false;
  503. // We pull the dimensions and positions from the selection rectangle.
  504. // The selection rectangle automatically converts the positions and
  505. // dimensions to absolute coordinates when we set them earilier.
  506. x = selection->m_x;
  507. y = selection->m_y;
  508. w = selection->m_width;
  509. h = selection->m_height;
  510. // Delete the rectangle, which will remove it from the screen.
  511. delete selection;
  512. // Make sure if no window was specifically specified, that we output the root window.
  513. Window temp = window;
  514. if ( temp == None ) {
  515. temp = xengine->m_root;
  516. }
  517. // Print the selection :)
  518. printSelection( format, false, x, y, w, h, temp );
  519. break;
  520. }
  521. }
  522. // 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.
  523. // 0.01 seconds
  524. usleep( 10000 );
  525. }
  526. xengine->releaseCursor();
  527. xengine->releaseKeyboard();
  528. // Try to process any last-second requests.
  529. //xengine->tick();
  530. // Clean up global classes.
  531. delete xengine;
  532. // Sleep for 0.05 seconds to ensure everything was cleaned up. (Without this, slop's window often shows up in screenshots.)
  533. usleep( 50000 );
  534. // If we canceled the selection, return error.
  535. if ( state == -1 ) {
  536. return EXIT_FAILURE;
  537. }
  538. return EXIT_SUCCESS;
  539. }
  540. int main( int argc, char** argv ) {
  541. try {
  542. return app( argc, argv );
  543. } catch( std::bad_alloc const& exception ) {
  544. fprintf( stderr, "Couldn't allocate enough memory! No space left in RAM." );
  545. } catch( std::exception const& exception ) {
  546. fprintf( stderr, "Unhandled Exception Thrown: %s\n", exception.what() );
  547. } catch( std::string err ) {
  548. fprintf( stderr, "Unhandled Exception Thrown: %s\n", err.c_str() );
  549. } catch( char* err ) {
  550. fprintf( stderr, "Unhandled Exception Thrown: %s\n", err );
  551. } catch( ... ) {
  552. fprintf( stderr, "Unknown Exception Thrown!\n" );
  553. }
  554. return EXIT_FAILURE;
  555. }