root/maint/gnulib/tests/test-iconvme.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Recode strings between character sets, using iconv.
   2    Copyright (C) 2004-2005, 2009-2021 Free Software Foundation, Inc.
   3    Written by Simon Josefsson.
   4 
   5    This program is free software: you can redistribute it and/or modify
   6    it under the terms of the GNU General Public License as published by
   7    the Free Software Foundation; either version 3 of the License, or
   8    (at your option) any later version.
   9 
  10    This program is distributed in the hope that it will be useful,
  11    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13    GNU General Public License for more details.
  14 
  15    You should have received a copy of the GNU General Public License
  16    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  17 
  18 #include <config.h>
  19 
  20 #include <stdlib.h>
  21 #include <stdio.h>
  22 
  23 #include "iconvme.h"
  24 
  25 int main (int ac, char *av[])
     /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27   char *in = NULL, *out = NULL;
  28   char *to = NULL, *from = NULL;
  29 
  30   if (ac > 1)
  31     from = av[1];
  32 
  33   if (ac > 2)
  34     to = av[2];
  35 
  36   if (ac > 3)
  37     in = av[3];
  38 
  39   if (!in)
  40     {
  41       size_t len = 0;
  42       printf ("Enter string to convert:\n\t> ");
  43       if (getline (&in, &len, stdin) < 0)
  44         perror ("getline");
  45       if (in[strlen (in) - 1] == '\n')
  46         in[strlen (in) - 1] = '\0';
  47     }
  48 
  49   if (!to)
  50     {
  51       size_t len = 0;
  52       printf ("Enter destination code set:\n\t> ");
  53       if (getline (&to, &len, stdin) < 0)
  54         perror ("getline");
  55       if (to[strlen (to) - 1] == '\n')
  56         to[strlen (to) - 1] = '\0';
  57     }
  58 
  59   if (!from)
  60     {
  61       size_t len = 0;
  62       printf ("Enter source code set:\n\t> ");
  63       if (getline (&from, &len, stdin) < 0)
  64         perror ("getline");
  65       if (from[strlen (from) - 1] == '\n')
  66         from[strlen (from) - 1] = '\0';
  67     }
  68 
  69   printf (" Input string: '%s'\n"
  70           "From code set: '%s'\n"
  71           "  To code set: '%s'\n",
  72           in, from, to);
  73 
  74   out = iconv_string (in, from, to);
  75 
  76   if (out == NULL)
  77     perror ("iconv");
  78   else
  79     {
  80       printf ("\nOutput: '%s'\n", out);
  81       free (out);
  82     }
  83 
  84   return EXIT_SUCCESS;
  85 }

/* [previous][next][first][last][top][bottom][index][help] */