예제 #1
0
파일: xml.c 프로젝트: BugIsBitch/AOT
/**********************************************************************
* FUNCTION NAME:
*   save_file
*
* DESCRIPTION:
*   This function save the RAM tree info to the given file
*
* INTERFACE:
*   GLOBAL DATA:
*     None
*
*   INPUT:
*     file_name-- given file name
*     root --root of the tree 
*
*   OUTPUT:
*     None
*
*   INPUT/OUTPUT:
*     None
*
* AUTHOR:
*   Fu Pei
*
* RETURN VALUE:
*
* if save file failed return the error type otherwise return PROCESS_SUCCESS
*
*
* NOTES:
*
*********************************************************************/
int save_file(char *file_name,node_t* root)
{
	int ret = PROCESS_SUCCESS;
	FILE* file;
    stack_t stk;
	node_t *child = NULL;
	node_t* nd = NULL;
	if (file_name)
	{
		file = fopen( file_name, "w" );
	}	
	/*file open failed*/
	if ((NULL == file) ||(NULL == root) )
	{
		ret = FILE_WRITE_ERROR;
	}
	if (ret >= 0)
	{
		/*print head of xml*/
		print_declaration(file,root);
		/*create stack*/
		init_stack(&stk);
		/*push all children of the node to stack*/
		child = root->child;
		while(child)
		{
			/*push data to stack*/
			push(&stk,child);
			child = child->sibl;
		}
		/*is stack empty*/
		while (!stack_empty(&stk))
		{ 
			node_t* nd_child = NULL;
			int nd_chld_index = 0;
			/*get node from the stack*/
			pop(&stk,&nd);
			/*write node to xml file*/
			write_node_begin(file,nd);
			/*last leaf node of the tree with nd as its root*/
			write_node_end(file,nd,&stk);
			/*does nd node have child*/
			nd_child = nd->child;
			/*push all nd_child to stack*/
			while (nd_child)
			{
				push(&stk,nd_child);
				
				nd_child = nd_child->sibl;
			}/*end while*/
		}/*end while*/
		fclose(file);
	}
	
	  return ret;
}
예제 #2
0
void
print_node(ndr_node_t *np)
{
	char		*nm;

	if (!np) {
		(void) printf("<null>");
		return;
	}

	switch (np->label) {
	case ALIGN_KW:		nm = "align";		break;
	case STRUCT_KW:		nm = "struct";		break;
	case UNION_KW:		nm = "union";		break;
	case TYPEDEF_KW:	nm = "typedef";		break;
	case INTERFACE_KW:	nm = "interface";	break;
	case IN_KW:		nm = "in";		break;
	case OUT_KW:		nm = "out";		break;
	case SIZE_IS_KW:	nm = "size_is";		break;
	case LENGTH_IS_KW:	nm = "length_is";	break;
	case STRING_KW:		nm = "string";		break;
	case TRANSMIT_AS_KW:	nm = "transmit_as";	break;
	case OPERATION_KW:	nm = "operation";	break;
	case UUID_KW:		nm = "uuid";		break;
	case _NO_REORDER_KW:	nm = "_no_reorder";	break;
	case EXTERN_KW:		nm = "extern";		break;
	case ARG_IS_KW:		nm = "arg_is";		break;
	case CASE_KW:		nm = "case";		break;
	case DEFAULT_KW:	nm = "default";		break;
	case BASIC_TYPE:	nm = "<btype>";		break;
	case TYPENAME:		nm = "<tname>";		break;
	case IDENTIFIER:	nm = "<ident>";		break;
	case INTEGER:		nm = "<intg>";		break;
	case STRING:		nm = "<string>";	break;
	case STAR:		nm = "<*>";		break;
	case LB:		nm = "<[>";		break;
	case LP:		nm = "<(>";		break;
	case L_MEMBER:		nm = "<member>";	break;
	default:
		(void) printf("<<lab=%d>>", np->label);
		return;
	}

	switch (np->label) {
	case STRUCT_KW:
	case UNION_KW:
	case TYPEDEF_KW:
		(void) printf("\n");
		if (np->n_c_advice) {
			print_advice_list(np->n_c_advice);
			(void) printf("\n");
		}
		(void) printf("%s ", nm);
		print_node(np->n_c_typename);
		(void) printf(" {\n");
		print_node_list(np->n_c_members);
		(void) printf("};\n");
		break;

	case IN_KW:
	case OUT_KW:
	case STRING_KW:
	case DEFAULT_KW:
	case _NO_REORDER_KW:
	case EXTERN_KW:
		(void) printf("%s", nm);
		break;

	case ALIGN_KW:
		/*
		 * Don't output anything for default alignment.
		 */
		if ((np->n_a_arg == NULL) || (np->n_a_arg->n_int == 0))
			break;
		(void) printf("%s(", nm);
		print_node(np->n_a_arg);
		(void) printf(")");
		break;

	case SIZE_IS_KW:
	case LENGTH_IS_KW:
		(void) printf("%s(", nm);
		print_field_attr(np);
		(void) printf(")");
		break;

	case INTERFACE_KW:
	case TRANSMIT_AS_KW:
	case ARG_IS_KW:
	case CASE_KW:
	case OPERATION_KW:
	case UUID_KW:
		(void) printf("%s(", nm);
		print_node(np->n_a_arg);
		(void) printf(")");
		break;

	case BASIC_TYPE:
	case TYPENAME:
	case IDENTIFIER:
		(void) printf("%s", np->n_sym->name);
		break;

	case INTEGER:
		(void) printf("%ld", np->n_int);
		break;

	case STRING:
		(void) printf("\"%s\"", np->n_str);
		break;

	case STAR:
		(void) printf("*");
		print_node(np->n_d_descend);
		break;

	case LB:
		print_node(np->n_d_descend);
		(void) printf("[");
		if (np->n_d_dim)
			print_node(np->n_d_dim);
		(void) printf("]");
		break;

	case LP:
		(void) printf("(");
		print_node(np->n_d_descend);
		(void) printf(")");
		break;

	case L_MEMBER:
		if (np->n_m_advice) {
			(void) printf("    ");
			print_advice_list(np->n_m_advice);
			(void) printf("\n");
		}
		(void) printf("\t");
		print_declaration(np);
		(void) printf(";\n");
		break;

	default:
		return;
	}
}