~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to tools/pdbgen/pdb/procedural_db.pdb

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# The GIMP -- an image manipulation program
 
1
# GIMP - The GNU Image Manipulation Program
2
2
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 
4
4
# This program is free software; you can redistribute it and/or modify
17
17
 
18
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
19
19
 
20
 
sub proc_name_arg () {{
21
 
    name  => 'procedure',
22
 
    type  => 'string',
23
 
    desc  => 'The procedure name',
24
 
    alias => 'proc_name'
25
 
}}
26
 
 
27
 
sub data_ident_arg () {{
28
 
    name => 'identifier',
29
 
    type => 'string',
30
 
    desc => 'The identifier associated with data'
31
 
}}
32
 
 
33
 
sub data_bytes_arg () {{
34
 
    name => 'bytes',
35
 
    type => '0 < int32',
36
 
    desc => 'The number of bytes in the data',
37
 
}}
38
 
 
39
 
sub data_arg () {{
40
 
    name  => 'data',
41
 
    type  => 'int8array',
42
 
    desc  => 'A byte array containing data',
43
 
    array => &data_bytes_arg
44
 
}}
45
 
 
46
 
sub arg_info_proc {
47
 
    my ($type, $long_type, $real_type) = @_;
48
 
 
49
 
    $blurb = <<BLURB;
50
 
Queries the procedural database for information on the specified procedure's
51
 
$long_type.
52
 
BLURB
53
 
 
54
 
    $help = <<HELP;
55
 
This procedure returns information on the specified procedure's $long_type. The
56
 
$long_type type, name, and a description are retrieved.
57
 
HELP
58
 
 
59
 
    &std_pdb_misc;
60
 
    $date = '1997';
61
 
 
62
 
    @inargs = (
63
 
        &proc_name_arg,
64
 
        { name => "${type}_num", type => 'int32',
65
 
          desc => "The $long_type number" }
66
 
    );
67
 
 
68
 
    @outargs = (
69
 
        { name => "${type}_type", type => 'enum GimpPDBArgType (no GIMP_PDB_END)',
70
 
          desc => "The type of $long_type { %%desc%% }", void_ret => 1,
71
 
          alias => "${type}->arg_type", no_declare => 1 },
72
 
        { name => "${type}_name", type => 'string',
73
 
          desc => "The name of the $long_type",
74
 
          alias => "g_strdup (${type}->name)", no_declare => 1 },
75
 
        { name => "${type}_desc", type => 'string',
76
 
          desc => "A description of the $long_type",
77
 
          alias => "g_strdup (${type}->description)", no_declare => 1 }
78
 
    );
79
 
 
80
 
   %invoke = (
81
 
        vars => [ 'ProcRecord *proc', "ProcArg *$type = NULL" ],
82
 
        code => <<CODE
83
 
{
84
 
  proc = procedural_db_lookup (gimp, proc_name);
85
 
 
86
 
  if (! proc)
87
 
    {
88
 
      const gchar *compat_name;
89
 
 
90
 
      compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
91
 
 
92
 
      if (compat_name)
93
 
        proc = procedural_db_lookup (gimp, compat_name);
94
 
    }
95
 
 
96
 
  if (proc && (${type}_num >= 0 && ${type}_num < proc->num_$real_type))
97
 
    $type = \&proc->${real_type}\[${type}_num];
98
 
  else
99
 
    success = FALSE;
100
 
}
101
 
CODE
102
 
   );
103
 
}
104
 
 
105
 
# The defs
106
 
 
107
20
sub procedural_db_temp_name {
108
21
    $blurb = 'Generates a unique temporary PDB name.';
109
22
 
110
23
    $help = <<'HELP';
111
24
This procedure generates a temporary PDB entry name that is guaranteed to be
112
 
unique. It is many used by the interactive popup dialogs to generate a PDB
113
 
entry name.
 
25
unique.
114
26
HELP
115
27
 
116
 
    $author = $copyright = 'Andy Thomas';
117
 
    $date = '1998';
 
28
    &andy_pdb_misc('1998');
118
29
 
119
30
    @outargs = (
120
31
        { name => 'temp_name', type => 'string',
122
33
    );
123
34
 
124
35
    %invoke = (
125
 
        vars => [ 'static gint proc_number = 0' ],
126
36
        code => <<'CODE'
127
 
temp_name = g_strdup_printf ("temp_procedure_number_%d", proc_number++);
 
37
{
 
38
  static gint proc_number = 0;
 
39
 
 
40
  temp_name = g_strdup_printf ("temp-procedure-number-%d", proc_number++);
 
41
}
128
42
CODE
129
43
    );
130
44
}
149
63
    );
150
64
 
151
65
    %invoke = (
152
 
        headers => [ qw(<stdio.h> "core/gimp.h") ],
153
 
        vars => [ "FILE *file" ],
154
66
        code => <<'CODE'
155
67
{
156
 
  if ((file = fopen (filename, "w")))
157
 
    {
158
 
      g_hash_table_foreach (gimp->procedural_ht,
159
 
                            procedural_db_print_entry, file);
160
 
      fclose (file);
161
 
    }
162
 
  else
163
 
    success = FALSE;
 
68
  success = gimp_pdb_dump (gimp->pdb, filename);
164
69
}
165
70
CODE
166
71
    );
187
92
 
188
93
    &std_pdb_misc;
189
94
 
190
 
    my $regcomp = ""; $once = 0;
191
 
    foreach (qw(name blurb help author copyright date proc_type)) {
192
 
        push @inargs, { name => $_, type => 'string', no_validate => 1,
193
 
                        desc => "The regex for procedure $_" };
194
 
 
195
 
        $regcomp .= ' ' x 2 if $once++;
196
 
        $regcomp .= "if (regcomp (&pdb_query.${_}_regex, $_, 0))\n";
197
 
        $regcomp .= "    goto free_${_};\n";
198
 
    }
199
 
 
200
 
    my $free = ""; $once = 0;
201
 
    foreach (qw(proc_type date copyright author help blurb name)) {
202
 
        $free .= ' ' x 2 if $once++;
203
 
        $free .= "free_${_}:\n";
204
 
        $free .= "    regfree (&pdb_query.${_}_regex);\n";
205
 
    }
206
 
    chop $free;
207
 
 
208
 
    $inargs[$#inargs]->{desc} =~
209
 
        s <proc_type$>
210
 
          <type: { 'Internal GIMP procedure', 'GIMP Plug-in',
211
 
                   'GIMP Extension' }>;
 
95
    @inargs = (
 
96
        { name => 'name', type => 'string', no_validate => 1,
 
97
          desc => 'The regex for procedure name' },
 
98
        { name => 'blurb', type => 'string', no_validate => 1,
 
99
          desc => 'The regex for procedure blurb' },
 
100
        { name => 'help', type => 'string', no_validate => 1,
 
101
          desc => 'The regex for procedure help' },
 
102
        { name => 'author', type => 'string', no_validate => 1,
 
103
          desc => 'The regex for procedure author' },
 
104
        { name => 'copyright', type => 'string', no_validate => 1,
 
105
          desc => 'The regex for procedure copyright' },
 
106
        { name => 'date', type => 'string', no_validate => 1,
 
107
          desc => 'The regex for procedure date' },
 
108
        { name => 'proc_type', type => 'string', no_validate => 1,
 
109
          desc => 'The regex for procedure type: { \'Internal GIMP procedure\',
 
110
                   \'GIMP Plug-In\', \'GIMP Extension\',
 
111
                   \'Temporary Procedure\' }' }
 
112
    );
212
113
 
213
114
    @outargs = (
214
115
        { name  => 'procedure_names', type  => 'stringarray', void_ret => 1,
215
116
          desc  => 'The list of procedure names',
216
 
          alias => 'pdb_query.list_of_procs', no_declare => 1,
217
117
          array => { name  => 'num_matches',
218
 
                     desc  => 'The number of matching procedures',
219
 
                     alias => 'pdb_query.num_procs', no_declare => 1 }
220
 
        }
 
118
                     desc  => 'The number of matching procedures' } }
221
119
    );
222
120
 
223
121
    %invoke = (
224
 
        headers => [ qw(<stdlib.h> "regexrepl/regex.h") ],
225
 
        vars => [ 'PDBQuery pdb_query' ],
226
122
        code => <<CODE
227
123
{
228
 
  success = FALSE;
229
 
 
230
 
  $regcomp
231
 
 
232
 
  success = TRUE;
233
 
 
234
 
  pdb_query.gimp            = gimp;
235
 
  pdb_query.list_of_procs   = NULL;
236
 
  pdb_query.num_procs       = 0;
237
 
  pdb_query.querying_compat = FALSE;
238
 
 
239
 
  g_hash_table_foreach (gimp->procedural_ht,
240
 
                        procedural_db_query_entry, \&pdb_query);
241
 
 
242
 
  pdb_query.querying_compat = TRUE;
243
 
 
244
 
  g_hash_table_foreach (gimp->procedural_compat_ht,
245
 
                        procedural_db_query_entry, \&pdb_query);
246
 
 
247
 
  $free
 
124
  success = gimp_pdb_query (gimp->pdb,
 
125
                            name, blurb, help, author,
 
126
                            copyright, date, proc_type,
 
127
                            &num_matches, &procedure_names);
248
128
}
249
129
CODE
250
130
    );
256
136
BLURB
257
137
 
258
138
    $help = <<'HELP';
259
 
This procedure returns information on the specified procedure. A short blurb,
260
 
detailed help, author(s), copyright information, procedure type, number of
261
 
input, and number of return values are returned. For specific information on
262
 
each input argument and return value, use the
263
 
'gimp_procedural_db_proc_arg' and
264
 
'gimp_procedural_db_proc_val' procedures.
 
139
This procedure returns information on the specified procedure. A short
 
140
blurb, detailed help, author(s), copyright information, procedure
 
141
type, number of input, and number of return values are returned. For
 
142
specific information on each input argument and return value, use the
 
143
gimp_procedural_db_proc_arg() and gimp_procedural_db_proc_val()
 
144
procedures.
265
145
HELP
266
146
 
267
147
    &std_pdb_misc;
268
148
    $date = '1997';
269
149
 
270
 
    @inargs = ( &proc_name_arg );
 
150
    @inargs = (
 
151
        { name  => 'procedure_name', type  => 'string',
 
152
          desc  => 'The procedure name' }
 
153
    );
271
154
 
272
155
    @outargs = (
273
156
        { name => 'blurb', type => 'string', void_ret => 1, wrap => 1,
281
164
        { name => 'date', type => 'string',
282
165
          desc => 'Copyright date' },
283
166
        { name => 'proc_type', type => 'enum GimpPDBProcType',
284
 
          desc => 'The procedure type: { %%desc%% }' },
 
167
          desc => 'The procedure type' },
285
168
        { name => 'num_args', type => 'int32',
286
169
          desc => 'The number of input arguments' },
287
170
        { name => 'num_values', type => 'int32',
288
171
          desc => 'The number of return values' }
289
172
    );
290
173
 
291
 
    foreach (@outargs) {
292
 
        if ($_->{type} eq 'string') {
293
 
            $_->{alias} = "strings.compat ? strings.$_->{name} : g_strdup (strings.$_->{name})";
294
 
        } else {
295
 
            $_->{alias} = "proc->$_->{name}";
296
 
        }
297
 
 
298
 
        $_->{no_declare} = 1;
299
 
    }
300
 
 
301
174
    %invoke = (
302
 
        vars => [ 'PDBStrings strings', 'ProcRecord *proc = NULL' ],
303
175
        code => <<'CODE'
304
176
{
305
 
  proc = procedural_db_lookup (gimp, proc_name);
306
 
 
307
 
  if (proc)
308
 
    {
309
 
      get_pdb_strings (&strings, proc, FALSE);
310
 
    }
311
 
  else
312
 
    {
313
 
      const gchar *compat_name;
314
 
 
315
 
      compat_name = g_hash_table_lookup (gimp->procedural_compat_ht, proc_name);
316
 
 
317
 
      if (compat_name)
318
 
        {
319
 
          proc = procedural_db_lookup (gimp, compat_name);
320
 
 
321
 
          if (proc)
322
 
            get_pdb_strings (&strings, proc, TRUE);
323
 
        }
324
 
    }
325
 
 
326
 
  success = (proc != NULL);
 
177
  GimpPDBProcType  ptype;
 
178
  gchar           *canonical;
 
179
 
 
180
  canonical = gimp_canonicalize_identifier (procedure_name);
 
181
 
 
182
  success = gimp_pdb_proc_info (gimp->pdb, canonical,
 
183
                                &blurb, &help, &author,
 
184
                                &copyright, &date, &ptype,
 
185
                                &num_args, &num_values);
 
186
  proc_type = ptype;
 
187
 
 
188
  g_free (canonical);
327
189
}
328
190
CODE
329
191
    );
330
192
}
331
193
 
332
194
sub procedural_db_proc_arg {
333
 
    &arg_info_proc('arg', 'argument', 'args');
 
195
    $blurb = <<BLURB;
 
196
Queries the procedural database for information on the specified procedure's
 
197
argument.
 
198
BLURB
 
199
 
 
200
    $help = <<HELP;
 
201
This procedure returns information on the specified procedure's argument. The
 
202
argument type, name, and a description are retrieved.
 
203
HELP
 
204
 
 
205
    &std_pdb_misc;
 
206
    $date = '1997';
 
207
 
 
208
    @inargs = (
 
209
        { name => 'procedure_name', type  => 'string',
 
210
          desc => 'The procedure name' },
 
211
        { name => 'arg_num', type => 'int32',
 
212
          desc => 'The argument number' }
 
213
    );
 
214
 
 
215
    @outargs = (
 
216
        { name => 'arg_type', type => 'enum GimpPDBArgType (no GIMP_PDB_END)',
 
217
          desc => "The type of argument", void_ret => 1 },
 
218
        { name => 'arg_name', type => 'string',
 
219
          desc => 'The name of the argument' },
 
220
        { name => 'arg_desc', type => 'string',
 
221
          desc => 'A description of the argument' }
 
222
    );
 
223
 
 
224
   %invoke = (
 
225
        code => <<CODE
 
226
{
 
227
  GimpProcedure *proc;
 
228
  gchar         *canonical;
 
229
 
 
230
  canonical = gimp_canonicalize_identifier (procedure_name);
 
231
 
 
232
  proc = gimp_pdb_lookup_procedure (gimp->pdb, canonical);
 
233
 
 
234
  if (! proc)
 
235
    {
 
236
      const gchar *compat_name;
 
237
 
 
238
      compat_name = gimp_pdb_lookup_compat_proc_name (gimp->pdb, canonical);
 
239
 
 
240
      if (compat_name)
 
241
        proc = gimp_pdb_lookup_procedure (gimp->pdb, compat_name);
 
242
    }
 
243
 
 
244
  g_free (canonical);
 
245
 
 
246
  if (proc && (arg_num >= 0 && arg_num < proc->num_args))
 
247
    {
 
248
      GParamSpec *pspec = proc->args[arg_num];
 
249
 
 
250
      arg_type = gimp_pdb_compat_arg_type_from_gtype (G_PARAM_SPEC_VALUE_TYPE (pspec));
 
251
      arg_name = g_strdup (g_param_spec_get_name (pspec));
 
252
      arg_desc = gimp_param_spec_get_desc (pspec);
 
253
    }
 
254
  else
 
255
    success = FALSE;
 
256
}
 
257
CODE
 
258
   );
334
259
}
335
260
 
336
261
sub procedural_db_proc_val {
337
 
    &arg_info_proc('val', 'return value', 'values');
 
262
    $blurb = <<BLURB;
 
263
Queries the procedural database for information on the specified procedure's
 
264
return value.
 
265
BLURB
 
266
 
 
267
    $help = <<HELP;
 
268
This procedure returns information on the specified procedure's return value.
 
269
The return value type, name, and a description are retrieved.
 
270
HELP
 
271
 
 
272
    &std_pdb_misc;
 
273
    $date = '1997';
 
274
 
 
275
    @inargs = (
 
276
        { name => 'procedure_name', type  => 'string',
 
277
          desc => 'The procedure name' },
 
278
        { name => 'val_num', type => 'int32',
 
279
          desc => 'The return value number' }
 
280
    );
 
281
 
 
282
    @outargs = (
 
283
        { name => 'val_type', type => 'enum GimpPDBArgType (no GIMP_PDB_END)',
 
284
          desc => "The type of return value", void_ret => 1 },
 
285
        { name => 'val_name', type => 'string',
 
286
          desc => 'The name of the return value' },
 
287
        { name => 'val_desc', type => 'string',
 
288
          desc => 'A description of the return value' }
 
289
    );
 
290
 
 
291
   %invoke = (
 
292
        code => <<CODE
 
293
{
 
294
  GimpProcedure *proc;
 
295
  gchar         *canonical;
 
296
 
 
297
  canonical = gimp_canonicalize_identifier (procedure_name);
 
298
 
 
299
  proc = gimp_pdb_lookup_procedure (gimp->pdb, canonical);
 
300
 
 
301
  if (! proc)
 
302
    {
 
303
      const gchar *compat_name;
 
304
 
 
305
      compat_name = gimp_pdb_lookup_compat_proc_name (gimp->pdb, canonical);
 
306
 
 
307
      if (compat_name)
 
308
        proc = gimp_pdb_lookup_procedure (gimp->pdb, compat_name);
 
309
    }
 
310
 
 
311
  g_free (canonical);
 
312
 
 
313
  if (proc && (val_num >= 0 && val_num < proc->num_values))
 
314
    {
 
315
      GParamSpec *pspec = proc->values[val_num];
 
316
 
 
317
      val_type = gimp_pdb_compat_arg_type_from_gtype (G_PARAM_SPEC_VALUE_TYPE (pspec));
 
318
      val_name = g_strdup (g_param_spec_get_name (pspec));
 
319
      val_desc = gimp_param_spec_get_desc (pspec);
 
320
    }
 
321
  else
 
322
    success = FALSE;
 
323
}
 
324
CODE
 
325
   );
338
326
}
339
327
 
340
328
sub procedural_db_get_data {
341
 
    $alias{lib} = 'get_data';
342
 
 
343
329
    $blurb = 'Returns data associated with the specified identifier.';
344
330
 
345
331
    $help = <<'HELP';
351
337
    &std_pdb_misc;
352
338
    $date = '1997';
353
339
 
354
 
    @inargs = ( &data_ident_arg );
 
340
    @inargs = (
 
341
        { name => 'identifier', type => 'string',
 
342
          desc => 'The identifier associated with data' }
 
343
    );
355
344
 
356
 
    @outargs = ( &data_arg );
357
 
    $outargs[0]->{alias} = 'data_copy';
358
 
    $outargs[0]->{init} = 1;
359
 
    $outargs[0]->{wrap} = 1;
360
 
    $outargs[0]->{void_ret} = 1;
 
345
    @outargs = (
 
346
        { name  => 'data', type  => 'int8array',
 
347
          desc  => 'A byte array containing data', wrap => 1,
 
348
          void_ret => 1,
 
349
          array => { name => 'bytes', type => '1 <= int32',
 
350
                     desc => 'The number of bytes in the data' } }
 
351
    );
361
352
 
362
353
    %invoke = (
363
 
        vars => [ 'const guint8 *data' ],
364
354
        code => <<'CODE'
365
355
{
366
 
  data = procedural_db_get_data (gimp, identifier, &bytes);
367
 
  success = (data != NULL);
368
 
 
369
 
  if (success)
370
 
    data_copy = g_memdup (data, bytes);
 
356
  gchar        *canonical = gimp_canonicalize_identifier (identifier);
 
357
  const guint8 *orig_data;
 
358
 
 
359
  orig_data = gimp_plug_in_manager_get_data (gimp->plug_in_manager,
 
360
                                             canonical, &bytes);
 
361
 
 
362
  g_free (canonical);
 
363
 
 
364
  if (orig_data)
 
365
    data = g_memdup (orig_data, bytes);
 
366
  else
 
367
    success = FALSE;
371
368
}
372
369
CODE
373
370
    );
382
379
an error is returned.
383
380
HELP
384
381
 
385
 
    $author = $copyright = 'Nick Lamb';
386
 
    $date = '1998';
387
 
 
388
 
    @inargs = ( &data_ident_arg );
389
 
 
390
 
    @outargs = ( &data_bytes_arg );
 
382
    &nick_pdb_misc('1998');
 
383
 
 
384
    @inargs = (
 
385
        { name => 'identifier', type => 'string',
 
386
          desc => 'The identifier associated with data' }
 
387
    );
 
388
 
 
389
    @outargs = (
 
390
        { name => 'bytes', type => '1 <= int32',
 
391
          desc => 'The number of bytes in the data' }
 
392
    );
391
393
 
392
394
    %invoke = (
393
 
        vars => [ 'const guint8 *data' ],
394
395
        code => <<'CODE'
395
396
{
396
 
  data = procedural_db_get_data (gimp, identifier, &bytes);
397
 
  success = (data != NULL);
 
397
  gchar *canonical = gimp_canonicalize_identifier (identifier);
 
398
 
 
399
  if (! gimp_plug_in_manager_get_data (gimp->plug_in_manager,
 
400
                                       canonical, &bytes))
 
401
    success = FALSE;
 
402
 
 
403
  g_free (canonical);
398
404
}
399
405
CODE
400
406
    );
401
407
}
402
408
 
403
409
sub procedural_db_set_data {
404
 
    $alias{lib} = 'set_data';
405
 
 
406
410
    $blurb = 'Associates the specified identifier with the supplied data.';
407
411
 
408
412
    $help = <<'HELP';
413
417
    &std_pdb_misc;
414
418
    $date = '1997';
415
419
 
416
 
    @inargs = ( &data_ident_arg, &data_arg );
417
 
    $inargs[1]->{wrap} = 1;
418
 
    delete @{$inargs[1]->{array}}{qw(alias no_declare)};
 
420
    @inargs = (
 
421
        { name => 'identifier', type => 'string',
 
422
          desc => 'The identifier associated with data' },
 
423
        { name  => 'data', type  => 'int8array',
 
424
          desc  => 'A byte array containing data', wrap => 1,
 
425
          array => { name => 'bytes', type => '1 <= int32',
 
426
                     desc => 'The number of bytes in the data' } }
 
427
    );
419
428
 
420
429
    %invoke = (
421
 
        code => 'procedural_db_set_data (gimp, identifier, bytes, data);'
 
430
        code => <<'CODE'
 
431
{
 
432
  gchar *canonical = gimp_canonicalize_identifier (identifier);
 
433
 
 
434
  gimp_plug_in_manager_set_data (gimp->plug_in_manager,
 
435
                                 canonical, bytes, data);
 
436
 
 
437
  g_free (canonical);
 
438
}
 
439
CODE
422
440
    );
423
441
}
424
442
 
425
 
@headers = qw(<string.h> "gimp-intl.h");
426
 
 
427
 
$extra{app}->{decls} = <<'CODE';
428
 
#define COMPAT_BLURB "This procedure is deprecated! Use '%s' instead."
429
 
 
430
 
 
431
 
/*  Query structure  */
432
 
typedef struct _PDBQuery PDBQuery;
433
 
 
434
 
struct _PDBQuery
435
 
{
436
 
  Gimp     *gimp;
437
 
 
438
 
  regex_t   name_regex;
439
 
  regex_t   blurb_regex;
440
 
  regex_t   help_regex;
441
 
  regex_t   author_regex;
442
 
  regex_t   copyright_regex;
443
 
  regex_t   date_regex;
444
 
  regex_t   proc_type_regex;
445
 
 
446
 
  gchar   **list_of_procs;
447
 
  gint      num_procs;
448
 
  gboolean  querying_compat;
449
 
};
450
 
 
451
 
 
452
 
typedef struct _PDBStrings PDBStrings;
453
 
 
454
 
struct _PDBStrings
455
 
{
456
 
  gboolean  compat;
457
 
 
458
 
  gchar    *blurb;
459
 
  gchar    *help;
460
 
  gchar    *author;
461
 
  gchar    *copyright;
462
 
  gchar    *date;
463
 
};
464
 
 
465
 
static gchar *proc_type_str[] =
466
 
{
467
 
  N_("Internal GIMP procedure"),
468
 
  N_("GIMP Plug-In"),
469
 
  N_("GIMP Extension"),
470
 
  N_("Temporary Procedure")
471
 
};
472
 
 
473
 
static const gchar * const type_str[] =
474
 
{
475
 
CODE
476
 
 
477
 
foreach (@{$Gimp::CodeGen::enums::enums{GimpPDBArgType}->{symbols}}) {
478
 
    $extra{app}->{decls} .= qq/  "$_",\n/;
479
 
}
480
 
 
481
 
$extra{app}->{decls} =~ s/,\n$/\n};\n/;
482
 
 
483
 
$extra{app}->{code} = <<'CODE';
484
 
static int
485
 
match_strings (regex_t     *preg,
486
 
               const gchar *a)
487
 
{
488
 
  if (!a)
489
 
    a = "";
490
 
 
491
 
  return regexec (preg, a, 0, NULL, 0);
492
 
}
493
 
 
494
 
static void
495
 
get_pdb_strings (PDBStrings *strings,
496
 
                 ProcRecord *proc,
497
 
                 gboolean    compat)
498
 
{
499
 
  strings->compat = compat;
500
 
 
501
 
  if (compat)
502
 
    {
503
 
      strings->blurb     = g_strdup_printf (COMPAT_BLURB, proc->name);
504
 
      strings->help      = g_strdup (strings->blurb);
505
 
      strings->author    = NULL;
506
 
      strings->copyright = NULL;
507
 
      strings->date      = NULL;
508
 
    }
509
 
  else
510
 
    {
511
 
      strings->blurb     = proc->blurb;
512
 
      strings->help      = proc->help;
513
 
      strings->author    = proc->author;
514
 
      strings->copyright = proc->copyright;
515
 
      strings->date      = proc->date;
516
 
    }
517
 
}
518
 
 
519
 
static void
520
 
procedural_db_query_entry (gpointer key,
521
 
                           gpointer value,
522
 
                           gpointer user_data)
523
 
{
524
 
  PDBQuery    *pdb_query = user_data;
525
 
  GList       *list;
526
 
  ProcRecord  *proc;
527
 
  const gchar *proc_name;
528
 
  PDBStrings   strings;
529
 
 
530
 
  proc_name = key;
531
 
 
532
 
  if (pdb_query->querying_compat)
533
 
    list = g_hash_table_lookup (pdb_query->gimp->procedural_ht, value);
534
 
  else
535
 
    list = value;
536
 
 
537
 
  if (! list)
538
 
    return;
539
 
 
540
 
  proc = (ProcRecord *) list->data;
541
 
 
542
 
  get_pdb_strings (&strings, proc, pdb_query->querying_compat);
543
 
 
544
 
  if (! match_strings (&pdb_query->name_regex,      proc_name)         &&
545
 
      ! match_strings (&pdb_query->blurb_regex,     strings.blurb)     &&
546
 
      ! match_strings (&pdb_query->help_regex,      strings.help)      &&
547
 
      ! match_strings (&pdb_query->author_regex,    strings.author)    &&
548
 
      ! match_strings (&pdb_query->copyright_regex, strings.copyright) &&
549
 
      ! match_strings (&pdb_query->date_regex,      strings.date)      &&
550
 
      ! match_strings (&pdb_query->proc_type_regex,
551
 
                       proc_type_str[(gint) proc->proc_type]))
552
 
    {
553
 
      pdb_query->num_procs++;
554
 
      pdb_query->list_of_procs = g_renew (gchar *, pdb_query->list_of_procs,
555
 
                                          pdb_query->num_procs);
556
 
      pdb_query->list_of_procs[pdb_query->num_procs - 1] = g_strdup (proc_name);
557
 
    }
558
 
 
559
 
  if (strings.compat)
560
 
    {
561
 
      g_free (strings.blurb);
562
 
      g_free (strings.help);
563
 
    }
564
 
}
565
 
 
566
 
static gboolean
567
 
output_string (FILE        *file,
568
 
               const gchar *string)
569
 
{
570
 
  if (fprintf (file, "\"") < 0)
571
 
    return FALSE;
572
 
 
573
 
  if (string)
574
 
    while (*string)
575
 
      {
576
 
        switch (*string)
577
 
          {
578
 
          case '\\' : if (fprintf (file, "\\\\") < 0) return FALSE; break;
579
 
          case '\"' : if (fprintf (file, "\\\"") < 0) return FALSE; break;
580
 
          case '{'  : if (fprintf (file, "@{")   < 0) return FALSE; break;
581
 
          case '@'  : if (fprintf (file, "@@")   < 0) return FALSE; break;
582
 
          case '}'  : if (fprintf (file, "@}")   < 0) return FALSE; break;
583
 
 
584
 
          default:
585
 
            if (fprintf (file, "%c", *string) < 0)
586
 
              return FALSE;
587
 
          }
588
 
        string++;
589
 
      }
590
 
 
591
 
  if (fprintf (file, "\"\n") < 0)
592
 
    return FALSE;
593
 
 
594
 
  return TRUE;
595
 
}
596
 
 
597
 
static void
598
 
procedural_db_print_entry (gpointer key,
599
 
                           gpointer value,
600
 
                           gpointer user_data)
601
 
{
602
 
  ProcRecord *procedure;
603
 
  GString    *buf;
604
 
  GList      *list;
605
 
  FILE       *file;
606
 
  gint        i;
607
 
  gint        num = 0;
608
 
 
609
 
  list = (GList *) value;
610
 
  file = (FILE *) user_data;
611
 
 
612
 
  buf = g_string_new ("");
613
 
 
614
 
  while (list)
615
 
    {
616
 
      num++;
617
 
      procedure = (ProcRecord*) list->data;
618
 
      list = list->next;
619
 
 
620
 
      fprintf (file, "\n(register-procedure ");
621
 
 
622
 
      if (list || num != 1)
623
 
        {
624
 
          g_string_printf (buf, "%s <%d>", procedure->name, num);
625
 
          output_string (file, buf->str);
626
 
        }
627
 
      else
628
 
        output_string (file, procedure->name);
629
 
 
630
 
      output_string (file, procedure->blurb);
631
 
      output_string (file, procedure->help);
632
 
      output_string (file, procedure->author);
633
 
      output_string (file, procedure->copyright);
634
 
      output_string (file, procedure->date);
635
 
      output_string (file, proc_type_str[(int) procedure->proc_type]);
636
 
 
637
 
      fprintf (file, "( ");
638
 
      for (i = 0; i < procedure->num_args; i++)
639
 
        {
640
 
          fprintf (file, "( ");
641
 
 
642
 
          output_string (file, procedure->args[i].name );
643
 
          output_string (file, type_str[procedure->args[i].arg_type]);
644
 
          output_string (file, procedure->args[i].description);
645
 
 
646
 
          fprintf (file, " ) ");
647
 
        }
648
 
      fprintf (file, " ) ");
649
 
 
650
 
      fprintf (file, "( ");
651
 
      for (i = 0; i < procedure->num_values; i++)
652
 
        {
653
 
          fprintf (file, "( ");
654
 
          output_string (file, procedure->values[i].name );
655
 
          output_string (file, type_str[procedure->values[i].arg_type]);
656
 
          output_string (file, procedure->values[i].description);
657
 
 
658
 
          fprintf (file, " ) ");
659
 
        }
660
 
      fprintf (file, " ) ");
661
 
      fprintf (file, " ) ");
662
 
    }
663
 
 
664
 
  g_string_free (buf, TRUE);
665
 
}
666
 
 
667
 
/* This really doesn't belong here, but it depends on our generated type_str
668
 
 * array.
669
 
 */
670
 
const char *
671
 
pdb_type_name (gint type)
672
 
{
673
 
  if (type >= 0 && type <= GIMP_PDB_END)
674
 
    return type_str[type];
675
 
  else
676
 
    return g_strdup_printf ("(PDB type %d unknown)", type);
677
 
   /* Yeah, we leak the memory.  But then you shouldn't try and
678
 
    * get the name of a PDB type that doesn't exist, should you.
679
 
    */
680
 
}
681
 
CODE
 
443
 
 
444
@headers = qw("libgimpbase/gimpbase.h"
 
445
              "core/gimp.h"
 
446
              "core/gimpparamspecs-desc.h"
 
447
              "gimppdb-query.h"
 
448
              "gimp-pdb-compat.h"
 
449
              "plug-in/gimppluginmanager-data.h");
682
450
 
683
451
@procs = qw(procedural_db_temp_name procedural_db_dump
684
452
            procedural_db_query procedural_db_proc_info
685
453
            procedural_db_proc_arg procedural_db_proc_val
686
454
            procedural_db_get_data procedural_db_get_data_size
687
455
            procedural_db_set_data);
 
456
 
688
457
%exports = (app => [@procs], lib => [@procs]);
689
458
 
690
459
$desc = 'Procedural database';