1 /* LIBGIMP - The GIMP Library
2  * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball
3  *
4  * gimpproceduraldb.c
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 #include "config.h"
22 
23 #include <string.h> /* memcmp */
24 
25 #include "gimp.h"
26 
27 /**
28  * gimp_procedural_db_proc_info:
29  * @procedure: The procedure name.
30  * @blurb: A short blurb.
31  * @help: Detailed procedure help.
32  * @author: Author(s) of the procedure.
33  * @copyright: The copyright.
34  * @date: Copyright date.
35  * @proc_type: The procedure type.
36  * @num_args: The number of input arguments.
37  * @num_values: The number of return values.
38  * @args: The input arguments.
39  * @return_vals: The return values.
40  *
41  * Queries the procedural database for information on the specified
42  * procedure.
43  *
44  * This procedure returns information on the specified procedure. A
45  * short blurb, detailed help, author(s), copyright information,
46  * procedure type, number of input, and number of return values are
47  * returned. Additionally this function returns specific information
48  * about each input argument and return value.
49  *
50  * Returns: TRUE on success.
51  */
52 gboolean
gimp_procedural_db_proc_info(const gchar * procedure,gchar ** blurb,gchar ** help,gchar ** author,gchar ** copyright,gchar ** date,GimpPDBProcType * proc_type,gint * num_args,gint * num_values,GimpParamDef ** args,GimpParamDef ** return_vals)53 gimp_procedural_db_proc_info (const gchar      *procedure,
54                               gchar           **blurb,
55                               gchar           **help,
56                               gchar           **author,
57                               gchar           **copyright,
58                               gchar           **date,
59                               GimpPDBProcType  *proc_type,
60                               gint             *num_args,
61                               gint             *num_values,
62                               GimpParamDef    **args,
63                               GimpParamDef    **return_vals)
64 {
65   gint i;
66   gboolean success = TRUE;
67 
68   success = _gimp_procedural_db_proc_info (procedure,
69                                            blurb,
70                                            help,
71                                            author,
72                                            copyright,
73                                            date,
74                                            proc_type,
75                                            num_args,
76                                            num_values);
77 
78   if (success)
79     {
80       *args        = g_new (GimpParamDef, *num_args);
81       *return_vals = g_new (GimpParamDef, *num_values);
82 
83       for (i = 0; i < *num_args; i++)
84         {
85           if (! gimp_procedural_db_proc_arg (procedure,
86                                              i,
87                                              &(*args)[i].type,
88                                              &(*args)[i].name,
89                                              &(*args)[i].description))
90             {
91               g_free (*args);
92               g_free (*return_vals);
93 
94               return FALSE;
95             }
96         }
97 
98       for (i = 0; i < *num_values; i++)
99         {
100           if (! gimp_procedural_db_proc_val (procedure,
101                                              i,
102                                              &(*return_vals)[i].type,
103                                              &(*return_vals)[i].name,
104                                              &(*return_vals)[i].description))
105             {
106               g_free (*args);
107               g_free (*return_vals);
108 
109               return FALSE;
110             }
111         }
112      }
113 
114   return success;
115 }
116 
117 /**
118  * gimp_procedural_db_get_data:
119  * @identifier: The identifier associated with data.
120  * @data: A byte array containing data.
121  *
122  * Returns data associated with the specified identifier.
123  *
124  * This procedure returns any data which may have been associated with
125  * the specified identifier. The data is copied into the given memory
126  * location.
127  *
128  * Returns: TRUE on success, FALSE if no data has been associated with
129  * the identifier
130  */
131 gboolean
gimp_procedural_db_get_data(const gchar * identifier,gpointer data)132 gimp_procedural_db_get_data (const gchar *identifier,
133                              gpointer     data)
134 {
135   gint      size;
136   guint8   *hack;
137   gboolean  success;
138 
139   success = _gimp_procedural_db_get_data (identifier,
140                                           &size,
141                                           &hack);
142   if (hack)
143     {
144       memcpy (data, (gconstpointer) hack, size * sizeof (guint8));
145       g_free (hack);
146     }
147 
148   return success;
149 }
150 
151 /**
152  * gimp_procedural_db_set_data:
153  * @identifier: The identifier associated with data.
154  * @data: A byte array containing data.
155  * @bytes: The number of bytes in the data
156  *
157  * Associates the specified identifier with the supplied data.
158  *
159  * This procedure associates the supplied data with the provided
160  * identifier. The data may be subsequently retrieved by a call to
161  * 'procedural-db-get-data'.
162  *
163  * Returns: TRUE on success.
164  */
165 gboolean
gimp_procedural_db_set_data(const gchar * identifier,gconstpointer data,guint32 bytes)166 gimp_procedural_db_set_data (const gchar   *identifier,
167                              gconstpointer  data,
168                              guint32        bytes)
169 {
170   return _gimp_procedural_db_set_data (identifier,
171                                        bytes,
172                                        data);
173 }
174