Debian Codegraph @

test/frei0r-meta.c

raw symbols SCIP
1 /* This file is part of frei0r (https://frei0r.dyne.org)
2 *
3 * Copyright (C) 2024-2025 Dyne.org foundation
4 * designed, written and maintained by Denis Roio <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program 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
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <dlfcn.h>
26 #include <libgen.h>
27
28 #include <frei0r.h>cxx . . $ `<file>/include/frei0r.h`/
29
30 // frei0r function prototypes
31 typedef int (*f0r_init_fcxx . . $ f0r_init_f#)(void);
32 typedef void (*f0r_deinit_fcxx . . $ f0r_deinit_f#)(void);
33 typedef void (*f0r_get_plugin_info_fcxx . . $ f0r_get_plugin_info_f#)(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t# *info);
34 typedef void (*f0r_get_param_info_fcxx . . $ f0r_get_param_info_f#)(f0r_param_info_tcxx . . $ f0r_param_info_t# *info, int param_index);
35
36 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) {
37
38 // instance frei0r pointers
39 static void *dl_handle;
40 static f0r_init_fcxx . . $ f0r_init_f# f0r_init;
41 static f0r_init_fcxx . . $ f0r_init_f# f0r_deinit;
42 static f0r_plugin_info_tcxx . . $ f0r_plugin_info_t# pi;
43 static f0r_get_plugin_info_fcxx . . $ f0r_get_plugin_info_f# f0r_get_plugin_info;
44 static f0r_get_param_info_fcxx . . $ f0r_get_param_info_f# f0r_get_param_info;
45 static f0r_param_info_tcxx . . $ f0r_param_info_t# param;
46
47 int c;
48
49 if(argc<2) exitcxx . . $ exit(3ca292c338df9bb3).(1);
50 const char *file = basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(argv[1]);
51 const char *dir = dirnamecxx . . $ dirname(7a9722d75b371431).(argv[1]);
52 char path[256];;
53 snprintfcxx . . $ snprintf(ea502d73e74c754c).(path, 255,"%s/%s",dir,file);
54 // fprintf(stderr,"%s %s\n",argv[0], file);
55 // load shared library
56 dl_handle = dlopencxx . . $ dlopen(fb9ec0bb113f3da8).(path, RTLD_NOWcxx . . $ `<external>/10632388298615623587/dlfcn.h:25:9`!|RTLD_LOCALcxx . . $ `<external>/10632388298615623587/dlfcn.h:38:9`!);
57 if(!dl_handle) {
58 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!,"error: %s\n",dlerrorcxx . . $ dlerror(41208ce6ca65dd58).());
59 exitcxx . . $ exit(3ca292c338df9bb3).(1);
60 }
61 // get plugin function calls
62 f0r_init = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_init");
63 f0r_deinit = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_deinit");
64 f0r_get_plugin_info = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_get_plugin_info");
65 f0r_get_param_info = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dl_handle,"f0r_get_param_info");
66 // always initialize plugin first
67 f0r_init();
68 // get info about plugin
69 f0r_get_plugin_info(&pi);
70 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!,
71 "{\n \"name\":\"%s\",\n \"type\":\"%s\",\n \"author\":\"%s\",\n"
72 " \"explanation\":\"%s\",\n \"color_model\":\"%s\",\n"
73 " \"frei0r_version\":\"%d\",\n \"version\":\"%d.%d\",\n \"num_params\":\"%d\"",
74 pi.namecxx . . $ f0r_plugin_info#name.,
75 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`! ? "filter" :
76 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_SOURCEcxx . . $ `include/frei0r.h:249:9`! ? "source" :
77 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER2cxx . . $ `include/frei0r.h:251:9`! ? "mixer2" :
78 pi.plugin_typecxx . . $ f0r_plugin_info#plugin_type. == F0R_PLUGIN_TYPE_MIXER3cxx . . $ `include/frei0r.h:253:9`! ? "mixer3" : "unknown",
79 pi.authorcxx . . $ f0r_plugin_info#author., pi.explanationcxx . . $ f0r_plugin_info#explanation.,
80 pi.color_modelcxx . . $ f0r_plugin_info#color_model. == F0R_COLOR_MODEL_BGRA8888cxx . . $ `include/frei0r.h:299:9`! ? "bgra8888" :
81 pi.color_modelcxx . . $ f0r_plugin_info#color_model. == F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`! ? "rgba8888" :
82 pi.color_modelcxx . . $ f0r_plugin_info#color_model. == F0R_COLOR_MODEL_PACKED32cxx . . $ `include/frei0r.h:322:9`! ? "packed32" : "unknown",
83 pi.frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version., pi.major_versioncxx . . $ f0r_plugin_info#major_version., pi.minor_versioncxx . . $ f0r_plugin_info#minor_version., pi.num_paramscxx . . $ f0r_plugin_info#num_params.);
84
85 /* // check icon */
86 /* char icon[256]; */
87 /* char *dot = rindex(file, '.'); */
88 /* *dot = 0x0; */
89 /* snprintf(icon,255,"%s/%s.png",dir,file); */
90 /* FILE *icon_fd = fopen(icon,"r"); */
91 /* if(icon_fd) { */
92 /* fprintf(stderr," icon found: %s\n",icon); */
93 /* } */
94
95 // get info about params
96 if(pi.num_paramscxx . . $ f0r_plugin_info#num_params.>0) {
97 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!,",\n \"params\":[\n");
98 for(c=0; c<pi.num_paramscxx . . $ f0r_plugin_info#num_params.; c++) {
99 f0r_get_param_info(&param, c);
100 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!,
101 " {\n \"name\":\"%s\",\n \"type\":\"%s\",\n \"explanation\":\"%s\"\n }",
102 param.namecxx . . $ f0r_param_info#name.,
103 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_BOOLcxx . . $ `include/frei0r.h:377:9`! ? "bool" :
104 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_COLORcxx . . $ `include/frei0r.h:389:9`! ? "color" :
105 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`! ? "number" :
106 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_POSITIONcxx . . $ `include/frei0r.h:394:9`! ? "position" :
107 param.typecxx . . $ f0r_param_info#type. == F0R_PARAM_STRINGcxx . . $ `include/frei0r.h:400:9`! ? "string" : "unknown",
108 param.explanationcxx . . $ f0r_param_info#explanation.);
109 if(pi.num_paramscxx . . $ f0r_plugin_info#num_params.>c+1) {
110 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!,",\n");
111 } else {
112 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!,"\n");
113 }
114 }
115 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!," ]\n");
116 }
117 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!,"\n}\n");
118 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!);
119 f0r_deinit();
120 dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dl_handle);
121 exitcxx . . $ exit(3ca292c338df9bb3).(0);
122 }