示例#1
0
struct result_queue* result_queue_new(GMainContext* context,
                                      result_queue_handler_f handler,
                                      gpointer userdata)
{
        struct result_queue *queue;

        g_return_val_if_fail(handler!=NULL, NULL);

        queue = (struct result_queue *)
                g_source_new(&source_functions,
                             sizeof(struct result_queue));
        queue->async_queue=g_async_queue_new();
        queue->handler=handler;
        queue->main_context=context;
        queue->userdata=userdata;

        g_source_set_callback(SOURCE(queue),
                              source_callback,
                              NULL/*data*/,
                              NULL/*notify*/);

        g_source_attach(SOURCE(queue), context);

        result_queue_counter++;
        return queue;
}
示例#2
0
文件: graph.c 项目: 8l/csolve
Vertices *
GenTree(int nVertex)
{
  int       i;
  int       weight;
  Vertices * vertex;
  Vertices * graph;
  Edges * edge;

  graph = NewVertex();
  NEXT_VERTEX(graph) = graph;

  for(i = 1; i < nVertex; i++)
  {
    vertex = NewVertex();
    edge = NewEdge();

    /*
     * The newly created vertex has one edge ...
     */
    EDGES(vertex) = edge;

    /*
     * ... which is connected to the graph so far generated.  The connection
     * point in the graph is picked at random.
     */
    VERTEX(edge) = PickVertex(graph, random() % i);
    weight = GET_WEIGHT;
    WEIGHT(edge) = weight;
    SOURCE(edge) = vertex;

    /*
     * Link the new vertex into the graph.
     */
    NEXT_VERTEX(vertex) = NEXT_VERTEX(graph);
    NEXT_VERTEX(graph) = vertex;

    /*
     * Add an edge to the vertex randomly picked as the connection point.
     */
    edge = NewEdge();
    WEIGHT(edge) = weight;
    SOURCE(edge) = VERTEX(EDGES(vertex));
    VERTEX(edge) = vertex;
    NEXT_EDGE(edge) = EDGES(VERTEX(EDGES(vertex)));
    EDGES(VERTEX(EDGES(vertex))) = edge;
   }

  return(graph);
}
示例#3
0
文件: test-xml.c 项目: vilkov/xml.c
/**
 * Tries to parse a document containing multiple tags
 */
static void test_xml_parse_document_1() {
	SOURCE(source, ""
		"<Parent>\n"
		"\t<Child>\n"
		"\t\tFirst content\n"
		"\t</Child>\n"
		"\t<Child>\n"
		"\t\tSecond content\n"
		"\t</Child>\n"
		"</Parent>\n"
	);
	struct xml_document* document = xml_parse_document(source, strlen(source));
	assert_that(document, "Could not parse document");

	struct xml_node* root = xml_document_root(document);
//	assert_that(string_equals(xml_node_name(root), "Parent"), "root node name must be `Parent'");
	assert_that(2 == xml_node_children(root), "root must have two children");

	struct xml_node* first_child = xml_node_child(root, 0);
	struct xml_node* second_child = xml_node_child(root, 1);
	assert_that(first_child && second_child, "Failed retrieving the children of root");

	struct xml_node* third_child = xml_node_child(root, 2);
	assert_that(!third_child, "root has a third child where non should be");

//	assert_that(string_equals(xml_node_name(first_child), "Child"), "first_child node name must be `Child'");
//	assert_that(string_equals(xml_node_content(first_child), "First content"), "first_child node content must be `First content'");
//	assert_that(string_equals(xml_node_name(second_child), "Child"), "second_child node name must be `Child'");
//	assert_that(string_equals(xml_node_content(second_child), "Second content"), "second_child node content must be `tSecond content'");

	xml_document_free(document, true);
}
示例#4
0
文件: xaaBitmap.c 项目: aosm/X11
static CARD32*
BitmapScanline(
   CARD32 *src, CARD32 *dest,
   int count, int skipleft )
{
   while(count >= 4) {
	DEST(0) = SOURCE(0);
	DEST(1) = SOURCE(1);
	DEST(2) = SOURCE(2);
	DEST(3) = SOURCE(3);
	count -= 4;
	src += 4;
#ifndef FIXEDBASE
	dest += 4;
#endif
   }
   
   if(!count) return dest;
   DEST(0) = SOURCE(0);
   if(count == 1) RETURN(1);
   DEST(1) = SOURCE(1);
   if(count == 2) RETURN(2);
   DEST(2) = SOURCE(2);
   RETURN(3);
}
示例#5
0
文件: yapi.cpp 项目: vscosta/yap-6.3
Term YAPListTerm::cdr() {
  Term to = gt();
  if (IsPairTerm(to))
    return (TailOfTerm(to));
  else if (to == TermNil)
    return TermNil;
  /* error */
  throw YAPError(SOURCE(), TYPE_ERROR_LIST, to, "");
}
示例#6
0
文件: yapi.cpp 项目: vscosta/yap-6.3
Term YAPListTerm::car() {
  Term to = gt();
  if (IsPairTerm(to))
    return (HeadOfTerm(to));
  else {
    throw YAPError(SOURCE(), TYPE_ERROR_LIST, to, "");
    return TermUnique;
  }
}
示例#7
0
文件: graph.c 项目: 8l/csolve
void
PrintNeighbors(Vertices * vertex)
{
  Edges * edge;

  edge = EDGES(vertex);
  while(edge != NULL)
  {
    printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge)));
    edge = NEXT_EDGE(edge);
  }
}
示例#8
0
文件: yapi.cpp 项目: vscosta/yap-6.3
Term YAPTerm::getArg(arity_t i) {
  BACKUP_MACHINE_REGS();
  Term tf = 0;
  Term t0 = gt();

  if (IsApplTerm(t0)) {
    if (i > ArityOfFunctor(FunctorOfTerm(t0)))
      throw YAPError(SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()");
    tf = (ArgOfTerm(i, t0));
  } else if (IsPairTerm(t0)) {
    if (i == 1)
      tf = (HeadOfTerm(t0));
    else if (i == 2)
      tf = (TailOfTerm(t0));
    else
      throw YAPError(SOURCE(), DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()");
  } else {
    throw YAPError(SOURCE(), TYPE_ERROR_COMPOUND, t0, "t0.getArg()");
  }
  RECOVER_MACHINE_REGS();
  return tf;
}
示例#9
0
void result_queue_delete(struct result_queue* queue)
{
        GSource *source;
        g_return_if_fail(queue);

        source=SOURCE(queue);
        g_source_destroy(source);
        g_source_unref(source);
        /* resources are only released by source_finalize(),
         * caled by g_source_unref() whenever it thinks
         * there are no more references to the source.
         */
}
示例#10
0
文件: graph.c 项目: 8l/csolve
void
Connect(Vertices * vertex1, Vertices * vertex2)
{
  int    weight;
  Edges * edge;

  weight = GET_WEIGHT;

  edge = NewEdge();
  WEIGHT(edge) = weight;
  SOURCE(edge) = vertex1;
  VERTEX(edge) = vertex2;
  NEXT_EDGE(edge) = EDGES(vertex1);
  EDGES(vertex1) = edge;
  
  edge = NewEdge();
  WEIGHT(edge) = weight;
  SOURCE(edge) = vertex2;
  VERTEX(edge) = vertex1;
  NEXT_EDGE(edge) = EDGES(vertex2);
  EDGES(vertex2) = edge;
}
示例#11
0
文件: yapi.cpp 项目: vscosta/yap-6.3
YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) {
  Term t0 = t;
  ap = nullptr;
restart:
  if (IsVarTerm(t)) {
    throw YAPError(SOURCE(), INSTANTIATION_ERROR, t0, pname);
  } else if (IsAtomTerm(t)) {
    ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod));
    ts = nullptr;
  } else if (IsIntegerTerm(t) && tmod == IDB_MODULE) {
    ts = nullptr;
    ap = Yap_FindLUIntKey(IntegerOfTerm(t));
  } else if (IsPairTerm(t)) {
    t = Yap_MkApplTerm(FunctorCsult, 1, &t);
    goto restart;
  } else if (IsApplTerm(t)) {
    Functor fun = FunctorOfTerm(t);
    if (IsExtensionFunctor(fun)) {
      throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE,
                     Yap_TermToIndicator(t, tmod), pname);
    }
    if (fun == FunctorModule) {
      tmod = ArgOfTerm(1, t);
      if (IsVarTerm(tmod)) {
        throw YAPError(SOURCE(), INSTANTIATION_ERROR, t0, pname);
      }
      if (!IsAtomTerm(tmod)) {
        throw YAPError(SOURCE(), TYPE_ERROR_ATOM, t0, pname);
      }
      t = ArgOfTerm(2, t);
      goto restart;
    }
    ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod));
    ts = RepAppl(t) + 1;
  } else {
    throw YAPError(SOURCE(), TYPE_ERROR_CALLABLE, t0, pname);
  }
}
示例#12
0
文件: yapi.cpp 项目: vscosta/yap-6.3
std::vector<YAPTerm> YAPPairTerm::listToVector() {
  Term *tailp;
  Term t1 = gt();
  Int l = Yap_SkipList(&t1, &tailp);
  if (l < 0) {
    throw YAPError(SOURCE(), TYPE_ERROR_LIST, (t), nullptr);
  }
  std::vector<YAPTerm> o = *new std::vector<YAPTerm>(l);
  int i = 0;
  Term t = gt();
  while (t != TermNil) {
    o[i++] = YAPTerm(HeadOfTerm(t));
    t = TailOfTerm(t);
  }
  return o;
}
示例#13
0
文件: test-xml.c 项目: vilkov/xml.c
/**
 * Tries to parse a simple document containing only one tag
 */
static void test_xml_parse_document_0() {
	SOURCE(source, "<Hello>World</Hello>");
//	uint8_t* source = malloc((1 + strlen("<Hello>World</Hello>")) * sizeof(uint8_t));
//	{	char const* content_string = "<Hello>World</Hello>";
//		memcpy(source, content_string, strlen("<Hello>World</Hello>") + 1);
//	}

	struct xml_document* document = xml_parse_document(source, strlen(source));
	assert_that(document, "Could not parse document");

	struct xml_node* root = xml_document_root(document);
//	assert_that(string_equals(xml_node_name(root), "Hello"), "root node name must be `Hello'");
//	assert_that(string_equals(xml_node_content(root), "World"), "root node content must be `World'");

	xml_document_free(document, true);
}
示例#14
0
文件: ft.c 项目: 8l/csolve
void
PrintMST(Vertices * graph)
{
  Vertices * vertex;

  assert(graph != NULL_VERTEX);

  vertex = NEXT_VERTEX(graph);

  while(vertex != graph)
  {
    printf("vertex %d to %d\n", ID(vertex), ID(SOURCE(CHOSEN_EDGE(vertex))));
    vertex = NEXT_VERTEX(vertex);
  }

}
示例#15
0
文件: test-xml.c 项目: vilkov/xml.c
/**
 * Tests the eas functionality
 */
static void test_xml_parse_document_2() {
	SOURCE(source, ""
		"<Parent>\n"
		"\t<Child>\n"
		"\t\tFirst content\n"
		"\t</Child>\n"
		"\t<This><Is>\n"
			"<A><Test>Content A</Test></A>\n"
			"<B><Test>Content B</Test></B>\n"
		"\t</Is></This>\n"
		"\t<Child>\n"
		"\t\tSecond content\n"
		"\t</Child>\n"
		"</Parent>\n"
	);
	struct xml_document* document = xml_parse_document(source, strlen(source));
	assert_that(document, "Could not parse document");

	struct xml_node* root = xml_document_root(document);
//	assert_that(string_equals(xml_node_name(root), "Parent"), "root node name must be `Parent'");
	assert_that(3 == xml_node_children(root), "root must have two children");

	struct xml_node* test_a = xml_easy_child(root, "This", "Is", "A", "Test", 0);
	assert_that(test_a, "Cannot find Parent/This/Is/A/Test");
//	assert_that(string_equals(xml_node_content(test_a), "Content A"), "Content of Parent/This/Is/A/Test must be `Content A'");

	struct xml_node* test_b = xml_easy_child(root, "This", "Is", "B", "Test", 0);
	assert_that(test_b, "Cannot find Parent/This/Is/B/Test");
//	assert_that(string_equals(xml_node_content(test_b), "Content B"), "Content of Parent/This/Is/B/Test must be `Content B'");

	struct xml_node* test_c = xml_easy_child(root, "This", "Is", "C", "Test", 0);
	assert_that(!test_c, "Must not find Parent/This/Is/C/Test because no such path exists");

	struct xml_node* must_be_null = xml_easy_child(root, "Child");
	assert_that(!must_be_null, "Parent/Child cannot be a valid expression, because there are two children named `Child' in `Parent'");

//	uint8_t* name_is = xml_easy_name(xml_easy_child(root, "This", "Is", 0));
//	assert_that(!strcmp(name_is, "Is"), "Name of Parent/This/Is must be `Is'");
//	free(name_is);

//	uint8_t* content_a = xml_easy_content(test_a);
//	assert_that(!strcmp(content_a, "Content A"), "Content of Parent/This/Is/A/Test must be `Content A'");
//	free(content_a);

	xml_document_free(document, true);
}
示例#16
0
文件: yapi.cpp 项目: vscosta/yap-6.3
Term &YAPTerm::operator[](arity_t i) {
  BACKUP_MACHINE_REGS();
  Term t0 = gt();
  Term *tf = nullptr;
  if (IsApplTerm(t0)) {
    // Functor f = FunctorOfTerm(t0);
    // if (IsExtensionFunctor(f))
    //  return 0;
    tf = RepAppl(t0) + (i + 1);
  } else if (IsPairTerm(t0)) {
    if (i == 0)
      tf = RepPair(t0);
    else if (i == 1)
      tf = RepPair(t0) + 1;
    RECOVER_MACHINE_REGS();
  } else {
    throw YAPError(SOURCE(), TYPE_ERROR_COMPOUND, t0, "");
  }
  RECOVER_MACHINE_REGS();
  return *tf;
}
示例#17
0
/*
====================================================================
Load terrain types, weather information and hex tile icons.
====================================================================
*/
int terrain_load( char *fname )
{
    int i, j, k;
    PData *pd, *sub, *subsub, *subsubsub;
    List *entries, *flags;
    char path[512], transitionPath[512];
    char *flag, *str;
    char *domain = 0;
    int count;
    /* log info */
    int  log_dot_limit = 40; /* maximum of dots */
    char log_str[128];
    sprintf( transitionPath, "Scenario/%s", fname );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( pd = parser_read_file( fname, path ) ) == 0 ) goto parser_failure;
//    domain = determine_domain(pd, fname);
//    locale_load_domain(domain, 0/*FIXME*/);
    /* get weather */
    if ( !parser_get_entries( pd, "weather", &entries ) ) goto parser_failure;
    weather_type_count = entries->count;
    weather_types = calloc( weather_type_count, sizeof( Weather_Type ) );
    list_reset( entries ); i = 0;
    while ( ( sub = list_next( entries ) ) ) {
        weather_types[i].id = strdup( sub->name );
//        if ( !parser_get_localized_string( sub, "name", domain, &weather_types[i].name ) ) goto parser_failure;
        if ( !parser_get_value( sub, "name", &str, 0 ) ) goto parser_failure;
        weather_types[i].name = strdup( str );
        if ( !parser_get_value( sub, "ground_cond", &str, 0 ) ) goto parser_failure;
        weather_types[i].ground_conditions = strdup( str );
        if ( !parser_get_values( sub, "flags", &flags ) ) goto parser_failure;
        list_reset( flags );
        while ( ( flag = list_next( flags ) ) )
            weather_types[i].flags |= check_flag( flag, fct_terrain );
        i++;
    }
    /* hex tile geometry */
    if ( !parser_get_int( pd, "hex_width", &hex_w ) ) goto parser_failure;
    if ( !parser_get_int( pd, "hex_height", &hex_h ) ) goto parser_failure;
    if ( !parser_get_int( pd, "hex_x_offset", &hex_x_offset ) ) goto parser_failure;
    if ( !parser_get_int( pd, "hex_y_offset", &hex_y_offset ) ) goto parser_failure;
    /* terrain icons */
    terrain_icons = calloc( 1, sizeof( Terrain_Icons ) );
    if ( !parser_get_value( pd, "fog", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->fog = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "danger", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->danger = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "grid", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->grid = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "frame", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->select = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto failure;
    if ( !parser_get_value( pd, "crosshair", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->cross = anim_create( load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ), 1000/config.anim_speed, hex_w, hex_h, sdl.screen, 0, 0 ) ) == 0 )
        goto failure;
    anim_hide( terrain_icons->cross, 1 );
    if ( !parser_get_value( pd, "explosion", &str, 0 ) ) goto parser_failure;
    sprintf( transitionPath, "Graphics/%s", str );
    search_file_name_exact( path, transitionPath, config.mod_name );
    if ( ( terrain_icons->expl1 = anim_create( load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ), 50/config.anim_speed, hex_w, hex_h, sdl.screen, 0, 0 ) ) == 0 )
        goto failure;
    anim_hide( terrain_icons->expl1, 1 );
    if ( ( terrain_icons->expl2 = anim_create( load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ), 50/config.anim_speed, hex_w, hex_h, sdl.screen, 0, 0 ) ) == 0 )
        goto failure;
    anim_hide( terrain_icons->expl2, 1 );
    /* terrain sounds */
#ifdef WITH_SOUND    
    if ( parser_get_value( pd, "explosion_sound", &str, 0 ) )
    {
        snprintf( transitionPath, 512, "Sound/%s", str );
        search_file_name_exact( path, transitionPath, config.mod_name );
        terrain_icons->wav_expl = wav_load( path, 2 );
    }
    if ( parser_get_value( pd, "select_sound", &str, 0 ) )
    {
        snprintf( transitionPath, 512, "Sound/%s", str );
        search_file_name_exact( path, transitionPath, config.mod_name );
        terrain_icons->wav_select = wav_load( path, 1 );
    }
#endif
    /* terrain data image columns */
    if ( !parser_get_int( pd, "terrain_columns", &terrain_columns ) ) goto parser_failure;
    /* terrain data image rows */
    if ( !parser_get_int( pd, "terrain_rows", &terrain_rows ) ) goto parser_failure;
    /* each ground condition type got its own image -- if it's named 'default' we
       point towards the image of weather_type 0 */
    terrain_images = calloc( 1, sizeof( Terrain_Images ) );
    terrain_images->images = calloc( weather_type_count / 4, sizeof( SDL_Surface* ) );
    for ( j = 0; j < weather_type_count / 4; j++ ) {
        terrain_images->ground_conditions = strdup( weather_types[4*j].ground_conditions );
        sprintf( path, "image/%s", weather_types[4*j].ground_conditions );
        if ( !parser_get_value( pd, path, &str, 0 ) ) goto parser_failure;
        if ( STRCMP( "default", str ) && j > 0 ) {
            /* just a pointer */
            terrain_images->images[j] = terrain_images->images[0];
        }
        else {
            sprintf( transitionPath, "Graphics/%s", str );
            search_file_name_exact( path, transitionPath, config.mod_name );
            if ( ( terrain_images->images[j] = load_surf( path, SDL_SWSURFACE, 0, 0, 0, 0 ) ) == 0 ) goto parser_failure;
            SDL_SetColorKey( terrain_images->images[j], SDL_SRCCOLORKEY, 
                             get_pixel( terrain_images->images[j], 0, 0 ) );
        }
    }
    /* fog image */
    terrain_images->images_fogged = calloc( weather_type_count / 4, sizeof( SDL_Surface* ) );
    for ( j = 0; j < weather_type_count / 4; j++ ) {
        if ( terrain_images->images[j] == terrain_images->images[0] && j > 0 ) {
            /* just a pointer */
            terrain_images->images_fogged[j] = terrain_images->images_fogged[0];
        }
        else {
            terrain_images->images_fogged[j] = create_surf( terrain_images->images[j]->w, terrain_images->images[j]->h, SDL_SWSURFACE );
            FULL_DEST( terrain_images->images_fogged[j]  );
            FULL_SOURCE( terrain_images->images[j] );
            blit_surf();
            count =  terrain_images->images[j]->w /  hex_w;
            for ( i = 0; i < terrain_rows; i++ )
                for ( k = 0; k < terrain_columns; k++ ) {
                    DEST( terrain_images->images_fogged[j], k * hex_w, i * hex_h,  hex_w, hex_h );
                    SOURCE( terrain_icons->fog, 0, 0 );
                    alpha_blit_surf( FOG_ALPHA );
                }
            SDL_SetColorKey( terrain_images->images_fogged[j], SDL_SRCCOLORKEY, get_pixel( terrain_images->images_fogged[j], 0, 0 ) );
        }
    }
    /* terrain types */
    if ( !parser_get_entries( pd, "terrain", &entries ) ) goto parser_failure;
    terrain_type_count = entries->count;
    terrain_types = calloc( terrain_type_count, sizeof( Terrain_Type ) );
    list_reset( entries ); i = 0;
    while ( ( sub = list_next( entries ) ) ) {
        /* id */
        terrain_types[i].id = sub->name[0];
        /* name */
        if ( !parser_get_localized_string( sub, "name", domain, &terrain_types[i].name ) ) goto parser_failure;
        /* spot cost */
        terrain_types[i].spt = calloc( weather_type_count, sizeof( int ) );
        if ( !parser_get_pdata( sub, "spot_cost",  &subsub ) ) goto parser_failure;
        for ( j = 0; j < weather_type_count; j++ )
            if ( !parser_get_int( subsub, weather_types[j].id, &terrain_types[i].spt[j] ) ) goto parser_failure;
        /* image */
        terrain_types[i].images = terrain_images->images;
        /* fog image */
        terrain_types[i].images_fogged = terrain_images->images_fogged;
        /* mov cost */
        terrain_types[i].mov = calloc( mov_type_count * weather_type_count, sizeof( int ) );
        if ( !parser_get_pdata( sub, "move_cost",  &subsub ) ) goto parser_failure;
        for ( k = 0; k < mov_type_count; k++ ) {
            if ( !parser_get_pdata( subsub, mov_types[k].id,  &subsubsub ) ) goto parser_failure;
            for ( j = 0; j < weather_type_count; j++ ) {
                if ( !parser_get_value( subsubsub, weather_types[j].id, &str, 0 ) ) goto parser_failure;
                if ( str[0] == 'X' )
                    terrain_types[i].mov[j + k * weather_type_count] = 0; /* impassable */
                else
                    if ( str[0] == 'A' )
                        terrain_types[i].mov[j + k * weather_type_count] = -1; /* costs all */
                    else
                        terrain_types[i].mov[j + k * weather_type_count] = atoi( str ); /* normal cost */
            }
        }
        /* entrenchment */
        if ( !parser_get_int( sub, "min_entr",  &terrain_types[i].min_entr ) ) goto parser_failure;
        if ( !parser_get_int( sub, "max_entr",  &terrain_types[i].max_entr ) ) goto parser_failure;
        /* initiative modification */
        if ( !parser_get_int( sub, "max_init",  &terrain_types[i].max_ini ) ) goto parser_failure;
        /* flags */
        terrain_types[i].flags = calloc( weather_type_count, sizeof( int ) );
        if ( !parser_get_pdata( sub, "flags",  &subsub ) ) goto parser_failure;
        for ( j = 0; j < weather_type_count; j++ ) {
            if ( !parser_get_values( subsub, weather_types[j].id, &flags ) ) goto parser_failure;
            list_reset( flags );
            while ( ( flag = list_next( flags ) ) )
                terrain_types[i].flags[j] |= check_flag( flag, fct_terrain );
        }
        /* next terrain */
        i++;
        /* LOG */
        strcpy( log_str, "  [                                        ]" );
        for ( k = 0; k < i * log_dot_limit / entries->count; k++ )
            log_str[3 + k] = '*';
        write_text( log_font, sdl.screen, log_x, log_y, log_str, 255 );
        SDL_UpdateRect( sdl.screen, log_font->last_x, log_font->last_y, log_font->last_width, log_font->last_height );
    }
    parser_free( &pd );
    /* LOG */
    write_line( sdl.screen, log_font, log_str, log_x, &log_y ); refresh_screen( 0, 0, 0, 0 );
    free(domain);
    return 1;
parser_failure:        
    fprintf( stderr, "%s\n", parser_get_error() );
failure:
    terrain_delete();
    if ( pd ) parser_free( &pd );
    free(domain);
    printf(tr("If data seems to be missing, please re-run the converter lgc-pg.\n"));
    return 0;
}
static int
compact_effect_edge(effect_t *effect, IPA_cgraph_edge_t *edge, 
		    IPA_cgraph_edgelist_e edge_type, 
		    int issrc, int retain_oldeffect, int update)
{
  IPA_cgraph_node_t *n_src = NULL;
  IPA_cgraph_node_t *n_dst = NULL;
  IPA_cgraph_edgelist_e n_type = 0;
  IPA_cgraph_edge_data_t n_data;
  int n_skew;
  int t1, z1, s1, t2, z2, s2;
  int ts1, ss1, ts2, ss2;
  int compaction_action;

  compaction_action = NO_EFFECT;

  /* All addr effects are from initial effects and
     should be kept */
  if (effect->edge_type == ASSIGN_ADDR)
    {
      /* This is not really an error but reaching this is
	 an inefficiency */
      assert(0);
      return 1;
    }

  /* AA and DA edges are added during initial effect
     generation only */
  if ((edge_type == ASSIGN_ADDR 
      /* FIXTEST */
      && !(issrc && effect->edge_type == DEREF_ASSIGN)
      ) || edge_type == DEREF_ASSIGN)
    {
      /* do nothing */
#if DB_EFF > 1
      printf("AD/AA : no action\n");
#endif      
      return 0;
    }

  /* Override if src is PARAM and we're handling the
   *   dst of an DEREF_ASSIGN  */
  if (!issrc && IPA_FLAG_ISSET(edge->src_elist->node->flags,
			       IPA_CG_NODE_FLAGS_PARAM))
    {
#if DB_EFF > 1
      printf("FORCE - ");
#endif      
      retain_oldeffect = 1;
    }

  t1 = TARGET(effect->edata);
  ts1 = TGTSTR(effect->edata);
  z1 = SIZE(effect->edata);
  ss1 = SRCSTR(effect->edata);
  s1 = SOURCE(effect->edata);

  n_skew = effect->skew;

  t2 = TARGET(edge->data);
  ts2 = TGTSTR(edge->data);
  z2 = SIZE(edge->data);
  ss2 = SRCSTR(edge->data);
  s2 = SOURCE(edge->data);

  switch(effect->edge_type)
    {
      /***************** ASSIGN ********************/
    case ASSIGN:
      assert(issrc);
      n_src = edge->src_elist->node;
      n_dst = effect->dst;

      if (ss1 != 0 || ts2 != 0)
	{
	  /* Meshing stride, retain effect */
	  compaction_action = HAS_EFFECT;
	  retain_oldeffect = 1;
	  break;
	}

      switch(edge_type)
	{
	case ASSIGN:
	  n_type = ASSIGN;
	  if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("A-A : new 1");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1;
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = MIN(z1, z2 - (s1-t2));
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2 + (s1-t2);
	    }
	  else if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("A-A : new 2");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1 + (t2-s1);
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = MIN(z2, z1 - (t2-s1));
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2;
	    }
#if DB_EFF > 1
	  else
	    printf("A-A : none");
#endif
	  break;
	case SKEW:
	  n_type = SKEW;
	  if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("A-K : new 1");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1 + (t2-s1);
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = z2;
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2;
	    }	
#if DB_EFF > 1
	  else
	    printf("A-K : none");
#endif
	  break;
	case ASSIGN_DEREF:
	  n_type = ASSIGN_DEREF;
	  if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("A-AD : new 1");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1;
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = MIN(z1, z2-(s1-t2));
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2;
	      n_skew += (s1 - t2);
	    }
	  else if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("A-AD : new 2");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1 + (t2-s1);
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = MIN(z2, z1 - (t2-s1));;
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2;
	    }
#if DB_EFF > 1
	  else
	    printf("A-AD : none");
#endif
	  break;
	default:
	  assert(0);
	}
      break;
    case SKEW:
      /***************** SKEW ********************/
      assert(issrc);
      n_src = edge->src_elist->node;
      n_dst = effect->dst;

      if (ss1 != 0 || ts2 != 0)
	{
	  /* Meshing stride, retain effect */
	  compaction_action = HAS_EFFECT;
	  retain_oldeffect = 1;
	  break;
	}

      switch(edge_type)
	{
	case ASSIGN:
	  n_type = SKEW;
	  if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("K-A : new 1");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1;
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = z1;
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2 + (s1 - t2);
	    }
#if DB_EFF > 1
	  else
	    printf("K-A : none");
#endif
	  break;
	case SKEW:
	  n_type = SKEW;
	  if (s1 == t2)
	    {
#if DB_EFF > 1
	      printf("K-K : new 1");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1;
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = (z1 + z2);
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2;
	    }
#if DB_EFF > 1
	  else
	    printf("K-K : none");
#endif
	  break;
	case ASSIGN_DEREF:
	  if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("K-AD : retain 1");
#endif
	      compaction_action = HAS_EFFECT;
	    }
#if DB_EFF > 1
	  else
	    printf("K-AD : none");
#endif
	  retain_oldeffect = 1;
	  break;
	default:
	  assert(0);
	}
      break;
    case ASSIGN_DEREF:
      /***************** ASSIGN_DEREF ********************/
      assert(issrc);
      n_src = edge->src_elist->node;
      n_dst = effect->dst;

      if (ss1 != 0 || ts2 != 0)
	{
	  /* Meshing stride, retain effect */
	  compaction_action = HAS_EFFECT;
	  retain_oldeffect = 1;
	  break;
	}      

      switch(edge_type)
	{
	case ASSIGN:
	  n_type = ASSIGN_DEREF;
	  if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("AD-A : new 1");
#endif
	      compaction_action = HAS_EFFECT;
	      TARGET(n_data) = t1;
	      TGTSTR(n_data) = ts1;
	      SIZE(n_data) = z1;
	      SRCSTR(n_data) = ss2;
	      SOURCE(n_data) = s2 + (s1-t2);
	    }
#if DB_EFF > 1
	  else
	    printf("AD-A : none");
#endif
	  break;
	case SKEW:
	  if (s1 == t2)
	    {
#if DB_EFF > 1
	      printf("AD-K : retain 1");
#endif
	      compaction_action = HAS_EFFECT;
	    }
#if DB_EFF > 1
	  else
	    printf("AD-K : none");
#endif
	  retain_oldeffect = 1;
	  break;
	case ASSIGN_DEREF:
	  if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
	    {
#if DB_EFF > 1
	      printf("AD-AD : retain 1");
#endif
	      compaction_action = HAS_EFFECT;
	    }
#if DB_EFF > 1
	  else
	    printf("AD-AD : none");
#endif
	  retain_oldeffect = 1;
	  break;
	default:
	  assert(0);
	}
      break;
    case DEREF_ASSIGN:
      if (issrc)
	{
	  /***************** (source) DEREF_ASSIGN ********************/

	  if (ss1 != 0 || ts2 != 0)
	    {
	      /* Meshing stride, retain effect */
	      compaction_action = HAS_EFFECT;
	      retain_oldeffect = 1;
	      break;
	    }

	  switch(edge_type)
	    {
	    case ASSIGN:
	      n_type = DEREF_ASSIGN;
	      n_src = edge->src_elist->node;
	      n_dst = effect->dst;
	      if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE))
		{
#if DB_EFF > 1
		  printf("DA-A : src new 1");
#endif
		  compaction_action = HAS_EFFECT;
		  TARGET(n_data) = t1;
		  TGTSTR(n_data) = ts1;
		  SIZE(n_data) = MIN(z1, z2-(s1-t2));
		  SRCSTR(n_data) = ss2;
		  SOURCE(n_data) = s2 + (s1-t2);
		}
	      else if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE))
		{
#if DB_EFF > 1
		  printf("DA-A : src new 2");
#endif
		  compaction_action = HAS_EFFECT;
		  TARGET(n_data) = t1;
		  TGTSTR(n_data) = ts1;
		  SIZE(n_data) = MIN(z2, z1 - (t2-s1));
		  SRCSTR(n_data) = ss2;
		  SOURCE(n_data) = s2;
		  n_skew += (t2 - s1);
		}
#if DB_EFF > 1
	      else
		printf("DA-A : src none");
#endif
	      
	      break;
	    case SKEW:
	      if (BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE))
		{
#if DB_EFF > 1
		  printf("DA-K : src retain 1");
#endif
		  compaction_action = HAS_EFFECT;
		}
#if DB_EFF > 1
	      else
		printf("DA-K : src none");
#endif
	      retain_oldeffect = 1;
	      break;
	    case ASSIGN_DEREF:
	      if (BOUND(t2, s1, t2 + z2 - IPA_POINTER_SIZE) ||
		  BOUND(s1, t2, s1 + z1 - IPA_POINTER_SIZE))
		{
#if DB_EFF > 1
		  printf("DA-K/AD : src retain 1");
#endif
		  compaction_action = HAS_EFFECT;
		}
#if DB_EFF > 1
	      else
		printf("DA-K/AD : src none");
#endif
	      retain_oldeffect = 1;
	      break;


	      /* FIXTEST */
	    case ASSIGN_ADDR:
	      if (s1 == t2)
		{
#if DB_EFF > 1
		  printf("AD-ADDR : retain 1");
#endif
		  compaction_action = HAS_EFFECT;
		}
#if DB_EFF > 1
	      else
		printf("AD-ADDR : none");
#endif
	      retain_oldeffect = 1;
	      break;

	    default:
	      assert(0);
	    }
	}
      else
	{
	  /***************** (dest) DEREF_ASSIGN ********************/

	  if (ts1 != 0 || ts2 != 0)
	    {
	      /* Meshing stride, retain effect */
	      compaction_action = HAS_EFFECT;
	      retain_oldeffect = 1;
	      break;
	    }

	  switch(edge_type)
	    {
	    case ASSIGN:
	      n_type = DEREF_ASSIGN;
	      n_src = effect->src;
	      n_dst = edge->src_elist->node;
	      if (BOUND(t2, t1, t2 + z2 - IPA_POINTER_SIZE))
		{
#if DB_EFF > 1
		  printf("DA-A : dst new 1");
#endif
		  compaction_action = HAS_EFFECT;
		  TARGET(n_data) = s2 + (t1-t2);
		  TGTSTR(n_data) = ss2;
		  SIZE(n_data) = z1;
		  SRCSTR(n_data) = ss1;
		  SOURCE(n_data) = s1;
		}
#if DB_EFF > 1
	      else
		printf("DA-A : dst none");
#endif
	      break;
	    case SKEW:
	      if (t1 == t2)
		{
#if DB_EFF > 1
		  printf("DA-K : dst retain 1");
#endif
		  compaction_action = HAS_EFFECT;
		}
#if DB_EFF > 1
	      else
		printf("DA-K : dst none");
#endif
	      retain_oldeffect = 1;
	      break;	      
	    case ASSIGN_DEREF:
	      if (BOUND(t2, t1, t2 + z2 - IPA_POINTER_SIZE))
		{
#if DB_EFF > 1
		  printf("DA-AD : dst retain 1");
#endif
		  compaction_action = HAS_EFFECT;
		}
#if DB_EFF > 1
	      else
		printf("DA-AD : dst none");
#endif
	      retain_oldeffect = 1;
	      break;
	    default:
	      assert(0);
	    }
	}
      break;
    default:
      assert(0);
    }

  if (SRCSTR(n_data) != 0)
    {
      SOURCE(n_data) = 0;
      SIZE(n_data) = IPA_POINTER_SIZE;
    }
  if (TGTSTR(n_data) != 0)
    {
      TARGET(n_data) = 0;
      SIZE(n_data) = IPA_POINTER_SIZE;
    }

  if (compaction_action == HAS_EFFECT)
    {
      if (retain_oldeffect) 
	{
#if DB_EFF > 1
	  printf(" : has effect, retain old effect\n");
#endif
	  if (update)
	    SE_addedgeto_effectlist(edge);
	  return 1;
	}
      else
	{
#if DB_EFF > 1
	  printf(" : has effect, compact\n");
#endif
	  if (update)
	    SE_addto_effectlist(n_type, n_src, n_dst, &n_data, n_skew);
	  return 0;
	}
    }

#if DB_EFF > 1
  printf(" : no effect\n");
#endif
  return 0;
}
static void
SE_process_effect(effect_t *effect)
{
  switch(effect->edge_type)
    {
    case DEREF_ASSIGN:
      if (SE_reflect_effect(effect, 1) == ADD_EFFECT)
	{
#if 1
	  if (effect->skew != 0)
	    {
	      IPA_cgraph_edge_data_t data;
	      IPA_cgraph_node_t *tmp_node;
	      
	      tmp_node = new_temp_node(local_sum, IPA_CG_NODE_FLAGS_SUMMARY);

	      /* SUMMARY:  tmp(0) *=(z) src(s) */
	      TARGET(data) = 0;
	      TGTSTR(data) = 0;
	      SIZE(data) = SIZE(effect->edata);
	      SRCSTR(data) = SRCSTR(effect->edata);
	      SOURCE(data) = SOURCE(effect->edata);
	      SE_addto_summary(effect->edge_type, 
			       effect->src, tmp_node, &data);
	      
	      /* EFFECT :  tmp(0) =+(k) dst(t) */
	      TARGET(data) = 0;
	      TGTSTR(data) = 0;
	      SIZE(data) = effect->skew;
	      SRCSTR(data) = TGTSTR(effect->edata);
	      SOURCE(data) = TARGET(effect->edata);
	      SE_addto_effectlist(SKEW, effect->dst, tmp_node, &data, 0);
	      break;
	    }
#endif
	  if (SE_reflect_effect(effect, 0) == ADD_EFFECT)
	    {
	      /* Effect not skipped */
	      SE_addto_summary(effect->edge_type, effect->src,
			       effect->dst, &effect->edata);
	    }
	}
      break;

    case ASSIGN_DEREF:
#if 1
      if (effect->skew != 0)
	{
	  IPA_cgraph_edge_data_t data;
	  IPA_cgraph_node_t *tmp_node;

	  tmp_node = new_temp_node(local_sum, IPA_CG_NODE_FLAGS_SUMMARY);
	  
	  /* SUMMARY:  dst(t) =*(z) tmp(0) */
	  TARGET(data) = TARGET(effect->edata);
	  TGTSTR(data) = TGTSTR(effect->edata);
	  SIZE(data) = SIZE(effect->edata);
	  SRCSTR(data) = 0;
	  SOURCE(data) = 0;
	  SE_addto_summary(effect->edge_type, 
			   tmp_node, effect->dst, &data);
	  
	  /* EFFECT :  tmp(0) =+(k) src(s) */
	  TARGET(data) = 0;
	  TGTSTR(data) = 0;
	  SIZE(data) = effect->skew;
	  SRCSTR(data) = SRCSTR(effect->edata);
	  SOURCE(data) = SOURCE(effect->edata);
	  SE_addto_effectlist(SKEW, effect->src, tmp_node, &data, 0);
	  break;
	}
#endif
    case ASSIGN:
    case SKEW:
      if (SE_reflect_effect(effect, 1) == ADD_EFFECT)
	{
	  /* Effect not skipped */
	  SE_addto_summary(effect->edge_type, effect->src,
			   effect->dst, &effect->edata);
	}
      break;
      
    case ASSIGN_ADDR:
      SE_addto_summary(effect->edge_type, effect->src,
		       effect->dst, &effect->edata);
      break;
      
    default:
      assert(0);
    }
}