<commit_before>/* See LICENSE file for copyright and license details.
 *
 * To understand surf, start reading main().
 */
#include <X11/X.h>
#include <X11/Xatom.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <webkit/webkit.h>

#define LENGTH(x) (sizeof x / sizeof x[0])

Display *dpy;
Atom urlprop;
typedef struct Client {
	GtkWidget *win, *scroll, *vbox, *urlbar, *urllist, *searchbar;
	WebKitWebView *view;
	gchar *title;
	gint progress;
	struct Client *next;
} Client;
Client *clients = NULL;
gboolean embed = FALSE;
gboolean showxid = FALSE;
gboolean ignore_once = FALSE;
extern char *optarg;
extern int optind;

static void cleanup(void);
static gboolean decidewindow(WebKitWebView *view, WebKitWebFrame *f,
		WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
		WebKitWebPolicyDecision *p, gpointer d);
static void destroyclient(Client *c);
static void destroywin(GtkWidget* w, gpointer d);
static void die(char *str);
static gboolean download(WebKitWebView *view, GObject *o, gpointer d);
static gchar *geturi(Client *c);
static void hidesearch(Client *c);
static void hideurl(Client *c);
static gboolean keypress(GtkWidget* w, GdkEventKey *ev, gpointer d);
static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, gpointer d);
static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
static void loadfile(const Client *c, const gchar *f);
static void loaduri(const Client *c, const gchar *uri);
static Client *newclient();
static WebKitWebView *newwindow(WebKitWebView  *v, WebKitWebFrame *f, gpointer d);
static void progresschange(WebKitWebView *view, gint p, gpointer d);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer data);
static void setup(void);
static void showsearch(Client *c);
static void showurl(Client *c);
static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, gpointer d);
static void updatetitle(Client *c);

void
cleanup(void) {
	while(clients)
		destroyclient(clients);
}

gboolean
decidewindow(WebKitWebView *view, WebKitWebFrame *f,
		WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
		WebKitWebPolicyDecision *p, gpointer d) {
	/* TODO */
	return TRUE;
}

void
destroyclient(Client *c) {
	Client *p;

	gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
	gtk_widget_destroy(c->scroll);
	gtk_widget_destroy(c->urlbar);
	gtk_widget_destroy(c->urllist);
	gtk_widget_destroy(c->searchbar);
	gtk_widget_destroy(c->vbox);
	gtk_widget_destroy(c->win);
	for(p = clients; p && p->next != c; p = p->next);
	if(p)
		p->next = c->next;
	else
		clients = c->next;
	free(c);
	if(clients == NULL)
		gtk_main_quit();
}

void
destroywin(GtkWidget* w, gpointer d) {
	Client *c = (Client *)d;

	destroyclient(c);
}

void die(char *str) {
	fputs(str, stderr);
	exit(EXIT_FAILURE);
}

gboolean
download(WebKitWebView *view, GObject *o, gpointer d) {
	/* TODO */
	return FALSE;
}<commit_msg>added spaceinvaders downloading support, thanks :)<commit_after>/* See LICENSE file for copyright and license details.
 *
 * To understand surf, start reading main().
 */
#include <X11/X.h>
#include <X11/Xatom.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
#include <webkit/webkit.h>

#define LENGTH(x) (sizeof x / sizeof x[0])

Display *dpy;
Atom urlprop;
typedef struct Client {
	GtkWidget *win, *scroll, *vbox, *urlbar, *urllist, *searchbar;
	WebKitWebView *view;
	gchar *title;
	gint progress;
	struct Client *next;
} Client;
Client *clients = NULL;
gboolean embed = FALSE;
gboolean showxid = FALSE;
gboolean ignore_once = FALSE;
extern char *optarg;
extern int optind;

static void cleanup(void);
static gboolean decidewindow(WebKitWebView *view, WebKitWebFrame *f,
		WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
		WebKitWebPolicyDecision *p, gpointer d);
static void destroyclient(Client *c);
static void destroywin(GtkWidget* w, gpointer d);
static void die(char *str);
static gboolean download(WebKitWebView *view, WebKitDownload *o, gpointer d);
static gchar *geturi(Client *c);
static void hidesearch(Client *c);
static void hideurl(Client *c);
static gboolean keypress(GtkWidget* w, GdkEventKey *ev, gpointer d);
static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, gpointer d);
static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
static void loadfile(const Client *c, const gchar *f);
static void loaduri(const Client *c, const gchar *uri);
static Client *newclient();
static WebKitWebView *newwindow(WebKitWebView  *v, WebKitWebFrame *f, gpointer d);
static void progresschange(WebKitWebView *view, gint p, gpointer d);
static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer data);
static void setup(void);
static void showsearch(Client *c);
static void showurl(Client *c);
static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, gpointer d);
static void updatetitle(Client *c);

void
cleanup(void) {
	while(clients)
		destroyclient(clients);
}

gboolean
decidewindow(WebKitWebView *view, WebKitWebFrame *f,
		WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
		WebKitWebPolicyDecision *p, gpointer d) {
	/* TODO */
	return TRUE;
}

void
destroyclient(Client *c) {
	Client *p;

	gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
	gtk_widget_destroy(c->scroll);
	gtk_widget_destroy(c->urlbar);
	gtk_widget_destroy(c->urllist);
	gtk_widget_destroy(c->searchbar);
	gtk_widget_destroy(c->vbox);
	gtk_widget_destroy(c->win);
	for(p = clients; p && p->next != c; p = p->next);
	if(p)
		p->next = c->next;
	else
		clients = c->next;
	free(c);
	if(clients == NULL)
		gtk_main_quit();
}

void
destroywin(GtkWidget* w, gpointer d) {
	Client *c = (Client *)d;

	destroyclient(c);
}

void die(char *str) {
	fputs(str, stderr);
	exit(EXIT_FAILURE);
}

gboolean
download(WebKitWebView *view, WebKitDownload *o, gpointer d) {
	/* TODO */
	const gchar *home;
	gchar *uri, *filename;

	home = g_get_home_dir();
	filename = g_build_filename(home, "Desktop", 
			webkit_download_get_suggested_filename(o), NULL);
	uri = g_strconcat("file://", filename, NULL);
	webkit_download_set_destination_uri(o, uri);
	g_free(filename);
	g_free(uri);
	webkit_download_start(o);
	return TRUE;
}
{'fraction_non_alphanumeric': 0.12903225806451613, 'fraction_numerical': 0.0015360983102918587, 'mean_word_length': 6.023732470334412, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1279004', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2352, 'n_words': 647}