Exemple #1
0
int parse_data_module( DATAModule *module ) {
  int data_count;
  bool fatalError = TRUE; // if true, catch leads to exit(-1)
  try {
    data_count = module->datas_count;
    for ( int i = 0; i < module->datas_count; i++ ) {
      DataContext ctx; data_context = &ctx;

      const char *tagName = module->datas[i]->tag->image;
      const int tagId = find_tag( tagName );
      if ( DATA_VERBOSE > 4 ) {
	printf("tagName: %s  tagId: %d\n\r", tagName, tagId );
      }
      switch ( tagId ) {
      case TAG_Prereq: parse_prerequisite( module->datas[i] ); break;
      case TAG_BrewFormula: 
	create_brew_formula_table( module->datas_count ); 
	parse_brew_formula( module->datas[i] ); 
	break;
      case TAG_Ban: parse_ban( module->datas[i] ); break;
      case TAG_Command:
	create_command_table( module->datas_count );
	parse_command( module->datas[i] );
	break;
      case TAG_Unique: parse_unique( module->datas[i] ); break;
      case TAG_Disable: parse_disabled( module->datas[i] ); break;
      case TAG_Material: 
	create_material_table( module->datas_count );
	parse_material( module->datas[i] );
	break;
      case TAG_Liquid:
	create_liquid_table( module->datas_count );
	parse_liquid( module->datas[i] );
	break;
      case TAG_God:
	create_god_table( module->datas_count );
	parse_god( module->datas[i] );
	break;
      case TAG_Clan: parse_clan( module->datas[i] ); break;
      case TAG_Faction:
	create_faction_table( module->datas_count, module );
	parse_faction( module->datas[i] );
	break;
      case TAG_Race:
	create_races_table( module->datas_count );
	parse_race( module->datas[i] );
	break;
      case TAG_PCRace:
	create_pcraces_table( module->datas_count );
	parse_pcrace( module->datas[i] );
	break;
      case TAG_Sphere:
	create_spheres_table( module->datas_count );
	parse_sphere( module->datas[i] );
	break;
      case TAG_Group:
	create_groups_table( module->datas_count );
	parse_groups( module->datas[i] );
	break;
      case TAG_Ability: parse_abilities( module->datas[i] ); break;
      case TAG_Class: 
	create_classes_table( module->datas_count );
	parse_classes( module->datas[i] );
	break;
      case TAG_Player: 
	fatalError = FALSE;
	parse_player( module->datas[i] );
	fatalError = TRUE;
	break;
      case TAG_Area: parse_area( module->datas[i] ); break;
      case TAG_Config:
	if ( parse_config( module->datas[i] ) )  // once we have found the right config: skip others
	  return data_count;
	break;
      case TAG_AreaState: parse_area_state( module->datas[i] ); break;
      case TAG_Time: parse_time( module->datas[i] ); break;
      case TAG_Hometown:
	create_hometown_table( module->datas_count );
	parse_hometown( module->datas[i] );
	break;
      case TAG_School:
	create_school_table( module->datas_count );
	parse_school( module->datas[i] );
	break;
      case TAG_Super_Race:
	create_super_race_table( module->datas_count );
	parse_super_race( module->datas[i] );
	break;

      default: p_error("Invalid Tag: %s", tagName ); break;
      }

    }
  } catch (ScriptException e) {
    bug("Error while parsing datas. %s", e.msg );
    if ( fatalError ) {
      bug("FATAL error. Bye!");
      exit(-1);
    }
    else
      return -1;
  }

  dump_GC_info();

  return data_count;
}
static void
handle_context_element (ParserState *parser_state)
{
	gchar *id, *parent_id, *style_ref;
	xmlChar *ref, *sub_pattern, *tmp;
	int is_empty;
	gboolean success;
	gboolean ignore_style = FALSE;
	GtkSourceContextRefOptions options = 0;
	GSList *context_classes;

	GError *tmp_error = NULL;

	g_return_if_fail (parser_state->error == NULL);

	ref = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "ref");
	sub_pattern = xmlTextReaderGetAttribute (parser_state->reader,
						 BAD_CAST "sub-pattern");

	tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "ignore-style");
	if (tmp != NULL && str_to_bool (tmp))
		ignore_style = TRUE;
	xmlFree (tmp);

	tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "style-ref");
	if (tmp == NULL || id_is_decorated ((gchar*) tmp, NULL))
		style_ref = g_strdup ((gchar*) tmp);
	else
		style_ref = decorate_id (parser_state, (gchar*) tmp);
	xmlFree (tmp);

	if (ignore_style && ref == NULL)
	{
		g_set_error (&parser_state->error,
			     PARSER_ERROR,
			     PARSER_ERROR_WRONG_STYLE,
			     "ignore-style used not in a reference to context");

		xmlFree (ref);
		g_free (style_ref);

		return;
	}

	if (ignore_style)
	{
		options |= GTK_SOURCE_CONTEXT_IGNORE_STYLE;

		if (style_ref != NULL)
			g_warning ("in file %s: style-ref and ignore-style used simultaneously",
				   parser_state->filename);
	}

	/* XXX */
	if (!ignore_style && style_ref != NULL &&
	    g_hash_table_lookup (parser_state->styles_mapping, style_ref) == NULL)
	{
		g_warning ("in file %s: style '%s' not defined", parser_state->filename, style_ref);
	}

	context_classes = parse_classes (parser_state);

	if (ref != NULL)
	{
		tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "original");
		if (tmp != NULL && str_to_bool (tmp))
			options |= GTK_SOURCE_CONTEXT_REF_ORIGINAL;
		xmlFree (tmp);

		if (style_ref != NULL)
			options |= GTK_SOURCE_CONTEXT_OVERRIDE_STYLE;

		add_ref (parser_state,
		         (gchar*) ref,
		         options,
		         style_ref,
		         &tmp_error);
	}
	else
	{
		char *freeme = NULL;

		tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "id");
		if (tmp == NULL)
		{
			freeme = generate_new_id (parser_state);
			tmp = xmlStrdup (BAD_CAST freeme);
		}

		if (id_is_decorated ((gchar*) tmp, NULL))
			id = g_strdup ((gchar*) tmp);
		else
			id = decorate_id (parser_state, (gchar*) tmp);

		g_free (freeme);
		xmlFree (tmp);

		if (parser_state->ctx_data != NULL)
		{
			if (sub_pattern != NULL)
			{
				create_sub_pattern (parser_state,
				                    id,
				                    (gchar *)sub_pattern,
				                    style_ref,
				                    context_classes,
				                    &tmp_error);
			}
			else
			{
				parent_id = g_queue_peek_head (
						parser_state->curr_parents);

				is_empty = xmlTextReaderIsEmptyElement (
						parser_state->reader);

				if (is_empty)
					success = _gtk_source_context_data_define_context (parser_state->ctx_data,
											   id,
											   parent_id,
											   "$^",
											   NULL,
											   NULL,
											   NULL,
											   NULL,
											   0,
											   &tmp_error);
				else
					success = create_definition (parser_state,
					                             id,
					                             parent_id,
					                             style_ref,
					                             context_classes,
					                             &tmp_error);

				if (success && !is_empty)
				{
					/* Push the new context in the curr_parents
					 * stack only if other contexts can be
					 * defined inside it */
					g_queue_push_head (parser_state->curr_parents,
							   g_strdup (id));
				}
			}
		}

		g_free (id);
	}

	g_slist_free_full (context_classes, (GDestroyNotify)gtk_source_context_class_free);

	g_free (style_ref);
	xmlFree (sub_pattern);
	xmlFree (ref);

	if (tmp_error != NULL)
		g_propagate_error (&parser_state->error, tmp_error);
}