Skip to content

Commit

Permalink
Add group in configure.Ac
Browse files Browse the repository at this point in the history
  • Loading branch information
sgranjoux committed Nov 24, 2009
1 parent 09bef3e commit 6ff7276
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 29 deletions.
57 changes: 44 additions & 13 deletions libanjuta/anjuta-token-style.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,25 +463,56 @@ anjuta_token_list_replace_nth (AnjutaToken *list, guint n, AnjutaToken *item)
}

AnjutaToken *
anjuta_token_list_insert_after (AnjutaToken *sibling, AnjutaToken *baby)
anjuta_token_list_insert_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *item)
{
AnjutaToken *token = sibling;
AnjutaToken *separator;
AnjutaToken *token;

if (anjuta_token_get_type (token) == ANJUTA_TOKEN_LAST)
token = anjuta_token_list_first (list);
if (token == NULL)
{
token = anjuta_token_previous_sibling (token);
token = anjuta_token_insert_child (list, anjuta_token_new_static (ANJUTA_TOKEN_START | ANJUTA_TOKEN_ADDED, NULL));
token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
}
else if ((anjuta_token_get_type (token) != ANJUTA_TOKEN_NEXT) && (anjuta_token_next_sibling (token) != NULL))

for (;;)
{
token = anjuta_token_next_sibling (token);
}

separator = anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL);
token = anjuta_token_insert_after (token, separator);
token = anjuta_token_insert_after (token, baby);
AnjutaToken *next;

return 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 token;
case ANJUTA_TOKEN_START:
case ANJUTA_TOKEN_NEXT:
if (token == sibling)
{
anjuta_token_insert_after (token, item);
anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
return token;
}
break;
default:
if (token == sibling)
{
anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_NEXT | ANJUTA_TOKEN_ADDED, NULL));
anjuta_token_insert_after (token, item);
return token;
}
break;
}

next = anjuta_token_next (token);
if (next == NULL)
{
token = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
}
else
{
token = next;
}
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion libanjuta/anjuta-token-style.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AnjutaToken *anjuta_token_list_last (AnjutaToken *list);
AnjutaToken *anjuta_token_list_next (AnjutaToken *sibling);
AnjutaToken *anjuta_token_list_replace (AnjutaToken *sibling, AnjutaToken *baby);
AnjutaToken *anjuta_token_list_replace_nth (AnjutaToken *list, guint n, AnjutaToken *baby);
AnjutaToken *anjuta_token_list_insert_after (AnjutaToken *sibling, AnjutaToken *baby);
AnjutaToken *anjuta_token_list_insert_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *baby);
void anjuta_token_list_delete (AnjutaToken *sibling);

G_END_DECLS
Expand Down
115 changes: 110 additions & 5 deletions libanjuta/anjuta-token.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,6 @@ anjuta_token_merge_children (AnjutaToken *first, AnjutaToken *end)
AnjutaToken *
anjuta_token_merge_previous (AnjutaToken *first, AnjutaToken *end)
{
AnjutaToken *child;
AnjutaToken *tok;

if ((end == NULL) || (first == end)) return first;

anjuta_token_unlink (first);
Expand Down Expand Up @@ -1172,8 +1169,6 @@ anjuta_token_check_child (AnjutaToken *token, AnjutaToken *parent)
gboolean
anjuta_token_check (AnjutaToken *token)
{
AnjutaToken *next = token;

if ((token->children != NULL) && (token->last != NULL))
{
anjuta_token_show (token, 0);
Expand Down Expand Up @@ -1241,6 +1236,116 @@ AnjutaToken *anjuta_token_group_children (AnjutaToken *token)
return token;
}

/* Additional public functions
*---------------------------------------------------------------------------*/

AnjutaToken *
anjuta_token_find_type (AnjutaToken *list, gint flags, AnjutaTokenType* types)
{
AnjutaToken *tok;
AnjutaToken *last = NULL;

for (tok = list; tok != NULL; tok = anjuta_token_next (tok))
{
AnjutaTokenType *type;
for (type = types; *type != 0; type++)
{
if (anjuta_token_get_type (tok) == *type)
{
last = tok;
if (flags & ANJUTA_TOKEN_SEARCH_NOT) break;
if (!(flags & ANJUTA_TOKEN_SEARCH_LAST)) break;
}
}
if ((flags & ANJUTA_TOKEN_SEARCH_NOT) && (*type == 0)) break;
}

return last;
}

AnjutaToken *
anjuta_token_skip_comment (AnjutaToken *token)
{
if (token == NULL) return NULL;

for (;;)
{
for (;;)
{
AnjutaToken *next = anjuta_token_next (token);

if (next == NULL) return token;

switch (anjuta_token_get_type (token))
{
case ANJUTA_TOKEN_FILE:
case ANJUTA_TOKEN_SPACE:
token = next;
continue;
case ANJUTA_TOKEN_COMMENT:
token = next;
break;
default:
return token;
}
break;
}

for (;;)
{
AnjutaToken *next = anjuta_token_next (token);

if (next == NULL) return token;
token = next;
if (anjuta_token_get_type (token) == ANJUTA_TOKEN_EOL) break;
}
}
}

AnjutaToken *
anjuta_token_insert_token_before (AnjutaToken *pos,...)
{
AnjutaToken *first = NULL;
GList *group = NULL;
va_list args;
gint type;

va_start (args, pos);

for (type = va_arg (args, gint); type != 0; type = va_arg (args, gint))
{
gchar *string = va_arg (args, gchar *);
AnjutaToken *token;

token = anjuta_token_insert_before (pos, anjuta_token_new_string (type | ANJUTA_TOKEN_ADDED, string));
if (first == NULL) first = token;

if (group != NULL)
{
anjuta_token_merge ((AnjutaToken *)group->data, token);
}

if (string == NULL)
{
switch (type)
{
case ANJUTA_TOKEN_LIST:
break;
default:
group = g_list_delete_link (group, group);
break;
}
group = g_list_prepend (group, token);
}
}
g_list_free (group);

va_end (args);

return first;
}


/* Constructor & Destructor
*---------------------------------------------------------------------------*/

Expand Down
8 changes: 7 additions & 1 deletion libanjuta/anjuta-token.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ enum AnjutaTokenSearchFlag
ANJUTA_SEARCH_OVER = 0,
ANJUTA_SEARCH_INTO = 1 << 0,
ANJUTA_SEARCH_ALL = 1 << 1,
ANJUTA_SEARCH_BACKWARD = 1 << 2
ANJUTA_SEARCH_BACKWARD = 1 << 2,
ANJUTA_TOKEN_SEARCH_LAST = 1 << 3,
ANJUTA_TOKEN_SEARCH_NOT = 1 << 4,
};

typedef gboolean (*AnjutaTokenTraverseFunc) (AnjutaToken* token, gpointer data);
Expand Down Expand Up @@ -192,6 +194,10 @@ const gchar *anjuta_token_get_string (AnjutaToken *token);
void anjuta_token_set_string (AnjutaToken *token, const char *value, guint length);
guint anjuta_token_get_length (AnjutaToken *token);

AnjutaToken *anjuta_token_find_type (AnjutaToken *list, gint flags, AnjutaTokenType* types);
AnjutaToken *anjuta_token_skip_comment (AnjutaToken *list);
AnjutaToken *anjuta_token_insert_token_before (AnjutaToken *list,...);

G_END_DECLS

#endif
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ projectparser_SOURCES = \
ac-scanner.h \
ac-writer.h \
ac-writer.c \
am-writer.h \
am-writer.c \
am-dialogs.c \
am-dialogs.h \
mk-project.c \
Expand Down
2 changes: 1 addition & 1 deletion src/ac-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
%token LOWER '<'
%token GREATER '>'

%token COMMENT
%token COMMENT 256
%token NAME
%token VARIABLE
%token MACRO
Expand Down
22 changes: 15 additions & 7 deletions src/am-project.c
Original file line number Diff line number Diff line change
Expand Up @@ -1772,27 +1772,35 @@ amp_project_add_sibling_group (AmpProject *project,
g_object_add_toggle_ref (G_OBJECT (tfile), remove_config_file, project);

/* Add in configure */
token_list= amp_group_get_token (parent, AM_GROUP_TOKEN_CONFIGURE);
token_list = NULL;
if (sibling) amp_group_get_token (sibling, AM_GROUP_TOKEN_CONFIGURE);
if (token_list == NULL) token_list= amp_group_get_token (parent, AM_GROUP_TOKEN_CONFIGURE);
if (token_list == NULL)
{
token_list = amp_project_write_config_list (project);
token_list = anjuta_token_next (token_list);
}
if (token_list != NULL)
{
gchar *relative_make;
gchar *ext;
AnjutaTokenStyle *style;
//AnjutaTokenStyle *style;

prev_token = (AnjutaToken *)token_list->data;
//prev_token = (AnjutaToken *)token_list->data;

relative_make = g_file_get_relative_path (project->root_file, makefile);
ext = relative_make + strlen (relative_make) - 3;
if (strcmp (ext, ".am") == 0)
{
*ext = '\0';
}
token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, relative_make);
//token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, relative_make);
amp_project_write_config_file_before (project, token_list, sibling, relative_make);
g_free (relative_make);

style = anjuta_token_style_new (NULL," ","\n",NULL,0);
add_list_item (prev_token, token, style);
anjuta_token_style_free (style);
//style = anjuta_token_style_new (NULL," ","\n",NULL,0);
//add_list_item (prev_token, token, style);
//anjuta_token_style_free (style);
}

/* Add in Makefile.am */
Expand Down
Loading

0 comments on commit 6ff7276

Please sign in to comment.