Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zathura
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
59
Issues
59
List
Boards
Labels
Milestones
Custom Issue Tracker
Custom Issue Tracker
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pwmt
zathura
Commits
a08520a3
Commit
a08520a3
authored
Aug 14, 2012
by
Moritz Lipp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement cmd_exec with
parent
65bd5452
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
0 deletions
+86
-0
commands.c
commands.c
+22
-0
commands.h
commands.h
+9
-0
config.c
config.c
+1
-0
utils.c
utils.c
+42
-0
utils.h
utils.h
+12
-0
No files found.
commands.c
View file @
a08520a3
...
...
@@ -21,6 +21,7 @@
#include <girara/session.h>
#include <girara/settings.h>
#include <girara/commands.h>
#include <girara/datastructures.h>
#include <girara/utils.h>
...
...
@@ -487,6 +488,27 @@ error_ret:
return
true
;
}
bool
cmd_exec
(
girara_session_t
*
session
,
girara_list_t
*
argument_list
)
{
g_return_val_if_fail
(
session
!=
NULL
,
false
);
g_return_val_if_fail
(
session
->
global
.
data
!=
NULL
,
false
);
zathura_t
*
zathura
=
session
->
global
.
data
;
if
(
zathura
->
document
!=
NULL
)
{
const
char
*
path
=
zathura_document_get_path
(
zathura
->
document
);
GIRARA_LIST_FOREACH
(
argument_list
,
char
*
,
iter
,
value
)
char
*
r
=
NULL
;
if
((
r
=
replace_substring
(
value
,
"$FILE"
,
path
))
!=
NULL
)
{
girara_list_iterator_set
(
iter
,
r
);
}
GIRARA_LIST_FOREACH_END
(
argument_list
,
char
*
,
iter
,
value
);
}
return
girara_exec_with_argument_list
(
session
,
argument_list
);
}
bool
cmd_offset
(
girara_session_t
*
session
,
girara_list_t
*
argument_list
)
{
...
...
commands.h
View file @
a08520a3
...
...
@@ -142,6 +142,15 @@ bool cmd_search(girara_session_t* session, const char* input, girara_argument_t*
*/
bool
cmd_export
(
girara_session_t
*
session
,
girara_list_t
*
argument_list
);
/**
* Execute command
*
* @param session The used girara session
* @param argument_list List of passed arguments
* @return true if no error occured
*/
bool
cmd_exec
(
girara_session_t
*
session
,
girara_list_t
*
argument_list
);
/**
* Set page offset
*
...
...
config.c
View file @
a08520a3
...
...
@@ -293,6 +293,7 @@ config_load_default(zathura_t* zathura)
girara_inputbar_command_add
(
gsession
,
"blist"
,
NULL
,
cmd_bookmark_open
,
cc_bookmarks
,
_
(
"List all bookmarks"
));
girara_inputbar_command_add
(
gsession
,
"close"
,
NULL
,
cmd_close
,
NULL
,
_
(
"Close current file"
));
girara_inputbar_command_add
(
gsession
,
"info"
,
NULL
,
cmd_info
,
NULL
,
_
(
"Show file information"
));
girara_inputbar_command_add
(
gsession
,
"exec"
,
NULL
,
cmd_exec
,
NULL
,
_
(
"Execute a command"
));
girara_inputbar_command_add
(
gsession
,
"help"
,
NULL
,
cmd_help
,
NULL
,
_
(
"Show help"
));
girara_inputbar_command_add
(
gsession
,
"open"
,
"o"
,
cmd_open
,
cc_open
,
_
(
"Open document"
));
girara_inputbar_command_add
(
gsession
,
"quit"
,
"q"
,
cmd_quit
,
NULL
,
_
(
"Close zathura"
));
...
...
utils.c
View file @
a08520a3
...
...
@@ -393,3 +393,45 @@ zathura_get_version_string(zathura_t* zathura, bool markup)
return
version
;
}
char
*
replace_substring
(
const
char
*
string
,
const
char
*
old
,
const
char
*
new
)
{
if
(
string
==
NULL
||
old
==
NULL
||
new
==
NULL
)
{
return
NULL
;
}
size_t
old_len
=
strlen
(
old
);
size_t
new_len
=
strlen
(
new
);
/* count occurences */
unsigned
int
count
=
0
;
unsigned
int
i
=
0
;
for
(
i
=
0
;
string
[
i
]
!=
'\0'
;
i
++
)
{
if
(
strstr
(
&
string
[
i
],
old
)
==
&
string
[
i
])
{
i
+=
(
old_len
-
1
);
count
++
;
}
}
if
(
count
==
0
)
{
return
NULL
;
}
char
*
ret
=
g_malloc0
(
sizeof
(
char
)
*
(
i
-
count
*
old_len
+
count
*
new_len
+
1
));
i
=
0
;
/* replace */
while
(
*
string
!=
'\0'
)
{
if
(
strstr
(
string
,
old
)
==
string
)
{
strcpy
(
&
ret
[
i
],
new
);
i
+=
new_len
;
string
+=
old_len
;
}
else
{
ret
[
i
++
]
=
*
string
++
;
}
}
return
ret
;
}
utils.h
View file @
a08520a3
...
...
@@ -140,4 +140,16 @@ void document_draw_search_results(zathura_t* zathura, bool value);
*/
char
*
zathura_get_version_string
(
zathura_t
*
zathura
,
bool
markup
);
/**
* Replaces all occurences of \ref old in \ref string with \ref new and returns
* a new allocated string
*
* @param string The original string
* @param old String to replace
* @param new Replacement string
*
* @return new allocated string
*/
char
*
replace_substring
(
const
char
*
string
,
const
char
*
old
,
const
char
*
new
);
#endif // UTILS_H
Write
Preview
Markdown
is supported
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