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