1 /* $Id: main.mm,v 1.3 2005/11/25 15:04:35 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
7 #include <Cocoa/Cocoa.h>
14 void SigHandler( int signal )
16 [NSApp terminate: NULL];
19 /****************************************************************************
22 * Change this to display a dialog box - and maybe move it somewhere else,
23 * this is the only place I could find that looked like C :)
24 ****************************************************************************/
26 void hb_error_handler( const char *errmsg )
28 fprintf(stderr, "GUI ERROR dialog: %s\n", errmsg );
32 char * str_printf(const char *fmt, ...)
34 /* Guess we need no more than 100 bytes. */
38 char *tmp, *str = NULL;
40 str = (char*)malloc(size);
43 /* Try to print in the allocated space. */
45 len = vsnprintf(str, size, fmt, ap);
48 /* If that worked, return the string. */
49 if (len > -1 && len < size) {
53 /* Else try again with more space. */
54 if (len > -1) /* glibc 2.1 */
55 size = len+1; /* precisely what is needed */
57 size *= 2; /* twice the old size */
59 tmp = (char*)realloc(str, size);
67 #define EXTRA_VLC_DYLD_PATH "/Applications/VLC.app/Contents/MacOS/lib"
68 #define DEFAULT_DYLD_PATH "/usr/local/lib:/usr/lib"
70 int main( int argc, const char ** argv )
75 // Check for flag that prevents exec bomb. It
76 // incidentally can be used to prevent adding
77 // our modifications to the dyld env vars.
78 if ( argc > 1 && strncmp(argv[1], "-n", 2) == 0 )
83 dylib_path = getenv("DYLD_FALLBACK_LIBRARY_PATH");
84 if ( dylib_path == NULL ||
85 strstr( dylib_path, "/Applications/VLC.app/Contents/MacOS/lib" ) == NULL )
91 home = getenv("HOME");
93 if ( dylib_path == NULL )
95 // Set the system default of $HOME/lib:/usr/local/lib:/usr/lib
96 // And add our extra path
99 path = str_printf("%s/lib:%s:%s:%s%s", home,
102 home, EXTRA_VLC_DYLD_PATH);
106 path = str_printf("%s:%s", DEFAULT_DYLD_PATH, EXTRA_VLC_DYLD_PATH);
109 result = setenv("DYLD_FALLBACK_LIBRARY_PATH", path, 1);
113 // add our extra path
116 path = str_printf("%s:%s:%s%s", dylib_path, EXTRA_VLC_DYLD_PATH,
117 home, EXTRA_VLC_DYLD_PATH);
121 path = str_printf("%s:%s", dylib_path, EXTRA_VLC_DYLD_PATH);
124 result = setenv("DYLD_FALLBACK_LIBRARY_PATH", path, 1);
128 const char ** new_argv;
131 new_argv = (const char**)malloc( (argc + 2) * sizeof(char*) );
132 new_argv[0] = argv[0];
134 for (i = 1; i < argc; i++)
135 new_argv[i+1] = argv[i];
136 new_argv[i+1] = NULL;
137 execv(new_argv[0], (char* const*)new_argv);
141 signal( SIGINT, SigHandler );
142 hb_register_error_handler(&hb_error_handler);
143 return NSApplicationMain( argc, argv );