minor cleanup, hopefully not breaking anything.

2007-11-17  Sven Neumann  <sven@gimp.org>

	* tools/gimptool.c: minor cleanup, hopefully not breaking 
anything.


svn path=/trunk/; revision=24181
This commit is contained in:
Sven Neumann 2007-11-17 13:30:23 +00:00 committed by Sven Neumann
parent 287cc39898
commit bbef0f35e8
2 changed files with 104 additions and 72 deletions

View File

@ -1,3 +1,7 @@
2007-11-17 Sven Neumann <sven@gimp.org>
* tools/gimptool.c: minor cleanup, hopefully not breaking anything.
2007-11-17 Sven Neumann <sven@gimp.org> 2007-11-17 Sven Neumann <sven@gimp.org>
* app/base/base-utils.[ch]: changed to get_physical_memory_size() * app/base/base-utils.[ch]: changed to get_physical_memory_size()

View File

@ -1,5 +1,5 @@
/* gimptool in C /* gimptool in C
* Copyright (C) 2001--2007 Tor Lillqvist * Copyright (C) 2001-2007 Tor Lillqvist
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -35,16 +35,18 @@
#include "libgimpbase/gimpversion.h" #include "libgimpbase/gimpversion.h"
static gboolean silent = FALSE;
static gboolean dry_run = FALSE;
static gchar *prefix;
static gchar *exec_prefix;
static gchar *env_cc; static gboolean silent = FALSE;
static gboolean msvc_syntax = FALSE; static gboolean dry_run = FALSE;
static gchar *env_cflags; static gchar *prefix;
static gchar *env_ldflags; static gchar *exec_prefix;
static gchar *env_libs;
static gchar *env_cc;
static gboolean msvc_syntax = FALSE;
static gchar *env_cflags;
static gchar *env_ldflags;
static gchar *env_libs;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
#define EXEEXT ".exe" #define EXEEXT ".exe"
@ -61,30 +63,30 @@ static gchar *env_libs;
#endif #endif
static struct { static struct {
gchar *option; const gchar *option;
gchar *value; gchar *value;
} dirs[] = { } dirs[] = {
{ "prefix", PREFIX }, { "prefix", PREFIX },
{ "exec-prefix", EXEC_PREFIX }, { "exec-prefix", EXEC_PREFIX },
{ "bindir", BINDIR }, { "bindir", BINDIR },
{ "sbindir", SBINDIR }, { "sbindir", SBINDIR },
{ "libexecdir", LIBEXECDIR }, { "libexecdir", LIBEXECDIR },
{ "datadir", DATADIR }, { "datadir", DATADIR },
{ "datarootdir", DATAROOTDIR }, { "datarootdir", DATAROOTDIR },
{ "sysconfdir", SYSCONFDIR }, { "sysconfdir", SYSCONFDIR },
{ "sharedstatedir", SHAREDSTATEDIR }, { "sharedstatedir", SHAREDSTATEDIR },
{ "localstatedir", LOCALSTATEDIR }, { "localstatedir", LOCALSTATEDIR },
{ "libdir", LIBDIR }, { "libdir", LIBDIR },
{ "infodir", INFODIR }, { "infodir", INFODIR },
{ "mandir", MANDIR }, { "mandir", MANDIR },
#if 0 #if 0
/* For --includedir we want the includedir of the developer package, /* For --includedir we want the includedir of the developer package,
* not an includedir under the runtime installation prefix. * not an includedir under the runtime installation prefix.
*/ */
{ "includedir", INCLUDEDIR }, { "includedir", INCLUDEDIR },
#endif #endif
{ "gimpplugindir", GIMPPLUGINDIR }, { "gimpplugindir", GIMPPLUGINDIR },
{ "gimpdatadir", GIMPDATADIR } { "gimpdatadir", GIMPDATADIR }
}; };
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
@ -115,13 +117,13 @@ one_line_output (gchar *program,
gchar *args) gchar *args)
{ {
gchar *command = g_strconcat (program, " ", args, NULL); gchar *command = g_strconcat (program, " ", args, NULL);
FILE *pipe = popen (command, "r"); FILE *pipe = popen (command, "r");
char line[1000]; gchar line[1000];
if (pipe == NULL) if (pipe == NULL)
{ {
fprintf (stderr, "Cannot run '%s'\n", command); g_printerr ("Cannot run '%s'\n", command);
exit (1); exit (EXIT_FAILURE);
} }
if (fgets (line, sizeof (line), pipe) == NULL) if (fgets (line, sizeof (line), pipe) == NULL)
@ -136,8 +138,8 @@ one_line_output (gchar *program,
if (strlen (line) == 0) if (strlen (line) == 0)
{ {
fprintf (stderr, "No output from '%s'\n", command); g_printerr ("No output from '%s'\n", command);
exit (1); exit (EXIT_FAILURE);
} }
return g_strdup (line); return g_strdup (line);
@ -164,13 +166,13 @@ get_runtime_prefix (gchar slash)
*/ */
gchar *path; gchar *path;
char *p, *r; gchar *p, *r;
path = g_find_program_in_path ("gimp-" GIMP_APP_VERSION ".exe"); path = g_find_program_in_path ("gimp-" GIMP_APP_VERSION ".exe");
if (path == NULL) if (path == NULL)
path = g_find_program_in_path ("gimp.exe"); path = g_find_program_in_path ("gimp.exe");
if (path != NULL) if (path != NULL)
{ {
r = strrchr (path, G_DIR_SEPARATOR); r = strrchr (path, G_DIR_SEPARATOR);
@ -193,8 +195,9 @@ get_runtime_prefix (gchar slash)
} }
} }
fprintf (stderr, "Cannot determine GIMP " GIMP_APP_VERSION " installation location\n"); g_printerr ("Cannot determine GIMP " GIMP_APP_VERSION " installation location\n");
exit (1);
exit (EXIT_FAILURE);
#else #else
/* On Unix assume the executable package is in the same prefix as the developer stuff */ /* On Unix assume the executable package is in the same prefix as the developer stuff */
return pkg_config ("--variable=prefix gimp-2.0"); return pkg_config ("--variable=prefix gimp-2.0");
@ -268,7 +271,7 @@ find_out_env_flags (void)
static void static void
usage (int exit_status) usage (int exit_status)
{ {
printf ("\ g_print ("\
Usage: gimptool-2.0 [OPTION]...\n\ Usage: gimptool-2.0 [OPTION]...\n\
\n\ \n\
General options:\n\ General options:\n\
@ -318,7 +321,7 @@ appended with -noui for appropriate settings. For plug-ins that use GTK+ but\n\
not libgumpui, append -nogimpui.\n"); not libgumpui, append -nogimpui.\n");
exit (exit_status); exit (exit_status);
} }
static gchar * static gchar *
get_includedir (void) get_includedir (void)
{ {
@ -328,7 +331,7 @@ get_includedir (void)
static void static void
do_includedir (void) do_includedir (void)
{ {
printf ("%s\n", get_includedir ()); g_print ("%s\n", get_includedir ());
} }
static gchar * static gchar *
@ -340,7 +343,7 @@ get_cflags (void)
static void static void
do_cflags (void) do_cflags (void)
{ {
printf ("%s\n", get_cflags ()); g_print ("%s\n", get_cflags ());
} }
static gchar * static gchar *
@ -352,7 +355,7 @@ get_cflags_noui (void)
static void static void
do_cflags_noui (void) do_cflags_noui (void)
{ {
printf ("%s\n", get_cflags_noui ()); g_print ("%s\n", get_cflags_noui ());
} }
static gchar * static gchar *
@ -364,7 +367,7 @@ get_cflags_nogimpui (void)
static void static void
do_cflags_nogimpui (void) do_cflags_nogimpui (void)
{ {
printf ("%s\n", get_cflags_nogimpui ()); g_print ("%s\n", get_cflags_nogimpui ());
} }
static gchar * static gchar *
@ -376,7 +379,7 @@ get_libs (void)
static void static void
do_libs (void) do_libs (void)
{ {
printf ("%s\n", get_libs ()); g_print ("%s\n", get_libs ());
} }
static gchar * static gchar *
@ -388,7 +391,7 @@ get_libs_noui (void)
static void static void
do_libs_noui (void) do_libs_noui (void)
{ {
printf ("%s\n", get_libs_noui ()); g_print ("%s\n", get_libs_noui ());
} }
static gchar * static gchar *
@ -400,14 +403,14 @@ get_libs_nogimpui (void)
static void static void
do_libs_nogimpui (void) do_libs_nogimpui (void)
{ {
printf ("%s\n", get_libs_nogimpui ()); g_print ("%s\n", get_libs_nogimpui ());
} }
static void static void
maybe_run (gchar *cmd) maybe_run (gchar *cmd)
{ {
if (!silent) if (!silent)
printf ("%s\n", cmd); g_print ("%s\n", cmd);
if (!dry_run) if (!dry_run)
system (cmd); system (cmd);
@ -425,7 +428,7 @@ do_build_2 (gchar *cflags,
gchar *dest_exe; gchar *dest_exe;
gchar *here_comes_linker_flags = ""; gchar *here_comes_linker_flags = "";
gchar *windows_subsystem_flag = ""; gchar *windows_subsystem_flag = "";
gchar *p, *q, *r; gchar *p, *q;
if (install_dir != NULL) if (install_dir != NULL)
dest_dir = g_strconcat (install_dir, "/", NULL); dest_dir = g_strconcat (install_dir, "/", NULL);
@ -435,24 +438,29 @@ do_build_2 (gchar *cflags,
dest_exe = g_strdup (what); dest_exe = g_strdup (what);
p = strrchr (dest_exe, '.'); p = strrchr (dest_exe, '.');
if (p == NULL || !(strcmp (p, ".c") == 0 || strcmp (p, ".cc") == 0 || strcmp (p, ".cpp") == 0)) if (p == NULL ||
!(strcmp (p, ".c") == 0 ||
strcmp (p, ".cc") == 0 ||
strcmp (p, ".cpp") == 0))
{ {
fprintf (stderr, "plug-in source %s is not a C or C++ file?\n", what); g_printerr ("plug-in source %s is not a C or C++ file?\n", what);
exit (1); exit (EXIT_FAILURE);
} }
*p = '\0'; *p = '\0';
q = strrchr (dest_exe, G_DIR_SEPARATOR); q = strrchr (dest_exe, G_DIR_SEPARATOR);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
r = strrchr (dest_exe, '/'); {
if (r != NULL && (q == NULL || r > q)) gchar *r = strrchr (dest_exe, '/');
q = r; if (r != NULL && (q == NULL || r > q))
q = r;
}
#endif #endif
if (q == NULL) if (q == NULL)
q = dest_exe; q = dest_exe;
else else
q++; q++;
dest_exe = g_strconcat (q, EXEEXT, NULL); dest_exe = g_strconcat (q, EXEEXT, NULL);
if (msvc_syntax) if (msvc_syntax)
@ -683,7 +691,7 @@ main (int argc,
gint i; gint i;
if (argc == 1) if (argc == 1)
usage (0); usage (EXIT_SUCCESS);
/* First scan for flags that affect our behaviour globally, but /* First scan for flags that affect our behaviour globally, but
* are still allowed late on the command line. * are still allowed late on the command line.
@ -695,21 +703,31 @@ main (int argc,
strcmp (argv[argi], "--just-print") == 0 || strcmp (argv[argi], "--just-print") == 0 ||
strcmp (argv[argi], "--dry-run") == 0 || strcmp (argv[argi], "--dry-run") == 0 ||
strcmp (argv[argi], "--recon") == 0) strcmp (argv[argi], "--recon") == 0)
dry_run = TRUE; {
dry_run = TRUE;
}
else if (strcmp (argv[argi], "--help") == 0) else if (strcmp (argv[argi], "--help") == 0)
usage (0); {
usage (EXIT_SUCCESS);
}
else if (g_str_has_prefix (argv[argi], "--prefix=")) else if (g_str_has_prefix (argv[argi], "--prefix="))
prefix = argv[argi] + strlen ("--prefix="); {
prefix = argv[argi] + strlen ("--prefix=");
}
else if (g_str_has_prefix (argv[argi], "--exec-prefix=")) else if (g_str_has_prefix (argv[argi], "--exec-prefix="))
exec_prefix = argv[argi] + strlen ("--exec_prefix="); {
exec_prefix = argv[argi] + strlen ("--exec_prefix=");
}
else if (strcmp (argv[argi], "--msvc-syntax") == 0) else if (strcmp (argv[argi], "--msvc-syntax") == 0)
msvc_syntax = TRUE; {
msvc_syntax = TRUE;
}
} }
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
if (msvc_syntax) if (msvc_syntax)
{ {
fprintf (stderr, "Ignoring --msvc-syntax\n"); g_printerr ("Ignoring --msvc-syntax\n");
msvc_syntax = FALSE; msvc_syntax = FALSE;
} }
#endif #endif
@ -721,17 +739,26 @@ main (int argc,
while (++argi < argc) while (++argi < argc)
{ {
for (i = 0; i < G_N_ELEMENTS (dirs); i++) for (i = 0; i < G_N_ELEMENTS (dirs); i++)
if (strcmp (argv[argi], g_strconcat ("--", dirs[i].option, NULL)) == 0) {
break; if (strcmp (argv[argi],
g_strconcat ("--", dirs[i].option, NULL)) == 0)
break;
}
if (i < G_N_ELEMENTS (dirs)) if (i < G_N_ELEMENTS (dirs))
printf ("%s\n", expand_and_munge (dirs[i].value)); {
g_print ("%s\n", expand_and_munge (dirs[i].value));
}
else if (strcmp (argv[argi], "--quiet") == 0 || else if (strcmp (argv[argi], "--quiet") == 0 ||
strcmp (argv[argi], "--silent") == 0) strcmp (argv[argi], "--silent") == 0)
silent = TRUE; {
silent = TRUE;
}
else if (strcmp (argv[argi], "--version") == 0) else if (strcmp (argv[argi], "--version") == 0)
{ {
printf ("%d.%d.%d\n", GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION); g_print ("%d.%d.%d\n",
exit (0); GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION);
exit (EXIT_SUCCESS);
} }
else if (strcmp (argv[argi], "-n") == 0 || else if (strcmp (argv[argi], "-n") == 0 ||
strcmp (argv[argi], "--just-print") == 0 || strcmp (argv[argi], "--just-print") == 0 ||
@ -794,11 +821,12 @@ main (int argc,
do_uninstall_admin_script (argv[++argi]); do_uninstall_admin_script (argv[++argi]);
else else
{ {
fprintf (stderr, "Unrecognized switch %s\n", argv[argi]); g_printerr ("Unrecognized switch %s\n", argv[argi]);
usage (1); usage (EXIT_FAILURE);
} }
} }
exit (0);
exit (EXIT_SUCCESS);
} }
/* /*
* Local Variables: * Local Variables: