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>
* app/base/base-utils.[ch]: changed to get_physical_memory_size()

View File

@ -1,5 +1,5 @@
/* 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
* it under the terms of the GNU General Public License as published by
@ -35,6 +35,7 @@
#include "libgimpbase/gimpversion.h"
static gboolean silent = FALSE;
static gboolean dry_run = FALSE;
static gchar *prefix;
@ -46,6 +47,7 @@ static gchar *env_cflags;
static gchar *env_ldflags;
static gchar *env_libs;
#ifdef G_OS_WIN32
#define EXEEXT ".exe"
#else
@ -61,7 +63,7 @@ static gchar *env_libs;
#endif
static struct {
gchar *option;
const gchar *option;
gchar *value;
} dirs[] = {
{ "prefix", PREFIX },
@ -116,12 +118,12 @@ one_line_output (gchar *program,
{
gchar *command = g_strconcat (program, " ", args, NULL);
FILE *pipe = popen (command, "r");
char line[1000];
gchar line[1000];
if (pipe == NULL)
{
fprintf (stderr, "Cannot run '%s'\n", command);
exit (1);
g_printerr ("Cannot run '%s'\n", command);
exit (EXIT_FAILURE);
}
if (fgets (line, sizeof (line), pipe) == NULL)
@ -136,8 +138,8 @@ one_line_output (gchar *program,
if (strlen (line) == 0)
{
fprintf (stderr, "No output from '%s'\n", command);
exit (1);
g_printerr ("No output from '%s'\n", command);
exit (EXIT_FAILURE);
}
return g_strdup (line);
@ -164,7 +166,7 @@ get_runtime_prefix (gchar slash)
*/
gchar *path;
char *p, *r;
gchar *p, *r;
path = g_find_program_in_path ("gimp-" GIMP_APP_VERSION ".exe");
@ -193,8 +195,9 @@ get_runtime_prefix (gchar slash)
}
}
fprintf (stderr, "Cannot determine GIMP " GIMP_APP_VERSION " installation location\n");
exit (1);
g_printerr ("Cannot determine GIMP " GIMP_APP_VERSION " installation location\n");
exit (EXIT_FAILURE);
#else
/* On Unix assume the executable package is in the same prefix as the developer stuff */
return pkg_config ("--variable=prefix gimp-2.0");
@ -268,7 +271,7 @@ find_out_env_flags (void)
static void
usage (int exit_status)
{
printf ("\
g_print ("\
Usage: gimptool-2.0 [OPTION]...\n\
\n\
General options:\n\
@ -328,7 +331,7 @@ get_includedir (void)
static void
do_includedir (void)
{
printf ("%s\n", get_includedir ());
g_print ("%s\n", get_includedir ());
}
static gchar *
@ -340,7 +343,7 @@ get_cflags (void)
static void
do_cflags (void)
{
printf ("%s\n", get_cflags ());
g_print ("%s\n", get_cflags ());
}
static gchar *
@ -352,7 +355,7 @@ get_cflags_noui (void)
static void
do_cflags_noui (void)
{
printf ("%s\n", get_cflags_noui ());
g_print ("%s\n", get_cflags_noui ());
}
static gchar *
@ -364,7 +367,7 @@ get_cflags_nogimpui (void)
static void
do_cflags_nogimpui (void)
{
printf ("%s\n", get_cflags_nogimpui ());
g_print ("%s\n", get_cflags_nogimpui ());
}
static gchar *
@ -376,7 +379,7 @@ get_libs (void)
static void
do_libs (void)
{
printf ("%s\n", get_libs ());
g_print ("%s\n", get_libs ());
}
static gchar *
@ -388,7 +391,7 @@ get_libs_noui (void)
static void
do_libs_noui (void)
{
printf ("%s\n", get_libs_noui ());
g_print ("%s\n", get_libs_noui ());
}
static gchar *
@ -400,14 +403,14 @@ get_libs_nogimpui (void)
static void
do_libs_nogimpui (void)
{
printf ("%s\n", get_libs_nogimpui ());
g_print ("%s\n", get_libs_nogimpui ());
}
static void
maybe_run (gchar *cmd)
{
if (!silent)
printf ("%s\n", cmd);
g_print ("%s\n", cmd);
if (!dry_run)
system (cmd);
@ -425,7 +428,7 @@ do_build_2 (gchar *cflags,
gchar *dest_exe;
gchar *here_comes_linker_flags = "";
gchar *windows_subsystem_flag = "";
gchar *p, *q, *r;
gchar *p, *q;
if (install_dir != NULL)
dest_dir = g_strconcat (install_dir, "/", NULL);
@ -435,18 +438,23 @@ do_build_2 (gchar *cflags,
dest_exe = g_strdup (what);
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);
exit (1);
g_printerr ("plug-in source %s is not a C or C++ file?\n", what);
exit (EXIT_FAILURE);
}
*p = '\0';
q = strrchr (dest_exe, G_DIR_SEPARATOR);
#ifdef G_OS_WIN32
r = strrchr (dest_exe, '/');
{
gchar *r = strrchr (dest_exe, '/');
if (r != NULL && (q == NULL || r > q))
q = r;
}
#endif
if (q == NULL)
q = dest_exe;
@ -683,7 +691,7 @@ main (int argc,
gint i;
if (argc == 1)
usage (0);
usage (EXIT_SUCCESS);
/* First scan for flags that affect our behaviour globally, but
* are still allowed late on the command line.
@ -695,21 +703,31 @@ main (int argc,
strcmp (argv[argi], "--just-print") == 0 ||
strcmp (argv[argi], "--dry-run") == 0 ||
strcmp (argv[argi], "--recon") == 0)
{
dry_run = TRUE;
}
else if (strcmp (argv[argi], "--help") == 0)
usage (0);
{
usage (EXIT_SUCCESS);
}
else if (g_str_has_prefix (argv[argi], "--prefix="))
{
prefix = argv[argi] + strlen ("--prefix=");
}
else if (g_str_has_prefix (argv[argi], "--exec-prefix="))
{
exec_prefix = argv[argi] + strlen ("--exec_prefix=");
}
else if (strcmp (argv[argi], "--msvc-syntax") == 0)
{
msvc_syntax = TRUE;
}
}
#ifndef G_OS_WIN32
if (msvc_syntax)
{
fprintf (stderr, "Ignoring --msvc-syntax\n");
g_printerr ("Ignoring --msvc-syntax\n");
msvc_syntax = FALSE;
}
#endif
@ -721,17 +739,26 @@ main (int argc,
while (++argi < argc)
{
for (i = 0; i < G_N_ELEMENTS (dirs); i++)
if (strcmp (argv[argi], g_strconcat ("--", dirs[i].option, NULL)) == 0)
{
if (strcmp (argv[argi],
g_strconcat ("--", dirs[i].option, NULL)) == 0)
break;
}
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 ||
strcmp (argv[argi], "--silent") == 0)
{
silent = TRUE;
}
else if (strcmp (argv[argi], "--version") == 0)
{
printf ("%d.%d.%d\n", GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION);
exit (0);
g_print ("%d.%d.%d\n",
GIMP_MAJOR_VERSION, GIMP_MINOR_VERSION, GIMP_MICRO_VERSION);
exit (EXIT_SUCCESS);
}
else if (strcmp (argv[argi], "-n") == 0 ||
strcmp (argv[argi], "--just-print") == 0 ||
@ -794,11 +821,12 @@ main (int argc,
do_uninstall_admin_script (argv[++argi]);
else
{
fprintf (stderr, "Unrecognized switch %s\n", argv[argi]);
usage (1);
g_printerr ("Unrecognized switch %s\n", argv[argi]);
usage (EXIT_FAILURE);
}
}
exit (0);
exit (EXIT_SUCCESS);
}
/*
* Local Variables: