forked from sergiotarxz/mangareader
Adding missing files.
This commit is contained in:
parent
280b0445a2
commit
cbd490d99c
2
Makefile
2
Makefile
@ -6,4 +6,4 @@ LDFLAGS := $(shell pkg-config --libs ${LIBS})
|
|||||||
CC_COMMAND := ${CC} ${INCDIR} ${CFLAGS}
|
CC_COMMAND := ${CC} ${INCDIR} ${CFLAGS}
|
||||||
all: build
|
all: build
|
||||||
build:
|
build:
|
||||||
${CC_COMMAND} src/util/string.c src/util/xml.c src/util/soup.c src/view/list_view_manga.c src/view/main_view.c src/manga.c src/backend/readmng.c manga.c main.c -o main ${LDFLAGS} -ggdb
|
${CC_COMMAND} src/util/xml.c src/util/soup.c src/view/list_view_manga.c src/view/main_view.c src/manga.c src/backend/readmng.c manga.c main.c -o main ${LDFLAGS} -ggdb
|
||||||
|
@ -24,7 +24,12 @@ struct String {
|
|||||||
|
|
||||||
struct SplittedString *
|
struct SplittedString *
|
||||||
split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size);
|
split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size);
|
||||||
|
char *
|
||||||
|
alloc_string(size_t len);
|
||||||
void
|
void
|
||||||
splitted_string_free (struct SplittedString *splitted_string);
|
splitted_string_free (struct SplittedString *splitted_string);
|
||||||
char *
|
char *
|
||||||
match_1 (char *re_str, char *subject);
|
match_1 (char *re_str, char *subject);
|
||||||
|
void
|
||||||
|
copy_substring(const char *origin, char *dest, size_t dest_len, size_t start,
|
||||||
|
size_t len);
|
||||||
|
47
manga.c
47
manga.c
@ -4,8 +4,6 @@
|
|||||||
#include <pcre2.h>
|
#include <pcre2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <openmg/util/string.h>
|
|
||||||
|
|
||||||
#include <manga.h>
|
#include <manga.h>
|
||||||
|
|
||||||
// TODO: Split this file and delete it.
|
// TODO: Split this file and delete it.
|
||||||
@ -14,6 +12,20 @@ iterate_string_to_split(struct SplittedString *splitted_string,
|
|||||||
pcre2_code *re, int *will_break, const char *subject,
|
pcre2_code *re, int *will_break, const char *subject,
|
||||||
size_t subject_size, size_t *start_pos, size_t *offset);
|
size_t subject_size, size_t *start_pos, size_t *offset);
|
||||||
|
|
||||||
|
void
|
||||||
|
copy_substring(const char *origin, char *dest, size_t dest_len, size_t start,
|
||||||
|
size_t len) {
|
||||||
|
size_t copying_offset = 0;
|
||||||
|
while (copying_offset < len) {
|
||||||
|
if (!(start+copying_offset <=dest_len)) {
|
||||||
|
fprintf(stderr, "Read attempt out of bounds.%ld %ld %ld\n", dest_len, start, len);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dest[copying_offset] = origin[start+copying_offset];
|
||||||
|
copying_offset++;
|
||||||
|
}
|
||||||
|
dest[len] = '\0';
|
||||||
|
}
|
||||||
struct SplittedString *
|
struct SplittedString *
|
||||||
split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size) {
|
split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size) {
|
||||||
pcre2_code_8 *re;
|
pcre2_code_8 *re;
|
||||||
@ -43,6 +55,13 @@ split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size
|
|||||||
|
|
||||||
return splitted_string;
|
return splitted_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
alloc_string(size_t len) {
|
||||||
|
char * return_value = NULL;
|
||||||
|
return g_malloc (len + 1 * sizeof *return_value);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
splitted_string_free (struct SplittedString *splitted_string) {
|
splitted_string_free (struct SplittedString *splitted_string) {
|
||||||
for (int i = 0; i<splitted_string->n_strings; i++) {
|
for (int i = 0; i<splitted_string->n_strings; i++) {
|
||||||
@ -54,13 +73,11 @@ splitted_string_free (struct SplittedString *splitted_string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
iterate_string_to_split(struct SplittedString *splitted_string,
|
iterate_string_to_split(struct SplittedString *splitted_string, pcre2_code *re, int *will_break, const char *subject,
|
||||||
pcre2_code *re, int *will_break, const char *subject,
|
|
||||||
size_t subject_size, size_t *start_pos, size_t *offset) {
|
size_t subject_size, size_t *start_pos, size_t *offset) {
|
||||||
pcre2_match_data_8 *match_data;
|
pcre2_match_data_8 *match_data;
|
||||||
PCRE2_SIZE *ovector;
|
PCRE2_SIZE *ovector;
|
||||||
int rc;
|
int rc;
|
||||||
MgUtilString *string_util = mg_util_string_new ();
|
|
||||||
|
|
||||||
splitted_string->n_strings++;
|
splitted_string->n_strings++;
|
||||||
match_data = pcre2_match_data_create_from_pattern_8 (re, NULL);
|
match_data = pcre2_match_data_create_from_pattern_8 (re, NULL);
|
||||||
@ -75,22 +92,24 @@ iterate_string_to_split(struct SplittedString *splitted_string,
|
|||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
struct String *current_substring =
|
struct String *current_substring =
|
||||||
&splitted_string->substrings [*offset];
|
&splitted_string->substrings [*offset];
|
||||||
current_substring->content = mg_util_string_alloc_string (string_util,
|
current_substring->content = alloc_string (subject_size
|
||||||
|
- *start_pos);
|
||||||
|
copy_substring (subject, current_substring->content,
|
||||||
|
subject_size,
|
||||||
|
*start_pos,
|
||||||
subject_size - *start_pos);
|
subject_size - *start_pos);
|
||||||
mg_util_string_copy_substring (string_util, subject,
|
|
||||||
current_substring->content, subject_size,
|
|
||||||
*start_pos, subject_size - *start_pos);
|
|
||||||
current_substring->size = subject_size - *start_pos;
|
current_substring->size = subject_size - *start_pos;
|
||||||
|
|
||||||
*will_break = 1;
|
*will_break = 1;
|
||||||
goto cleanup_iterate_string_to_split;
|
goto cleanup_iterate_string_to_split;
|
||||||
}
|
}
|
||||||
ovector = pcre2_get_ovector_pointer_8(match_data);
|
ovector = pcre2_get_ovector_pointer_8(match_data);
|
||||||
splitted_string->substrings[*offset].content =
|
splitted_string->substrings[*offset].content = alloc_string (
|
||||||
mg_util_string_alloc_string (string_util, ovector[0] - *start_pos);
|
ovector[0] - *start_pos);
|
||||||
mg_util_string_copy_substring (string_util,
|
copy_substring (subject, splitted_string->substrings[*offset]
|
||||||
subject, splitted_string->substrings[*offset].content,
|
.content,
|
||||||
subject_size, *start_pos,
|
subject_size,
|
||||||
|
*start_pos,
|
||||||
ovector[0] - *start_pos);
|
ovector[0] - *start_pos);
|
||||||
splitted_string->substrings[*offset].size =
|
splitted_string->substrings[*offset].size =
|
||||||
ovector[0] - *start_pos;
|
ovector[0] - *start_pos;
|
||||||
|
24
src/manga.c
24
src/manga.c
@ -1,9 +1,7 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
#include <openmg/util/string.h>
|
|
||||||
#include <openmg/manga.h>
|
|
||||||
|
|
||||||
#include <manga.h>
|
#include <manga.h>
|
||||||
|
#include <openmg/manga.h>
|
||||||
|
|
||||||
struct _MgManga {
|
struct _MgManga {
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
@ -145,20 +143,12 @@ mg_manga_get_property (GObject *object,
|
|||||||
MgManga *
|
MgManga *
|
||||||
mg_manga_new (const char *const image_url, const char *const title, const char *id) {
|
mg_manga_new (const char *const image_url, const char *const title, const char *id) {
|
||||||
MgManga *self = NULL;
|
MgManga *self = NULL;
|
||||||
MgUtilString *string_util = mg_util_string_new ();
|
|
||||||
self = MG_MANGA ((g_object_new (MG_TYPE_MANGA, NULL)));
|
self = MG_MANGA ((g_object_new (MG_TYPE_MANGA, NULL)));
|
||||||
self->image_url = mg_util_string_alloc_string (string_util,
|
self->image_url = alloc_string (strlen (image_url));
|
||||||
strlen (image_url));
|
self->title = alloc_string (strlen (title));
|
||||||
self->title = mg_util_string_alloc_string (string_util,
|
self->id = alloc_string (strlen (id));
|
||||||
strlen (title));
|
copy_substring (image_url, self->image_url, strlen(image_url) + 1, 0, strlen (image_url));
|
||||||
self->id = mg_util_string_alloc_string (string_util,
|
copy_substring (title, self->title, strlen(title) + 1, 0, strlen (title));
|
||||||
strlen (id));
|
copy_substring (id, self->id, strlen(id) + 1, 0, strlen (id));
|
||||||
mg_util_string_copy_substring (string_util,
|
|
||||||
image_url, self->image_url,
|
|
||||||
strlen(image_url) + 1, 0, strlen (image_url));
|
|
||||||
mg_util_string_copy_substring (string_util,
|
|
||||||
title, self->title, strlen(title) + 1, 0, strlen (title));
|
|
||||||
mg_util_string_copy_substring (string_util,
|
|
||||||
id, self->id, strlen(id) + 1, 0, strlen (id));
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include <libxml/HTMLparser.h>
|
#include <libxml/HTMLparser.h>
|
||||||
#include <libxml/xpath.h>
|
#include <libxml/xpath.h>
|
||||||
|
|
||||||
#include <openmg/util/string.h>
|
|
||||||
#include <openmg/util/xml.h>
|
#include <openmg/util/xml.h>
|
||||||
|
|
||||||
struct _MgUtilXML {
|
struct _MgUtilXML {
|
||||||
@ -57,7 +56,6 @@ mg_util_xml_find_class (MgUtilXML *self, xmlNodePtr node, char *class,
|
|||||||
char *
|
char *
|
||||||
mg_util_xml_get_attr (MgUtilXML *self, xmlNodePtr const node, const char *attr_name) {
|
mg_util_xml_get_attr (MgUtilXML *self, xmlNodePtr const node, const char *attr_name) {
|
||||||
char *return_value = NULL;
|
char *return_value = NULL;
|
||||||
MgUtilString *string_util = mg_util_string_new ();
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -67,9 +65,11 @@ mg_util_xml_get_attr (MgUtilXML *self, xmlNodePtr const node, const char *attr_n
|
|||||||
if (!attr->children->content) continue;
|
if (!attr->children->content) continue;
|
||||||
size_t content_len = strlen((char *)
|
size_t content_len = strlen((char *)
|
||||||
attr->children->content);
|
attr->children->content);
|
||||||
return_value = mg_util_string_alloc_string (string_util, content_len);
|
return_value = alloc_string(content_len);
|
||||||
mg_util_string_copy_substring (string_util, (char *) attr->children->content,
|
copy_substring ((char *) attr->children->content, return_value,
|
||||||
return_value, content_len, 0, content_len);
|
content_len,
|
||||||
|
0,
|
||||||
|
content_len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user