Get some of the last remaining C files into C++

They still need to be fixed up, but they now build with C++.
This commit is contained in:
2025-08-23 02:09:47 -04:00
parent e4f1102e32
commit f283391b46
78 changed files with 172 additions and 144 deletions

View File

@ -4,5 +4,5 @@ AM_CPPFLAGS = \
noinst_LIBRARIES = libDlib.a
libDlib_a_SOURCES = \
dlib.h \
dlib.hh \
dlib.cc

View File

@ -27,7 +27,7 @@
#include <ctype.h>
#include <time.h>
#include "dlib.h"
#include "dlib.hh"
static bool dLib_show_msg = TRUE;
@ -962,6 +962,27 @@ char *dGetline (FILE *stream)
return line;
}
std::optional< std::string >
dGetline_string (FILE *stream)
{
int ch;
Dstr *dstr;
if( stream == nullptr ) return std::nullopt;
dstr = dStr_sized_new(64);
while ((ch = fgetc(stream)) != EOF) {
dStr_append_c(dstr, ch);
if (ch == '\n')
break;
}
std::optional< std::string > line;
if(dstr->len) line= dstr->str;
dStr_free(dstr, 1);
return line;
}
/**
* Close a FD handling EINTR.
*/

View File

@ -6,7 +6,8 @@
#include <stdarg.h> /* for va_list */
#include <string.h> /* for strerror */
#include <stdbool.h>
#include <string>
#include <optional>
#include "d_size.h"
@ -184,6 +185,7 @@ void dLib_show_messages(bool show);
*/
char *dGetcwd(void);
char *dGethomedir(void);
std::optional< std::string > dGetline_string(FILE *stream);
char *dGetline(FILE *stream);
int dClose(int fd);
int dUsleep(unsigned long us);

View File

@ -35,7 +35,7 @@
#include <netdb.h>
#include <fcntl.h>
#include <signal.h>
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "dpiutil.hh"

View File

@ -49,7 +49,7 @@ int main(void)
#include <netdb.h>
#include <signal.h>
#include "dpiutil.hh"
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
/*

View File

@ -18,7 +18,7 @@
#include <ctype.h>
#include <errno.h>
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "dpiutil.hh"
#include "../src/misc.hh"

View File

@ -49,7 +49,7 @@
#include "config.h"
#include "dpiutil.hh"
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
/*
* Debugging macros

View File

@ -20,7 +20,7 @@
#include <stdio.h>
#include "d_size.h"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#ifdef __cplusplus

View File

@ -34,7 +34,7 @@
#include <signal.h>
#include <netinet/in.h>
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "dpiutil.hh"
#include "d_size.h"

View File

@ -41,7 +41,7 @@
#include <sys/time.h>
#include <ctype.h>
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "dpiutil.hh"
#include "d_size.h"

View File

@ -18,7 +18,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "dpiutil.hh"
/*

View File

@ -19,7 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "dpiutil.hh"
/*

View File

@ -14,17 +14,17 @@ dpidc_LDADD = \
EXTRA_DIST = dpidrc.in
dpid_SOURCES = \
dpi.h \
dpi_socket_dir.h \
dpid.h \
dpid_common.h \
misc_new.h \
dpi.hh \
dpi_socket_dir.hh \
dpid.hh \
dpid_common.hh \
misc_new.hh \
dpi.cc \
dpi_socket_dir.c \
dpi_socket_dir.cc \
dpid.cc \
dpid_common.c \
main.c \
misc_new.c
dpid_common.cc \
main.cc \
misc_new.cc
dpidc_SOURCES = dpidc.cc

View File

@ -23,9 +23,9 @@
#include <errno.h>
#include <stdlib.h> /* for exit */
#include "dpid_common.h"
#include "dpi.h"
#include "misc_new.h"
#include "dpid_common.hh"
#include "dpi.hh"
#include "misc_new.hh"
/*! \Return
* Returns path to the dpi_socket_dir file

View File

@ -21,10 +21,10 @@
#include <errno.h>
#include <stdlib.h>
#include "dpid_common.h"
#include "dpi.h"
#include "misc_new.h"
#include "dpi_socket_dir.h" /* for function prototypes */
#include "dpid_common.hh"
#include "dpi.hh"
#include "misc_new.hh"
#include "dpi_socket_dir.hh" /* for function prototypes */
/*! Save socket directory name in ~/.dillo/dpi_socket_dir
* \Return
@ -76,17 +76,18 @@ int tst_dir(char *dir)
*/
char *mk_sockdir(void)
{
char *template, *logname;
char *template_;
const char *logname;
logname = getenv("LOGNAME") ? getenv("LOGNAME") : "flenser";
template = dStrconcat("/tmp/", logname, "-", "XXXXXX", NULL);
if (a_Misc_mkdtemp(template) == NULL) {
template_ = dStrconcat("/tmp/", logname, "-", "XXXXXX", NULL);
if (a_Misc_mkdtemp(template_) == NULL) {
ERRMSG("mk_sockdir", "a_Misc_mkdtemp", 0);
MSG_ERR(" - %s\n", template);
dFree(template);
MSG_ERR(" - %s\n", template_);
dFree(template_);
return (NULL);
}
return template;
return template_;
}
/*! Create socket directory if it does not exist and save its name in

View File

@ -31,13 +31,13 @@
#include <arpa/inet.h>
#include <unistd.h>
#include "dpid_common.h"
#include "dpid.h"
#include "dpi.h"
#include "dpi_socket_dir.h"
#include "misc_new.h"
#include "dpid_common.hh"
#include "dpid.hh"
#include "dpi.hh"
#include "dpi_socket_dir.hh"
#include "misc_new.hh"
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
using namespace std::literals::string_literals;

View File

@ -12,7 +12,7 @@
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include "dpid_common.h"
#include "dpid_common.hh"
/*
* Send a verbose error message.

View File

@ -9,16 +9,17 @@
* the next patch
*/
#ifdef __cplusplus
extern "C"
{
#endif
#include <dirent.h>
#include <stddef.h> /* size_t */
#include <sys/types.h> /* ssize_t */
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#ifdef __cplusplus
extern "C"
{
#endif
/*
* Debugging macros

View File

@ -20,8 +20,8 @@
#include <netdb.h>
#include <errno.h>
#include "../dlib/dlib.h"
#include "../dpip/dpip.h"
#include "../dlib/dlib.hh"
#include "../dpip/dpip.hh"
#define MSG_ERR(...) printf("** ERROR **: " __VA_ARGS__);

View File

@ -24,14 +24,14 @@
#include <assert.h> /* for assert */
#include <sys/stat.h> /* for umask */
#include "dpid_common.h"
#include "dpid.h"
#include "dpi.h"
#include "dpi_socket_dir.h"
#include "misc_new.h"
#include "dpid_common.hh"
#include "dpid.hh"
#include "dpi.hh"
#include "dpi_socket_dir.hh"
#include "misc_new.hh"
#include "../dlib/dlib.h"
#include "../dpip/dpip.h"
#include "../dlib/dlib.hh"
#include "../dpip/dpip.hh"
sigset_t mask_sigchld;

View File

@ -15,9 +15,9 @@
#include <sys/stat.h> /* stat */
#include <stdlib.h> /* rand, srand */
#include "../dlib/dlib.h"
#include "dpid_common.h"
#include "misc_new.h" /* for function prototypes */
#include "../dlib/dlib.hh"
#include "dpid_common.hh"
#include "misc_new.hh" /* for function prototypes */
/*! Reads a dpi tag from a socket
* \li Continues after a signal interrupt
@ -128,30 +128,30 @@ int a_Misc_nohang_rdtag(int socket, int timeout, Dstr **tag)
* Alternative to mkdtemp().
* Not as strong as mkdtemp, but enough for creating a directory.
*/
char *a_Misc_mkdtemp(char *template)
char *a_Misc_mkdtemp(char *template_)
{
for (;;) {
if (a_Misc_mkfname(template) && mkdir(template, 0700) == 0)
if (a_Misc_mkfname(template_) && mkdir(template_, 0700) == 0)
break;
if (errno == EEXIST)
continue;
return 0;
}
return template;
return template_;
}
/**
* Return a new, nonexistent file name from a template.
* (adapted from dietlibc; alternative to mkdtemp())
*/
char *a_Misc_mkfname(char *template)
char *a_Misc_mkfname(char *template_)
{
char *tmp = template + strlen(template) - 6;
char *tmp = template_ + strlen(template_) - 6;
int i;
uint_t random;
struct stat stat_buf;
if (tmp < template)
if (tmp < template_)
goto error;
for (i = 0; i < 6; ++i)
if (tmp[i] != 'X') {
@ -168,10 +168,10 @@ char *a_Misc_mkfname(char *template)
tmp[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
}
if (stat(template, &stat_buf) == -1 && errno == ENOENT)
return template;
if (stat(template_, &stat_buf) == -1 && errno == ENOENT)
return template_;
MSG_ERR("a_Misc_mkfname: another round for %s \n", template);
MSG_ERR("a_Misc_mkfname: another round for %s \n", template_);
}
}

View File

@ -4,5 +4,5 @@ AM_CPPFLAGS = \
noinst_LIBRARIES = libDpip.a
libDpip_a_SOURCES = \
dpip.h \
dpip.c
dpip.hh \
dpip.cc

View File

@ -19,7 +19,7 @@
#include <unistd.h> /* for close */
#include <fcntl.h> /* for fcntl */
#include "dpip.h"
#include "dpip.hh"
#include "d_size.h"
#define RBUF_SZ 16*1024

View File

@ -5,12 +5,12 @@
#ifndef __DPIP_H__
#define __DPIP_H__
#include "../dlib/dlib.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "../dlib/dlib.h"
/*
* Communication mode flags
*/

View File

@ -20,7 +20,7 @@
#include "core.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "../lout/debug.hh"
#include "../lout/msg.h"

View File

@ -19,7 +19,7 @@
#include <stdio.h>
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "../lout/msg.h"
#include "../lout/debug.hh"
#include "fltkcore.hh"

View File

@ -25,7 +25,7 @@
#include "fltkcore.hh"
#include "fltkflatview.hh"
#include "fltkcomplexbutton.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "../lout/msg.h"
#include "../lout/misc.hh"

View File

@ -21,7 +21,7 @@
#include "hyphenator.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "../lout/misc.hh"
#include "../lout/unicode.hh"
#include <limits.h>

View File

@ -22,7 +22,7 @@
//#define DEBUG_LEVEL 1
#include "image.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "../lout/msg.h"
#include "../lout/misc.hh"
#include "../lout/debug.hh"

View File

@ -22,7 +22,7 @@
#include "core.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "../lout/msg.h"
#include "../lout/debug.hh"
#include "../lout/misc.hh"

View File

@ -26,7 +26,7 @@ static_assert( __cplusplus > 2020'02 );
#include <algorithm>
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "core.hh"
#include "../lout/msg.h"

View File

@ -26,7 +26,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
namespace lout {

View File

@ -20,7 +20,7 @@
#include "object.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include <stdio.h>
#include <stdint.h>
#include <config.h>

View File

@ -18,7 +18,7 @@
#include <unistd.h>
#include "../msg.hh"
#include "../chain.hh"
#include "../klist.h"
#include "../klist.hh"
#include "IO.hh"
#include "iowatch.hh"
#include "tls.hh"

View File

@ -4,7 +4,7 @@
#include <string_view>
#include "d_size.h"
#include "../../dlib/dlib.h"
#include "../../dlib/dlib.hh"
#include "../chain.hh"
/*

View File

@ -3,7 +3,7 @@
#include "../chain.hh"
#include "../url.hh"
#include "../../dlib/dlib.h"
#include "../../dlib/dlib.hh"
#ifdef __cplusplus
extern "C" {

View File

@ -36,11 +36,11 @@
#include <netdb.h>
#include "../msg.hh"
#include "../klist.h"
#include "../klist.hh"
#include "IO.hh"
#include "Url.h"
#include "../../dpip/dpip.h"
#include "dlib/dlib.h"
#include "../../dpip/dpip.hh"
#include "dlib/dlib.hh"
/* This one is tricky, some sources state it should include the byte
* for the terminating NULL, and others say it shouldn't. */

View File

@ -32,7 +32,7 @@
#include "tls.hh"
#include "Url.h"
#include "../msg.hh"
#include "../klist.h"
#include "../klist.hh"
#include "../dns.hh"
#include "../web.hh"
#include "../cookies.hh"

View File

@ -14,13 +14,13 @@
#include <config.h>
#include "../cache.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "../cache.hh"
typedef void* (*Viewer_t) (const char*, void*, CA_Callback_t*, void**);
/**

View File

@ -45,9 +45,9 @@
#include <ctype.h> /* tolower for wget stuff */
#include <stdio.h>
#include <errno.h>
#include "../../dlib/dlib.h"
#include "../../dlib/dlib.hh"
#include "../dialog.hh"
#include "../klist.h"
#include "../klist.hh"
#include "iowatch.hh"
#include "tls.hh"
#include "Url.h"

View File

@ -25,12 +25,12 @@
#ifndef __TLS_OPENSSL_H__
#define __TLS_OPENSSL_H__
#include "../url.hh"
#ifdef __cplusplus
extern "C" {
#endif
#include "../url.hh"
const char *a_Tls_openssl_version(char *buf, int n);
void a_Tls_openssl_init(void);
int a_Tls_openssl_certificate_is_clean(const DilloUrl *url);

View File

@ -68,8 +68,8 @@ flenser_SOURCES = \
url.hh \
bitvec.cc \
bitvec.hh \
klist.c \
klist.h \
klist.cc \
klist.hh \
chain.cc \
chain.hh \
utf8.cc \

View File

@ -11,7 +11,7 @@
#include "actions.hh"
#include "msg.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include <errno.h>
static Dlist *link_actions = NULL;

View File

@ -12,12 +12,12 @@
#ifndef ACTIONS_H
#define ACTIONS_H
#include "dlib/dlib.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "dlib/dlib.h"
typedef struct {
char *label;
char *cmd;

View File

@ -23,7 +23,7 @@
#include "misc.hh"
#include "dialog.hh"
#include "digest.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
typedef struct {
int ok;

View File

@ -13,7 +13,7 @@
* A simple ADT for bit arrays
*/
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include "bitvec.hh"
extern "C" {

View File

@ -15,7 +15,7 @@
#include "history.hh"
#include "capi.hh"
#include "bookmark.hh" /* for prototypes */
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"

View File

@ -1,14 +1,15 @@
#ifndef __CACHE_H__
#define __CACHE_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "chain.hh"
#include "url.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* Cache Op codes
*/

View File

@ -31,7 +31,7 @@
#include "dpiapi.hh"
#include "uicmd.hh"
#include "domain.hh"
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
#include "prefs.hh"
/* for testing dpi chat */

View File

@ -15,7 +15,7 @@
#include "msg.hh"
#include "chain.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#define VERBOSE 0

View File

@ -43,7 +43,7 @@ void a_Cookies_init(void)
#include "list.h"
#include "cookies.hh"
#include "capi.hh"
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
/** The maximum length of a line in the cookie file */

View File

@ -10,7 +10,7 @@
*/
#include <stdio.h>
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include "msg.hh"
#include "html_common.hh"
#include "css.hh"

View File

@ -1,7 +1,7 @@
#ifndef __DECODE_H__
#define __DECODE_H__
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#ifdef __cplusplus
extern "C" {

View File

@ -1,13 +1,13 @@
#ifndef __GIF_H__
#define __GIF_H__
#include "url.hh"
#include "image.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "url.hh"
#include "image.hh"
struct DilloGif;
DilloGif *a_Gif_new(DilloImage *Image, DilloUrl *url, int version);

View File

@ -37,7 +37,7 @@
#include "dialog.hh"
#include "misc.hh"
#include "prefs.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
/*
* Local Data

View File

@ -13,7 +13,7 @@
#include "digest.hh"
#include "md5.h"
#include "msg.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include <string_view>

View File

@ -2,7 +2,7 @@
#define __DIGEST_H__
#include "auth.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#ifdef __cplusplus
extern "C" {

View File

@ -1,13 +1,14 @@
#ifndef __JPEG_H__
#define __JPEG_H__
#include "url.hh"
#include "image.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "url.hh"
#include "image.hh"
void *a_Jpeg_new(DilloImage *Image, DilloUrl *url, int version);
void a_Jpeg_callback(int Op, void *data);

View File

@ -12,7 +12,7 @@
#include <vector>
#include <string>
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include "msg.hh"
#include "list.h"
#include "domain.hh"

View File

@ -18,7 +18,7 @@
#include "capi.hh"
#include "dpiapi.hh" /* for prototypes */
#include "dialog.hh"
#include "../dpip/dpip.h"
#include "../dpip/dpip.hh"
//----------------------------------------------------------------------------

View File

@ -1,16 +1,16 @@
#ifndef __PNG_H__
#define __PNG_H__
#include "url.hh"
#include "image.hh"
#include "cache.hh"
#ifdef __cplusplus
extern "C" {
#else
#error PNG header is now C++ only
#endif /* __cplusplus */
#include "url.hh"
#include "image.hh"
#include "cache.hh"
struct DilloPng;
DilloPng *a_Png_new(DilloImage *Image, DilloUrl *url, int version);

View File

@ -1,14 +1,14 @@
#ifndef __SVG_H__
#define __SVG_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "url.hh"
#include "image.hh"
#include "cache.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void *a_Svg_new(DilloImage *Image, DilloUrl *url, int version);
void a_Svg_callback(int Op, CacheClient_t *Client);

View File

@ -1,14 +1,15 @@
#ifndef __WEBP_H__
#define __WEBP_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "url.hh"
#include "image.hh"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void *a_Webp_new(DilloImage *Image, DilloUrl *url, int version);
void a_Webp_callback(int Op, void *data);
const char *a_Webp_version(char *buf, int n);

View File

@ -20,7 +20,7 @@
#include "dw/core.hh"
#include "dw/textblock.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "misc.hh"
#include "msg.hh"
#include "prefs.hh"

View File

@ -31,7 +31,7 @@
#include "hsts.hh"
#include "msg.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include "IO/tls.hh"
#include <string>

View File

@ -16,7 +16,7 @@
#include <string.h>
#include <ctype.h>
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "keys.hh"
#include "utf8.hh"
#include "msg.hh"

View File

@ -18,7 +18,7 @@
* remains with the caller.
*/
#include "klist.h"
#include "klist.hh"
/**

View File

@ -1,7 +1,7 @@
#ifndef __KLIST_H__
#define __KLIST_H__
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#ifdef __cplusplus

View File

@ -14,7 +14,7 @@
#include <sys/stat.h>
#include "msg.hh"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include "paths.hh"
/*

View File

@ -10,7 +10,7 @@
* (at your option) any later version.
*/
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
#include "msg.hh"
#include "prefs.hh"
#include "misc.hh"

View File

@ -27,7 +27,7 @@
#include "prefs.hh"
#include "tipwin.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
/*
* Forward declarations

View File

@ -46,7 +46,7 @@
#include "msg.hh"
#include "prefs.hh"
#include "misc.hh"
#include "dlib/dlib.h"
#include "dlib/dlib.hh"
#include "dw/fltkviewport.hh"

View File

@ -13,7 +13,7 @@
#define __URL_H__
#include "d_size.h"
#include "../dlib/dlib.h"
#include "../dlib/dlib.hh"
extern "C++"
{

View File

@ -11,7 +11,7 @@
#include <FL/fl_utf8.h>
#include "../dlib/dlib.h" /* TRUE/FALSE */
#include "../dlib/dlib.hh" /* TRUE/FALSE */
#include "utf8.hh"
// C++ functions with C linkage ----------------------------------------------