From 01935064d8e9467795e21ec57e3fee9f5f19876b Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Tue, 26 Jan 2021 17:27:32 +0100 Subject: [PATCH] Add `-rasi-validate` option. Issue: #1260 --- doc/rofi.1 | 6 ++++++ doc/rofi.1.markdown | 4 ++++ include/theme.h | 8 ++++++++ source/rofi.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/doc/rofi.1 b/doc/rofi.1 index a45c9367..f1bba192 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -215,6 +215,12 @@ Dump the current active theme, in rasi format, to stdout and exit. Dump the current active configuration, in Xresources format, to stdout. This does not validate all passed values (for example, colors). +.PP +\fB\fC\-rasi\-validate\fR \fIfilename\fP + +.PP +Try to parse the file and 0 when succesful. + .PP \fB\fC\-threads\fR \fInum\fP diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 3c287361..6e849fd1 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -128,6 +128,10 @@ Dump the current active theme, in rasi format, to stdout and exit. Dump the current active configuration, in Xresources format, to stdout. This does not validate all passed values (for example, colors). +`-rasi-validate` *filename* + +Try to parse the file and 0 when succesful. + `-threads` *num* Specify the number of threads **rofi** should use: diff --git a/include/theme.h b/include/theme.h index 28dd0982..f50f892e 100644 --- a/include/theme.h +++ b/include/theme.h @@ -387,4 +387,12 @@ void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child ); */ ThemeMediaType rofi_theme_parse_media_type ( const char *type ); RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance ); + +/** + * @param filename The file to validate. + * + * @returns the program exit code. + */ +int rofi_theme_rasi_validate ( const char *filename ); + #endif diff --git a/source/rofi.c b/source/rofi.c index 281435e1..6d066f54 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -796,6 +796,19 @@ int main ( int argc, char *argv[] ) return EXIT_SUCCESS; } + if ( find_arg ( "-rasi-validate" ) >= 0 ) { + char *str = NULL; + find_arg_str ( "-rasi-validate", &str ); + if ( str != NULL ) { + int retv = rofi_theme_rasi_validate ( str ); + cleanup (); + return retv; + } + fprintf ( stderr, "Usage: %s -rasi-validate my-theme.rasi", argv[0] ); + return EXIT_FAILURE; + } + + { const char *ro_pid = g_getenv ( "ROFI_OUTSIDE" ); if ( ro_pid != NULL ) { @@ -1158,3 +1171,21 @@ int main ( int argc, char *argv[] ) g_free ( windowid ); return return_code; } + + +/** List of error messages.*/ +extern GList *list_of_error_msgs; +int rofi_theme_rasi_validate ( const char *filename ) +{ + rofi_theme_parse_file ( filename ); + if ( list_of_error_msgs == NULL ) { + return EXIT_SUCCESS; + } + + for ( GList *iter = g_list_first ( list_of_error_msgs ); + iter != NULL; iter = g_list_next ( iter ) ) { + fputs ( ((GString*)iter->data)->str, stderr ); + } + + return EXIT_FAILURE; +}