Пример #1
0
/**
 Szuka słowo w poddrzewie node'a
 @param[in] node Węzeł
 @param[in] word Słowo
 @return Nowy węzeł
 */
static bool node_find(trie_node *node, const wchar_t *word)
{
	assert(node != NULL);
	if(word[0] == L'\0')
		return node->end_of_word;
	if(word[0] == IGNORE_CHAR)
		return node_find(node, word + 1);
	trie_node *son = node_son(node, word[0]);
	if(son == NULL)
		return false;
	return node_find(son, word + 1);
}
Пример #2
0
void
fen_remove (const gchar *filename, gpointer sub, gboolean is_mondir)
{
    node_t* f;
    
    g_assert (filename);
    g_assert (sub);

    G_LOCK (fen_lock);
	f = node_find(NULL, filename, FALSE);
    FH_W ("%s 0x%p sub[0x%p] %s\n", __func__, f, sub, filename);

    if (f) {
        if (is_mondir) {
            f->dir_subs = g_list_remove(f->dir_subs, sub);
        } else {
            f->subs = g_list_remove(f->subs, sub);
        }

        if (!NODE_IS_ACTIVE(f)) {
            node_try_delete (f);
        }
    }
    G_UNLOCK (fen_lock);
}
Пример #3
0
int lf_add_dependency_cpp(lua_State *L)
{
	struct CONTEXT *context;
	struct DEFERRED *deferred;
	struct NODE * node;
	int n = lua_gettop(L);
	
	if(n != 1)
		luaL_error(L, "add_dependency_cpp: incorrect number of arguments");
	luaL_checkstring(L,1);
	
	context = context_get_pointer(L);
	node = node_find(context->graph, lua_tostring(L,1));

	if(!node)
		luaL_error(L, "add_dependency_cpp: couldn't find node with name '%s'", lua_tostring(L,1));

	deferred = (struct DEFERRED *)mem_allocate(context->deferredheap, sizeof(struct DEFERRED));
	deferred->node = node;
	deferred->user = current_includepaths;
	deferred->run = dependency_cpp_do_run;
	deferred->next = context->firstdeferred_cpp;
	context->firstdeferred_cpp = deferred;
	return 0;
}
Пример #4
0
/* add_output(string output, string other_output) */
int lf_add_output(lua_State *L)
{
	struct NODE *output;
	struct NODE *other_output;
	struct CONTEXT *context;
	int i;
	const char *filename;
	
	if(lua_gettop(L) != 2)
		luaL_error(L, "add_output: incorrect number of arguments");

	luaL_checktype(L, 1, LUA_TSTRING);
	luaL_checktype(L, 2, LUA_TSTRING);
	
	context = context_get_pointer(L);

	output = node_find(context->graph, lua_tostring(L,1));
	if(!output)
		luaL_error(L, "add_output: couldn't find node with name '%s'", lua_tostring(L,1));

	if(!output->job->real)
		luaL_error(L, "add_output: '%s' does not have a job", lua_tostring(L,1));


	filename = lua_tostring(L, -1);
	i = node_create(&other_output, context->graph, filename, output->job);
	if(i == NODECREATE_NOTNICE)
		luaL_error(L, "add_output: node '%s' is not nice", filename);
	else if(i == NODECREATE_EXISTS)
		luaL_error(L, "add_output: node '%s' already exists", filename);
	else if(i != NODECREATE_OK)
		luaL_error(L, "add_output: unknown error creating node '%s'", filename);

	return 0;
}
Пример #5
0
bool trie_find(trie_tree *tree, const wchar_t *word)
{
	assert(tree != NULL);
	if(tree->root == NULL)
		return false;
	return node_find(tree->root, word);
}
Пример #6
0
void node_add(node_t **n, int value)
{
  node_t **found = node_find(n, value);

  if (*found == NULL)
    {
      *found = node_new(value);
    }
}
Пример #7
0
Файл: RT1.C Проект: g8bpq/BPQ32
int rtloginl ()
{
	LINK    *link;
	CIRCUIT *circuit;
	SADDR   sp;
	char    *buf, call[ln_axaddr+1];

	if (MemLow) return cmd_exit;
	getpeername(CurProc->input, &sp);
	if (sp.type isnt TYPE_NETROM) return cmd_exit;
	ax2str(call, sp.a.nr.node);
	if (node_find(call)) return cmd_exit; // Already linked.

	for (link = link_hd; link; link = link->next)
		if (matchi(call, link->call)) break;

	if (!link) return cmd_exit;           // We don't link with this system.
	if (link->flags & (p_linked | p_linkini)) return cmd_exit;  // Already linked.

// Accept the link request.

	puser(link->alias);
	buf = mallocw(LINE128);
	strcpy(buf, call);
	strlop(buf, '-');
	puser(buf);
	free(buf);

// Create a circuit for this link.

	circuit = circuit_new(p_linked, CurProc->output);
	if (!circuit) return cmd_exit;

	tputs("OK\n");
	circuit->u.link = link;
	link->flags     = p_linked;
	state_tell(circuit);
	makelinks();

// Run in circles, scream and shout.

	for (;;) if (getinp(circuit))
		chkctl(circuit);
	else
	{
		link_drop(circuit);
		link->flags = p_nil;
		return cmd_exit;
	}
}
Пример #8
0
static int node_findfile(struct GRAPH *graph, const char *filename, struct NODE **node, time_t *timestamp)
{
	/* first check the graph */
	*node = node_find(graph, filename);
	if(*node)
		return 1;

	/* then check the file system */
	*timestamp = file_timestamp(filename);
	if(*timestamp && file_isregular(filename))
		return 1;

	return 0;
}
Пример #9
0
/**
 * fen_add
 * 
 * Won't hold a ref, we have a timout callback to clean unused node_t.
 * If there is no value for a key, add it and return it; else return the old
 * one.
 */
void
fen_add (const gchar *filename, gpointer sub, gboolean is_mondir)
{
	node_t* f;

    g_assert (filename);
    g_assert (sub);

    G_LOCK (fen_lock);
	f = node_find(NULL, filename, TRUE);
    FH_W ("%s 0x%p sub[0x%p] %s\n", __func__, f, sub, filename);
    g_assert (f);

    /* Update timestamp, the events in global queue will compare itself to this
     * timestamp to decide if be emitted. TODO, timestamp should be per sub.
     */
    if (!NODE_IS_ACTIVE(f)) {
        g_get_current_time(&f->atv);
    }

    if (is_mondir) {
        f->dir_subs = g_list_prepend(f->dir_subs, sub);
    } else {
        f->subs = g_list_prepend(f->subs, sub);
    }
    
    if (NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED) ||
      (node_lstat(f) == 0 && port_add(f) == 0)) {
#ifndef GIO_COMPILATION
        gam_server_emit_one_event (NODE_NAME(f),
          gam_subscription_is_dir (sub), GAMIN_EVENT_EXISTS, sub, 1);
#endif
        if (is_mondir) {
            scan_children_init (f, sub);
        }
    } else {
#ifndef GIO_COMPILATION
        gam_server_emit_one_event (NODE_NAME(f),
          gam_subscription_is_dir (sub), GAMIN_EVENT_DELETED, sub, 1);
#endif
        node_adjust_deleted (f);
    }
#ifndef GIO_COMPILATION
    gam_server_emit_one_event (NODE_NAME(f),
      gam_subscription_is_dir (sub), GAMIN_EVENT_ENDEXISTS, sub, 1);
#endif
    G_UNLOCK (fen_lock);
}
Пример #10
0
/* nodeexist(string nodename) */
int lf_nodeexist(struct lua_State *L)
{
	struct NODE *node;
	
	if(lua_gettop(L) != 1)
		luaL_error(L, "nodeexists: takes exactly one argument");

	luaL_checktype(L, 1, LUA_TSTRING);
	
	node = node_find(context_get_pointer(L)->graph, lua_tostring(L,1));
	if(!node)
		lua_pushboolean(L, 1);
	else
		lua_pushboolean(L, 0);
	return 1;
}
Пример #11
0
static void xmlrpc_config_ready(void *vptr)
{
    /* Note: handle_xmlrpc.path may point to freed memory between
     * reading the config and here.
     */
    handle_xmlrpc.path = xmlrpc_config.path;

    if (handle_xmlrpc.handler != NULL)
    {
        if (node_find(&handle_xmlrpc, httpd_path_handlers))
            return;

        node_add(&handle_xmlrpc, node_create(), httpd_path_handlers);
    }
    else
        slog(LG_ERROR, "xmlrpc_config_ready(): xmlrpc {} block missing or invalid");
}
Пример #12
0
Файл: RT1.C Проект: g8bpq/BPQ32
static NODE *node_inc(char *call, char *alias)
{
	NODE *node;

	node = node_find(call);

	if (!node)
	{
		node = zallocw(sizeof(NODE));
		sl_ins_hd(node, node_hd);
		node->call  = strdup(call);
		node->alias = strdup(alias);
	}

	node->refcnt++;
	return node;
}
Пример #13
0
Файл: RT1.C Проект: g8bpq/BPQ32
static void makelinks(void)
{
	LINK *link;

	rtrun = true;

// Make the links.

	for (link = link_hd; link; link = link->next)
	{
// Is this link already established?
		if (link->flags & (p_linked | p_linkini)) continue;
// Already linked through some other node?
// If so, making this link would create a loop.
		if (node_find(link->call)) continue;
// Fire up the process to handle this link.
		link->flags = p_linkini;
		pcreate("RT", RT_STACK, link_out, PR_LINK, link);
	}
}
Пример #14
0
void _moddeinit(void)
{
    node_t *n;

    xmlrpc_unregister_method("atheme.login");
    xmlrpc_unregister_method("atheme.logout");
    xmlrpc_unregister_method("atheme.command");

    if ((n = node_find(&handle_xmlrpc, httpd_path_handlers)) != NULL)
    {
        node_del(n, httpd_path_handlers);
        node_free(n);
    }

    del_conf_item("PATH", &conf_xmlrpc_table);
    del_top_conf("XMLRPC");

    free(xmlrpc_config.path);

    hook_del_config_ready(xmlrpc_config_ready);
}
Пример #15
0
/* default_target(string filename) */
int lf_default_target(lua_State *L)
{
	struct NODE *node;
	struct CONTEXT *context;

	int n = lua_gettop(L);
	if(n != 1)
		luaL_error(L, "default_target: incorrect number of arguments");
	luaL_checktype(L, 1, LUA_TSTRING);

	/* fetch context from lua */
	context = context_get_pointer(L);

	/* search for the node */
	node = node_find(context->graph, lua_tostring(L,1));
	if(!node)
		luaL_error(L, "default_target: node '%s' not found", lua_tostring(L,1));
	
	/* set target */
	context_default_target(context, node);
	return 0;
}
Пример #16
0
static
int node_find_impl( mxml_node *n, const mxml_char_t * path, LIST_TYPE lst )
{
#define TMP_LIST_INIT_SIZE 32
	size_t length = 0;
	list_type tmp_list;

	list_init( &tmp_list, TMP_LIST_INIT_SIZE );
#undef TMP_LIST_INIT_SIZE

	if ( match_nodes( path, &length, n, &tmp_list ) == 0 )
	{
		size_t ii = 0;
		if ( length != 0 )
		{
			for ( ii = 0; ii < tmp_list.count; ++ii )
			{
				node_find( tmp_list.items[ ii ], path + length + 1, lst );
			}

			list_free( &tmp_list );
			return 0;
		}
		else
		{
			for ( ii = 0; ii < tmp_list.count; ++ii )
				lst->items[ lst->count + ii ] = tmp_list.items[ ii ];

			lst->count += tmp_list.count;

			list_free( &tmp_list );
			return 0;
		}		
	}
	
	list_free( &tmp_list );
	return -1;
}
Пример #17
0
int lf_set_filter(struct lua_State *L)
{
	struct NODE *node;
	const char *str;
	size_t len;
	
	/* check the arguments */
	if(lua_gettop(L) < 2)
		luaL_error(L, "set_filter: too few arguments");
		
	luaL_checktype(L, 1, LUA_TSTRING);
	luaL_checktype(L, 2, LUA_TSTRING);

	/* find the node */
	node = node_find(context_get_pointer(L)->graph, lua_tostring(L,1));
	if(!node)
		luaL_error(L, "set_filter: couldn't find node with name '%s'", lua_tostring(L,1));

	/* setup the string */	
	str = lua_tolstring(L, 2, &len);
	node->job->filter = (char *)mem_allocate(node->graph->heap, len+1);
	memcpy(node->job->filter, str, len+1);
	return 0;
}
Пример #18
0
int trie_check(TRIE **head,char *str) {
    TRIE *t = *head;
    int index = 0;
    while(*str) {
        TRIE *l = node_find(t,str,&index);
        if(l && index == strlen(l->str)) {
            str += index;
            if(*str) {
                t = l->son;
            } else {
                t = l;
                break;
            }
        } else {
            t = NULL;
            break;
        }
    }
    if(t) {
        return t->isEmail;
    } else {
        return false;
    }
}
Пример #19
0
/* add_dependency(string node, string dependency) */
static int add_node_attribute(lua_State *L, const char *funcname, struct NODE *(*callback)(struct NODE*, const char *))
{
	struct NODE *node;
	struct CONTEXT *context;
	int n = lua_gettop(L);
	struct NODEATTRIB_CBINFO cbinfo;
	
	if(n < 2)
		luaL_error(L, "%s: to few arguments", funcname);

	luaL_checktype(L, 1, LUA_TSTRING);

	context = context_get_pointer(L);

	node = node_find(context->graph, lua_tostring(L,1));
	if(!node)
		luaL_error(L, "%s: couldn't find node with name '%s'", funcname, lua_tostring(L,1));
	
	/* seek deps */
	cbinfo.node = node;
	cbinfo.callback = callback;
	deep_walk(L, 2, n, callback_node_attrib, &cbinfo);
	return 0;
}
Пример #20
0
Файл: RT1.C Проект: g8bpq/BPQ32
static void chkctl(CIRCUIT *ckt_from)
{
	NODE    *node, *ln;
	CIRCUIT *ckt_to;
	USER    *user, *su;
	char    *ncall, *ucall, *f1, *f2, *buf;

	if (ckt_from->buf[FORMAT_O] != FORMAT) return; // Not a control message.
	buf = strdup(ckt_from->buf + DATA_O);

// FORMAT and TYPE bytes are followed by node and user callsigns.

	ncall = buf;
	ucall = strlop(buf, ' ');
	if (!ucall) { free(buf); return; } // Not a control message.

// There may be at least one field after the node and user callsigns.
// Node leave (id_unlink) has no F1.

	f1 = strlop(ucall, ' ');

// If the frame came from an unknown node ignore it.
// If the frame came from us ignore it (loop breaking).

	node = node_find(ncall);
	if (!node || matchi(ncall, Node->calls)) { free(buf); return; }

	switch(ckt_from->buf[TYPE_O])
	{
// Data from user ucall at node ncall.

		case id_data :
			user = user_find(ucall);
			if (!user) break;
			text_tellu(user, f1, NULL, o_topic);

			for (ckt_to = circuit_hd; ckt_to; ckt_to = ckt_to->next)
				if ((ckt_to->flags & p_linked) &&
					   ckt_to->refcnt &&
					   !cn_find(ckt_to, node) &&
					   ct_find(ckt_to, user->topic)) nprintf(ckt_to->s, "%s\n", ckt_from->buf);
			break;

// User ucall at node ncall changed their Name/QTH info.

		case id_user :
			echo(ckt_from, node);  // Relay to other nodes.
			user = user_find(ucall);
			if (!user) break;
			f2 = strlop(f1, ' ');
			if (!f2) break;
			strnew(&user->name, f1);
			strnew(&user->qth,  f2);
			upduser(user);
			break;

// User ucall logged into node ncall.

		case id_join :
			echo(ckt_from, node);  // Relay to other nodes.
			f2 = strlop(f1, ' ');
			if (!f2) break;
			user = user_join(ckt_from, ucall, ncall, NULL);
			if (!user) break;
			ckt_from->refcnt++;
			text_tellu(user, rtjoin, NULL, o_all);
			strnew(&user->name, f1);
			strnew(&user->qth,  f2);
			upduser(user);
			break;

// User ucall logged out of node ncall.

		case id_leave :
			echo(ckt_from, node);  // Relay to other nodes.
			user = user_find(ucall);
			if (!user) break;
			f2 = strlop(f1, ' ');
			if (!f2) break;
			text_tellu(user, rtleave, NULL, o_all);
			ckt_from->refcnt--;
			cn_dec(ckt_from, node);
			strnew(&user->name, f1);
			strnew(&user->qth,  f2);
			upduser(user);
			user_leave(user);
			break;

// Node ncall lost its link to node ucall, alias f1.

		case id_unlink :
			echo(ckt_from, node);  // Relay to other nodes.
			ln = node_find(ucall);
			if (ln)	cn_dec(ckt_from, ln);
			break;

// Node ncall acquired a link to node ucall, alias f1.
// If we are not linked, is no problem, don't link.
// If we are linked, is a loop, do what?

		case id_link :
			echo(ckt_from, node);  // Relay to other nodes.
			ln = node_find(ucall);
			if (!ln && !matchi(ncall, Node->calls)) cn_inc(ckt_from, ucall, f1);
			break;

// User ucall at node ncall sent f2 to user f1.

		case id_send :
			user = user_find(ucall);
			if (!user) break;
			f2 = strlop(f1, ' ');
			if (!f2) break;
			su = user_find(f1);
			if (!su) break;

			if (su->circuit->flags & p_user)
				text_tellu(user, f2, f1, o_one);
			else
				echo(ckt_from, node);  // Relay to other nodes.
			break;

// User ucall at node ncall changed topic.

		case id_topic :
			echo(ckt_from, node);  //  Relay to other nodes.
			user = user_find(ucall);
			if (user) topic_chg(user, f1);
			break;

		default :  break;
	}

	free(buf);
}
Пример #21
0
void buckets_finalize_migration(client_t *client, hash_t hashmask, int level, conninfo_t *conninfo)
{
	bucket_t *bucket;
	
	assert(_mask > 0 && (hashmask >= 0 && hashmask <= _mask));
	assert(client);
	assert(level == 0 || level == 1);
	assert(conninfo);
	
	// ** some of these valumes should be checked at runtime
	bucket = _buckets[hashmask];
	assert(bucket);
	assert(bucket->hashmask == hashmask);
	assert(bucket->level < 0);
	assert(bucket->source_node == NULL);
	assert(bucket->backup_node == NULL);
	assert(data_in_transit() == 0);
	assert(bucket->transfer_event == NULL);
	assert(_bucket_transfer);

	assert(bucket->transfer_client == client);
	assert(client);
	assert(client->node);
	logger(LOG_DEBUG, "Removing transfer client ('%s') from bucket %#llx.", node_name(client->node), bucket->hashmask);

	bucket->transfer_client = NULL;
		
	// mark the bucket as ready for action.
	bucket->level = level;
	if (level == 0) {
		// we are receiving a primary bucket.  
		if (conninfo) {
			assert(bucket->backup_node == NULL);
			bucket->backup_node = node_find(conninfo);
			assert(bucket->backup_node);
			assert(bucket->backup_node->client);
		}
		else {
			assert(bucket->backup_node == NULL);
		}
		assert(bucket->source_node == NULL);
		
		// if level is -1 then indicates bucket is not here.  bucket is here.
		assert(bucket->level >= 0);	

		// indicates buckets is hosted here if level is not -1.
		bucket->primary_node = NULL;
		
		_primary_buckets ++;
		assert(_primary_buckets > 0);
	}
	else {
		// we are receiving a backup bucket.  
		assert(conninfo);
		
		logger(LOG_DEBUG, "Setting source_node [%d]", __LINE__);
		bucket->source_node = node_find(conninfo);
		assert(bucket->source_node);
		assert(bucket->source_node->client);

		// if level is -1 then indicates bucket is not here.  bucket is here.
		assert(bucket->level >= 0);	
		
		// setting this to NULL while level is not -1 indicates that the bucket is here.
		bucket->secondary_node = NULL;
		
		// we should be connected to this other node.
		assert(bucket->backup_node == NULL);
		
		_secondary_buckets ++;
		assert(_secondary_buckets > 0);
	}
}
Пример #22
0
Файл: set.c Проект: simon582/dm
/* ---------------------------------
 * brief  : check if pdata is in set
 * return : find 1, not find 0
 * --------------------------------- */
int set_in(Set *st, void *pdata) {
    if (node_find(st->rb, pdata) != NULL) return 1;
    return 0;
}
Пример #23
0
int trie_add(TRIE **head,char *str) {
    TRIE *t = *head;
    int index=0,len1;
    char *pstr;
    while(*str) {
        TRIE *l =node_find(t,str,&index);
        if(l) {	/*exist the same header string.OK divided it.*/
            len1 = strlen(l->str);
            if(index < len1) {	/*divied it*/

                /*find the end of list*/
                TRIE *tp = l->son,*temp,*q;

                /*new a sub node*/
                temp =(TRIE *)malloc(sizeof(TRIE));
                temp->isEmail = l->isEmail;
                q = temp;
                pstr = l->str;
                pstr += index;
                q->str = (char *)malloc(strlen(pstr)+1);
                strcpy(q->str,pstr);
                q->bro= q->son = NULL;

                if(tp) {
                    q->son = tp;
                }

                /*redirect the node*/
                l->son = temp;

                /*change l->cNode*/
                l->str[index] = '\0';
                l->isEmail = false;


                /*move t*/
                t = l->son;
                str += index;
            } else if(index == len1) { /*l->cNode is short*/
                str += index;
                if(!l->son) {
                    l->son = (TRIE *)malloc(sizeof(TRIE));
                    l->son->isEmail = false;
                    l->son->son = l->son->bro = NULL;
                    l->son->str = (char *)malloc(strlen(str)+1);
                    strcpy(l->son->str,str);
                    t = l->son;
                    break;
                }
                if(*str) {
                    t = l->son;
                } else {
                    t = l;
                }
            }
        } else {	/*new*/
            TRIE *p,*q=NULL;
            if(t) {
                if(!t->bro) {
                    t->bro = (TRIE *)malloc(sizeof(TRIE));
                    t->bro->son = t->bro->bro  = NULL;
                    t->bro->str = NULL;
                    q = t->bro ;
                } else {
                    q = p = t;
                    while(p) {
                        q = p;
                        p = p->bro;
                    }
                    q->bro = (TRIE *)malloc(sizeof(TRIE));
                    q = q->bro;
                    q->str = NULL;
                }
            } else {
                *head = (TRIE *)malloc(sizeof(TRIE));
                (*head)->str = NULL;
                (*head)->son = (*head)->bro = NULL;
                q = (*head);
            }
            if(q->str) {
                free(q->str);
                q->str = NULL;
            }
            q->str = (char *)malloc(strlen(str)+1);
            strcpy(q->str,str);
            t = q;
            break;
        }
    }
    t->isEmail = true;
    return 0;
}
Пример #24
0
Файл: main.c Проект: malind/bam
static int bam_setup(struct CONTEXT *context, const char *scriptfile, const char **targets, int num_targets)
{
	/* */	
	if(session.verbose)
		printf("%s: setup started\n", session.name);
	
	/* set filename */
	context->filename = scriptfile;
	
	/* set global timestamp to the script file */
	context->globaltimestamp = file_timestamp(scriptfile);

	/* */
	context->forced = option_force;
	
	/* fetch script directory */
	{
		char cwd[MAX_PATH_LENGTH];
		char path[MAX_PATH_LENGTH];

		if(!getcwd(cwd, sizeof(cwd)))
		{
			printf("%s: error: couldn't get current working directory\n", session.name);
			return -1;
		}
		
		if(path_directory(context->filename, path, sizeof(path)))
		{
			printf("%s: error: path too long '%s'\n", session.name, path);
			return -1;
		}
		
		if(path_join(cwd, -1, path, -1, context->script_directory, sizeof(context->script_directory)))
		{
			printf("%s: error: path too long when joining '%s' and '%s'\n", session.name, cwd, path);
			return -1;
		}
	}
	
	/* register all functions */
	event_begin(0, "lua setup", NULL);
	if(register_lua_globals(context->lua, context->script_directory, context->filename) != 0)
	{
		printf("%s: error: registering of lua functions failed\n", session.name);
		return -1;
	}
	event_end(0, "lua setup", NULL);

	/* load script */	
	if(session.verbose)
		printf("%s: reading script from '%s'\n", session.name, scriptfile);

	event_begin(0, "script load", NULL);
	/* push error function to stack and load the script */
	lua_getglobal(context->lua, "errorfunc");
	switch(luaL_loadfile(context->lua, scriptfile))
	{
		case 0: break;
		case LUA_ERRSYNTAX:
			lf_errorfunc(context->lua);
			return -1;
		case LUA_ERRMEM:
			printf("%s: memory allocation error\n", session.name);
			return -1;
		case LUA_ERRFILE:
			printf("%s: error opening '%s'\n", session.name, scriptfile);
			return -1;
		default:
			printf("%s: unknown error\n", session.name);
			return -1;
	}
	event_end(0, "script load", NULL);

	/* start the background stat thread */
	node_graph_start_statthread(context->graph);

	/* call the code chunk */
	event_begin(0, "script run", NULL);
	if(lua_pcall(context->lua, 0, LUA_MULTRET, -2) != 0)
	{
		node_graph_end_statthread(context->graph);
		printf("%s: script error (-t for more detail)\n", session.name);
		return -1;
	}
	event_end(0, "script run", NULL);

	/* stop the background stat thread */
	event_begin(0, "stat", NULL);
	node_graph_end_statthread(context->graph);
	event_end(0, "stat", NULL);
	
	/* run deferred functions */
	event_begin(0, "deferred cpp dependencies", NULL);
	if(run_deferred_functions(context, context->firstdeferred_cpp) != 0)
		return -1;
	event_end(0, "deferred cpp dependencies", NULL);
		
	event_begin(0, "deferred search dependencies", NULL);
	if(run_deferred_functions(context, context->firstdeferred_search) != 0)
		return -1;
	event_end(0, "deferred search dependencies", NULL);

	/* */	
	if(session.verbose)
		printf("%s: making build target\n", session.name);
	
	/* make build target */
	{
		struct NODE *node;
		int all_target = 0;
		int i;

		if(node_create(&context->target, context->graph, "_bam_buildtarget", NULL, TIMESTAMP_PSEUDO))
			return -1;

		if(num_targets)
		{
			/* search for all target */
			for(i = 0; i < num_targets; i++)
			{
				if(strcmp(targets[i], "all") == 0)
				{
					all_target = 1;
					break;
				}
			}
		}
		
		/* default too all if we have no targets or default target */
		if(num_targets == 0 && !context->defaulttarget)
			all_target = 1;
		
		if(all_target)
		{
			/* build the all target */
			for(node = context->graph->first; node; node = node->next)
			{
				if(node->firstparent == NULL && node != context->target)
				{
					if(!node_add_dependency (context->target, node))
						return -1;
				}
			}
		}
		else
		{
			if(num_targets)
			{
				for(i = 0; i < num_targets; i++)
				{
					struct NODE *node = node_find(context->graph, targets[i]);
					if(!node)
					{
						printf("%s: target '%s' not found\n", session.name, targets[i]);
						return -1;
					}
					
					if(option_dependent)
					{
						/* TODO: this should perhaps do a reverse walk up in the tree to
							find all dependent node with commandline */
						struct NODELINK *parent;
						for(parent = node->firstparent; parent; parent = parent->next)
						{
							if(!node_add_dependency (context->target, parent->node))
								return -1;
						}
								
					}
					else
					{
						if(!node_add_dependency (context->target, node))
							return -1;
					}
				}
			}
			else
			{
				if(!node_add_dependency (context->target, context->defaulttarget))
					return -1;
			}

		}
	}

	/* zero out the global timestamp if we don't want to use it */
	if(option_no_scripttimestamp)
		context->globaltimestamp = 0;

	/* */	
	if(session.verbose)
		printf("%s: setup done\n", session.name);
	
	/* return success */
	return 0;
}
Пример #25
0
bool node_contains(node_t **n, int value)
{
  return *node_find(n, value) != NULL; 
}