Esempio n. 1
0
File: megahal.c Progetto: lp0/sqlhal
static int megahal_reply(brain_t brain, list_t *input, list_t **output) {
	dict_t *keywords;
	list_t *current;
	struct timespec start;
	double surprise;
	double max_surprise;
	int ret;

	*output = NULL;

	ret = megahal_keywords(brain, input, &keywords);
	if (ret) return ret;

	ret = megahal_generate(brain, NULL, output);
	if (ret) {
		dict_free(&keywords);
		return ret;
	}

	if (!list_equal(input, *output))
		list_free(output);

	ret = clock_gettime(CLOCK_MONOTONIC, &start);
	if (ret) {
			ret = -ECLOCK;
			goto fail;
	}

	max_surprise = -1.0;
	do {
		ret = megahal_generate(brain, keywords, &current);
		if (ret) goto fail;

		ret = megahal_evaluate(brain, keywords, current, &surprise);
		if (ret) goto fail;

		if (surprise > max_surprise && !list_equal(input, current)) {
			max_surprise = surprise;
			list_free(output);
			*output = current;
		} else {
			list_free(&current);
		}
	} while(!megahal_timeout(start));

	dict_free(&keywords);

	return OK;

fail:
	list_free(output);
	dict_free(&keywords);
	return ret;
}
Esempio n. 2
0
/* check if anything has changed for this bookmark */
static bool should_update_bookmark(url_t *url)
{
	if(url->noupdate)
		return false;

	/* don't update bookmark if username has changed */
	if(url->username && strcmp(url->username, ftp->url->username) != 0)
		return false;

	if(url->directory && strcmp(url->directory, ftp->curdir) != 0)
		return true;
	if(!url->directory && strcmp(ftp->curdir, ftp->homedir) != 0)
		return true;
	if(xstrcmp(url->hostname, ftp->url->hostname) != 0)
		return true;
	if(url->port != ftp->url->port)
		return true;
	if(!list_equal(url->mech, ftp->url->mech, (listsortfunc)strcasecmp) != 0)
		return true;
	if(xstrcmp(url->protlevel, ftp->url->protlevel) != 0)
		return true;
	if(url->pasvmode != ftp->url->pasvmode && ftp->url->pasvmode != -1)
		return true;
	if(xstrcmp(url->protocol, ftp->url->protocol) != 0)
		return true;
	if(xstrcmp(url->sftp_server, ftp->url->sftp_server) != 0)
		return true;
	return false;
}
void
extensions__dlg_preferences_apply (GtkWidget  *dialog,
		  	  	   GthBrowser *browser,
		  	  	   GtkBuilder *dialog_builder)
{
	BrowserData         *data;
	GList               *active_extensions;
	GthExtensionManager *manager;
	GList               *extension_names;
	GList               *scan;

	data = g_object_get_data (G_OBJECT (dialog), BROWSER_DATA_KEY);
	g_return_if_fail (data != NULL);

	active_extensions = NULL;
	manager = gth_main_get_default_extension_manager ();
	extension_names = gth_extension_manager_get_extensions (manager);
	for (scan = extension_names; scan; scan = scan->next) {
		char                    *extension_name = scan->data;
		GthExtensionDescription *description;

		description = gth_extension_manager_get_description (manager, extension_name);
		if ((description == NULL) || description->mandatory || description->hidden)
			continue;

		if (gth_extension_description_is_active (description))
			active_extensions = g_list_prepend (active_extensions, g_strdup (extension_name));
	}
	active_extensions = g_list_reverse (active_extensions);
	_g_settings_set_string_list (data->settings, PREF_GENERAL_ACTIVE_EXTENSIONS, active_extensions);

	if (! list_equal (active_extensions, data->active_extensions)) {
		GtkWidget *dialog;
		int        response;

		dialog = _gtk_message_dialog_new (GTK_WINDOW (data->dialog),
						  GTK_DIALOG_MODAL,
						  _GTK_ICON_NAME_DIALOG_WARNING,
						  _("Restart required"),
						  _("You need to restart gthumb for these changes to take effect"),
						  _("_Continue"), GTK_RESPONSE_CANCEL,
						  _("_Restart"), GTK_RESPONSE_OK,
						  NULL);
		response = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

		if (response == GTK_RESPONSE_OK)
			gth_quit (TRUE);
	}

	g_list_foreach (active_extensions, (GFunc) g_free, NULL);
	g_list_free (active_extensions);
	g_list_free (extension_names);
}
Esempio n. 4
0
/**
 * Tests if the two queues are equal.
 */
bool_t queue_equal(const queue_t* cpque_first, const queue_t* cpque_second)
{
    assert(cpque_first != NULL);
    assert(cpque_second != NULL);

#ifdef CSTL_QUEUE_LIST_SEQUENCE
    return list_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#else
    return deque_equal(&cpque_first->_t_sequence, &cpque_second->_t_sequence);
#endif
}
Esempio n. 5
0
static inline bool
aggregate_changed(int agg_type, void *v1, void *v2)
{
  switch(agg_type) {
  case AGG_FIRST:
    return false;

  case AGG_MIN_INT:
  case AGG_MAX_INT:
  case AGG_SUM_INT:
    return MELD_INT(v1) != MELD_INT(v2);
    
  case AGG_MIN_FLOAT:
  case AGG_MAX_FLOAT:
  case AGG_SUM_FLOAT:
    return MELD_FLOAT(v1) != MELD_FLOAT(v2);

  case AGG_SET_UNION_INT:
  case AGG_SET_UNION_FLOAT: {
    Set *setOld = MELD_SET(v1);
    Set *setNew = MELD_SET(v2);

    if(!set_equal(setOld, setNew))
      return true;

    /* delete new set union */
    set_delete(setNew);
    return false;
  }
    break;

  case AGG_SUM_LIST_INT:
  case AGG_SUM_LIST_FLOAT: {
    List *listOld = MELD_LIST(v1);
    List *listNew = MELD_LIST(v2);

    if(!list_equal(listOld, listNew))
      return true;

    /* delete new list */
    list_delete(listNew);
    return false;
  }
    break;

  default:
    assert(0);
    return true;
  }

  assert(0);
  while(1);
}
Esempio n. 6
0
/**
 * Tests if the two stacks are equal.
 */
bool_t stack_equal(const cstl_stack_t* cpsk_first, const cstl_stack_t* cpsk_second)
{
    assert(cpsk_first != NULL);
    assert(cpsk_second != NULL);

#if defined (CSTL_STACK_VECTOR_SEQUENCE)
    return vector_equal(&cpsk_first->_t_sequence, &cpsk_second->_t_sequence);
#elif defined (CSTL_STACK_LIST_SEQUENCE)
    return list_equal(&cpsk_first->_t_sequence, &cpsk_second->_t_sequence);
#else
    return deque_equal(&cpsk_first->_t_sequence, &cpsk_second->_t_sequence);
#endif
}
Esempio n. 7
0
/* Builds the canonical collection of sets into C[] and nC.  Prints
   the sets to stdout if debugging is enabled. */
static void
build_canonical_sets (void)
{
  int i;

  nC = 1;
  list_init (&C[0]);
  list_add (&C[0], 0, 0);
  calc_closure (&C[0], &C[0]);

  for (i = 0; i < nC; i++)
    {
      int X;

      for (X = 0; X < n_symbols; X++)
	{
	  struct list list;

	  calc_goto (&list, &C[i], symbols[X].sym);
	  if (list_count (&list))
	    {
	      int j;

	      for (j = 0; j < nC; j++)
		if (list_equal (&list, &C[j]))
		  break;
	      if (j >= nC)
		{
		  assert (nC < MAX_LOL_COUNT);
		  C[nC++] = list;
		}
	      else
		list_free (&list);
	    }
	  else
	    list_free (&list);
	}
    }

  if (debug)
    {
      printf ("Canonical collection of sets:\n");
      for (i = 0; i < nC; i++)
	{
	  printf ("\tI(%d) = ", i);
	  list_print (&C[i]);
	  putchar ('\n');
	}
    }
}
Esempio n. 8
0
void testrandomlists(int n, int size)
{
  for(int i=0; i<n; i++)
    {
      int list[size];
      int check[size];
      fill_random(list, size);
      list_copy(list, check, size);
      insertionSort(list, size);
      insertionSortSafe(check, size);
      if(!list_equal(list, check, size))
	 printf("FAIL!\n");
    }
}
Esempio n. 9
0
static struct ps_map_entry * ps_map_insert(struct ps_map * map, LIST * key)
{
    unsigned hash_val = list_hash( key );
    unsigned bucket = hash_val % map->table_size;
    struct ps_map_entry * pos;
    for ( pos = map->table[bucket]; pos ; pos = pos->next )
    {
        if ( list_equal( pos->key, key ) )
            return pos;
    }

    if ( map->num_elems >= map->table_size )
    {
        ps_map_rehash( map );
        bucket = hash_val % map->table_size;
    }
    pos = BJAM_MALLOC( sizeof( struct ps_map_entry ) );
    pos->next = map->table[bucket];
    pos->key = key;
    pos->value = 0;
    map->table[bucket] = pos;
    ++map->num_elems;
    return pos;
}
Esempio n. 10
0
LIST *
	hcache( TARGET *t, LIST *hdrscan )
{
	HCACHEDATA	cachedata, *c = &cachedata;
	HCACHEFILE	*file;
	LIST	*l = 0;
	int		use_cache = 1;
	const char *target;
# ifdef DOWNSHIFT_PATHS
	char path[ MAXJPATH ];
	char *p;
# endif

	target = t->boundname;

# ifdef DOWNSHIFT_PATHS
	p = path;

	do *p++ = (char)tolower( *target );
	while( *target++ );

	target = path;
# endif

	++queries;

	c->boundname = target;

	file = hcachefile_get( t );
	//    if ( file )
	{
		if( hashcheck( hcachehash, (HASHDATA **) &c ) )
		{
#ifdef OPT_BUILTIN_MD5CACHE_EXT
			if( c->time == t->time  &&  md5matchescommandline( t ) )
#else
			if( c->time == t->time )
#endif
			{
				if( !list_equal(hdrscan, c->hdrscan) )
					use_cache = 0;
			}
			else
				use_cache = 0;

			if( use_cache ) {
				if( DEBUG_HEADER )
					printf( "using header cache for %s\n", t->boundname );
				c->age = 0; /* The entry has been used, its young again */
				++hits;
				l = list_copy( 0, c->includes );
				{
					LIST *hdrfilter = var_get( "HDRFILTER" );
					if ( list_first(hdrfilter) )
					{
						LOL lol;
						lol_init( &lol );
						lol_add( &lol, list_append( L0, t->name, 1 ) );
						lol_add( &lol, l );
						lol_add( &lol, list_append( L0, t->boundname, 0 ) );
						l = evaluate_rule( list_value(list_first(hdrfilter)), &lol, NULL );
						lol_free( &lol );
					}
				}
				return l;
			}
			else {
				if( DEBUG_HEADER )
					printf( "header cache out of date for %s\n", t->boundname );
				list_free( c->includes );
				list_free( c->hdrscan );
				c->includes = 0;
				c->hdrscan = 0;
			}
		} else {
			if( hashenter( hcachehash, (HASHDATA **)&c ) ) {
				c->boundname = newstr( c->boundname );
				c->file = file;
				c->next = c->file->hcachelist;
				c->file->hcachelist = c;
#ifdef OPT_BUILTIN_MD5CACHE_EXT
				c->mtime = 0;
				memset( &c->rulemd5sum, 0, MD5_SUMSIZE );
				memset( &c->currentrulemd5sum, 0, MD5_SUMSIZE );
				memset( &c->contentmd5sum, 0, MD5_SUMSIZE );
				memset( &c->currentcontentmd5sum, 0, MD5_SUMSIZE );
#endif
			}
		}
	}

	c->file->dirty = 1;

	/* 'c' points at the cache entry.  Its out of date. */

	l = headers1( c->boundname, hdrscan );

	l = list_appendList( list_copy( 0, var_get( "HDREXTRA" ) ), l );

	c->includes = list_copy( 0, l );

	{
		LIST *hdrfilter = var_get( "HDRFILTER" );
		if (list_first(hdrfilter))
		{
			LOL lol;
			lol_init( &lol );
			lol_add( &lol, list_append( L0, t->name, 1 ) );
			lol_add( &lol, l );
			lol_add( &lol, list_append( L0, t->boundname, 0 ) );
			l = evaluate_rule( list_value(list_first(hdrfilter)), &lol, NULL );
			lol_free( &lol );
		}
	}

	c->time = t->time;
	c->age = 0;

	c->hdrscan = list_copy( 0, hdrscan );

	return l;
}
Esempio n. 11
0
int test_lists() {
  int len = 0;
  // create a list of integers (li1) from 1 to SIZE
  DLL *li1 = list_sequence(1, SIZE);
  // copy the list to li2
  DLL *li2 = list_copy(li1);
  // remove each individual item from left side of li2 and
  // append to right side of li3 (preserving order)
  DLL *li3 = list_new();
  // compare li2 and li1 for equality
  if (!list_equal(li2, li1)) {
    print("li2!=li1\n");
    while(1);
  }
  while (!list_empty(li2)) {
    list_push_tail(li3, list_pop_head(li2));
  }
  // li2 must now be empty
  if (!list_empty(li2)) {
    print("li2 ne\n");
    while(1);
  }
  // remove each individual item from right side of li3 and
  // append to right side of li2 (reversing list)
  while (!list_empty(li3)) {
    list_push_tail(li2, list_pop_tail(li3));
  }
  // li3 must now be empty
  if (!list_empty(li3)) {
    print( "li3 ne\n");
    while(1);
  }
  // reverse li1 in place
  list_reverse(li1);
  // check that li1's first item is now SIZE
  if (list_first(li1)->val != SIZE) {
    print( "li1 stw\n");
    while(1);
  }
  // check that li1's last item is now 1
  if (list_last(li1)->val != 1) {
    print( "lstw\n");
    while(1);
  }
  // check that li2's first item is now SIZE
  if (list_first(li2)->val != SIZE) {
    print( "li2 stw\n");
    while(1);
  }
  // check that li2's last item is now 1
  if (list_last(li2)->val != 1) {
    print( "lstw\n");
    while(1);
  }

  // check that li1's length is still SIZE
  if (list_length(li1) != SIZE) {
    print( "li1 szw\n");
    while(1);
  }
  // compare li1 and li2 for equality
  if (!list_equal(li1, li2)) {
    print( "li1!=li2\n");
    while(1);
  }
  len = list_length(li1);
  //  free(li1);
  //  free(li2);
  //  free(li3);
  // return the length of the list
  printnum(len);
  print("\n");

  return  0;
}
Esempio n. 12
0
/* Builds and outputs to stdout the action table for the parser,
   including enumerated types for actions and lexemes. */
static void
build_action_table (void)
{
  unsigned char **actions;
  int i;

  actions = xmalloc (sizeof *actions * nC);
  for (i = 0; i < nC; i++)
    {
      actions[i] = xmalloc (sizeof **actions * (n_symbols + 1));
      memset (actions[i], 0, sizeof **actions * (n_symbols + 1));
    }

  for (i = 0; i < nC; i++)
    {
      int j;

      for (j = 0; j < list_count (&C[i]); j++)
	{
	  const struct item *item = list_item (&C[i], j);
	  const struct production *prod = &G[item->prod];
	  const struct symbol *A = find_symbol (prod->left);
	  
	  if (item_n_after_dot (item) > 0)
	    {
	      struct symbol *a;

	      a = find_symbol (item_symbol_after_dot (item));
	      if (!a->nonterminal)
		{
		  struct list list;
		  int k;

		  calc_goto (&list, &C[i], a->sym);
		  
		  for (k = 0; k < nC; k++)
		    if (list_equal (&list, &C[k]))
		      set_action (actions, i, a - symbols, 2 + k);

		  list_free (&list);
		}
	    }
	  else if (A->sym != G[0].left)
	    {
	      const struct set *follow_A = &A->follow;
	      int k;

	      for (k = 0; k < follow_A->n; k++)
		{
		  int c;
		  int index;

		  c = follow_A->which[k];
		  if (c == '$')
		    index = n_symbols;
		  else
		    index = find_symbol (c) - symbols;
		  
		  set_action (actions, i, index, 2 + nC + (prod - G));
		}
	    }

	  if (list_contains (&C[i], 0, 1))
	    set_action (actions, i, n_symbols, 1);
	}
    }

  fputs ("/* Actions used in action_table[][] entries. */\n"
	 "enum\n"
	 "  {\n"
	 "    err,\t/* Error. */\n"
	 "    acc,\t/* Accept. */\n"
	 "\n"
	 "    /* Shift actions. */\n", stdout);

  print_enum_list ('s', 0, nC - 1);

  fputs ("\n"
	 "    /* Reduce actions. */\n", stdout);
  print_enum_list ('r', 1, n_grammar);

  printf ("\n"
	  "    n_states = %d,\n"
	  "    n_terminals = %d,\n"
	  "    n_nonterminals = %d,\n"
	  "    n_reductions = %d\n"
	  "  };\n"
	  "\n"
	  "/* Symbolic token names used in parse_table[][] second index. */\n"
	  "enum\n"
	  "  {\n",
	  nC, n_terminals + 1, n_nonterminals, n_grammar);
  
  for (i = 0; i < n_symbols; i++)
    {
      struct symbol *sym = &symbols[i];
      int j;

      if (sym->nonterminal)
	continue;

      for (j = 0; j < n_tokens; j++)
	if (tokens[j].token == sym->sym)
	  break;
      assert (j < n_tokens);
      
      printf ("    %s,%*c/* %c */\n",
	      tokens[j].name, 25 - (int) strlen (tokens[j].name), ' ',
	      sym->sym);
    }

  fputs ("    lex_stop                  /* $ */\n"
	 "  };\n"
	 "\n"
	 "/* Action table.  This is action[][] from Fig. 4.30, \"LR parsing\n"
	 "   program\", in Aho, Sethi, and Ullman. */\n"
	 "static const unsigned char action_table[n_states][n_terminals] =\n"
	 "  {\n"
	 "    /*        ", stdout);
  for (i = 0; i < n_symbols; i++)
    if (!symbols[i].nonterminal)
      printf ("  %c ", symbols[i].sym);
  fputs ("  $ */\n", stdout);
  for (i = 0; i < nC; i++)
    {
      int j;
      
      printf ("    /*%3d */ {", i);
      for (j = 0; j <= n_symbols; j++)
	if (j == n_symbols || !symbols[j].nonterminal)
	  {
	    char buf[16];
	    if (j != 0)
	      putchar (',');

	    action_name (buf, actions[i][j]);
	    printf ("%3s", buf);
	  }
      fputs ("},\n", stdout);
    }
  fputs ("  };\n\n", stdout);
      
  for (i = 0; i < nC; i++)
    free (actions[i]);
  free (actions);
}
Esempio n. 13
0
/* Builds and prints to stdout the goto table for this parser. */
static void
build_goto_table (void)
{
  unsigned char **gotos;
  int i;

  gotos = xmalloc (sizeof *gotos * nC);
  for (i = 0; i < nC; i++)
    {
      gotos[i] = xmalloc (sizeof **gotos * n_nonterminals);
      memset (gotos[i], 0, sizeof **gotos * n_nonterminals);
    }

  for (i = 0; i < nC; i++)
    {
      int j;

      for (j = 0; j < n_symbols; j++)
	{
	  struct symbol *A;
	  struct list list;

	  A = &symbols[j];
	  if (A->nonterminal)
	    {
	      int k;

	      calc_goto (&list, &C[i], A->sym);
		  
	      for (k = 0; k < nC; k++)
		if (list_equal (&list, &C[k]))
		  {
		    gotos[i][A->nt_index] = k;
		    break;
		  }

	      list_free (&list);
	    }
	}
    }

  fputs ("/* Go to table.  This is goto[][] from Fig. 4.30, \"LR parsing\n"
	 "   program\", in Aho, Sethi, and Ullman. */\n"
	 "static const unsigned char goto_table[n_states][n_nonterminals] =\n"
	 "  {\n"
	 "    /*        ", stdout);
  for (i = 0; i < n_symbols; i++)
    if (symbols[i].nonterminal)
      printf (" %c ", symbols[i].sym);
  fputs ("*/\n", stdout);
  for (i = 0; i < nC; i++)
    {
      int j;
      
      printf ("    /*%3d */ {", i);
      for (j = 0; j < n_symbols; j++)
	{
	  struct symbol *sym = &symbols[j];
	  
	  if (sym->nonterminal)
	    {
	      if (sym->nt_index != 0)
		putchar (',');
	      
	      printf ("%2d", gotos[i][sym->nt_index]);
	    }
	}
  
      fputs ("},\n", stdout);
    }
  fputs ("  };\n\n", stdout);

  for (i = 0; i < nC; i++)
    free (gotos[i]);
  free (gotos);
}
Esempio n. 14
0
int compare_entry_state (Entry_State *entry1, Entry_State *entry2, int run)
{
	int j;
	int error = 0;

	/* first - quick check for present / not present */
	for (j = 0; j < sim.value_count; j++)
	{
		if (entry1->values[j].present != entry2->values[j].present)
		{
			fprintf (sim.fout, 
				"value %s is %s present in the first run but %s present in the %d run\n",
					 g_values[j], entry1->values[j].present ? "" : "not",	
					 entry2->values[j].present ? "" : "not", run);
			error = 1;
		}					 
	}

	if (error)
		return 3;

	/* compare value state */
	error = 0;
	if (entry1->attr_delete_csn != entry2->attr_delete_csn)
	{
		fprintf (sim.fout, "attribute delete csn is %d for run 1 "
				 "but is %d for run %d\n", entry1->attr_delete_csn, 
				 entry2->attr_delete_csn, run);
		error = 1;
	}

	for (j = 0; j < sim.value_count; j++)
	{
		if (entry1->values[j].presense_csn != entry2->values[j].presense_csn)
		{
			fprintf (sim.fout, "presence csn for value %s is %d in run 1 "
					 "but is %d in run %d\n", g_values[j], entry1->values[j].presense_csn, 
					 entry2->values[j].presense_csn, run);
			error = 1;
		}

		if (entry1->values[j].distinguished_csn != entry2->values[j].distinguished_csn)
		{
			fprintf (sim.fout, "distinguished csn for value %s is %d in run 1 "
					 "but is %d in run %d\n", g_values[j], entry1->values[j].distinguished_csn, 
					 entry2->values[j].distinguished_csn, run);
			error = 1;
		}

		if (entry1->values[j].delete_csn != entry2->values[j].delete_csn)
		{
			fprintf (sim.fout, "delete csn for value %s is %d in run 1 "
					 "but is %d in run %d\n", g_values[j], entry1->values[j].delete_csn, 
					 entry2->values[j].delete_csn, run);
			error = 1;
		}
		
		if (!list_equal (entry1->values[j].non_distinguished_csns,
						 entry2->values[j].non_distinguished_csns))
		{
			fprintf (sim.fout, "pending list mismatch for valye %s in runs 1 and %d\n", 
					 g_values[j], run);
			dump_list (entry1->values[j].non_distinguished_csns);
			dump_list (entry2->values[j].non_distinguished_csns);			
		}			 
	}

	if (error != 0)
	{
		return 1;
	}
	else
		return 0;
}
Esempio n. 15
0
char list_not_equal(array x, array y) {
    return !list_equal(x,y);
}