~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/pdb/procedural_db_cmds.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995-2003 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
/* NOTE: This file is autogenerated by pdbgen.pl. */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
#include <string.h>
 
26
 
 
27
#include <glib-object.h>
 
28
 
 
29
#include "pdb-types.h"
 
30
#include "procedural_db.h"
 
31
 
 
32
#include "core/gimp.h"
 
33
#include "gimp-intl.h"
 
34
 
 
35
#ifdef HAVE_GLIBC_REGEX
 
36
#include <regex.h>
 
37
#else
 
38
#include "regexrepl/regex.h"
 
39
#endif
 
40
 
 
41
#define COMPAT_BLURB "This procedure is deprecated! Use '%s' instead."
 
42
 
 
43
 
 
44
/*  Query structure  */
 
45
typedef struct _PDBQuery PDBQuery;
 
46
 
 
47
struct _PDBQuery
 
48
{
 
49
  Gimp     *gimp;
 
50
 
 
51
  regex_t   name_regex;
 
52
  regex_t   blurb_regex;
 
53
  regex_t   help_regex;
 
54
  regex_t   author_regex;
 
55
  regex_t   copyright_regex;
 
56
  regex_t   date_regex;
 
57
  regex_t   proc_type_regex;
 
58
 
 
59
  gchar   **list_of_procs;
 
60
  gint      num_procs;
 
61
  gboolean  querying_compat;
 
62
};
 
63
 
 
64
 
 
65
typedef struct _PDBStrings PDBStrings;
 
66
 
 
67
struct _PDBStrings
 
68
{
 
69
  gboolean  compat;
 
70
 
 
71
  gchar    *blurb;
 
72
  gchar    *help;
 
73
  gchar    *author;
 
74
  gchar    *copyright;
 
75
  gchar    *date;
 
76
};
 
77
 
 
78
static gchar *proc_type_str[] =
 
79
{
 
80
  N_("Internal GIMP procedure"),
 
81
  N_("GIMP Plug-In"),
 
82
  N_("GIMP Extension"),
 
83
  N_("Temporary Procedure")
 
84
};
 
85
 
 
86
static const gchar * const type_str[] =
 
87
{
 
88
  "GIMP_PDB_INT32",
 
89
  "GIMP_PDB_INT16",
 
90
  "GIMP_PDB_INT8",
 
91
  "GIMP_PDB_FLOAT",
 
92
  "GIMP_PDB_STRING",
 
93
  "GIMP_PDB_INT32ARRAY",
 
94
  "GIMP_PDB_INT16ARRAY",
 
95
  "GIMP_PDB_INT8ARRAY",
 
96
  "GIMP_PDB_FLOATARRAY",
 
97
  "GIMP_PDB_STRINGARRAY",
 
98
  "GIMP_PDB_COLOR",
 
99
  "GIMP_PDB_REGION",
 
100
  "GIMP_PDB_DISPLAY",
 
101
  "GIMP_PDB_IMAGE",
 
102
  "GIMP_PDB_LAYER",
 
103
  "GIMP_PDB_CHANNEL",
 
104
  "GIMP_PDB_DRAWABLE",
 
105
  "GIMP_PDB_SELECTION",
 
106
  "GIMP_PDB_BOUNDARY",
 
107
  "GIMP_PDB_PATH",
 
108
  "GIMP_PDB_PARASITE",
 
109
  "GIMP_PDB_STATUS",
 
110
  "GIMP_PDB_END"
 
111
};
 
112
 
 
113
static ProcRecord procedural_db_temp_name_proc;
 
114
static ProcRecord procedural_db_dump_proc;
 
115
static ProcRecord procedural_db_query_proc;
 
116
static ProcRecord procedural_db_proc_info_proc;
 
117
static ProcRecord procedural_db_proc_arg_proc;
 
118
static ProcRecord procedural_db_proc_val_proc;
 
119
static ProcRecord procedural_db_get_data_proc;
 
120
static ProcRecord procedural_db_get_data_size_proc;
 
121
static ProcRecord procedural_db_set_data_proc;
 
122
 
 
123
void
 
124
register_procedural_db_procs (Gimp *gimp)
 
125
{
 
126
  procedural_db_register (gimp, &procedural_db_temp_name_proc);
 
127
  procedural_db_register (gimp, &procedural_db_dump_proc);
 
128
  procedural_db_register (gimp, &procedural_db_query_proc);
 
129
  procedural_db_register (gimp, &procedural_db_proc_info_proc);
 
130
  procedural_db_register (gimp, &procedural_db_proc_arg_proc);
 
131
  procedural_db_register (gimp, &procedural_db_proc_val_proc);
 
132
  procedural_db_register (gimp, &procedural_db_get_data_proc);
 
133
  procedural_db_register (gimp, &procedural_db_get_data_size_proc);
 
134
  procedural_db_register (gimp, &procedural_db_set_data_proc);
 
135
}
 
136
 
 
137
static int
 
138
match_strings (regex_t     *preg,
 
139
               const gchar *a)
 
140
{
 
141
  if (!a)
 
142
    a = "";
 
143
 
 
144
  return regexec (preg, a, 0, NULL, 0);
 
145
}
 
146
 
 
147
static void
 
148
get_pdb_strings (PDBStrings *strings,
 
149
                 ProcRecord *proc,
 
150
                 gboolean    compat)
 
151
{
 
152
  strings->compat = compat;
 
153
 
 
154
  if (compat)
 
155
    {
 
156
      strings->blurb     = g_strdup_printf (COMPAT_BLURB, proc->name);
 
157
      strings->help      = g_strdup (strings->blurb);
 
158
      strings->author    = NULL;
 
159
      strings->copyright = NULL;
 
160
      strings->date      = NULL;
 
161
    }
 
162
  else
 
163
    {
 
164
      strings->blurb     = proc->blurb;
 
165
      strings->help      = proc->help;
 
166
      strings->author    = proc->author;
 
167
      strings->copyright = proc->copyright;
 
168
      strings->date      = proc->date;
 
169
    }
 
170
}
 
171
 
 
172
static void
 
173
procedural_db_query_entry (gpointer key,
 
174
                           gpointer value,
 
175
                           gpointer user_data)
 
176
{
 
177
  PDBQuery    *pdb_query = user_data;
 
178
  GList       *list;
 
179
  ProcRecord  *proc;
 
180
  const gchar *proc_name;
 
181
  PDBStrings   strings;
 
182
 
 
183
  proc_name = key;
 
184
 
 
185
  if (pdb_query->querying_compat)
 
186
    list = g_hash_table_lookup (pdb_query->gimp->procedural_ht, value);
 
187
  else
 
188
    list = value;
 
189
 
 
190
  if (! list)
 
191
    return;
 
192
 
 
193
  proc = (ProcRecord *) list->data;
 
194
 
 
195
  get_pdb_strings (&strings, proc, pdb_query->querying_compat);
 
196
 
 
197
  if (! match_strings (&pdb_query->name_regex,      proc_name)         &&
 
198
      ! match_strings (&pdb_query->blurb_regex,     strings.blurb)     &&
 
199
      ! match_strings (&pdb_query->help_regex,      strings.help)      &&
 
200
      ! match_strings (&pdb_query->author_regex,    strings.author)    &&
 
201
      ! match_strings (&pdb_query->copyright_regex, strings.copyright) &&
 
202
      ! match_strings (&pdb_query->date_regex,      strings.date)      &&
 
203
      ! match_strings (&pdb_query->proc_type_regex,
 
204
                       proc_type_str[(gint) proc->proc_type]))
 
205
    {
 
206
      pdb_query->num_procs++;
 
207
      pdb_query->list_of_procs = g_renew (gchar *, pdb_query->list_of_procs,
 
208
                                          pdb_query->num_procs);
 
209
      pdb_query->list_of_procs[pdb_query->num_procs - 1] = g_strdup (proc_name);
 
210
    }
 
211
 
 
212
  if (strings.compat)
 
213
    {
 
214
      g_free (strings.blurb);
 
215
      g_free (strings.help);
 
216
    }
 
217
}
 
218
 
 
219
static gboolean
 
220
output_string (FILE        *file,
 
221
               const gchar *string)
 
222
{
 
223
  if (fprintf (file, "\"") < 0)
 
224
    return FALSE;
 
225
 
 
226
  if (string)
 
227
    while (*string)
 
228
      {
 
229
        switch (*string)
 
230
          {
 
231
          case '\\' : if (fprintf (file, "\\\\") < 0) return FALSE; break;
 
232
          case '\"' : if (fprintf (file, "\\\"") < 0) return FALSE; break;
 
233
          case '{'  : if (fprintf (file, "@{")   < 0) return FALSE; break;
 
234
          case '@'  : if (fprintf (file, "@@")   < 0) return FALSE; break;
 
235
          case '}'  : if (fprintf (file, "@}")   < 0) return FALSE; break;
 
236
 
 
237
          default:
 
238
            if (fprintf (file, "%c", *string) < 0)
 
239
              return FALSE;
 
240
          }
 
241
        string++;
 
242
      }
 
243
 
 
244
  if (fprintf (file, "\"\n") < 0)
 
245
    return FALSE;
 
246
 
 
247
  return TRUE;
 
248
}
 
249
 
 
250
static void
 
251
procedural_db_print_entry (gpointer key,
 
252
                           gpointer value,
 
253
                           gpointer user_data)
 
254
{
 
255
  ProcRecord *procedure;
 
256
  GString    *buf;
 
257
  GList      *list;
 
258
  FILE       *file;
 
259
  gint        i;
 
260
  gint        num = 0;
 
261
 
 
262
  list = (GList *) value;
 
263
  file = (FILE *) user_data;
 
264
 
 
265
  buf = g_string_new ("");
 
266
 
 
267
  while (list)
 
268
    {
 
269
      num++;
 
270
      procedure = (ProcRecord*) list->data;
 
271
      list = list->next;
 
272
 
 
273
      fprintf (file, "\n(register-procedure ");
 
274
 
 
275
      if (list || num != 1)
 
276
        {
 
277
          g_string_printf (buf, "%s <%d>", procedure->name, num);
 
278
          output_string (file, buf->str);
 
279
        }
 
280
      else
 
281
        output_string (file, procedure->name);
 
282
 
 
283
      output_string (file, procedure->blurb);
 
284
      output_string (file, procedure->help);
 
285
      output_string (file, procedure->author);
 
286
      output_string (file, procedure->copyright);
 
287
      output_string (file, procedure->date);
 
288
      output_string (file, proc_type_str[(int) procedure->proc_type]);
 
289
 
 
290
      fprintf (file, "( ");
 
291
      for (i = 0; i < procedure->num_args; i++)
 
292
        {
 
293
          fprintf (file, "( ");
 
294
 
 
295
          output_string (file, procedure->args[i].name );
 
296
          output_string (file, type_str[procedure->args[i].arg_type]);
 
297
          output_string (file, procedure->args[i].description);
 
298
 
 
299
          fprintf (file, " ) ");
 
300
        }
 
301
      fprintf (file, " ) ");
 
302
 
 
303
      fprintf (file, "( ");
 
304
      for (i = 0; i < procedure->num_values; i++)
 
305
        {
 
306
          fprintf (file, "( ");
 
307
          output_string (file, procedure->values[i].name );
 
308
          output_string (file, type_str[procedure->values[i].arg_type]);
 
309
          output_string (file, procedure->values[i].description);
 
310
 
 
311
          fprintf (file, " ) ");
 
312
        }
 
313
      fprintf (file, " ) ");
 
314
      fprintf (file, " ) ");
 
315
    }
 
316
 
 
317
  g_string_free (buf, TRUE);
 
318
}
 
319
 
 
320
/* This really doesn't belong here, but it depends on our generated type_str
 
321
 * array.
 
322
 */
 
323
const char *
 
324
pdb_type_name (gint type)
 
325
{
 
326
  if (type >= 0 && type <= GIMP_PDB_END)
 
327
    return type_str[type];
 
328
  else
 
329
    return g_strdup_printf ("(PDB type %d unknown)", type);
 
330
   /* Yeah, we leak the memory.  But then you shouldn't try and
 
331
    * get the name of a PDB type that doesn't exist, should you.
 
332
    */
 
333
}
 
334
 
 
335
static Argument *
 
336
procedural_db_temp_name_invoker (Gimp         *gimp,
 
337
                                 GimpContext  *context,
 
338
                                 GimpProgress *progress,
 
339
                                 Argument     *args)
 
340
{
 
341
  Argument *return_args;
 
342
  gchar *temp_name;
 
343
  static gint proc_number = 0;
 
344
 
 
345
  temp_name = g_strdup_printf ("temp_procedure_number_%d", proc_number++);
 
346
 
 
347
  return_args = procedural_db_return_args (&procedural_db_temp_name_proc, TRUE);
 
348
  return_args[1].value.pdb_pointer = temp_name;
 
349
 
 
350
  return return_args;
 
351
}
 
352
 
 
353
static ProcArg procedural_db_temp_name_outargs[] =
 
354
{
 
355
  {
 
356
    GIMP_PDB_STRING,
 
357
    "temp_name",
 
358
    "A unique temporary name for a temporary PDB entry"
 
359
  }
 
360
};
 
361
 
 
362
static ProcRecord procedural_db_temp_name_proc =
 
363
{
 
364
  "gimp_procedural_db_temp_name",
 
365
  "Generates a unique temporary PDB name.",
 
366
  "This procedure generates a temporary PDB entry name that is guaranteed to be unique. It is many used by the interactive popup dialogs to generate a PDB entry name.",
 
367
  "Andy Thomas",
 
368
  "Andy Thomas",
 
369
  "1998",
 
370
  NULL,
 
371
  GIMP_INTERNAL,
 
372
  0,
 
373
  NULL,
 
374
  1,
 
375
  procedural_db_temp_name_outargs,
 
376
  { { procedural_db_temp_name_invoker } }
 
377
};
 
378
 
 
379
static Argument *
 
380
procedural_db_dump_invoker (Gimp         *gimp,
 
381
                            GimpContext  *context,
 
382
                            GimpProgress *progress,
 
383
                            Argument     *args)
 
384
{
 
385
  gboolean success = TRUE;
 
386
  gchar *filename;
 
387
  FILE *file;
 
388
 
 
389
  filename = (gchar *) args[0].value.pdb_pointer;
 
390
  if (filename == NULL)
 
391
    success = FALSE;
 
392
 
 
393
  if (success)
 
394
    {
 
395
      if ((file = fopen (filename, "w")))
 
396
        {
 
397
          g_hash_table_foreach (gimp->procedural_ht,
 
398
                                procedural_db_print_entry, file);
 
399
          fclose (file);
 
400
        }
 
401
      else
 
402
        success = FALSE;
 
403
    }
 
404
 
 
405
  return procedural_db_return_args (&procedural_db_dump_proc, success);
 
406
}
 
407
 
 
408
static ProcArg procedural_db_dump_inargs[] =
 
409
{
 
410
  {
 
411
    GIMP_PDB_STRING,
 
412
    "filename",
 
413
    "The dump filename"
 
414
  }
 
415
};
 
416
 
 
417
static ProcRecord procedural_db_dump_proc =
 
418
{
 
419
  "gimp_procedural_db_dump",
 
420
  "Dumps the current contents of the procedural database",
 
421
  "This procedure dumps the contents of the procedural database to the specified file. The file will contain all of the information provided for each registered procedure. This file is in a format appropriate for use with the supplied \"pdb_self_doc.el\" Elisp script, which generates a texinfo document.",
 
422
  "Spencer Kimball & Josh MacDonald",
 
423
  "Spencer Kimball & Josh MacDonald & Peter Mattis",
 
424
  "1995-1996",
 
425
  NULL,
 
426
  GIMP_INTERNAL,
 
427
  1,
 
428
  procedural_db_dump_inargs,
 
429
  0,
 
430
  NULL,
 
431
  { { procedural_db_dump_invoker } }
 
432
};
 
433
 
 
434
static Argument *
 
435
procedural_db_query_invoker (Gimp         *gimp,
 
436
                             GimpContext  *context,
 
437
                             GimpProgress *progress,
 
438
                             Argument     *args)
 
439
{
 
440
  gboolean success = TRUE;
 
441
  Argument *return_args;
 
442
  gchar *name;
 
443
  gchar *blurb;
 
444
  gchar *help;
 
445
  gchar *author;
 
446
  gchar *copyright;
 
447
  gchar *date;
 
448
  gchar *proc_type;
 
449
  PDBQuery pdb_query;
 
450
 
 
451
  name = (gchar *) args[0].value.pdb_pointer;
 
452
  if (name == NULL)
 
453
    success = FALSE;
 
454
 
 
455
  blurb = (gchar *) args[1].value.pdb_pointer;
 
456
  if (blurb == NULL)
 
457
    success = FALSE;
 
458
 
 
459
  help = (gchar *) args[2].value.pdb_pointer;
 
460
  if (help == NULL)
 
461
    success = FALSE;
 
462
 
 
463
  author = (gchar *) args[3].value.pdb_pointer;
 
464
  if (author == NULL)
 
465
    success = FALSE;
 
466
 
 
467
  copyright = (gchar *) args[4].value.pdb_pointer;
 
468
  if (copyright == NULL)
 
469
    success = FALSE;
 
470
 
 
471
  date = (gchar *) args[5].value.pdb_pointer;
 
472
  if (date == NULL)
 
473
    success = FALSE;
 
474
 
 
475
  proc_type = (gchar *) args[6].value.pdb_pointer;
 
476
  if (proc_type == NULL)
 
477
    success = FALSE;
 
478
 
 
479
  if (success)
 
480
    {
 
481
      success = FALSE;
 
482
 
 
483
      if (regcomp (&pdb_query.name_regex, name, 0))
 
484
        goto free_name;
 
485
      if (regcomp (&pdb_query.blurb_regex, blurb, 0))
 
486
        goto free_blurb;
 
487
      if (regcomp (&pdb_query.help_regex, help, 0))
 
488
        goto free_help;
 
489
      if (regcomp (&pdb_query.author_regex, author, 0))
 
490
        goto free_author;
 
491
      if (regcomp (&pdb_query.copyright_regex, copyright, 0))
 
492
        goto free_copyright;
 
493
      if (regcomp (&pdb_query.date_regex, date, 0))
 
494
        goto free_date;
 
495
      if (regcomp (&pdb_query.proc_type_regex, proc_type, 0))
 
496
        goto free_proc_type;
 
497
 
 
498
      success = TRUE;
 
499
 
 
500
      pdb_query.gimp            = gimp;
 
501
      pdb_query.list_of_procs   = NULL;
 
502
      pdb_query.num_procs       = 0;
 
503
      pdb_query.querying_compat = FALSE;
 
504
 
 
505
      g_hash_table_foreach (gimp->procedural_ht,
 
506
                            procedural_db_query_entry, &pdb_query);
 
507
 
 
508
      pdb_query.querying_compat = TRUE;
 
509
 
 
510
      g_hash_table_foreach (gimp->procedural_compat_ht,
 
511
                            procedural_db_query_entry, &pdb_query);
 
512
 
 
513
      free_proc_type:
 
514
        regfree (&pdb_query.proc_type_regex);
 
515
      free_date:
 
516
        regfree (&pdb_query.date_regex);
 
517
      free_copyright:
 
518
        regfree (&pdb_query.copyright_regex);
 
519
      free_author:
 
520
        regfree (&pdb_query.author_regex);
 
521
      free_help:
 
522
        regfree (&pdb_query.help_regex);
 
523
      free_blurb:
 
524
        regfree (&pdb_query.blurb_regex);
 
525
      free_name:
 
526
        regfree (&pdb_query.name_regex);
 
527
    }
 
528
 
 
529
  return_args = procedural_db_return_args (&procedural_db_query_proc, success);
 
530
 
 
531
  if (success)
 
532
    {
 
533
      return_args[1].value.pdb_int = pdb_query.num_procs;
 
534
      return_args[2].value.pdb_pointer = pdb_query.list_of_procs;
 
535
    }
 
536
 
 
537
  return return_args;
 
538
}
 
539
 
 
540
static ProcArg procedural_db_query_inargs[] =
 
541
{
 
542
  {
 
543
    GIMP_PDB_STRING,
 
544
    "name",
 
545
    "The regex for procedure name"
 
546
  },
 
547
  {
 
548
    GIMP_PDB_STRING,
 
549
    "blurb",
 
550
    "The regex for procedure blurb"
 
551
  },
 
552
  {
 
553
    GIMP_PDB_STRING,
 
554
    "help",
 
555
    "The regex for procedure help"
 
556
  },
 
557
  {
 
558
    GIMP_PDB_STRING,
 
559
    "author",
 
560
    "The regex for procedure author"
 
561
  },
 
562
  {
 
563
    GIMP_PDB_STRING,
 
564
    "copyright",
 
565
    "The regex for procedure copyright"
 
566
  },
 
567
  {
 
568
    GIMP_PDB_STRING,
 
569
    "date",
 
570
    "The regex for procedure date"
 
571
  },
 
572
  {
 
573
    GIMP_PDB_STRING,
 
574
    "proc_type",
 
575
    "The regex for procedure type: { 'Internal GIMP procedure', 'GIMP Plug-in', 'GIMP Extension' }"
 
576
  }
 
577
};
 
578
 
 
579
static ProcArg procedural_db_query_outargs[] =
 
580
{
 
581
  {
 
582
    GIMP_PDB_INT32,
 
583
    "num_matches",
 
584
    "The number of matching procedures"
 
585
  },
 
586
  {
 
587
    GIMP_PDB_STRINGARRAY,
 
588
    "procedure_names",
 
589
    "The list of procedure names"
 
590
  }
 
591
};
 
592
 
 
593
static ProcRecord procedural_db_query_proc =
 
594
{
 
595
  "gimp_procedural_db_query",
 
596
  "Queries the procedural database for its contents using regular expression matching.",
 
597
  "This procedure queries the contents of the procedural database. It is supplied with seven arguments matching procedures on { name, blurb, help, author, copyright, date, procedure type}. This is accomplished using regular expression matching. For instance, to find all procedures with \"jpeg\" listed in the blurb, all seven arguments can be supplied as \".*\", except for the second, which can be supplied as \".*jpeg.*\". There are two return arguments for this procedure. The first is the number of procedures matching the query. The second is a concatenated list of procedure names corresponding to those matching the query. If no matching entries are found, then the returned string is NULL and the number of entries is 0.",
 
598
  "Spencer Kimball & Peter Mattis",
 
599
  "Spencer Kimball & Peter Mattis",
 
600
  "1995-1996",
 
601
  NULL,
 
602
  GIMP_INTERNAL,
 
603
  7,
 
604
  procedural_db_query_inargs,
 
605
  2,
 
606
  procedural_db_query_outargs,
 
607
  { { procedural_db_query_invoker } }
 
608
};
 
609
 
 
610
static Argument *
 
611
procedural_db_proc_info_invoker (Gimp         *gimp,
 
612
                                 GimpContext  *context,
 
613
                                 GimpProgress *progress,
 
614
                                 Argument     *args)
 
615
{
 
616
  gboolean success = TRUE;
 
617
  Argument *return_args;
 
618
  gchar *proc_name;
 
619
  PDBStrings strings;
 
620
  ProcRecord *proc = NULL;
 
621
 
 
622
  proc_name = (gchar *) args[0].value.pdb_pointer;
 
623
  if (proc_name == NULL || !g_utf8_validate (proc_name, -1, NULL))
 
624
    success = FALSE;
 
625
 
 
626
  if (success)
 
627
    {
 
628
      proc = procedural_db_lookup (gimp, proc_name);
 
629
 
 
630
      if (proc)
 
631
        {
 
632
          get_pdb_strings (&strings, proc, FALSE);
 
633
        }
 
634
      else
 
635
        {
 
636
          const gchar *compat_name;
 
637
 
 
638
          compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
 
639
 
 
640
          if (compat_name)
 
641
            {
 
642
              proc = procedural_db_lookup (gimp, compat_name);
 
643
 
 
644
              if (proc)
 
645
                get_pdb_strings (&strings, proc, TRUE);
 
646
            }
 
647
        }
 
648
 
 
649
      success = (proc != NULL);
 
650
    }
 
651
 
 
652
  return_args = procedural_db_return_args (&procedural_db_proc_info_proc, success);
 
653
 
 
654
  if (success)
 
655
    {
 
656
      return_args[1].value.pdb_pointer = strings.compat ? strings.blurb : g_strdup (strings.blurb);
 
657
      return_args[2].value.pdb_pointer = strings.compat ? strings.help : g_strdup (strings.help);
 
658
      return_args[3].value.pdb_pointer = strings.compat ? strings.author : g_strdup (strings.author);
 
659
      return_args[4].value.pdb_pointer = strings.compat ? strings.copyright : g_strdup (strings.copyright);
 
660
      return_args[5].value.pdb_pointer = strings.compat ? strings.date : g_strdup (strings.date);
 
661
      return_args[6].value.pdb_int = proc->proc_type;
 
662
      return_args[7].value.pdb_int = proc->num_args;
 
663
      return_args[8].value.pdb_int = proc->num_values;
 
664
    }
 
665
 
 
666
  return return_args;
 
667
}
 
668
 
 
669
static ProcArg procedural_db_proc_info_inargs[] =
 
670
{
 
671
  {
 
672
    GIMP_PDB_STRING,
 
673
    "procedure",
 
674
    "The procedure name"
 
675
  }
 
676
};
 
677
 
 
678
static ProcArg procedural_db_proc_info_outargs[] =
 
679
{
 
680
  {
 
681
    GIMP_PDB_STRING,
 
682
    "blurb",
 
683
    "A short blurb"
 
684
  },
 
685
  {
 
686
    GIMP_PDB_STRING,
 
687
    "help",
 
688
    "Detailed procedure help"
 
689
  },
 
690
  {
 
691
    GIMP_PDB_STRING,
 
692
    "author",
 
693
    "Author(s) of the procedure"
 
694
  },
 
695
  {
 
696
    GIMP_PDB_STRING,
 
697
    "copyright",
 
698
    "The copyright"
 
699
  },
 
700
  {
 
701
    GIMP_PDB_STRING,
 
702
    "date",
 
703
    "Copyright date"
 
704
  },
 
705
  {
 
706
    GIMP_PDB_INT32,
 
707
    "proc_type",
 
708
    "The procedure type: { GIMP_INTERNAL (0), GIMP_PLUGIN (1), GIMP_EXTENSION (2), GIMP_TEMPORARY (3) }"
 
709
  },
 
710
  {
 
711
    GIMP_PDB_INT32,
 
712
    "num_args",
 
713
    "The number of input arguments"
 
714
  },
 
715
  {
 
716
    GIMP_PDB_INT32,
 
717
    "num_values",
 
718
    "The number of return values"
 
719
  }
 
720
};
 
721
 
 
722
static ProcRecord procedural_db_proc_info_proc =
 
723
{
 
724
  "gimp_procedural_db_proc_info",
 
725
  "Queries the procedural database for information on the specified procedure.",
 
726
  "This procedure returns information on the specified procedure. A short blurb, detailed help, author(s), copyright information, procedure type, number of input, and number of return values are returned. For specific information on each input argument and return value, use the 'gimp_procedural_db_proc_arg' and 'gimp_procedural_db_proc_val' procedures.",
 
727
  "Spencer Kimball & Peter Mattis",
 
728
  "Spencer Kimball & Peter Mattis",
 
729
  "1997",
 
730
  NULL,
 
731
  GIMP_INTERNAL,
 
732
  1,
 
733
  procedural_db_proc_info_inargs,
 
734
  8,
 
735
  procedural_db_proc_info_outargs,
 
736
  { { procedural_db_proc_info_invoker } }
 
737
};
 
738
 
 
739
static Argument *
 
740
procedural_db_proc_arg_invoker (Gimp         *gimp,
 
741
                                GimpContext  *context,
 
742
                                GimpProgress *progress,
 
743
                                Argument     *args)
 
744
{
 
745
  gboolean success = TRUE;
 
746
  Argument *return_args;
 
747
  gchar *proc_name;
 
748
  gint32 arg_num;
 
749
  ProcRecord *proc;
 
750
  ProcArg *arg = NULL;
 
751
 
 
752
  proc_name = (gchar *) args[0].value.pdb_pointer;
 
753
  if (proc_name == NULL || !g_utf8_validate (proc_name, -1, NULL))
 
754
    success = FALSE;
 
755
 
 
756
  arg_num = args[1].value.pdb_int;
 
757
 
 
758
  if (success)
 
759
    {
 
760
      proc = procedural_db_lookup (gimp, proc_name);
 
761
 
 
762
      if (! proc)
 
763
        {
 
764
          const gchar *compat_name;
 
765
 
 
766
          compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
 
767
 
 
768
          if (compat_name)
 
769
            proc = procedural_db_lookup (gimp, compat_name);
 
770
        }
 
771
 
 
772
      if (proc && (arg_num >= 0 && arg_num < proc->num_args))
 
773
        arg = &proc->args[arg_num];
 
774
      else
 
775
        success = FALSE;
 
776
    }
 
777
 
 
778
  return_args = procedural_db_return_args (&procedural_db_proc_arg_proc, success);
 
779
 
 
780
  if (success)
 
781
    {
 
782
      return_args[1].value.pdb_int = arg->arg_type;
 
783
      return_args[2].value.pdb_pointer = g_strdup (arg->name);
 
784
      return_args[3].value.pdb_pointer = g_strdup (arg->description);
 
785
    }
 
786
 
 
787
  return return_args;
 
788
}
 
789
 
 
790
static ProcArg procedural_db_proc_arg_inargs[] =
 
791
{
 
792
  {
 
793
    GIMP_PDB_STRING,
 
794
    "procedure",
 
795
    "The procedure name"
 
796
  },
 
797
  {
 
798
    GIMP_PDB_INT32,
 
799
    "arg_num",
 
800
    "The argument number"
 
801
  }
 
802
};
 
803
 
 
804
static ProcArg procedural_db_proc_arg_outargs[] =
 
805
{
 
806
  {
 
807
    GIMP_PDB_INT32,
 
808
    "arg_type",
 
809
    "The type of argument { GIMP_PDB_INT32 (0), GIMP_PDB_INT16 (1), GIMP_PDB_INT8 (2), GIMP_PDB_FLOAT (3), GIMP_PDB_STRING (4), GIMP_PDB_INT32ARRAY (5), GIMP_PDB_INT16ARRAY (6), GIMP_PDB_INT8ARRAY (7), GIMP_PDB_FLOATARRAY (8), GIMP_PDB_STRINGARRAY (9), GIMP_PDB_COLOR (10), GIMP_PDB_REGION (11), GIMP_PDB_DISPLAY (12), GIMP_PDB_IMAGE (13), GIMP_PDB_LAYER (14), GIMP_PDB_CHANNEL (15), GIMP_PDB_DRAWABLE (16), GIMP_PDB_SELECTION (17), GIMP_PDB_BOUNDARY (18), GIMP_PDB_PATH (19), GIMP_PDB_PARASITE (20), GIMP_PDB_STATUS (21) }"
 
810
  },
 
811
  {
 
812
    GIMP_PDB_STRING,
 
813
    "arg_name",
 
814
    "The name of the argument"
 
815
  },
 
816
  {
 
817
    GIMP_PDB_STRING,
 
818
    "arg_desc",
 
819
    "A description of the argument"
 
820
  }
 
821
};
 
822
 
 
823
static ProcRecord procedural_db_proc_arg_proc =
 
824
{
 
825
  "gimp_procedural_db_proc_arg",
 
826
  "Queries the procedural database for information on the specified procedure's argument.",
 
827
  "This procedure returns information on the specified procedure's argument. The argument type, name, and a description are retrieved.",
 
828
  "Spencer Kimball & Peter Mattis",
 
829
  "Spencer Kimball & Peter Mattis",
 
830
  "1997",
 
831
  NULL,
 
832
  GIMP_INTERNAL,
 
833
  2,
 
834
  procedural_db_proc_arg_inargs,
 
835
  3,
 
836
  procedural_db_proc_arg_outargs,
 
837
  { { procedural_db_proc_arg_invoker } }
 
838
};
 
839
 
 
840
static Argument *
 
841
procedural_db_proc_val_invoker (Gimp         *gimp,
 
842
                                GimpContext  *context,
 
843
                                GimpProgress *progress,
 
844
                                Argument     *args)
 
845
{
 
846
  gboolean success = TRUE;
 
847
  Argument *return_args;
 
848
  gchar *proc_name;
 
849
  gint32 val_num;
 
850
  ProcRecord *proc;
 
851
  ProcArg *val = NULL;
 
852
 
 
853
  proc_name = (gchar *) args[0].value.pdb_pointer;
 
854
  if (proc_name == NULL || !g_utf8_validate (proc_name, -1, NULL))
 
855
    success = FALSE;
 
856
 
 
857
  val_num = args[1].value.pdb_int;
 
858
 
 
859
  if (success)
 
860
    {
 
861
      proc = procedural_db_lookup (gimp, proc_name);
 
862
 
 
863
      if (! proc)
 
864
        {
 
865
          const gchar *compat_name;
 
866
 
 
867
          compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
 
868
 
 
869
          if (compat_name)
 
870
            proc = procedural_db_lookup (gimp, compat_name);
 
871
        }
 
872
 
 
873
      if (proc && (val_num >= 0 && val_num < proc->num_values))
 
874
        val = &proc->values[val_num];
 
875
      else
 
876
        success = FALSE;
 
877
    }
 
878
 
 
879
  return_args = procedural_db_return_args (&procedural_db_proc_val_proc, success);
 
880
 
 
881
  if (success)
 
882
    {
 
883
      return_args[1].value.pdb_int = val->arg_type;
 
884
      return_args[2].value.pdb_pointer = g_strdup (val->name);
 
885
      return_args[3].value.pdb_pointer = g_strdup (val->description);
 
886
    }
 
887
 
 
888
  return return_args;
 
889
}
 
890
 
 
891
static ProcArg procedural_db_proc_val_inargs[] =
 
892
{
 
893
  {
 
894
    GIMP_PDB_STRING,
 
895
    "procedure",
 
896
    "The procedure name"
 
897
  },
 
898
  {
 
899
    GIMP_PDB_INT32,
 
900
    "val_num",
 
901
    "The return value number"
 
902
  }
 
903
};
 
904
 
 
905
static ProcArg procedural_db_proc_val_outargs[] =
 
906
{
 
907
  {
 
908
    GIMP_PDB_INT32,
 
909
    "val_type",
 
910
    "The type of return value { GIMP_PDB_INT32 (0), GIMP_PDB_INT16 (1), GIMP_PDB_INT8 (2), GIMP_PDB_FLOAT (3), GIMP_PDB_STRING (4), GIMP_PDB_INT32ARRAY (5), GIMP_PDB_INT16ARRAY (6), GIMP_PDB_INT8ARRAY (7), GIMP_PDB_FLOATARRAY (8), GIMP_PDB_STRINGARRAY (9), GIMP_PDB_COLOR (10), GIMP_PDB_REGION (11), GIMP_PDB_DISPLAY (12), GIMP_PDB_IMAGE (13), GIMP_PDB_LAYER (14), GIMP_PDB_CHANNEL (15), GIMP_PDB_DRAWABLE (16), GIMP_PDB_SELECTION (17), GIMP_PDB_BOUNDARY (18), GIMP_PDB_PATH (19), GIMP_PDB_PARASITE (20), GIMP_PDB_STATUS (21) }"
 
911
  },
 
912
  {
 
913
    GIMP_PDB_STRING,
 
914
    "val_name",
 
915
    "The name of the return value"
 
916
  },
 
917
  {
 
918
    GIMP_PDB_STRING,
 
919
    "val_desc",
 
920
    "A description of the return value"
 
921
  }
 
922
};
 
923
 
 
924
static ProcRecord procedural_db_proc_val_proc =
 
925
{
 
926
  "gimp_procedural_db_proc_val",
 
927
  "Queries the procedural database for information on the specified procedure's return value.",
 
928
  "This procedure returns information on the specified procedure's return value. The return value type, name, and a description are retrieved.",
 
929
  "Spencer Kimball & Peter Mattis",
 
930
  "Spencer Kimball & Peter Mattis",
 
931
  "1997",
 
932
  NULL,
 
933
  GIMP_INTERNAL,
 
934
  2,
 
935
  procedural_db_proc_val_inargs,
 
936
  3,
 
937
  procedural_db_proc_val_outargs,
 
938
  { { procedural_db_proc_val_invoker } }
 
939
};
 
940
 
 
941
static Argument *
 
942
procedural_db_get_data_invoker (Gimp         *gimp,
 
943
                                GimpContext  *context,
 
944
                                GimpProgress *progress,
 
945
                                Argument     *args)
 
946
{
 
947
  gboolean success = TRUE;
 
948
  Argument *return_args;
 
949
  gchar *identifier;
 
950
  gint32 bytes;
 
951
  guint8 *data_copy = NULL;
 
952
  const guint8 *data;
 
953
 
 
954
  identifier = (gchar *) args[0].value.pdb_pointer;
 
955
  if (identifier == NULL || !g_utf8_validate (identifier, -1, NULL))
 
956
    success = FALSE;
 
957
 
 
958
  if (success)
 
959
    {
 
960
      data = procedural_db_get_data (gimp, identifier, &bytes);
 
961
      success = (data != NULL);
 
962
 
 
963
      if (success)
 
964
        data_copy = g_memdup (data, bytes);
 
965
    }
 
966
 
 
967
  return_args = procedural_db_return_args (&procedural_db_get_data_proc, success);
 
968
 
 
969
  if (success)
 
970
    {
 
971
      return_args[1].value.pdb_int = bytes;
 
972
      return_args[2].value.pdb_pointer = data_copy;
 
973
    }
 
974
 
 
975
  return return_args;
 
976
}
 
977
 
 
978
static ProcArg procedural_db_get_data_inargs[] =
 
979
{
 
980
  {
 
981
    GIMP_PDB_STRING,
 
982
    "identifier",
 
983
    "The identifier associated with data"
 
984
  }
 
985
};
 
986
 
 
987
static ProcArg procedural_db_get_data_outargs[] =
 
988
{
 
989
  {
 
990
    GIMP_PDB_INT32,
 
991
    "bytes",
 
992
    "The number of bytes in the data"
 
993
  },
 
994
  {
 
995
    GIMP_PDB_INT8ARRAY,
 
996
    "data",
 
997
    "A byte array containing data"
 
998
  }
 
999
};
 
1000
 
 
1001
static ProcRecord procedural_db_get_data_proc =
 
1002
{
 
1003
  "gimp_procedural_db_get_data",
 
1004
  "Returns data associated with the specified identifier.",
 
1005
  "This procedure returns any data which may have been associated with the specified identifier. The data is a variable length array of bytes. If no data has been associated with the identifier, an error is returned.",
 
1006
  "Spencer Kimball & Peter Mattis",
 
1007
  "Spencer Kimball & Peter Mattis",
 
1008
  "1997",
 
1009
  NULL,
 
1010
  GIMP_INTERNAL,
 
1011
  1,
 
1012
  procedural_db_get_data_inargs,
 
1013
  2,
 
1014
  procedural_db_get_data_outargs,
 
1015
  { { procedural_db_get_data_invoker } }
 
1016
};
 
1017
 
 
1018
static Argument *
 
1019
procedural_db_get_data_size_invoker (Gimp         *gimp,
 
1020
                                     GimpContext  *context,
 
1021
                                     GimpProgress *progress,
 
1022
                                     Argument     *args)
 
1023
{
 
1024
  gboolean success = TRUE;
 
1025
  Argument *return_args;
 
1026
  gchar *identifier;
 
1027
  gint32 bytes;
 
1028
  const guint8 *data;
 
1029
 
 
1030
  identifier = (gchar *) args[0].value.pdb_pointer;
 
1031
  if (identifier == NULL || !g_utf8_validate (identifier, -1, NULL))
 
1032
    success = FALSE;
 
1033
 
 
1034
  if (success)
 
1035
    {
 
1036
      data = procedural_db_get_data (gimp, identifier, &bytes);
 
1037
      success = (data != NULL);
 
1038
    }
 
1039
 
 
1040
  return_args = procedural_db_return_args (&procedural_db_get_data_size_proc, success);
 
1041
 
 
1042
  if (success)
 
1043
    return_args[1].value.pdb_int = bytes;
 
1044
 
 
1045
  return return_args;
 
1046
}
 
1047
 
 
1048
static ProcArg procedural_db_get_data_size_inargs[] =
 
1049
{
 
1050
  {
 
1051
    GIMP_PDB_STRING,
 
1052
    "identifier",
 
1053
    "The identifier associated with data"
 
1054
  }
 
1055
};
 
1056
 
 
1057
static ProcArg procedural_db_get_data_size_outargs[] =
 
1058
{
 
1059
  {
 
1060
    GIMP_PDB_INT32,
 
1061
    "bytes",
 
1062
    "The number of bytes in the data"
 
1063
  }
 
1064
};
 
1065
 
 
1066
static ProcRecord procedural_db_get_data_size_proc =
 
1067
{
 
1068
  "gimp_procedural_db_get_data_size",
 
1069
  "Returns size of data associated with the specified identifier.",
 
1070
  "This procedure returns the size of any data which may have been associated with the specified identifier. If no data has been associated with the identifier, an error is returned.",
 
1071
  "Nick Lamb",
 
1072
  "Nick Lamb",
 
1073
  "1998",
 
1074
  NULL,
 
1075
  GIMP_INTERNAL,
 
1076
  1,
 
1077
  procedural_db_get_data_size_inargs,
 
1078
  1,
 
1079
  procedural_db_get_data_size_outargs,
 
1080
  { { procedural_db_get_data_size_invoker } }
 
1081
};
 
1082
 
 
1083
static Argument *
 
1084
procedural_db_set_data_invoker (Gimp         *gimp,
 
1085
                                GimpContext  *context,
 
1086
                                GimpProgress *progress,
 
1087
                                Argument     *args)
 
1088
{
 
1089
  gboolean success = TRUE;
 
1090
  gchar *identifier;
 
1091
  gint32 bytes;
 
1092
  guint8 *data;
 
1093
 
 
1094
  identifier = (gchar *) args[0].value.pdb_pointer;
 
1095
  if (identifier == NULL || !g_utf8_validate (identifier, -1, NULL))
 
1096
    success = FALSE;
 
1097
 
 
1098
  bytes = args[1].value.pdb_int;
 
1099
  if (bytes <= 0)
 
1100
    success = FALSE;
 
1101
 
 
1102
  data = (guint8 *) args[2].value.pdb_pointer;
 
1103
 
 
1104
  if (success)
 
1105
    procedural_db_set_data (gimp, identifier, bytes, data);
 
1106
 
 
1107
  return procedural_db_return_args (&procedural_db_set_data_proc, success);
 
1108
}
 
1109
 
 
1110
static ProcArg procedural_db_set_data_inargs[] =
 
1111
{
 
1112
  {
 
1113
    GIMP_PDB_STRING,
 
1114
    "identifier",
 
1115
    "The identifier associated with data"
 
1116
  },
 
1117
  {
 
1118
    GIMP_PDB_INT32,
 
1119
    "bytes",
 
1120
    "The number of bytes in the data"
 
1121
  },
 
1122
  {
 
1123
    GIMP_PDB_INT8ARRAY,
 
1124
    "data",
 
1125
    "A byte array containing data"
 
1126
  }
 
1127
};
 
1128
 
 
1129
static ProcRecord procedural_db_set_data_proc =
 
1130
{
 
1131
  "gimp_procedural_db_set_data",
 
1132
  "Associates the specified identifier with the supplied data.",
 
1133
  "This procedure associates the supplied data with the provided identifier. The data may be subsequently retrieved by a call to 'procedural-db-get-data'.",
 
1134
  "Spencer Kimball & Peter Mattis",
 
1135
  "Spencer Kimball & Peter Mattis",
 
1136
  "1997",
 
1137
  NULL,
 
1138
  GIMP_INTERNAL,
 
1139
  3,
 
1140
  procedural_db_set_data_inargs,
 
1141
  0,
 
1142
  NULL,
 
1143
  { { procedural_db_set_data_invoker } }
 
1144
};