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

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

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* Ad-hoc testing program for GNU libtextstyle.
   2    Copyright (C) 2018-2021 Free Software Foundation, Inc.
   3    Written by Bruno Haible <bruno@clisp.org>, 2018.
   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 <textstyle.h>
  21 
  22 #include <stdio.h>
  23 #include <stdlib.h>
  24 #include <string.h>
  25 #include <unistd.h>
  26 
  27 int
  28 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30   const char *program_name = argv[0];
  31   int i;
  32 
  33   /* Parse the command-line arguments.  */
  34   for (i = 1; i < argc; i++)
  35     {
  36       const char *arg = argv[i];
  37       if (strncmp (arg, "--color=", 8) == 0)
  38         handle_color_option (arg + 8);
  39       else if (strncmp (arg, "--style=", 8) == 0)
  40         handle_style_option (arg + 8);
  41       else if (arg[0] == '-')
  42         {
  43           fprintf (stderr, "%s: invalid argument: %s\n", program_name, arg);
  44           exit (1);
  45         }
  46       else
  47         /* Handle non-option arguments here.  */
  48         ;
  49     }
  50 
  51   /* Handle the --color=test special argument.  */
  52   if (color_test_mode)
  53     {
  54       print_color_test ();
  55       exit (0);
  56     }
  57 
  58   #if HAVE_LIBTEXTSTYLE
  59   if (color_mode == color_yes
  60       || (color_mode == color_tty
  61           && isatty (STDOUT_FILENO)
  62           && getenv ("NO_COLOR") == NULL)
  63       || color_mode == color_html)
  64     {
  65       /* If no style file is explicitly specified, use the default in the
  66          source directory.  */
  67       if (style_file_name == NULL)
  68         style_file_name = SRCDIR "test-libtextstyle-default.css";
  69     }
  70   else
  71     /* No styling.  */
  72     style_file_name = NULL;
  73   #endif
  74 
  75   /* Create a terminal output stream that uses this style file.  */
  76   styled_ostream_t stream =
  77     (color_mode == color_html
  78      ? html_styled_ostream_create (file_ostream_create (stdout),
  79                                    style_file_name)
  80      : styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
  81                               style_file_name));
  82 
  83   ostream_write_str (stream, "Hello ");
  84 
  85   /* Associate the entire full name in CSS class 'name'.  */
  86   styled_ostream_begin_use_class (stream, "name");
  87 
  88   ostream_write_str (stream, "Dr. ");
  89   styled_ostream_begin_use_class (stream, "boy-name");
  90   ostream_write_str (stream, "Linus");
  91   styled_ostream_end_use_class (stream, "boy-name");
  92   ostream_write_str (stream, " Pauling");
  93 
  94   /* Terminate the name.  */
  95   styled_ostream_end_use_class (stream, "name");
  96 
  97   ostream_write_str (stream, "!\n");
  98 
  99   /* Flush and close the terminal stream.  */
 100   styled_ostream_free (stream);
 101 
 102   return 0;
 103 }

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