|
Packit |
4a5d52 |
/*
|
|
Packit |
4a5d52 |
*
|
|
Packit |
4a5d52 |
* Some crude tests for libIDL.
|
|
Packit |
4a5d52 |
*
|
|
Packit |
4a5d52 |
* Usage: tstidl <filename> [flags]
|
|
Packit |
4a5d52 |
*
|
|
Packit |
4a5d52 |
* if given, flags is read as (output_flags << 24) | parse_flags
|
|
Packit |
4a5d52 |
*
|
|
Packit |
4a5d52 |
* gcc `libIDL-config --cflags --libs` tstidl.c -o tstidl
|
|
Packit |
4a5d52 |
*
|
|
Packit |
4a5d52 |
*/
|
|
Packit |
4a5d52 |
#ifdef G_LOG_DOMAIN
|
|
Packit |
4a5d52 |
# undef G_LOG_DOMAIN
|
|
Packit |
4a5d52 |
#endif
|
|
Packit |
4a5d52 |
#define G_LOG_DOMAIN "tstidl"
|
|
Packit |
4a5d52 |
#include <stdio.h>
|
|
Packit |
4a5d52 |
#include <stdlib.h>
|
|
Packit |
4a5d52 |
#include <string.h>
|
|
Packit |
4a5d52 |
#include <ctype.h>
|
|
Packit |
4a5d52 |
#include <libIDL/IDL.h>
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
#define IDLFP_IDENT_VISITED (1UL << 0)
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
typedef struct {
|
|
Packit |
4a5d52 |
IDL_tree tree;
|
|
Packit |
4a5d52 |
IDL_ns ns;
|
|
Packit |
4a5d52 |
} WalkData;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
static gboolean
|
|
Packit |
4a5d52 |
print_repo_id (IDL_tree_func_data *tfd, WalkData *data)
|
|
Packit |
4a5d52 |
{
|
|
Packit |
4a5d52 |
char *repo_id = NULL;
|
|
Packit |
4a5d52 |
IDL_tree p;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
p = tfd->tree;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (IDL_NODE_TYPE (p) == IDLN_INTERFACE) {
|
|
Packit |
4a5d52 |
repo_id = IDL_IDENT_REPO_ID (IDL_INTERFACE (p).ident);
|
|
Packit |
4a5d52 |
} else if (IDL_NODE_TYPE (p) == IDLN_IDENT &&
|
|
Packit |
4a5d52 |
IDL_NODE_UP (p) != NULL &&
|
|
Packit |
4a5d52 |
IDL_NODE_UP (IDL_NODE_UP (p)) != NULL &&
|
|
Packit |
4a5d52 |
IDL_NODE_TYPE (IDL_NODE_UP (IDL_NODE_UP (p))) == IDLN_ATTR_DCL)
|
|
Packit |
4a5d52 |
repo_id = IDL_IDENT_REPO_ID (p);
|
|
Packit |
4a5d52 |
if (repo_id)
|
|
Packit |
4a5d52 |
printf ("%s\n", repo_id);
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return TRUE;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
static gboolean
|
|
Packit |
4a5d52 |
print_xpidl_exts (IDL_tree_func_data *tfd, WalkData *data)
|
|
Packit |
4a5d52 |
{
|
|
Packit |
4a5d52 |
IDL_tree p;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
p = tfd->tree;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (IDL_NODE_TYPE (p) == IDLN_IDENT &&
|
|
Packit |
4a5d52 |
IDL_NODE_TYPE (IDL_NODE_UP (p)) == IDLN_INTERFACE) {
|
|
Packit |
4a5d52 |
const char *val;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
val = IDL_tree_property_get (p, "IID");
|
|
Packit |
4a5d52 |
if (val) printf ("\tinterface `%s' XPIDL IID:\"%s\"\n",
|
|
Packit |
4a5d52 |
IDL_IDENT (IDL_INTERFACE (IDL_NODE_UP (p)).ident).str,
|
|
Packit |
4a5d52 |
val);
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (IDL_NODE_TYPE (p) == IDLN_NATIVE &&
|
|
Packit |
4a5d52 |
IDL_NATIVE (p).user_type)
|
|
Packit |
4a5d52 |
g_message ("XPIDL native type: \"%s\"", IDL_NATIVE (p).user_type);
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (IDL_NODE_TYPE (p) == IDLN_CODEFRAG) {
|
|
Packit |
4a5d52 |
GSList *slist = IDL_CODEFRAG (p).lines;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
g_message ("XPIDL code fragment desc.: \"%s\"", IDL_CODEFRAG (p).desc);
|
|
Packit |
4a5d52 |
for (; slist; slist = slist->next)
|
|
Packit |
4a5d52 |
g_message ("XPIDL code fragment line.: \"%s\"", (char *) slist->data);
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return TRUE;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
static gboolean
|
|
Packit |
4a5d52 |
print_ident_comments (IDL_tree_func_data *tfd, WalkData *data)
|
|
Packit |
4a5d52 |
{
|
|
Packit |
4a5d52 |
GSList *list;
|
|
Packit |
4a5d52 |
IDL_tree p;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
p = tfd->tree;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (IDL_NODE_TYPE (p) == IDLN_IDENT) {
|
|
Packit |
4a5d52 |
if (!(p->flags & IDLFP_IDENT_VISITED)) {
|
|
Packit |
4a5d52 |
printf ("Identifier: %s\n", IDL_IDENT (p).str);
|
|
Packit |
4a5d52 |
for (list = IDL_IDENT (p).comments; list;
|
|
Packit |
4a5d52 |
list = g_slist_next (list)) {
|
|
Packit |
4a5d52 |
char *comment = list->data;
|
|
Packit |
4a5d52 |
printf ("%s\n", comment);
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
p->flags |= IDLFP_IDENT_VISITED;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return TRUE;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
static gboolean
|
|
Packit |
4a5d52 |
print_const_dcls (IDL_tree_func_data *tfd, WalkData *data)
|
|
Packit |
4a5d52 |
{
|
|
Packit |
4a5d52 |
IDL_tree p;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
p = tfd->tree;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (IDL_NODE_TYPE (p) == IDLN_CONST_DCL) {
|
|
Packit |
4a5d52 |
GString *s;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
s = IDL_tree_to_IDL_string (p, NULL, IDLF_OUTPUT_NO_NEWLINES);
|
|
Packit |
4a5d52 |
puts (s->str);
|
|
Packit |
4a5d52 |
g_string_free (s, TRUE);
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return FALSE;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return TRUE;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
/* Example input method... simply reads in from some file and passes it along as
|
|
Packit |
4a5d52 |
* is--warning, no actual C preprocessing performed here! Standard C preprocessor
|
|
Packit |
4a5d52 |
* indicators should also be passed to libIDL, including # <line> "filename" (double
|
|
Packit |
4a5d52 |
* quotes expected), etcetera (do not confuse this with passing #defines to libIDL, this
|
|
Packit |
4a5d52 |
* should not be done). */
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
/* #define TEST_INPUT_CB */
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
#ifdef G_OS_WIN32
|
|
Packit |
4a5d52 |
# ifndef TEST_INPUT_CB
|
|
Packit |
4a5d52 |
# define TEST_INPUT_CB
|
|
Packit |
4a5d52 |
# endif
|
|
Packit |
4a5d52 |
#endif
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
#ifdef TEST_INPUT_CB
|
|
Packit |
4a5d52 |
typedef struct {
|
|
Packit |
4a5d52 |
FILE *in;
|
|
Packit |
4a5d52 |
} InputData;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
static int
|
|
Packit |
4a5d52 |
my_input_cb (IDL_input_reason reason, union IDL_input_data *cb_data, gpointer user_data)
|
|
Packit |
4a5d52 |
{
|
|
Packit |
4a5d52 |
InputData *my_data = user_data;
|
|
Packit |
4a5d52 |
int rv;
|
|
Packit |
4a5d52 |
static int linecount;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
switch (reason) {
|
|
Packit |
4a5d52 |
case IDL_INPUT_REASON_INIT:
|
|
Packit |
4a5d52 |
g_message ("my_input_cb: filename: %s", cb_data->init.filename);
|
|
Packit |
4a5d52 |
my_data->in = fopen (cb_data->init.filename, "r");
|
|
Packit |
4a5d52 |
/* If failed, should know that it is implied to libIDL that errno is set
|
|
Packit |
4a5d52 |
* appropriately by a C library function or otherwise. Return 0 upon
|
|
Packit |
4a5d52 |
* success. */
|
|
Packit |
4a5d52 |
linecount = 1;
|
|
Packit |
4a5d52 |
IDL_file_set (cb_data->init.filename, 1);
|
|
Packit |
4a5d52 |
return my_data->in ? 0 : -1;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
case IDL_INPUT_REASON_FILL:
|
|
Packit |
4a5d52 |
/* Fill the buffer here... return number of bytes read (maximum of
|
|
Packit |
4a5d52 |
cb_data->fill.max_size), 0 for EOF, negative value upon error. */
|
|
Packit |
4a5d52 |
rv = fread (cb_data->fill.buffer, 1, cb_data->fill.max_size, my_data->in);
|
|
Packit |
4a5d52 |
IDL_queue_new_ident_comment ("Queue some comment...");
|
|
Packit |
4a5d52 |
g_message ("my_input_cb: fill, max size %d, got %d",
|
|
Packit |
4a5d52 |
cb_data->fill.max_size, rv);
|
|
Packit |
4a5d52 |
if (rv == 0 && ferror (my_data->in))
|
|
Packit |
4a5d52 |
return -1;
|
|
Packit |
4a5d52 |
IDL_file_set (NULL, ++linecount);
|
|
Packit |
4a5d52 |
return rv;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
case IDL_INPUT_REASON_ABORT:
|
|
Packit |
4a5d52 |
case IDL_INPUT_REASON_FINISH:
|
|
Packit |
4a5d52 |
/* Called after parsing to indicate success or failure */
|
|
Packit |
4a5d52 |
g_message ("my_input_cb: abort or finish");
|
|
Packit |
4a5d52 |
fclose (my_data->in);
|
|
Packit |
4a5d52 |
break;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return 0;
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
#endif
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
int
|
|
Packit |
4a5d52 |
main (int argc, char *argv[])
|
|
Packit |
4a5d52 |
{
|
|
Packit |
4a5d52 |
int rv;
|
|
Packit |
4a5d52 |
IDL_tree tree;
|
|
Packit |
4a5d52 |
IDL_ns ns;
|
|
Packit |
4a5d52 |
char *fn;
|
|
Packit |
4a5d52 |
WalkData data;
|
|
Packit |
4a5d52 |
unsigned long parse_flags = 0;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
#ifndef G_PLATFORM_WIN32
|
|
Packit |
4a5d52 |
{ extern int __IDL_debug;
|
|
Packit |
4a5d52 |
__IDL_debug = argc >= 4 ? TRUE : FALSE; }
|
|
Packit |
4a5d52 |
#endif
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
IDL_check_cast_enable (TRUE);
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
g_message ("libIDL version %s", IDL_get_libver_string ());
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (argc < 2) {
|
|
Packit |
4a5d52 |
fprintf (stderr, "usage: tstidl <filename> [parse flags, hex]\n");
|
|
Packit |
4a5d52 |
exit (1);
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
fn = argv[1];
|
|
Packit |
4a5d52 |
if (argc >= 3)
|
|
Packit |
4a5d52 |
sscanf (argv[2], "%lx", &parse_flags);
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
#ifdef TEST_INPUT_CB
|
|
Packit |
4a5d52 |
{ InputData input_cb_data;
|
|
Packit |
4a5d52 |
g_message ("IDL_parse_filename_with_input");
|
|
Packit |
4a5d52 |
rv = IDL_parse_filename_with_input (
|
|
Packit |
4a5d52 |
fn, my_input_cb, &input_cb_data,
|
|
Packit |
4a5d52 |
NULL, &tree, &ns, parse_flags,
|
|
Packit |
4a5d52 |
IDL_WARNING1);
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
#else
|
|
Packit |
4a5d52 |
g_message ("IDL_parse_filename");
|
|
Packit |
4a5d52 |
rv = IDL_parse_filename (
|
|
Packit |
4a5d52 |
fn, NULL, NULL, &tree, &ns,
|
|
Packit |
4a5d52 |
parse_flags, IDL_WARNING1);
|
|
Packit |
4a5d52 |
#endif
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
if (rv == IDL_ERROR) {
|
|
Packit |
4a5d52 |
g_message ("IDL_ERROR");
|
|
Packit |
4a5d52 |
exit (1);
|
|
Packit |
4a5d52 |
} else if (rv < 0) {
|
|
Packit |
4a5d52 |
perror (fn);
|
|
Packit |
4a5d52 |
exit (1);
|
|
Packit |
4a5d52 |
}
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
/* rv == IDL_SUCCESS */
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
data.tree = tree;
|
|
Packit |
4a5d52 |
data.ns = ns;
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
g_print ("--------------------------------------\n");
|
|
Packit |
4a5d52 |
g_message ("Repository IDs");
|
|
Packit |
4a5d52 |
g_print ("--------------------------------------\n");
|
|
Packit |
4a5d52 |
IDL_tree_walk_in_order (tree, (IDL_tree_func) print_repo_id, &data);
|
|
Packit |
4a5d52 |
g_print ("\n--------------------------------------\n");
|
|
Packit |
4a5d52 |
g_message ("XPIDL extensions");
|
|
Packit |
4a5d52 |
g_print ("--------------------------------------\n");
|
|
Packit |
4a5d52 |
IDL_tree_walk_in_order (tree, (IDL_tree_func) print_xpidl_exts, &data);
|
|
Packit |
4a5d52 |
g_print ("\n--------------------------------------\n");
|
|
Packit |
4a5d52 |
g_message ("Constant Declarations");
|
|
Packit |
4a5d52 |
g_print ("--------------------------------------\n");
|
|
Packit |
4a5d52 |
IDL_tree_walk_in_order (tree, (IDL_tree_func) print_const_dcls, &data);
|
|
Packit |
4a5d52 |
g_print ("\n--------------------------------------\n");
|
|
Packit |
4a5d52 |
g_message ("Identifiers");
|
|
Packit |
4a5d52 |
g_print ("--------------------------------------\n");
|
|
Packit |
4a5d52 |
IDL_tree_walk_in_order (tree, (IDL_tree_func) print_ident_comments, &data);
|
|
Packit |
4a5d52 |
g_print ("\n--------------------------------------\n");
|
|
Packit |
4a5d52 |
g_message ("IDL_tree_to_IDL");
|
|
Packit |
4a5d52 |
g_print ("--------------------------------------\n");
|
|
Packit |
4a5d52 |
IDL_tree_to_IDL (tree, ns, stdout, parse_flags >> 24);
|
|
Packit |
4a5d52 |
IDL_ns_free (ns);
|
|
Packit |
4a5d52 |
IDL_tree_free (tree);
|
|
Packit |
4a5d52 |
|
|
Packit |
4a5d52 |
return 0;
|
|
Packit |
4a5d52 |
}
|