1 /*
2  * (C) Copyright 2005- ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  *
7  * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8  * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9  */
10 
11 #include "grib_api_internal.h"
12 
13 typedef struct grib_action_if
14 {
15     grib_action act;
16     /* Members defined in section */
17     /* Members defined in if */
18     grib_expression* expression;
19     grib_action* block_true;
20     grib_action* block_false;
21 } grib_action_if;
22 
23 typedef struct grib_action_list
24 {
25     grib_action act;
26     /* Members defined in section */
27     /* Members defined in list */
28     grib_expression* expression;
29     grib_action* block_list;
30 } grib_action_list;
31 
32 typedef struct grib_action_gen
33 {
34     grib_action act;
35     /* Members defined in gen */
36     long len;
37     grib_arguments* params;
38 } grib_action_gen;
39 
print_names(grib_action * a)40 static void print_names(grib_action* a)
41 {
42     while (a) {
43         if (a->op && !strcmp(a->op, "label")) {
44             a = a->next;
45             continue;
46         }
47         if (!strcmp(a->cclass->name, "action_class_noop") ||
48             !strcmp(a->cclass->name, "action_class_when")) {
49             a = a->next;
50             continue;
51         }
52 
53         if (!strcmp(a->cclass->name, "action_class_list")) {
54             grib_action_list* al = (grib_action_list*)a;
55             /*printf("%s\n", a->name);*/
56             print_names(al->block_list);
57         }
58         else if (!strcmp(a->cclass->name, "action_class_if")) {
59             grib_action_if* ai = (grib_action_if*)a;
60             print_names(ai->block_false);
61             print_names(ai->block_true);
62         }
63         else if (!strcmp(a->cclass->name, "action_class_gen")) {
64             const char* table = NULL;
65             grib_action_gen* ag = (grib_action_gen*)a;
66             if (strcmp(a->op,"codetable")==0 || strcmp(a->op,"codeflag")==0) {
67                 printf("%s", a->name);
68                 table = grib_arguments_get_string(NULL, ag->params, 0);
69                 if (table) printf("\t%s=%s", a->op, table);
70                 printf("\n");
71             }
72         }
73         else {
74             /*printf("%s\n", a->name);*/
75         }
76 
77         a = a->next;
78     }
79 }
80 
main(int argc,char * argv[])81 int main(int argc, char* argv[])
82 {
83     int i    = 0;
84     int fail = 0;
85 
86     grib_context* c = grib_context_get_default();
87     grib_action* a  = NULL;
88 
89     for (i = 1; i < argc; i++) {
90         if (!(a = grib_parse_file(c, argv[i]))) {
91             fail++;
92             printf("FAILED\n");
93             exit(1);
94         }
95         else {
96             print_names(a);
97         }
98     }
99 
100     return fail;
101 }
102