summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-06-14 16:19:17 +0200
committerDave Davenport <qball@gmpclient.org>2017-06-14 16:19:17 +0200
commit22aacb8f94f4b6837dc192b98d243da4c2ae3f34 (patch)
tree7793d7e3d260af2839c53f0bae54bdd41aa6db3e
parentc851134411ac2a2ae75f74f21cde2f3db8e97441 (diff)
Add extra check for rofi_theme_parse_prepare_file
-rw-r--r--include/theme.h10
-rw-r--r--lexer/theme-lexer.l20
-rw-r--r--source/theme.c21
-rw-r--r--test/theme-parser-test.c32
4 files changed, 63 insertions, 20 deletions
diff --git a/include/theme.h b/include/theme.h
index b956af0e..c0182e64 100644
--- a/include/theme.h
+++ b/include/theme.h
@@ -484,4 +484,14 @@ void rofi_theme_convert_old ( void );
* @returns path to theme or copy of filename if not found.
*/
char *helper_get_theme_path ( const char *file );
+
+/**
+ * @param file File name to prepare.
+ * @param parent_file Filename of parent file.
+ *
+ * Tries to find full path relative to parent file.
+ *
+ * @returns full path to file.
+ */
+char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file );
#endif
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index 3831d26e..19790d93 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -34,7 +34,6 @@
%{
#include <stdio.h>
#include <glib.h>
-#include <gio/gio.h>
#include <helper.h>
#include <math.h>
#include <strings.h>
@@ -84,7 +83,6 @@ GQueue *queue = NULL;
ParseObject *current = NULL;
-static char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file );
static double rofi_theme_parse_convert_hex ( char high, char low)
@@ -562,24 +560,6 @@ if ( queue == NULL ){
%%
-static char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file )
-{
- char *filename = rofi_expand_path ( file );
- // If no absolute path specified, expand it.
- if ( parent_file != NULL && ! g_path_is_absolute ( filename ) ) {
- char *basedir = g_path_get_dirname ( parent_file );
- char *path = g_build_filename ( basedir, filename, NULL );
- g_free ( filename);
- filename = path;
- g_free ( basedir );
- }
- GFile *gf = g_file_new_for_path ( filename );
- g_free(filename);
- filename = g_file_get_path ( gf );
- g_object_unref ( gf );
-
- return filename;
-}
gboolean rofi_theme_parse_file ( const char *file )
{
char *file2 = helper_get_theme_path ( file );
diff --git a/source/theme.c b/source/theme.c
index 77d4443e..cdfca812 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -32,6 +32,8 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+// GFile stuff.
+#include <gio/gio.h>
#include "theme.h"
#include "theme-parser.h"
#include "helper.h"
@@ -779,3 +781,22 @@ void rofi_theme_convert_old ( void )
}
}
#endif // THEME_CONVERTER
+
+char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file )
+{
+ char *filename = rofi_expand_path ( file );
+ // If no absolute path specified, expand it.
+ if ( parent_file != NULL && ! g_path_is_absolute ( filename ) ) {
+ char *basedir = g_path_get_dirname ( parent_file );
+ char *path = g_build_filename ( basedir, filename, NULL );
+ g_free ( filename);
+ filename = path;
+ g_free ( basedir );
+ }
+ GFile *gf = g_file_new_for_path ( filename );
+ g_free(filename);
+ filename = g_file_get_path ( gf );
+ g_object_unref ( gf );
+
+ return filename;
+}
diff --git a/test/theme-parser-test.c b/test/theme-parser-test.c
index 24561728..77148ab6 100644
--- a/test/theme-parser-test.c
+++ b/test/theme-parser-test.c
@@ -177,6 +177,9 @@ START_TEST ( test_core_comments )
ck_assert_ptr_null ( rofi_theme->parent );
ck_assert_str_eq ( rofi_theme->name, "Root" );
+ // Test comment on last lines
+ rofi_theme_parse_string ( "// c++ style" );
+ rofi_theme_parse_string ( "/* c style" );
}
END_TEST
START_TEST ( test_core_newline )
@@ -1191,6 +1194,30 @@ START_TEST ( test_import_error )
}
END_TEST
+START_TEST ( test_prepare_path )
+{
+ char *current_dir = g_get_current_dir ();
+ ck_assert_ptr_nonnull ( current_dir );
+ char *f = rofi_theme_parse_prepare_file ( "../", NULL );
+ ck_assert_ptr_nonnull ( f );
+ ck_assert_int_eq ( *f, '/');
+ ck_assert_str_ne ( f, current_dir);
+ ck_assert ( g_str_has_prefix( current_dir, f ) == TRUE );
+ g_free(f);
+
+ f = rofi_theme_parse_prepare_file ( "../", "/tmp/" );
+ ck_assert_ptr_nonnull ( f );
+ ck_assert_str_eq ( f, "/");
+ g_free ( f );
+
+ f = rofi_theme_parse_prepare_file ( "/tmp/test.rasi" , "/random/");
+ ck_assert_ptr_nonnull ( f );
+ ck_assert_str_eq ( f, "/tmp/test.rasi" );
+ g_free ( f );
+
+ g_free ( current_dir );
+}
+END_TEST
static Suite * theme_parser_suite (void)
{
Suite *s;
@@ -1329,6 +1356,11 @@ static Suite * theme_parser_suite (void)
tcase_add_test ( tc_prop_import, test_import_error);
suite_add_tcase(s, tc_prop_import );
}
+ {
+ TCase *tc_prepare_path = tcase_create("prepare_path");
+ tcase_add_test ( tc_prepare_path, test_prepare_path);
+ suite_add_tcase(s, tc_prepare_path );
+ }
return s;
}