summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2021-01-26 17:27:32 +0100
committerDave Davenport <qball@gmpclient.org>2021-01-26 17:27:32 +0100
commit01935064d8e9467795e21ec57e3fee9f5f19876b (patch)
tree715a170848827ec7ae46f4a997c7654bed7ce7e9
parent8999d94850d4276f0220074f75c7e13aa8725597 (diff)
Add `-rasi-validate` option.
Issue: #1260
-rw-r--r--doc/rofi.16
-rw-r--r--doc/rofi.1.markdown4
-rw-r--r--include/theme.h8
-rw-r--r--source/rofi.c31
4 files changed, 49 insertions, 0 deletions
diff --git a/doc/rofi.1 b/doc/rofi.1
index a45c9367..f1bba192 100644
--- a/doc/rofi.1
+++ b/doc/rofi.1
@@ -216,6 +216,12 @@ 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
.PP
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;
+}