Commit 08c3ed08 authored by pierre's avatar pierre Committed by Pierre Wieser

Split Exec key to get Path and Parameters data

parent b177031b
2010-08-05 Pierre Wieser <pwieser@trychlos.org>
* src/api/na-core-utils.h:
* src/core/na-core-utils.c
(na_core_utils_str_get_first_word): Removed function.
(na_core_utils_str_split_first_word): New function.
* src/io-desktop/nadp-reader.c
(nadp_reader_ifactory_provider_read_done):
Split the Exec content to get Path and Parameters data.
* src/core/na-object-profile-factory.c:
Review the description of the NAFO_DATA_PARAMETERS data.
......
......@@ -49,9 +49,9 @@ gboolean na_core_utils_boolean_from_string( const gchar *string );
*/
gchar *na_core_utils_str_add_prefix( const gchar *prefix, const gchar *str );
int na_core_utils_str_collate( const gchar *str1, const gchar *str2 );
gchar *na_core_utils_str_get_first_word( const gchar *string );
gchar *na_core_utils_str_remove_char( const gchar *string, const gchar *to_remove );
gchar *na_core_utils_str_remove_suffix( const gchar *string, const gchar *suffix );
void na_core_utils_str_split_first_word( const gchar *string, gchar **first, gchar **other );
/* some functions to get or set GSList list of strings
*/
......
......@@ -111,36 +111,6 @@ na_core_utils_str_collate( const gchar *str1, const gchar *str2 )
return( res );
}
/**
* na_core_utils_str_get_first_word:
* @string: a space-separated string.
*
* Returns: the first word of @string, as a newly allocated string which
* should be g_free() by the caller.
*/
gchar *
na_core_utils_str_get_first_word( const gchar *string )
{
gchar **splitted, **iter;
gchar *word, *tmp;
splitted = g_strsplit( string, " ", 0 );
iter = splitted;
word = NULL;
while( *iter ){
tmp = g_strstrip( *iter );
if( g_utf8_strlen( tmp, -1 )){
word = g_strdup( tmp );
break;
}
iter++;
}
g_strfreev( splitted );
return( word );
}
/**
* na_core_utils_str_remove_char:
* @string: source string.
......@@ -209,6 +179,33 @@ na_core_utils_str_remove_suffix( const gchar *string, const gchar *suffix )
return( removed );
}
/**
* na_core_utils_str_split_first_word:
* @string: a space-separated string.
* @first: a pointer to a gchar *.
* @other: a pointer to a gchar *.
*
* Split the @string string into two components:
* - the first word which is allocated in @first,
* - the rest of the string which is allocated in @other.
*
* The two allocated strings should be g_free() by the caller.
*/
void
na_core_utils_str_split_first_word( const gchar *string, gchar **first, gchar **other )
{
gchar **splitted, **iter;
splitted = g_strsplit( string, " ", 2 );
iter = splitted;
*first = g_strdup( *iter );
iter++;
*other = g_strdup( *iter );
g_strfreev( splitted );
}
void
na_core_utils_slist_add_message( GSList **messages, const gchar *format, ... )
{
......
......@@ -76,6 +76,7 @@ static void read_start_profile_attach_profile( const NAIFactoryProv
static gboolean read_done_item_is_writable( const NAIFactoryProvider *provider, NAObjectItem *item, NadpReaderData *reader_data, GSList **messages );
static void read_done_action_read_profiles( const NAIFactoryProvider *provider, NAObjectAction *action, NadpReaderData *data, GSList **messages );
static void read_done_action_load_profile( const NAIFactoryProvider *provider, NadpReaderData *reader_data, const gchar *profile_id, GSList **messages );
static void read_done_profile_split_exec( const NAIFactoryProvider *provider, NAObjectProfile *profile, NadpReaderData *reader_data, GSList **messages );
/*
* Returns an unordered list of NAIFactoryObject-derived objects
......@@ -607,6 +608,10 @@ nadp_reader_ifactory_provider_read_done( const NAIFactoryProvider *reader, void
read_done_action_read_profiles( reader, NA_OBJECT_ACTION( serializable ), ( NadpReaderData * ) reader_data, messages );
}
if( NA_IS_OBJECT_PROFILE( serializable )){
read_done_profile_split_exec( reader, NA_OBJECT_PROFILE( serializable ), ( NadpReaderData * ) reader_data, messages );
}
g_debug( "%s: quitting for %s at %p", thisfn, G_OBJECT_TYPE_NAME( serializable ), ( void * ) serializable );
}
}
......@@ -669,3 +674,19 @@ read_done_action_load_profile( const NAIFactoryProvider *provider, NadpReaderDat
NA_IFACTORY_OBJECT( profile ),
messages );
}
static void
read_done_profile_split_exec( const NAIFactoryProvider *provider, NAObjectProfile *profile, NadpReaderData *reader_data, GSList **messages )
{
gchar *exec;
gchar *path, *parameters;
exec = na_object_get_path( profile );
na_core_utils_str_split_first_word( exec, &path, &parameters );
na_object_set_path( profile, path );
na_object_set_parameters( profile, parameters );
g_free( parameters );
g_free( path );
g_free( exec );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment