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 );
37 char * str_printf(const char *fmt, ...)
39 /* Guess we need no more than 100 bytes. */
43 char *tmp, *str = NULL;
45 str = (char*)malloc(size);
48 /* Try to print in the allocated space. */
50 len = vsnprintf(str, size, fmt, ap);
53 /* If that worked, return the string. */
54 if (len > -1 && len < size) {
58 /* Else try again with more space. */
59 if (len > -1) /* glibc 2.1 */
60 size = len+1; /* precisely what is needed */
62 size *= 2; /* twice the old size */
64 tmp = (char*)realloc(str, size);
72 #define EXTRA_VLC_DYLD_PATH "/Applications/VLC.app/Contents/MacOS/lib"
73 #define DEFAULT_DYLD_PATH "/usr/local/lib:/usr/lib"
75 int main( int argc, const char ** argv )
80 // Check for flag that prevents exec bomb. It
81 // incidentally can be used to prevent adding
82 // our modifications to the dyld env vars.
83 if ( argc > 1 && strncmp(argv[1], "-n", 2) == 0 )
88 dylib_path = getenv("DYLD_FALLBACK_LIBRARY_PATH");
89 if ( dylib_path == NULL ||
90 strstr( dylib_path, "/Applications/VLC.app/Contents/MacOS/lib" ) == NULL )
96 home = getenv("HOME");
98 if ( dylib_path == NULL )
100 // Set the system default of $HOME/lib:/usr/local/lib:/usr/lib
101 // And add our extra path
104 path = str_printf("%s/lib:%s:%s:%s%s", home,
107 home, EXTRA_VLC_DYLD_PATH);
111 path = str_printf("%s:%s", DEFAULT_DYLD_PATH, EXTRA_VLC_DYLD_PATH);
114 result = setenv("DYLD_FALLBACK_LIBRARY_PATH", path, 1);
118 // add our extra path
121 path = str_printf("%s:%s:%s%s", dylib_path, EXTRA_VLC_DYLD_PATH,
122 home, EXTRA_VLC_DYLD_PATH);
126 path = str_printf("%s:%s", dylib_path, EXTRA_VLC_DYLD_PATH);
129 result = setenv("DYLD_FALLBACK_LIBRARY_PATH", path, 1);
133 const char ** new_argv;
136 new_argv = (const char**)malloc( (argc + 2) * sizeof(char*) );
137 new_argv[0] = argv[0];
139 for (i = 1; i < argc; i++)
140 new_argv[i+1] = argv[i];
141 new_argv[i+1] = NULL;
142 execv(new_argv[0], (char* const*)new_argv);
146 mm_flags = mm_support();
147 signal( SIGINT, SigHandler );
148 hb_register_error_handler(&hb_error_handler);
149 return NSApplicationMain( argc, argv );