]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libtextstyle: Add a program for ad-hoc testing.
authorBruno Haible <bruno@clisp.org>
Mon, 11 Mar 2019 20:19:57 +0000 (21:19 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 11 Mar 2019 20:21:14 +0000 (21:21 +0100)
* libtextstyle/adhoc-tests/README: New file.
* libtextstyle/adhoc-tests/hello.c: New file, based on
libtextstyle/examples/color-hello/hello.c.
* libtextstyle/adhoc-tests/hello-default.css: New file, copied from
libtextstyle/examples/color-hello/hello-default.css.
* libtextstyle/adhoc-tests/Makefile.am: New file.
* libtextstyle/configure.ac (AC_CONFIG_FILES): Add adhoc-tests/Makefile.
* libtextstyle/Makefile.am (SUBDIRS): Add adhoc-tests.

libtextstyle/.gitignore
libtextstyle/Makefile.am
libtextstyle/adhoc-tests/Makefile.am [new file with mode: 0644]
libtextstyle/adhoc-tests/README [new file with mode: 0644]
libtextstyle/adhoc-tests/hello-default.css [new file with mode: 0644]
libtextstyle/adhoc-tests/hello.c [new file with mode: 0644]
libtextstyle/configure.ac

index 3aee04ae726e2870406a76f6834db56d2654bf19..78009428f7301b44cfc18e39f2d3466d3b1e8b68 100644 (file)
 /doc/Makefile.in
 /lib/Makefile.in
 /tests/Makefile.in
+/adhoc-tests/Makefile.in
 
 # ---------- "make maintainer-clean" gets you here ----------
 
@@ -306,6 +307,11 @@ autom4te.cache/
 /lib/textstyle/version.h
 /lib/textstyle/woe32dll.h
 /tests/Makefile
+/adhoc-tests/Makefile
+
+# Directories generated by "make" and not distributed
+# (i.e. erased by "make distclean"):
+/adhoc-tests/.deps/
 
 # Files generated by "make" and not distributed
 # (i.e. erased by "make distclean"):
@@ -318,6 +324,7 @@ autom4te.cache/
 
 # Directories generated by "make" and erased by "make clean":
 /lib/**/.libs/
+/adhoc-tests/**/.libs/
 
 # Files generated by "make" and erased by "make clean"
 # (see CLEANFILES in Makefile.am and, if present, Makefile.gnulib):
@@ -330,6 +337,9 @@ autom4te.cache/
 /lib/libtextstyle.la
 /lib/libxml_rpl.la
 /lib/textstyle/stdbool.h
+# Executables generated by "make":
+/adhoc-tests/hello
+/adhoc-tests/hello.exe
 
 # ---------- "make mostlyclean" gets you here ----------
 
index da4e038ae7248fa3b8668a652a10e221faac6312..8da85ebe5191cc207f7a22380f2e5656ff82d046 100644 (file)
@@ -20,7 +20,7 @@ AUTOMAKE_OPTIONS = 1.13 gnu no-dependencies
 ACLOCAL_AMFLAGS = -I m4 -I gnulib-m4
 
 # The list of subdirectories containing Makefiles.
-SUBDIRS = doc lib tests
+SUBDIRS = doc lib tests adhoc-tests
 
 EXTRA_DIST = \
   version.sh \
diff --git a/libtextstyle/adhoc-tests/Makefile.am b/libtextstyle/adhoc-tests/Makefile.am
new file mode 100644 (file)
index 0000000..7b78df8
--- /dev/null
@@ -0,0 +1,52 @@
+## Makefile for the adhoc-tests subdirectory of GNU libtextstyle.
+## Copyright (C) 2019 Free Software Foundation, Inc.
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+## Process this file with automake to produce Makefile.in.
+
+AUTOMAKE_OPTIONS = 1.13 gnits
+EXTRA_DIST =
+MOSTLYCLEANFILES = core *.stackdump
+CLEANFILES =
+DISTCLEANFILES =
+
+RM = rm -f
+
+# The list of programs that are built.
+noinst_PROGRAMS = hello
+
+# The source files of each program.
+hello_SOURCES = hello.c
+
+# Define the styles.
+noinst_DATA = hello-default.css
+
+AM_CPPFLAGS = \
+  -I. -I$(srcdir) \
+  -I.. \
+  -I../lib -I$(srcdir)/../lib \
+  -DSRCDIR=\"$(srcdir)/\"
+
+# Link dependencies.
+LDADD = ../lib/libtextstyle.la
+
+# Additional files to be distributed.
+EXTRA_DIST += $(noinst_DATA)
+
+
+# Remove .deps directories creates by 'configure'.
+# I would say that this left-over is an Automake 1.16.1 bug.
+distclean-local:
+       rm -rf $(DEPDIR) */$(DEPDIR)
diff --git a/libtextstyle/adhoc-tests/README b/libtextstyle/adhoc-tests/README
new file mode 100644 (file)
index 0000000..32d0e02
--- /dev/null
@@ -0,0 +1,2 @@
+This directory contains programs that are linked against the libtextstyle in
+the build tree.  They are used for ad-hoc testing and interactive testing.
diff --git a/libtextstyle/adhoc-tests/hello-default.css b/libtextstyle/adhoc-tests/hello-default.css
new file mode 100644 (file)
index 0000000..7eba906
--- /dev/null
@@ -0,0 +1,7 @@
+/* This file is in the public domain.
+
+   Styling rules for the color-hello example.  */
+
+.name      { text-decoration : underline; }
+.boy-name  { background-color : rgb(123,201,249); }
+.girl-name { background-color : rgb(250,149,158); }
diff --git a/libtextstyle/adhoc-tests/hello.c b/libtextstyle/adhoc-tests/hello.c
new file mode 100644 (file)
index 0000000..1147493
--- /dev/null
@@ -0,0 +1,99 @@
+/* Ad-hoc testing program for GNU libtextstyle.
+   Copyright (C) 2018-2019 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2018.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <textstyle.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main (int argc, char *argv[])
+{
+  const char *program_name = argv[0];
+  int i;
+
+  /* Parse the command-line arguments.  */
+  for (i = 1; i < argc; i++)
+    {
+      const char *arg = argv[i];
+      if (strncmp (arg, "--color=", 8) == 0)
+        handle_color_option (arg + 8);
+      else if (strncmp (arg, "--style=", 8) == 0)
+        handle_style_option (arg + 8);
+      else if (arg[0] == '-')
+        {
+          fprintf (stderr, "%s: invalid argument: %s\n", program_name, arg);
+          exit (1);
+        }
+      else
+        /* Handle non-option arguments here.  */
+        ;
+    }
+
+  /* Handle the --color=test special argument.  */
+  if (color_test_mode)
+    {
+      print_color_test ();
+      exit (0);
+    }
+
+  if (color_mode == color_yes
+      || (color_mode == color_tty && isatty (STDOUT_FILENO))
+      || color_mode == color_html)
+    {
+      /* If no style file is explicitly specified, use the default in the
+         source directory.  */
+      if (style_file_name == NULL)
+        style_file_name = SRCDIR "hello-default.css";
+    }
+  else
+    /* No styling.  */
+    style_file_name = NULL;
+
+  /* Create a terminal output stream that uses this style file.  */
+  styled_ostream_t stream =
+    (color_mode == color_html
+     ? html_styled_ostream_create (file_ostream_create (stdout),
+                                   style_file_name)
+     : styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
+                              style_file_name));
+
+  ostream_write_str (stream, "Hello ");
+
+  /* Associate the entire full name in CSS class 'name'.  */
+  styled_ostream_begin_use_class (stream, "name");
+
+  ostream_write_str (stream, "Dr. ");
+  styled_ostream_begin_use_class (stream, "boy-name");
+  ostream_write_str (stream, "Linus");
+  styled_ostream_end_use_class (stream, "boy-name");
+  ostream_write_str (stream, " Pauling");
+
+  /* Terminate the name.  */
+  styled_ostream_end_use_class (stream, "name");
+
+  ostream_write_str (stream, "!\n");
+
+  /* Flush and close the terminal stream.  */
+  styled_ostream_free (stream);
+
+  return 0;
+}
index 203ac97120be32a11eb8e24d5f173f23e1939d3f..166022bc69b8e1cb5814518cbb1b0b04629d4776 100644 (file)
@@ -181,4 +181,5 @@ AC_CONFIG_FILES([lib/exported.sh])
 AC_CONFIG_FILES([lib/textstyle/version.h:lib/textstyle/version.in.h])
 AC_CONFIG_FILES([lib/textstyle/woe32dll.h:lib/textstyle/woe32dll.in.h])
 AC_CONFIG_FILES([tests/Makefile])
+AC_CONFIG_FILES([adhoc-tests/Makefile])
 AC_OUTPUT