1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

[ecmascript] Moved add_to_ecmascript_string_list to util/string.h

This commit is contained in:
Witold Filipczyk 2023-01-01 09:04:20 +01:00
parent f2fa1d40e2
commit 2f6cac0243
6 changed files with 54 additions and 62 deletions

View File

@ -41,10 +41,6 @@
/* Unsafe macros */ /* Unsafe macros */
#include "document/html/internal.h" #include "document/html/internal.h"
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
#include "ecmascript/ecmascript.h"
#endif
void void
html_span(struct html_context *html_context, char *a, html_span(struct html_context *html_context, char *a,
char *xxx3, char *xxx4, char **xxx5) char *xxx3, char *xxx4, char **xxx5)

View File

@ -27,10 +27,6 @@
/* Unsafe macros */ /* Unsafe macros */
#include "document/html/internal.h" #include "document/html/internal.h"
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
#include "ecmascript/ecmascript.h"
#endif
#if 0 //def CONFIG_XML #if 0 //def CONFIG_XML
#include <libxml++/libxml++.h> #include <libxml++/libxml++.h>
#endif #endif

View File

@ -110,50 +110,6 @@ char *local_storage_filename;
int local_storage_ready; int local_storage_ready;
struct string *
add_to_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list,
const char *source, int length, int element_offset)
{
struct ecmascript_string_list_item *item;
struct string *string;
assertm(list && source, "[add_to_string_list]");
if_assert_failed return NULL;
item = (struct ecmascript_string_list_item *)mem_alloc(sizeof(*item));
if (!item) return NULL;
string = &item->string;
if (length < 0) length = strlen(source);
if (!init_string(string)
|| !add_bytes_to_string(string, source, length)) {
done_string(string);
mem_free(item);
return NULL;
}
item->element_offset = element_offset;
add_to_list_end(*list, item);
return string;
}
void
free_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list)
{
assertm(list != NULL, "[free_string_list]");
if_assert_failed return;
while (!list_empty(*list)) {
struct ecmascript_string_list_item *item = (struct ecmascript_string_list_item *)list->next;
del_from_list(item);
done_string(&item->string);
mem_free(item);
}
}
static int static int
is_prefix(char *prefix, char *url, int dl) is_prefix(char *prefix, char *url, int dl)
{ {

View File

@ -27,6 +27,7 @@
#include "main/module.h" #include "main/module.h"
#include "main/timer.h" #include "main/timer.h"
#include "util/string.h"
#include "util/time.h" #include "util/time.h"
//#define ECMASCRIPT_DEBUG 1 //#define ECMASCRIPT_DEBUG 1
@ -47,12 +48,6 @@ struct terminal;
struct uri; struct uri;
struct view_state; struct view_state;
struct ecmascript_string_list_item {
LIST_HEAD(struct ecmascript_string_list_item);
struct string string;
int element_offset;
};
struct ecmascript_interpreter { struct ecmascript_interpreter {
struct view_state *vs; struct view_state *vs;
void *backend_data; void *backend_data;
@ -202,10 +197,6 @@ void free_document(void *doc);
void location_goto(struct document_view *doc_view, char *url); void location_goto(struct document_view *doc_view, char *url);
void location_goto_const(struct document_view *doc_view, const char *url); void location_goto_const(struct document_view *doc_view, const char *url);
struct string *add_to_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list, const char *string, int length, int element_offset);
void free_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list);
extern char *console_error_filename; extern char *console_error_filename;
extern char *console_log_filename; extern char *console_log_filename;

View File

@ -654,3 +654,47 @@ free_string_list(LIST_OF(struct string_list_item) *list)
mem_free(item); mem_free(item);
} }
} }
struct string *
add_to_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list,
const char *source, int length, int element_offset)
{
struct ecmascript_string_list_item *item;
struct string *string;
assertm(list && source, "[add_to_string_list]");
if_assert_failed return NULL;
item = (struct ecmascript_string_list_item *)mem_alloc(sizeof(*item));
if (!item) return NULL;
string = &item->string;
if (length < 0) length = strlen(source);
if (!init_string(string)
|| !add_bytes_to_string(string, source, length)) {
done_string(string);
mem_free(item);
return NULL;
}
item->element_offset = element_offset;
add_to_list_end(*list, item);
return string;
}
void
free_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list)
{
assertm(list != NULL, "[free_string_list]");
if_assert_failed return;
while (!list_empty(*list)) {
struct ecmascript_string_list_item *item = (struct ecmascript_string_list_item *)list->next;
del_from_list(item);
done_string(&item->string);
mem_free(item);
}
}

View File

@ -308,6 +308,15 @@ add_to_string_list(LIST_OF(struct string_list_item) *list,
void free_string_list(LIST_OF(struct string_list_item) *list); void free_string_list(LIST_OF(struct string_list_item) *list);
struct ecmascript_string_list_item {
LIST_HEAD(struct ecmascript_string_list_item);
struct string string;
int element_offset;
};
struct string *add_to_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list, const char *string, int length, int element_offset);
void free_ecmascript_string_list(LIST_OF(struct ecmascript_string_list_item) *list);
void string_replace(struct string *res, struct string *inp, struct string *what, struct string *repl); void string_replace(struct string *res, struct string *inp, struct string *what, struct string *repl);