diff --git a/src/Makefile.am b/src/Makefile.am index 0b279fb..804ffc6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,7 @@ toilet_SOURCES = main.c toilet.h \ io.c io.h \ render.c render.h \ filter.c filter.h \ + export.c export.h \ term.c figlet.c toilet_CFLAGS = `pkg-config --cflags cucul` toilet_LDFLAGS = `pkg-config --libs cucul` @GETOPT_LIBS@ @ZLIB_LIBS@ diff --git a/src/export.c b/src/export.c new file mode 100644 index 0000000..813a521 --- /dev/null +++ b/src/export.c @@ -0,0 +1,58 @@ +/* + * TOIlet The Other Implementation’s letters + * Copyright (c) 2006 Sam Hocevar + * 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 +#endif +#include +#include +#include +#include + +#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; +} + diff --git a/src/export.h b/src/export.h new file mode 100644 index 0000000..370b12d --- /dev/null +++ b/src/export.h @@ -0,0 +1,20 @@ +/* + * TOIlet The Other Implementation’s letters + * Copyright (c) 2006 Sam Hocevar + * 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 *); + diff --git a/src/main.c b/src/main.c index e9a3531..fef4517 100644 --- a/src/main.c +++ b/src/main.c @@ -34,12 +34,12 @@ #include "toilet.h" #include "render.h" #include "filter.h" +#include "export.h" static void version(void); #if defined(HAVE_GETOPT_H) static void usage(void); #endif -static int export_list(void); int main(int argc, char *argv[]) { @@ -138,13 +138,14 @@ int main(int argc, char *argv[]) case 'E': /* --export */ if(!strcmp(optarg, "list")) return export_list(); - cx->export = optarg; + if(export_set(cx, optarg) < 0) + return -1; break; case 140: /* --irc */ - cx->export = "irc"; + export_set(cx, "irc"); break; case 141: /* --html */ - cx->export = "html"; + export_set(cx, "html"); break; case '?': printf(MOREINFO, argv[0]); @@ -260,16 +261,3 @@ static void usage(void) } #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; -} -