Removing manga.c splited in soup.c, string.c and regex.c.

This commit is contained in:
sergiotarxz 2021-10-31 15:25:04 +01:00
parent 4f5e37cd45
commit ed7a3a4ec5
7 changed files with 77 additions and 46 deletions

View File

@ -6,4 +6,4 @@ LDFLAGS := $(shell pkg-config --libs ${LIBS})
CC_COMMAND := ${CC} ${INCDIR} ${CFLAGS}
all: 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/regex.c 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

View File

@ -1,30 +0,0 @@
#pragma once
#include <libsoup/soup.h>
#include <libxml/HTMLparser.h>
#include <libxml/xpath.h>
#ifndef PCRE2_CODE_UNIT_WIDTH
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
#endif
struct Manga {
char *title;
char *image_url;
};
struct SplittedString {
struct String *substrings;
size_t n_strings;
};
struct String {
char *content;
size_t size;
};
struct SplittedString *
split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size);
void
splitted_string_free (struct SplittedString *splitted_string);
char *
match_1 (char *re_str, char *subject);

View File

@ -0,0 +1,32 @@
#pragma once
#include <glib-object.h>
G_BEGIN_DECLS;
#define MG_TYPE_UTIL_REGEX mg_util_regex_get_type()
G_DECLARE_FINAL_TYPE (MgUtilRegex, mg_util_regex, MG, UTIL_REGEX, GObject)
MgUtilRegex *mg_util_regex_new ();
struct SplittedString {
struct String *substrings;
size_t n_strings;
};
struct String {
char *content;
size_t size;
};
struct SplittedString *
mg_util_regex_split (MgUtilRegex *self,
char *re_str, size_t re_str_size, const char *subject, size_t subject_size);
void
mg_util_regex_splitted_string_free (MgUtilRegex *self,
struct SplittedString *splitted_string);
char *
mg_util_regex_match_1 (MgUtilRegex *self,
char *re_str, char *subject);
G_END_DECLS

View File

@ -2,6 +2,7 @@
#include <openmg/backend/readmng.h>
#include <openmg/util/soup.h>
#include <openmg/util/regex.h>
#include <openmg/util/xml.h>
#include <openmg/manga.h>
@ -255,7 +256,8 @@ static char *
mg_backend_get_id_manga_link (MgBackendReadmng *self, xmlNodePtr a) {
char *re_str = "readmng\\.com/([^/]+)";
MgUtilXML *xml_utils = self->xml_utils;
return match_1 (re_str, mg_util_xml_get_attr (xml_utils, a, "href"));
MgUtilRegex *regex_util = mg_util_regex_new ();
return mg_util_regex_match_1 (regex_util, re_str, mg_util_xml_get_attr (xml_utils, a, "href"));
}
static void

View File

@ -1,21 +1,42 @@
#include <libsoup/soup.h>
#include <glib-object.h>
#ifndef PCRE2_CODE_UNIT_WIDTH
#define PCRE2_CODE_UNIT_WIDTH 8
#include <pcre2.h>
#endif
#include <openmg/util/regex.h>
#include <openmg/util/string.h>
#include <manga.h>
struct _MgUtilRegex {
GObject parent_instance;
};
G_DEFINE_TYPE (MgUtilRegex, mg_util_regex, G_TYPE_OBJECT)
// TODO: Split this file and delete it.
static void
iterate_string_to_split(struct SplittedString *splitted_string,
mg_util_regex_class_init (MgUtilRegexClass *class) {
}
static void
mg_util_regex_init (MgUtilRegex *class) {
}
static void
mg_util_regex_iterate_string_to_split (MgUtilRegex *self,
struct SplittedString *splitted_string,
pcre2_code *re, int *will_break, const char *subject,
size_t subject_size, size_t *start_pos, size_t *offset);
MgUtilRegex *
mg_util_regex_new () {
MgUtilRegex *self = NULL;
self = MG_UTIL_REGEX ((g_object_new (MG_TYPE_UTIL_REGEX, NULL)));
return self;
}
struct SplittedString *
split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size) {
mg_util_regex_split (MgUtilRegex *self,
char *re_str, size_t re_str_size, const char *subject, size_t subject_size) {
pcre2_code_8 *re;
size_t start_pos = 0;
size_t offset = 0;
@ -31,7 +52,8 @@ split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size
re_str_size, 0, &regex_compile_error, &error_offset, NULL);
while (start_pos < subject_size) {
int will_break = 0;
iterate_string_to_split(splitted_string, re, &will_break,
mg_util_regex_iterate_string_to_split (self,
splitted_string, re, &will_break,
subject, subject_size, &start_pos, &offset);
if (will_break) {
break;
@ -43,8 +65,10 @@ split(char *re_str, size_t re_str_size, const char *subject, size_t subject_size
return splitted_string;
}
void
splitted_string_free (struct SplittedString *splitted_string) {
mg_util_regex_splitted_string_free (MgUtilRegex *self,
struct SplittedString *splitted_string) {
for (int i = 0; i<splitted_string->n_strings; i++) {
g_free (splitted_string->substrings[i].content);
}
@ -54,8 +78,9 @@ splitted_string_free (struct SplittedString *splitted_string) {
}
static void
iterate_string_to_split(struct SplittedString *splitted_string,
pcre2_code *re, int *will_break, const char *subject,
mg_util_regex_iterate_string_to_split (MgUtilRegex *self,
struct SplittedString *splitted_string,
pcre2_code *re, int *will_break, const char *subject,
size_t subject_size, size_t *start_pos, size_t *offset) {
pcre2_match_data_8 *match_data;
PCRE2_SIZE *ovector;
@ -104,7 +129,8 @@ cleanup_iterate_string_to_split:
}
char *
match_1 (char *re_str, char *subject) {
mg_util_regex_match_1 (MgUtilRegex *self,
char *re_str, char *subject) {
pcre2_code *re;
pcre2_match_data *match_data;

View File

@ -28,7 +28,6 @@ mg_util_soup_get_request (MgUtilSoup *self, const char *url, gsize *size_respons
SoupSession *soup_session;
SoupMessage *msg;
GValue response = G_VALUE_INIT;
guint status;
*size_response_text = 0;
@ -36,7 +35,7 @@ mg_util_soup_get_request (MgUtilSoup *self, const char *url, gsize *size_respons
soup_session = soup_session_new ();
msg = soup_message_new ("GET", url);
status = soup_session_send_message (soup_session, msg);
soup_session_send_message (soup_session, msg);
g_object_get_property(
G_OBJECT (msg),
"response-body-data",

View File

@ -4,6 +4,7 @@
#include <libxml/xpath.h>
#include <openmg/util/string.h>
#include <openmg/util/regex.h>
#include <openmg/util/xml.h>
struct _MgUtilXML {
@ -94,8 +95,9 @@ mg_util_xml_has_class (MgUtilXML *self,
const char *class_attribute, const char *class_to_check) {
char *re = "\\s+";
struct SplittedString *classes;
MgUtilRegex *regex_util = mg_util_regex_new ();
int return_value = 0;
classes = split (re, strlen(re), class_attribute,
classes = mg_util_regex_split (regex_util, re, strlen(re), class_attribute,
strlen (class_attribute));
for (int i = 0; i<classes->n_strings; i++) {
if (strcmp (classes->substrings[i].content, class_to_check) == 0) {
@ -105,7 +107,7 @@ mg_util_xml_has_class (MgUtilXML *self,
}
cleanup_has_class:
splitted_string_free (classes);
mg_util_regex_splitted_string_free (regex_util, classes);
return return_value;
}