Can make requests

This commit is contained in:
Romain de Laage 2021-02-18 15:03:21 +01:00
parent 52cac2c063
commit 2dfbf78259
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
5 changed files with 42 additions and 21 deletions

View File

@ -9,17 +9,17 @@ all: debug
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
testgemparse:
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:
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:
mkdir -p $(BUILD_DIR)/test

View File

@ -1,6 +1,6 @@
#ifndef _GEMPARSE_H
#define _GEMPARSE_H
int parseFile (const char *path);
int parseFile (FILE *fileToParse);
#endif

View File

@ -1,5 +1,6 @@
#include <gtk/gtk.h>
#include "../include/gemgui.h"
#include <gemgui.h>
void linkAction (GtkWidget *widget, gpointer data);
extern char links[1024][20];

View File

@ -1,8 +1,10 @@
#include <stdio.h>
#include <string.h>
#ifndef TESTGEMPARSE
#include <gtk/gtk.h>
#include "../include/gemgui.h"
#include <gemgui.h>
#endif
#ifdef TESTGEMPARSE
@ -19,7 +21,7 @@ void addUList (const char *text);
// general functions
int parseFile (const char *path);
int parseFile (FILE *fileToParse);
#else
@ -29,14 +31,15 @@ extern char links[1024][20];
#endif
int
parseFile (const char *path)
parseFile (FILE *fileToParse)
{
FILE *fileToParse = fopen (path, "r");
char line[4096];
#ifndef TESTGEMPARSE
int linkNumber = 0;
#endif
rewind (fileToParse);
if (fileToParse == NULL)
{
#ifdef TESTGEMPARSE
@ -44,7 +47,6 @@ parseFile (const char *path)
#else
addH1 (render, "An error occured");
addText (render, "Can't open the file");
addCode (render, path, NULL);
#endif
return 1;
}
@ -260,8 +262,6 @@ parseFile (const char *path)
#endif
}
fclose (fileToParse);
return 0;
}
@ -272,7 +272,13 @@ main (int argc,
char **argv)
{
if (argc >= 2)
return parseFile (argv[1]);
{
FILE *file = fopen (argv[1], "r");
if (file == NULL)
return 1;
return parseFile (file);
}
else
{
fprintf (stderr, "USAGE: %s FILE\n", argv[0]);

View File

@ -1,19 +1,28 @@
#include <gtk/gtk.h>
#include "../include/gemgui.h"
#include "../include/gemparse.h"
#include <gemgui.h>
#include <gemparse.h>
#include <gemini.h>
GtkEntryBuffer *pathBarContent = NULL;
GtkWidget *render = NULL;
GtkWidget *scrollbar = NULL;
char links[1024][20];
static void makeRender (const char *path);
static void makeRender (FILE *file);
static void
loadPage (const char *link)
{
makeRender (link);
gtk_container_foreach (GTK_CONTAINER (render), (GtkCallback)gtk_widget_show_all, NULL);
FILE *file = tmpfile ();
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
@ -31,7 +40,7 @@ goAction (GtkWidget *widget,
}
static void
makeRender (const char *path)
makeRender (FILE *file)
{
if (render == NULL)
{
@ -41,7 +50,7 @@ makeRender (const char *path)
else
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 */
@ -53,6 +62,7 @@ build_interface (GtkWidget *window,
GtkWidget *headerBar;
GtkWidget *goButtonBox;
GtkWidget *goButton;
FILE *file = fopen (path, "r");
/* Building title bar */
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), goButtonBox);
makeRender (path);
if (file != NULL)
{
makeRender (file);
fclose (file);
}
}
/* This function's goal is to create the window then show it */