summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-06-21 08:19:47 +0200
committerDave Davenport <qball@gmpclient.org>2017-06-21 08:19:47 +0200
commit77a4d97262c3a1837d4b3752c2f222d7ea097703 (patch)
tree5310f88fd6155cd6ea5586663fdaa6532eed8183
parent9af191de26611ce5025e3363dafd0cdbf8ab38b9 (diff)
Add -dump-config option.
-rw-r--r--include/theme.h7
-rw-r--r--include/xrmoptions.h5
-rw-r--r--source/rofi.c7
-rw-r--r--source/theme.c8
-rw-r--r--source/xrmoptions.c69
5 files changed, 96 insertions, 0 deletions
diff --git a/include/theme.h b/include/theme.h
index c0182e64..28c8f225 100644
--- a/include/theme.h
+++ b/include/theme.h
@@ -240,6 +240,13 @@ ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *nam
void rofi_theme_print ( ThemeWidget *widget );
/**
+ * @param widget The widget handle.
+ *
+ * Print out the theme and config to the commandline.
+ */
+void rofi_dump_config ( ThemeWidget *widget );
+
+/**
* @param type The type of the property to create.
*
* Create a theme property of type.
diff --git a/include/xrmoptions.h b/include/xrmoptions.h
index 791121a3..2a01d72c 100644
--- a/include/xrmoptions.h
+++ b/include/xrmoptions.h
@@ -165,5 +165,10 @@ char ** config_parser_return_display_help ( unsigned int *length );
* @returns true when failed to set property.
*/
gboolean config_parse_set_property ( const Property *p, char **error );
+
+/**
+ * @brief Dump configuration in rasi format.
+ */
+void config_parse_dump_config ( void );
/* @}*/
#endif
diff --git a/source/rofi.c b/source/rofi.c
index 39013f09..fbce9631 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -267,6 +267,8 @@ static void print_main_application_options ( int is_term )
print_help_msg ( "-show", "[mode]", "Show the mode 'mode' and exit. The mode has to be enabled.", NULL, is_term );
print_help_msg ( "-no-lazy-grab", "", "Disable lazy grab that, when fail to grab keyboard, does not block but retry later.", NULL, is_term );
print_help_msg ( "-no-plugins", "", "Disable loading of external plugins.", NULL, is_term );
+ print_help_msg ( "-dump-config", "", "Dump the current configuration and theme in rasi format and exit.", NULL, is_term );
+ print_help_msg ( "-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term );
}
static void help ( G_GNUC_UNUSED int argc, char **argv )
{
@@ -895,6 +897,11 @@ int main ( int argc, char *argv[] )
cleanup ();
return EXIT_SUCCESS;
}
+ if ( find_arg ( "-dump-config" ) >= 0 ) {
+ rofi_dump_config ( rofi_theme );
+ cleanup ();
+ return EXIT_SUCCESS;
+ }
// Dump.
// catch help request
if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 || find_arg ( "--help" ) >= 0 ) {
diff --git a/source/theme.c b/source/theme.c
index b929a9ea..c09f9c52 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -290,6 +290,14 @@ void rofi_theme_print ( ThemeWidget *widget )
}
}
+void rofi_dump_config ( ThemeWidget *widget )
+{
+ config_parse_dump_config ( );
+ if ( widget != NULL ) {
+ rofi_theme_print_index ( widget );
+ }
+}
+
/**
* Main lex parser.
*/
diff --git a/source/xrmoptions.c b/source/xrmoptions.c
index 91d69c3a..03ded07c 100644
--- a/source/xrmoptions.c
+++ b/source/xrmoptions.c
@@ -513,6 +513,75 @@ void config_parse_xresource_dump ( void )
}
}
+static void config_parse_dump_config_option ( XrmOption *option )
+{
+ if ( option->type == xrm_Char ) {
+ printf ( "/*" );
+ }
+ printf ( "\t%s: ", option->name );
+ switch ( option->type )
+ {
+ case xrm_Number:
+ printf ( "%u", *( option->value.num ) );
+ break;
+ case xrm_SNumber:
+ printf ( "%i", *( option->value.snum ) );
+ break;
+ case xrm_String:
+ if ( ( *( option->value.str ) ) != NULL ) {
+ // TODO should this be escaped?
+ printf ( "\"%s\"", *( option->value.str ) );
+ }
+ break;
+ case xrm_Boolean:
+ printf ( "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" );
+ break;
+ case xrm_Char:
+ // TODO
+ if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) {
+ printf ( "'%c'", *( option->value.charc ) );
+ }
+ else {
+ printf ( "'\\x%02X'", *( option->value.charc ) );
+ }
+ printf ( " /* unsupported */" );
+ break;
+ default:
+ break;
+ }
+
+ printf ( ";" );
+ if ( option->type == xrm_Char ) {
+ printf ( "*/" );
+ }
+ printf ( "\n" );
+}
+
+void config_parse_dump_config ( void )
+{
+ printf ( "configuration {\n" );
+
+ unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions );
+ for ( unsigned int i = 0; i < entries; ++i ) {
+ // Skip duplicates.
+ if ( ( i + 1 ) < entries ) {
+ if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) {
+ continue;
+ }
+ }
+ if ( xrmOptions[i].source != CONFIG_DEFAULT ) {
+ config_parse_dump_config_option ( &( xrmOptions[i] ) );
+ }
+ }
+ for ( unsigned int i = 0; i < num_extra_options; i++ ) {
+ if ( extra_options[i].source != CONFIG_DEFAULT ) {
+ config_parse_dump_config_option ( &( extra_options[i] ) );
+ }
+ }
+
+ printf ( "}\n" );
+}
+
static void print_option_string ( XrmOption *xo, int is_term )
{
int l = strlen ( xo->name );