aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/IO/IO.c5
-rw-r--r--src/IO/dpi.c34
-rw-r--r--src/IO/http.c13
-rw-r--r--src/bitvec.h6
-rw-r--r--src/bw.h8
-rw-r--r--src/cache.c2
-rw-r--r--src/cache.h5
-rw-r--r--src/chain.h10
-rw-r--r--src/cookies.c3
-rw-r--r--src/decode.h10
-rw-r--r--src/dialog.cc96
-rw-r--r--src/dialog.hh4
-rw-r--r--src/dicache.c5
-rw-r--r--src/dicache.h8
-rw-r--r--src/dillo.cc4
-rw-r--r--src/dns.c9
-rw-r--r--src/dns.h4
-rw-r--r--src/domain.c2
-rw-r--r--src/dpiapi.c4
-rw-r--r--src/gif.c2
-rw-r--r--src/html.cc2
-rw-r--r--src/html_common.hh11
-rw-r--r--src/jpeg.c10
-rw-r--r--src/klist.h11
-rw-r--r--src/misc.c2
-rw-r--r--src/nav.c12
-rw-r--r--src/png.c3
-rw-r--r--src/prefs.h6
-rw-r--r--src/prefsparser.cc2
-rw-r--r--src/ui.cc6
-rw-r--r--src/uicmd.cc135
-rw-r--r--src/url.h6
32 files changed, 224 insertions, 216 deletions
diff --git a/src/IO/IO.c b/src/IO/IO.c
index 1243c70a..a0a8bba5 100644
--- a/src/IO/IO.c
+++ b/src/IO/IO.c
@@ -125,7 +125,6 @@ static void IO_free(IOData_t *io)
*/
static void IO_close_fd(IOData_t *io, int CloseCode)
{
- int st;
int events = 0;
_MSG("====> begin IO_close_fd (%d) Key=%d CloseCode=%d Flags=%d ",
@@ -135,9 +134,7 @@ static void IO_close_fd(IOData_t *io, int CloseCode)
* closed! (other clients may set 'IOFlag_ForceClose') */
if (((io->Flags & IOFlag_ForceClose) || (CloseCode == IO_StopRdWr)) &&
io->FD != -1) {
- do
- st = close(io->FD);
- while (st < 0 && errno == EINTR);
+ dClose(io->FD);
} else {
_MSG(" NOT CLOSING ");
}
diff --git a/src/IO/dpi.c b/src/IO/dpi.c
index 24f1fce8..8e71f8ca 100644
--- a/src/IO/dpi.c
+++ b/src/IO/dpi.c
@@ -86,19 +86,6 @@ void a_Dpi_init(void)
}
/*
- * Close a FD handling EINTR
- */
-static void Dpi_close_fd(int fd)
-{
- int st;
-
- dReturn_if (fd < 0);
- do
- st = close(fd);
- while (st < 0 && errno == EINTR);
-}
-
-/*
* Create a new connection data structure
*/
static dpi_conn_t *Dpi_conn_new(ChainLink *Info)
@@ -362,7 +349,7 @@ static int Dpi_start_dpid(void)
if (pid == 0) {
/* This is the child process. Execute the command. */
char *path1 = dStrconcat(dGethomedir(), "/.dillo/dpid", NULL);
- Dpi_close_fd(st_pipe[0]);
+ dClose(st_pipe[0]);
if (execl(path1, "dpid", (char*)NULL) == -1) {
dFree(path1);
path1 = dStrconcat(DILLO_BINDIR, "dpid", NULL);
@@ -373,7 +360,7 @@ static int Dpi_start_dpid(void)
if (Dpi_blocking_write(st_pipe[1], "ERROR", 5) == -1) {
MSG("Dpi_start_dpid (child): can't write to pipe.\n");
}
- Dpi_close_fd(st_pipe[1]);
+ dClose(st_pipe[1]);
_exit (EXIT_FAILURE);
}
}
@@ -382,19 +369,18 @@ static int Dpi_start_dpid(void)
/* The fork failed. Report failure. */
MSG("Dpi_start_dpid: %s\n", dStrerror(errno));
/* close the unused pipe */
- Dpi_close_fd(st_pipe[0]);
- Dpi_close_fd(st_pipe[1]);
-
+ dClose(st_pipe[0]);
+ dClose(st_pipe[1]);
} else {
/* This is the parent process, check our child status... */
- Dpi_close_fd(st_pipe[1]);
+ dClose(st_pipe[1]);
if ((answer = Dpi_blocking_read(st_pipe[0])) != NULL) {
MSG("Dpi_start_dpid: can't start dpid\n");
dFree(answer);
} else {
ret = 0;
}
- Dpi_close_fd(st_pipe[0]);
+ dClose(st_pipe[0]);
}
return ret;
@@ -467,7 +453,7 @@ static int Dpi_check_dpid_ids()
} else if (connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) {
MSG("Dpi_check_dpid_ids: %s\n", dStrerror(errno));
} else {
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
ret = 1;
}
}
@@ -603,7 +589,7 @@ static int Dpi_get_server_port(const char *server_name)
dFree(cmd);
}
dFree(rply);
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
return ok ? dpi_port : -1;
}
@@ -648,7 +634,7 @@ static int Dpi_connect_socket(const char *server_name)
}
dFree(cmd);
if (sock_fd != -1 && ret == -1) /* can't send cmd? */
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
return ret;
}
@@ -797,7 +783,7 @@ char *a_Dpi_send_blocking_cmd(const char *server_name, const char *cmd)
} if ((ret = Dpi_blocking_read(sock_fd)) == NULL) {
MSG_ERR("[a_Dpi_send_blocking_cmd] Can't read message.\n");
}
- Dpi_close_fd(sock_fd);
+ dClose(sock_fd);
return ret;
}
diff --git a/src/IO/http.c b/src/IO/http.c
index 3e87f912..bb4bca15 100644
--- a/src/IO/http.c
+++ b/src/IO/http.c
@@ -210,17 +210,6 @@ static void Http_socket_free(int SKey)
}
/*
- * Close the socket's FD
- */
-static void Http_socket_close(SocketData_t *S)
-{
- int st;
- do
- st = close(S->SockFD);
- while (st < 0 && errno == EINTR);
-}
-
-/*
* Make the HTTP header's Referer line according to preferences
* (default is "host" i.e. "scheme://hostname/" )
*/
@@ -448,7 +437,7 @@ static int Http_connect_socket(ChainLink *Info)
status = connect(S->SockFD, (struct sockaddr *)&name, socket_len);
if (status == -1 && errno != EINPROGRESS) {
S->Err = errno;
- Http_socket_close(S);
+ dClose(S->SockFD);
MSG("Http_connect_socket ERROR: %s\n", dStrerror(S->Err));
} else {
a_Chain_bcb(OpSend, Info, &S->SockFD, "FD");
diff --git a/src/bitvec.h b/src/bitvec.h
index f9063070..d2f6d9e1 100644
--- a/src/bitvec.h
+++ b/src/bitvec.h
@@ -6,12 +6,10 @@
#define BVEC_TYPE uchar_t
#define BVEC_SIZE sizeof(BVEC_TYPE)
-typedef struct _bitvec bitvec_t;
-
-struct _bitvec {
+typedef struct {
BVEC_TYPE *vec;
int len; /* number of bits [1 based] */
-};
+} bitvec_t;
/*
diff --git a/src/bw.h b/src/bw.h
index 590af4fb..e07c9c34 100644
--- a/src/bw.h
+++ b/src/bw.h
@@ -11,12 +11,8 @@
#define BW_Force (4) /* Stop connection too */
-typedef struct _BrowserWindow BrowserWindow;
-
-
/* browser_window contains the specific data for a single window */
-struct _BrowserWindow
-{
+typedef struct {
/* Pointer to the UI object this bw belongs to */
void *ui;
@@ -61,7 +57,7 @@ struct _BrowserWindow
/* HTML-bugs detected at parse time */
int num_page_bugs;
Dstr *page_bugs;
-};
+} BrowserWindow;
#ifdef __cplusplus
diff --git a/src/cache.c b/src/cache.c
index 9636d0d8..04c8d356 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -233,7 +233,7 @@ static CacheEntry_t *Cache_entry_search_with_redirect(const DilloUrl *Url)
break;
}
/* Test for a working redirection */
- if (entry && entry->Flags & CA_Redirect && entry->Location) {
+ if (entry->Flags & CA_Redirect && entry->Location) {
Url = entry->Location;
} else
break;
diff --git a/src/cache.h b/src/cache.h
index c01bec55..c39e4600 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -34,16 +34,17 @@ extern "C" {
#define CA_HugeFile 0x1000 /* URL content is too big */
#define CA_IsEmpty 0x2000 /* True until a byte of content arrives */
+typedef struct CacheClient CacheClient_t;
+
/*
* Callback type for cache clients
*/
-typedef struct _CacheClient CacheClient_t;
typedef void (*CA_Callback_t)(int Op, CacheClient_t *Client);
/*
* Data structure for cache clients.
*/
-struct _CacheClient {
+struct CacheClient {
int Key; /* Primary Key for this client */
const DilloUrl *Url; /* Pointer to a cache entry Url */
int Version; /* Dicache version of this Url (0 if not used) */
diff --git a/src/chain.h b/src/chain.h
index fd86557c..10957dc3 100644
--- a/src/chain.h
+++ b/src/chain.h
@@ -29,14 +29,12 @@
#define FWD 1
#define BCK 2
-
-typedef struct _ChainLink ChainLink;
-typedef struct _DataBuf DataBuf;
+typedef struct ChainLink ChainLink;
typedef void (*ChainFunction_t)(int Op, int Branch, int Dir, ChainLink *Info,
void *Data1, void *Data2);
/* This is the main data structure for CCC nodes */
-struct _ChainLink {
+struct ChainLink {
void *LocalKey;
int Flags;
@@ -51,11 +49,11 @@ struct _ChainLink {
};
/* A convenience data structure for passing data chunks between nodes */
-struct _DataBuf {
+typedef struct {
char *Buf;
int Size;
int Code;
-};
+} DataBuf;
diff --git a/src/cookies.c b/src/cookies.c
index 0a1e94ff..deaae2ab 100644
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -90,7 +90,7 @@ static FILE *Cookies_fopen(const char *filename, char *init_str)
filename, dStrerror(errno));
}
}
- close(fd);
+ dClose(fd);
MSG("Cookies: Created file: %s\n", filename);
F_in = fopen(filename, "r");
@@ -260,6 +260,7 @@ static int Cookie_control_init(void)
if (!rc && ferror(stream)) {
MSG("Cookies1: Error while reading rule from cookiesrc: %s\n",
dStrerror(errno));
+ fclose(stream);
return 2; /* bail out */
}
diff --git a/src/decode.h b/src/decode.h
index 064177eb..279807a6 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -7,15 +7,13 @@
extern "C" {
#endif /* __cplusplus */
-typedef struct _Decode Decode;
-
-struct _Decode {
+typedef struct Decode {
char *buffer;
Dstr *leftover;
void *state;
- Dstr *(*decode) (Decode *dc, const char *instr, int inlen);
- void (*free) (Decode *dc);
-};
+ Dstr *(*decode) (struct Decode *dc, const char *instr, int inlen);
+ void (*free) (struct Decode *dc);
+} Decode;
Decode *a_Decode_transfer_init(const char *format);
Decode *a_Decode_content_init(const char *format);
diff --git a/src/dialog.cc b/src/dialog.cc
index 83b9ed8b..484eebc4 100644
--- a/src/dialog.cc
+++ b/src/dialog.cc
@@ -36,7 +36,7 @@
*/
static int input_answer;
static char *input_str = NULL;
-static int choice5_answer;
+static int choice_answer;
/*
@@ -321,54 +321,50 @@ void a_Dialog_text_window(const char *title, const char *txt)
/*--------------------------------------------------------------------------*/
-static void choice5_cb(Fl_Widget *button, void *number)
+static void choice_cb(Fl_Widget *button, void *number)
{
- choice5_answer = VOIDP2INT(number);
- _MSG("choice5_cb: %d\n", choice5_answer);
+ choice_answer = VOIDP2INT(number);
+ _MSG("choice_cb: %d\n", choice_answer);
button->window()->hide();
}
/*
- * Make a question-dialog with a question and up to five alternatives.
- * (if less alternatives, non used parameters must be NULL).
+ * Make a question-dialog with a question and alternatives.
+ * Last parameter must be NULL.
*
- * Return value: 0 = dialog was cancelled, 1-5 = selected alternative.
+ * Return value: 0 = dialog was cancelled, >0 = selected alternative.
*/
-int a_Dialog_choice5(const char *title, const char *msg,
- const char *alt1, const char *alt2, const char *alt3,
- const char *alt4, const char *alt5)
+int a_Dialog_choice(const char *title, const char *msg, ...)
{
- choice5_answer = 0;
+ va_list ap;
+ int i, n;
- int ww = 440, wh = 120, bw = 50, bh = 45, ih = 50, nb = 0;
- const char *txt[7];
-
- if (!(title && *title))
+ if (title == NULL || *title == '\0')
title = "Dillo: Choice";
- if (!msg)
- msg = "";
-
- txt[0] = txt[6] = NULL;
- txt[1] = alt1; txt[2] = alt2; txt[3] = alt3;
- txt[4] = alt4; txt[5] = alt5;
- for (int i=1; txt[i]; ++i, ++nb)
- ;
-
- if (!nb) {
- MSG_ERR("a_Dialog_choice5: No choices.\n");
- return choice5_answer;
+
+ va_start(ap, msg);
+ for (n = 0; va_arg(ap, char *) != NULL; n++);
+ va_end(ap);
+
+ if (n == 0) {
+ MSG_ERR("Dialog_choice: no alternatives.\n");
+ return 0;
}
- ww = 140 + nb*(bw+10);
- Fl_Window *window = new Fl_Window(ww,wh,title);
+ int gap = 8;
+ int ww = 140 + n * 60, wh = 120;
+ int bw = (ww - gap) / n - gap, bh = 45;
+ int ih = 50;
+
+ Fl_Window *window = new Fl_Window(ww, wh, title);
window->set_modal();
window->begin();
- Fl_Group* ib = new Fl_Group(0,0,window->w(),window->h());
+ Fl_Group *ib = new Fl_Group(0, 0, window->w(), window->h());
ib->begin();
window->resizable(ib);
-
+
/* '?' Icon */
- Fl_Box* o = new Fl_Box(10, (wh-bh-ih)/2, ih, ih);
+ Fl_Box *o = new Fl_Box(10, (wh - bh - ih) / 2, ih, ih);
o->box(FL_THIN_UP_BOX);
o->labelfont(FL_TIMES_BOLD);
o->labelsize(34);
@@ -376,36 +372,36 @@ int a_Dialog_choice5(const char *title, const char *msg,
o->labelcolor(FL_BLUE);
o->label("?");
o->show();
-
- Fl_Box *box = new Fl_Box(60,0,ww-60,wh-bh, msg);
- box->labelfont(FL_HELVETICA);
- box->labelsize(14);
- box->align(FL_ALIGN_WRAP);
-
- Fl_Button *b;
- int xpos = 0, gap = 8;
- bw = (ww - gap)/nb - gap;
- xpos += gap;
- for (int i=1; i <= nb; ++i) {
- b = new EnterButton(xpos, wh-bh, bw, bh, txt[i]);
- b->align(FL_ALIGN_WRAP|FL_ALIGN_CLIP);
+
+ if (msg != NULL){
+ Fl_Box *box = new Fl_Box(60, 0, ww - 60, wh - bh, msg);
+ box->labelfont(FL_HELVETICA);
+ box->labelsize(14);
+ box->align(FL_ALIGN_WRAP);
+ }
+
+ int xpos = gap;
+ va_start(ap, msg);
+ for (i = 1; i <= n; i++) {
+ Fl_Button *b = new EnterButton(xpos, wh-bh, bw, bh, va_arg(ap, char *));
+ b->align(FL_ALIGN_WRAP | FL_ALIGN_CLIP);
b->box(FL_UP_BOX);
- b->callback(choice5_cb, INT2VOIDP(i));
+ b->callback(choice_cb, INT2VOIDP(i));
xpos += bw + gap;
/* TODO: set focus to the *-prefixed alternative */
}
+ va_end(ap);
window->end();
window->show();
while (window->shown())
Fl::wait();
- _MSG("a_Dialog_choice5 answer = %d\n", choice5_answer);
+ _MSG("Dialog_choice answer = %d\n", answer);
delete window;
- return choice5_answer;
+ return choice_answer;
}
-
/*--------------------------------------------------------------------------*/
static void Dialog_user_password_cb(Fl_Widget *button, void *)
{
@@ -443,7 +439,7 @@ int a_Dialog_user_password(const char *title, const char *msg,
fl_font(msg_box->labelfont(), msg_box->labelsize());
msg_w -= 6; /* The label doesn't fill the entire box. */
- fl_measure(msg_box->label(), msg_w, msg_h, 0); /* fl_measure wraps at msg_w */
+ fl_measure(msg_box->label(), msg_w, msg_h, 0); // fl_measure wraps at msg_w
msg_box->size(msg_box->w(), msg_h);
window->add(msg_box);
diff --git a/src/dialog.hh b/src/dialog.hh
index 8b3bc1b7..0a489590 100644
--- a/src/dialog.hh
+++ b/src/dialog.hh
@@ -9,9 +9,7 @@ typedef void (*UserPasswordCB)(const char *user, const char *password,
void *vp);
void a_Dialog_msg(const char *title, const char *msg);
-int a_Dialog_choice5(const char *title, const char *msg,
- const char *alt1, const char *alt2, const char *alt3,
- const char *alt4, const char *alt5);
+int a_Dialog_choice(const char *title, const char *msg, ...);
int a_Dialog_user_password(const char *title, const char *msg,
UserPasswordCB cb, void *vp);
const char *a_Dialog_input(const char *title, const char *msg);
diff --git a/src/dicache.c b/src/dicache.c
index e700f000..23721685 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -21,7 +21,6 @@
#include "dgif.h"
#include "djpeg.h"
-typedef struct _DICacheNode DICacheNode;
enum {
DIC_Gif,
@@ -29,11 +28,11 @@ enum {
DIC_Jpeg
};
-struct _DICacheNode {
+typedef struct {
int valid; /* flag */
DilloUrl *url; /* primary "Key" for this dicache entry */
DICacheEntry *first; /* pointer to the first dicache entry in this list */
-};
+} DICacheNode;
/*
* List of DICacheNode. One node per URL. Each node may have several
diff --git a/src/dicache.h b/src/dicache.h
index 70adb6c0..76fdba92 100644
--- a/src/dicache.h
+++ b/src/dicache.h
@@ -24,9 +24,7 @@ typedef enum {
DIC_Abort /* Image transfer aborted */
} DicEntryState;
-typedef struct _DICacheEntry DICacheEntry;
-
-struct _DICacheEntry {
+typedef struct DICacheEntry {
DilloUrl *url; /* Image URL for this entry */
uint_t width, height; /* As taken from image data */
DilloImgType type; /* Image type */
@@ -44,8 +42,8 @@ struct _DICacheEntry {
void *DecoderData; /* Client function data */
uint_t DecodedSize; /* Size of already decoded data */
- DICacheEntry *next; /* Link to the next "newer" version */
-};
+ struct DICacheEntry *next; /* Link to the next "newer" version */
+} DICacheEntry;
void a_Dicache_init (void);
diff --git a/src/dillo.cc b/src/dillo.cc
index 80d0c949..5ad34e78 100644
--- a/src/dillo.cc
+++ b/src/dillo.cc
@@ -272,8 +272,8 @@ static void setColors()
fl_lighter(FL_BACKGROUND_COLOR));
setColorPrefWdef(prefs.ui_tab_active_bg_color, FL_BACKGROUND2_COLOR);
setColorPrefWdef(prefs.ui_tab_bg_color, FL_BACKGROUND_COLOR);
- setColorPrefWdef(prefs.ui_tab_active_fg_color, prefs.ui_fg_color);
- setColorPrefWdef(prefs.ui_tab_fg_color, prefs.ui_fg_color);
+ setColorPrefWdef(prefs.ui_tab_active_fg_color, FL_FOREGROUND_COLOR);
+ setColorPrefWdef(prefs.ui_tab_fg_color, FL_FOREGROUND_COLOR);
}
/*
diff --git a/src/dns.c b/src/dns.c
index 7ae19fe4..e288e8cc 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -217,9 +217,8 @@ void a_Dns_init(void)
/* If the IPv6 address family is not available there is no point
wasting time trying to connect to v6 addresses. */
int fd = socket(AF_INET6, SOCK_STREAM, 0);
- if (fd >= 0) {
- close(fd);
- }
+ if (fd >= 0)
+ dClose(fd);
}
#endif
}
@@ -510,8 +509,8 @@ void a_Dns_freeall(void)
dList_free(dns_cache[i].addr_list);
}
a_IOwatch_remove_fd(dns_notify_pipe[0], DIO_READ);
- close(dns_notify_pipe[0]);
- close(dns_notify_pipe[1]);
+ dClose(dns_notify_pipe[0]);
+ dClose(dns_notify_pipe[1]);
dFree(dns_cache);
}
diff --git a/src/dns.h b/src/dns.h
index 70c0b8dc..61ae6410 100644
--- a/src/dns.h
+++ b/src/dns.h
@@ -20,12 +20,12 @@ void a_Dns_resolve(const char *hostname, DnsCallback_t cb_func, void *cb_data);
# define DILLO_ADDR_MAX sizeof(struct in_addr)
#endif
-typedef struct _DilloHost
-{
+typedef struct {
int af;
int alen;
char data[DILLO_ADDR_MAX];
} DilloHost;
+
void a_Dns_dillohost_to_string(DilloHost *host, char *dst, size_t size);
#ifdef __cplusplus
diff --git a/src/domain.c b/src/domain.c
index 90d6b414..be5d2221 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -14,7 +14,7 @@
#include "list.h"
#include "domain.h"
-typedef struct Rule {
+typedef struct {
char *origin;
char *destination;
} Rule;
diff --git a/src/dpiapi.c b/src/dpiapi.c
index d8980a17..4cdde96e 100644
--- a/src/dpiapi.c
+++ b/src/dpiapi.c
@@ -69,8 +69,8 @@ void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag)
alt4 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt4");
alt5 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt5");
- ret = a_Dialog_choice5(title, msg, alt1, alt2, alt3, alt4, alt5);
- /* As choice5 is modal, call the callback function directly. */
+ ret = a_Dialog_choice(title, msg, alt1, alt2, alt3, alt4, alt5, NULL);
+ /* As choice is modal, call the callback function directly. */
Dpiapi_dialog_answer_cb(bw, ret);
dFree(alt1); dFree(alt2); dFree(alt3); dFree(alt4); dFree(alt5);
diff --git a/src/gif.c b/src/gif.c
index 61407982..554ffa83 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -79,7 +79,7 @@
#define MAX_LWZ_BITS 12
-typedef struct _DilloGif {
+typedef struct {
DilloImage *Image;
DilloUrl *url;
int version;
diff --git a/src/html.cc b/src/html.cc
index 7fa8a7b5..7819edb7 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -1961,8 +1961,6 @@ static void Html_tag_open_abbr(DilloHtml *html, const char *tag, int tagsize)
}
/*
- html->styleEngine->inheritBackgroundColor ();
- html->styleEngine->inheritBackgroundColor ();
* Read image-associated tag attributes and create new image.
*/
void a_Html_image_attrs(DilloHtml *html, const char *tag, int tagsize)
diff --git a/src/html_common.hh b/src/html_common.hh
index a89e1cb5..cdb856db 100644
--- a/src/html_common.hh
+++ b/src/html_common.hh
@@ -39,9 +39,6 @@
* Typedefs
*/
-typedef struct _DilloHtmlImage DilloHtmlImage;
-typedef struct _DilloHtmlState DilloHtmlState;
-
typedef enum {
DT_NONE,
DT_HTML,
@@ -94,12 +91,12 @@ typedef enum {
* Data Structures
*/
-struct _DilloHtmlImage {
+typedef struct {
DilloUrl *url;
DilloImage *image;
-};
+} DilloHtmlImage;
-struct _DilloHtmlState {
+typedef struct {
DilloHtmlParseMode parse_mode;
DilloHtmlTableMode table_mode;
DilloHtmlTableBorderMode table_border_mode;
@@ -120,7 +117,7 @@ struct _DilloHtmlState {
have to be "handed over" (see Html_add_indented and
Html_eventually_pop_dw). */
bool hand_over_break;
-};
+} DilloHtmlState;
/*
* Classes
diff --git a/src/jpeg.c b/src/jpeg.c
index b99d0bc7..c81afe1d 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -46,20 +46,22 @@ typedef enum {
DILLO_JPEG_ERROR
} DilloJpegState;
+typedef struct DilloJpeg DilloJpeg;
+
/* An implementation of a suspending source manager */
typedef struct {
struct jpeg_source_mgr pub; /* public fields */
- struct DilloJpeg *jpeg; /* a pointer back to the jpeg object */
+ DilloJpeg *jpeg; /* a pointer back to the jpeg object */
} my_source_mgr;
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
};
-typedef struct my_error_mgr * my_error_ptr;
+typedef struct my_error_mgr *my_error_ptr;
-typedef struct DilloJpeg {
+struct DilloJpeg {
DilloImage *Image;
DilloUrl *url;
int version;
@@ -74,7 +76,7 @@ typedef struct DilloJpeg {
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
-} DilloJpeg;
+};
/*
* Forward declarations
diff --git a/src/klist.h b/src/klist.h
index 53b2bc31..04e14d33 100644
--- a/src/klist.h
+++ b/src/klist.h
@@ -8,19 +8,16 @@
extern "C" {
#endif /* __cplusplus */
-typedef struct _KlistNode KlistNode_t;
-typedef struct _Klist Klist_t;
-
-struct _KlistNode {
+typedef struct {
int Key; /* primary key */
void *Data; /* data reference */
-};
+} KlistNode_t;
-struct _Klist {
+typedef struct {
Dlist *List;
int Clean; /* check flag */
int Counter; /* counter (for making keys) */
-};
+} Klist_t;
/*
diff --git a/src/misc.c b/src/misc.c
index 0181a125..3e8496e5 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -97,7 +97,7 @@ a_Misc_expand_tabs(char **start, char *end, char *buf, int buflen)
}
/* TODO: could use dStr ADT! */
-typedef struct ContentType_ {
+typedef struct {
const char *str;
int len;
} ContentType_t;
diff --git a/src/nav.c b/src/nav.c
index 2cf51c23..4ccb28be 100644
--- a/src/nav.c
+++ b/src/nav.c
@@ -27,12 +27,10 @@
* For back and forward navigation, each bw keeps an url index,
* and its scroll position.
*/
-typedef struct _nav_stack_item nav_stack_item;
-struct _nav_stack_item
-{
+typedef struct {
int url_idx;
int posx, posy;
-};
+} nav_stack_item;
@@ -487,9 +485,9 @@ static void Nav_reload_callback(void *data)
confirmed = 1;
} else if (URL_FLAGS(h_url) & URL_Post) {
/* Attempt to repost data, let's confirm... */
- choice = a_Dialog_choice5("Dillo: Repost form?",
- "Repost form data?",
- "No", "Yes", "Cancel", NULL, NULL);
+ choice = a_Dialog_choice("Dillo: Repost form?",
+ "Repost form data?",
+ "No", "Yes", "Cancel", NULL);
confirmed = (choice == 2); /* "Yes" */
}
diff --git a/src/png.c b/src/png.c
index 3bf79db7..995725cd 100644
--- a/src/png.c
+++ b/src/png.c
@@ -58,8 +58,7 @@ static char *prog_state_name[] =
* ones for XBM and PNM are.
*/
-typedef
-struct _DilloPng {
+typedef struct {
DilloImage *Image; /* Image meta data */
DilloUrl *url; /* Primary Key for the dicache */
int version; /* Secondary Key for the dicache */
diff --git a/src/prefs.h b/src/prefs.h
index 68bf773a..2b0f15e4 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -26,9 +26,7 @@ extern "C" {
/* Panel sizes */
enum { P_tiny = 0, P_small, P_medium };
-typedef struct _DilloPrefs DilloPrefs;
-
-struct _DilloPrefs {
+typedef struct {
int width;
int height;
int xpos;
@@ -99,7 +97,7 @@ struct _DilloPrefs {
bool_t middle_click_drags_page;
int penalty_hyphen, penalty_hyphen_2;
int penalty_em_dash_left, penalty_em_dash_right, penalty_em_dash_right_2;
-};
+} DilloPrefs;
/* Global Data */
extern DilloPrefs prefs;
diff --git a/src/prefsparser.cc b/src/prefsparser.cc
index 55c5b5e4..74444bd8 100644
--- a/src/prefsparser.cc
+++ b/src/prefsparser.cc
@@ -35,7 +35,7 @@ typedef enum {
PREFS_PANEL_SIZE
} PrefType_t;
-typedef struct SymNode_ {
+typedef struct {
const char *name;
void *pref;
PrefType_t type;
diff --git a/src/ui.cc b/src/ui.cc
index a0ec32a2..9ff4a0a4 100644
--- a/src/ui.cc
+++ b/src/ui.cc
@@ -409,17 +409,17 @@ void UI::make_toolbar(int tw, int th)
if (!icons->ImgLeftIn) {
icons->ImgLeftIn = icons->ImgLeft->copy();
icons->ImgLeftIn->desaturate();
- icons->ImgLeftIn->color_average(FL_BACKGROUND_COLOR, .1f);
+ icons->ImgLeftIn->color_average(FL_BACKGROUND_COLOR, .14f);
}
if (!icons->ImgRightIn) {
icons->ImgRightIn = icons->ImgRight->copy();
icons->ImgRightIn->desaturate();
- icons->ImgRightIn->color_average(FL_BACKGROUND_COLOR, .1f);
+ icons->ImgRightIn->color_average(FL_BACKGROUND_COLOR, .14f);
}
if (!icons->ImgStopIn) {
icons->ImgStopIn = icons->ImgStop->copy();
icons->ImgStopIn->desaturate();
- icons->ImgStopIn->color_average(FL_BACKGROUND_COLOR, .1f);
+ icons->ImgStopIn->color_average(FL_BACKGROUND_COLOR, .14f);
}
Back = make_button("Back", icons->ImgLeft, icons->ImgLeftIn, UI_BACK, 1);
Forw = make_button("Forw", icons->ImgRight, icons->ImgRightIn, UI_FORW);
diff --git a/src/uicmd.cc b/src/uicmd.cc
index 54efa7a4..be2359da 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -18,6 +18,7 @@
#include <stdlib.h> /* for qsort */
#include <math.h> /* for rint */
#include <limits.h> /* for UINT_MAX */
+#include <sys/stat.h>
#include <FL/Fl.H>
#include <FL/Fl_Widget.H>
@@ -502,9 +503,9 @@ static void win_cb (Fl_Widget *w, void *cb_data) {
}
if (prefs.show_quit_dialog && ntabs > 1)
- choice = a_Dialog_choice5("Dillo: Close window?",
- "Window contains more than one tab.",
- "Close", "Cancel", NULL, NULL, NULL);
+ choice = a_Dialog_choice("Dillo: Close window?",
+ "Window contains more than one tab.",
+ "Close", "Cancel", NULL);
if (choice == 1)
while (ntabs-- > 0)
a_UIcmd_close_bw(a_UIcmd_get_bw_by_widget(tabs->wizard()->value()));
@@ -643,9 +644,9 @@ void a_UIcmd_close_all_bw(void *)
int choice = 1;
if (prefs.show_quit_dialog && a_Bw_num() > 1)
- choice = a_Dialog_choice5("Dillo: Quit?",
- "More than one open tab or window.",
- "Quit", "Cancel", NULL, NULL, NULL);
+ choice = a_Dialog_choice("Dillo: Quit?",
+ "More than one open tab or window.",
+ "Quit", "Cancel", NULL);
if (choice == 1)
while ((bw = a_Bw_get(0)))
a_UIcmd_close_bw((void*)bw);
@@ -813,30 +814,51 @@ void a_UIcmd_redirection0(void *vbw, const DilloUrl *url)
/*
* Return a suitable filename for a given URL path.
*/
-static char *UIcmd_make_save_filename(const char *pathstr)
+static char *UIcmd_make_save_filename(const DilloUrl *url)
{
size_t MaxLen = 64;
- char *FileName, *newname, *o, *n;
- const char *name, *dir = save_dir;
+ const char *dir = save_dir, *path, *path2, *query;
+ char *name, *free1, *free2, *n1, *n2;
- if ((name = strrchr(pathstr, '/'))) {
- if (strlen(++name) > MaxLen) {
- name = name + strlen(name) - MaxLen;
- }
- /* Replace %20 and ' ' with '_' in Filename */
- o = n = newname = dStrdup(name);
- for (int i = 0; o[i]; i++) {
- *n++ = (o[i] == ' ') ? '_' :
- (o[i] == '%' && o[i+1] == '2' && o[i+2] == '0') ?
- i+=2, '_' : o[i];
+ free1 = free2 = NULL;
+
+ /* get the last component of the path */
+ path = URL_PATH(url);
+ path2 = strrchr(path, '/');
+ path = path2 ? path2 + 1 : path;
+
+ /* truncate the path if necessary */
+ if (strlen(path) > MaxLen) {
+ path = free1 = dStrndup(path, MaxLen);
+ }
+
+ /* is there a query? */
+ query = URL_QUERY(url);
+ if (*query) {
+ /* truncate the query if necessary */
+ if (strlen(query) > MaxLen) {
+ query = free2 = dStrndup(query, MaxLen);
}
- *n = 0;
- FileName = dStrconcat(dir, newname, NULL);
- dFree(newname);
+ name = dStrconcat(dir, path, "?", query, NULL);
} else {
- FileName = dStrconcat(dir, pathstr, NULL);
+ name = dStrconcat(dir, path, NULL);
}
- return FileName;
+
+ dFree(free1);
+ dFree(free2);
+
+ /* Replace %20 and ' ' with '_' */
+ for (n1 = n2 = name; *n1; n1++, n2++) {
+ *n2 =
+ (n1[0] == ' ')
+ ? '_' :
+ (n1[0] == '%' && n1[1] == '2' && n1[2] == '0')
+ ? (n1 += 2, '_') :
+ n1[0];
+ }
+ *n2 = 0;
+
+ return name;
}
/*
@@ -856,19 +878,64 @@ void a_UIcmd_init(void)
}
/*
+ * Check a file to save to.
+ */
+static int UIcmd_save_file_check(const char *name)
+{
+ struct stat ss;
+ if (stat(name, &ss) == 0) {
+ Dstr *ds;
+ int ch;
+ ds = dStr_sized_new(128);
+ dStr_sprintf(ds,
+ "The file:\n %s (%d Bytes)\nalready exists. What do we do?",
+ name, (int)ss.st_size);
+ ch = a_Dialog_choice("Dillo Save: File exists!", ds->str,
+ "Abort", "Continue", "Rename", NULL);
+ dStr_free(ds, 1);
+ return ch;
+ } else {
+ return 2; /* assume the file does not exist, so Continue */
+ }
+}
+
+/*
* Save a URL
*/
static void UIcmd_save(BrowserWindow *bw, const DilloUrl *url,
- const char *title, const char *url_str)
+ const char *title)
{
- char *SuggestedName;
const char *name;
- SuggestedName = UIcmd_make_save_filename(url_str);
- name = a_Dialog_save_file(title, NULL, SuggestedName);
- dFree(SuggestedName);
- if (name) {
- MSG("UIcmd_save: %s\n", name);
- a_Nav_save_url(bw, url, name);
+ bool_t first_prompt = 1;
+ while (1) {
+ char *SuggestedName;
+
+ SuggestedName =
+ first_prompt
+ ? UIcmd_make_save_filename(url)
+ : dStrdup(name);
+ first_prompt = 0;
+ name = a_Dialog_save_file(title, NULL, SuggestedName);
+ dFree(SuggestedName);
+
+ if (name) {
+ switch (UIcmd_save_file_check(name)) {
+ case 0:
+ case 1:
+ /* Abort */
+ return;
+ case 2:
+ /* Continue */
+ MSG("UIcmd_save: %s\n", name);
+ a_Nav_save_url(bw, url, name);
+ return;
+ default:
+ /* Rename */
+ break; /* prompt again */
+ }
+ } else {
+ return; /* no name, so Abort */
+ }
}
}
@@ -881,7 +948,7 @@ void a_UIcmd_save(void *vbw)
const DilloUrl *url = a_History_get_url(NAV_TOP_UIDX(bw));
if (url) {
- UIcmd_save(bw, url, "Save Page as File", URL_PATH(url));
+ UIcmd_save(bw, url, "Save Page as File");
}
}
@@ -1002,7 +1069,7 @@ const char *a_UIcmd_get_passwd(const char *user)
*/
void a_UIcmd_save_link(BrowserWindow *bw, const DilloUrl *url)
{
- UIcmd_save(bw, url, "Dillo: Save Link as File", URL_STR(url));
+ UIcmd_save(bw, url, "Dillo: Save Link as File");
}
/*
diff --git a/src/url.h b/src/url.h
index c5f70615..bb20d789 100644
--- a/src/url.h
+++ b/src/url.h
@@ -84,13 +84,11 @@
#define URL_ILLEGAL_CHARS_SPC(u) URL_ILLEGAL_CHARS_SPC_(u)
-typedef struct _DilloUrl DilloUrl;
-
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
-struct _DilloUrl {
+typedef struct {
Dstr *url_string;
const char *buffer;
const char *scheme; /**/
@@ -106,7 +104,7 @@ struct _DilloUrl {
int ismap_url_len; /* Used by server side image maps */
int illegal_chars; /* number of illegal chars */
int illegal_chars_spc; /* number of illegal space chars */
-};
+} DilloUrl;
DilloUrl* a_Url_new(const char *url_str, const char *base_url);