Another string.

This commit is contained in:
2025-08-05 22:29:54 -04:00
parent 9cb76d2b22
commit 92e90f9233
4 changed files with 12 additions and 17 deletions

View File

@ -150,7 +150,7 @@ public: //BUG: for now everything is public
entries, it is the initial value */ entries, it is the initial value */
DilloHtmlSelect *select; DilloHtmlSelect *select;
bool init_val; /* only meaningful for buttons */ bool init_val; /* only meaningful for buttons */
Dstr *file_data; /* only meaningful for file inputs. std::string file_data; /* only meaningful for file inputs.
TODO: may become a list... */ TODO: may become a list... */
private: private:
@ -1639,7 +1639,6 @@ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, Embed *embed2,
default: default:
break; break;
} }
file_data = NULL;
reset (); reset ();
} }
@ -1648,7 +1647,6 @@ DilloHtmlInput::DilloHtmlInput (DilloHtmlInputType type2, Embed *embed2,
*/ */
DilloHtmlInput::~DilloHtmlInput () DilloHtmlInput::~DilloHtmlInput ()
{ {
dStr_free(file_data, 1);
if (select) if (select)
delete select; delete select;
} }
@ -1714,9 +1712,8 @@ void DilloHtmlInput::readFile (BrowserWindow *bw)
const char *filename = a_UIcmd_select_file(); const char *filename = a_UIcmd_select_file();
if (filename) { if (filename) {
a_UIcmd_set_msg(bw, "Loading file..."); a_UIcmd_set_msg(bw, "Loading file...");
dStr_free(file_data, 1);
file_data = a_Misc_file2dstr(filename); file_data = a_Misc_file2dstr(filename);
if (file_data) { if (not file_data.empty()) {
a_UIcmd_set_msg(bw, "File loaded."); a_UIcmd_set_msg(bw, "File loaded.");
LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource(); LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource();
lbr->setLabel(filename); lbr->setLabel(filename);
@ -1775,8 +1772,8 @@ void DilloHtmlInput::appendValuesTo(std::vector< std::string > &values, bool is_
LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource(); LabelButtonResource *lbr = (LabelButtonResource*)embed->getResource();
const char *filename = lbr->getLabel(); const char *filename = lbr->getLabel();
if (filename[0] && strcmp(filename, init_str.value().c_str())) { if (filename[0] && strcmp(filename, init_str.value().c_str())) {
if (file_data) { if (not file_data.empty()) {
values.push_back( file_data->str ); values.push_back( file_data );
} else { } else {
MSG("FORM file input \"%s\" not loaded.\n", filename); MSG("FORM file input \"%s\" not loaded.\n", filename);
} }

View File

@ -466,19 +466,18 @@ char *a_Misc_encode_base64(const char *in)
* Return value: dStr on success, NULL on error. * Return value: dStr on success, NULL on error.
* TODO: a filesize threshold may be implemented. * TODO: a filesize threshold may be implemented.
*/ */
Dstr *a_Misc_file2dstr(const char *filename) std::string a_Misc_file2dstr(const char *filename)
{ {
FILE *F_in; FILE *F_in;
int n; int n;
char buf[4096]; char buf[4096];
Dstr *dstr = NULL; std::string str;
if ((F_in = fopen(filename, "r"))) { if ((F_in = fopen(filename, "r"))) {
dstr = dStr_sized_new(4096);
while ((n = fread (buf, 1, 4096, F_in)) > 0) { while ((n = fread (buf, 1, 4096, F_in)) > 0) {
dStr_append_l(dstr, buf, n); std::copy_n( buf, n, std::back_inserter( str ) );
} }
fclose(F_in); fclose(F_in);
} }
return dstr; return str;
} }

View File

@ -10,6 +10,7 @@
#include <string_view> #include <string_view>
std::string a_Misc_escape_chars(std::string_view str, std::string_view esc_set); std::string a_Misc_escape_chars(std::string_view str, std::string_view esc_set);
std::optional< std::string > a_Misc_parse_content_type(const char *str, char **major, char **minor); std::optional< std::string > a_Misc_parse_content_type(const char *str, char **major, char **minor);
std::string a_Misc_file2dstr(const char *filename);
#endif #endif
int a_Misc_expand_tabs(char **start, char *end, char *buf, int buflen); int a_Misc_expand_tabs(char **start, char *end, char *buf, int buflen);
@ -19,4 +20,3 @@ int a_Misc_content_type_cmp(const char* ct1, const char *ct2);
int a_Misc_parse_geometry(char *geom, int *x, int *y, int *w, int *h); int a_Misc_parse_geometry(char *geom, int *x, int *y, int *w, int *h);
int a_Misc_parse_search_url(char *source, char **label, char **urlstr); int a_Misc_parse_search_url(char *source, char **label, char **urlstr);
char *a_Misc_encode_base64(const char *in); char *a_Misc_encode_base64(const char *in);
Dstr *a_Misc_file2dstr(const char *filename);

View File

@ -1074,12 +1074,11 @@ void StyleEngine::init () {
} }
void StyleEngine::buildUserStyle () { void StyleEngine::buildUserStyle () {
Dstr *style;
char *filename = dStrconcat(dGethomedir(), "/.flenser/style.css", NULL); char *filename = dStrconcat(dGethomedir(), "/.flenser/style.css", NULL);
if ((style = a_Misc_file2dstr(filename))) { const std::string style= a_Misc_file2dstr(filename);
CssParser::parse (NULL,NULL,cssContext,style->str, style->len,CSS_ORIGIN_USER); if (not style.empty()) {
dStr_free (style, 1); CssParser::parse (NULL,NULL,cssContext, style.c_str(), style.size(), CSS_ORIGIN_USER);
} }
dFree (filename); dFree (filename);
} }