Can make requests
This commit is contained in:
parent
52cac2c063
commit
2dfbf78259
6
Makefile
6
Makefile
|
@ -9,17 +9,17 @@ all: debug
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
mkdir -p build/debug
|
mkdir -p build/debug
|
||||||
$(CC) -o $(BUILD_DIR)/debug/$(BUILD_NAME)-$(OS) $(CFLAGS) src/*
|
$(CC) -o $(BUILD_DIR)/debug/$(BUILD_NAME)-$(OS) $(CFLAGS) -Iinclude -lcrypto -lssl src/* lib/gemini.c
|
||||||
|
|
||||||
test: testgemparse testurllib
|
test: testgemparse testurllib
|
||||||
|
|
||||||
testgemparse:
|
testgemparse:
|
||||||
mkdir -p $(BUILD_DIR)/test
|
mkdir -p $(BUILD_DIR)/test
|
||||||
$(CC) -o $(BUILD_DIR)/test/gemparse-$(OS) -D TESTGEMPARSE src/gemparse.c
|
$(CC) -o $(BUILD_DIR)/test/gemparse-$(OS) -D TESTGEMPARSE -Iinclude src/gemparse.c
|
||||||
|
|
||||||
testurllib:
|
testurllib:
|
||||||
mkdir -p $(BUILD_DIR)/test
|
mkdir -p $(BUILD_DIR)/test
|
||||||
$(CC) -o $(BUILD_DIR)/test/urllib-$(OS) -D TESTURLLIB lib/url.c
|
$(CC) -o $(BUILD_DIR)/test/urllib-$(OS) -D TESTURLLIB -Iinclude lib/url.c
|
||||||
|
|
||||||
testgemini:
|
testgemini:
|
||||||
mkdir -p $(BUILD_DIR)/test
|
mkdir -p $(BUILD_DIR)/test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#ifndef _GEMPARSE_H
|
#ifndef _GEMPARSE_H
|
||||||
#define _GEMPARSE_H
|
#define _GEMPARSE_H
|
||||||
|
|
||||||
int parseFile (const char *path);
|
int parseFile (FILE *fileToParse);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "../include/gemgui.h"
|
|
||||||
|
#include <gemgui.h>
|
||||||
|
|
||||||
void linkAction (GtkWidget *widget, gpointer data);
|
void linkAction (GtkWidget *widget, gpointer data);
|
||||||
extern char links[1024][20];
|
extern char links[1024][20];
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef TESTGEMPARSE
|
#ifndef TESTGEMPARSE
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "../include/gemgui.h"
|
|
||||||
|
#include <gemgui.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TESTGEMPARSE
|
#ifdef TESTGEMPARSE
|
||||||
|
@ -19,7 +21,7 @@ void addUList (const char *text);
|
||||||
|
|
||||||
// general functions
|
// general functions
|
||||||
|
|
||||||
int parseFile (const char *path);
|
int parseFile (FILE *fileToParse);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -29,14 +31,15 @@ extern char links[1024][20];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
parseFile (const char *path)
|
parseFile (FILE *fileToParse)
|
||||||
{
|
{
|
||||||
FILE *fileToParse = fopen (path, "r");
|
|
||||||
char line[4096];
|
char line[4096];
|
||||||
#ifndef TESTGEMPARSE
|
#ifndef TESTGEMPARSE
|
||||||
int linkNumber = 0;
|
int linkNumber = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
rewind (fileToParse);
|
||||||
|
|
||||||
if (fileToParse == NULL)
|
if (fileToParse == NULL)
|
||||||
{
|
{
|
||||||
#ifdef TESTGEMPARSE
|
#ifdef TESTGEMPARSE
|
||||||
|
@ -44,7 +47,6 @@ parseFile (const char *path)
|
||||||
#else
|
#else
|
||||||
addH1 (render, "An error occured");
|
addH1 (render, "An error occured");
|
||||||
addText (render, "Can't open the file");
|
addText (render, "Can't open the file");
|
||||||
addCode (render, path, NULL);
|
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -260,8 +262,6 @@ parseFile (const char *path)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (fileToParse);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,13 @@ main (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
if (argc >= 2)
|
if (argc >= 2)
|
||||||
return parseFile (argv[1]);
|
{
|
||||||
|
FILE *file = fopen (argv[1], "r");
|
||||||
|
if (file == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return parseFile (file);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf (stderr, "USAGE: %s FILE\n", argv[0]);
|
fprintf (stderr, "USAGE: %s FILE\n", argv[0]);
|
||||||
|
|
30
src/main.c
30
src/main.c
|
@ -1,19 +1,28 @@
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "../include/gemgui.h"
|
|
||||||
#include "../include/gemparse.h"
|
#include <gemgui.h>
|
||||||
|
#include <gemparse.h>
|
||||||
|
#include <gemini.h>
|
||||||
|
|
||||||
GtkEntryBuffer *pathBarContent = NULL;
|
GtkEntryBuffer *pathBarContent = NULL;
|
||||||
GtkWidget *render = NULL;
|
GtkWidget *render = NULL;
|
||||||
GtkWidget *scrollbar = NULL;
|
GtkWidget *scrollbar = NULL;
|
||||||
char links[1024][20];
|
char links[1024][20];
|
||||||
|
|
||||||
static void makeRender (const char *path);
|
static void makeRender (FILE *file);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
loadPage (const char *link)
|
loadPage (const char *link)
|
||||||
{
|
{
|
||||||
makeRender (link);
|
FILE *file = tmpfile ();
|
||||||
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL);
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
GEM_send_request ("gemini://rdelaage.ovh\r\n", "rdelaage.ovh:1965", file);
|
||||||
|
makeRender (file);
|
||||||
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL);
|
||||||
|
|
||||||
|
fclose (file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -31,7 +40,7 @@ goAction (GtkWidget *widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
makeRender (const char *path)
|
makeRender (FILE *file)
|
||||||
{
|
{
|
||||||
if (render == NULL)
|
if (render == NULL)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +50,7 @@ makeRender (const char *path)
|
||||||
else
|
else
|
||||||
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_destroy, NULL);
|
||||||
|
|
||||||
parseFile (path);
|
parseFile (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function's goal is to build the main interface */
|
/* This function's goal is to build the main interface */
|
||||||
|
@ -53,6 +62,7 @@ build_interface (GtkWidget *window,
|
||||||
GtkWidget *headerBar;
|
GtkWidget *headerBar;
|
||||||
GtkWidget *goButtonBox;
|
GtkWidget *goButtonBox;
|
||||||
GtkWidget *goButton;
|
GtkWidget *goButton;
|
||||||
|
FILE *file = fopen (path, "r");
|
||||||
|
|
||||||
/* Building title bar */
|
/* Building title bar */
|
||||||
scrollbar = gtk_scrolled_window_new (NULL, NULL);
|
scrollbar = gtk_scrolled_window_new (NULL, NULL);
|
||||||
|
@ -70,7 +80,11 @@ build_interface (GtkWidget *window,
|
||||||
gtk_container_add (GTK_CONTAINER (headerBar), pathBar);
|
gtk_container_add (GTK_CONTAINER (headerBar), pathBar);
|
||||||
gtk_container_add (GTK_CONTAINER (headerBar), goButtonBox);
|
gtk_container_add (GTK_CONTAINER (headerBar), goButtonBox);
|
||||||
|
|
||||||
makeRender (path);
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
makeRender (file);
|
||||||
|
fclose (file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function's goal is to create the window then show it */
|
/* This function's goal is to create the window then show it */
|
||||||
|
|
Loading…
Reference in New Issue