36
/* Show all paint actions with flashing stuff.
36
40
/* Stop startup creation of externs for all VIPS functions etc.
37
41
#define DEBUG_NOAUTO
40
/* stop on any gtk error/warning/whatever
44
/* Stop on any gtk error/warning/whatever. Usually set by configure for dev
41
46
#define DEBUG_FATAL
49
/* But some themes can trigger warnings, argh, so sometimes we need to
50
* undef it. VipsObject sets can also trigger warnings.
93
103
static gboolean main_option_print_main = FALSE;
94
104
static gboolean main_option_version = FALSE;
95
105
static gboolean main_option_verbose = FALSE;
106
static gboolean main_option_test = FALSE;
107
static char *main_option_prefix = NULL;
97
109
static GOptionEntry main_option[] = {
98
110
{ "expression", 'e', 0, G_OPTION_ARG_STRING, &main_option_expression,
113
125
&main_option_no_load_menus,
114
126
N_( "don't load menu definitions" ), NULL },
115
127
{ "no-load-args", 'a', 0, G_OPTION_ARG_NONE, &main_option_no_load_args,
116
N_( "don't try to load extra cmd-line args as files" ), NULL },
128
N_( "don't try to load command-line arguments" ), NULL },
117
129
{ "stdin-ws", 'w', 0, G_OPTION_ARG_NONE, &main_option_stdin_ws,
118
130
N_( "load stdin as a workspace" ), NULL },
119
131
{ "stdin-def", 'd', 0, G_OPTION_ARG_NONE, &main_option_stdin_def,
127
139
{ "time-save", 't', 0, G_OPTION_ARG_NONE, &main_option_time_save,
128
140
N_( "time image save operations" ),
142
{ "prefix", 'x', 0, G_OPTION_ARG_FILENAME, &main_option_prefix,
143
N_( "start as if installed to PREFIX" ), "PREFIX" },
130
144
{ "i18n", 'i', 0, G_OPTION_ARG_NONE, &main_option_i18n,
131
145
N_( "output strings for internationalisation" ),
133
147
{ "version", 'v', 0, G_OPTION_ARG_NONE, &main_option_version,
134
148
N_( "print version number" ),
150
{ "test", 'T', 0, G_OPTION_ARG_NONE, &main_option_test,
151
N_( "test for errors and quit" ), NULL },
139
155
/* Accumulate startup errors here.
141
157
static char main_start_error_txt[MAX_STRSIZE];
142
static BufInfo main_start_error =
143
BUF_STATIC( main_start_error_txt, MAX_STRSIZE );
158
static VipsBuf main_start_error =
159
VIPS_BUF_STATIC( main_start_error_txt, MAX_STRSIZE );
146
162
main_log_add( const char *fmt, ... )
150
166
va_start( ap, fmt );
151
buf_vappendf( &main_start_error, fmt, ap );
167
vips_buf_vappendf( &main_start_error, fmt, ap );
155
171
static const char *
156
172
main_log_get( void )
158
return( buf_all( &main_start_error ) );
174
return( vips_buf_all( &main_start_error ) );
162
178
main_log_is_empty( void )
164
return( buf_is_empty( &main_start_error ) );
180
return( vips_buf_is_empty( &main_start_error ) );
167
183
/* NULL log handler. Used to suppress output on win32 without DEBUG_FATAL.
191
207
error_get_top(), error_get_sub() );
193
209
if( main_option_verbose ) {
195
211
char txt[MAX_STRSIZE];
197
buf_init_static( &buf, txt, MAX_STRSIZE );
213
vips_buf_init_static( &buf, txt, MAX_STRSIZE );
198
214
slist_map( expr_error_all,
199
215
(SListMapFn) expr_error_print, &buf );
200
fprintf( stderr, "%s\n", buf_all( &buf ) );
216
fprintf( stderr, "%s\n", vips_buf_all( &buf ) );
220
236
char filename[FILENAME_MAX];
222
238
im_strncpy( filename, main_option_output, FILENAME_MAX );
223
if( save_objects( root, filename ) )
224
main_error_exit( _( "error calculating \"%s\"" ),
239
if( !group_save_item( root, filename ) )
240
main_error_exit( _( "error saving \"%s\"" ),
225
241
symbol_name( sym ) );
479
479
if( !main_option_no_load_menus || im_skip_dir( filename )[0] == '_' ) {
480
main_splash_update( _( "Loading toolkit \"%s\"" ),
481
im_skip_dir( filename ) );
480
progress_update_loading( 0, im_skip_dir( filename ) );
483
482
if( !(kit = toolkit_new_from_file( main_toolkitgroup,
499
498
printf( "main_load_ws: %s\n", filename );
502
main_splash_update( _( "Loading workspace \"%s\"" ),
503
im_skip_dir( filename ) );
501
progress_update_loading( 0, im_skip_dir( filename ) );
505
503
if( !(ws = workspace_new_from_file( main_workspacegroup, filename )) )
506
504
box_alert( NULL );
531
529
sym = symbol_new( symbol_root->expr->compile,
532
530
pack->table[i]->name );
533
assert( sym->type == SYM_ZOMBIE );
531
g_assert( sym->type == SYM_ZOMBIE );
534
532
sym->type = SYM_EXTERNAL;
535
533
sym->function = pack->table[i];
536
534
sym->fn_nargs = vips_n_args( pack->table[i] );
796
792
gtk_widget_realize( main_window_top );
797
793
main_window_gdk = main_window_top->window;
800
796
printf( "*** debug updates is on\n" );
801
797
gdk_window_set_debug_updates( TRUE );
798
#endif /*DEBUG_UPDATES*/
804
800
main_register_icons();
806
802
if( main_splash_enabled() ) {
807
803
main_splash = splash_new();
808
804
gtk_widget_show( GTK_WIDGET( main_splash ) );
806
/* Wait for the splashscreen to pop up. We want this to appear
807
* as quickly as possible.
809
while( g_main_context_iteration( NULL, FALSE ) )
811
813
/* Next window we make is end of startup.
859
861
if( total > 10 * 1024 * 1024 ) {
862
864
char tmp[FILENAME_MAX];
864
866
expand_variables( PATH_TMP, tmp );
865
867
nativeize_path( tmp );
866
868
absoluteize_path( tmp );
868
buf_init_static( &buf, txt, 256 );
870
vips_buf_init_static( &buf, txt, 256 );
869
871
to_size( &buf, total );
1072
1074
bindtextdomain( GETTEXT_PACKAGE, name );
1073
1075
bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
1075
#ifdef G_THREADS_ENABLED
1076
/* If VIPS has been configured without threads, we will need to start
1077
* the thread system ourselves so that we can make the async queue in
1080
if( !g_thread_supported() )
1081
g_thread_init( NULL );
1082
#endif /*G_THREADS_ENABLED*/
1084
1077
context = g_option_context_new( _( "- image processing spreadsheet" ) );
1085
1078
g_option_context_add_main_entries( context,
1086
1079
main_option, GETTEXT_PACKAGE );
1100
1093
g_option_context_free( context );
1095
/* Override the install guess from vips. This won't pick up msg
1096
* cats sadly :( since we have to init i18n before arg parsing. Handy
1097
* for testing without installing.
1099
if( main_option_prefix ) {
1100
char tmp[FILENAME_MAX];
1102
im_strncpy( tmp, main_option_prefix, FILENAME_MAX );
1103
nativeize_path( tmp );
1104
absoluteize_path( tmp );
1105
prefix = im_strdupn( tmp );
1106
setenvf( "VIPSHOME", "%s", prefix );
1102
1109
if( main_option_version ) {
1103
1110
printf( "%s-%s", PACKAGE, VERSION );
1104
1111
printf( "\n" );
1106
printf( _( "linked to vips-%s" ),
1107
im_version_string() );
1113
printf( _( "linked to vips-%s" ), im_version_string() );
1108
1114
printf( "\n" );
1147
1153
main_stdin = file_open_read_stdin();
1149
1155
#ifdef HAVE_GETRLIMIT
1150
/* Make sure we have lots of file descriptors.
1156
/* Make sure we have lots of file descriptors. Some platforms have cur
1157
* as 256 and max at 1024 to keep stdio happy.
1152
1159
if( getrlimit( RLIMIT_NOFILE, &rlp ) == 0 ) {
1160
rlim_t old_limit = rlp.rlim_cur;
1153
1162
rlp.rlim_cur = rlp.rlim_max;
1154
1163
if( setrlimit( RLIMIT_NOFILE, &rlp ) == 0 ) {
1157
1166
(int) rlp.rlim_max );
1158
1167
#endif /*DEBUG*/
1161
g_warning( _( "unable to change max file "
1169
else if( (int) rlp.rlim_max != -1 ) {
1170
/* -1 means can't-be-set, at least on os x, so don't
1173
g_warning( _( "unable to change max file descriptors\n"
1163
1174
"max file descriptors still set to %d" ),
1164
(int) rlp.rlim_cur );
1217
1232
g_object_ref( G_OBJECT( main_imageinfogroup ) );
1218
1233
iobject_sink( IOBJECT( main_imageinfogroup ) );
1235
/* First pass at command-line options. Just look at the flags that
1236
* imply other flags, don't do any processing yet.
1238
if( main_option_script ) {
1239
main_option_batch = TRUE;
1240
main_option_no_load_menus = TRUE;
1241
main_option_no_load_args = TRUE;
1242
main_option_print_main = TRUE;
1245
if( main_option_test ) {
1246
main_option_batch = TRUE;
1247
main_option_verbose = TRUE;
1250
if( main_option_expression ) {
1251
main_option_batch = TRUE;
1252
main_option_no_load_menus = TRUE;
1253
main_option_no_load_args = TRUE;
1254
main_option_print_main = TRUE;
1257
if( main_option_benchmark ) {
1258
main_option_batch = TRUE;
1259
main_option_no_load_menus = FALSE;
1262
if( main_option_i18n ) {
1263
/* Just start up and shutdown, no X. Output constant
1266
main_option_batch = TRUE;
1267
main_option_no_load_menus = FALSE;
1271
if( main_option_batch )
1272
printf( "non-interactive mode\n" );
1275
/* Start the X connection. We need this before _load_all(), so that
1276
* we can pop up error dialogs.
1278
if( !main_option_batch )
1279
main_x_init( &argc, &argv );
1281
/* Load start-up stuff. Builtins, plugins, externals etc. We need to
1282
* do this before we load any user code so we can prevent redefinition
1285
main_load_startup();
1221
1288
printf( "arg processing\n" );
1222
1289
#endif/*DEBUG*/
1229
/* Interpret compound options first: these imply other options.
1296
/* Second command-line pass. This time we do any actions.
1231
1298
if( main_option_script ) {
1232
1299
if( !toolkit_new_from_file( main_toolkitgroup,
1233
1300
main_option_script ) )
1234
1301
main_log_add( "%s\n", error_get_sub() );
1236
main_option_batch = TRUE;
1237
main_option_no_load_menus = TRUE;
1238
main_option_no_load_args = TRUE;
1239
main_option_print_main = TRUE;
1242
1304
if( main_option_expression ) {
1243
1305
kit = toolkit_new( main_toolkitgroup, "_expression" );
1245
buf_init_static( &buf, txt, MAX_STRSIZE );
1246
buf_appendf( &buf, "main = %s;", main_option_expression );
1247
attach_input_string( buf_all( &buf ) );
1307
vips_buf_init_static( &buf, txt, MAX_STRSIZE );
1308
vips_buf_appendf( &buf, "main = %s;", main_option_expression );
1309
attach_input_string( vips_buf_all( &buf ) );
1248
1310
(void) parse_onedef( kit, -1 );
1250
1312
filemodel_set_modified( FILEMODEL( kit ), FALSE );
1252
main_option_batch = TRUE;
1253
main_option_no_load_menus = TRUE;
1254
main_option_no_load_args = TRUE;
1255
main_option_print_main = TRUE;
1258
if( main_option_benchmark ) {
1259
main_option_batch = TRUE;
1260
main_option_no_load_menus = FALSE;
1263
if( main_option_i18n ) {
1264
/* Just start up and shutdown, no X. Output constant
1267
main_option_batch = TRUE;
1268
main_option_no_load_menus = FALSE;
1271
1315
if( main_option_stdin_def ) {
1272
/* Load stdin as a set of defs. Good for HEREIS
1275
1316
if( !(kit = toolkit_new_from_openfile(
1276
1317
main_toolkitgroup, main_stdin )) )
1277
1318
main_log_add( "%s\n", error_get_sub() );
1280
1321
if( main_option_stdin_ws ) {
1281
/* Load stdin as a workspace.
1283
1322
if( !(ws = workspace_new_from_openfile(
1284
1323
main_workspacegroup, main_stdin )) )
1285
1324
main_log_add( "%s\n", error_get_sub() );
1296
1335
ws = workspace_new_blank( main_workspacegroup, name );
1300
if( main_option_batch )
1301
printf( "non-interactive mode\n" );
1304
/* Start the X connection. We need this before _load_all(), so that
1305
* we can pop up error dialogs.
1307
if( !main_option_batch )
1308
main_x_init( &argc, &argv );
1310
1338
/* Reset IM_CONCURRENCY if a watch changes. Need to do this after
1311
1339
* parsing options so we skip in batch mode.
1313
1341
g_signal_connect( main_watchgroup, "watch_changed",
1314
1342
G_CALLBACK( main_watchgroup_changed_cb ), NULL );
1316
/* Load start-up stuff.
1318
main_load_startup();
1320
1344
/* Recalc to build all classes. We have to do this in batch
1321
1345
* mode since we can find dirties through dynamic lookups. Even though
1322
1346
* you might think we could just follow recomps.
1324
main_splash_update( "%s", _( "First recalculation ..." ) );
1325
symbol_recalculate_all();
1348
symbol_recalculate_all_force( TRUE );
1327
1350
/* Measure amount of stuff in temp area ... need this for checking
1328
1351
* temps later. We pop a dialog if there are too many, so only useful
1334
1357
/* Make nip's argc/argv[].
1336
1359
kit = toolkit_new( main_toolkitgroup, "_args" );
1337
buf_init_static( &buf, txt, MAX_STRSIZE );
1338
buf_appendf( &buf, "argc = %d;", argc );
1339
attach_input_string( buf_all( &buf ) );
1360
vips_buf_init_static( &buf, txt, MAX_STRSIZE );
1361
vips_buf_appendf( &buf, "argc = %d;", argc );
1362
attach_input_string( vips_buf_all( &buf ) );
1340
1363
(void) parse_onedef( kit, -1 );
1342
buf_init_static( &buf, txt, MAX_STRSIZE );
1343
buf_appendf( &buf, "argv = [" );
1365
vips_buf_init_static( &buf, txt, MAX_STRSIZE );
1366
vips_buf_appendf( &buf, "argv = [" );
1344
1367
for( i = 0; i < argc; i++ ) {
1346
buf_appendf( &buf, ", " );
1347
buf_appendf( &buf, "\"%s\"", argv[i] );
1369
vips_buf_appendf( &buf, ", " );
1370
vips_buf_appendf( &buf, "\"%s\"", argv[i] );
1349
buf_appendf( &buf, "];" );
1372
vips_buf_appendf( &buf, "];" );
1351
attach_input_string( buf_all( &buf ) );
1374
attach_input_string( vips_buf_all( &buf ) );
1352
1375
if( !parse_onedef( kit, -1 ) )
1353
1376
main_log_add( "%s\n", error_get_sub() );
1383
1406
/* Recalc to load any args.
1385
main_splash_update( "%s", _( "Final recalculation ..." ) );
1386
symbol_recalculate_all();
1408
symbol_recalculate_all_force( TRUE );
1388
1410
/* Make sure our start ws doesn't have modified set. We may have
1389
1411
* loaded some images or whatever into it.