PageRenderTime 345ms CodeModel.GetById 201ms app.highlight 10ms RepoModel.GetById 131ms app.codeStats 1ms

/tools/fbusgen/main.c

http://ftk.googlecode.com/
C | 154 lines | 107 code | 18 blank | 29 comment | 33 complexity | fefb37b67b536422557ed3e07985419d MD5 | raw file
  1/*
  2 * File:    
  3 * Author:  Li XianJing <xianjimli@hotmail.com>
  4 * Brief:   
  5 *
  6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
  7 *
  8 * Licensed under the Academic Free License version 2.1
  9 *
 10 * This program is free software; you can redistribute it and/or modify
 11 * it under the terms of the GNU General Public License as published by
 12 * the Free Software Foundation; either version 2 of the License, or
 13 * (at your option) any later version.
 14 *
 15 * This program is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18 * GNU General Public License for more details.
 19 *
 20 * You should have received a copy of the GNU General Public License
 21 * along with this program; if not, write to the Free Software
 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 23 */
 24
 25/*
 26 * History:
 27 * ================================================================
 28 * 2010-07-31 Li XianJing <xianjimli@hotmail.com> created
 29 *
 30 */
 31
 32#include "coder_intf.h"
 33#include "coder_client.h"
 34#include "coder_xxxx.h"
 35#include "coder_service.h"
 36#include "coder_share.h"
 37
 38static gboolean coder_generator(IDL_tree_func_data *tfd, Coder* coder)
 39{
 40	IDL_tree p = tfd->tree;
 41
 42	if (IDL_NODE_TYPE (p) == IDLN_INTERFACE)
 43	{
 44		const char* parent = "";
 45		struct _IDL_INTERFACE intf = IDL_INTERFACE(p);
 46		const char* name = IDL_IDENT(intf.ident).str;
 47
 48		if(intf.inheritance_spec != NULL)
 49		{
 50			struct _IDL_LIST list = IDL_LIST(intf.inheritance_spec);
 51			parent = IDL_IDENT(list.data).str;
 52		}
 53		return coder_on_interface(coder, name, parent);
 54	}
 55	else if(IDL_NODE_TYPE (p) == IDLN_OP_DCL)
 56	{
 57		return coder_on_function(coder, IDL_OP_DCL(p));
 58	}
 59	else if(IDL_NODE_TYPE (p) == IDLN_CONST_DCL)
 60	{
 61		return coder_on_const(coder, IDL_CONST_DCL(p));
 62	}
 63	else if(IDL_NODE_TYPE(p) == IDLN_TYPE_STRUCT)
 64	{
 65		return coder_on_struct(coder, IDL_TYPE_STRUCT(p));
 66	}
 67	else if(IDL_NODE_TYPE(p) == IDLN_TYPE_ENUM)
 68	{
 69		return coder_on_enum(coder, IDL_TYPE_ENUM(p));
 70	}
 71	else if(IDL_NODE_TYPE(p) == IDLN_TYPE_UNION)
 72	{
 73		return coder_on_union(coder, IDL_TYPE_UNION(p));
 74	}
 75
 76	return TRUE;
 77}
 78
 79struct _CoderNameAndCreator
 80{
 81	char* name;
 82	CoderCreate create;
 83}g_coders [] =
 84{
 85	{"intf", coder_intf_create},
 86	{"client", coder_client_create},
 87	{"service", coder_service_create},
 88	{"share", coder_share_create},
 89	{NULL, NULL}
 90};
 91
 92static Coder* coder_create(const char* name)
 93{
 94	int i = 0;
 95	g_return_val_if_fail(name != NULL, NULL);
 96
 97	for(i = 0; g_coders[i].name != NULL; i++)
 98	{
 99		if(strcmp(name, g_coders[i].name) == 0)
100		{
101			printf("Found coder %s.\n", name);
102			return g_coders[i].create(name);
103		}
104	}
105
106	printf("Cannt found coder %s, use xxxx\n", name);
107
108	return coder_xxxx_create(name);
109}
110
111int main (int argc, char *argv[])
112{
113	int rv = 0;
114	IDL_ns ns = {0};
115	IDL_tree tree = {0};
116	Coder* coder = NULL;
117	const char* type = NULL;
118	const char* filename = NULL;
119	unsigned long parse_flags = 0;
120
121	IDL_check_cast_enable (TRUE);
122
123	if (argc < 3 || (type = strstr(argv[1], "-type=")) == NULL) 
124	{
125		fprintf (stderr, "usage: %s -type=intf|client|service|xxx idl \n", argv[0]);
126		exit (1);	
127	}
128
129	type += 6;
130	filename = argv[2];
131	rv = IDL_parse_filename (filename, NULL, NULL, &tree, &ns, parse_flags, IDL_WARNING1);
132	if (rv == IDL_ERROR) 
133	{
134		g_message ("IDL_ERROR: %s\n", filename);
135		exit (1);	
136	} 
137	else if (rv < 0) 
138	{
139		perror (filename);
140		exit (1);
141	}
142
143	coder = coder_create(type);
144	if(coder != NULL)
145	{
146		IDL_tree_walk_in_order (tree, (IDL_tree_func)coder_generator, coder);
147		coder_destroy(coder);
148	}
149
150	IDL_ns_free (ns);
151	IDL_tree_free (tree);
152
153	return 0;
154}