1 /* Ad-hoc testing program for GNU libtextstyle.
2 Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2018.
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.
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.
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/>. */
20 #include <textstyle.h>
28 main (int argc
, char *argv
[])
30 const char *program_name
= argv
[0];
33 /* Parse the command-line arguments. */
34 for (i
= 1; i
< argc
; i
++)
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] == '-')
43 fprintf (stderr
, "%s: invalid argument: %s\n", program_name
, arg
);
47 /* Handle non-option arguments here. */
51 /* Handle the --color=test special argument. */
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
)
65 /* If no style file is explicitly specified, use the default in the
67 if (style_file_name
== NULL
)
68 style_file_name
= SRCDIR
"test-libtextstyle-default.css";
72 style_file_name
= NULL
;
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
),
80 : styled_ostream_create (STDOUT_FILENO
, "(stdout)", TTYCTL_AUTO
,
83 ostream_write_str (stream
, "Hello ");
85 /* Associate the entire full name in CSS class 'name'. */
86 styled_ostream_begin_use_class (stream
, "name");
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");
94 /* Terminate the name. */
95 styled_ostream_end_use_class (stream
, "name");
97 ostream_write_str (stream
, "!\n");
99 /* Flush and close the terminal stream. */
100 styled_ostream_free (stream
);