* Bail out with an error if the requested export format is unsupported.pull/1/head
@@ -5,6 +5,7 @@ toilet_SOURCES = main.c toilet.h \ | |||||
io.c io.h \ | io.c io.h \ | ||||
render.c render.h \ | render.c render.h \ | ||||
filter.c filter.h \ | filter.c filter.h \ | ||||
export.c export.h \ | |||||
term.c figlet.c | term.c figlet.c | ||||
toilet_CFLAGS = `pkg-config --cflags cucul` | toilet_CFLAGS = `pkg-config --cflags cucul` | ||||
toilet_LDFLAGS = `pkg-config --libs cucul` @GETOPT_LIBS@ @ZLIB_LIBS@ | toilet_LDFLAGS = `pkg-config --libs cucul` @GETOPT_LIBS@ @ZLIB_LIBS@ | ||||
@@ -0,0 +1,58 @@ | |||||
/* | |||||
* TOIlet The Other Implementation’s letters | |||||
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the Do What The Fuck You Want To | |||||
* Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* This file contains export functions. | |||||
*/ | |||||
#include "config.h" | |||||
#if defined(HAVE_INTTYPES_H) | |||||
# include <inttypes.h> | |||||
#endif | |||||
#include <string.h> | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <cucul.h> | |||||
#include "toilet.h" | |||||
#include "export.h" | |||||
int export_list(void) | |||||
{ | |||||
char const * const * exports, * const * p; | |||||
printf("Available export formats:\n"); | |||||
exports = cucul_get_export_list(); | |||||
for(p = exports; *p; p += 2) | |||||
printf("\"%s\": %s\n", *p, *(p + 1)); | |||||
return 0; | |||||
} | |||||
int export_set(context_t *cx, char const *format) | |||||
{ | |||||
char const * const * exports, * const * p; | |||||
cx->export = format; | |||||
exports = cucul_get_export_list(); | |||||
for(p = exports; *p; p += 2) | |||||
if(!strcmp(*p, format)) | |||||
return 0; | |||||
fprintf(stderr, "unknown export format `%s'\n", format); | |||||
return -1; | |||||
} | |||||
@@ -0,0 +1,20 @@ | |||||
/* | |||||
* TOIlet The Other Implementation’s letters | |||||
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This program is free software; you can redistribute it and/or | |||||
* modify it under the terms of the Do What The Fuck You Want To | |||||
* Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* This header defines export functions. | |||||
*/ | |||||
extern int export_list(void); | |||||
extern int export_set(context_t *, char const *); | |||||
@@ -34,12 +34,12 @@ | |||||
#include "toilet.h" | #include "toilet.h" | ||||
#include "render.h" | #include "render.h" | ||||
#include "filter.h" | #include "filter.h" | ||||
#include "export.h" | |||||
static void version(void); | static void version(void); | ||||
#if defined(HAVE_GETOPT_H) | #if defined(HAVE_GETOPT_H) | ||||
static void usage(void); | static void usage(void); | ||||
#endif | #endif | ||||
static int export_list(void); | |||||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||||
{ | { | ||||
@@ -138,13 +138,14 @@ int main(int argc, char *argv[]) | |||||
case 'E': /* --export */ | case 'E': /* --export */ | ||||
if(!strcmp(optarg, "list")) | if(!strcmp(optarg, "list")) | ||||
return export_list(); | return export_list(); | ||||
cx->export = optarg; | |||||
if(export_set(cx, optarg) < 0) | |||||
return -1; | |||||
break; | break; | ||||
case 140: /* --irc */ | case 140: /* --irc */ | ||||
cx->export = "irc"; | |||||
export_set(cx, "irc"); | |||||
break; | break; | ||||
case 141: /* --html */ | case 141: /* --html */ | ||||
cx->export = "html"; | |||||
export_set(cx, "html"); | |||||
break; | break; | ||||
case '?': | case '?': | ||||
printf(MOREINFO, argv[0]); | printf(MOREINFO, argv[0]); | ||||
@@ -260,16 +261,3 @@ static void usage(void) | |||||
} | } | ||||
#endif | #endif | ||||
static int export_list(void) | |||||
{ | |||||
char const * const * exports, * const * p; | |||||
exports = cucul_get_export_list(); | |||||
printf("Available export formats:\n"); | |||||
for(p = exports; *p; p += 2) | |||||
printf("\"%s\": %s\n", *p, *(p + 1)); | |||||
return 0; | |||||
} | |||||