Skip to content
Newer
Older
100644 57 lines (44 sloc) 1.55 KB
579e6de @residuum Made functions static where applicable.
authored
1 /*
2 * [json-decode] decodes JSON data and outputs it as lists.
3 * */
4
5a9caf9 @eighthave update Makefile and arrange files to match the Library Template:
eighthave authored
5 #include "purest_json.h"
6
7 static t_class *json_decode_class;
8
9 void setup_json0x2ddecode(void) {
10 json_decode_class = class_new(gensym("json-decode"), (t_newmethod)json_decode_new,
11 0, sizeof(t_json_decode), 0, A_GIMME, 0);
12 class_addsymbol(json_decode_class, (t_method)json_decode_string);
9b28222 @residuum Some small bug fixes and cleanups.
authored
13 /* Commented because it defeats json_decode_string: [l2s] is always needed */
14 /*class_addlist(json_decode_class, (t_method)json_decode_list);*/
5a9caf9 @eighthave update Makefile and arrange files to match the Library Template:
eighthave authored
15 class_sethelpsymbol(json_decode_class, gensym("json"));
16 }
17
18 void *json_decode_new(t_symbol *selector, int argcount, t_atom *argvec) {
19 t_json_decode *x = (t_json_decode*)pd_new(json_decode_class);
9b28222 @residuum Some small bug fixes and cleanups.
authored
20
68efd0b @residuum Do not show unused parameter warning.
authored
21 (void) selector;
22 (void) argcount;
23 (void) argvec;
9b28222 @residuum Some small bug fixes and cleanups.
authored
24
5a9caf9 @eighthave update Makefile and arrange files to match the Library Template:
eighthave authored
25 outlet_new(&x->x_ob, NULL);
26 x->done_outlet = outlet_new(&x->x_ob, &s_bang);
27 return (void *)x;
28 }
29
30 void json_decode_string(t_json_decode *x, t_symbol *data) {
5854491 @residuum rest-json is now working again.
authored
31 size_t memsize = 0;
32 char *json_string = remove_backslashes(data->s_name, memsize);
9b28222 @residuum Some small bug fixes and cleanups.
authored
33
34 if (json_string != NULL) {
35 output_json_string(json_string, x->x_ob.ob_outlet, x->done_outlet);
5854491 @residuum rest-json is now working again.
authored
36 freebytes(json_string, memsize);
9b28222 @residuum Some small bug fixes and cleanups.
authored
37 }
6624bc6 @residuum Fixing issue #4:
authored
38 }
39
40 void json_decode_list(t_json_decode *x, t_symbol *selector, int argcount, t_atom *argvec) {
5854491 @residuum rest-json is now working again.
authored
41 char json_string[MAXPDSTRING];
42 char value[MAXPDSTRING];
6624bc6 @residuum Fixing issue #4:
authored
43 int i;
68efd0b @residuum Do not show unused parameter warning.
authored
44
45 (void) selector;
46
47
6624bc6 @residuum Fixing issue #4:
authored
48 if (argcount > 1) {
5854491 @residuum rest-json is now working again.
authored
49 atom_string(argvec + 1, json_string, MAXPDSTRING);
6624bc6 @residuum Fixing issue #4:
authored
50 for (i = 2; i < argcount; i++) {
5854491 @residuum rest-json is now working again.
authored
51 atom_string(argvec + i, value, MAXPDSTRING);
6624bc6 @residuum Fixing issue #4:
authored
52 strcat(json_string, value);
53 }
68efd0b @residuum Do not show unused parameter warning.
authored
54 output_json_string(json_string, x->x_ob.ob_outlet, x->done_outlet);
6624bc6 @residuum Fixing issue #4:
authored
55 }
5a9caf9 @eighthave update Makefile and arrange files to match the Library Template:
eighthave authored
56 }
Something went wrong with that request. Please try again.