コード例 #1
0
ファイル: anjuta-token-list.c プロジェクト: GNOME/anjuta
AnjutaToken *
anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *item)
{
	AnjutaToken *token;

	if (list == NULL) list = anjuta_token_list (sibling);

	for (token = anjuta_token_first_item (list); token != NULL;)
	{
		AnjutaToken *next;

		next = anjuta_token_next_item (token);

		switch (anjuta_token_get_type (token))
		{
		case ANJUTA_TOKEN_LAST:
			anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
			anjuta_token_insert_before (token, item);
			return item;
		case ANJUTA_TOKEN_START:
			if ((sibling == NULL) || (token == sibling))
			{
				if (next != NULL) anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
				anjuta_token_insert_after (token, item);
				return item;
			}
			break;
		case ANJUTA_TOKEN_NEXT:
			if (token == sibling)
			{
				token = anjuta_token_insert_after (token, item);
				anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
				return item;
			}
			break;
		default:
			if (token == sibling)
			{
				token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
				anjuta_token_insert_after (token, item);
				return item;
			}
			break;
		}

		if (next == NULL)
		{
			token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
			anjuta_token_insert_after (token, item);
			return item;
		}
		token = next;
	}

	anjuta_token_prepend_items (list, item);

	return item;
}
コード例 #2
0
ファイル: anjuta-token-stream.c プロジェクト: rosedu/anjuta
/**
 * anjuta_token_stream_push:
 * @parent: a parent #AnjutaTokenStream object or NULL.
 * @root: a token or NULL
 * @content: a token list.
 *
 * Create a new stream from a list of tokens. If a parent stream is passed,
 * the new stream keep a link on it, so we can return it when the new stream
 * will be destroyed.
 *
 * Return value: The newly created stream.
 */
AnjutaTokenStream *
anjuta_token_stream_push (AnjutaTokenStream *parent, AnjutaToken *root, AnjutaToken *content, GFile *file)
{
	AnjutaTokenStream *child;

	child = g_new (AnjutaTokenStream, 1);
	child->first = content;
	child->pos = 0;
	child->begin = 0;
	child->parent = parent;

	child->next = anjuta_token_next (content);
	child->start = child->next;
	child->last = anjuta_token_last (content);
	if (child->last == content) child->last = NULL;

	child->root = root == NULL ? anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL) : root;
	if (file == NULL)
	{
		child->current_directory = parent == NULL ? NULL : (parent->current_directory == NULL ? NULL : g_object_ref (parent->current_directory));
		child->current_file = NULL;
	}
	else
	{
		child->current_directory = g_file_get_parent (file);
		child->current_file = g_object_ref (file);
	}

	return child;
}
コード例 #3
0
ファイル: amp-group.c プロジェクト: GNOME/anjuta
AnjutaTokenFile*
amp_group_node_set_makefile (AmpGroupNode *group, GFile *makefile, AmpProject *project)
{
	if (group->makefile != NULL) g_object_unref (group->makefile);
	if (group->tfile != NULL) anjuta_token_file_free (group->tfile);
	if (makefile != NULL)
	{
		AnjutaToken *token;
		AmpAmScanner *scanner;
		AnjutaProjectNode *source;

		group->makefile = g_object_ref (makefile);
		group->tfile = anjuta_token_file_new (makefile);
		source = amp_source_node_new (makefile, ANJUTA_PROJECT_PROJECT | ANJUTA_PROJECT_FRAME | ANJUTA_PROJECT_READ_ONLY);
		anjuta_project_node_append (ANJUTA_PROJECT_NODE (group), source);

		token = anjuta_token_file_load (group->tfile, NULL);
		amp_project_add_file (project, makefile, group->tfile);

		amp_group_node_update_preset_variable (group);

		scanner = amp_am_scanner_new (project, group);
		group->make_token = amp_am_scanner_parse_token (scanner, anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL), token, makefile, NULL);
		amp_am_scanner_free (scanner);

		group->monitor = g_file_monitor_file (makefile,
						      									G_FILE_MONITOR_NONE,
						       									NULL,
						       									NULL);
		if (group->monitor != NULL)
		{
			g_signal_connect (G_OBJECT (group->monitor),
					  "changed",
					  G_CALLBACK (on_group_monitor_changed),
					  group);
		}
	}
	else
	{
		group->makefile = NULL;
		group->tfile = NULL;
		group->make_token = NULL;
		if (group->monitor) g_object_unref (group->monitor);
		group->monitor = NULL;
	}

	return group->tfile;
}
コード例 #4
0
ファイル: anjuta-token-stream.c プロジェクト: tuxdna/anjuta
/**
 * anjuta_token_stream_push:
 * @parent: a parent #AnjutaTokenStream object or NULL.
 * @root: a token or NULL
 * @content: a token list.
 *
 * Create a new stream from a list of tokens. If a parent stream is passed,
 * the new stream keep a link on it, so we can return it when the new stream
 * will be destroyed.
 *
 * Return value: The newly created stream.
 */
AnjutaTokenStream *
anjuta_token_stream_push (AnjutaTokenStream *parent, AnjutaToken *root, AnjutaToken *content, GFile *file)
{
	AnjutaTokenStream *child;
	AnjutaTokenStream *stream;

	/* Check if content is not already parsed to avoid endless parsing loop */
	for (stream = parent; stream != NULL; stream = stream->parent)
	{
		if (stream->content == content) return NULL;
	}

	/* Create new stream */
	child = g_new (AnjutaTokenStream, 1);
	child->first = content;
	child->pos = 0;
	child->begin = 0;
	child->parent = parent;
	child->content = content;
	child->token = content;
	child->start = child->token;
	child->last = content == NULL ? NULL : anjuta_token_last (content);

	child->root = root == NULL ? anjuta_token_new_static (ANJUTA_TOKEN_FILE, NULL) : root;
	if (file == NULL)
	{
		child->current_directory = parent == NULL ? NULL : (parent->current_directory == NULL ? NULL : g_object_ref (parent->current_directory));
		child->current_file = NULL;
	}
	else
	{
		child->current_directory = g_file_get_parent (file);
		child->current_file = g_object_ref (file);
	}

	return child;
}
コード例 #5
0
ファイル: anjuta-token-stream.c プロジェクト: tuxdna/anjuta
/**
 * anjuta_token_stream_tokenize:
 * @stream: a #AnjutaTokenStream object.
 * @type: a token type.
 * @length: the token length in character.
 *
 * Create a token of type from the last length characters previously read and
 * append it in the output stream. The characters are not copied in the output
 * stream, the new token uses the same characters.
 *
 * Return value: The created token.
 */
AnjutaToken*
anjuta_token_stream_tokenize (AnjutaTokenStream *stream, gint type, gsize length)
{
    AnjutaToken *frag;
    AnjutaToken *end;

    frag = anjuta_token_new_static (type, NULL);

    for (end = stream->start; end != NULL;)
    {
        if ((anjuta_token_get_type (end) < ANJUTA_TOKEN_PARSED) || (anjuta_token_get_length (end) == 0))
        {
            gint toklen = anjuta_token_get_length (end);
            AnjutaToken *copy = anjuta_token_cut (end, stream->begin, length);

            if (toklen >= (length + stream->begin))
            {

                if (end == stream->start)
                {
                    /* Get whole token */
                    anjuta_token_free (frag);
                    anjuta_token_set_type (copy, type);
                    frag = copy;
                }
                else
                {
                    /* Get several token */
                    anjuta_token_insert_after (frag, copy);
                    anjuta_token_merge (frag, copy);
                }

                if (toklen == (length + stream->begin))
                {
                    stream->start = anjuta_token_next (end);
                    stream->begin = 0;
                }
                else
                {
                    stream->start = end;
                    stream->begin += length;
                }
                break;
            }
            else
            {
                anjuta_token_insert_after (frag, copy);
                anjuta_token_merge (frag, copy);
                length -= toklen - stream->begin;
                end = anjuta_token_next (end);
                stream->begin = 0;
            }
        }
        else
        {
            end = anjuta_token_next (end);
            stream->begin = 0;
        }
    }

    anjuta_token_stream_append_token (stream, frag);

    return frag;
}
コード例 #6
0
ファイル: amp-group.c プロジェクト: GNOME/anjuta
static void
amp_group_node_update_preset_variable (AmpGroupNode *group)
{
	gchar *path;
	AnjutaToken *value;
	AmpVariable *var;
	GFile *root;
	GFile *file;
	AnjutaProjectNode *node;

	if (group->preset_token != NULL) anjuta_token_free (group->preset_token);
	group->preset_token = anjuta_token_new_static (ANJUTA_TOKEN_FILE,  NULL);

	/* Get project root */
	for (node = ANJUTA_PROJECT_NODE (group); anjuta_project_node_parent (node) != NULL; node = anjuta_project_node_parent (node));
	root = anjuta_project_node_get_file (node);

	/* Set source directory variables */
	file = anjuta_project_node_get_file (group);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, ".",
	                                  NULL);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);

	path = g_file_get_path (file);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, path,
	                                  NULL);
	g_free (path);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("abs_srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("abs_builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);

	path = get_relative_path (file, root);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, path,
	                                  NULL);
	g_free (path);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("top_srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("top_builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);

	path = g_file_get_path (root);
	value = anjuta_token_insert_token_list (FALSE, NULL,
	                                  ANJUTA_TOKEN_LIST, NULL,
	                                  ANJUTA_TOKEN_ARGUMENT, NULL,
	                                  ANJUTA_TOKEN_CONTENT, path,
	                                  NULL);
	g_free (path);
	anjuta_token_append_child (group->preset_token, value);
	var = amp_variable_new ("abs_top_srcdir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
	var = amp_variable_new ("abs_top_builddir", 0, value);
	g_hash_table_insert (group->variables, var->name, var);
}
コード例 #7
0
ファイル: anjuta-token-list.c プロジェクト: GNOME/anjuta
AnjutaToken *
anjuta_token_replace_nth_word (AnjutaToken *list, guint n, AnjutaToken *item)
{
	AnjutaToken *token;
	gboolean no_item = TRUE;

	token = anjuta_token_first_item (list);
	if (token == NULL)
	{
		token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
		anjuta_token_merge (list, token);
	}

	for (n++;;)
	{
		AnjutaToken *next;

		switch (anjuta_token_get_type (token))
		{
		case ANJUTA_TOKEN_LAST:
			if (no_item)
			{
				n--;
				if (n == 0)
				{
					token = anjuta_token_insert_before (token, item);
					return token;
				}
			}
			token = anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
			no_item = TRUE;
			break;
		case ANJUTA_TOKEN_NEXT:
			if (no_item)
			{
				n--;
				if (n == 0)
				{
					token = anjuta_token_insert_before (token, item);
					return token;
				}
			}
			no_item = TRUE;
			break;
		case ANJUTA_TOKEN_ITEM:
			n--;
			if (n == 0)
			{
				anjuta_token_set_flags (token, ANJUTA_TOKEN_REMOVED);
				token = anjuta_token_insert_before (token, item);
				return token;
			}
			no_item = FALSE;
			break;
		default:
			break;
		}

		next = anjuta_token_next_item (token);
		if (next == NULL)
		{
			token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
			anjuta_token_merge (list, token);
		}
		else
		{
			token = next;
		}
	}
}
コード例 #8
0
ファイル: ac-writer.c プロジェクト: kyoushuu/anjuta
gboolean
amp_project_update_ac_property (AmpProject *project, AnjutaProjectProperty *property)
{
	AnjutaToken *token;
	AnjutaToken *arg;
	AnjutaToken *args;
	AmpProperty *prop;
	AmpPropertyInfo *info;

	if (g_strcmp0 (((AmpPropertyInfo *)property->info)->value, property->value) == 0)
	{
		/* Remove property */
		info = (AmpPropertyInfo *)property->info;
		prop = (AmpProperty *)property;

		if (info->position == -1)
		{
			token = prop->token;

			anjuta_token_remove_list (anjuta_token_list (token));
		}

		anjuta_project_node_remove_property (ANJUTA_PROJECT_NODE (project), property);
	}
	else
	{
		info = (AmpPropertyInfo *)property->info;
		prop = find_similar_property (ANJUTA_PROJECT_NODE (project), (AmpProperty *)property);
		args = prop != NULL ? prop->token : NULL;

		prop = (AmpProperty *)property;

		if (args == NULL)
		{
			AnjutaToken *group;
			AnjutaToken *configure;
			const char *suffix;

			configure = amp_project_get_configure_token (project);
			token = anjuta_token_find_position (configure, TRUE, info->token_type, NULL);
			if (token == NULL)
			{
				token = skip_comment (configure);
				if (token == NULL)
				{
					token = anjuta_token_append_child (configure, anjuta_token_new_string (COMMENT | ANJUTA_TOKEN_ADDED, "#"));
					token = anjuta_token_insert_after (token, anjuta_token_new_string (SPACE | ANJUTA_TOKEN_ADDED, " Created by Anjuta project manager"));
					token = anjuta_token_insert_after (token, anjuta_token_new_string (END_OF_LINE | ANJUTA_TOKEN_ADDED, "\n"));
					token = anjuta_token_insert_after (token, anjuta_token_new_string (END_OF_LINE | ANJUTA_TOKEN_ADDED, "\n"));
				}
			}

			suffix = info->suffix;
			token = anjuta_token_insert_after (token, anjuta_token_new_string (AC_TOKEN_AC_INIT | ANJUTA_TOKEN_ADDED, suffix));
			if (suffix[strlen(suffix) - 1] == '(')
			{
				group = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LIST | ANJUTA_TOKEN_ADDED, NULL));
				args = group;
				token = anjuta_token_insert_after (group, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
				anjuta_token_merge (group, token);
			}
			anjuta_token_insert_after (token, anjuta_token_new_string (END_OF_LINE | ANJUTA_TOKEN_ADDED, "\n"));
		}
		if (args != NULL)
		{
			guint pos;

			token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, prop->base.value);
			arg = anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_ITEM | ANJUTA_TOKEN_ADDED, NULL));
			anjuta_token_merge (arg, token);

			pos = info->position;
			if (pos == -1) pos = 0;
			anjuta_token_replace_nth_word (args, pos, arg);
			anjuta_token_style_format (project->arg_list, args);
		}
	}

	amp_project_update_configure (project, token);

	return TRUE;
}