~ubuntu-branches/ubuntu/saucy/gimp/saucy-updates

« back to all changes in this revision

Viewing changes to .pc/string-format.patch/app/main.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-02-22 23:47:53 UTC
  • mfrom: (1.1.25) (0.4.15 sid)
  • Revision ID: package-import@ubuntu.com-20120222234753-2a4wqdkb2bbx4mjb
Tags: 2.6.12-1ubuntu1
* Merge from Debian unstable (LP: #925674). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates

* Drop poppler patch as it's been applied upstream
  - drop debian/patches/poppler0.18.patch
  - update debian/patches/series
* fix LP: #680521 - Embed page setup dialog functionality in the print dialog
  - add debian/patches/embed-page-setup-dialog.patch
  - update debian/patches/series

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GIMP - The GNU Image Manipulation Program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
7
 
 * (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
#include "config.h"
20
 
 
21
 
#define _GNU_SOURCE  /* for the sigaction stuff */
22
 
 
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
#include <string.h>
26
 
#include <signal.h>
27
 
 
28
 
#ifdef HAVE_UNISTD_H
29
 
#include <unistd.h>
30
 
#endif
31
 
 
32
 
#ifdef __GLIBC__
33
 
#include <malloc.h>
34
 
#endif
35
 
 
36
 
#include <locale.h>
37
 
 
38
 
#include <glib-object.h>
39
 
 
40
 
#ifdef G_OS_WIN32
41
 
#include <io.h> /* get_osfhandle */
42
 
#endif
43
 
 
44
 
#ifndef GIMP_CONSOLE_COMPILATION
45
 
#include <gdk/gdk.h>
46
 
#endif
47
 
 
48
 
#include "libgimpbase/gimpbase.h"
49
 
 
50
 
#include "core/core-types.h"
51
 
 
52
 
#include "base/tile.h"
53
 
 
54
 
#include "config/gimpconfig-dump.h"
55
 
 
56
 
#include "core/gimp.h"
57
 
 
58
 
#include "about.h"
59
 
#include "app.h"
60
 
#include "errors.h"
61
 
#include "sanity.h"
62
 
#include "unique.h"
63
 
#include "units.h"
64
 
#include "version.h"
65
 
 
66
 
#ifdef G_OS_WIN32
67
 
/* To get PROCESS_DEP_* defined we need _WIN32_WINNT at 0x0601. We still
68
 
 * use the API optionally only if present, though.
69
 
 */
70
 
#define _WIN32_WINNT 0x0601
71
 
#include <windows.h>
72
 
#include <conio.h>
73
 
#endif
74
 
 
75
 
#include "gimp-log.h"
76
 
#include "gimp-intl.h"
77
 
 
78
 
 
79
 
static gboolean  gimp_option_fatal_warnings   (const gchar  *option_name,
80
 
                                               const gchar  *value,
81
 
                                               gpointer      data,
82
 
                                               GError      **error);
83
 
static gboolean  gimp_option_stack_trace_mode (const gchar  *option_name,
84
 
                                               const gchar  *value,
85
 
                                               gpointer      data,
86
 
                                               GError      **error);
87
 
static gboolean  gimp_option_pdb_compat_mode  (const gchar  *option_name,
88
 
                                               const gchar  *value,
89
 
                                               gpointer      data,
90
 
                                               GError      **error);
91
 
static gboolean  gimp_option_dump_gimprc      (const gchar  *option_name,
92
 
                                               const gchar  *value,
93
 
                                               gpointer      data,
94
 
                                               GError      **error);
95
 
 
96
 
static void      gimp_show_version_and_exit   (void) G_GNUC_NORETURN;
97
 
static void      gimp_show_license_and_exit   (void) G_GNUC_NORETURN;
98
 
 
99
 
static void      gimp_init_i18n               (void);
100
 
static void      gimp_init_malloc             (void);
101
 
static void      gimp_init_signal_handlers    (void);
102
 
 
103
 
#ifndef G_OS_WIN32
104
 
static void      gimp_sigfatal_handler        (gint sig_num) G_GNUC_NORETURN;
105
 
#endif
106
 
 
107
 
#if defined (G_OS_WIN32) && !defined (GIMP_CONSOLE_COMPILATION)
108
 
static void      gimp_open_console_window     (void);
109
 
#else
110
 
#define gimp_open_console_window() /* as nothing */
111
 
#endif
112
 
 
113
 
static const gchar        *system_gimprc     = NULL;
114
 
static const gchar        *user_gimprc       = NULL;
115
 
static const gchar        *session_name      = NULL;
116
 
static const gchar        *batch_interpreter = NULL;
117
 
static const gchar       **batch_commands    = NULL;
118
 
static const gchar       **filenames         = NULL;
119
 
static gboolean            as_new            = FALSE;
120
 
static gboolean            no_interface      = FALSE;
121
 
static gboolean            no_data           = FALSE;
122
 
static gboolean            no_fonts          = FALSE;
123
 
static gboolean            no_splash         = FALSE;
124
 
static gboolean            be_verbose        = FALSE;
125
 
static gboolean            new_instance      = FALSE;
126
 
#if defined (USE_SYSV_SHM) || defined (USE_POSIX_SHM) || defined (G_OS_WIN32)
127
 
static gboolean            use_shm           = TRUE;
128
 
#else
129
 
static gboolean            use_shm           = FALSE;
130
 
#endif
131
 
static gboolean            use_cpu_accel     = TRUE;
132
 
static gboolean            console_messages  = FALSE;
133
 
static gboolean            use_debug_handler = FALSE;
134
 
 
135
 
#ifdef GIMP_UNSTABLE
136
 
static GimpStackTraceMode  stack_trace_mode  = GIMP_STACK_TRACE_QUERY;
137
 
static GimpPDBCompatMode   pdb_compat_mode   = GIMP_PDB_COMPAT_WARN;
138
 
#else
139
 
static GimpStackTraceMode  stack_trace_mode  = GIMP_STACK_TRACE_NEVER;
140
 
static GimpPDBCompatMode   pdb_compat_mode   = GIMP_PDB_COMPAT_ON;
141
 
#endif
142
 
 
143
 
 
144
 
static const GOptionEntry main_entries[] =
145
 
{
146
 
  { "version", 'v', G_OPTION_FLAG_NO_ARG,
147
 
    G_OPTION_ARG_CALLBACK, (GOptionArgFunc) gimp_show_version_and_exit,
148
 
    N_("Show version information and exit"), NULL
149
 
  },
150
 
  {
151
 
    "license", 0, G_OPTION_FLAG_NO_ARG,
152
 
    G_OPTION_ARG_CALLBACK, (GOptionArgFunc) gimp_show_license_and_exit,
153
 
    N_("Show license information and exit"), NULL
154
 
  },
155
 
  {
156
 
    "verbose", 0, 0,
157
 
    G_OPTION_ARG_NONE, &be_verbose,
158
 
    N_("Be more verbose"), NULL
159
 
  },
160
 
  {
161
 
    "new-instance", 'n', 0,
162
 
    G_OPTION_ARG_NONE, &new_instance,
163
 
    N_("Start a new GIMP instance"), NULL
164
 
  },
165
 
  {
166
 
    "as-new", 'a', 0,
167
 
    G_OPTION_ARG_NONE, &as_new,
168
 
    N_("Open images as new"), NULL
169
 
  },
170
 
  {
171
 
    "no-interface", 'i', 0,
172
 
    G_OPTION_ARG_NONE, &no_interface,
173
 
    N_("Run without a user interface"), NULL
174
 
  },
175
 
  {
176
 
    "no-data", 'd', 0,
177
 
    G_OPTION_ARG_NONE, &no_data,
178
 
    N_("Do not load brushes, gradients, patterns, ..."), NULL
179
 
  },
180
 
  {
181
 
    "no-fonts", 'f', 0,
182
 
    G_OPTION_ARG_NONE, &no_fonts,
183
 
    N_("Do not load any fonts"), NULL
184
 
  },
185
 
  {
186
 
    "no-splash", 's', 0,
187
 
    G_OPTION_ARG_NONE, &no_splash,
188
 
    N_("Do not show a startup window"), NULL
189
 
  },
190
 
  {
191
 
    "no-shm", 0, G_OPTION_FLAG_REVERSE,
192
 
    G_OPTION_ARG_NONE, &use_shm,
193
 
    N_("Do not use shared memory between GIMP and plugins"), NULL
194
 
  },
195
 
  {
196
 
    "no-cpu-accel", 0, G_OPTION_FLAG_REVERSE,
197
 
    G_OPTION_ARG_NONE, &use_cpu_accel,
198
 
    N_("Do not use special CPU acceleration functions"), NULL
199
 
  },
200
 
  {
201
 
    "session", 0, 0,
202
 
    G_OPTION_ARG_FILENAME, &session_name,
203
 
    N_("Use an alternate sessionrc file"), "<name>"
204
 
  },
205
 
  {
206
 
    "gimprc", 'g', 0,
207
 
    G_OPTION_ARG_FILENAME, &user_gimprc,
208
 
    N_("Use an alternate user gimprc file"), "<filename>"
209
 
  },
210
 
  {
211
 
    "system-gimprc", 0, 0,
212
 
    G_OPTION_ARG_FILENAME, &system_gimprc,
213
 
    N_("Use an alternate system gimprc file"), "<filename>"
214
 
  },
215
 
  {
216
 
    "batch", 'b', 0,
217
 
    G_OPTION_ARG_STRING_ARRAY, &batch_commands,
218
 
    N_("Batch command to run (can be used multiple times)"), "<command>"
219
 
  },
220
 
  {
221
 
    "batch-interpreter", 0, 0,
222
 
    G_OPTION_ARG_STRING, &batch_interpreter,
223
 
    N_("The procedure to process batch commands with"), "<proc>"
224
 
  },
225
 
  {
226
 
    "console-messages", 'c', 0,
227
 
    G_OPTION_ARG_NONE, &console_messages,
228
 
    N_("Send messages to console instead of using a dialog"), NULL
229
 
  },
230
 
  {
231
 
    "pdb-compat-mode", 0, 0,
232
 
    G_OPTION_ARG_CALLBACK, gimp_option_pdb_compat_mode,
233
 
    /*  don't translate the mode names (off|on|warn)  */
234
 
    N_("PDB compatibility mode (off|on|warn)"), "<mode>"
235
 
  },
236
 
  {
237
 
    "stack-trace-mode", 0, 0,
238
 
    G_OPTION_ARG_CALLBACK, gimp_option_stack_trace_mode,
239
 
    /*  don't translate the mode names (never|query|always)  */
240
 
    N_("Debug in case of a crash (never|query|always)"), "<mode>"
241
 
  },
242
 
  {
243
 
    "debug-handlers", 0, G_OPTION_FLAG_NO_ARG,
244
 
    G_OPTION_ARG_NONE, &use_debug_handler,
245
 
    N_("Enable non-fatal debugging signal handlers"), NULL
246
 
  },
247
 
  {
248
 
    "g-fatal-warnings", 0, G_OPTION_FLAG_NO_ARG,
249
 
    G_OPTION_ARG_CALLBACK, gimp_option_fatal_warnings,
250
 
    N_("Make all warnings fatal"), NULL
251
 
  },
252
 
  {
253
 
    "dump-gimprc", 0, G_OPTION_FLAG_NO_ARG,
254
 
    G_OPTION_ARG_CALLBACK, gimp_option_dump_gimprc,
255
 
    N_("Output a gimprc file with default settings"), NULL
256
 
  },
257
 
  {
258
 
    "dump-gimprc-system", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
259
 
    G_OPTION_ARG_CALLBACK, gimp_option_dump_gimprc,
260
 
    NULL, NULL
261
 
  },
262
 
  {
263
 
    "dump-gimprc-manpage", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
264
 
    G_OPTION_ARG_CALLBACK, gimp_option_dump_gimprc,
265
 
    NULL, NULL
266
 
  },
267
 
  {
268
 
    G_OPTION_REMAINING, 0, 0,
269
 
    G_OPTION_ARG_FILENAME_ARRAY, &filenames,
270
 
    NULL, NULL
271
 
  },
272
 
  { NULL }
273
 
};
274
 
 
275
 
int
276
 
main (int    argc,
277
 
      char **argv)
278
 
{
279
 
  GOptionContext *context;
280
 
  GError         *error = NULL;
281
 
  const gchar    *abort_message;
282
 
  gchar          *basename;
283
 
  gint            i;
284
 
 
285
 
#if defined (__GNUC__) && defined (_WIN64)
286
 
  /* mingw-w64, at least the unstable build from late July 2008,
287
 
   * starts subsystem:windows programs in main(), but passes them
288
 
   * bogus argc and argv. __argc and __argv are OK, though, so just
289
 
   * use them.
290
 
   */
291
 
  argc = __argc;
292
 
  argv = __argv;
293
 
#endif
294
 
 
295
 
#ifdef G_OS_WIN32
296
 
  /* Reduce risks */
297
 
  {
298
 
    typedef BOOL (WINAPI *t_SetDllDirectoryA) (LPCSTR lpPathName);
299
 
    t_SetDllDirectoryA p_SetDllDirectoryA;
300
 
 
301
 
    p_SetDllDirectoryA = GetProcAddress (GetModuleHandle ("kernel32.dll"),
302
 
                                         "SetDllDirectoryA");
303
 
    if (p_SetDllDirectoryA)
304
 
      (*p_SetDllDirectoryA) ("");
305
 
  }
306
 
#ifndef _WIN64
307
 
  {
308
 
    typedef BOOL (WINAPI *t_SetProcessDEPPolicy) (DWORD dwFlags);
309
 
    t_SetProcessDEPPolicy p_SetProcessDEPPolicy;
310
 
 
311
 
    p_SetProcessDEPPolicy = GetProcAddress (GetModuleHandle ("kernel32.dll"),
312
 
                                            "SetProcessDEPPolicy");
313
 
    if (p_SetProcessDEPPolicy)
314
 
      (*p_SetProcessDEPPolicy) (PROCESS_DEP_ENABLE|PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION);
315
 
  }
316
 
#endif
317
 
#endif
318
 
 
319
 
  g_thread_init (NULL);
320
 
 
321
 
#ifdef GIMP_UNSTABLE
322
 
  gimp_open_console_window ();
323
 
#endif
324
 
 
325
 
  gimp_init_malloc ();
326
 
 
327
 
  gimp_env_init (FALSE);
328
 
 
329
 
  gimp_log_init ();
330
 
 
331
 
  gimp_init_i18n ();
332
 
 
333
 
  g_set_application_name (GIMP_NAME);
334
 
 
335
 
  basename = g_path_get_basename (argv[0]);
336
 
  g_set_prgname (basename);
337
 
  g_free (basename);
338
 
 
339
 
  /* Check argv[] for "--verbose" first */
340
 
  for (i = 1; i < argc; i++)
341
 
    {
342
 
      const gchar *arg = argv[i];
343
 
 
344
 
      if (arg[0] != '-')
345
 
        continue;
346
 
 
347
 
      if ((strcmp (arg, "--verbose") == 0) || (strcmp (arg, "-v") == 0))
348
 
        {
349
 
          be_verbose = TRUE;
350
 
        }
351
 
    }
352
 
 
353
 
  /* Check argv[] for "--no-interface" before trying to initialize gtk+. */
354
 
  for (i = 1; i < argc; i++)
355
 
    {
356
 
      const gchar *arg = argv[i];
357
 
 
358
 
      if (arg[0] != '-')
359
 
        continue;
360
 
 
361
 
      if ((strcmp (arg, "--no-interface") == 0) || (strcmp (arg, "-i") == 0))
362
 
        {
363
 
          no_interface = TRUE;
364
 
        }
365
 
      else if ((strcmp (arg, "--version") == 0) || (strcmp (arg, "-v") == 0))
366
 
        {
367
 
          gimp_show_version_and_exit ();
368
 
        }
369
 
#if defined (G_OS_WIN32) && !defined (GIMP_CONSOLE_COMPILATION)
370
 
      else if ((strcmp (arg, "--help") == 0) ||
371
 
               (strcmp (arg, "-?") == 0) ||
372
 
               (strncmp (arg, "--help-", 7) == 0))
373
 
        {
374
 
          gimp_open_console_window ();
375
 
        }
376
 
#endif
377
 
    }
378
 
 
379
 
#ifdef GIMP_CONSOLE_COMPILATION
380
 
  no_interface = TRUE;
381
 
#endif
382
 
 
383
 
  context = g_option_context_new (_("[FILE|URI...]"));
384
 
  g_option_context_set_summary (context, GIMP_NAME);
385
 
 
386
 
  g_option_context_add_main_entries (context, main_entries, GETTEXT_PACKAGE);
387
 
 
388
 
  app_libs_init (context, no_interface);
389
 
 
390
 
  if (! g_option_context_parse (context, &argc, &argv, &error))
391
 
    {
392
 
      if (error)
393
 
        {
394
 
          gimp_open_console_window ();
395
 
          g_print ("%s\n", error->message);
396
 
          g_error_free (error);
397
 
        }
398
 
      else
399
 
        {
400
 
          g_print ("%s\n",
401
 
                   _("GIMP could not initialize the graphical user interface.\n"
402
 
                     "Make sure a proper setup for your display environment "
403
 
                     "exists."));
404
 
        }
405
 
 
406
 
      app_exit (EXIT_FAILURE);
407
 
    }
408
 
 
409
 
  if (no_interface || be_verbose || console_messages || batch_commands != NULL)
410
 
    gimp_open_console_window ();
411
 
 
412
 
  if (no_interface)
413
 
    new_instance = TRUE;
414
 
 
415
 
#ifndef GIMP_CONSOLE_COMPILATION
416
 
  if (! new_instance && gimp_unique_open (filenames, as_new))
417
 
    {
418
 
      if (be_verbose)
419
 
        g_print ("%s\n",
420
 
                 _("Another GIMP instance is already running."));
421
 
 
422
 
      gdk_notify_startup_complete ();
423
 
 
424
 
      return EXIT_SUCCESS;
425
 
    }
426
 
#endif
427
 
 
428
 
  abort_message = sanity_check ();
429
 
  if (abort_message)
430
 
    app_abort (no_interface, abort_message);
431
 
 
432
 
  gimp_init_signal_handlers ();
433
 
 
434
 
  app_run (argv[0],
435
 
           filenames,
436
 
           system_gimprc,
437
 
           user_gimprc,
438
 
           session_name,
439
 
           batch_interpreter,
440
 
           batch_commands,
441
 
           as_new,
442
 
           no_interface,
443
 
           no_data,
444
 
           no_fonts,
445
 
           no_splash,
446
 
           be_verbose,
447
 
           use_shm,
448
 
           use_cpu_accel,
449
 
           console_messages,
450
 
           use_debug_handler,
451
 
           stack_trace_mode,
452
 
           pdb_compat_mode);
453
 
 
454
 
  g_option_context_free (context);
455
 
 
456
 
  return EXIT_SUCCESS;
457
 
}
458
 
 
459
 
 
460
 
#ifdef G_OS_WIN32
461
 
 
462
 
/* Provide WinMain in case we build GIMP as a subsystem:windows
463
 
 * application. Well, we do. When built with mingw, though, user code
464
 
 * execution still starts in main() in that case. So WinMain() gets
465
 
 * used on MSVC builds only.
466
 
 */
467
 
 
468
 
#ifdef __GNUC__
469
 
#  ifndef _stdcall
470
 
#    define _stdcall  __attribute__((stdcall))
471
 
#  endif
472
 
#endif
473
 
 
474
 
int _stdcall
475
 
WinMain (struct HINSTANCE__ *hInstance,
476
 
         struct HINSTANCE__ *hPrevInstance,
477
 
         char               *lpszCmdLine,
478
 
         int                 nCmdShow)
479
 
{
480
 
  return main (__argc, __argv);
481
 
}
482
 
 
483
 
#ifndef GIMP_CONSOLE_COMPILATION
484
 
 
485
 
static void
486
 
wait_console_window (void)
487
 
{
488
 
  FILE *console = fopen ("CONOUT$", "w");
489
 
 
490
 
  SetConsoleTitleW (g_utf8_to_utf16 (_("GIMP output. Type any character to close this window."), -1, NULL, NULL, NULL));
491
 
  fprintf (console, _("(Type any character to close this window)\n"));
492
 
  fflush (console);
493
 
  _getch ();
494
 
}
495
 
 
496
 
static void
497
 
gimp_open_console_window (void)
498
 
{
499
 
  if (((HANDLE) _get_osfhandle (fileno (stdout)) == INVALID_HANDLE_VALUE ||
500
 
       (HANDLE) _get_osfhandle (fileno (stderr)) == INVALID_HANDLE_VALUE) && AllocConsole ())
501
 
    {
502
 
      if ((HANDLE) _get_osfhandle (fileno (stdout)) == INVALID_HANDLE_VALUE)
503
 
        freopen ("CONOUT$", "w", stdout);
504
 
 
505
 
      if ((HANDLE) _get_osfhandle (fileno (stderr)) == INVALID_HANDLE_VALUE)
506
 
        freopen ("CONOUT$", "w", stderr);
507
 
 
508
 
      SetConsoleTitleW (g_utf8_to_utf16 (_("GIMP output. You can minimize this window, but don't close it."), -1, NULL, NULL, NULL));
509
 
 
510
 
      atexit (wait_console_window);
511
 
    }
512
 
}
513
 
#endif
514
 
 
515
 
#endif /* G_OS_WIN32 */
516
 
 
517
 
 
518
 
static gboolean
519
 
gimp_option_fatal_warnings (const gchar  *option_name,
520
 
                            const gchar  *value,
521
 
                            gpointer      data,
522
 
                            GError      **error)
523
 
{
524
 
  GLogLevelFlags fatal_mask;
525
 
 
526
 
  fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
527
 
  fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
528
 
 
529
 
  g_log_set_always_fatal (fatal_mask);
530
 
 
531
 
  return TRUE;
532
 
}
533
 
 
534
 
static gboolean
535
 
gimp_option_stack_trace_mode (const gchar  *option_name,
536
 
                              const gchar  *value,
537
 
                              gpointer      data,
538
 
                              GError      **error)
539
 
{
540
 
  if (strcmp (value, "never") == 0)
541
 
    stack_trace_mode = GIMP_STACK_TRACE_NEVER;
542
 
  else if (strcmp (value, "query") == 0)
543
 
    stack_trace_mode = GIMP_STACK_TRACE_QUERY;
544
 
  else if (strcmp (value, "always") == 0)
545
 
    stack_trace_mode = GIMP_STACK_TRACE_ALWAYS;
546
 
  else
547
 
    return FALSE;
548
 
 
549
 
  return TRUE;
550
 
}
551
 
 
552
 
static gboolean
553
 
gimp_option_pdb_compat_mode (const gchar  *option_name,
554
 
                             const gchar  *value,
555
 
                             gpointer      data,
556
 
                             GError      **error)
557
 
{
558
 
  if (! strcmp (value, "off"))
559
 
    pdb_compat_mode = GIMP_PDB_COMPAT_OFF;
560
 
  else if (! strcmp (value, "on"))
561
 
    pdb_compat_mode = GIMP_PDB_COMPAT_ON;
562
 
  else if (! strcmp (value, "warn"))
563
 
    pdb_compat_mode = GIMP_PDB_COMPAT_WARN;
564
 
  else
565
 
    return FALSE;
566
 
 
567
 
  return TRUE;
568
 
}
569
 
 
570
 
static gboolean
571
 
gimp_option_dump_gimprc (const gchar  *option_name,
572
 
                         const gchar  *value,
573
 
                         gpointer      data,
574
 
                         GError      **error)
575
 
{
576
 
  GimpConfigDumpFormat format = GIMP_CONFIG_DUMP_NONE;
577
 
 
578
 
  gimp_open_console_window ();
579
 
 
580
 
  if (strcmp (option_name, "--dump-gimprc") == 0)
581
 
    format = GIMP_CONFIG_DUMP_GIMPRC;
582
 
  if (strcmp (option_name, "--dump-gimprc-system") == 0)
583
 
    format = GIMP_CONFIG_DUMP_GIMPRC_SYSTEM;
584
 
  else if (strcmp (option_name, "--dump-gimprc-manpage") == 0)
585
 
    format = GIMP_CONFIG_DUMP_GIMPRC_MANPAGE;
586
 
 
587
 
  if (format)
588
 
    {
589
 
      Gimp     *gimp;
590
 
      gboolean  success;
591
 
 
592
 
      gimp = g_object_new (GIMP_TYPE_GIMP, NULL);
593
 
 
594
 
      units_init (gimp);
595
 
 
596
 
      success = gimp_config_dump (format);
597
 
 
598
 
      g_object_unref (gimp);
599
 
 
600
 
      app_exit (success ? EXIT_SUCCESS : EXIT_FAILURE);
601
 
    }
602
 
 
603
 
  return FALSE;
604
 
}
605
 
 
606
 
static void
607
 
gimp_show_version_and_exit (void)
608
 
{
609
 
  gimp_open_console_window ();
610
 
  gimp_version_show (be_verbose);
611
 
 
612
 
  app_exit (EXIT_SUCCESS);
613
 
}
614
 
 
615
 
static void
616
 
gimp_show_license_and_exit (void)
617
 
{
618
 
  gimp_open_console_window ();
619
 
  gimp_version_show (be_verbose);
620
 
 
621
 
  g_print ("\n");
622
 
  g_print (GIMP_LICENSE);
623
 
  g_print ("\n\n");
624
 
 
625
 
  app_exit (EXIT_SUCCESS);
626
 
}
627
 
 
628
 
static void
629
 
gimp_init_malloc (void)
630
 
{
631
 
#ifdef GIMP_GLIB_MEM_PROFILER
632
 
  g_mem_set_vtable (glib_mem_profiler_table);
633
 
  g_atexit (g_mem_profile);
634
 
#endif
635
 
 
636
 
#ifdef __GLIBC__
637
 
  /* Tweak memory allocation so that memory allocated in chunks >= 4k
638
 
   * (64x64 pixel 1bpp tile) gets returned to the system when free()'d.
639
 
   *
640
 
   * The default value for M_MMAP_THRESHOLD in glibc-2.3 is 128k.
641
 
   * This is said to be an empirically derived value that works well
642
 
   * in most systems. Lowering it to 4k is thus probably not the ideal
643
 
   * solution.
644
 
   *
645
 
   * An alternative to tuning this parameter would be to use
646
 
   * malloc_trim(), for example after releasing a large tile-manager.
647
 
   */
648
 
  mallopt (M_MMAP_THRESHOLD, TILE_WIDTH * TILE_HEIGHT);
649
 
#endif
650
 
}
651
 
 
652
 
static void
653
 
gimp_init_i18n (void)
654
 
{
655
 
  setlocale (LC_ALL, "");
656
 
 
657
 
  bindtextdomain (GETTEXT_PACKAGE"-libgimp", gimp_locale_directory ());
658
 
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
659
 
  bind_textdomain_codeset (GETTEXT_PACKAGE"-libgimp", "UTF-8");
660
 
#endif
661
 
 
662
 
  bindtextdomain (GETTEXT_PACKAGE, gimp_locale_directory ());
663
 
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
664
 
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
665
 
#endif
666
 
 
667
 
  textdomain (GETTEXT_PACKAGE);
668
 
}
669
 
 
670
 
static void
671
 
gimp_init_signal_handlers (void)
672
 
{
673
 
#ifndef G_OS_WIN32
674
 
  /* No use catching these on Win32, the user won't get any
675
 
   * stack trace from glib anyhow. It's better to let Windows inform
676
 
   * about the program error, and offer debugging (if the user
677
 
   * has installed MSVC or some other compiler that knows how to
678
 
   * install itself as a handler for program errors).
679
 
   */
680
 
 
681
 
  /* Handle fatal signals */
682
 
 
683
 
  /* these are handled by gimp_terminate() */
684
 
  gimp_signal_private (SIGHUP,  gimp_sigfatal_handler, 0);
685
 
  gimp_signal_private (SIGINT,  gimp_sigfatal_handler, 0);
686
 
  gimp_signal_private (SIGQUIT, gimp_sigfatal_handler, 0);
687
 
  gimp_signal_private (SIGABRT, gimp_sigfatal_handler, 0);
688
 
  gimp_signal_private (SIGTERM, gimp_sigfatal_handler, 0);
689
 
 
690
 
  if (stack_trace_mode != GIMP_STACK_TRACE_NEVER)
691
 
    {
692
 
      /* these are handled by gimp_fatal_error() */
693
 
      gimp_signal_private (SIGBUS,  gimp_sigfatal_handler, 0);
694
 
      gimp_signal_private (SIGSEGV, gimp_sigfatal_handler, 0);
695
 
      gimp_signal_private (SIGFPE,  gimp_sigfatal_handler, 0);
696
 
    }
697
 
 
698
 
  /* Ignore SIGPIPE because plug_in.c handles broken pipes */
699
 
  gimp_signal_private (SIGPIPE, SIG_IGN, 0);
700
 
 
701
 
  /* Restart syscalls on SIGCHLD */
702
 
  gimp_signal_private (SIGCHLD, SIG_DFL, SA_RESTART);
703
 
 
704
 
#endif /* G_OS_WIN32 */
705
 
}
706
 
 
707
 
 
708
 
#ifndef G_OS_WIN32
709
 
 
710
 
/* gimp core signal handler for fatal signals */
711
 
 
712
 
static void
713
 
gimp_sigfatal_handler (gint sig_num)
714
 
{
715
 
  switch (sig_num)
716
 
    {
717
 
    case SIGHUP:
718
 
    case SIGINT:
719
 
    case SIGQUIT:
720
 
    case SIGABRT:
721
 
    case SIGTERM:
722
 
      gimp_terminate (g_strsignal (sig_num));
723
 
      break;
724
 
 
725
 
    case SIGBUS:
726
 
    case SIGSEGV:
727
 
    case SIGFPE:
728
 
    default:
729
 
      gimp_fatal_error (g_strsignal (sig_num));
730
 
      break;
731
 
    }
732
 
}
733
 
 
734
 
#endif /* ! G_OS_WIN32 */