1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
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.
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.
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.
21
#include <glib/gstdio.h>
25
#ifdef HAVE_GLIBC_REGEX
28
#include "regexrepl/regex.h"
31
#include <glib-object.h>
33
#include "libgimpbase/gimpbase.h"
35
#include "pdb-types.h"
37
#include "core/gimpparamspecs-desc.h"
40
#include "gimppdb-query.h"
41
#include "gimp-pdb-compat.h"
42
#include "gimpprocedure.h"
44
#include "gimp-intl.h"
47
#define PDB_REGCOMP_FLAGS REG_ICASE
49
#define COMPAT_BLURB "This procedure is deprecated! Use '%s' instead."
52
typedef struct _PDBDump PDBDump;
59
gboolean dumping_compat;
62
typedef struct _PDBQuery PDBQuery;
72
regex_t copyright_regex;
74
regex_t proc_type_regex;
76
gchar **list_of_procs;
78
gboolean querying_compat;
81
typedef struct _PDBStrings PDBStrings;
95
/* local function prototypes */
97
static void gimp_pdb_query_entry (gpointer key,
100
static void gimp_pdb_print_entry (gpointer key,
103
static void gimp_pdb_get_strings (PDBStrings *strings,
104
GimpProcedure *procedure,
106
static void gimp_pdb_free_strings (PDBStrings *strings);
109
/* public functions */
112
gimp_pdb_dump (GimpPDB *pdb,
113
const gchar *filename)
117
g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
118
g_return_val_if_fail (filename != NULL, FALSE);
121
pdb_dump.file = g_fopen (filename, "w");
126
pdb_dump.dumping_compat = FALSE;
128
g_hash_table_foreach (pdb->procedures,
129
gimp_pdb_print_entry,
132
pdb_dump.dumping_compat = TRUE;
134
g_hash_table_foreach (pdb->compat_proc_names,
135
gimp_pdb_print_entry,
138
fclose (pdb_dump.file);
144
gimp_pdb_query (GimpPDB *pdb,
149
const gchar *copyright,
151
const gchar *proc_type,
156
gboolean success = FALSE;
158
g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
159
g_return_val_if_fail (name != NULL, FALSE);
160
g_return_val_if_fail (blurb != NULL, FALSE);
161
g_return_val_if_fail (help != NULL, FALSE);
162
g_return_val_if_fail (author != NULL, FALSE);
163
g_return_val_if_fail (copyright != NULL, FALSE);
164
g_return_val_if_fail (date != NULL, FALSE);
165
g_return_val_if_fail (proc_type != NULL, FALSE);
166
g_return_val_if_fail (num_procs != NULL, FALSE);
167
g_return_val_if_fail (procs != NULL, FALSE);
172
if (regcomp (&pdb_query.name_regex, name, PDB_REGCOMP_FLAGS))
174
if (regcomp (&pdb_query.blurb_regex, blurb, PDB_REGCOMP_FLAGS))
176
if (regcomp (&pdb_query.help_regex, help, PDB_REGCOMP_FLAGS))
178
if (regcomp (&pdb_query.author_regex, author, PDB_REGCOMP_FLAGS))
180
if (regcomp (&pdb_query.copyright_regex, copyright, PDB_REGCOMP_FLAGS))
182
if (regcomp (&pdb_query.date_regex, date, PDB_REGCOMP_FLAGS))
184
if (regcomp (&pdb_query.proc_type_regex, proc_type, PDB_REGCOMP_FLAGS))
190
pdb_query.list_of_procs = NULL;
191
pdb_query.num_procs = 0;
192
pdb_query.querying_compat = FALSE;
194
g_hash_table_foreach (pdb->procedures,
195
gimp_pdb_query_entry, &pdb_query);
197
pdb_query.querying_compat = TRUE;
199
g_hash_table_foreach (pdb->compat_proc_names,
200
gimp_pdb_query_entry, &pdb_query);
203
regfree (&pdb_query.proc_type_regex);
205
regfree (&pdb_query.date_regex);
207
regfree (&pdb_query.copyright_regex);
209
regfree (&pdb_query.author_regex);
211
regfree (&pdb_query.help_regex);
213
regfree (&pdb_query.blurb_regex);
215
regfree (&pdb_query.name_regex);
219
*num_procs = pdb_query.num_procs;
220
*procs = pdb_query.list_of_procs;
227
gimp_pdb_proc_info (GimpPDB *pdb,
228
const gchar *proc_name,
234
GimpPDBProcType *proc_type,
238
GimpProcedure *procedure;
241
g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
242
g_return_val_if_fail (proc_name != NULL, FALSE);
244
procedure = gimp_pdb_lookup_procedure (pdb, proc_name);
248
gimp_pdb_get_strings (&strings, procedure, FALSE);
252
const gchar *compat_name;
254
compat_name = gimp_pdb_lookup_compat_proc_name (pdb, proc_name);
258
procedure = gimp_pdb_lookup_procedure (pdb, compat_name);
261
gimp_pdb_get_strings (&strings, procedure, TRUE);
267
*blurb = strings.compat ? strings.blurb : g_strdup (strings.blurb);
268
*help = strings.compat ? strings.help : g_strdup (strings.help);
269
*author = strings.compat ? strings.author : g_strdup (strings.author);
270
*copyright = strings.compat ? strings.copyright : g_strdup (strings.copyright);
271
*date = strings.compat ? strings.date : g_strdup (strings.date);
272
*proc_type = procedure->proc_type;
273
*num_args = procedure->num_args;
274
*num_values = procedure->num_values;
283
/* private functions */
286
match_strings (regex_t *preg,
292
return regexec (preg, a, 0, NULL, 0);
296
gimp_pdb_query_entry (gpointer key,
300
PDBQuery *pdb_query = user_data;
302
GimpProcedure *procedure;
303
const gchar *proc_name;
305
GEnumClass *enum_class;
306
GimpEnumDesc *type_desc;
310
if (pdb_query->querying_compat)
311
list = g_hash_table_lookup (pdb_query->pdb->procedures, value);
318
procedure = list->data;
320
gimp_pdb_get_strings (&strings, procedure, pdb_query->querying_compat);
322
enum_class = g_type_class_ref (GIMP_TYPE_PDB_PROC_TYPE);
323
type_desc = gimp_enum_get_desc (enum_class, procedure->proc_type);
324
g_type_class_unref (enum_class);
326
if (! match_strings (&pdb_query->name_regex, proc_name) &&
327
! match_strings (&pdb_query->blurb_regex, strings.blurb) &&
328
! match_strings (&pdb_query->help_regex, strings.help) &&
329
! match_strings (&pdb_query->author_regex, strings.author) &&
330
! match_strings (&pdb_query->copyright_regex, strings.copyright) &&
331
! match_strings (&pdb_query->date_regex, strings.date) &&
332
! match_strings (&pdb_query->proc_type_regex, type_desc->value_desc))
334
pdb_query->num_procs++;
335
pdb_query->list_of_procs = g_renew (gchar *, pdb_query->list_of_procs,
336
pdb_query->num_procs);
337
pdb_query->list_of_procs[pdb_query->num_procs - 1] = g_strdup (proc_name);
340
gimp_pdb_free_strings (&strings);
343
/* #define DEBUG_OUTPUT 1 */
346
output_string (FILE *file,
350
if (fprintf (file, "\"") < 0)
359
case '\\' : if (fprintf (file, "\\\\") < 0) return FALSE; break;
360
case '\"' : if (fprintf (file, "\\\"") < 0) return FALSE; break;
361
case '{' : if (fprintf (file, "@{") < 0) return FALSE; break;
362
case '@' : if (fprintf (file, "@@") < 0) return FALSE; break;
363
case '}' : if (fprintf (file, "@}") < 0) return FALSE; break;
366
if (fprintf (file, "%c", *string) < 0)
373
if (fprintf (file, "\"\n") < 0)
381
gimp_pdb_print_entry (gpointer key,
385
PDBDump *pdb_dump = user_data;
386
FILE *file = pdb_dump->file;
387
const gchar *proc_name;
389
GEnumClass *arg_class;
390
GEnumClass *proc_class;
396
if (pdb_dump->dumping_compat)
397
list = g_hash_table_lookup (pdb_dump->pdb->procedures, value);
401
arg_class = g_type_class_ref (GIMP_TYPE_PDB_ARG_TYPE);
402
proc_class = g_type_class_ref (GIMP_TYPE_PDB_PROC_TYPE);
404
buf = g_string_new ("");
406
for (; list; list = list->next)
408
GimpProcedure *procedure = list->data;
410
GEnumValue *arg_value;
411
GimpEnumDesc *type_desc;
416
gimp_pdb_get_strings (&strings, procedure, pdb_dump->dumping_compat);
421
fprintf (file, "(register-procedure ");
426
g_string_printf (buf, "%s <%d>", proc_name, num);
427
output_string (file, buf->str);
431
output_string (file, proc_name);
434
type_desc = gimp_enum_get_desc (proc_class, procedure->proc_type);
438
fprintf (file, " (");
440
for (i = 0; i < procedure->num_args; i++)
442
GParamSpec *pspec = procedure->args[i];
443
GimpPDBArgType arg_type;
445
arg_type = gimp_pdb_compat_arg_type_from_gtype (pspec->value_type);
447
arg_value = g_enum_get_value (arg_class, arg_type);
452
output_string (file, arg_value->value_name);
455
fprintf (file, ") (");
457
for (i = 0; i < procedure->num_values; i++)
459
GParamSpec *pspec = procedure->values[i];
460
GimpPDBArgType arg_type;
462
arg_type = gimp_pdb_compat_arg_type_from_gtype (pspec->value_type);
464
arg_value = g_enum_get_value (arg_class, arg_type);
469
output_string (file, arg_value->value_name);
471
fprintf (file, "))\n");
473
#else /* ! DEBUG_OUTPUT */
476
output_string (file, strings.blurb);
478
output_string (file, strings.help);
480
output_string (file, strings.author);
482
output_string (file, strings.copyright);
484
output_string (file, strings.date);
486
output_string (file, type_desc->value_desc);
488
fprintf (file, " (");
489
for (i = 0; i < procedure->num_args; i++)
491
GParamSpec *pspec = procedure->args[i];
492
GimpPDBArgType arg_type;
493
gchar *desc = gimp_param_spec_get_desc (pspec);
495
fprintf (file, "\n (\n");
497
arg_type = gimp_pdb_compat_arg_type_from_gtype (pspec->value_type);
499
arg_value = g_enum_get_value (arg_class, arg_type);
502
output_string (file, g_param_spec_get_name (pspec));
504
output_string (file, arg_value->value_name);
506
output_string (file, desc);
509
fprintf (file, " )");
511
fprintf (file, "\n )\n");
513
fprintf (file, " (");
514
for (i = 0; i < procedure->num_values; i++)
516
GParamSpec *pspec = procedure->values[i];
517
GimpPDBArgType arg_type;
518
gchar *desc = gimp_param_spec_get_desc (pspec);
520
fprintf (file, "\n (\n");
522
arg_type = gimp_pdb_compat_arg_type_from_gtype (pspec->value_type);
524
arg_value = g_enum_get_value (arg_class, arg_type);
527
output_string (file, g_param_spec_get_name (pspec));
529
output_string (file, arg_value->value_name);
531
output_string (file, desc);
534
fprintf (file, " )");
536
fprintf (file, "\n )");
537
fprintf (file, "\n)\n");
539
#endif /* DEBUG_OUTPUT */
541
gimp_pdb_free_strings (&strings);
544
g_string_free (buf, TRUE);
546
g_type_class_unref (arg_class);
547
g_type_class_unref (proc_class);
551
gimp_pdb_get_strings (PDBStrings *strings,
552
GimpProcedure *procedure,
555
strings->compat = compat;
559
strings->blurb = g_strdup_printf (COMPAT_BLURB,
560
GIMP_OBJECT (procedure)->name);
561
strings->help = g_strdup (strings->blurb);
562
strings->author = NULL;
563
strings->copyright = NULL;
564
strings->date = NULL;
568
strings->blurb = procedure->blurb;
569
strings->help = procedure->help;
570
strings->author = procedure->author;
571
strings->copyright = procedure->copyright;
572
strings->date = procedure->date;
577
gimp_pdb_free_strings (PDBStrings *strings)
581
g_free (strings->blurb);
582
g_free (strings->help);