Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
196c6d2f
Commit
196c6d2f
authored
May 25, 2011
by
Moritz Lipp
Browse files
Update cc_open
parent
caa058e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
completion.c
View file @
196c6d2f
...
...
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include "completion.h"
#include "utils.h"
...
...
@@ -74,18 +75,18 @@ cc_open(girara_session_t* session, char* input)
girara_completion_t
*
completion
=
girara_completion_init
();
girara_completion_group_t
*
group
=
girara_completion_group_create
(
session
,
NULL
);
if
(
!
input
||
!
completion
||
!
group
)
{
if
(
completion
==
NULL
||
group
==
NULL
)
{
goto
error_free
;
}
gchar
*
path
=
girara_fix_path
(
input
);
if
(
path
==
NULL
||
strlen
(
path
)
==
0
)
{
if
(
path
==
NULL
)
{
goto
error_free
;
}
/* If the path does not begin with a slash we update the path with the current
* working directory */
if
(
path
[
0
]
!=
'/'
)
{
if
(
strlen
(
path
)
==
0
||
path
[
0
]
!=
'/'
)
{
size_t
path_max
;
#ifdef PATH_MAX
path_max
=
PATH_MAX
;
...
...
@@ -107,9 +108,25 @@ cc_open(girara_session_t* session, char* input)
path
=
tmp_path
;
}
/* Append a slash if the given argument is a directory */
if
((
g_file_test
(
path
,
G_FILE_TEST_IS_DIR
)
==
TRUE
)
&&
(
path
[
strlen
(
path
)
-
1
]
!=
'/'
))
{
char
*
tmp_path
=
g_strdup_printf
(
"%s/"
,
path
);
if
(
tmp_path
==
NULL
)
{
goto
error_free
;
}
g_free
(
path
);
path
=
tmp_path
;
}
gchar
*
current_path
=
(
path
[
strlen
(
path
)
-
1
]
==
'/'
)
?
path
:
dirname
(
path
);
gchar
*
current_file
=
(
path
[
strlen
(
path
)
-
1
]
==
'/'
)
?
""
:
basename
(
path
);
int
current_file_length
=
strlen
(
current_file
);
/* read directory */
if
(
g_file_test
(
path
,
G_FILE_TEST_IS_DIR
)
==
TRUE
)
{
GDir
*
dir
=
g_dir_open
(
path
,
0
,
NULL
);
if
(
g_file_test
(
current_
path
,
G_FILE_TEST_IS_DIR
)
==
TRUE
)
{
GDir
*
dir
=
g_dir_open
(
current_
path
,
0
,
NULL
);
if
(
dir
==
NULL
)
{
goto
error_free
;
}
...
...
@@ -117,17 +134,25 @@ cc_open(girara_session_t* session, char* input)
/* read files */
char
*
name
=
NULL
;
while
((
name
=
(
char
*
)
g_dir_read_name
(
dir
))
!=
NULL
)
{
char
*
e_name
=
g_filename_display_name
(
name
);
char
*
e_name
=
g_filename_display_name
(
name
);
int
e_length
=
strlen
(
e_name
);
if
(
e_name
==
NULL
)
{
goto
error_free
;
}
char
*
full_path
=
g_strdup_printf
(
"%s
/
%s"
,
path
,
e_name
);
char
*
full_path
=
g_strdup_printf
(
"%s%s"
,
current_
path
,
e_name
);
if
(
full_path
==
NULL
)
{
g_free
(
e_name
);
goto
error_free
;
}
if
(
file_valid_extension
(
zathura
,
full_path
)
==
true
)
{
if
(
g_file_test
(
full_path
,
G_FILE_TEST_IS_DIR
)
==
true
)
{
char
*
tmp_path
=
full_path
;
full_path
=
g_strdup_printf
(
"%s/"
,
full_path
);
g_free
(
tmp_path
);
girara_completion_group_add_element
(
group
,
full_path
,
NULL
);
}
else
if
(
file_valid_extension
(
zathura
,
full_path
)
==
true
)
{
girara_completion_group_add_element
(
group
,
full_path
,
NULL
);
}
...
...
@@ -136,11 +161,6 @@ cc_open(girara_session_t* session, char* input)
}
g_dir_close
(
dir
);
/* given path is a file */
}
else
if
(
g_file_test
(
path
,
G_FILE_TEST_IS_REGULAR
)
==
TRUE
)
{
if
(
file_valid_extension
(
zathura
,
path
)
==
true
)
{
girara_completion_group_add_element
(
group
,
path
,
NULL
);
}
}
g_free
(
path
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment