author | Lorenzo Bettini <bettini@dsi.unifi.it> | 2007年03月23日 18:13:11 +0000 |
---|---|---|
committer | Lorenzo Bettini <bettini@dsi.unifi.it> | 2007年03月23日 18:13:11 +0000 |
commit | 6fcee8f6e2f2212855b5b3e3ea5db76dc5d48cc3 (patch) | |
tree | 75e439f2d91fd9476d729dfe18c2765cd08f47eb /src | |
parent | 5a0ebf841e2df9b60a10545d9abd5350bd06a346 (diff) | |
download | src-highlite-6fcee8f6e2f2212855b5b3e3ea5db76dc5d48cc3.tar.gz |
diff --git a/src/.cvsignore b/src/.cvsignore index 497b478..ab0c685 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -1,6 +1,9 @@ Makefile.in Makefile .deps +.libs +*.lo +*.la *.stamp source-highlight source-highlight-cgi diff --git a/src/Makefile.am b/src/Makefile.am index 6fe37e0..e6ca190 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,19 +10,22 @@ bin_PROGRAMS = source-highlight bin_SCRIPTS = java2html cpp2html src-hilite-lesspipe.sh -noinst_LIBRARIES = libsh.a -EXTRA_PROGRAMS = source-highlight-cgi source-highlight-efence +noinst_LTLIBRARIES = libsh.la +libsh_la_LIBADD = $(BOOST_REGEX_LIB) $(LDADD) lib/libcommon.la +EXTRA_PROGRAMS = source-highlight-cgi SRCHILITE = $(top_builddir)/src/source-highlight$(EXEEXT) -libsh_a_AR = @ar_to_use@ - LIBSUBDIR = $(SUBDIRS) INCLUDES = -I@top_srcdir@/src/lib -LDADD = @LEXLIB@ @LIBOBJS@ -source_highlight_LDADD = -l$(BOOST_REGEX_LIB) $(LDADD) lib/libcommon.a -source_highlight_cgi_LDADD = -l$(BOOST_REGEX_LIB) $(LDADD) lib/libcgi.a + +AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_builddir)/gl + +LDADD = @LEXLIB@ $(top_builddir)/gl/libgnu.la + +source_highlight_LDADD = libsh.la +source_highlight_cgi_LDADD = libsh.la SUBDIRS = \ lib \ @@ -32,15 +35,12 @@ DIST_SUBDIRS = \ lib \ includes -libsh_a_SOURCES = cxxconfig.h source-highlight.cc regexpengine.cpp regexpstate.cpp regexpenginedebug.cpp +libsh_la_SOURCES = source-highlight.cc regexpengine.cpp regexpstate.cpp regexpenginedebug.cpp # for most rules, we use one file per line. `diffs' are more clear this way -source_highlight_SOURCES = startapp.cc $(libsh_a_SOURCES) +source_highlight_SOURCES = startapp.cc -source_highlight_cgi_SOURCES = startapp-cgi.cc $(libsh_a_SOURCES) - -startapp-cgi.cc: - cd @top_srcdir@/src/lib && $(MAKE) libcgi.a +source_highlight_cgi_SOURCES = startapp-cgi.cc envmapper.c # files that we don't want automake/autoconf to touch ever. # just stick them in the distribution as-is @@ -49,7 +49,7 @@ java2html.in \ cpp2html.in \ src-hilite-lesspipe.sh.in \ startapp.h \ -gnugetopt.h \ +envmapper.h \ $(source_highlightdata_DATA) LANGFILES = \ @@ -61,24 +61,27 @@ pascal.lang fortran.lang html.lang latex.lang logtalk.lang \ diff.lang c_string.lang langdef.lang outlang.lang style.lang \ extreme_comment.lang extreme_comment2.lang extreme_comment3.lang \ postscript.lang csharp.lang xml.lang sh.lang script_comment.lang \ -tcl.lang sql.lang bib.lang \ +tcl.lang sql.lang bib.lang makefile.lang css.lang m4.lang \ default.lang nohilite.lang OUTLANGFILES = \ css_common.outlang \ -cssdoc.outlang \ esc.outlang \ html_common.outlang \ html_notfixed.outlang \ +htmlcss.outlang \ htmldoc.outlang \ +htmltable.outlang \ html.outlang \ latexdoc.outlang \ latex.outlang \ latexcolordoc.outlang \ latexcolor.outlang \ +xhtml_common.outlang \ xhtmlcss.outlang \ xhtmldoc.outlang \ xhtml.outlang \ +xhtmltable.outlang \ texinfo.outlang \ javadoc.outlang \ docbook.outlang @@ -89,11 +92,8 @@ source_highlightdata_DATA = \ $(LANGFILES) $(OUTLANGFILES) \ $(STYLEFILES) \ default.style style2.style style3.style \ -lang.map outlang.map - -source_highlight_efence_SOURCES = startapp-cgi.cc $(source_highlight_SOURCES) - -source_highlight_efence_LDADD = $(source_highlight_LDADD) -lefence +lang.map outlang.map \ +default.css # files that are built before distribution gets built #MAINTAINERCLEANFILES = $(BUILT_SOURCES) diff --git a/src/css.lang b/src/css.lang new file mode 100644 index 0000000..4bda394 --- /dev/null +++ b/src/css.lang @@ -0,0 +1,14 @@ +# language definition for css style sheets + +include "c_comment.lang" + +selector = '(\.|#)[[:word:]]+' + +state cbracket delim "{" "}" multiline begin + include "c_comment.lang" + property = '[[:word:]-]+[[:blank:]]*:' + value = '[.%[:word:]-]+' + string = '#([[:word:]]+)' +end + +include "symbols.lang"
\ No newline at end of file diff --git a/src/css_common.outlang b/src/css_common.outlang index f05a0ef..a530e03 100644 --- a/src/css_common.outlang +++ b/src/css_common.outlang @@ -8,8 +8,8 @@ end doctemplate "<!-- Generator: $additional --> -<pre><tt>" -"</tt></pre> +$header<pre><tt>" +"</tt></pre>$footer " end diff --git a/src/cxxconfig.h b/src/cxxconfig.h deleted file mode 100644 index 16f8adb..0000000 --- a/src/cxxconfig.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - This is a little work around: if the C compiler does not support const - "const" would be define as an empty string and this would not make the C++ - compiler work (where const is a keyword). So if const for C compiler does - not work we still keep const for C++ compiler. -*/ - -#ifdef __cplusplus -#undef const -#endif /* __cplusplus */ diff --git a/src/default.css b/src/default.css new file mode 100644 index 0000000..e08e98b --- /dev/null +++ b/src/default.css @@ -0,0 +1,46 @@ +body { background-color: white; } + +.keyword { color: blue; font-weight: bold; } +.type { color: darkgreen; } +.string { color: red; font-family: monospace; } +.specialchar { color: pink; font-family: monospace; } +.comment { color: brown; font-style: italic; } +.number { color: purple; } +.preproc { color: darkblue; font-weight: bold; } +.symbol { color: darkred; } +.function { color: black; font-weight: bold; } +.cbracket { color: red; } +.todo { font-weight: bold; background-color: cyan; } + +/* line numbers */ +.linenum { color: black; font-family: monospace; } + +/* Internet related */ +.url { color: blue; text-decoration: underline; font-family: monospace; } + +/* other elements for ChangeLog and Log files */ +.date { color: blue; font-weight: bold; } +.time, .file { color: darkblue; font-weight: bold; } +.ip, .name { color: darkgreen; } + +/* for Prolog, Perl */ +.variable { color: darkgreen; } +.italics { color: darkgreen; font-style: italic; } +.bold { color: darkgreen; font-weight: bold; } + +/* for LaTeX */ +.underline { color: darkgreen; text-decoration: underline; } +.fixed { color: green; font-family: monospace; } +.argument, .optionalargument { color: darkgreen; } +.math { color: orange; } +.bibtex { color: blue; } + +/* for diffs */ +.oldfile { color: orange; } +.newfile { color: darkgreen; } +.difflines { color: blue; } + +/* for css */ +.selector { color: purple; } +.property { color: blue; } +.value { color: darkgreen; font-style: italic; }
\ No newline at end of file diff --git a/src/default.style b/src/default.style index f5866dc..5ade28d 100644 --- a/src/default.style +++ b/src/default.style @@ -1,3 +1,5 @@ +bgcolor "white"; // the background color for documents + keyword blue b ; // for language keywords type darkgreen ; // for basic types string red f ; // for strings and chars @@ -8,7 +10,7 @@ preproc darkblue b ; // for preproc directives (e.g. #include, import) symbol darkred ; // for simbols (e.g. <, >, +) function black b; // for function calls and declarations cbracket red; // for block brackets (e.g. {, }) -todo b; // for TODO and FIXME +todo bg:cyan b; // for TODO and FIXME // line numbers linenum black f; @@ -18,10 +20,8 @@ url blue u, f; // other elements for ChangeLog and Log files date blue b ; -time darkblue b ; -ip darkgreen ; -file darkblue b ; -name darkgreen ; +time, file darkblue b ; +ip, name darkgreen ; // for Prolog, Perl... variable darkgreen ; @@ -40,3 +40,8 @@ bibtex blue; oldfile orange; newfile darkgreen; difflines blue; + +// for css +selector purple; +property blue; +value darkgreen i;
\ No newline at end of file diff --git a/src/lib/envmapper.c b/src/envmapper.c index 294ecaa..294ecaa 100644 --- a/src/lib/envmapper.c +++ b/src/envmapper.c diff --git a/src/lib/envmapper.h b/src/envmapper.h index 14a2535..14a2535 100644 --- a/src/lib/envmapper.h +++ b/src/envmapper.h diff --git a/src/esc.style b/src/esc.style index d49bd75..8c00bda 100644 --- a/src/esc.style +++ b/src/esc.style @@ -2,7 +2,7 @@ keyword blue b ; type darkgreen ; string red ; specialchar pink ; -comment brown i ; +comment cyan i ; number purple ; preproc darkblue b ; symbol darkred ; @@ -21,4 +21,14 @@ file darkblue ; name darkgreen ; // Internet related -url blue u;
\ No newline at end of file +url blue u; + +// for diffs +oldfile orange; +newfile darkgreen; +difflines blue; + +// for css +selector purple; +property blue; +value darkgreen i;
\ No newline at end of file diff --git a/src/getopt.c b/src/getopt.c deleted file mode 100644 index 9fb69b1..0000000 --- a/src/getopt.c +++ /dev/null @@ -1,1055 +0,0 @@ -/* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to drepper@gnu.org - before changing it! - Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. - Ditto for AIX 3.2 and <stdlib.h>. */ -#ifndef _NO_PROTO -# define _NO_PROTO -#endif - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -# ifndef const -# define const -# endif -#endif - -#include <stdio.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#define GETOPT_INTERFACE_VERSION 2 -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 -# include <gnu-versions.h> -# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -# define ELIDE_CODE -# endif -#endif - -#ifndef ELIDE_CODE - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -/* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -# include <stdlib.h> -# include <unistd.h> -#endif /* GNU C library. */ - -#ifdef VMS -# include <unixlib.h> -# if HAVE_STRING_H - 0 -# include <string.h> -# endif -#endif - -#ifndef _ -/* This is for other GNU distributions with internationalized messages. */ -# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC -# include <libintl.h> -# ifndef _ -# define _(msgid) gettext (msgid) -# endif -# else -# define _(msgid) (msgid) -# endif -#endif - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ - -#include "getopt.h" - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -/* 1003.2 says this must be 1 before any call. */ -int optind = 1; - -/* Formerly, initialization of getopt depended on optind==0, which - causes problems with re-calling getopt as programs generally don't - know that. */ - -int __getopt_initialized; - -/* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ - -static char *nextchar; - -/* Callers store zero here to inhibit the error message - for unrecognized options. */ - -int opterr = 1; - -/* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ - -int optopt = '?'; - -/* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return -1 with `optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER -} ordering; - -/* Value of POSIXLY_CORRECT environment variable. */ -static char *posixly_correct; - -#ifdef __GNU_LIBRARY__ -/* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ -# include <string.h> -# define my_index strchr -#else - -# if HAVE_STRING_H -# include <string.h> -# else -# include <strings.h> -# endif - -/* Avoid depending on library functions or files - whose names are inconsistent. */ - -#ifndef getenv -extern char *getenv (); -#endif - -static char * -my_index (str, chr) - const char *str; - int chr; -{ - while (*str) - { - if (*str == chr) - return (char *) str; - str++; - } - return 0; -} - -/* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. */ -#ifdef __GNUC__ -/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - That was relevant to code that was here before. */ -# if (!defined __STDC__ || !__STDC__) && !defined strlen -/* gcc with -traditional declares the built-in strlen to return int, - and has done so at least since version 2.4.5. -- rms. */ -extern int strlen (const char *); -# endif /* not __STDC__ */ -#endif /* __GNUC__ */ - -#endif /* not __GNU_LIBRARY__ */ - -/* Handle permutation of arguments. */ - -/* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ - -static int first_nonopt; -static int last_nonopt; - -#ifdef _LIBC -/* Stored original parameters. - XXX This is no good solution. We should rather copy the args so - that we can compare them later. But we must not use malloc(3). */ -extern int __libc_argc; -extern char **__libc_argv; - -/* Bash 2.0 gives us an environment variable containing flags - indicating ARGV elements that should not be considered arguments. */ - -# ifdef USE_NONOPTION_FLAGS -/* Defined in getopt_init.c */ -extern char *__getopt_nonoption_flags; - -static int nonoption_flags_max_len; -static int nonoption_flags_len; -# endif - -# ifdef USE_NONOPTION_FLAGS -# define SWAP_FLAGS(ch1, ch2) \ - if (nonoption_flags_len > 0) \ - { \ - char __tmp = __getopt_nonoption_flags[ch1]; \ - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ - __getopt_nonoption_flags[ch2] = __tmp; \ - } -# else -# define SWAP_FLAGS(ch1, ch2) -# endif -#else /* !_LIBC */ -# define SWAP_FLAGS(ch1, ch2) -#endif /* _LIBC */ - -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. - - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ - -#if defined __STDC__ && __STDC__ -static void exchange (char **); -#endif - -static void -exchange (argv) - char **argv; -{ - int bottom = first_nonopt; - int middle = last_nonopt; - int top = optind; - char *tem; - - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ - -#if defined _LIBC && defined USE_NONOPTION_FLAGS - /* First make sure the handling of the `__getopt_nonoption_flags' - string can work normally. Our top argument must be in the range - of the string. */ - if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) - { - /* We must extend the array. The user plays games with us and - presents new arguments. */ - char *new_str = malloc (top + 1); - if (new_str == NULL) - nonoption_flags_len = nonoption_flags_max_len = 0; - else - { - memset (__mempcpy (new_str, __getopt_nonoption_flags, - nonoption_flags_max_len), - '0円', top + 1 - nonoption_flags_max_len); - nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } - } -#endif - - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; -} - -/* Initialize the internal data when the first call is made. */ - -#if defined __STDC__ && __STDC__ -static const char *_getopt_initialize (int, char *const *, const char *); -#endif -static const char * -_getopt_initialize (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; -{ - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ - - first_nonopt = last_nonopt = optind; - - nextchar = NULL; - - posixly_correct = getenv ("POSIXLY_CORRECT"); - - /* Determine how to handle the ordering of options and nonoptions. */ - - if (optstring[0] == '-') - { - ordering = RETURN_IN_ORDER; - ++optstring; - } - else if (optstring[0] == '+') - { - ordering = REQUIRE_ORDER; - ++optstring; - } - else if (posixly_correct != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; - -#if defined _LIBC && defined USE_NONOPTION_FLAGS - if (posixly_correct == NULL - && argc == __libc_argc && argv == __libc_argv) - { - if (nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL - || __getopt_nonoption_flags[0] == '0円') - nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = nonoption_flags_max_len = strlen (orig_str); - if (nonoption_flags_max_len < argc) - nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - (char *) malloc (nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - nonoption_flags_max_len = -1; - else - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), - '0円', nonoption_flags_max_len - len); - } - } - nonoption_flags_len = nonoption_flags_max_len; - } - else - nonoption_flags_len = 0; -#endif - - return optstring; -} - -/* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns -1. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ - -int -_getopt_internal (argc, argv, optstring, longopts, longind, long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; -{ - int print_errors = opterr; - if (optstring[0] == ':') - print_errors = 0; - - if (argc < 1) - return -1; - - optarg = NULL; - - if (optind == 0 || !__getopt_initialized) - { - if (optind == 0) - optind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = _getopt_initialize (argc, argv, optstring); - __getopt_initialized = 1; - } - - /* Test whether ARGV[optind] points to a non-option argument. - Either it does not have option syntax, or there is an environment flag - from the shell indicating it is not an option. The later information - is only used when the used in the GNU libc. */ -#if defined _LIBC && defined USE_NONOPTION_FLAGS -# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '0円' \ - || (optind < nonoption_flags_len \ - && __getopt_nonoption_flags[optind] == '1')) -#else -# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '0円') -#endif - - if (nextchar == NULL || *nextchar == '0円') - { - /* Advance to the next ARGV-element. */ - - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ - if (last_nonopt > optind) - last_nonopt = optind; - if (first_nonopt > optind) - first_nonopt = optind; - - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; - - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ - - while (optind < argc && NONOPTION_P) - optind++; - last_nonopt = optind; - } - - /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ - - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; - - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; - - optind = argc; - } - - /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return -1; - } - - /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ - - if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - optarg = argv[optind++]; - return 1; - } - - /* We have found another option-ARGV-element. - Skip the initial punctuation. */ - - nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[optind][1] == '-' - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) - == (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else if (long_only - || pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (print_errors) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - optopt = 0; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (print_errors) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[optind - 1][0], pfound->name); - } - - nextchar += strlen (nextchar); - - optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (print_errors) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - - /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ - if (!long_only || argv[optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (print_errors) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - optopt = 0; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '0円') - ++optind; - - if (temp == NULL || c == ':') - { - if (print_errors) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), - argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), - argv[0], c); - } - optopt = c; - return '?'; - } - /* Convenience. Treat POSIX -W foo same as long option --foo */ - if (temp[0] == 'W' && temp[1] == ';') - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '0円') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (print_errors) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - - /* optarg is now the argument, see if it's in the - table of longopts. */ - - for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (print_errors) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (print_errors) - fprintf (stderr, _("\ -%s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (print_errors) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ - } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '0円') - { - optarg = nextchar; - optind++; - } - else - optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '0円') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (print_errors) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } - } - return c; - } -} - -int -getopt (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; -{ - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); -} - -#endif /* Not ELIDE_CODE. */ - -#ifdef TEST - -/* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - - c = getopt (argc, argv, "abc:d:0123456789"); - if (c == -1) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/src/getopt1.c b/src/getopt1.c deleted file mode 100644 index 22a7efb..0000000 --- a/src/getopt1.c +++ /dev/null @@ -1,188 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "getopt.h" - -#if !defined __STDC__ || !__STDC__ -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include <stdio.h> - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#define GETOPT_INTERFACE_VERSION 2 -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 -#include <gnu-versions.h> -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -#define ELIDE_CODE -#endif -#endif - -#ifndef ELIDE_CODE - - -/* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ -#include <stdlib.h> -#endif - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* Not ELIDE_CODE. */ - -#ifdef TEST - -#include <stdio.h> - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == -1) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/src/gnugetopt.h b/src/gnugetopt.h deleted file mode 100644 index a1b8dd6..0000000 --- a/src/gnugetopt.h +++ /dev/null @@ -1,180 +0,0 @@ -/* Declarations for getopt. - Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef _GETOPT_H - -#ifndef __need_getopt -# define _GETOPT_H 1 -#endif - -/* If __GNU_LIBRARY__ is not already defined, either we are being used - standalone, or this is the first header included in the source file. - If we are being used with glibc, we need to include <features.h>, but - that does not exist if we are standalone. So: if __GNU_LIBRARY__ is - not defined, include <ctype.h>, which will pull in <features.h> for us - if it's from glibc. (Why ctype.h? It's guaranteed to exist and it - doesn't flood the namespace with stuff the way some other headers do.) */ -#if !defined __GNU_LIBRARY__ -# include <ctype.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ - -extern char *optarg; - -/* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ - -extern int optind; - -/* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ - -extern int opterr; - -/* Set to an option character which was unrecognized. */ - -extern int optopt; - -#ifndef __need_getopt -/* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -struct option -{ -# if (defined __STDC__ && __STDC__) || defined __cplusplus - const char *name; -# else - char *name; -# endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* Names for the values of the `has_arg' field of `struct option'. */ - -# define no_argument 0 -# define required_argument 1 -# define optional_argument 2 -#endif /* need getopt */ - - -/* Get definitions and prototypes for functions to process the - arguments in ARGV (ARGC of them, minus the program name) for - options given in OPTS. - - Return the option character from OPTS just read. Return -1 when - there are no more options. For unrecognized options, or options - missing arguments, `optopt' is set to the option letter, and '?' is - returned. - - The OPTS string is a list of characters which are recognized option - letters, optionally followed by colons, specifying that that letter - takes an argument, to be placed in `optarg'. - - If a letter in OPTS is followed by two colons, its argument is - optional. This behavior is specific to the GNU `getopt'. - - The argument `--' causes premature termination of argument - scanning, explicitly telling `getopt' that there are no more - options. - - If OPTS begins with `--', then non-option arguments are treated as - arguments to the option '0円'. This behavior is specific to the GNU - `getopt'. */ - -#if (defined __STDC__ && __STDC__) || defined __cplusplus -# ifdef __GNU_LIBRARY__ -/* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int getopt (int __argc, char *const *__argv, const char *__shortopts); -# else /* not __GNU_LIBRARY__ */ -extern int getopt (); -# endif /* __GNU_LIBRARY__ */ - -# ifndef __need_getopt -extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, - const struct option *__longopts, int *__longind); -extern int getopt_long_only (int __argc, char *const *__argv, - const char *__shortopts, - const struct option *__longopts, int *__longind); - -/* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int __argc, char *const *__argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - int __long_only); -# endif -#else /* not __STDC__ */ -extern int getopt (); -# ifndef __need_getopt -extern int getopt_long (); -extern int getopt_long_only (); - -extern int _getopt_internal (); -# endif -#endif /* __STDC__ */ - -#ifdef __cplusplus -} -#endif - -/* Make sure we later can get all the definitions and declarations. */ -#undef __need_getopt - -#endif /* getopt.h */ diff --git a/src/cssdoc.outlang b/src/htmlcss.outlang index e750574..8b26385 100644 --- a/src/cssdoc.outlang +++ b/src/htmlcss.outlang @@ -5,8 +5,7 @@ doctemplate \"http://www.w3.org/TR/REC-html40/strict.dtd\"> <html> <head> -<meta http-equiv=\"Content-Type\" -content=\"text/html; charset=iso-8859-1\"> +<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> <meta name=\"GENERATOR\" content=\"$additional\"> <title>$title</title> <link rel=\"stylesheet\" href=\"$css\" type=\"text/css\"> diff --git a/src/htmldoc.outlang b/src/htmldoc.outlang index 7ba39f3..3fc9aba 100644 --- a/src/htmldoc.outlang +++ b/src/htmldoc.outlang @@ -4,12 +4,11 @@ doctemplate "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"> <html> <head> -<meta http-equiv=\"Content-Type\" -content=\"text/html; charset=iso-8859-1\"> +<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"> <meta name=\"GENERATOR\" content=\"$additional\"> <title>$title</title> </head> -<body> +<body bgcolor=\"$docbgcolor\"> $header<pre><tt>" "</tt></pre> $footer</body> diff --git a/src/htmltable.outlang b/src/htmltable.outlang new file mode 100644 index 0000000..32d4342 --- /dev/null +++ b/src/htmltable.outlang @@ -0,0 +1,14 @@ +include "html_common.outlang" + +doctemplate +"<table BGCOLOR=\"$docbgcolor\" NOSAVE > +<tr NOSAVE> +<td NOSAVE> +<pre><tt>" +"</tt></pre> +</td> +</tr> +</table> +" +end + diff --git a/src/lang.map b/src/lang.map index a02c0bc..d15938b 100644 --- a/src/lang.map +++ b/src/lang.map @@ -16,6 +16,8 @@ pl = prolog.lang perl = perl.lang pm = perl.lang php3 = php.lang +php4 = php.lang +php5 = php.lang php = php.lang python = python.lang py = python.lang @@ -63,9 +65,17 @@ docbook = xml.lang xml = xml.lang xhtml = xml.lang sh = sh.lang +csh = sh.lang +ksh = sh.lang +tcsh = sh.lang shell = sh.lang tcl = tcl.lang tk = tcl.lang txt = nohilite.lang sql = sql.lang bib = bib.lang +makefile = makefile.lang +am = makefile.lang +in = makefile.lang +css = css.lang +m4 = m4.lang diff --git a/src/latexcolor.outlang b/src/latexcolor.outlang index 72a35cb..a0f8cbc 100644 --- a/src/latexcolor.outlang +++ b/src/latexcolor.outlang @@ -1,6 +1,7 @@ include "latex.outlang" color "\textcolor{$style}{$text}" +bgcolor "\colorbox{$style}{$text}" colormap "green" "Green" diff --git a/src/lib/.cvsignore b/src/lib/.cvsignore index 1a74ff6..f661af7 100644 --- a/src/lib/.cvsignore +++ b/src/lib/.cvsignore @@ -1,11 +1,17 @@ Makefile.in Makefile .deps -optparser.cc -optparser.h -optparser.stamp -optscanner.cc -optscanner.stamp +.libs +*.lo +*.la +styleparser.cc +styleparser.h +stylecssparser.cc +stylecssparser.h +styleparser.stamp +stylescanner.cc +stylecssscanner.cc +stylescanner.stamp langdefparser.cc langdefparser.h langdefparser.stamp @@ -44,4 +50,6 @@ test_outlangparser outlangtest.outlang test_readtags test_langinfer -mytags
\ No newline at end of file +mytags +copyright.c +reportbugs.c
\ No newline at end of file diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 8a44f05..2aa586e 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -10,19 +10,8 @@ SUFFIXES = .text .ggo -.cc.stamp: - sed -f $(srcdir)/$*.sed $< > __temp.cc - cp -f __temp.cc $< - rm -f __temp.cc - if test -f $*.h ; then \ - sed -f $(srcdir)/$*.sed $*.h > __temp.h ;\ - cp -f __temp.h $*.h ;\ - rm -f __temp.h ;\ - else :; fi - echo timestamp > $@ - -.text.o: - $(TXTC) $< +.text.c: + $(TXTC) -c $< if NO_GENGETOPT .ggo.c: @@ -41,37 +30,33 @@ $(srcdir)/%.H: $(srcdir)/%.h touch $@ endif -noinst_LIBRARIES = libcommon.a -EXTRA_LIBRARIES = libcgi.a +AM_CPPFLAGS = -I$(top_srcdir)/gl -I$(top_builddir)/gl -libcommon_a_AR = @ar_to_use@ -libcommon_a_SOURCES = copyright.text reportbugs.text cmdline.c styles.cc \ - messages.cc fileutil.cc chartranslator.cc generatorfactory.cc docgenerator.cc \ - optparser.yy optscanner.ll langdefparser.yy langdefscanner.ll outlangdefparser.yy \ - outlangdefscanner.ll srcuntabifier.cpp generatormap.cpp maingeneratormap.cpp \ - outputbuffer.cpp outputgenerator.cpp mainoutputbuffer.cpp lineoutputgenerator.cpp \ - stringdef.cpp langelem.cpp statelangelem.cpp langelems.cpp regexpreprocessor.cpp \ - regexpstatebuilder.H regexpstatebuilder_dbtab.cc regexpstatebuilder.cpp langdefloader.cpp \ - langmap.cpp statestartlangelem.cpp stringlistlangelem.cpp delimitedlangelem.cpp \ - vardefinitions.cpp textformatter.cpp textstyle.cpp textgenerator.cpp textstylebuilder.cpp \ - doctemplate.cpp substfun.cpp refgeneratormap.cpp readtags.c fileinfo.cpp linebuffer.cpp \ - preformatter.cpp regexpstateprinter.cpp langelemsprinter.cpp langelemsprinter.H \ - langelemsprinter_dbtab.cc languageinfer.cpp stopwatch.cpp utils.cpp utils.h +LDADD = @LEXLIB@ $(top_builddir)/gl/libgnu.la -libcgi_a_AR = @ar_to_use@ -libcgi_a_SOURCES = $(libcommon_a_SOURCES) envmapper.c +noinst_LTLIBRARIES = libcommon.la -# LIBADD = @LIBOBJS@ - -# libcgi_a_LIBADD = $(LIBADD) -# libcommon_a_LIBADD = $(LIBADD) +libcommon_la_SOURCES = copyright.text reportbugs.text cmdline.c messages.cc \ + fileutil.cc chartranslator.cc generatorfactory.cc docgenerator.cc styleparser.yy \ + stylescanner.ll langdefparser.yy langdefscanner.ll outlangdefparser.yy \ + stylecssparser.yy stylecssscanner.ll outlangdefscanner.ll srcuntabifier.cpp \ + generatormap.cpp maingeneratormap.cpp outputbuffer.cpp outputgenerator.cpp \ + mainoutputbuffer.cpp lineoutputgenerator.cpp stringdef.cpp langelem.cpp statelangelem.cpp \ + langelems.cpp regexpreprocessor.cpp regexpstatebuilder.H regexpstatebuilder_dbtab.cc \ + regexpstatebuilder.cpp langdefloader.cpp langmap.cpp statestartlangelem.cpp \ + stringlistlangelem.cpp delimitedlangelem.cpp vardefinitions.cpp textformatter.cpp \ + textstyle.cpp textgenerator.cpp textstylebuilder.cpp doctemplate.cpp substfun.cpp \ + refgeneratormap.cpp readtags.c fileinfo.cpp linebuffer.cpp preformatter.cpp \ + regexpstateprinter.cpp langelemsprinter.cpp langelemsprinter.H langelemsprinter_dbtab.cc \ + languageinfer.cpp stopwatch.cpp utils.cpp utils.h +libcommon_la_LIBADD = $(BOOST_REGEX_LIB) INCLUDES = -I@top_srcdir@/src EXTRA_DIST = colors.h generatorfactory.h \ - keys.h optparser.h styles.h \ + keys.h styleparser.h stylecssparser.h \ tokens.h messages.h fileutil.h \ - cmdline.h envmapper.h \ + cmdline.h \ chartranslator.h my_set.h my_sstream.h my_string.h \ linenumdigit.h globalostream.h \ docgenerator.h \ @@ -79,12 +64,12 @@ EXTRA_DIST = colors.h generatorfactory.h \ cmdline.ggo \ copyright.h reportbugs.h \ srcuntabifier.h colormap.h \ - optparser.sed optscanner.sed \ - langdefparser.sed langdefscanner.sed \ langdefparser.h outlangdefparser.h \ outlangtest.outlang.tmpl -BUILT_SOURCES = optparser.cc optparser.h optscanner.cc \ +BUILT_SOURCES = styleparser.cc styleparser.h \ +stylecssparser.cc stylecssparser.h \ +stylescanner.cc stylecssscanner.cc \ langdefparser.cc langdefparser.h langdefscanner.cc \ regexpstatebuilder.H regexpstatebuilder_dbtab.cc \ langelemsprinter.H langelemsprinter_dbtab.cc @@ -101,11 +86,17 @@ outlangdefscanner.cc: $(srcdir)/outlangdefscanner.ll outlangdefparser.cc outlangdefparser.h: $(srcdir)/outlangdefparser.yy $(YACC) -p outlangdef_ -o $@ $(srcdir)/outlangdefparser.yy --defines=$*.h -optscanner.cc: $(srcdir)/optscanner.ll - $(LEX) $(LFLAGS) -o $@ $(srcdir)/optscanner.ll +stylescanner.cc: $(srcdir)/stylescanner.ll + $(LEX) $(LFLAGS) -o $@ $(srcdir)/stylescanner.ll + +stylecssscanner.cc: $(srcdir)/stylecssscanner.ll + $(LEX) $(LFLAGS) -o $@ $(srcdir)/stylecssscanner.ll -optparser.cc optparser.h: $(srcdir)/optparser.yy - $(YACC) -p opsc_ -o $@ $(srcdir)/optparser.yy --defines=$*.h +styleparser.cc styleparser.h: $(srcdir)/styleparser.yy + $(YACC) -p stylesc_ -o $@ $(srcdir)/styleparser.yy --defines=$*.h + +stylecssparser.cc stylecssparser.h: $(srcdir)/stylecssparser.yy + $(YACC) -p stylecsssc_ -o $@ $(srcdir)/stylecssparser.yy --defines=$*.h TESTS = test_textstyle test_textgenerator test_outlangparser test_readtags \ test_langinfer @@ -113,45 +104,49 @@ test_langinfer check_PROGRAMS = test_langdefparser test_langmap test_textstyle test_textgenerator test_outlangparser test_readtags test_langinfer test_langdefparser_SOURCES = test_langdefparser_main.cpp -test_langmap_SOURCES = test_langmap_main.cpp langmap.cpp fileutil.cc messages.cc -test_textstyle_SOURCES = textstyle.cpp test_textstyle_main.cpp substfun.cpp -test_textgenerator_SOURCES = test_textgenerator_main.cpp textstylebuilder.cpp +test_langdefparser_LDADD = libcommon.la + +test_langmap_SOURCES = test_langmap_main.cpp +test_langmap_LDADD = langmap.$(OBJEXT) fileutil.$(OBJEXT) messages.$(OBJEXT) $(BOOST_REGEX_LIB) -test_outlangparser_SOURCES = textstyle.cpp test_outlangparser_main.cpp +test_textstyle_SOURCES = test_textstyle_main.cpp +test_textstyle_LDADD = $(BOOST_REGEX_LIB) textstyle.$(OBJEXT) substfun.$(OBJEXT) + +test_textgenerator_SOURCES = test_textgenerator_main.cpp +test_textgenerator_LDADD = libcommon.la textstylebuilder.$(OBJEXT) + +test_outlangparser_SOURCES = test_outlangparser_main.cpp test_outlangparser_DEPENDENCIES = outlangtest.outlang +test_outlangparser_LDADD = libcommon.la textstyle.$(OBJEXT) -test_readtags_SOURCES = test_readtags_main.cpp readtags.c readtags.h +test_readtags_SOURCES = test_readtags_main.cpp readtags.h test_readtags_DEPENDENCIES = mytags +test_readtags_LDADD = readtags.$(OBJEXT) test_langinfer_SOURCES = test_langinfer.cpp -test_langinfer_LDADD = libcommon.a -l$(BOOST_REGEX_LIB) +test_langinfer_LDADD = libcommon.la mytags: $(srcdir)/test_readtags_main.cpp - ctags --excmd=n --fields=+n -o mytags $(srcdir)/test_readtags_main.cpp $(srcdir)/readtags.h + $(CTAGS) --excmd=n --fields=+n -o mytags $(srcdir)/test_readtags_main.cpp $(srcdir)/readtags.h outlangtest.outlang: $(srcdir)/outlangtest.outlang.tmpl rm -f outlangtest.outlang cp -f $(srcdir)/outlangtest.outlang.tmpl outlangtest.outlang -DISTCLEANFILES = outlangtest.outlang mytags +DISTCLEANFILES = outlangtest.outlang mytags copyright.c reportbugs.c -MAINTAINERCLEANFILES = optparser.cc optparser.h optscanner.cc \ +MAINTAINERCLEANFILES = styleparser.cc styleparser.h stylescanner.cc \ langdefparser.cc langdefparser.h langdefscanner.cc \ outlangdefparser.cc outlangdefparser.h outlangdefscanner.cc noinst_HEADERS = parsestyles.h generatormap.h maingeneratormap.h outputbuffer.h \ - outputgenerator.h mainoutputbuffer.h lineoutputgenerator.h stringdef.h langelem.h \ - statelangelem.h langelems.h langdefparserfun.h outlangdefparserfun.h \ - tostringcollection.h regexpreprocessor.h regexpstatebuilder.h langdefloader.h \ - langdefscanner.h outlangdefscanner.h parsestruct.h langmap.h statestartlangelem.h \ - stringlistlangelem.h delimitedlangelem.h vardefinitions.h textformatter.h textstyle.h \ - textstyles.h textgenerator.h textstylebuilder.h doctemplate.h substfun.h \ - parserinfo.h refgeneratormap.h readtags.h fileinfo.h linebuffer.h preformatter.h \ - regexpstateprinter.h langelemsprinter.h languageinfer.h stopwatch.h - -test_langdefparser_LDADD = -l$(BOOST_REGEX_LIB) libcommon.a -test_langmap_LDADD = -l$(BOOST_REGEX_LIB) -test_textstyle_LDADD = -l$(BOOST_REGEX_LIB) -test_textgenerator_LDADD = -l$(BOOST_REGEX_LIB) libcommon.a -test_outlangparser_LDADD = -l$(BOOST_REGEX_LIB) libcommon.a + outputgenerator.h mainoutputbuffer.h lineoutputgenerator.h stringdef.h langelem.h \ + statelangelem.h langelems.h langdefparserfun.h outlangdefparserfun.h \ + tostringcollection.h regexpreprocessor.h regexpstatebuilder.h langdefloader.h \ + langdefscanner.h outlangdefscanner.h parsestruct.h langmap.h statestartlangelem.h \ + stringlistlangelem.h delimitedlangelem.h vardefinitions.h textformatter.h textstyle.h \ + textstyles.h textgenerator.h textstylebuilder.h doctemplate.h substfun.h \ + parserinfo.h refgeneratormap.h readtags.h fileinfo.h linebuffer.h preformatter.h \ + regexpstateprinter.h langelemsprinter.h languageinfer.h stopwatch.h stylekey.h + diff --git a/src/lib/cmdline.c b/src/lib/cmdline.c index c20fc56..a471a23 100644 --- a/src/lib/cmdline.c +++ b/src/lib/cmdline.c @@ -1,5 +1,5 @@ /* - File autogenerated by gengetopt version 2.18rc + File autogenerated by gengetopt version 2.19.1 generated with the following command: /home/bettini/usr/local/bin/gengetopt --input cmdline.ggo --unamed-opts --no-handle-help --no-handle-version @@ -25,6 +25,8 @@ const char *gengetopt_args_info_purpose = "Highlight the syntax of a source file const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]... [FILES]..."; +const char *gengetopt_args_info_description = ""; + const char *gengetopt_args_info_help[] = { " -h, --help Print help and exit", " -V, --version Print version and exit", @@ -42,6 +44,7 @@ const char *gengetopt_args_info_help[] = { " -H, --header=filename file to insert as header", " -F, --footer=filename file to insert as footer", " --style-file=filename specify the file containing format options \n (default=`default.style')", + " --style-css-file=filename specify the file containing format options (in \n css syntax)", " --outlang-def=filename output language definition file", " --outlang-map=filename output language map file \n (default=`outlang.map')", " --data-dir=path directory where language definition files and \n language maps are searched for. If not \n specified these files are searched for in the \n current directory and in the data dir \n installation directory", @@ -58,6 +61,7 @@ const char *gengetopt_args_info_help[] = { " --ctags=cmd how to run the ctags command. If this option \n is not specified, ctags will be executed with \n the default value. If it is specified with \n an empty string, ctags will not be executed \n at all (default=`ctags --excmd=n \n --tag-relative=yes')", "\ntesting:", " -v, --verbose verbose mode on", + " -q, --quiet print no progress information", " --statistics print some statistics (i.e., elapsed time)", " --gen-version put source-highlight version in the generated \n file (default=on)", " --check-lang=filename only check the correctness of a language \n definition file", @@ -102,6 +106,7 @@ void clear_given (struct gengetopt_args_info *args_info) args_info->header_given = 0 ; args_info->footer_given = 0 ; args_info->style_file_given = 0 ; + args_info->style_css_file_given = 0 ; args_info->outlang_def_given = 0 ; args_info->outlang_map_given = 0 ; args_info->data_dir_given = 0 ; @@ -116,6 +121,7 @@ void clear_given (struct gengetopt_args_info *args_info) args_info->ctags_file_given = 0 ; args_info->ctags_given = 0 ; args_info->verbose_given = 0 ; + args_info->quiet_given = 0 ; args_info->statistics_given = 0 ; args_info->gen_version_given = 0 ; args_info->check_lang_given = 0 ; @@ -148,6 +154,8 @@ void clear_args (struct gengetopt_args_info *args_info) args_info->footer_orig = NULL; args_info->style_file_arg = gengetopt_strdup ("default.style"); args_info->style_file_orig = NULL; + args_info->style_css_file_arg = NULL; + args_info->style_css_file_orig = NULL; args_info->outlang_def_arg = NULL; args_info->outlang_def_orig = NULL; args_info->outlang_map_arg = gengetopt_strdup ("outlang.map"); @@ -201,27 +209,29 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->header_help = gengetopt_args_info_help[13] ; args_info->footer_help = gengetopt_args_info_help[14] ; args_info->style_file_help = gengetopt_args_info_help[15] ; - args_info->outlang_def_help = gengetopt_args_info_help[16] ; - args_info->outlang_map_help = gengetopt_args_info_help[17] ; - args_info->data_dir_help = gengetopt_args_info_help[18] ; - args_info->output_dir_help = gengetopt_args_info_help[19] ; - args_info->lang_def_help = gengetopt_args_info_help[20] ; - args_info->lang_map_help = gengetopt_args_info_help[21] ; - args_info->show_lang_elements_help = gengetopt_args_info_help[22] ; - args_info->infer_lang_help = gengetopt_args_info_help[23] ; - args_info->line_number_help = gengetopt_args_info_help[25] ; - args_info->line_number_ref_help = gengetopt_args_info_help[26] ; - args_info->gen_references_help = gengetopt_args_info_help[27] ; - args_info->ctags_file_help = gengetopt_args_info_help[28] ; - args_info->ctags_help = gengetopt_args_info_help[29] ; - args_info->verbose_help = gengetopt_args_info_help[31] ; - args_info->statistics_help = gengetopt_args_info_help[32] ; - args_info->gen_version_help = gengetopt_args_info_help[33] ; - args_info->check_lang_help = gengetopt_args_info_help[34] ; - args_info->check_outlang_help = gengetopt_args_info_help[35] ; - args_info->failsafe_help = gengetopt_args_info_help[36] ; - args_info->debug_langdef_help = gengetopt_args_info_help[37] ; - args_info->show_regex_help = gengetopt_args_info_help[38] ; + args_info->style_css_file_help = gengetopt_args_info_help[16] ; + args_info->outlang_def_help = gengetopt_args_info_help[17] ; + args_info->outlang_map_help = gengetopt_args_info_help[18] ; + args_info->data_dir_help = gengetopt_args_info_help[19] ; + args_info->output_dir_help = gengetopt_args_info_help[20] ; + args_info->lang_def_help = gengetopt_args_info_help[21] ; + args_info->lang_map_help = gengetopt_args_info_help[22] ; + args_info->show_lang_elements_help = gengetopt_args_info_help[23] ; + args_info->infer_lang_help = gengetopt_args_info_help[24] ; + args_info->line_number_help = gengetopt_args_info_help[26] ; + args_info->line_number_ref_help = gengetopt_args_info_help[27] ; + args_info->gen_references_help = gengetopt_args_info_help[28] ; + args_info->ctags_file_help = gengetopt_args_info_help[29] ; + args_info->ctags_help = gengetopt_args_info_help[30] ; + args_info->verbose_help = gengetopt_args_info_help[32] ; + args_info->quiet_help = gengetopt_args_info_help[33] ; + args_info->statistics_help = gengetopt_args_info_help[34] ; + args_info->gen_version_help = gengetopt_args_info_help[35] ; + args_info->check_lang_help = gengetopt_args_info_help[36] ; + args_info->check_outlang_help = gengetopt_args_info_help[37] ; + args_info->failsafe_help = gengetopt_args_info_help[38] ; + args_info->debug_langdef_help = gengetopt_args_info_help[39] ; + args_info->show_regex_help = gengetopt_args_info_help[40] ; } @@ -241,6 +251,10 @@ cmdline_parser_print_help (void) printf("\n%s\n", gengetopt_args_info_purpose); printf("\n%s\n\n", gengetopt_args_info_usage); + + if (strlen(gengetopt_args_info_description) > 0) + printf("%s\n", gengetopt_args_info_description); + while (gengetopt_args_info_help[i]) printf("%s\n", gengetopt_args_info_help[i++]); } @@ -356,6 +370,16 @@ cmdline_parser_release (struct gengetopt_args_info *args_info) free (args_info->style_file_orig); /* free previous argument */ args_info->style_file_orig = 0; } + if (args_info->style_css_file_arg) + { + free (args_info->style_css_file_arg); /* free previous argument */ + args_info->style_css_file_arg = 0; + } + if (args_info->style_css_file_orig) + { + free (args_info->style_css_file_orig); /* free previous argument */ + args_info->style_css_file_orig = 0; + } if (args_info->outlang_def_arg) { free (args_info->outlang_def_arg); /* free previous argument */ @@ -618,6 +642,13 @@ cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_ fprintf(outfile, "%s\n", "style-file"); } } + if (args_info->style_css_file_given) { + if (args_info->style_css_file_orig) { + fprintf(outfile, "%s=\"%s\"\n", "style-css-file", args_info->style_css_file_orig); + } else { + fprintf(outfile, "%s\n", "style-css-file"); + } + } if (args_info->outlang_def_given) { if (args_info->outlang_def_orig) { fprintf(outfile, "%s=\"%s\"\n", "outlang-def", args_info->outlang_def_orig); @@ -704,6 +735,9 @@ cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_ if (args_info->verbose_given) { fprintf(outfile, "%s\n", "verbose"); } + if (args_info->quiet_given) { + fprintf(outfile, "%s\n", "quiet"); + } if (args_info->statistics_given) { fprintf(outfile, "%s\n", "statistics"); } @@ -874,6 +908,7 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf { "header", 1, NULL, 'H' }, { "footer", 1, NULL, 'F' }, { "style-file", 1, NULL, 0 }, + { "style-css-file", 1, NULL, 0 }, { "outlang-def", 1, NULL, 0 }, { "outlang-map", 1, NULL, 0 }, { "data-dir", 1, NULL, 0 }, @@ -888,6 +923,7 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf { "ctags-file", 1, NULL, 0 }, { "ctags", 1, NULL, 0 }, { "verbose", 0, NULL, 'v' }, + { "quiet", 0, NULL, 'q' }, { "statistics", 0, NULL, 0 }, { "gen-version", 0, NULL, 0 }, { "check-lang", 1, NULL, 0 }, @@ -899,7 +935,7 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf }; stop_char = 0; - c = getopt_long (argc, argv, "hVi:o:s:f:dc:T:t:H:F:nvg::", long_options, &option_index); + c = getopt_long (argc, argv, "hVi:o:s:f:dc:T:t:H:F:nvqg::", long_options, &option_index); if (c == -1) break; /* Exit from `while (1)' loop. */ @@ -1131,6 +1167,18 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf args_info->verbose_given = 1; break; + case 'q': /* print no progress information. */ + if (local_args_info.quiet_given) + { + fprintf (stderr, "%s: `--quiet' (`-q') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->quiet_given && ! override) + continue; + local_args_info.quiet_given = 1; + args_info->quiet_given = 1; + break; + case 'g': /* debug a language definition. In dump mode just dumps all the steps; in interactive, at each step, waits for some input (press ENTER to step). */ if (local_args_info.debug_langdef_given) { @@ -1220,6 +1268,25 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf free (args_info->style_file_orig); /* free previous string */ args_info->style_file_orig = gengetopt_strdup (optarg); } + /* specify the file containing format options (in css syntax). */ + else if (strcmp (long_options[option_index].name, "style-css-file") == 0) + { + if (local_args_info.style_css_file_given) + { + fprintf (stderr, "%s: `--style-css-file' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->style_css_file_given && ! override) + continue; + local_args_info.style_css_file_given = 1; + args_info->style_css_file_given = 1; + if (args_info->style_css_file_arg) + free (args_info->style_css_file_arg); /* free previous string */ + args_info->style_css_file_arg = gengetopt_strdup (optarg); + if (args_info->style_css_file_orig) + free (args_info->style_css_file_orig); /* free previous string */ + args_info->style_css_file_orig = gengetopt_strdup (optarg); + } /* output language definition file. */ else if (strcmp (long_options[option_index].name, "outlang-def") == 0) { diff --git a/src/lib/cmdline.ggo b/src/lib/cmdline.ggo index 3348042..e855554 100644 --- a/src/lib/cmdline.ggo +++ b/src/lib/cmdline.ggo @@ -49,6 +49,7 @@ option "tab" t "specify tab length." int default="8" no option "header" H "file to insert as header" string typestr="filename" no option "footer" F "file to insert as footer" string typestr="filename" no option "style-file" - "specify the file containing format options" string typestr="filename" default="default.style" no +option "style-css-file" - "specify the file containing format options (in css syntax)" string typestr="filename" optional option "outlang-def" - "output language definition file" string typestr="filename" no option "outlang-map" - "output language map file" string typestr="filename" default="outlang.map" no option "data-dir" - "directory where language definition files and language maps are searched for. If not specified these files are searched for in the current directory and in the data dir installation directory" string typestr="path" no @@ -67,6 +68,7 @@ option "ctags" - "how to run the ctags command. If this option is not spe section "testing" option "verbose" v "verbose mode on" optional +option "quiet" q "print no progress information" optional option "statistics" - "print some statistics (i.e., elapsed time)" optional option "gen-version" - "put source-highlight version in the generated file" flag on option "check-lang" - "only check the correctness of a language definition file" string typestr="filename" no diff --git a/src/lib/cmdline.h b/src/lib/cmdline.h index 152929f..cc28f14 100644 --- a/src/lib/cmdline.h +++ b/src/lib/cmdline.h @@ -1,6 +1,6 @@ /* cmdline.h */ -/* File autogenerated by gengetopt version 2.18rc */ +/* File autogenerated by gengetopt version 2.19.1 */ #ifndef CMDLINE_H #define CMDLINE_H @@ -60,6 +60,9 @@ struct gengetopt_args_info char * style_file_arg; /* specify the file containing format options (default='default.style'). */ char * style_file_orig; /* specify the file containing format options original value given at command line. */ const char *style_file_help; /* specify the file containing format options help description. */ + char * style_css_file_arg; /* specify the file containing format options (in css syntax). */ + char * style_css_file_orig; /* specify the file containing format options (in css syntax) original value given at command line. */ + const char *style_css_file_help; /* specify the file containing format options (in css syntax) help description. */ char * outlang_def_arg; /* output language definition file. */ char * outlang_def_orig; /* output language definition file original value given at command line. */ const char *outlang_def_help; /* output language definition file help description. */ @@ -96,6 +99,7 @@ struct gengetopt_args_info char * ctags_orig; /* how to run the ctags command. If this option is not specified, ctags will be executed with the default value. If it is specified with an empty string, ctags will not be executed at all original value given at command line. */ const char *ctags_help; /* how to run the ctags command. If this option is not specified, ctags will be executed with the default value. If it is specified with an empty string, ctags will not be executed at all help description. */ const char *verbose_help; /* verbose mode on help description. */ + const char *quiet_help; /* print no progress information help description. */ const char *statistics_help; /* print some statistics (i.e., elapsed time) help description. */ int gen_version_flag; /* put source-highlight version in the generated file (default=on). */ const char *gen_version_help; /* put source-highlight version in the generated file help description. */ @@ -129,6 +133,7 @@ struct gengetopt_args_info int header_given ; /* Whether header was given. */ int footer_given ; /* Whether footer was given. */ int style_file_given ; /* Whether style-file was given. */ + int style_css_file_given ; /* Whether style-css-file was given. */ int outlang_def_given ; /* Whether outlang-def was given. */ int outlang_map_given ; /* Whether outlang-map was given. */ int data_dir_given ; /* Whether data-dir was given. */ @@ -143,6 +148,7 @@ struct gengetopt_args_info int ctags_file_given ; /* Whether ctags-file was given. */ int ctags_given ; /* Whether ctags was given. */ int verbose_given ; /* Whether verbose was given. */ + int quiet_given ; /* Whether quiet was given. */ int statistics_given ; /* Whether statistics was given. */ int gen_version_given ; /* Whether gen-version was given. */ int check_lang_given ; /* Whether check-lang was given. */ diff --git a/src/lib/copyright.text b/src/lib/copyright.text index 94745f3..00c545a 100644 --- a/src/lib/copyright.text +++ b/src/lib/copyright.text @@ -1,4 +1,4 @@ -Copyright (C) 1999-2005 Lorenzo Bettini <http://www.lorenzobettini.it> +Copyright (C) 1999-2007 Lorenzo Bettini <http://www.lorenzobettini.it> This program comes with ABSOLUTELY NO WARRANTY. This is free software; you may redistribute copies of the program under the terms of the GNU General Public License. diff --git a/src/lib/docgenerator.cc b/src/lib/docgenerator.cc index ae6a544..72b6b1e 100644 --- a/src/lib/docgenerator.cc +++ b/src/lib/docgenerator.cc @@ -53,7 +53,8 @@ DocGenerator::generate_start_doc() "GNU " PACKAGE " " + string((gen_source_highlight_version ? VERSION : "")) + "\nby Lorenzo Bettini\nhttp://www.lorenzobettini.it\nhttp://www.gnu.org/software/src-highlite", doc_header, - doc_footer + doc_footer, + doc_background ) ); } @@ -67,7 +68,8 @@ DocGenerator::generate_end_doc() css_url, "\nby Lorenzo Bettini\nhttp://www.lorenzobettini.it\nhttp://www.gnu.org/software/src-highlite", doc_header, - doc_footer + doc_footer, + doc_background ) ); } diff --git a/src/lib/docgenerator.h b/src/lib/docgenerator.h index 924afe1..c2d1e60 100644 --- a/src/lib/docgenerator.h +++ b/src/lib/docgenerator.h @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999, 2000, 2001, 2002, 2003 Lorenzo Bettini <http://www.lorenzobettini.it> +** Copyright (C) 1999-2007 Lorenzo Bettini <http://www.lorenzobettini.it> ** ** 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 @@ -38,6 +38,7 @@ class DocGenerator string doc_header; string doc_footer; string css_url; + string doc_background; bool entire_doc; DocTemplate docTemplate; @@ -45,10 +46,11 @@ class DocGenerator public: DocGenerator(const string &s, const string &i, const string &h, const string &f, const string &c, + const string &back, bool entire, const string &start_tmpl, const string &end_tmpl) : title (s), gen_source_highlight_version (true), input_file_name (i), doc_header (h), - doc_footer (f), css_url (c), entire_doc (entire), + doc_footer (f), css_url (c), doc_background(back), entire_doc (entire), docTemplate(DocTemplate(start_tmpl, end_tmpl)) {} DocGenerator() {} ~DocGenerator() {} diff --git a/src/lib/doctemplate.cpp b/src/lib/doctemplate.cpp index 79d0b7f..c5d2dac 100644 --- a/src/lib/doctemplate.cpp +++ b/src/lib/doctemplate.cpp @@ -4,55 +4,72 @@ * Description: The template for a document containing the output of * highlighting * - * Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005 + * Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005-2007 * Copyright: See COPYING file that comes with this distribution */ #include "doctemplate.h" #include "substfun.h" +#define TITLE_VAR_TEXT "$title" // the text of the title variable +#define CSS_VAR_TEXT "$css" // the text of the css variable +#define ADDITIONAL_VAR_TEXT "$additional" // the text of the additional text variable +#define HEADER_VAR_TEXT "$header" // the text of the header variable +#define FOOTER_VAR_TEXT "$footer" // the text of the footer variable +#define BACKGROUND_VAR_TEXT "$docbgcolor" // the text of the background variable +#define TITLE_VAR "\\" TITLE_VAR_TEXT // the name of the title variable as regexp +#define CSS_VAR "\\" CSS_VAR_TEXT // the name of the css variable as regexp +#define ADDITIONAL_VAR "\\" ADDITIONAL_VAR_TEXT // the text of the additional text variable as regexp +#define HEADER_VAR "\\" HEADER_VAR_TEXT // the text of the header variable as regexp +#define FOOTER_VAR "\\" FOOTER_VAR_TEXT // the text of the footer variable as regexp +#define BACKGROUND_VAR "\\" BACKGROUND_VAR_TEXT // the text of the background variable as regexp + using namespace std; -DocTemplate::DocTemplate(const string &begin, const string &end) : +DocTemplate::DocTemplate(const string &begin, const string &end) : begin_repr(begin), end_repr(end) { } string DocTemplate::output_begin(const string &title, const string &cs, const string &add, - const string &header, const string &footer) + const string &header, const string &footer, const std::string &background) { boost::regex title_exp(TITLE_VAR); boost::regex css_exp(CSS_VAR); boost::regex additional_exp(ADDITIONAL_VAR); boost::regex header_exp(HEADER_VAR); boost::regex footer_exp(FOOTER_VAR); - + boost::regex background_exp(BACKGROUND_VAR); + string ret = subst(title_exp, begin_repr, title); ret = subst(css_exp, ret, cs); ret = subst(additional_exp, ret, add); ret = subst(header_exp, ret, header); ret = subst(footer_exp, ret, footer); - - return ret; + ret = subst(background_exp, ret, background); + + return ret; } string DocTemplate::output_end(const string &title, const string &cs, const string &add, - const string &header, const string &footer) + const string &header, const string &footer, const std::string &background) { boost::regex title_exp(TITLE_VAR); boost::regex css_exp(CSS_VAR); boost::regex additional_exp(ADDITIONAL_VAR); boost::regex header_exp(HEADER_VAR); boost::regex footer_exp(FOOTER_VAR); - + boost::regex background_exp(BACKGROUND_VAR); + string ret = subst(title_exp, end_repr, title); ret = subst(css_exp, ret, cs); ret = subst(additional_exp, ret, add); ret = subst(header_exp, ret, header); ret = subst(footer_exp, ret, footer); - - return ret; + ret = subst(background_exp, ret, background); + + return ret; } diff --git a/src/lib/doctemplate.h b/src/lib/doctemplate.h index 20f777e..6662985 100644 --- a/src/lib/doctemplate.h +++ b/src/lib/doctemplate.h @@ -4,7 +4,7 @@ * Description: The template for a document containing the output of * highlighting * - * Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005 + * Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2005-2007 * Copyright: See COPYING file that comes with this distribution */ @@ -13,27 +13,18 @@ #include <string> -#define TITLE_VAR_TEXT "$title" // the text of the title variable -#define CSS_VAR_TEXT "$css" // the text of the css variable -#define ADDITIONAL_VAR_TEXT "$additional" // the text of the additional text variable -#define HEADER_VAR_TEXT "$header" // the text of the header variable -#define FOOTER_VAR_TEXT "$footer" // the text of the footer variable -#define TITLE_VAR "\\" TITLE_VAR_TEXT // the name of the title variable as regexp -#define CSS_VAR "\\" CSS_VAR_TEXT // the name of the css variable as regexp -#define ADDITIONAL_VAR "\\" ADDITIONAL_VAR_TEXT // the text of the additional text variable as regexp -#define HEADER_VAR "\\" HEADER_VAR_TEXT // the text of the header variable as regexp -#define FOOTER_VAR "\\" FOOTER_VAR_TEXT // the text of the footer variable as regexp - class DocTemplate { std::string begin_repr, end_repr; public: DocTemplate(const std::string &begin = "", const std::string &end = ""); - - std::string output_begin(const std::string &title, const std::string &cs, - const std::string &add, const std::string &header, const std::string &footer); - std::string output_end(const std::string &title, const std::string &cs, - const std::string &add, const std::string &header, const std::string &footer); + + std::string output_begin(const std::string &title, const std::string &cs, + const std::string &add, const std::string &header, const std::string &footer, + const std::string &background); + std::string output_end(const std::string &title, const std::string &cs, + const std::string &add, const std::string &header, const std::string &footer, + const std::string &background); const std::string &toStringBegin() const { return begin_repr; } const std::string &toStringEnd() const { return end_repr; } diff --git a/src/lib/generatorfactory.cc b/src/lib/generatorfactory.cc index 70c2b0d..dcbb908 100644 --- a/src/lib/generatorfactory.cc +++ b/src/lib/generatorfactory.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 1999, 2000, 2001, 2002 Lorenzo Bettini <http://www.lorenzobettini.it> + * Copyright (C) 1999-2007 Lorenzo Bettini <http://www.lorenzobettini.it> * * 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 @@ -21,7 +21,6 @@ #include "generatorfactory.h" -#include "styles.h" #include "keys.h" #include "textgenerator.h" #include "textstyles.h" @@ -31,15 +30,18 @@ // global #include "maingeneratormap.h" -GeneratorFactory::GeneratorFactory(TextStylesPtr tstyles, Styles *sts, - PreFormatter *pf, - bool gen_ref, - const string &_ctags_file, RefPosition position) : - textStyles(tstyles), styles(sts), preformatter(pf), +GeneratorFactory::GeneratorFactory(TextStylesPtr tstyles, + PreFormatter *pf, + bool gen_ref, + const string &_ctags_file, RefPosition position, + bool optimizations) : + textStyles(tstyles), preformatter(pf), generate_references(gen_ref), ctags_file(_ctags_file), refposition(position), - noOptimizations(false) + noOptimizations(optimizations) { + generatormap = createGeneratorMap(); + generatormap->setNoOptimizations(noOptimizations); } GeneratorFactory::~ GeneratorFactory() @@ -58,58 +60,31 @@ GeneratorFactory::createGeneratorMap() return new GeneratorMap(preformatter); } -void -GeneratorFactory::createGenerators() +string GeneratorFactory::preprocessColor(const string &color) { - generatormap = createGeneratorMap(); - - generatormap->setNoOptimizations(noOptimizations); - - TextGenerator *text_gen; - for (Styles::const_iterator it = styles->begin(); it != styles->end(); ++it) - { - text_gen = createGenerator(*it); - generatormap->addGenerator((*it)->GetName(), text_gen); - } - - // set the normal generator as the default generator - TextGenerator *normal = createDefaultGenerator (); - generatormap->setDefaultGenerator(normal); -} - -TextGenerator * -GeneratorFactory::createDefaultGenerator() -{ - if (textStyles->onestyle.empty()) - return createGenerator (NORMAL); + if ( color[0] == '"' && color[color.size()-1] == '"') + return color.substr(1, color.size()-2); else - return new TextGenerator(textStyles->onestyle); + return textStyles->colorMap->getColor (color); } -TextGenerator * -GeneratorFactory::createGenerator( const string &key ) +bool GeneratorFactory::createGenerator(const string &key, const string &color, + const string &bgcolor, StyleConstantsPtr styleconstants) { - const Style *tag = styles->GetStyle( key ) ; - - if ( ! tag ) // no options - return new TextGenerator ; - - return createGenerator(tag); -} - -TextGenerator * -GeneratorFactory::createGenerator( const Style *tag ) -{ - if (! textStyles->onestyle.empty()) - return new TextGenerator(textStyles->onestyle.subst_style(tag->GetName())); + if (generatormap->hasGenerator(key)) + return false; + + if (! textStyles->onestyle.empty()) { + generatormap->addGenerator (key, new TextGenerator(textStyles->onestyle.subst_style(key))); + return true; + } TextStyleBuilder textStyleBuilder(textStyles->starting_template, textStyles->style_separator); textStyleBuilder.start(); - StyleConstantsPtr tagStyles = tag->getStyleConstants(); - if (tagStyles.get()) { - for (StyleConstantsIterator it = tagStyles->begin(); it != tagStyles->end(); ++it) { + if (styleconstants.get()) { + for (StyleConstantsIterator it = styleconstants->begin(); it != styleconstants->end(); ++it) { switch( *it ){ case ISBOLD: textStyleBuilder.add(textStyles->bold); @@ -127,25 +102,40 @@ GeneratorFactory::createGenerator( const Style *tag ) textStyleBuilder.add(textStyles->notfixed); break; case ISNOREF: - generatormap->addNoReference(tag->GetName()); + generatormap->addNoReference(key); break; } } } - const string &color = tag->GetColor() ; - if ( color.size () ) - { - string c; - if ( color[0] == '"' && color[color.size()-1] == '"') - c = color.substr(1, color.size()-2); - else - c = textStyles->colorMap->getColor (color); + if ( color.size () ) { + textStyleBuilder.add(textStyles->color.subst_style(preprocessColor(color))); + } - textStyleBuilder.add(textStyles->color.subst_style(c)); + if ( bgcolor.size () ) { + textStyleBuilder.add(textStyles->bg_color.subst_style(preprocessColor(bgcolor))); } TextStyle style = textStyleBuilder.end(); - return new TextGenerator(style); + generatormap->addGenerator(key, new TextGenerator(style)); + return true; } + +void GeneratorFactory::addDefaultGenerator() +{ + TextGenerator *defaultGenerator = generatormap->hasGenerator(NORMAL); + + if (!defaultGenerator) { + + if (textStyles->onestyle.empty()) + defaultGenerator = new TextGenerator(); + else + defaultGenerator = new TextGenerator(textStyles->onestyle.subst_style(NORMAL)); + + generatormap->addGenerator (NORMAL, defaultGenerator); + } + + generatormap->setDefaultGenerator(defaultGenerator); +} + diff --git a/src/lib/generatorfactory.h b/src/lib/generatorfactory.h index d4da4a8..b7da58a 100644 --- a/src/lib/generatorfactory.h +++ b/src/lib/generatorfactory.h @@ -1,5 +1,5 @@ /* -** Copyright (C) 1999, 2000, 2002 Lorenzo Bettini <http://www.lorenzobettini.it> +** Copyright (C) 1999-2007 Lorenzo Bettini <http://www.lorenzobettini.it> ** ** 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 @@ -23,13 +23,19 @@ #define GENERATORFACTORY_H #include <string> +#include <list> +#include <boost/shared_ptr.hpp> + #include "textstyles.h" #include "refgeneratormap.h" +typedef enum { ISBOLD=1, ISITALIC, ISUNDERLINE, ISFIXED, ISNOTFIXED, ISNOREF } StyleConstant; +typedef std::list<StyleConstant> StyleConstants; +typedef boost::shared_ptr<StyleConstants> StyleConstantsPtr; +typedef StyleConstants::const_iterator StyleConstantsIterator; + using std::string; -class Style; -class Styles; class TextGenerator; class PreFormatter; @@ -38,7 +44,6 @@ class GeneratorFactory protected: /// contains all the styles for formatting TextStylesPtr textStyles; - Styles *styles; /// to preformat text PreFormatter *preformatter; /// whether to generate references using ctags @@ -48,21 +53,43 @@ class GeneratorFactory /// whether to turn off optimizations for generating output (default false) bool noOptimizations; - TextGenerator *createGenerator(const string &key); - TextGenerator *createGenerator(const Style *style); - TextGenerator *createDefaultGenerator(); - GeneratorMap *createGeneratorMap(); public: - GeneratorFactory(TextStylesPtr tstyles, Styles *sts, PreFormatter *pf, + GeneratorFactory(TextStylesPtr tstyles, PreFormatter *pf, bool gen_references, - const string &ctags_file, RefPosition position); + const string &ctags_file, RefPosition position, + bool optimizations); + ~GeneratorFactory(); - void createGenerators(); + /** + * Creates a generator for the specific language element (identifed by + * key) with the passed style parameters + * + * @param key + * @param color + * @param bgcolor + * @param styleconstants + * @return false if a generator for the specific key is already present + */ + bool createGenerator(const string &key, const string &color, + const string &bgcolor, StyleConstantsPtr styleconstants); + + /** + * Adds the generator for the normal style if not already present. + * + * This must be called after all the generators for the language elements + */ + void addDefaultGenerator(); - void setNoOptimizations(bool n) { noOptimizations = n; } + /** + * Check whether the color must be translated with the color map or + * left as it is (in that case, remove the ") + * @param color + * @return + */ + string preprocessColor(const string &color); }; #endif // GENERATORFACTORY_H diff --git a/src/lib/generatormap.cpp b/src/lib/generatormap.cpp index 78a0c46..c7660e6 100644 --- a/src/lib/generatormap.cpp +++ b/src/lib/generatormap.cpp @@ -18,7 +18,7 @@ using namespace std; GeneratorMap::GeneratorMap(PreFormatter *pf) : - default_generator (new TextGenerator), + default_generator (0), preformatter(pf), noOptimizations(false) { } @@ -27,14 +27,11 @@ GeneratorMap::~GeneratorMap() { for (MapType::const_iterator it = generatormap.begin(); it != generatormap.end(); ++it) delete it->second; - delete default_generator; } void GeneratorMap::setDefaultGenerator(TextGenerator *gen) { - if (default_generator) - delete default_generator; default_generator = gen; } @@ -44,6 +41,15 @@ GeneratorMap::addGenerator(const std::string &elem, TextGenerator *gen) generatormap[elem] = gen; } +TextGenerator *GeneratorMap::hasGenerator(const string &elem) +{ + MapType::const_iterator it = generatormap.find(elem); + if (it == generatormap.end()) + return 0; + + return it->second; +} + TextGenerator * GeneratorMap::getGenerator(const string &elem) { diff --git a/src/lib/generatormap.h b/src/lib/generatormap.h index 8ea4450..b6fa977 100644 --- a/src/lib/generatormap.h +++ b/src/lib/generatormap.h @@ -53,6 +53,21 @@ class GeneratorMap GeneratorMap(PreFormatter *); virtual ~GeneratorMap(); + /** + * Returns the generator for the specific element name or null if + * there's no generator for the element + * @param elem + * @return + */ + TextGenerator *hasGenerator(const std::string &elem); + + /** + * Retrieves the generator for a specific element; if it doesn't find it, + * it creates a generator for that element, using the default generator + * (i.e., the one for "normal" element) + * @param elem + * @return + */ TextGenerator *getGenerator(const std::string &elem); void addGenerator(const std::string &elem, TextGenerator *gen); void addNoReference(const std::string &elem); diff --git a/src/lib/langdefparser.sed b/src/lib/langdefparser.sed deleted file mode 100644 index f6ab580..0000000 --- a/src/lib/langdefparser.sed +++ /dev/null @@ -1,56 +0,0 @@ -s/yymaxdepth/langdef_maxdepth/g -s/yyparse/langdef_parse/g -s/yylex/langdef_lex/g -s/yyerror/langdef_error/g -s/yylval/langdef_lval/g -s/yychar/langdef_char/g -s/yydebug/langdef_debug/g -s/yypact/langdef_pact/g -s/yydef/langdef_def/g -s/yychk/langdef_chk/g -s/yypgo/langdef_pgo/g -s/yyact/langdef_act/g -s/yyexca/langdef_exac/g -s/yyerrflag/langdef_errflag/g -s/yynerrs/langdef_nerrs/g -s/yyps/langdef_ps/g -s/yypv/langdef_pv/g -s/yys/langdef_s/g -s/yy_yys/langdef_yys/g -s/yystate/langdef_state/g -s/yytmp/langdef_tmp/g -s/yyv/langdef_v/g -s/yy_yyv/langdef_yyv/g -s/yyval/langdef_val/g -s/yylloc/langdef_lloc/g -s/yyreds/langdef_reds/g -s/yytoks/langdef_toks/g -s/yylhs/langdef_lhs/g -s/yylen/langdef_len/g -s/yydefred/langdef_defred/g -s/yydgoto/langdef_dgoto/g -s/yysindex/langdef_sindex/g -s/yyrindex/langdef_rindex/g -s/yygindex/langdef_gindex/g -s/yytable/langdef_table/g -s/yycheck/langdef_check/g -s/yyname/langdef_name/g -s/yyrule/langdef_rule/g - -s/yy_create_buffer/langdef_create_buffer/g -s/yy_scan_buffer/langdef_scan_buffer/g -s/yy_scan_string/langdef_scan_string/g -s/yy_scan_bytes/langdef_scan_bytes/g -s/yy_delete_buffer/langdef_delete_buffer/g -s/yy_init_buffer/langdef_init_buffer/g -s/yy_load_buffer_state/langdef_load_buffer_state/g -s/yy_buffer_state/langdef_buffer_state/g -s/yy_switch_to_buffer/langdef_switch_to_buffer/g - -s/yyin/langdef_in/g -s/yyleng/langdef_leng/g -s/yyout/langdef_out/g -s/yyrestart/langdef_restart/g -s/yytext/langdef_text/g -s/yylineno/langdef_lineno/g - diff --git a/src/lib/langdefscanner.ll b/src/lib/langdefscanner.ll index caabc1a..6104bab 100644 --- a/src/lib/langdefscanner.ll +++ b/src/lib/langdefscanner.ll @@ -35,9 +35,6 @@ #define DEB2(s,s2) #endif -#define PUSH(s) yy_push_state(s); -#define POP() yy_pop_state(); - static std::ostringstream buff; static void buffer(const char *s); @@ -72,8 +69,6 @@ IDE [a-zA-Z_]([a-zA-Z0-9_])* STRING \"[^\n"]+\" -%option stack - %s COMMENT_STATE STRING_STATE REGEXP_STATE INCLUDE_STATE %% @@ -104,6 +99,8 @@ STRING \"[^\n"]+\" <INITIAL>"include" { BEGIN(INCLUDE_STATE); } <INCLUDE_STATE>{STRING} { + DEB2("inclusion of ", yytext); + char *file_name = &yytext[1]; file_name[strlen(file_name)-1] = '0円'; @@ -115,6 +112,8 @@ STRING \"[^\n"]+\" } <<EOF>> { + DEB("END OF FILE"); + fclose(langdef_in); yypop_buffer_state(); diff --git a/src/lib/langdefscanner.sed b/src/lib/langdefscanner.sed deleted file mode 100644 index 41ba222..0000000 --- a/src/lib/langdefscanner.sed +++ /dev/null @@ -1,58 +0,0 @@ -s/yymaxdepth/langdef_maxdepth/g -s/yyparse/langdef_parse/g -s/yylex/langdef_lex/g -s/yyerror/langdef_error/g -s/yylval/langdef_lval/g -s/yychar/langdef_char/g -s/yydebug/langdef_debug/g -s/yypact/langdef_pact/g -s/yydef/langdef_def/g -s/yychk/langdef_chk/g -s/yypgo/langdef_pgo/g -s/yyact/langdef_act/g -s/yyexca/langdef_exac/g -s/yyerrflag/langdef_errflag/g -s/yynerrs/langdef_nerrs/g -s/yyps/langdef_ps/g -s/yypv/langdef_pv/g -s/yys/langdef_s/g -s/yy_yys/langdef_yys/g -s/yystate/langdef_state/g -s/yytmp/langdef_tmp/g -s/yyv/langdef_v/g -s/yy_yyv/langdef_yyv/g -s/yyval/langdef_val/g -s/yylloc/langdef_lloc/g -s/yyreds/langdef_reds/g -s/yytoks/langdef_toks/g -s/yylhs/langdef_lhs/g -s/yylen/langdef_len/g -s/yydefred/langdef_defred/g -s/yydgoto/langdef_dgoto/g -s/yysindex/langdef_sindex/g -s/yyrindex/langdef_rindex/g -s/yygindex/langdef_gindex/g -s/yytable/langdef_table/g -s/yycheck/langdef_check/g -s/yyname/langdef_name/g -s/yyrule/langdef_rule/g - -s/yy_create_buffer/langdef_create_buffer/g -s/yy_scan_buffer/langdef_scan_buffer/g -s/yy_scan_string/langdef_scan_string/g -s/yy_scan_bytes/langdef_scan_bytes/g -s/yy_delete_buffer/langdef_delete_buffer/g -s/yy_init_buffer/langdef_init_buffer/g -s/yy_load_buffer_state/langdef_load_buffer_state/g -s/yy_buffer_state/langdef_buffer_state/g -s/yy_switch_to_buffer/langdef_switch_to_buffer/g - -s/yyin/langdef_in/g -s/yyleng/langdef_leng/g -s/yyout/langdef_out/g -s/yyrestart/langdef_restart/g -s/yytext/langdef_text/g -s/yylineno/langdef_lineno/g - -s/yy/langdef_/g - diff --git a/src/lib/messages.cc b/src/lib/messages.cc index 319218c..b5439af 100644 --- a/src/lib/messages.cc +++ b/src/lib/messages.cc @@ -91,3 +91,8 @@ void foundBug(const std::string &error, const std::string &file, int line) cerr << PACKAGE << ": " << error << ", " << file << ":" << line << endl; exit(EXIT_FAILURE); } + +bool shouldPrint() +{ + return (_messager && !_messager->dontPrint); +} diff --git a/src/lib/messages.h b/src/lib/messages.h index 9dd8650..833aa72 100644 --- a/src/lib/messages.h +++ b/src/lib/messages.h @@ -5,6 +5,7 @@ #include <iostream> #include <string> +#include <iterator> using std::ostream; using std::cerr; @@ -12,6 +13,9 @@ using std::endl; class Messages { public: + /// whether to print anything + bool dontPrint; + virtual void printMessage( const char *s, ostream & stream = cerr ) = 0 ; virtual void printMessage( const std::string &s, ostream & stream = cerr ) = 0 ; @@ -21,7 +25,8 @@ class Messages { ostream & stream = cerr ) = 0 ; virtual void printWarning( const char *s, ostream & stream = cerr ) = 0 ; virtual void printError( const char *s, ostream & stream = cerr ) = 0 ; - + + Messages(bool dontPrint_ = true) : dontPrint(dontPrint_) {} virtual ~Messages() {} } ; @@ -49,6 +54,8 @@ class DefaultMessages : public Messages { { _print(s,stream); } virtual void printError( const char *s, ostream &stream ) { _print(s,stream); } + + DefaultMessages() : Messages(false) {} } ; // prefer functions? ;-) @@ -63,7 +70,18 @@ void printError(const std::string &filename, unsigned int line, const std::strin void memory_exhausted(); void exitError(const std::string &error); void foundBug(const std::string &error, const std::string &file, int line); +bool shouldPrint(); void setMessager( Messages *m ) ; +template <class T> +void printSequence( const T *seq, ostream & stream = cerr ) +{ + if (shouldPrint() && seq) { + std::copy(seq->begin(), seq->end(), + std::ostream_iterator<typename T::value_type>(stream, " ")); + } +} + + #endif // _MESSAGES_H diff --git a/src/lib/optparser.sed b/src/lib/optparser.sed deleted file mode 100644 index 5896e43..0000000 --- a/src/lib/optparser.sed +++ /dev/null @@ -1,56 +0,0 @@ -s/yymaxdepth/opsc_maxdepth/g -s/yyparse/opsc_parse/g -s/yylex/opsc_lex/g -s/yyerror/opsc_error/g -s/yylval/opsc_lval/g -s/yychar/opsc_char/g -s/yydebug/opsc_debug/g -s/yypact/opsc_pact/g -s/yydef/opsc_def/g -s/yychk/opsc_chk/g -s/yypgo/opsc_pgo/g -s/yyact/opsc_act/g -s/yyexca/opsc_exac/g -s/yyerrflag/opsc_errflag/g -s/yynerrs/opsc_nerrs/g -s/yyps/opsc_ps/g -s/yypv/opsc_pv/g -s/yys/opsc_s/g -s/yy_yys/opsc_yys/g -s/yystate/opsc_state/g -s/yytmp/opsc_tmp/g -s/yyv/opsc_v/g -s/yy_yyv/opsc_yyv/g -s/yyval/opsc_val/g -s/yylloc/opsc_lloc/g -s/yyreds/opsc_reds/g -s/yytoks/opsc_toks/g -s/yylhs/opsc_lhs/g -s/yylen/opsc_len/g -s/yydefred/opsc_defred/g -s/yydgoto/opsc_dgoto/g -s/yysindex/opsc_sindex/g -s/yyrindex/opsc_rindex/g -s/yygindex/opsc_gindex/g -s/yytable/opsc_table/g -s/yycheck/opsc_check/g -s/yyname/opsc_name/g -s/yyrule/opsc_rule/g - -s/yy_create_buffer/opsc_create_buffer/g -s/yy_scan_buffer/opsc_scan_buffer/g -s/yy_scan_string/opsc_scan_string/g -s/yy_scan_bytes/opsc_scan_bytes/g -s/yy_delete_buffer/opsc_delete_buffer/g -s/yy_init_buffer/opsc_init_buffer/g -s/yy_load_buffer_state/opsc_load_buffer_state/g -s/yy_buffer_state/opsc_buffer_state/g -s/yy_switch_to_buffer/opsc_switch_to_buffer/g - -s/yyin/opsc_in/g -s/yyleng/opsc_leng/g -s/yyout/opsc_out/g -s/yyrestart/opsc_restart/g -s/yytext/opsc_text/g -s/yylineno/opsc_lineno/g - diff --git a/src/lib/optscanner.ll b/src/lib/optscanner.ll deleted file mode 100644 index 5379535..0000000 --- a/src/lib/optscanner.ll +++ /dev/null @@ -1,130 +0,0 @@ -%{ -/* - * Copyright (C) 1999, 2000, Lorenzo Bettini, http://www.lorenzobettini.it - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include <stdlib.h> - -#include "styles.h" - -#include "optparser.h" -#include "my_sstream.h" -#include "messages.h" -#include "parsestyles.h" - -static std::ostringstream buff; - -extern int line ; - -#define PUSH(s) yy_push_state(s); -#define POP() yy_pop_state(); - -static void buffer(const char *s); -static const std::string *flush_buffer(); - -%} - -%option prefix="opsc_" -%option noyywrap - -ws [ ]+ -tabs [\t]+ - -nl \n -cr \r -IDE [a-zA-Z_]([a-zA-Z0-9_])* - -STRING \"[^\"\n]*\" - -%option stack - -%s COMMENT_STATE STRING_STATE - -%% - -{ws}|{tabs} {} - -\r {} - -<INITIAL>"//" { PUSH(COMMENT_STATE); } -<COMMENT_STATE>[^\n] {} -<COMMENT_STATE>\n { ++line; POP(); } - -<INITIAL>"green" | -"red" | -"darkred" | -"blue" | -"brown" | -"pink" | -"yellow" | -"cyan" | -"purple" | -"orange" | -"brightorange" | -"darkgreen" | -"brightgreen" | -"black" | -"teal" | -"gray" | -"darkblue" { opsc_lval.string = new std::string(yytext) ; return COLOR ; } - -<INITIAL>\#[a-fA-F0-9]{6} { - const std::string wrong = yytext ; - parseStyleError("use of direct colors has changed"); - parseStyleError("use double quoted syntax: \"" + wrong + "\" instead of " + wrong); - exit(EXIT_FAILURE); - return COLOR ; -} - -<INITIAL>"b" { opsc_lval.flag = ISBOLD ; return BOLD ; } -<INITIAL>"i" { opsc_lval.flag = ISITALIC ; return ITALICS ; } -<INITIAL>"u" { opsc_lval.flag = ISUNDERLINE ; return UNDERLINE ; } -<INITIAL>"f" { opsc_lval.flag = ISFIXED; return FIXED; } -<INITIAL>"nf" { opsc_lval.flag = ISNOTFIXED; return NOTFIXED; } -<INITIAL>"noref" { opsc_lval.flag = ISNOREF; return NOREF; } - -<INITIAL>"," { return ',' ; } -<INITIAL>";" { return ';' ; } - -<INITIAL>{IDE} { opsc_lval.string = new std::string(yytext) ; return KEY ; } - -<INITIAL>\" { BEGIN(STRING_STATE); buffer( yytext ) ; } -<STRING_STATE>\\\\ { buffer( yytext ) ; } -<STRING_STATE>"\\\"" { buffer( "\"" ) ; } -<STRING_STATE>\" { BEGIN(INITIAL) ; buffer( yytext ) ; opsc_lval.string = flush_buffer() ; return STRINGDEF; } -<STRING_STATE>[^\n]|" " { buffer( yytext ) ; } -<STRING_STATE>\n { buffer( "\n" ) ; } - -\n { ++line ; } - -<INITIAL>. { return yytext[0] ; } - -%% - -void buffer(const char *s) -{ - buff << s; -} - -const std::string *flush_buffer() -{ - const std::string *ret = new std::string(buff.str()); - buff.str(""); - return ret; -} - diff --git a/src/lib/optscanner.sed b/src/lib/optscanner.sed deleted file mode 100644 index 5896e43..0000000 --- a/src/lib/optscanner.sed +++ /dev/null @@ -1,56 +0,0 @@ -s/yymaxdepth/opsc_maxdepth/g -s/yyparse/opsc_parse/g -s/yylex/opsc_lex/g -s/yyerror/opsc_error/g -s/yylval/opsc_lval/g -s/yychar/opsc_char/g -s/yydebug/opsc_debug/g -s/yypact/opsc_pact/g -s/yydef/opsc_def/g -s/yychk/opsc_chk/g -s/yypgo/opsc_pgo/g -s/yyact/opsc_act/g -s/yyexca/opsc_exac/g -s/yyerrflag/opsc_errflag/g -s/yynerrs/opsc_nerrs/g -s/yyps/opsc_ps/g -s/yypv/opsc_pv/g -s/yys/opsc_s/g -s/yy_yys/opsc_yys/g -s/yystate/opsc_state/g -s/yytmp/opsc_tmp/g -s/yyv/opsc_v/g -s/yy_yyv/opsc_yyv/g -s/yyval/opsc_val/g -s/yylloc/opsc_lloc/g -s/yyreds/opsc_reds/g -s/yytoks/opsc_toks/g -s/yylhs/opsc_lhs/g -s/yylen/opsc_len/g -s/yydefred/opsc_defred/g -s/yydgoto/opsc_dgoto/g -s/yysindex/opsc_sindex/g -s/yyrindex/opsc_rindex/g -s/yygindex/opsc_gindex/g -s/yytable/opsc_table/g -s/yycheck/opsc_check/g -s/yyname/opsc_name/g -s/yyrule/opsc_rule/g - -s/yy_create_buffer/opsc_create_buffer/g -s/yy_scan_buffer/opsc_scan_buffer/g -s/yy_scan_string/opsc_scan_string/g -s/yy_scan_bytes/opsc_scan_bytes/g -s/yy_delete_buffer/opsc_delete_buffer/g -s/yy_init_buffer/opsc_init_buffer/g -s/yy_load_buffer_state/opsc_load_buffer_state/g -s/yy_buffer_state/opsc_buffer_state/g -s/yy_switch_to_buffer/opsc_switch_to_buffer/g - -s/yyin/opsc_in/g -s/yyleng/opsc_leng/g -s/yyout/opsc_out/g -s/yyrestart/opsc_restart/g -s/yytext/opsc_text/g -s/yylineno/opsc_lineno/g - diff --git a/src/lib/outlangdefparser.yy b/src/lib/outlangdefparser.yy index 1215810..4c8a28c 100644 --- a/src/lib/outlangdefparser.yy +++ b/src/lib/outlangdefparser.yy @@ -56,7 +56,7 @@ const char *anchor_vars[] = {"linenum", "infilename", "infile", 0}; }; %token <tok> BEGIN_T END_T DOC_TEMPLATE_T STYLE_TEMPLATE_T STYLE_SEPARATOR_T -%token <tok> BOLD_T ITALICS_T UNDERLINE_T COLOR_T FIXED_T NOTFIXED_T +%token <tok> BOLD_T ITALICS_T UNDERLINE_T COLOR_T BG_COLOR_T FIXED_T NOTFIXED_T %token <tok> COLORMAP_T DEFAULT_T ONESTYLE_T TRANSLATIONS_T EXTENSION_T ANCHOR_T %token <tok> REFERENCE_T INLINE_REFERENCE_T POSTLINE_REFERENCE_T POSTDOC_REFERENCE_T %token <string> KEY STRINGDEF REGEXDEF LINE_PREFIX_T @@ -126,6 +126,12 @@ outputlangdef : DOC_TEMPLATE_T STRINGDEF STRINGDEF END_T delete 2ドル; } | + BG_COLOR_T STRINGDEF +{ + textstyles->bg_color = *2ドル; + delete 2ドル; +} +| ONESTYLE_T STRINGDEF { textstyles->onestyle = *2ドル; diff --git a/src/lib/outlangdefscanner.ll b/src/lib/outlangdefscanner.ll index 1afa59f..d06bfa6 100644 --- a/src/lib/outlangdefscanner.ll +++ b/src/lib/outlangdefscanner.ll @@ -90,6 +90,7 @@ STRING \"[^\n"]+\" <INITIAL>"notfixed" { return NOTFIXED_T ; } <INITIAL>"fixed" { return FIXED_T ; } <INITIAL>"colormap" { return COLORMAP_T ; } +<INITIAL>"bgcolor" { return BG_COLOR_T ; } <INITIAL>"color" { return COLOR_T ; } <INITIAL>"default" { return DEFAULT_T ; } <INITIAL>"onestyle" { return ONESTYLE_T ; } diff --git a/src/lib/parsestyles.h b/src/lib/parsestyles.h index d61f0a2..a753917 100644 --- a/src/lib/parsestyles.h +++ b/src/lib/parsestyles.h @@ -1,10 +1,10 @@ // // C++ Interface: parsestyles // -// Description: +// Description: declaration of function for parsing style files // // -// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004 +// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2007 // // Copyright: See COPYING file that comes with this distribution // @@ -13,9 +13,17 @@ #ifndef PARSESTYLES_H #define PARSESTYLES_H -#include "styles.h" +class GeneratorFactory; -Styles *parseStyles(const std::string &path, const std::string &name) ; +/// for style files +void parseStyles(const std::string &path, const std::string &name, + GeneratorFactory *generatorFactory, + std::string &bodyBgColor) ; void parseStyleError(const std::string &error) ; +/// for css style files +void parseCssStyles(const std::string &path, const std::string &name, + GeneratorFactory *generatorFactory, + std::string &bodyBgColor) ; + #endif diff --git a/src/lib/readtags.c b/src/lib/readtags.c index 323d2c0..8cc0291 100644 --- a/src/lib/readtags.c +++ b/src/lib/readtags.c @@ -1,5 +1,5 @@ /* -* $Id: readtags.c,v 1.6 2006年10月05日 17:25:40 bettini Exp $ +* $Id: readtags.c,v 1.7 2007年03月23日 18:13:11 bettini Exp $ * * Copyright (c) 1996-2003, Darren Hiebert * diff --git a/src/lib/readtags.h b/src/lib/readtags.h index 398a3b9..ce32611 100644 --- a/src/lib/readtags.h +++ b/src/lib/readtags.h @@ -1,5 +1,5 @@ /* -* $Id: readtags.h,v 1.6 2006年10月05日 17:25:40 bettini Exp $ +* $Id: readtags.h,v 1.7 2007年03月23日 18:13:11 bettini Exp $ * * Copyright (c) 1996-2003, Darren Hiebert * diff --git a/src/lib/strdup.c b/src/lib/strdup.c deleted file mode 100644 index dc26788..0000000 --- a/src/lib/strdup.c +++ /dev/null @@ -1,14 +0,0 @@ -/* a replacement for strdup function, if it's not in std lib */ - -#include <stdlib.h> -#include <string.h> - -char * -strdup( const char *s ) -{ - char *result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} diff --git a/src/lib/stylecssparser.yy b/src/lib/stylecssparser.yy new file mode 100644 index 0000000..86b8659 --- /dev/null +++ b/src/lib/stylecssparser.yy @@ -0,0 +1,232 @@ +%{ +/* + * Copyright (C) 1999-2007 Lorenzo Bettini <http://www.lorenzobettini.it> + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <iostream> +#include <string> + +#include "my_sstream.h" + +#include "generatorfactory.h" +#include "colors.h" +#include "keys.h" +#include "messages.h" +#include "parsestyles.h" +#include "fileutil.h" +#include "stylekey.h" +#include "utils.h" + +using std::cerr; + +static int yyparse() ; +static void yyerror( char *s ) ; + +// line is defined in styleparser + +// to generate the generator for each language element +static GeneratorFactory *generatorFactory; + +static void updateBgColor(const std::string &c); + +// for the background color of the entire output +static string bodyBgColor; + +extern int stylecsssc_lex() ; +extern FILE *stylecsssc_in ; + +/// the global pointer to style constant for a specific element +static StyleConstantsPtr currentStyleConstants; +/// the global pointer to the current color +static string currentColor; +/// the global pointer to the current bg color +static string currentBGColor; + +%} + +%union { + int tok ; /* command */ + const std::string * string ; /* string : id, ... */ + StyleConstant flag ; + StyleConstants *styleconstants; + KeyList *keylist; +} ; + +%token <flag> BOLD ITALICS UNDERLINE FIXED NOTFIXED NOREF +%token <string> KEY COLOR BG_COLOR STRINGDEF BG_STRINGDEF + +%type <keylist> keylist + +%% + +stylefile : { /* allow empty files */ } + | statements + ; + +statements : statements statement + | statement + ; + +statement : option + ; + +option : keylist + { + printSequence( 1ドル ) ; + printMessage_noln( ": " ) ; + currentStyleConstants = StyleConstantsPtr(new StyleConstants); + currentColor = ""; + currentBGColor = ""; + } + optionspecs ';' + { + printMessage_noln(" color: " + currentColor + " ") ; + if (currentBGColor != "") + printMessage_noln(" bg color: " + currentBGColor + " ") ; + printMessage(""); + + KeyType key; + KeyList *keylist = 1ドル; + for (KeyList::const_iterator it = keylist->begin(); it != keylist->end(); ++it) { + key = *it; + // check whether it's the body specification + if (Utils::tolower(key) == "body") { + updateBgColor(currentBGColor); + + // notice that for text style specification for the body, the background + // is assumed for the entire document and not for the normal text + // following the semantics of css + + // avoid adding an empty style definition for normal + if (currentColor != "" || currentStyleConstants->size()) { + if (!generatorFactory->createGenerator(NORMAL, currentColor, "", currentStyleConstants)) { + parseStyleError(key); + yyerror("already defined"); + } + } + } else { + if (!generatorFactory->createGenerator(key, currentColor, currentBGColor, currentStyleConstants)) { + parseStyleError(key); + yyerror("already defined"); + } + } + } + delete keylist; + } + ; + +keylist : keylist ',' KEY + { + 1ドル->push_back(*3ドル); + $$ = 1ドル; + delete 3ドル; + } + | KEY + { + $$ = new KeyList; + $$->push_back(*1ドル); + delete 1ドル; + } + ; + +optionspecs : {} + | optionspecs optionspec + ; + +optionspec : color + | bgcolor + | styleconstant + ; + +color : COLOR + { + currentColor = *1ドル; + delete 1ドル; + } + | STRINGDEF + { + currentColor = *1ドル; + delete 1ドル; + } + ; + +bgcolor : BG_COLOR + { + currentBGColor = *1ドル; + delete 1ドル; + } + | BG_STRINGDEF + { + currentBGColor = *1ドル; + delete 1ドル; + } + ; + +styleconstant : BOLD { printMessage_noln( " bold" ) ; currentStyleConstants->push_back(ISBOLD); } + | ITALICS { printMessage_noln( " italics" ) ; currentStyleConstants->push_back(ISITALIC); } + | UNDERLINE { printMessage_noln( " underline" ) ; currentStyleConstants->push_back(ISUNDERLINE); } + | FIXED { printMessage_noln( " fixed" ) ; currentStyleConstants->push_back(ISFIXED); } + | NOTFIXED { printMessage_noln( " notfixed" ) ; currentStyleConstants->push_back(ISNOTFIXED); } + | NOREF { printMessage_noln( " noref" ) ; currentStyleConstants->push_back(ISNOREF); } + ; + +%% + +// string current_file; defined in styleparser + +extern string current_file; + +void parseCssStyles(const string &path, const string &name, GeneratorFactory *genFactory, + string &bodyBgColor_) +{ + generatorFactory = genFactory; + // opens the file for yylex + stylecsssc_in = open_data_file_stream(path, name); + + current_file = (path.size() ? path + "/" : "") + name; + + printMessage_noln( "Parsing ", cerr ) ; + printMessage_noln (current_file, cerr); + printMessage( " file ...", cerr ) ; + + bodyBgColor = ""; + + yyparse() ; + + bodyBgColor_ = bodyBgColor; + + printMessage( "Parsing done!", cerr ) ; + fclose(stylecsssc_in); +} + +void +yyerror( char *s ) +{ + parseStyleError(s); + exit(EXIT_FAILURE); +} + +void updateBgColor(const std::string &c) +{ + if (bodyBgColor != "") + yyerror("bgcolor already defined"); + else + bodyBgColor = c; +} diff --git a/src/lib/stylecssscanner.ll b/src/lib/stylecssscanner.ll new file mode 100644 index 0000000..1806907 --- /dev/null +++ b/src/lib/stylecssscanner.ll @@ -0,0 +1,223 @@ +%{ +/* + * Copyright (C) 1999-2007 Lorenzo Bettini, http://www.lorenzobettini.it + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdlib.h> +#include <string.h> + +#include "generatorfactory.h" +#include "stylekey.h" + +#include "stylecssparser.h" +#include "my_sstream.h" +#include "messages.h" +#include "parsestyles.h" + +static std::ostringstream buff; + +extern int line ; + +//#define DEBUG_SCANNER +#ifdef DEBUG_SCANNER +#include <iostream> // for debug +#define DEB(s) std::cerr << s << std::endl; +#define DEB2(s,s2) std::cerr << s << ": " << s2 << std::endl; +#else +#define DEB(s) +#define DEB2(s,s2) +#endif + + +%} + +%option prefix="stylecsssc_" +%option noyywrap + +ws [ ]+ +tabs [\t]+ + +nl \n +cr \r +IDE [a-zA-Z_]([a-zA-Z0-9_])* + +VALUE [^\n\r:;[:blank:]]+ + +STRING \"[^\"\n]*\" + +%s COMMENT_STATE MULTI_COMMENT_STATE STRING_STATE CSS_SELECTOR CSS_PROPERTIES CSS_COLOR CSS_BG_COLOR CSS_FONT_WEIGHT CSS_FONT_STYLE CSS_FONT_FAMILY CSS_TEXT_DECORATION + +%% + +{ws}|{tabs} {} + +\r {} + +"/*" { BEGIN(MULTI_COMMENT_STATE); } +<MULTI_COMMENT_STATE>[^\n] {} +<MULTI_COMMENT_STATE>\n { ++line; BEGIN(INITIAL); } + + +<CSS_SELECTOR>"," { return ',' ; } +<CSS_SELECTOR>{IDE} { stylecsssc_lval.string = new std::string(yytext) ; return KEY ; } + +\n { ++line ; } + +<INITIAL>\. { + BEGIN(CSS_SELECTOR) ; + DEB("CSS SELECTOR"); +} +<INITIAL>[bB][oO][dD][yY] { + BEGIN(CSS_SELECTOR) ; + DEB("BODY CSS SELECTOR"); + stylecsssc_lval.string = new std::string(yytext) ; + return KEY; +} + +<CSS_SELECTOR>\. { + // in case of comma separated selectors + DEB("CSS SELECTOR"); +} +<CSS_SELECTOR>"{" { + BEGIN(CSS_PROPERTIES); + DEB("CSS PROPERTIES"); +} +<CSS_PROPERTIES>"color" { + BEGIN(CSS_COLOR); + DEB("CSS COLOR"); +} +<CSS_COLOR>"green"|"red"|"darkred"|"blue"|"brown"|"pink"|"yellow"|"cyan"|"purple"|"orange"|"brightorange"|"darkgreen"|"brightgreen"|"black"|"teal"|"gray"|"darkblue" { + BEGIN(CSS_PROPERTIES); + stylecsssc_lval.string = new std::string(yytext) ; + DEB2("CSS COLOR", yytext); + return COLOR ; +} +<CSS_COLOR>[#[:alnum:]]+ { + BEGIN(CSS_PROPERTIES); + DEB2("CSS COLOR", yytext); + /* + we need to add the " in order to make source-highlight realize + that this is a direct color specification + */ + stylecsssc_lval.string = new std::string("\"" + std::string(yytext) + "\""); + return STRINGDEF; +} +<CSS_PROPERTIES>"background-color" { + BEGIN(CSS_BG_COLOR); + DEB("CSS BACKGROUND COLOR"); +} +<CSS_BG_COLOR>"green"|"red"|"darkred"|"blue"|"brown"|"pink"|"yellow"|"cyan"|"purple"|"orange"|"brightorange"|"darkgreen"|"brightgreen"|"black"|"teal"|"gray"|"darkblue" { + BEGIN(CSS_PROPERTIES); + stylecsssc_lval.string = new std::string(yytext) ; + DEB2("CSS BG COLOR", yytext); + return BG_COLOR ; +} +<CSS_BG_COLOR>[#[:alnum:]]+ { + BEGIN(CSS_PROPERTIES); + DEB2("CSS BG COLOR", yytext); + /* + we need to add the " in order to make source-highlight realize + that this is a direct color specification + */ + stylecsssc_lval.string = new std::string("\"" + std::string(yytext) + "\""); + return BG_STRINGDEF; +} +<CSS_PROPERTIES>"font-weight" { + BEGIN(CSS_FONT_WEIGHT); + DEB("CSS FONT WEIGHT"); +} +<CSS_FONT_WEIGHT>{VALUE} { + BEGIN(CSS_PROPERTIES); + if (strcmp(yytext, "bold") == 0) { + DEB("CSS BOLD"); + stylecsssc_lval.flag = ISBOLD ; + return BOLD ; + } + DEB2("discarding not handled value", yytext); +} +<CSS_PROPERTIES>"font-style" { + BEGIN(CSS_FONT_STYLE); + DEB("CSS FONT STYLE"); +} +<CSS_FONT_STYLE>{VALUE} { + BEGIN(CSS_PROPERTIES); + if (strcmp(yytext, "italic") == 0) { + DEB("CSS ITALIC"); + stylecsssc_lval.flag = ISITALIC ; + return ITALICS ; + } + DEB2("discarding not handled value", yytext); +} +<CSS_PROPERTIES>"font-family" { + BEGIN(CSS_FONT_FAMILY); + DEB("CSS FONT FAMILY"); +} +<CSS_FONT_FAMILY>{VALUE} { + BEGIN(CSS_PROPERTIES); + if (strcmp(yytext, "monospace") == 0) { + DEB("CSS FIXED"); + stylecsssc_lval.flag = ISFIXED ; + return FIXED ; + } + DEB2("discarding not handled value", yytext); +} +<CSS_PROPERTIES>"text-decoration" { + BEGIN(CSS_TEXT_DECORATION); + DEB("CSS TEXT DECORATION"); +} +<CSS_TEXT_DECORATION>{VALUE} { + BEGIN(CSS_PROPERTIES); + if (strcmp(yytext, "underline") == 0) { + DEB("CSS UNDERLINE"); + stylecsssc_lval.flag = ISUNDERLINE ; + return UNDERLINE ; + } + DEB2("discarding not handled value", yytext); +} +<CSS_PROPERTIES>"}" { + BEGIN(INITIAL); + DEB("CSS END PROPERTIES"); + /* + we must return ; since this is the terminator of a style option + so we simulate it in case of css files + */ + return ';' ; +} +<CSS_COLOR,CSS_BG_COLOR,CSS_FONT_WEIGHT,CSS_FONT_STYLE,CSS_FONT_FAMILY,CSS_TEXT_DECORATION>":"|";"|[\t]|[[:blank:]] { + /* discard other characters */ + DEB2("CSS discarding", yytext); +} +<CSS_PROPERTIES>. { + /* discard other properties */ + DEB2("CSS PROPERTIES discarding", yytext); +} + +<<EOF>> { + DEB("reached EOF of the style file"); + + DEB("freeing scanner memory"); + /* For non-reentrant C scanner only. */ + yy_delete_buffer(YY_CURRENT_BUFFER); + + yyterminate(); +} + +<INITIAL>. { return yytext[0] ; } + +%% + diff --git a/src/lib/stylekey.h b/src/lib/stylekey.h new file mode 100644 index 0000000..ec32eb1 --- /dev/null +++ b/src/lib/stylekey.h @@ -0,0 +1,28 @@ +// +// C++ Interface: stylekey +// +// Description: Structure for storing the keys of a style file. +// +// +// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef STYLEKEY_H +#define STYLEKEY_H + +#include <string> +#include <list> + +using std::list; +using std::string; + +// used to store a key +typedef string KeyType; + +// used to store the keys of styles +typedef list<KeyType> KeyList; + +#endif diff --git a/src/lib/optparser.yy b/src/lib/styleparser.yy index d8bcd84..a203137 100644 --- a/src/lib/optparser.yy +++ b/src/lib/styleparser.yy @@ -1,6 +1,6 @@ %{ /* - * Copyright (C) 1999, 2000, 2001 Lorenzo Bettini <http://www.lorenzobettini.it> + * Copyright (C) 1999-2007 Lorenzo Bettini <http://www.lorenzobettini.it> * * 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 @@ -25,12 +25,13 @@ #include "my_sstream.h" -#include "styles.h" +#include "generatorfactory.h" #include "colors.h" #include "keys.h" #include "messages.h" #include "parsestyles.h" #include "fileutil.h" +#include "stylekey.h" using std::cerr; @@ -39,11 +40,15 @@ static void yyerror( char *s ) ; int line = 1 ; -static void add_style(Styles *styles, Style *t); -static Styles *parsed_styles = 0; +extern int stylesc_lex() ; +extern FILE *stylesc_in ; -extern int opsc_lex() ; -extern FILE *opsc_in ; +static string bodyBgColor; + +static void updateBgColor(const std::string *); + +// to generate the generator for each language element +static GeneratorFactory *generatorFactory; %} @@ -51,53 +56,89 @@ extern FILE *opsc_in ; int tok ; /* command */ const std::string * string ; /* string : id, ... */ StyleConstant flag ; - Style *style ; - Styles *styles ; StyleConstants *styleconstants; + KeyList *keylist; } ; %token <flag> BOLD ITALICS UNDERLINE FIXED NOTFIXED NOREF -%token <string> KEY COLOR STRINGDEF +%token <string> KEY COLOR BG_COLOR STRINGDEF BODY_BG_COLOR +%token <tok> BG_T -%type <style> option -%type <styles> options %type <flag> value %type <styleconstants> stylevalues values -%type <string> color +%type <string> color bgcolor bodybgcolor +%type <keylist> keylist %% -globalstyles : options { parsed_styles = 1ドル; } -; - -options : options option { add_style( 1,ドル 2ドル ) ; } - | option { $$ = new Styles() ; $$->AddStyle( 1ドル ) ; } - ; - -option : KEY color +stylefile : { /* allow empty files */ } + | statements + ; + +statements : statements statement + | statement + ; + +statement : option + | bodybgcolor + ; + +option : keylist color bgcolor { - printMessage_noln( *1ドル ) ; + printSequence( 1ドル ) ; printMessage_noln( ": " ) ; printMessage_noln( (2ドル ? *2ドル : "") ) ; + printMessage_noln( " bg: " ) ; + printMessage_noln( (3ドル ? *3ドル : "") ) ; } stylevalues ';' { - if (2ドル) - $$ = new Style( *1,ドル *2ドル ) ; - else - $$ = new Style( *1ドル ) ; - $$->setStyles(StyleConstantsPtr(4ドル)) ; - delete 1ドル; + KeyType key; + KeyList *keylist = 1ドル; + StyleConstantsPtr stylevalues = StyleConstantsPtr(5ドル); + for (KeyList::const_iterator it = keylist->begin(); it != keylist->end(); ++it) { + key = *it; + if (!generatorFactory->createGenerator(key, (2ドル ? *2ドル : ""), (3ドル ? *3ドル : ""), stylevalues)) { + parseStyleError(key); + yyerror("already defined"); + } + } + delete keylist; if (2ドル) delete 2ドル; + if (3ドル) + delete 3ドル; } ; +keylist : keylist ',' KEY + { + 1ドル->push_back(*3ドル); + $$ = 1ドル; + delete 3ドル; + } + | KEY + { + $$ = new KeyList; + $$->push_back(*1ドル); + delete 1ドル; + } + ; + color : { $$ = 0; } | COLOR { $$ = 1ドル;} | STRINGDEF { $$ = 1ドル; } ; +bgcolor : { $$ = 0; } + | BG_T ':' COLOR { $$ = 3ドル;} + | BG_T ':' STRINGDEF { $$ = 3ドル; } + ; + +bodybgcolor : BODY_BG_COLOR COLOR ';' { updateBgColor(2ドル); } + | BODY_BG_COLOR STRINGDEF ';' { updateBgColor(2ドル); } + ; + stylevalues : { $$ = 0 ; printMessage( " (no options) " ) ; } | values { $$ = 1ドル; printMessage(""); } ; @@ -118,22 +159,29 @@ value : BOLD { printMessage_noln( " - bold" ) ; $$ = ISBOLD ; } string current_file; -Styles * -parseStyles(const string &path, const string &name) +void +parseStyles(const string &path, const string &name, GeneratorFactory *genFactory, + string &bodyBgColor_) { + generatorFactory = genFactory; + // opens the file for yylex - opsc_in = open_data_file_stream(path, name); + stylesc_in = open_data_file_stream(path, name); current_file = (path.size() ? path + "/" : "") + name; printMessage_noln( "Parsing ", cerr ) ; printMessage_noln (current_file, cerr); printMessage( " file ...", cerr ) ; - parsed_styles = 0; + + bodyBgColor = ""; + yyparse() ; + + bodyBgColor_ = bodyBgColor; + printMessage( "Parsing done!", cerr ) ; - fclose(opsc_in); - return parsed_styles; + fclose(stylesc_in); } void @@ -150,11 +198,14 @@ void parseStyleError(const std::string &error) printError( str.str(), cerr ) ; } -void -add_style(Styles *styles, Style *t) +void updateBgColor(const std::string *c) { - if (! styles->AddStyle(t)) - { - yyerror("already defined"); - } + if (bodyBgColor != "") + yyerror("bgcolor already defined"); + else + bodyBgColor = *c; + + // we don't need it anymore + delete c; } + diff --git a/src/lib/styles.cc b/src/lib/styles.cc deleted file mode 100644 index 72566d4..0000000 --- a/src/lib/styles.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* -** Copyright (C) 1999, 2000, 2001 Lorenzo Bettini <http://www.lorenzobettini.it> -** -** 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 2 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, write to the Free Software -** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -** -*/ - - -#include "styles.h" -#include "colors.h" -#include "keys.h" - -#include <iostream> - -using std::cerr; -using std::endl; - -Style::Style( const string &n, const string &c ) : StyleName( n ), color (c) -{ -} - -void Style::Print() { - cerr << StyleName << " " << color << " " ; - if (styles.get()) { - for (StyleConstantsIterator it = styles->begin(); it != styles->end(); ++it) - cerr << *it << " "; - } - cerr << endl ; -} - -Styles::~Styles() -{ - for (const_iterator it = begin(); it != end(); ++it) - delete *it; -} - diff --git a/src/lib/styles.h b/src/lib/styles.h deleted file mode 100644 index dca35a2..0000000 --- a/src/lib/styles.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef STYLES_H -#define STYLES_H - -#include "my_set.h" - -#include <string> -#include <list> -#include <boost/shared_ptr.hpp> - -typedef enum { ISBOLD=1, ISITALIC, ISUNDERLINE, ISFIXED, ISNOTFIXED, ISNOREF } StyleConstant; -typedef std::list<StyleConstant> StyleConstants; -typedef boost::shared_ptr<StyleConstants> StyleConstantsPtr; -typedef StyleConstants::const_iterator StyleConstantsIterator; - -using std::string; - -class Style -{ - protected: - string StyleName ; - string color ; - StyleConstantsPtr styles; - - public: - Style( const string &n ) : StyleName( n ) {} - Style( const string &n, const string &c ); - - void setStyles( StyleConstantsPtr t ) { styles = t; } - const StyleConstantsPtr getStyleConstants() const { return styles; } - - string GetName() const { return StyleName ; } - string GetColor() const { return color ; } - void SetColor( const string &col ) { color = col ; } - void Print() ; -} ; - -struct StyleLess -{ - typedef std::less<string> value_compare; - - value_compare value_comp; - - public: - bool operator() (const Style *t1, const Style *t2) const - { return value_comp(t1->GetName(),t2->GetName()); } -}; - -class Styles : protected set<Style *, StyleLess> -{ - typedef set<Style *, StyleLess> container_type; - - public: - using container_type::begin; - using container_type::end; - using container_type::const_iterator; - - Styles() {} - ~Styles(); - bool AddStyle( Style *t ) { return insert( t ).second ; } - Style *GetStyle( const string &name ) ; -} ; - -inline Style * -Styles::GetStyle( const string &name ) -{ - Style *temp = new Style (name); - const_iterator p = find (temp); - delete temp; - if (p != end ()) - return *p; - - return 0; -} - -#endif diff --git a/src/lib/stylescanner.ll b/src/lib/stylescanner.ll new file mode 100644 index 0000000..c5b5c19 --- /dev/null +++ b/src/lib/stylescanner.ll @@ -0,0 +1,137 @@ +%{ +/* + * Copyright (C) 1999-2007 Lorenzo Bettini, http://www.lorenzobettini.it + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdlib.h> + +#include "stylekey.h" + +#include "generatorfactory.h" +#include "styleparser.h" +#include "my_sstream.h" +#include "messages.h" +#include "parsestyles.h" + +static std::ostringstream buff; + +extern int line ; + +//#define DEBUG_SCANNER +#ifdef DEBUG_SCANNER +#include <iostream> // for debug +#define DEB(s) std::cerr << s << std::endl; +#define DEB2(s,s2) std::cerr << s << ": " << s2 << std::endl; +#else +#define DEB(s) +#define DEB2(s,s2) +#endif + + +static void buffer(const char *s); +static const std::string *flush_buffer(); + +%} + +%option prefix="stylesc_" +%option noyywrap + +ws [ ]+ +tabs [\t]+ + +nl \n +cr \r +IDE [a-zA-Z_]([a-zA-Z0-9_])* + +STRING \"[^\"\n]*\" + +%s COMMENT_STATE STRING_STATE + +%% + +{ws}|{tabs} {} + +\r {} + +<INITIAL>"//" { BEGIN(COMMENT_STATE); } +<COMMENT_STATE>[^\n] {} +<COMMENT_STATE>\n { ++line; BEGIN(INITIAL); } + +<INITIAL>"green"|"red"|"darkred"|"blue"|"brown"|"pink"|"yellow"|"cyan"|"purple"|"orange"|"brightorange"|"darkgreen"|"brightgreen"|"black"|"teal"|"gray"|"darkblue" { stylesc_lval.string = new std::string(yytext) ; return COLOR ; } + +<INITIAL>\#[a-fA-F0-9]{6} { + const std::string wrong = yytext ; + parseStyleError("use of direct colors has changed"); + parseStyleError("use double quoted syntax: \"" + wrong + "\" instead of " + wrong); + exit(EXIT_FAILURE); + return COLOR ; +} + +<INITIAL>"bgcolor" { return BODY_BG_COLOR ; } + +<INITIAL>"bg" { return BG_T ; } + +<INITIAL>"b" { stylesc_lval.flag = ISBOLD ; return BOLD ; } +<INITIAL>"i" { stylesc_lval.flag = ISITALIC ; return ITALICS ; } +<INITIAL>"u" { stylesc_lval.flag = ISUNDERLINE ; return UNDERLINE ; } +<INITIAL>"f" { stylesc_lval.flag = ISFIXED; return FIXED; } +<INITIAL>"nf" { stylesc_lval.flag = ISNOTFIXED; return NOTFIXED; } +<INITIAL>"noref" { stylesc_lval.flag = ISNOREF; return NOREF; } + +<INITIAL>"," { return ',' ; } +<INITIAL>";" { return ';' ; } +<INITIAL>":" { return ':' ; } + +<INITIAL>{IDE} { stylesc_lval.string = new std::string(yytext) ; return KEY ; } + +<INITIAL>\" { BEGIN(STRING_STATE); DEB("STRING_STATE"); buffer( yytext ) ; } +<STRING_STATE>\\\\ { buffer( yytext ) ; } +<STRING_STATE>"\\\"" { buffer( "\"" ) ; } +<STRING_STATE>\" { BEGIN(INITIAL) ; buffer( yytext ) ; DEB("END STRING_STATE"); stylesc_lval.string = flush_buffer() ; return STRINGDEF; } +<STRING_STATE>[^\n]|" " { buffer( yytext ) ; } +<STRING_STATE>\n { buffer( "\n" ) ; } + +\n { ++line ; } + +<<EOF>> { + DEB("reached EOF of the style file"); + + DEB("freeing scanner memory"); + /* For non-reentrant C scanner only. */ + yy_delete_buffer(YY_CURRENT_BUFFER); + + yyterminate(); +} + +<INITIAL>. { /* anything else will generate a parsing error */ return yytext[0] ; } + +%% + +void buffer(const char *s) +{ + DEB2("BUFFERING ", s); + buff << s; +} + +const std::string *flush_buffer() +{ + const std::string *ret = new std::string(buff.str()); + buff.str(""); + return ret; +} + diff --git a/src/lib/test_outlangparser_main.cpp b/src/lib/test_outlangparser_main.cpp index d3dbe5f..dc1cf84 100644 --- a/src/lib/test_outlangparser_main.cpp +++ b/src/lib/test_outlangparser_main.cpp @@ -25,9 +25,9 @@ main() cout << "DocTemplate start:\n" << textstyles->docTemplate.toStringBegin() << endl; cout << "DocTemplate end:\n" << textstyles->docTemplate.toStringEnd() << endl; cout << "DocTemplate start:\n" << textstyles->docTemplate.output_begin - ("title", "css", "additional", "header", "footer") << endl; + ("title", "css", "additional", "header", "footer", "") << endl; cout << "DocTemplate end:\n" << textstyles->docTemplate.output_end - ("title", "css", "additional", "header", "footer") << endl; + ("title", "css", "additional", "header", "footer", "") << endl; cout << "Style template:\n" << textstyles->starting_template << endl; cout << "Style separator: " << textstyles->style_separator << endl; diff --git a/src/lib/test_textgenerator_main.cpp b/src/lib/test_textgenerator_main.cpp index 25474a9..c26d171 100644 --- a/src/lib/test_textgenerator_main.cpp +++ b/src/lib/test_textgenerator_main.cpp @@ -71,8 +71,8 @@ main() string expected_end = "\nFOOTER"; DocTemplate docTemplate(start, end); - string transformed_start = docTemplate.output_begin("TITLE", "CSS", "ADDITIONAL", "HEADER\n", "\nFOOTER"); - string transformed_end = docTemplate.output_end("TITLE", "CSS", "ADDITIONAL", "HEADER\n", "\nFOOTER"); + string transformed_start = docTemplate.output_begin("TITLE", "CSS", "ADDITIONAL", "HEADER\n", "\nFOOTER", ""); + string transformed_end = docTemplate.output_end("TITLE", "CSS", "ADDITIONAL", "HEADER\n", "\nFOOTER", ""); cout << "orig start : " << start << endl; cout << "transformed: " << transformed_start << endl; diff --git a/src/lib/textstyles.h b/src/lib/textstyles.h index e859333..712f243 100644 --- a/src/lib/textstyles.h +++ b/src/lib/textstyles.h @@ -18,7 +18,7 @@ struct TextStyles { TextStyle bold, italics, underline, notfixed, fixed, - color, onestyle; + color, bg_color, onestyle; struct RefTextStyle { diff --git a/src/m4.lang b/src/m4.lang new file mode 100644 index 0000000..6c37260 --- /dev/null +++ b/src/m4.lang @@ -0,0 +1,17 @@ +# language definition for m4 files + +state keyword start "dnl" begin + include "url.lang" + include "html.lang" + type = '@[[:alpha:]]+' + # the following is similar to .+ but does not exclude the + # url, html, type defined above + comment = '[^[:blank:]]+' + comment = '[[:blank:]]+' +end + +# since ## is not a comment in shell scripts, but it is in m4 +# we kind of redefine multiple #'s as comments +comment start '#+' + +include "sh.lang"
\ No newline at end of file diff --git a/src/makefile.lang b/src/makefile.lang new file mode 100644 index 0000000..b97481d --- /dev/null +++ b/src/makefile.lang @@ -0,0 +1,42 @@ +# Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +# WWW: http://www.pd.infn.it/~loreti/mlo.html +# +###################################################################### +# Language definitions for Makefiles; intended for source-highlight +# (see http://www.gnu.org/software/src-highlite). +###################################################################### + +# Modified by Lorenzo Bettini, http://www.lorenzobettini.it + +# Declared symbols; e.g.: +# SOURCE = foo.c +# ^^^^^^^^ will be highlighted as "type" (default: dark green) + +type = '^[a-zA-Z0-9_-]+[[:space:]]*=' + +# Special statements; e.g.: +# .PHONY: clean +# ^^^^^^^ will be highlighted as "preproc" (default: dark blue) + +preproc = '^\.[a-zA-Z0-9_-]+[[:space:]]*:' + +# automake/autoconf variables +preproc = '@(.+)@' + +# Dependencies; e.g.: +# foo.o foo.z: foo.c +# ^^^^^^^^^^^^ will be highlighted as "symbol" (default: dark red) + +symbol = '^([[:word:].[:space:]-])+:' + +# Rules; e.g.: +# %.o:%.c +# ^^^^^^^ will be highlighted as "string" (default: red) + +string = '%[a-zA-Z0-9_.-]+:%[a-zA-Z0-9_.-]+' + +# filenames +normal = '([[:word:]-]*)\.([[:word:]-]+)' + +# The statements following dependencies are for /bin/sh; so: +include "sh.lang" diff --git a/src/outlang.lang b/src/outlang.lang index 36e9117..50851f1 100644 --- a/src/outlang.lang +++ b/src/outlang.lang @@ -5,6 +5,7 @@ comment start "#" preproc = "include" string delim "\"" "\"" escape "\\" multiline +string delim "'" "'" escape "\\" multiline keyword = "doctemplate|styletemplate|styleseparator|bold|italics", "underline|notfixed|fixed|colormap|color|default|onestyle", diff --git a/src/outlang.map b/src/outlang.map index 68cfd31..b8907e5 100644 --- a/src/outlang.map +++ b/src/outlang.map @@ -1,11 +1,13 @@ html = html.outlang +htmltable = htmltable.outlang html-doc = htmldoc.outlang html-css = css_common.outlang -html-css-doc = cssdoc.outlang +html-css-doc = htmlcss.outlang xhtml = xhtml.outlang +xhtmltable = xhtmltable.outlang xhtml-doc = xhtmldoc.outlang -xhtml-css-doc = xhtmldoc.outlang -xhtml-css = xhtmlcss.outlang +xhtml-css = css_common.outlang +xhtml-css-doc = xhtmlcss.outlang esc = esc.outlang esc-doc = esc.outlang latex = latex.outlang diff --git a/src/php.lang b/src/php.lang index df5b6c3..8649a72 100644 --- a/src/php.lang +++ b/src/php.lang @@ -10,10 +10,12 @@ string delim "'" "'" escape "\\" multiline keyword = "and|or|xor|__FILE__|exception|php_user_filter|__LINE__|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|each|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exit|extends|for|foreach|function|global|if|isset|list|new|old_function|print|return|static|switch|unset|use|var|while|__FUNCTION__|__CLASS__|__METHOD__" -comment delim "/*" "*/" multiline nested +include "c_comment.lang" type = '(?:\$[#]?|@|%)[[:word:]]+' +symbol = "<?php" + include "symbols.lang" cbracket = "{|}" diff --git a/src/sh.lang b/src/sh.lang index 3dc19b0..c42d7f5 100644 --- a/src/sh.lang +++ b/src/sh.lang @@ -1,16 +1,19 @@ preproc = "import" -include "script_comment.lang" +#number = '(?<=-)([[:digit:]]+)' include "number.lang" +normal = '\\"' +normal = '\\\'' + include "c_string.lang" function = 'function[[:blank:]]+([[:alpha:]]|_)[[:word:]]*[[:blank:]]*(\(\))?' function = '([[:alpha:]]|_)[[:word:]]*[[:blank:]]*\(\)' # avoids, in things such as --bind, that words are highlighted as keywords -normal = '([[:word:]]*[-/]+[[:word:]]+)+' +normal = '([[:alpha:]]*[-/]+[[:alpha:]]+)+' keyword = "alias|bg|bind|break|builtin|caller|case|command|compgen", "complete|continue|declare|dirs|disown|do|done|elif|else|enable", @@ -21,8 +24,14 @@ keyword = "alias|bg|bind|break|builtin|caller|case|command|compgen", # it is considered a variable if there's a =, which is discarded anyway variable = '([[:alpha:]]|_)[[:word:]]*(?==)' -variable = '\$(\{|\()([[:alpha:]]|_)[[:word:]]*(\}|\))' +variable = '\$\{([^[:blank:]]+)\}' +variable = '\$\(([^[:blank:]]+)\)' variable = '\$([[:alpha:]]|_)[[:word:]]*' +variable = '\$([^[:blank:]]{1})' +# notice that - is not a symbol since it can be used in command line parameters symbol = "~","!","%","^","*","(",")","+","=","[", - "]","\\",":",";",",",".","/","?","&","<",">","\|" + "]","\\",":",";",",",".","/","?","&","<",">","\|",'(##){2}',"%%" + +include "script_comment.lang" + diff --git a/src/src-hilite-lesspipe.sh.in b/src/src-hilite-lesspipe.sh.in index b30f953..7c4bcec 100644 --- a/src/src-hilite-lesspipe.sh.in +++ b/src/src-hilite-lesspipe.sh.in @@ -4,6 +4,8 @@ for source in 1ドル; do case $source in ChangeLog|changelog) source-highlight --failsafe -f esc --lang-def=changelog.lang --style-file=esc.style -i $source ;; + Makefile|makefile) + source-highlight --failsafe -f esc --lang-def=makefile.lang --style-file=esc.style -i $source ;; *) source-highlight --failsafe --infer-lang -f esc --style-file=esc.style -i $source ;; esac done diff --git a/src/startapp.cc b/src/startapp.cc index 42c1c31..a025801 100644 --- a/src/startapp.cc +++ b/src/startapp.cc @@ -80,6 +80,18 @@ gengetopt_args_info args_info ; // command line structure static void print_cgi_header(); static void run_ctags(const string &cmd); +/** + * Print progress status information (provided --quiet is not specified) + * @param message + */ +static void progressInfo(const string &message) +{ + if (args_info.quiet_given) + return; + + cerr << message; +} + StartApp::StartApp() : docgenerator(0), formatter(0), preformatter(0), langmap(new LangMap), outlangmap(new LangMap), generator_factory(0), @@ -281,8 +293,6 @@ StartApp::start(int argc, char * argv[]) return (EXIT_SUCCESS); } - Styles *sts = parseStyles(data_dir, style_file); - outputbuffer = new OutputBuffer; // when debugging, always flush the output outputbuffer->setAlwaysFlush( args_info.debug_langdef_given ); @@ -382,19 +392,28 @@ StartApp::start(int argc, char * argv[]) PreFormatterPtr chartranslator(textstyles->charTranslator); preformatter->setFormatter(chartranslator); + string background_color; + generator_factory = - new GeneratorFactory(textstyles, sts, preformatter, - args_info.gen_references_given, - args_info.ctags_file_arg, - refposition); + new GeneratorFactory(textstyles, preformatter, + args_info.gen_references_given, + args_info.ctags_file_arg, + refposition, args_info.debug_langdef_given); + + if (args_info.style_css_file_given) { + parseCssStyles(data_dir, args_info.style_css_file_arg, generator_factory, background_color); + } else { + parseStyles(data_dir, style_file, generator_factory, background_color); + } - // turn off optimizations when debugging - generator_factory->setNoOptimizations( args_info.debug_langdef_given ); + generator_factory->addDefaultGenerator(); + + if (background_color != "") + background_color = generator_factory->preprocessColor( background_color ); - generator_factory->createGenerators (); docgenerator = new DocGenerator(title, inputFileName, doc_header, doc_footer, - css_url, entire_doc, + css_url, background_color, entire_doc, textstyles->docTemplate.toStringBegin(), textstyles->docTemplate.toStringEnd());; @@ -430,7 +449,7 @@ StartApp::start(int argc, char * argv[]) // let's process other files, if there are any if ( args_info.inputs_num && !is_cgi ) { for ( i = 0 ; i < (args_info.inputs_num) ; ++i ) { - cerr << "Processing " << args_info.inputs[i] << " ... " ; + progressInfo(string("Processing ") + args_info.inputs[i] + " ... "); const string &outputFileName = createOutputFileName (args_info.inputs[i], args_info.output_dir_arg, ext); result = processFile @@ -439,16 +458,13 @@ StartApp::start(int argc, char * argv[]) ext) ; if (result == EXIT_FAILURE) break; - cerr << "created " << outputFileName << endl ; + progressInfo("created " + outputFileName + "\n"); } } delete outputbuffer; outputbuffer = 0; - if (sts) - delete sts; - return (result); } diff --git a/src/style.lang b/src/style.lang index a89f3ba..6cf7d53 100644 --- a/src/style.lang +++ b/src/style.lang @@ -4,11 +4,12 @@ comment start "//" string delim "\"" "\"" escape "\\" -keyword = "purple|orange|brightorange|brightgreen|darkgreen", +keyword = "bgcolor|purple|orange|brightorange|brightgreen|darkgreen", "green|darkred|red|brown|pink|yellow|cyan", "black|teal|gray|darkblue|blue", "normal|linenum", "noref|nf|f|u|i|b" +keyword = 'bg\:' symbol = ",|;" diff --git a/src/texinfo.style b/src/texinfo.style index 03e6547..3adcf37 100644 --- a/src/texinfo.style +++ b/src/texinfo.style @@ -1,5 +1,4 @@ -keyword b ; -type b ; +keyword, type b ; variable f, i ; string f ; comment nf, i, noref ; @@ -12,6 +11,9 @@ linenum f; url f; // for diffs -oldfile i; -newfile i; -difflines b;
\ No newline at end of file +oldfile, newfile i; +difflines b; + +// for css +selector, property b; +value i;
\ No newline at end of file diff --git a/src/xhtml.outlang b/src/xhtml.outlang index 93b766b..2f8213b 100644 --- a/src/xhtml.outlang +++ b/src/xhtml.outlang @@ -1,13 +1,8 @@ -include "html_common.outlang" +include "xhtml_common.outlang" doctemplate "<!-- Generator: $additional --> -<pre><tt>" -"</tt></pre> +$header<pre><tt>" +"</tt></pre>$footer " end - -bold "<span style=\"font-weight: bold\">$text</span>" -italics "<span style=\"font-style: italic\">$text</span>" -underline "<span style=\"text-decoration: underline\">$text</span>" -color "<span style=\"color: $style\">$text</span>"
\ No newline at end of file diff --git a/src/xhtml_common.outlang b/src/xhtml_common.outlang new file mode 100644 index 0000000..6e9c9c6 --- /dev/null +++ b/src/xhtml_common.outlang @@ -0,0 +1,8 @@ +include "html_common.outlang" + +bold "<span style=\"font-weight: bold\">$text</span>" +italics "<span style=\"font-style: italic\">$text</span>" +underline "<span style=\"text-decoration: underline\">$text</span>" +color "<span style=\"color: $style\">$text</span>" +bgcolor "<span style=\"background-color: $style\">$text</span>" +anchor "<span id=\"$linenum\">$text</span>" diff --git a/src/xhtmlcss.outlang b/src/xhtmlcss.outlang index efa7208..215800f 100644 --- a/src/xhtmlcss.outlang +++ b/src/xhtmlcss.outlang @@ -1,15 +1,14 @@ -include "html_common.outlang" +include "css_common.outlang" doctemplate "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" - \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> + \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html> <head> -<meta http-equiv=\"Content-Type\" -content=\"text/html; charset=iso-8859-1\" /> +<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /> <meta name=\"GENERATOR\" content=\"$additional\" /> <title>$title</title> -<link rel=\"stylesheet\" href=\"$css\" type=\"text/css\">; +<link rel=\"stylesheet\" href=\"$css\" type=\"text/css\" /> </head> <body> $header<pre><tt>" @@ -18,8 +17,3 @@ $footer</body> </html> " end - -bold "<span style=\"font-weight: bold\">$text</span>" -italics "<span style=\"font-style: italic\">$text</span>" -underline "<span style=\"text-decoration: underline\">$text</span>" -color "<span style=\"color: $style\">$text</span>"
\ No newline at end of file diff --git a/src/xhtmldoc.outlang b/src/xhtmldoc.outlang index 71321ca..e29f9a1 100644 --- a/src/xhtmldoc.outlang +++ b/src/xhtmldoc.outlang @@ -1,24 +1,18 @@ -include "html_common.outlang" +include "xhtml_common.outlang" doctemplate "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" - \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> + \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html> <head> -<meta http-equiv=\"Content-Type\" -content=\"text/html; charset=iso-8859-1\" /> +<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" /> <meta name=\"GENERATOR\" content=\"$additional\" /> <title>$title</title> </head> -<body> +<body style=\"background-color: $docbgcolor\"> $header<pre><tt>" "</tt></pre> $footer</body> </html> " end - -bold "<span style=\"font-weight: bold\">$text</span>" -italics "<span style=\"font-style: italic\">$text</span>" -underline "<span style=\"text-decoration: underline\">$text</span>" -color "<span style=\"color: $style\">$text</span>"
\ No newline at end of file diff --git a/src/xhtmltable.outlang b/src/xhtmltable.outlang new file mode 100644 index 0000000..217b09d --- /dev/null +++ b/src/xhtmltable.outlang @@ -0,0 +1,14 @@ +include "xhtml_common.outlang" + +doctemplate +"<table style=\"background-color: $docbgcolor\"> +<tbody> +<tr><td> +<pre><tt>" +"</tt></pre> +</td></tr> +</tbody> +</table> +" +end + diff --git a/src/xml.lang b/src/xml.lang index 10f4353..4ef4259 100644 --- a/src/xml.lang +++ b/src/xml.lang @@ -4,9 +4,9 @@ end comment delim "<!--" "-->" multiline nested -keyword = '<(/)?[[:alnum:]:]+(/)?>' +keyword = '<(/)?[[:word:]:-]+(/)?>' -state keyword delim '<(/)?[[:alnum:]:]+' '(/)?>' multiline begin +state keyword delim '<(/)?[[:word:]:-]+' '(/)?>' multiline begin type = '[^="[:blank:]>]+' symbol = "=" string delim "\"" "\"" escape "\\" multiline |