Exemplo n.º 1
0
int		main(int ac, char **av)
{
  unsigned char	board[MEM_SIZE];
  t_vm		*vm;
  t_dlist	*list;
  t_dlist	*list_s;

  if (ac < 2)
    return (0);
  list = NULL;
  list_s = NULL;
  list = new_list(list);
  list_s = new_list(list_s);
  init_board(board);
  vm = NULL;
  vm = new_vm(vm);
  fill_list(list, av);
  check_debug(list, vm);
  syntax(list);
  find_dump(list, vm);
  find_champ(list, vm, board, 0);
  id_champ(vm);
  champ_id_reg(vm);
  init_alive(vm);
  start_vm(vm, board);
  winning(vm);
  return (0);
}
Exemplo n.º 2
0
Arquivo: parser2.c Projeto: tungvx/FSE
static AST block() {
    Token *t = &tok;
    AST a=0;
    AST vdl, fdl, sts;

    vdl = new_list(nVARDECLS);
    fdl = new_list(nFUNCDECLS);
    if(t->sym == '{') {
	gettoken();
	enter_block();

	vardecls(vdl,fdl);
	funcdecls(fdl);
	sts = stmts();

	a = make_AST(nBLOCK, vdl, fdl, sts, 0);
	leave_block();

	if (t->sym == '}') gettoken();
	else parse_error("expected }");

    } else {
	parse_error("expected {");
    }
    return a;
}
Exemplo n.º 3
0
/**
 * Initialize an interpreter instance.
 *
 * @param activity The root activity for the interpreter instance.
 * @param handlers The exit handlers used by all threads running under this instance.
 * @param defaultEnvironment
 *                 The default address environment for this interpreter instance.  Each
 *                 active interpreter instance can define its own default environment.
 */
void InterpreterInstance::initialize(RexxActivity *activity, RexxOption *options)
{
    rootActivity = activity;
    allActivities = new_list();
    searchExtensions = new_list();     // this will be filled in during options processing
    requiresFiles = new_directory();   // our list of loaded requires packages
    // this gets added to the entire active list.
    allActivities->append((RexxObject *)activity);
    globalReferences = new_identity_table();
    // create a default wrapper for this security manager
    securityManager = new SecurityManager(OREF_NULL);
    // set the default system address environment (can be overridden by options)
    defaultEnvironment = SystemInterpreter::getDefaultAddressName();
    // our list of command handlers (must be done before options are processed)
    commandHandlers = new_directory();

    // associate the thread with this instance
    activity->setupAttachedActivity(this);
    // create a local environment
    localEnvironment = new_directory();
    processOptions(options);
    // when handled originally, we didn't have the exits setup
    // do this now.
    activity->setupExits();
    // do system specific initialization
    sysInstance.initialize(this, options);
    // register the system command handlers for this platform.
    sysInstance.registerCommandHandlers(this);
    // now do the local initialization;
    Interpreter::initLocal();
}
Exemplo n.º 4
0
list from_string(char *s, char **e, list parent)
{
	list ret = 0;
	if (!parent) parent = new_list();

	while (*s != '\0') {
		if (*s == ']') {
			if (e) *e = s + 1;
			return parent;
		}
		if (*s == '[') {
			ret = new_list();
			ret->is_list = 1;
			ret->ival = 0;
			append(parent, ret);
			from_string(s + 1, &s, ret);
			continue;
		}
		if (*s >= '0' && *s <= '9') {
			ret = new_list();
			ret->is_list = 0;
			ret->ival = strtol(s, &s, 10);
			append(parent, ret);
			continue;
		}
		s++;
	}

	if (e) *e = s;
	return parent;
}
Exemplo n.º 5
0
Var process_result_set (MYSQL_CONN *conn, MYSQL_RES *res_set)
{
MYSQL_ROW    row;
unsigned int  i;
 int len = 0;
 int count = 1;
 int lcv = 1;
 len = mysql_num_rows(res_set);
 Var r;
 r.type = TYPE_LIST;
 if (len < 1)
   {
     r = new_list(0);
     mysql_free_result (res_set);
     return r;
   }
     
 r = new_list(len);
 while ((row = mysql_fetch_row (res_set)) != NULL)
    {
      r.v.list[count].type = TYPE_LIST;
      r.v.list[count].v.list = process_row(res_set,(const MYSQL_ROW*)row).v.list;
      count++;
    }
 mysql_free_result (res_set);
 return r;
}
Exemplo n.º 6
0
Arquivo: parser2.c Projeto: tungvx/FSE
static AST classdecl() {
    Token *t = &tok;
    AST a=0;
    AST a1=0, a2=0, a3=0, a4 = 0, a5 = 0;
    AST sdl = 0, vdl=0, fdl=0;  /* struct, var and func decl list */

    a1 = classhead();

    if (t->sym == '{') {
	gettoken();
	enter_block();

	sdl = new_list(nSTRUCTS);
	vdl = new_list(nVARDECLS);
	fdl = new_list(nFUNCDECLS);

	a2 = structdecls(sdl);
	if (t->sym == tCLASS) a3 = classdecls();
	a4 = vardecls(vdl, fdl);
	a5 = funcdecls(fdl);
	leave_block();

	if (t->sym == '}') {
	    gettoken();
	    a = make_AST(nCLASSBODY, a2, a3, a4, a5);
	    a = make_AST(nCLASSDECL, a1, a, 0, 0);
	} else {
	    parse_error("expected }");
	}

    } else {
	parse_error("expected {");
    }
    return a;
}
Exemplo n.º 7
0
void destroy_itemset( struct itemset * this_itemset ) {
    int i;
    char * key;
    struct list * key_list = new_list();
    list_keys_in_hash( this_itemset->items, key_list, "" );
    for ( i = 0; i < key_list->next_index; i++ ) {
        key = listlookup( key_list, i );
        struct item * data = hashlookup( this_itemset->items, key )->data;
        free( data );
    }
    destroy_key_list( key_list );
    destroy_hash( this_itemset->items );
    key_list = new_list();
    list_keys_in_hash( this_itemset->ready_for, key_list, "" );
    for ( i = 0; i < key_list->next_index; i++ ) {
        key = listlookup( key_list, i );
        struct list * ready_items = hashlookup( this_itemset->ready_for, key )->data;
        destroy_list( ready_items );
    }
    destroy_key_list( key_list );
    destroy_hash( this_itemset->ready_for );
    destroy_list( this_itemset->complete );
    free( this_itemset );
    return;
}
Exemplo n.º 8
0
static package
bf_has_callable_verb(Var arglist, Byte next, void *vdata, Objid progr)
{                               /* (object) */
    Objid oid = arglist.v.list[1].v.obj;

    if (!valid(oid)) {
	free_var(arglist);
	return make_error_pack(E_INVARG);
    } else if (!db_object_allows(oid, progr, FLAG_READ)) {
	free_var(arglist);
	return make_error_pack(E_PERM);
    } else {
	db_verb_handle vh;
	Var result;

	vh = db_find_callable_verb(oid, arglist.v.list[2].v.str);

	if (vh.ptr) {
	    result = new_list(1);
	    result.v.list[1].type = TYPE_OBJ;
	    result.v.list[1].v.obj = db_verb_definer(vh);
	} else {
	    result = new_list(0);
	}
	free_var(arglist);
	return make_var_pack(result);
    }
}
Exemplo n.º 9
0
int main(int argc, char** argv) {

	list* l;
	str* a = ref("hello",5);
	str* b = ref("world",5);

	ok(NULL == new_list(0), "allocate an empty list");	
	ok(NULL == new_list(1), "allocate a list with one element");
	ok(NULL != (l = new_list(2)), "allocate a list with two elements");
	value(2, l->size, "test the size of the list");	
	value(0, l->start, "test the start position");	
	value(0, l->end, "test the start position");	
	push(l,a);
	value(0, l->start, "test pushing start value");
	value(1, l->end, "test pushing end value");
	value(1, length(l), "has one element");
	push(l,b);
	value(0, l->start, "test pushing second  start value");
	value(2, l->end, "test pushing second end value");
	value(2, length(l), "has one element");
	ok(a == shift(l), "shift a");
	value(1, length(l), "has one element");
	ok(b == shift(l), "shift b");
	value(0, length(l), "has one element");
	ok(a == shift(l), "shift a again");
	value(-1, length(l), "has negative one elements");
	
	return done("test_list");
}
Exemplo n.º 10
0
Arquivo: buffer.c Projeto: dmt4/ne
buffer *alloc_buffer(const buffer * const cur_b) {

	buffer *b;

	if (b = calloc(1, sizeof(buffer))) {

		new_list(&b->line_desc_pool_list);
		new_list(&b->line_desc_list);
		new_list(&b->char_pool_list);

		b->cur_macro = alloc_char_stream(0);
		b->opt.tab_size = 8;

		b->opt.insert         =
		b->opt.tabs           =
		b->opt.shift_tabs     =
		b->opt.automatch      =
		b->opt.do_undo        =
		b->opt.auto_prefs     = 1;

		b->opt.utf8auto = io_utf8;

		b->attr_len = -1;

		if (cur_b) {

			b->opt.cur_clip       = cur_b->opt.cur_clip;
			b->opt.tab_size       = cur_b->opt.tab_size;
			b->opt.tabs           = cur_b->opt.tabs;
			b->opt.del_tabs       = cur_b->opt.del_tabs;
			b->opt.shift_tabs     = cur_b->opt.shift_tabs;
			b->opt.automatch      = cur_b->opt.automatch;
			b->opt.right_margin   = cur_b->opt.right_margin;

			b->opt.free_form      = cur_b->opt.free_form;
			b->opt.hex_code       = cur_b->opt.hex_code;
			b->opt.word_wrap      = cur_b->opt.word_wrap;
			b->opt.auto_indent    = cur_b->opt.auto_indent;
			b->opt.preserve_cr    = cur_b->opt.preserve_cr;

			b->opt.do_undo        = cur_b->opt.do_undo;
			b->opt.auto_prefs     = cur_b->opt.auto_prefs;
			b->opt.no_file_req    = cur_b->opt.no_file_req;

			b->opt.case_search    = cur_b->opt.case_search;
			b->opt.binary         = cur_b->opt.binary;
			b->opt.utf8auto       = cur_b->opt.utf8auto;
			b->opt.visual_bell    = cur_b->opt.visual_bell;

		}
		/* This leaves out onlyopt.read_only and opt.search_back, which are
		 implicitly set to 0 by the calloc(). */
		return b;
	}

	return NULL;
}
Exemplo n.º 11
0
list_t* find_and_report(const char* datafile, const char mode, int pkgc, list_t* argv)
{
	// set quiet to avoid print results of search_record()
	unsigned short int hold_quiet=quiet;
	quiet = 1;

	int i=0;
	int found = 0;
	unsigned short int fcount = 0;
	unsigned short int mcount = 0;
	
	list_t* founded = new_list(0);
	list_t* missing = new_list(0);
	
	for (i=0; i<pkgc; i++)
	{	
		char* pkg  = get_list(argv,i);
		char buf[1024];
		strcpy(buf, pkg);
		
		char* tk = strtok(buf, "|");
		while(tk != NULL)
		{
			found = 0;
			if(search_record(datafile, tk))
			{
				found = 1;
				break;
			}
			tk = strtok(NULL, " ,");
		}
	
		if(found == 1)
		{
			fcount = fcount+1;
			resize_list(founded,fcount);
			add_list(founded,fcount-1,tk);
		} else {
			mcount = mcount+1;
			resize_list(missing,mcount);
			add_list(missing,mcount-1,pkg);
		}
	}
	quiet = hold_quiet;
	
	switch(mode)
	{
		case 'f' :
			return(founded);
		case 'm' :
			return(missing);
	}
	
	destroy_list(founded);
	destroy_list(missing);
	return(NULL);
}
Exemplo n.º 12
0
struct parser_generator * new_parser_generator() {
    struct list * my_itemsets = new_list();
    struct hash * my_itemsets_by_key = new_hash();
    struct list * my_TABLE = new_list();
    struct list * my_GOTO = new_list();
    struct parser_generator * this_parser_generator = malloc( sizeof( struct parser_generator ) );
    this_parser_generator->itemsets = my_itemsets;
    this_parser_generator->itemsets_by_key = my_itemsets_by_key;
    this_parser_generator->TABLE = my_TABLE;
    this_parser_generator->GOTO = my_GOTO;
    return this_parser_generator;
}
Exemplo n.º 13
0
t_linked_list	*normalize_indentation(t_linked_list *resolved_layer, t_linked_list **strings)
{
	int				i;
	int				x;
	int				y;
	t_linked_list	*tmp_line;
	t_linked_list	*normalized;
	t_linked_list	*tmp_normalized;
	t_linked_list	*new_strings;
	t_linked_list	*tmp_strings;
	char			char_nb;
	char			*tmp_char;

	new_strings = new_list();
	normalized = new_list();
	char_nb = 0;
	i = 0;
	while (i < resolved_layer->len)
	{
		tmp_normalized = new_list();
		tmp_strings = new_list();
		tmp_line = ((t_linked_list*)resolved_layer->elts[i]);
		x = 0;
		while (x < tmp_line->len && (*((char*)tmp_line->elts[x]) == TAB || *((char*)tmp_line->elts[x]) == SPACE))
			x++;
		if (x != 0 && char_nb == 0)
			char_nb = x;
		y = 0;
		while (char_nb > 0 && y < x / char_nb)
		{
			if (!(tmp_char = (char*)malloc(sizeof(char))))
				malloc_error();
			*tmp_char = INDENT;
			add_to_list(tmp_normalized, tmp_char);
			add_to_list(tmp_strings, ft_strdup("\t"));
			y++;
		}
		while (x < tmp_line->len)
		{
			if (!(tmp_char = (char*)malloc(sizeof(char))))
				malloc_error();
			*tmp_char = *((char*)tmp_line->elts[x]);
			add_to_list(tmp_normalized, tmp_char);
			add_to_list(tmp_strings, ((char*)((t_linked_list*)(*strings)->elts[i])->elts[x]));
			x++;
		}
		add_to_list(normalized, tmp_normalized);
		add_to_list(new_strings, tmp_strings);
		i++;
	}
	*strings = new_strings;
	return (normalized);
}
Exemplo n.º 14
0
void parse_prog(struct list *prog) {
    struct list *cells = new_list(30000);
    struct list *loops = new_list(1000);
    int *cell_i = malloc(sizeof(int)); // current cell
    int *prog_i = malloc(sizeof(int)); // current position in program
    *cell_i = 0;
    *prog_i = 0;
    char c;
    while ((c = peek(prog, *prog_i))) {
        parse_char(c, cells, loops, cell_i, prog_i);
        //sleep(1);
    }
}
Exemplo n.º 15
0
/*
 * add to the dependecy and selection lists
 */
static void add_depend(struct makenode *node, const char *dst)
{
	struct makenode *dep;

	dep = add_target(dst);
	loop = 0;
	if (check_loop(dep, node))
		return;
	dep->select = new_list(node, dep->select);
	dep->num_sels++;
	node->depend = new_list(dep, node->depend);
	node->num_deps++;
}
Exemplo n.º 16
0
list flatten(list from, list to)
{
	int i;
	list t;

	if (!to) to = new_list();
	if (!from->is_list) {
		t = new_list();
		*t = *from;
		append(to, t);
	} else
		for (i = 0; i < from->ival; i++)
			flatten(from->lst[i], to);
	return to;
}
Exemplo n.º 17
0
void	add_list(t_lst **list, t_node *node_p)
{
	t_lst	*list_p;

	list_p = *list;
	if (list_p == NULL)
	{
		*list = new_list(node_p);
		return ;
	}
	while (list_p != NULL)
		list_p = list_p->next;
	list_p = new_list(node_p);
	return ;
}
/**
 * Find possible actions left on a row
 *
 * @param state a game state
 * @param row the row to check
 * @return a list of actions
 */
static struct List * actions_left( const struct State * state, int row )
{
    int idx = SIZE-1;
    struct List * actions = new_list();

     for(idx = SIZE - 1; (idx > 0) && ((idx - 2) >= 0); idx--){
       if( (state->board[ row ][idx] == state->player )
	    && (state->board[ row ][ idx - 1 ] == opposite_player( state->player ))
	    && (state->board[ row ][ idx - 2 ] == 'O')){
	   /* check for moves  - increment to optimize move*/
	   int end_col = idx - 2;
	   /* add move to action list for single jump  */
	   add_front( &actions, new_move( row, idx, row, end_col) );
	   while( ((end_col - 2) > 0 )
	        && (state->board[ row ][ end_col ] == 'O' )
	        && (state->board[ row ][ end_col - 1 ] == opposite_player( state->player ))
	        && (state->board[ row ][ end_col - 2 ] == 'O') ){
	     end_col -= 2;
	     /* add optimized moves to action list */ 
	     add_front( &actions, new_move( row, idx, row, end_col) );
	   }
       }
     }

    return actions;
}
/**
 * Find possible actions down on a column
 *
 * @param state a game state
 * @param col the column to check
 * @return a list of actions
 */
static struct List * actions_down( const struct State * state, int col )
{
    int idx = 0;
    struct List * actions = new_list();

    for(idx = 0; (idx < SIZE) && ((idx + 2) < SIZE); idx++){
      if(  (state->board[ idx ][col] == state->player )
	    && (state->board[ idx + 1 ][ col ] == opposite_player( state->player ))
	    && (state->board[ idx + 2 ][ col ] == 'O')){
	   /* check for moves  - increment to optimize move*/
	   int end_row = idx + 2;
	   /* add move to action list for single jump  */
	   add_front( &actions, new_move( idx, col, end_row, col) );
	   while( ((end_row + 2) < SIZE )
	        && (state->board[ end_row ][ col ] == 'O' )
	        && (state->board[ end_row + 1 ][ col ] == opposite_player( state->player ))
	        && (state->board[ end_row + 2 ][ col ] == 'O') ){
	     end_row += 2;
	     /* add optimized moves to action list */
	     add_front( &actions, new_move( idx, col, end_row, col) );
	   }
      }
    }
    
    return actions;
}
Exemplo n.º 20
0
static package
bf_verb_code(Var arglist, Byte next, void *vdata, Objid progr)
{				/* (object, verb-desc [, fully-paren [, indent]]) */
    int nargs = arglist.v.list[0].v.num;
    Objid oid = arglist.v.list[1].v.obj;
    Var desc = arglist.v.list[2];
    int parens = nargs >= 3 && is_true(arglist.v.list[3]);
    int indent = nargs < 4 || is_true(arglist.v.list[4]);
    db_verb_handle h;
    Var code;
    enum error e;

    if ((e = validate_verb_descriptor(desc)) != E_NONE
	|| (e = E_INVARG, !valid(oid))) {
	free_var(arglist);
	return make_error_pack(e);
    }
    h = find_described_verb(oid, desc);
    free_var(arglist);

    if (!h.ptr)
	return make_error_pack(E_VERBNF);
    else if (!db_verb_allows(h, progr, VF_READ))
	return make_error_pack(E_PERM);

    code = new_list(0);
    unparse_program(db_verb_program(h), lister, &code, parens, indent,
		    MAIN_VECTOR);

    return make_var_pack(code);
}
Exemplo n.º 21
0
static package
bf_verb_args(Var arglist, Byte next, void *vdata, Objid progr)
{				/* (object, verb-desc) */
    Objid oid = arglist.v.list[1].v.obj;
    Var desc = arglist.v.list[2];
    db_verb_handle h;
    db_arg_spec dobj, iobj;
    db_prep_spec prep;
    Var r;
    enum error e;

    if ((e = validate_verb_descriptor(desc)) != E_NONE
	|| (e = E_INVARG, !valid(oid))) {
	free_var(arglist);
	return make_error_pack(e);
    }
    h = find_described_verb(oid, desc);
    free_var(arglist);

    if (!h.ptr)
	return make_error_pack(E_VERBNF);
    else if (!db_verb_allows(h, progr, VF_READ))
	return make_error_pack(E_PERM);

    db_verb_arg_specs(h, &dobj, &prep, &iobj);
    r = new_list(3);
    r.v.list[1].type = TYPE_STR;
    r.v.list[1].v.str = unparse_arg_spec(dobj);
    r.v.list[2].type = TYPE_STR;
    r.v.list[2].v.str = str_dup(db_unparse_prep(prep));
    r.v.list[3].type = TYPE_STR;
    r.v.list[3].v.str = unparse_arg_spec(iobj);

    return make_var_pack(r);
}
Exemplo n.º 22
0
linked_list* make_pathlist(char* path_string)
{
   linked_list* list;
   int start,i,end;
   char* path;

   list = new_list();

   if (!path_string)
      return(list);

   start = 0;
   i = 0;
   end = strlen(path_string);

   /* if (!end)
      return(list); */

   while (i <= end)
   {
      if ((path_string[i] == ':') || (path_string[i] == '\0'))
      {
         path = (char*) malloc((i - start) + 1);
         strncpy(path, path_string + start, i - start);
         path[i - start] = '\0';
         add_to_tail(list, path);
         start = i + 1;
      }

      i++;
   }

   return(list);
}
Exemplo n.º 23
0
} END_TEST

// Ensure a list can be reversed with the expected values
// ✔ Data should be ordered as expected
START_TEST (test_reverse_list) {
  kld_list_t * list = (kld_list_t *) new_list();
  char * vals[4] = {"foo", "bar", "baz", "buz"};
  char * reversed_vals[4] = {"buz", "baz", "bar", "foo"};

  int i;
  for(i = 0; i < 4; i++) {
    list_append(list, vals[i]);  
  }
  
  kld_list_t * reversed_list = (kld_list_t*) list_reverse(list);
  kld_list_node_t * rev_current = reversed_list->head;

  int rev_count;

  for(rev_count = 0; rev_count < 4; rev_count++) {
    fail_if(strcmp(rev_current->data, reversed_vals[rev_count]) != 0, "Unexpected data");
    rev_current = rev_current->next;
  }

} END_TEST
Exemplo n.º 24
0
LIST* list_add_at(LIST* head, char* data, int index)
{
    LIST* new_node = new_list();
    LIST* list = head;
    int i = 0;

    new_node->value = data;
    while (list != NULL)
    {
        if (i == index) {
            new_node->next = list->next;
            list->next = new_node->next;
            break;
        }

        inc(list);
        i++;
    }

    if (list == NULL) {
        list = tail(head);
        list->next = new_node;
        new_node->next = NULL;
    }

    return head;
}
Exemplo n.º 25
0
char * print_hash_key_set( struct hash * current ) {
    struct list * var_list = new_list();
    list_keys_in_hash( current, var_list, "" );
    int var_list_len = 0;
    int i = var_list->next_index;
    while ( i-- ) {
        var_list_len += strlen(listlookup( var_list, i ));
    }
    int brace_len = BRACE_LEN;
    int comma_len = COMMA_LEN;
    char * key_set_str = malloc(
                             ( var_list->next_index  * comma_len
                               + var_list_len
                               + 2 * brace_len
                               + 1
                             ) * sizeof(char)
                         );

    *key_set_str = '\0';
    sprintf( key_set_str, "{" );
    i = var_list->next_index;
    while ( i-- ) {
        strcat( key_set_str, listlookup( var_list, i ));
        if ( i ) {
            strcat( key_set_str, "," );
        }
    }
    strcat( key_set_str, "}" );
    destroy_key_list(var_list);
    return key_set_str;
}
Exemplo n.º 26
0
void	add_cylinder(t_env *env, char **tab)
{
	t_point		p;
	t_list		*list;
	char		**split;

	split = ft_strsplit(tab[1], ',');
	p.x = ft_atoi(split[0] + 1);
	p.y = ft_atoi(split[1]);
	p.z = ft_atoi(split[2]);
	list = new_list(p, hex_to_i(tab[4]));
	list->name = "cylinder";
	ft_strsplit_clr(split);
	split = ft_strsplit(tab[2], ',');
	list->ori.x = ft_atoi(split[0] + 1);
	list->ori.y = ft_atoi(split[1]);
	list->ori.z = ft_atoi(split[2]);
	list->ori = norm(list->ori);
	list->radius = ft_atoi(tab[3]);
	list->diffuse = ft_atoi(tab[5]) / 100.0;
	list->specular = ft_atoi(tab[6]) / 100.0;
	list->phong = ft_atoi(tab[7]);
	list->fun = &(keyword[3]);
	env->object = add_list_list(env->object, list);
	ft_strsplit_clr(split);
}
Exemplo n.º 27
0
Arquivo: mct.c Projeto: elominp/zappy
bool
mct(t_cli *c, t_msg *msg)
{
  int64_t	x;
  int64_t	y;
  int64_t	xmax;
  int64_t	ymax;
  t_list	*params;

  (void)msg;
  x = 0;
  y = 0;
  xmax = c->servptr->map.width;
  ymax = c->servptr->map.height;
  if ((params = new_list()) == NULL || init_list(params) == false)
    return (ERR(RED"Omg malloc failed, BAIL OUT BAIL OUT\n"WHITE), false);
  while (y <= xmax)
    {
      while (x <= ymax)
	{
	  prepare_message(params, x, y);
	  bct(c, &(t_msg){NULL, "bct", params, 0});
	  x++;
	}
      x = 0;
      y++;
    }
  return (list_destruct(&params, &free), true);
}
Exemplo n.º 28
0
Arquivo: find.c Projeto: ryuever/sgrid
/** Search for objects that match criteria
	\p start may be a previous search result, or \p FT_NEW.
	\p FT_NEW starts a new search (starting with all objects)

	Searches criteria may be as follows:

		find_objects(\p FT_NEW, \p ftype, \p compare, \p value[, ...], \p NULL);

	and may be grouped using \p AND and \p OR.

	The criteria list must be terminated by \p NULL or \p FT_END.

	Values of \p ftype are:
		- \p FT_ID		 compares object ids (expects \e long value)
		- \p FT_SIZE	 compares object size excluding header (expects \e long value)
		- \p FT_CLASS	 compares object class name (expects \e char* value)
		- \p FT_PARENT	 uses parent for comparison (must be followed by another \p ftype)
		- \p FT_RANK	 compares object rank by number (expects \e long value)
		- \p FT_CLOCK	 compares object clock (expects \e TIMESTAMP value)
		- \p FT_PROPERTY compares property (expects \e char* value)
		- \p FT_MODULE	 compares module name
		- \p FT_ISA		 compares object class name including parent classes (expected \e char* value)

	Extended values of \p ftype are:
		- \p CF_NAME	looks for a particular name
		- \p CF_LATT	compares object lattitudes
		- \p CF_LONG	compares object longitudes
		- \p CF_INSVC	checks in-service timestamp
		- \p CF_OUTSVC	checks out-service timestamp

	Values of \p compare are:
		- \p EQ			equal
		- \p NE			not equal
		- \p LT			less than
		- \p GT			greater than
		- \p LE			less than or equal
		- \p GE			greather than or equal
		- \p NOT		opposite of test
		- \p BETWEEN	in between
		- \p SAME		same string
		- \p BEFORE	    alphabetic before
		- \p AFTER		alphabetic after
		- \p DIFF		alphabetic differ
		- \p MATCH		matches \e regex
		- \p LIKE		matches \e regex
		- \p UNLIKE		matches "not" \e regex

	Conjunctions are \e AND and \e OR, and can be used to do complex searches

	OBJECT *find_first(FINDLIST *list) returns the first object in the result list

	OBJECT *find_next(FINDLIST *list, OBJECT *previous) returns the next object in the result list

	@return a pointer for FINDLIST structure used by find_first(), find_next, and find_makearray(), will return NULL if an error occurs.
**/
FINDLIST *find_objects(FINDLIST *start, ...)
{	
	int ival;
	char *sval;
	OBJECTNUM oval;
	TIMESTAMP tval;
	double rval;
	OBJECT *obj;
	FINDLIST *result = start;
	if (start==FL_NEW || start==FL_GROUP)
	{
		result=new_list(object_get_count());
		ADDALL(*result);
	}
	/* FL_GROUP is something of an interrupt option that constructs a program by parsing string input. */
	if (start==FL_GROUP)
	{
		FINDPGM *pgm;
		va_list(ptr);
		va_start(ptr,start);
		pgm = find_mkpgm(va_arg(ptr,char*));
		if (pgm!=NULL){
			return find_runpgm(result,pgm);
		} else {
			va_end(ptr);
			DELALL(*result); /* pgm == NULL */
			return result;
		}
	}
Exemplo n.º 29
0
} END_TEST

// Ensure a single value is appended to a list as expected
// ✔ Head should be updated
// ✔ Tail should be updated
// ✔ Data should be the same
START_TEST (test_append_2_list) {
  kld_list_t * list = (kld_list_t *) new_list();
  char * buf = "test data";
  list_append(list, buf);

  char * buf2 = "test data2";
  list_append(list, buf2);
  
  fail_if(list->head == NULL, "Head is NULL");
  fail_if(list->tail == NULL, "Tail is NULL");

  fail_if(list->head->data == list->tail->data, "Head and Tail data have not diverged");
  fail_if(list->head->data != "test data", "Unexecpted head node value");
  fail_if(list->tail->data != "test data2", "Unexecpted tail node value");

  fail_if(list->head->next != list->tail, "Incorrect next node for Head");
  fail_if(list->tail->prev != list->head, "Incorrect prev node for Tail");

  fail_if(list->size != 2, "Unexpected list size");
} END_TEST
Exemplo n.º 30
0
} END_TEST

// Ensure a two values can be prepended to a list as expected
// ✔ Head should be updated
// ✔ Tail should be updated
// ✔ Data should be the same
// ✔ Size should be updated 
START_TEST (test_prepend_2_shift_1_list) {
  kld_list_t * list = (kld_list_t *) new_list();
  char * buf2 = "test data2";
  list_prepend(list, buf2);

  char * buf = "test data";
  list_prepend(list, buf);

  list_shift(list);
  
  fail_if(list->head == NULL, "Head is NULL");
  fail_if(list->tail == NULL, "Tail is NULL");

  fail_if(list->head->data != list->tail->data, "Head and Tail data have diverged");
  fail_if(list->head->data != "test data2", "Unexecpted tail node value");

  fail_if(list->size != 1, "Unexpected list size");
} END_TEST