ソースを参照

* Moved export stuff in export.c.

* Bail out with an error if the requested export format is unsupported.
pull/1/head
Sam Hocevar sam 18年前
コミット
41ffd5d7b8
4個のファイルの変更84行の追加17行の削除
  1. +1
    -0
      src/Makefile.am
  2. +58
    -0
      src/export.c
  3. +20
    -0
      src/export.h
  4. +5
    -17
      src/main.c

+ 1
- 0
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@


+ 58
- 0
src/export.c ファイルの表示

@@ -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;
}


+ 20
- 0
src/export.h ファイルの表示

@@ -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 *);


+ 5
- 17
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;
}


読み込み中…
キャンセル
保存