114 lines
2.0 KiB
C
114 lines
2.0 KiB
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "gemlib.h"
|
|
|
|
#define VERSION_MAJ 0
|
|
#define VERSION_MIN 1
|
|
#define VERSION_REV 0
|
|
#define NAME "gemcurl"
|
|
|
|
void printName (char *extra);
|
|
void printVersion (void);
|
|
void printLicence (void);
|
|
void printUsage (char *command);
|
|
void printHelp(void);
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
GEM_Request *request;
|
|
|
|
if (argc < 2)
|
|
{
|
|
printUsage(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
if (strcmp(argv[1], "-v") == 0 | strcmp(argv[1], "--version") == 0)
|
|
{
|
|
printName(NULL);
|
|
printVersion();
|
|
printLicence();
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
if (strcmp(argv[1], "-h") == 0 | strcmp(argv[1], "--help") == 0)
|
|
{
|
|
printName("A dead simple Gemini client");
|
|
printVersion();
|
|
printf("\n");
|
|
printUsage(argv[0]);
|
|
printHelp();
|
|
printf("\n");
|
|
printLicence();
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
if (strcmp(argv[1], "-g") == 0 | strcmp(argv[1], "--get") == 0)
|
|
{
|
|
if (argc < 3)
|
|
{
|
|
printUsage(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
request = GEM_new_request(argv[2]);
|
|
|
|
#ifdef DEBUG
|
|
GEM_print_request_info(request);
|
|
#endif
|
|
|
|
if (GEM_send_request(request, stdout) != 0)
|
|
return EXIT_FAILURE;
|
|
|
|
GEM_free_request(request);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
printUsage(argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
void printName (char *extra)
|
|
{
|
|
if (extra == NULL)
|
|
printf("%s\n", NAME);
|
|
else
|
|
printf("%s : %s\n", NAME, extra);
|
|
}
|
|
|
|
void printVersion (void)
|
|
{
|
|
if (VERSION_MIN == 0 && VERSION_REV == 0)
|
|
printf("Version : %d\n", VERSION_MAJ);
|
|
else if (VERSION_REV == 0)
|
|
printf("Version : %d.%d\n", VERSION_MAJ, VERSION_MIN);
|
|
else
|
|
printf("Version : %d.%d.%d\n", VERSION_MAJ, VERSION_MIN, VERSION_REV);
|
|
}
|
|
|
|
void printLicence (void)
|
|
{
|
|
printf("Written by Romain de Laage, Licence GPLv3\n");
|
|
}
|
|
|
|
void printUsage (char *command)
|
|
{
|
|
if (command == NULL)
|
|
printf("Usage : gemcurl CMD [URL]\n");
|
|
else
|
|
printf("Usage : %s CMD [URL]\n", command);
|
|
}
|
|
|
|
void printHelp (void)
|
|
{
|
|
printf("CMD :\n\t-h | --help : Show this help\n\t-v | --version : Show version\n\t-g | --get : Get a gemini content, must be followed by the URL\n");
|
|
}
|