Ejemplo n.º 1
0
static void bt_print_node(bt* tree, bt_node* node, char* indent,
                          void (*print_element)(void* val)) {
    printf("%s", indent);
    printf("(%p) ", node);
    printf("N=%i", node_N(node));

    if (!isleaf(node)) {
        char* subind;
        char* addind = "  ";
        printf(", leftmost (%p)", node->branch.firstleaf);
        printf(", Nleft=%i, Nright=%i, balance %i.\n",
               node_N(node->branch.children[0]),
               node_N(node->branch.children[1]),
               node->branch.balance);
        subind = malloc(strlen(indent) + strlen(addind) + 1);
        sprintf(subind, "%s%s", indent, addind);
        printf("%sLeft child:\n", indent);
        bt_print_node(tree, node->branch.children[0], subind, print_element);
        printf("%sRight child:\n", indent);
        bt_print_node(tree, node->branch.children[1], subind, print_element);
        free(subind);
    } else {
        int i;
        printf(".  Leaf.");
        if (print_element) {
            printf("  [ ");
            for (i=0; i<node_N(node); i++)
                print_element(get_element(tree, &node->leaf, i));
        }
        printf("]\n");
    }
}
Ejemplo n.º 2
0
int main ()
{
	int notpassed = 0;
	int passed = 0;
	
	struct array array1;
	
	check (init_array (&array1))
	
	test (add_element (&array1, 1), NO_ERRORS)
	
	test (add_element (&array1, 8), NO_ERRORS)
	
	test (change_element(&array1, 12, 33), WRITE_TO_UNALLOCATED_MEMORY)
	
	test (change_element(&array1, 1, 33), NO_ERRORS)
	
	test (add_element (&array1, 41), NO_ERRORS)
	
	test (add_element (&array1, 3), NO_ERRORS)
	
	test (add_element (&array1, 9), NO_ERRORS)
	
	
	test (elements_sum (&array1), NO_ERRORS)
	
	test (add_element (&array1, 13), NO_ERRORS)
	
	test (verbose_full_print (&array1), NO_ERRORS)
	
	test (remove_element (&array1, 4), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (find_element(&array1, 120), ELEMENT_NOT_FOUND)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	test (print_element(&array1, 40), GARBAGE_READ)
	
	test (zero_array   (&array1), NO_ERRORS)
	
	test (print_array (&array1), NO_ERRORS)
	
	printf ("datalen = %i, memlen = %i\n", get_datalen (&array1), get_memlen (&array1));
	
	for (int i = 0; i < 305; i ++)
		check (add_element (&array1, 41)); 
	
	printf ("Passed %i, not passed %i.\n", passed, notpassed);
	
	test (delete_array (&array1), NO_ERRORS)
	
	print_exit_message ();
	
	return 0;
}
Ejemplo n.º 3
0
/*
 Removal of tail recursion is so simple
 that some compilers do it automatically.
 Even so, it is best not to find out that
 yours does not.
*/
void    print_list( lista  *L )
{
/*1*/       if( L != NULL )
{
/*2*/            print_element( L->element );
/*3*/            print_list( L -> next );
}
}
Ejemplo n.º 4
0
//============================================
//  楕円曲線の確認用
//============================================
void test_feature(const EC_GROUP ec)
{
    fprintf(stdout, "---\n");
    fprintf(stdout, "Elliptic Curve Type: %s\n", curve_get_name(ec));
    fprintf(stdout, "   Y^2 = X^3 + aX + b\n");
    fprintf(stdout, "   a: ");
    print_element(ec->a);
    fprintf(stdout, "   b: ");
    print_element(ec->b);
    gmp_fprintf(stdout, "   field order: %Zx^%d\n", *field_get_char(ec->field), field_get_degree(ec->field));
    fprintf(stdout, "   generator of curve: ");
    print_point(ec->generator);
    gmp_fprintf(stdout, "   order: %Zx\n", ec->order);
    gmp_fprintf(stdout, "   trace: %Zx\n", ec->trace);
    gmp_fprintf(stdout, "   cofactor: %Zx\n", ec->cofactor);
    fprintf(stdout, "---\n");
}
Ejemplo n.º 5
0
void print_set(scp_operand set) {
	set.param_type = SCP_FIXED;
	scp_operand arc, element;
	MAKE_DEFAULT_ARC_ASSIGN(arc);
	MAKE_DEFAULT_OPERAND_ASSIGN(element);
	scp_iterator3 *iterator = scp_iterator3_new(s_default_ctx, &set, &arc, &element);
	while(SCP_RESULT_TRUE == scp_iterator3_new(s_default_ctx, &set, &arc, &element))
		print_element(element);
}
Ejemplo n.º 6
0
/**
 * @brief Return the XML representation of a XmlDocument.
 */
std::string XmlWriter::to_string( const XmlDocument& document )
{
    std::string res = "";
    if (!document.xml_tag.empty() || !document.declarations.empty()) {
        res = "<?" + document.xml_tag + print_attributes_list(document.declarations) + "?>\n";
    }
    print_element(res, &document, 0);
    return res + "\n";
}
Ejemplo n.º 7
0
int picreate (int credCreate, void *(*start)(void*), void *arg){
  //printf("DBG - chamado picriate(). ID: %d\n", id);
  if (inicializada != 0) //Primeira chamada a funcao.
  {
    printf("DBG - Inicializando biblioteca - thread main.\n");
    tcb[id] = (TCB_t *) malloc(sizeof(TCB_t)); //Aloca TCB da main
    //*/Ajusta o TCB da main/*/
    tcb[id]->tid = 0;
    tcb[id]->state = 1; //Criada
    //TCBmain->context = context;
    tcb[id]->credCreate = 100;
    tcb[id]->credReal = 100;
    tcb[id]->next = NULL;
    tcb[id]->prev = NULL;
    //printf("Contexto da main construido.\n");
    //*/Ajusta o TCB da main/*/
    //getcontext(&context); //Salva o contexto da main
    //printf("Primeiro ID: %d\n", id);
    inicializada = 0;
    getcontext(&(tcb[id]->context)); //Salva o contexto da main
    //print_element(tcb[id]);
    //tcb[id]->context = context;
    printf("Contexto da main construido.\n");
  }

  printf("Criando nova thread. ");
  //printf("Executando picreate na biblioteca. Creditos: %d\n", credCreate);
  id = id+1;
  printf("Incrementado ID.\n");
  tcb[id] = (TCB_t *) malloc(sizeof(TCB_t)); //Aloca um novo TCB
  tcb[id]->tid = id;
  tcb[id]->state = 1;
  tcb[id]->credCreate = credCreate;
  tcb[id]->credReal = credCreate;
  //tcb[id]->context = context;
  tcb[(id-1)]->next = tcb[id];
  tcb[id]->prev = tcb[id-1];
  tcb[id]->next = NULL;
  //getcontext(&context); //Salva o contexto da main
  //getcontext(&(tcb[id]->context));
  //thrcontext.uc_link = NULL;
  thrcontext.uc_link = &context;
  thrcontext.uc_stack.ss_sp = thr_stack;
  thrcontext.uc_stack.ss_size = sizeof(thr_stack);
  //printf("argumento = 0x%08x\n",*(int*)arg);
  //makecontext(&(tcb[id]->context), (void (*)(void)) start, 1, arg);
  //tcb[id]->context = thrcontext;
  //swapcontext(&context, &thrcontext);
  //setcontext(&thrcontext);
  //TCBmain->context = context;
  //setcontext(&context);
  //void dispatcher();
  //printf("Saindo do create() com ID=%d\n", id);
  print_element(tcb[id]);
  return id;
}
	int print_array ()
	{
		for (int i = 0; i < datalen; i ++)
		{
			print_element (i);
			printf (" ");
		}
	
		printf ("\n");
	
		return 1;
	}
Ejemplo n.º 9
0
/* DCE code. Must scan the entire live-out data.
   Can be used also to check the correctness of the output. */
static
void print_array(int nx,
		 DATA_TYPE POLYBENCH_1D(y,NX,nx))

{
  int i;
  char *printmat = malloc(nx*16 + 1); printmat[nx*16] = 0;

  for (i = 0; i < nx; i++)
    print_element(y[i], i*16, printmat);
  fputs(printmat, stderr);
  free(printmat);
}
Ejemplo n.º 10
0
/* DCE code. Must scan the entire live-out data.
   Can be used also to check the correctness of the output. */
static
void print_array(int ni, int nj,
		 DATA_TYPE POLYBENCH_2D(C,NI,NJ,ni,nj))
{
  int i, j;
  char *printmat = malloc(nj*8);

  for (i = 0; i < ni; i++) {
    for (j = 0; j < nj; j++)
      print_element(C[i][j], j*8, printmat);
    fputs(printmat, stderr);
  }
  free(printmat);
}
Ejemplo n.º 11
0
gboolean
gdata_parser_error_unhandled_element (xmlNode *element, GError **error)
{
	gchar *element_string = print_element (element);

	/* Translators: the parameter is the name of an XML element, including the angle brackets ("<" and ">").
	 *
	 * For example:
	 *  Unhandled <entry/yt:aspectRatio> element. */
	g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_UNHANDLED_XML_ELEMENT, _("Unhandled %s element."), element_string);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 12
0
/* DCE code. Must scan the entire live-out data.
   Can be used also to check the correctness of the output. */
static
void print_array(int ni,
		 DATA_TYPE POLYBENCH_2D(B,NI,NI,ni,ni))
{
  int i, j;
  char *printmat = malloc(ni*16 + 1); printmat[ni*16] = 0;

  for (i = 0; i < ni; i++) {
    for (j = 0; j < ni; j++)
      print_element(B[i][j], j*16, printmat);
    fputs(printmat, stderr);
  }
  free(printmat);
}
Ejemplo n.º 13
0
gboolean
gdata_parser_error_required_content_missing (xmlNode *element, GError **error)
{
	gchar *element_string = print_element (element);

	/* Translators: the parameter is the name of an XML element, including the angle brackets ("<" and ">").
	 *
	 * For example:
	 *  A <title> element was missing required content. */
	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR, _("A %s element was missing required content."), element_string);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 14
0
gboolean
gdata_parser_error_duplicate_element (xmlNode *element, GError **error)
{
	gchar *element_string = print_element (element);

	/* Translators: the parameter is the name of an XML element, including the angle brackets ("<" and ">").
	 *
	 * For example:
	 *  A singleton element (<feed/title>) was duplicated. */
	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR, _("A singleton element (%s) was duplicated."), element_string);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 15
0
static void
print_element (scew_element *element, unsigned int indent)
{
  XML_Char const *contents = NULL;
  scew_list *list = NULL;

  if (element == NULL)
    {
      return;
    }

  /* Prints the starting element tag with its attributes. */
  print_indent (indent);
  scew_printf (_XT("<%s"), scew_element_name (element));
  print_attributes (element);
  scew_printf (_XT(">"));

  contents = scew_element_contents (element);

  if (contents == NULL)
    {
      scew_printf (_XT("\n"));
    }

  /**
   * Call print_element function again for each child of the current
   * element.
   */
  list = scew_element_children (element);
  while (list != NULL)
    {
      scew_element *child = scew_list_data (list);
      print_element (child, indent + 1);
      list = scew_list_next (list);
    }

  /* Prints element's content. */
  if (contents != NULL)
    {
      scew_printf (_XT("%s"), contents);
    }
  else
    {
      print_indent (indent);
    }

  /* Prints the closing element tag. */
  scew_printf (_XT("</%s>\n"), scew_element_name (element));
}
Ejemplo n.º 16
0
/* DCE code. Must scan the entire live-out data.
   Can be used also to check the correctness of the output. */
static
void print_array(int n,
		 DATA_TYPE POLYBENCH_2D(A,N,N,n,n))

{
  int i, j;
  char *printmat = malloc(n*8);

  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      print_element(A[i][j], j*8, printmat);
    fputs(printmat, stderr);
  }
  free(printmat);
}
Ejemplo n.º 17
0
gboolean
gdata_parser_error_not_iso8601_format (xmlNode *element, const gchar *actual_value, GError **error)
{
	gchar *element_string = print_element (element);
	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
		     /* Translators: the first parameter is the name of an XML element (including the angle brackets ("<" and ">")), and the second parameter is
		      * the erroneous value (which was not in ISO 8601 format).
		      *
		      * For example:
		      *  The content of a <media:group/media:uploaded> element ("2009-05-06 26:30Z") was not in ISO 8601 format. */
		     _("The content of a %s element (\"%s\") was not in ISO 8601 format."), element_string, actual_value);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 18
0
gboolean
gdata_parser_error_unknown_content (xmlNode *element, const gchar *actual_content, GError **error)
{
	gchar *element_string = print_element (element);

	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
	             /* Translators: the first parameter is the name of an XML element (including the angle brackets ("<" and ">")),
	              * and the second parameter is the unknown content of that element.
	              *
	              * For example:
	              *  The content of a <gphoto:access> element ("protected") was unknown. */
	             _("The content of a %s element (\"%s\") was unknown."), element_string, actual_content);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 19
0
void *
thread_it(void *p)
{
	struct xmlsd_document		*xd;
	struct xmlsd_element		*xe;
	int				f;
	char				*b, *filename = (char *)p;
	struct stat			sb;

	if (xmlsd_doc_alloc(&xd) != XMLSD_ERR_SUCCES)
		errx(1,"xmlsd_doc_alloc");

	f = open(filename, O_RDONLY, 0);
	if (f == -1)
		err(1, "open");
	if (fstat(f, &sb) == -1)
		err(1, "stat");
	if (sb.st_size > XMLSD_MEM_MAXSIZE)
		errx(1, "file too big");
	b = malloc(sb.st_size);
	if (b == NULL)
		err(1, "malloc");
	memset(b, 0, sb.st_size);
	if (read(f, b, sb.st_size) != sb.st_size)
		err(1, "read");

	if (xmlsd_parse_mem(b, sb.st_size, xd) != XMLSD_ERR_SUCCES)
		errx(1, "xmlsd_parse");
	if (verbose) {
		if ((xe = xmlsd_doc_get_first_elem(xd)) != NULL)
			print_element(xe);
	}

	xmlsd_doc_free(xd);

	free(b);
	close(f);
	f = 0;

	pthread_mutex_lock(&mtx);
	completed++;
	pthread_mutex_unlock(&mtx);

	return (NULL);
}
Ejemplo n.º 20
0
static void
print_element(struct xmlsd_element *xe)
{
	struct xmlsd_element		*xc;
	struct xmlsd_attribute		*xa;

	fprintf(stderr, "%d %s = %s (parent = %s)\n",
	    xmlsd_elem_get_depth(xe),
	    xmlsd_elem_get_name(xe),
	    xmlsd_elem_get_value(xe) ? xmlsd_elem_get_value(xe) : "NOVAL",
	    xmlsd_elem_get_parent(xe) ?
	        xmlsd_elem_get_name(xmlsd_elem_get_parent(xe)) :"NOPARENT");
	XMLSD_ELEM_FOREACH_ATTR(xa, xe)
		fprintf(stderr, "\t%s = %s\n", xmlsd_attr_get_name(xa),
		    xmlsd_attr_get_value(xa));
	XMLSD_ELEM_FOREACH_CHILDREN(xc, xe)
		print_element(xc);
}
Ejemplo n.º 21
0
/*
 * fonction qui retourne un tableau d'entier trier en ordre décroissant.
 * @param tab un tableau de structure Element 
 * @param size un entier représentant la taille de tab 
 */
void get_tab_trier(struct Element tab[], int size)
{
   int tableau_taille[size];
  
   for(int i = 0; i<size; i++)
    tableau_taille[i] = tab[i].taille_element;
     
   tri_bulle(tableau_taille,size);

   for(int i = 0; i < size; i++)
       for(int j = 0; j < size; j++)
       {
         if(tableau_taille[i] == tab[j].taille_element && tab[i].file_path != NULL)
         {
          print_element(tableau_taille[i], tab[j].file_path);
          break;
         }
       }
};
Ejemplo n.º 22
0
gboolean
gdata_parser_error_unknown_property_value (xmlNode *element, const gchar *property_name, const gchar *actual_value, GError **error)
{
	gchar *property_string, *element_string;

	property_string = g_strdup_printf ("@%s", property_name);
	element_string = print_element (element);

	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
		     /* Translators: the first parameter is the name of an XML property, the second is the name of an XML element
		      * (including the angle brackets ("<" and ">")) to which the property belongs, and the third is the unknown value.
		      *
		      * For example:
		      *  The value of the @time property of a <media:group/media:thumbnail> element ("00:01:42.500") was unknown. */
		     _("The value of the %s property of a %s element (\"%s\") was unknown."), property_string, element_string, actual_value);
	g_free (property_string);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 23
0
gboolean
gdata_parser_error_required_property_missing (xmlNode *element, const gchar *property_name, GError **error)
{
	gchar *property_string, *element_string;

	property_string = g_strdup_printf ("@%s", property_name);
	element_string = print_element (element);

	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
		     /* Translators: the first parameter is the name of an XML element (including the angle brackets ("<" and ">")),
		      * and the second is the name of an XML property which it should have contained.
		      *
		      * For example:
		      *  A required property of a <entry/gAcl:role> element (@value) was not present. */
		     _("A required property of a %s element (%s) was not present."), property_string, element_string);
	g_free (property_string);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 24
0
/**
 * @brief Print an XML element.
 */
void XmlWriter::print_element (std::string& xml, const XmlElement* value, const int indent_level)
{
    // Prepare indention and opening tag.
    std::string in0 (indent_level * indent, ' ');
    xml += in0 + "<" + value->tag + print_attributes_list(value->attributes);

    // If it's an empty element, close it, and we are done.
    if (value->content.size() == 0) {
        xml += " />";
        return;
    }

    // If the element only contains a single markup, don't add new lines. However, if it contains
    // more data, put each element in a new line.
    xml += ">";
    if (value->content.size() == 1 && value->content[0]->is_markup()) {
        print_markup(xml, xml_value_to_markup(value->content[0].get()));
    } else {
        std::string in1 ((indent_level + 1) * indent, ' ');
        xml += "\n";

        for (auto& v : value->content) {
            if (v->is_comment()) {
                xml += in1;
                print_comment(xml, xml_value_to_comment(v.get()));
            } else if (v->is_markup()) {
                xml += in1;
                print_markup(xml, xml_value_to_markup(v.get()));
            } else if (v->is_element()) {
                print_element(xml, xml_value_to_element(v.get()), indent_level + 1);
            } else {
                // there are no other cases
                assert(0);
            }
            xml += "\n";
        }
        xml += in0;
    }

    xml += "</" + value->tag + ">";
}
Ejemplo n.º 25
0
static void	ft_print_elems_in_columns(t_select *env)
{
	t_dlst			*tmp;
	unsigned int	i;
	size_t			e;

	i = 0;
	tmp = env->page.start_page_element;
	while (tmp && i < env->page.elems_per_page)
	{
		e = 0;
		while (tmp && e < env->page.columns_infos.column_nb)
		{
			++e;
			print_element(env, (t_elem*)tmp->content);
			tmp = tmp->next;
			++i;
		}
		if (i != env->page.elems_per_page && tmp)
			ft_bufferize(STDIN_FILENO, "\n", 0);
	}
}
Ejemplo n.º 26
0
void
print_tuple(struct tuple *s)
{
	int i, n, flag = 0;
	if (logptr >= LOGBUFSIZE-128)
		return;
	logptr += sprintf(logbuf + logptr, "(");
	n = s->num_elts;
	assert(n);
	if (n > 10) {
		n = 10;
		flag = 1;
	}
	for (i = 0; i < n; i++) {
		if (i > 0) logptr += sprintf(logbuf + logptr, ", ");
		print_element(&s->elements[i]);
	}
	if (flag) {
		logptr += sprintf(logbuf + logptr, ".... ");
	}
	logptr += sprintf(logbuf + logptr, ")\n");
}
Ejemplo n.º 27
0
gboolean
gdata_parser_error_mutexed_properties (xmlNode *element, const gchar *property1_name, const gchar *property2_name, GError **error)
{
	gchar *property1_string, *property2_string, *element_string;

	property1_string = g_strdup_printf ("@%s", property1_name);
	property2_string = g_strdup_printf ("@%s", property2_name);
	element_string = print_element (element);

	g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_PROTOCOL_ERROR,
	             /* Translators: the first two parameters are the names of XML properties of an XML element given in the third
	              * parameter (including the angle brackets ("<" and ">")).
	              *
	              * For example:
	              *  Values were present for properties @rel and @label of a <entry/gContact:relation> element when only one of the
	              *  two is allowed. */
	             _("Values were present for properties %s and %s of a %s element when only one of the two is allowed."),
	             property1_string, property2_string, element_string);
	g_free (property1_string);
	g_free (property2_string);
	g_free (element_string);

	return FALSE;
}
Ejemplo n.º 28
0
static void bt_print_struct_node(bt* tree, bt_node* node, char* indent,
                                 void (*print_element)(void* val)) {

    printf("%s", indent);
    if (!isleaf(node)) {
        char* subind;
        char* addind = "|--";
        printf("(bal %i)\n", node->branch.balance);
        subind = malloc(strlen(indent) + strlen(addind) + 1);
        sprintf(subind, "%s%s", indent, addind);
        bt_print_struct_node(tree, node->branch.children[0], subind, print_element);
        bt_print_struct_node(tree, node->branch.children[1], subind, print_element);
    } else {
        int i;
        printf("(leaf)");
        if (print_element) {
            printf(" [ ");
            for (i=0; i<node_N(node); i++)
                print_element(get_element(tree, &node->leaf, i));
            printf("]");
        }
        printf("\n");
    }
}
Ejemplo n.º 29
0
/* 
 * Main function. 
 */ 
int main(int argc, char **argv) 
{ 
  uFlags = 0; 

  progname = argv[0]; 

  while (--argc > 0 && **(++argv) == '-') { 
    while (*(++(*argv))) { 
      switch (**argv) { 
        case 'a': 
          uFlags = (SYSNAME | NODENAME | RELEASE | ARCH | 
                    VERSION | MACHINE); 
          break; 
        case 'm': uFlags |= MACHINE;  break; 
        case 'n': uFlags |= NODENAME; break; 
        case 'p': uFlags |= ARCH;     break; 
        case 'r': uFlags |= RELEASE;  break; 
        case 's': uFlags |= SYSNAME;  break; 
        case 'v': uFlags |= VERSION;  break; 
        default: usage(); 
      } 
    } 
  } 

  if (uFlags == 0) 
    uFlags = SYSNAME; 

  detectOpSysVersion(); 
  detectHardware(); 

  print_element(SYSNAME,  sysname); 
  print_element(NODENAME, nodename); 
  print_element(RELEASE,  release); 
  print_element(VERSION,  version); 
  print_element(MACHINE,  machine); 
  print_element(ARCH,     processor); 

  exit(EXIT_SUCCESS); 
} 
Ejemplo n.º 30
0
int
main (int argc, char *argv[])
{
  scew_reader *reader = NULL;
  scew_parser *parser = NULL;
  scew_tree *tree = NULL;
  scew_writer *writer = NULL;
  scew_printer *printer = NULL;

#if defined(_MSC_VER) && defined(XML_UNICODE_WCHAR_T)
  /* Change stdout to Unicode before writing anything. */
  _setmode(_fileno(stdout), _O_U16TEXT);
#endif /* _MSC_VER && XML_UNICODE_WCHAR_T */

  if (argc < 2)
    {
      scew_printf (_XT("Usage: scew_print file.xml\n"));
      return EXIT_FAILURE;
    }

  /* Creates an SCEW parser. This is the first function to call. */
  parser = scew_parser_create ();

  scew_parser_ignore_whitespaces (parser, SCEW_TRUE);

  /* Loads an XML file. */
  reader = scew_reader_file_create (argv[1]);
  if (reader == NULL)
    {
      scew_error code = scew_error_code ();
      scew_printf (_XT("Unable to load file (error #%d: %s)\n"),
                   code, scew_error_string (code));
      return EXIT_FAILURE;
    }

  tree = scew_parser_load (parser, reader);
  if (tree == NULL)
    {
      scew_error code = scew_error_code ();
      scew_printf (_XT("Unable to parse file (error #%d: %s)\n"),
                   code, scew_error_string (code));
      if (code == scew_error_expat)
        {
          enum XML_Error expat_code = scew_error_expat_code (parser);
          scew_printf (_XT("Expat error #%d (line %d, column %d): %s\n"),
                       expat_code,
                       scew_error_expat_line (parser),
                       scew_error_expat_column (parser),
                       scew_error_expat_string (expat_code));
        }

      /* Frees the SCEW parser and reader. */
      scew_reader_free (reader);
      scew_parser_free (parser);

      return EXIT_FAILURE;
    }

  /* Prints full tree. */
  scew_printf (_XT("\n*** Manual print:\n\n"));
  print_element (scew_tree_root (tree), 0);

  /* Prints full tree using SCEW writer. */
  scew_printf (_XT("\n\n*** SCEW writer (stdout) print:\n\n"));

  writer = scew_writer_fp_create (stdout);
  printer = scew_printer_create (writer);
  scew_printer_print_tree (printer, tree);
  scew_printf (_XT("\n"));

  /* Remember to free tree (scew_parser_free does not free it). */
  scew_tree_free (tree);

  /* Also free the printer and writer. */
  scew_writer_free (writer);
  scew_printer_free (printer);

  /* Frees the SCEW parser and reader. */
  scew_reader_free (reader);
  scew_parser_free (parser);

  return 0;
}