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
f5fabb01
Commit
f5fabb01
authored
Nov 18, 2010
by
Moritz Lipp
Browse files
Determine realpath of path
parent
cd7fda37
Changes
4
Hide whitespace changes
Inline
Side-by-side
ft/document.c
View file @
f5fabb01
/* See LICENSE file for license and copyright information */
#define _BSD_SOURCE
#define _XOPEN_SOURCE 500
// TODO: Implement realpath
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "document.h"
#include "../utils.h"
...
...
@@ -32,13 +37,33 @@ zathura_document_open(const char* path, const char* password)
return
NULL
;
}
/* determine real path */
size_t
path_max
;
#ifdef PATH_MAX
path_max
=
PATH_MAX
;
#else
path_max
=
pathconf
(
path
,
_PC_PATH_MAX
);
if
(
path_max
<=
0
)
path_max
=
4096
;
#endif
char
*
real_path
=
malloc
(
sizeof
(
char
)
*
path_max
);
if
(
!
real_path
)
{
return
NULL
;
}
if
(
!
realpath
(
path
,
real_path
))
{
free
(
real_path
);
return
NULL
;
}
zathura_document_t
*
document
=
malloc
(
sizeof
(
zathura_document_t
));
if
(
!
document
)
{
free
(
real_path
);
return
NULL
;
}
document
->
file_path
=
path
;
document
->
file_path
=
real_path
;
document
->
password
=
password
;
document
->
current_page_number
=
0
;
document
->
number_of_pages
=
0
;
...
...
@@ -64,6 +89,11 @@ zathura_document_open(const char* path, const char* password)
if
(
zathura_document_plugins
[
i
].
open_function
)
{
if
(
zathura_document_plugins
[
i
].
open_function
(
document
))
{
return
document
;
}
else
{
fprintf
(
stderr
,
"error: could not open file
\n
"
);
free
(
real_path
);
free
(
document
);
return
NULL
;
}
}
}
...
...
@@ -71,6 +101,9 @@ zathura_document_open(const char* path, const char* password)
fprintf
(
stderr
,
"error: unknown file type
\n
"
);
free
(
real_path
);
free
(
document
);
return
NULL
;
}
...
...
@@ -83,12 +116,21 @@ zathura_document_free(zathura_document_t* document)
if
(
!
document
->
functions
.
document_free
)
{
fprintf
(
stderr
,
"error: %s not implemented
\n
"
,
__FUNCTION__
);
if
(
document
->
file_path
)
{
free
(
document
->
file_path
);
}
free
(
document
);
return
true
;
}
bool
r
=
document
->
functions
.
document_free
(
document
);
if
(
document
->
file_path
)
{
free
(
document
->
file_path
);
}
free
(
document
);
return
r
;
...
...
ft/document.h
View file @
f5fabb01
...
...
@@ -70,7 +70,7 @@ typedef struct zathura_page_s
struct
zathura_document_s
{
const
char
*
file_path
;
char
*
file_path
;
const
char
*
password
;
unsigned
int
current_page_number
;
unsigned
int
number_of_pages
;
...
...
ft/pdf/pdf.c
View file @
f5fabb01
...
...
@@ -21,13 +21,47 @@ pdf_document_open(zathura_document_t* document)
document
->
functions
.
page_render
=
pdf_page_render
;
document
->
functions
.
page_free
=
pdf_page_free
;
document
->
data
=
malloc
(
sizeof
(
pdf_document_t
));
if
(
!
document
->
data
)
{
return
false
;
}
/* format path */
GError
*
error
=
NULL
;
char
*
file_uri
=
g_filename_to_uri
(
document
->
file_path
,
NULL
,
&
error
);
if
(
!
file_uri
)
{
fprintf
(
stderr
,
"error: could not open file: %s
\n
"
,
error
->
message
);
g_error_free
(
error
);
free
(
document
->
data
);
return
false
;
}
pdf_document_t
*
pdf_document
=
(
pdf_document_t
*
)
document
->
data
;
pdf_document
->
document
=
poppler_document_new_from_file
(
file_uri
,
document
->
password
,
&
error
);
if
(
!
pdf_document
->
document
)
{
fprintf
(
stderr
,
"error: could not open file: %s
\n
"
,
error
->
message
);
g_error_free
(
error
);
free
(
document
->
data
);
return
false
;
}
return
true
;
}
bool
pdf_document_free
(
zathura_document_t
*
document
)
{
return
false
;
if
(
!
document
)
{
return
false
;
}
if
(
document
->
data
)
{
free
(
document
->
data
);
}
return
true
;
}
zathura_list_t
*
...
...
ft/pdf/pdf.h
View file @
f5fabb01
...
...
@@ -4,9 +4,15 @@
#define PDF_H
#include <stdbool.h>
#include <poppler.h>
#include "../document.h"
typedef
struct
pdf_document_s
{
PopplerDocument
*
document
;
}
pdf_document_t
;
bool
pdf_document_open
(
zathura_document_t
*
document
);
bool
pdf_document_free
(
zathura_document_t
*
document
);
zathura_list_t
*
pdf_document_index_generate
(
zathura_document_t
*
document
);
...
...
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