diff --git a/ChangeLog b/ChangeLog index ed8e1ca..86fa551 100644 --- a/ChangeLog +++ b/ChangeLog @@ -284,3 +284,5 @@ - Support EndNote reference citations in convert.c - Improved handling of some tables - Fixed --text processing broken in 0.21.8 - outputs/text.conf +0.21.10: + - added gentoo automake-fix and iconv-detection patches diff --git a/INSTALL b/INSTALL index 007e939..8865734 100644 --- a/INSTALL +++ b/INSTALL @@ -1,8 +1,8 @@ Installation Instructions ************************* -Copyright (C) 1994-1996, 1999-2002, 2004-2013 Free Software Foundation, -Inc. + Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software +Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright @@ -12,97 +12,96 @@ Basic Installation ================== - Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for + Briefly, the shell command './configure && make && make install' +should configure, build, and install this package. The following +more-detailed instructions are generic; see the 'README' file for instructions specific to this package. Some packages provide this -`INSTALL' file but do not implement all of the features documented +'INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. - The `configure' shell script attempts to guess correct values for + The 'configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that +those values to create a 'Makefile' in each directory of the package. +It may also create one or more '.h' files containing system-dependent +definitions. Finally, it creates a shell script 'config.status' that you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. +file 'config.log' containing compiler output (useful mainly for +debugging 'configure'). + + It can also use an optional file (typically called 'config.cache' and +enabled with '--cache-file=config.cache' or simply '-C') that saves the +results of its tests to speed up reconfiguring. Caching is disabled by +default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can +to figure out how 'configure' could check whether to do them, and mail +diffs or instructions to the address given in the 'README' so they can be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you +some point 'config.cache' contains results you don't want to keep, you may remove or edit it. - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. + The file 'configure.ac' (or 'configure.in') is used to create +'configure' by a program called 'autoconf'. You need 'configure.ac' if +you want to change it or regenerate 'configure' using a newer version of +'autoconf'. The simplest way to compile this package is: - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. - - Running `configure' might take a while. While running, it prints + 1. 'cd' to the directory containing the package's source code and type + './configure' to configure the package for your system. + + Running 'configure' might take a while. While running, it prints some messages telling which features it is checking for. - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with + 2. Type 'make' to compile the package. + + 3. Optionally, type 'make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. - 4. Type `make install' to install the programs and any data files and + 4. Type 'make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular - user, and only the `make install' phase executed with root + user, and only the 'make install' phase executed with root privileges. - 5. Optionally, type `make installcheck' to repeat any self-tests, but + 5. Optionally, type 'make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a - regular user, particularly if the prior `make install' required + regular user, particularly if the prior 'make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly + source code directory by typing 'make clean'. To also remove the + files that 'configure' created (so you can compile the package for + a different kind of computer), type 'make distclean'. There is + also a 'make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. - 7. Often, you can also type `make uninstall' to remove the installed + 7. Often, you can also type 'make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. - 8. Some packages, particularly those that use Automake, provide `make + 8. Some packages, particularly those that use Automake, provide 'make distcheck', which can by used by developers to test that all other - targets like `make install' and `make uninstall' work correctly. + targets like 'make install' and 'make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' +the 'configure' script does not know about. Run './configure --help' for details on some of the pertinent environment variables. - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: + You can give 'configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here is +an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix @@ -113,21 +112,21 @@ You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the +own directory. To do this, you can use GNU 'make'. 'cd' to the directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. This -is known as a "VPATH" build. - - With a non-GNU `make', it is safer to compile the package for one +the 'configure' script. 'configure' automatically checks for the source +code in the directory that 'configure' is in and in '..'. This is known +as a "VPATH" build. + + With a non-GNU 'make', it is safer to compile the package for one architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before +installed the package for one architecture, use 'make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple `-arch' options to the -compiler but only a single `-arch' option to the preprocessor. Like +"universal" binaries--by specifying multiple '-arch' options to the +compiler but only a single '-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ @@ -136,105 +135,104 @@ This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results -using the `lipo' tool if you have problems. +using the 'lipo' tool if you have problems. Installation Names ================== - By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX', where PREFIX must be an + By default, 'make install' installs the package's commands under +'/usr/local/bin', include files under '/usr/local/include', etc. You +can specify an installation prefix other than '/usr/local' by giving +'configure' the option '--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses +pass the option '--exec-prefix=PREFIX' to 'configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. In general, the -default for these options is expressed in terms of `${prefix}', so that -specifying just `--prefix' will affect all of the other directory +options like '--bindir=DIR' to specify different values for particular +kinds of files. Run 'configure --help' for a list of the directories +you can set and what kinds of files go in them. In general, the default +for these options is expressed in terms of '${prefix}', so that +specifying just '--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the -correct locations to `configure'; however, many packages provide one or +correct locations to 'configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the -`make install' command line to change installation locations without +'make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each -affected directory. For example, `make install +affected directory. For example, 'make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of -`${prefix}'. Any directories that were specified during `configure', -but not in terms of `${prefix}', must each be overridden at install -time for the entire installation to be relocated. The approach of -makefile variable overrides for each directory variable is required by -the GNU Coding Standards, and ideally causes no recompilation. -However, some platforms have known limitations with the semantics of -shared libraries that end up requiring recompilation when using this -method, particularly noticeable in packages that use GNU Libtool. - - The second method involves providing the `DESTDIR' variable. For -example, `make install DESTDIR=/alternate/directory' will prepend -`/alternate/directory' before all installation names. The approach of -`DESTDIR' overrides is not required by the GNU Coding Standards, and +'${prefix}'. Any directories that were specified during 'configure', +but not in terms of '${prefix}', must each be overridden at install time +for the entire installation to be relocated. The approach of makefile +variable overrides for each directory variable is required by the GNU +Coding Standards, and ideally causes no recompilation. However, some +platforms have known limitations with the semantics of shared libraries +that end up requiring recompilation when using this method, particularly +noticeable in packages that use GNU Libtool. + + The second method involves providing the 'DESTDIR' variable. For +example, 'make install DESTDIR=/alternate/directory' will prepend +'/alternate/directory' before all installation names. The approach of +'DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even -when some directory options were not specified in terms of `${prefix}' -at `configure' time. +when some directory options were not specified in terms of '${prefix}' +at 'configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the +with an extra prefix or suffix on their names by giving 'configure' the +option '--program-prefix=PREFIX' or '--program-suffix=SUFFIX'. + + Some packages pay attention to '--enable-FEATURE' options to +'configure', where FEATURE indicates an optional part of the package. +They may also pay attention to '--with-PACKAGE' options, where PACKAGE +is something like 'gnu-as' or 'x' (for the X Window System). The +'README' should mention any '--enable-' and '--with-' options that the package recognizes. - For packages that use the X Window System, `configure' can usually + For packages that use the X Window System, 'configure' can usually find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. +you can use the 'configure' options '--x-includes=DIR' and +'--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the -execution of `make' will be. For these packages, running `./configure +execution of 'make' will be. For these packages, running './configure --enable-silent-rules' sets the default to minimal output, which can be -overridden with `make V=1'; while running `./configure +overridden with 'make V=1'; while running './configure --disable-silent-rules' sets the default to verbose, which can be -overridden with `make V=0'. +overridden with 'make V=0'. Particular systems ================== - On HP-UX, the default C compiler is not ANSI C compatible. If GNU -CC is not installed, it is recommended to use the following options in + On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC +is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. - HP-UX `make' updates targets which have the same time stamps as -their prerequisites, which makes it generally unusable when shipped -generated files such as `configure' are involved. Use GNU `make' -instead. + HP-UX 'make' updates targets which have the same time stamps as their +prerequisites, which makes it generally unusable when shipped generated +files such as 'configure' are involved. Use GNU 'make' instead. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its `' header file. The option `-nodtk' can be used as -a workaround. If GNU CC is not installed, it is therefore recommended -to try +parse its '' header file. The option '-nodtk' can be used as a +workaround. If GNU CC is not installed, it is therefore recommended to +try ./configure CC="cc" @@ -242,26 +240,26 @@ ./configure CC="cc -nodtk" - On Solaris, don't put `/usr/ucb' early in your `PATH'. This + On Solaris, don't put '/usr/ucb' early in your 'PATH'. This directory contains several dysfunctional programs; working variants of -these programs are available in `/usr/bin'. So, if you need `/usr/ucb' -in your `PATH', put it _after_ `/usr/bin'. - - On Haiku, software installed for all users goes in `/boot/common', -not `/usr/local'. It is recommended to use the following options: +these programs are available in '/usr/bin'. So, if you need '/usr/ucb' +in your 'PATH', put it _after_ '/usr/bin'. + + On Haiku, software installed for all users goes in '/boot/common', +not '/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== - There may be some features `configure' cannot figure out + There may be some features 'configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints +_same_ architectures, 'configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: +'--build=TYPE' option. TYPE can either be a short name for the system +type, such as 'sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM @@ -270,101 +268,101 @@ OS KERNEL-OS - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't + See the file 'config.sub' for the possible values of each field. If +'config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will +use the option '--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. +eventually be run) with '--host=TYPE'. Sharing Defaults ================ - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. + If you want to set default values for 'configure' scripts to share, +you can create a site shell script called 'config.site' that gives +default values for variables like 'CC', 'cache_file', and 'prefix'. +'configure' looks for 'PREFIX/share/config.site' if it exists, then +'PREFIX/etc/config.site' if it exists. Or, you can set the +'CONFIG_SITE' environment variable to the location of the site script. +A warning: not all 'configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run +environment passed to 'configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: +them in the 'configure' command line, using 'VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc -causes the specified `gcc' to be used as the C compiler (unless it is +causes the specified 'gcc' to be used as the C compiler (unless it is overridden in the site shell script). -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf limitation. Until the limitation is lifted, you can use -this workaround: +Unfortunately, this technique does not work for 'CONFIG_SHELL' due to an +Autoconf limitation. Until the limitation is lifted, you can use this +workaround: CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash -`configure' Invocation +'configure' Invocation ====================== - `configure' recognizes the following options to control how it + 'configure' recognizes the following options to control how it operates. -`--help' -`-h' - Print a summary of all of the options to `configure', and exit. - -`--help=short' -`--help=recursive' +'--help' +'-h' + Print a summary of all of the options to 'configure', and exit. + +'--help=short' +'--help=recursive' Print a summary of the options unique to this package's - `configure', and exit. The `short' variant lists options used - only in the top level, while the `recursive' variant lists options - also present in any nested packages. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' + 'configure', and exit. The 'short' variant lists options used only + in the top level, while the 'recursive' variant lists options also + present in any nested packages. + +'--version' +'-V' + Print the version of Autoconf used to generate the 'configure' script, and exit. -`--cache-file=FILE' +'--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to + traditionally 'config.cache'. FILE defaults to '/dev/null' to disable caching. -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' +'--config-cache' +'-C' + Alias for '--cache-file=config.cache'. + +'--quiet' +'--silent' +'-q' Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error + suppress all normal output, redirect it to '/dev/null' (any error messages will still be shown). -`--srcdir=DIR' +'--srcdir=DIR' Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--prefix=DIR' - Use DIR as the installation prefix. *note Installation Names:: - for more details, including other options available for fine-tuning - the installation locations. - -`--no-create' -`-n' + 'configure' can determine that directory automatically. + +'--prefix=DIR' + Use DIR as the installation prefix. *note Installation Names:: for + more details, including other options available for fine-tuning the + installation locations. + +'--no-create' +'-n' Run the configure checks, but stop before creating any output files. -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. +'configure' also accepts some other, not widely useful, options. Run +'configure --help' for more details. diff --git a/Makefile.in b/Makefile.in index e3ea905..4595c53 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -16,7 +16,17 @@ # this is the main Makefile.am VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -80,18 +90,12 @@ build_triplet = @build@ host_triplet = @host@ subdir = . -DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \ - $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/configure $(am__configure_deps) \ - $(srcdir)/config.h.in COPYING config/config.guess \ - config/config.sub config/depcomp config/install-sh \ - config/missing $(top_srcdir)/config/config.guess \ - $(top_srcdir)/config/config.sub \ - $(top_srcdir)/config/install-sh $(top_srcdir)/config/missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ + $(am__configure_deps) $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d @@ -155,6 +159,13 @@ CTAGS = ctags CSCOPE = cscope DIST_SUBDIRS = $(SUBDIRS) +am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ + $(top_srcdir)/config/compile $(top_srcdir)/config/config.guess \ + $(top_srcdir)/config/config.sub \ + $(top_srcdir)/config/install-sh $(top_srcdir)/config/missing \ + AUTHORS COPYING ChangeLog INSTALL NEWS README config/compile \ + config/config.guess config/config.sub config/install-sh \ + config/missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -319,7 +330,6 @@ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -340,8 +350,8 @@ $(am__aclocal_m4_deps): config.h: stamp-h1 - @if test ! -f $@; then rm -f stamp-h1; else :; fi - @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi + @test -f $@ || rm -f stamp-h1 + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status @rm -f stamp-h1 @@ -525,7 +535,7 @@ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -541,11 +551,17 @@ $(am__post_remove_distdir) dist-tarZ: distdir + @echo WARNING: "Support for distribution archives compressed with" \ + "legacy program 'compress' is deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__post_remove_distdir) dist-shar: distdir - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + @echo WARNING: "Support for shar distribution archives is" \ + "deprecated." >&2 + @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -563,7 +579,7 @@ distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -573,22 +589,23 @@ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac chmod -R a-w $(distdir) chmod u+w $(distdir) - mkdir $(distdir)/_build $(distdir)/_inst + mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ - && $(am__cd) $(distdir)/_build \ - && ../configure --srcdir=.. --prefix="$$dc_install_base" \ + && $(am__cd) $(distdir)/_build/sub \ + && ../../configure \ $(AM_DISTCHECK_CONFIGURE_FLAGS) \ $(DISTCHECK_CONFIGURE_FLAGS) \ + --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) dvi \ && $(MAKE) $(AM_MAKEFLAGS) check \ @@ -763,6 +780,8 @@ mostlyclean-generic pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am +.PRECIOUS: Makefile + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/NEWS b/NEWS index d2cde3c..bd1fb06 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +0.21.10 (23 Nov 2018): + Applied gentoo automake-fix and iconv.detection patches 0.21.9 (2 Jan 2015): Correct text conversion failure introduced in 0.21.8 Improved processing of tables diff --git a/Windows/Makefile.mingw b/Windows/Makefile.mingw new file mode 100644 index 0000000..56e7456 --- /dev/null +++ b/Windows/Makefile.mingw @@ -0,0 +1,43 @@ +# +# Makefile for unrtf (MinGW version) +# + +CC = gcc +LD = gcc + +INSTALL = cp -f +INSTALL_PROGRAM = $(INSTALL) +INSTALL_DATA = $(INSTALL) + +# must be equal to DEBUG or NDEBUG +DB = NDEBUG +OPT = -O2 + +LDLIBS = -liconv -lShlwapi + +CFLAGS = -Wall $(OPT) -D$(DB) -I. -DHAVE_CONFIG_H +LDFLAGS = + +SRCS = attr.c convert.c error.c hash.c my_iconv.c main.c \ + malloc.c output.c parse.c path.c unicode.c user.c \ + util.c word.c unrtf_w.c +OBJS = attr.o convert.o error.o hash.o my_iconv.o main.o \ + malloc.o output.o parse.o path.o unicode.o user.o \ + util.o word.o unrtf_w.o + +PROGS = unrtf + +VPATH = ./:../src + +all: $(PROGS) + +clean: + rm -f $(OBJS) + rm -f $(PROGS) + +unrtf : $(OBJS) + @rm -f $@ + $(LD) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@ + +.c.o: + $(CC) $(CFLAGS) -c $< diff --git a/Windows/SolutionSettings.props b/Windows/SolutionSettings.props new file mode 100644 index 0000000..2533e5b --- /dev/null +++ b/Windows/SolutionSettings.props @@ -0,0 +1,15 @@ + + + + + c:\recolldeps\iconv64 + + + + + + $(libiconv) + true + + + \ No newline at end of file diff --git a/Windows/safeunistd.h b/Windows/safeunistd.h new file mode 100644 index 0000000..626e969 --- /dev/null +++ b/Windows/safeunistd.h @@ -0,0 +1,78 @@ +/* safeunistd.h: , but with compat. and large file support for MSVC. + * + * Copyright (C) 2007 Olly Betts + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef XAPIAN_INCLUDED_SAFEUNISTD_H +#define XAPIAN_INCLUDED_SAFEUNISTD_H + +#ifndef _MSC_VER +# include +#else + +// sys/types.h has a typedef for off_t so make sure we've seen that before +// we hide it behind a #define. +# include + +// MSVC doesn't even HAVE unistd.h - io.h seems the nearest equivalent. +// We also need to do some renaming of functions to get versions which +// work on large files. +# include + +# ifdef lseek +# undef lseek +# endif + +# ifdef off_t +# undef off_t +# endif + +# define lseek(FD, OFF, WHENCE) _lseeki64(FD, OFF, WHENCE) +# define off_t __int64 + +// process.h is needed for getpid(). +# include + +#endif + +#ifdef _MSC_VER + +inline unsigned int +sleep(unsigned int seconds) +{ + // Use our own little helper function to avoid pulling in . + extern void xapian_sleep_milliseconds(unsigned int millisecs); + + // Sleep takes a time interval in milliseconds, whereas POSIX sleep takes + // a time interval in seconds, so we need to multiply 'seconds' by 1000. + // + // But make sure the multiplication won't overflow! 4294967 seconds is + // nearly 50 days, so just sleep for that long and return the number of + // seconds left to sleep for. The common case of sleep(CONSTANT) should + // optimise to just xapian_sleep_milliseconds(CONSTANT). + if (seconds > 4294967u) { + xapian_sleep_milliseconds(4294967000u); + return seconds - 4294967u; + } + xapian_sleep_milliseconds(seconds * 1000u); + return 0; +} + +#endif + +#endif /* XAPIAN_INCLUDED_SAFEUNISTD_H */ diff --git a/Windows/unrtf.sln b/Windows/unrtf.sln new file mode 100644 index 0000000..f22543c --- /dev/null +++ b/Windows/unrtf.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unrtf", "unrtf.vcxproj", "{4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Debug|x64.ActiveCfg = Release|Win32 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Debug|x64.Build.0 = Release|Win32 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Debug|x86.ActiveCfg = Debug|Win32 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Debug|x86.Build.0 = Debug|Win32 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Release|x64.ActiveCfg = Release|x64 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Release|x64.Build.0 = Release|x64 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Release|x86.ActiveCfg = Release|Win32 + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Windows/unrtf.vcxproj b/Windows/unrtf.vcxproj new file mode 100644 index 0000000..754916a --- /dev/null +++ b/Windows/unrtf.vcxproj @@ -0,0 +1,199 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {4122B6B8-B7D8-46A4-9119-C7CE1CA9AB24} + Win32Proj + unrtf + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + $(SolutionDir)\$(Platform)\$(Configuration)\ + + + false + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir);$(libiconv)\include + + + Console + true + $(libiconv)\libiconv\$(Platform)\$(Configuration) + libiconv.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir);$(libiconv)\include + + + Console + true + $(libiconv)\libiconv\$(Platform)\$(Configuration) + libiconv.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir);$(libiconv)\include + + + Console + true + true + true + $(libiconv)\libiconv\$(Platform)\$(Configuration) + libiconv.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;HAVE_CONFIG_H;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(SolutionDir);$(libiconv)\include + + + Console + true + true + true + $(libiconv)\libiconv\$(Platform)\$(Configuration) + libiconv.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Windows/unrtf.vcxproj.filters b/Windows/unrtf.vcxproj.filters new file mode 100644 index 0000000..dee286e --- /dev/null +++ b/Windows/unrtf.vcxproj.filters @@ -0,0 +1,114 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Windows/unrtf_w.c b/Windows/unrtf_w.c new file mode 100644 index 0000000..464dfe7 --- /dev/null +++ b/Windows/unrtf_w.c @@ -0,0 +1,109 @@ +#include "config.h" + +#ifdef _WIN32 +/*- +* Copyright (c) 1990, 1993 +* The Regents of the University of California. All rights reserved. +* +* The quadratic code is derived from software contributed to Berkeley by +* Chris Torek. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 4. Neither the name of the University nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +*/ + +#include +#include +#include + +/* +* Find the first occurrence of find in s, ignore case. +*/ +char *strcasestr(const char *s, const char *find) +{ + /* Less code size, but quadratic performance in the worst case. */ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} + + + +unsigned int unrtf_ntohl(unsigned int in) +{ + const unsigned char *f = (const unsigned char*)∈ + return( + ((unsigned int)(f[3])) + + ((unsigned int)(f[2]) << 8) + + ((unsigned int)(f[1]) << 16) + + ((unsigned int)(f[0]) << 24)); +} + +#endif + +#include +#pragma comment(lib, "shlwapi.lib") + +const char *path_thisexecpath() +{ +#ifdef UNICODE +Error: Need to add UNICODE code here +#else + static TCHAR text[MAX_PATH]; + if (text[0] == 0) { + DWORD length = GetModuleFileName(NULL, text, MAX_PATH); +#ifdef NTDDI_WIN8_future + PathCchRemoveFileSpec(text, MAX_PATH); +#else + PathRemoveFileSpec(text); +#endif + } + return (const char *)text; +#endif +} + +/* Location for program data: charmaps etc */ +const char *unrtfDataDir() +{ + static char buffer[MAX_PATH]; + if (buffer[0] == 0) { + const char *execdir = path_thisexecpath(); + if (strlen(execdir) + strlen("Share") + 4 < MAX_PATH) { + snprintf(buffer, MAX_PATH, "%s\\Share\\", execdir); + } + } + return buffer; +} diff --git a/aclocal.m4 b/aclocal.m4 index 307288e..93cf701 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.13.4 -*- Autoconf -*- - -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# generated automatically by aclocal 1.15.1 -*- Autoconf -*- + +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -20,7 +20,7 @@ If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) -# Copyright (C) 2002-2013 Free Software Foundation, Inc. +# Copyright (C) 2002-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -32,10 +32,10 @@ # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], -[am__api_version='1.13' +[am__api_version='1.15' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.13.4], [], +m4_if([$1], [1.15.1], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,14 +51,14 @@ # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.13.4])dnl +[AM_AUTOMAKE_VERSION([1.15.1])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -103,15 +103,14 @@ # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], -[dnl Rely on autoconf to set up CDPATH properly. -AC_PREREQ([2.50])dnl -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +[AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -142,7 +141,7 @@ Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -333,7 +332,7 @@ # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2013 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -409,7 +408,7 @@ # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -417,6 +416,12 @@ # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. + +dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O. +m4_define([AC_PROG_CC], +m4_defn([AC_PROG_CC]) +[_AM_PROG_CC_C_O +]) # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) # AM_INIT_AUTOMAKE([OPTIONS]) @@ -493,8 +498,8 @@ # # AC_SUBST([mkdir_p], ['$(MKDIR_P)']) -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl @@ -526,6 +531,51 @@ AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) + fi +fi +dnl The trailing newline in this macro's definition is deliberate, for +dnl backward compatibility and to allow trailing 'dnl'-style comments +dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. ]) dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not @@ -533,7 +583,6 @@ dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) - # When config.status generates a header, we must update the stamp-h file. # This file resides in the same directory as the config header @@ -556,7 +605,7 @@ done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -567,7 +616,7 @@ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl -if test x"${install_sh}" != xset; then +if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; @@ -577,7 +626,7 @@ fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2013 Free Software Foundation, Inc. +# Copyright (C) 2003-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -599,7 +648,7 @@ # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -634,7 +683,7 @@ # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -684,7 +733,7 @@ # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2013 Free Software Foundation, Inc. +# Copyright (C) 1997-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -723,7 +772,7 @@ # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -752,9 +801,73 @@ AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) +# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# _AM_PROG_CC_C_O +# --------------- +# Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC +# to automatically call this. +AC_DEFUN([_AM_PROG_CC_C_O], +[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl +AC_REQUIRE_AUX_FILE([compile])dnl +AC_LANG_PUSH([C])dnl +AC_CACHE_CHECK( + [whether $CC understands -c and -o together], + [am_cv_prog_cc_c_o], + [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i]) +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +AC_LANG_POP([C])]) + +# For backward compatibility. +AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) + +# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_RUN_LOG(COMMAND) +# ------------------- +# Run COMMAND, save the exit status in ac_status, and log it. +# (This has been adapted from Autoconf's _AC_RUN_LOG macro.) +AC_DEFUN([AM_RUN_LOG], +[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD + ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD + (exit $ac_status); }]) + # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2013 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -835,7 +948,7 @@ rm -f conftest.file ]) -# Copyright (C) 2009-2013 Free Software Foundation, Inc. +# Copyright (C) 2009-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -895,7 +1008,7 @@ _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2013 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -923,7 +1036,7 @@ INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2013 Free Software Foundation, Inc. +# Copyright (C) 2006-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -942,7 +1055,7 @@ # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2013 Free Software Foundation, Inc. +# Copyright (C) 2004-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff --git a/charmaps/Makefile.am b/charmaps/Makefile.am index 6cb9aa0..c8d35a8 100644 --- a/charmaps/Makefile.am +++ b/charmaps/Makefile.am @@ -1,2 +1,2 @@ -outputsdir = ${libdir}/${PACKAGE} +outputsdir = ${pkgdatadir} dist_outputs_DATA = SYMBOL.charmap diff --git a/configure b/configure index f755e5f..5a33bd9 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for unrtf 0.21.9. +# Generated by GNU Autoconf 2.69 for unrtf 0.21.10. # # Report bugs to . # @@ -580,8 +580,8 @@ # Identity of this package. PACKAGE_NAME='unrtf' PACKAGE_TARNAME='unrtf' -PACKAGE_VERSION='0.21.9' -PACKAGE_STRING='unrtf 0.21.9' +PACKAGE_VERSION='0.21.10' +PACKAGE_STRING='unrtf 0.21.10' PACKAGE_BUGREPORT='bug-unrtf@gnu.org' PACKAGE_URL='' @@ -1278,7 +1278,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures unrtf 0.21.9 to adapt to many kinds of systems. +\`configure' configures unrtf 0.21.10 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1348,7 +1348,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of unrtf 0.21.9:";; + short | recursive ) echo "Configuration of unrtf 0.21.10:";; esac cat <<\_ACEOF @@ -1442,7 +1442,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -unrtf configure 0.21.9 +unrtf configure 0.21.10 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1811,7 +1811,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by unrtf $as_me 0.21.9, which was +It was created by unrtf $as_me 0.21.10, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2194,7 +2194,7 @@ # Initialize automake -am__api_version='1.13' +am__api_version='1.15' # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or @@ -2366,8 +2366,8 @@ ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` -# expand $ac_aux_dir to an absolute path -am_aux_dir=`cd $ac_aux_dir && pwd` +# Expand $ac_aux_dir to an absolute path. +am_aux_dir=`cd "$ac_aux_dir" && pwd` if test x"${MISSING+set}" != xset; then case $am_aux_dir in @@ -2386,7 +2386,7 @@ $as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi -if test x"${install_sh}" != xset; then +if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; @@ -2680,7 +2680,7 @@ # Define the identity of the package. PACKAGE='unrtf' - VERSION='0.21.9' + VERSION='0.21.10' cat >>confdefs.h <<_ACEOF @@ -2714,8 +2714,8 @@ # mkdir_p='$(MKDIR_P)' -# We need awk for the "check" target. The system "awk" is bad on -# some platforms. +# We need awk for the "check" target (and possibly the TAP driver). The +# system "awk" is bad on some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AMTAR='$${TAR-tar}' @@ -2730,6 +2730,48 @@ + +# POSIX will say in a future version that running "rm -f" with no argument +# is OK; and we want to be able to make that assumption in our Makefile +# recipes. So use an aggressive probe to check that the usage we want is +# actually supported "in the wild" to an acceptable degree. +# See automake bug#10828. +# To make any issue more visible, cause the running configure to be aborted +# by default if the 'rm' program in use doesn't match our expectations; the +# user can still override this though. +if rm -f && rm -fr && rm -rf; then : OK; else + cat >&2 <<'END' +Oops! + +Your 'rm' program seems unable to run without file operands specified +on the command line, even when the '-f' option is present. This is contrary +to the behaviour of most rm programs out there, and not conforming with +the upcoming POSIX standard: + +Please tell bug-automake@gnu.org about your system, including the value +of your $PATH and any error possibly output before this message. This +can help us improve future automake versions. + +END + if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then + echo 'Configuration will proceed anyway, since you have set the' >&2 + echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 + echo >&2 + else + cat >&2 <<'END' +Aborting the configuration process, to ensure you take notice of the issue. + +You can download and install GNU coreutils to get an 'rm' implementation +that behaves properly: . + +If you want to complete the configuration process using your problematic +'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM +to "yes", and re-run configure. + +END + as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 + fi +fi # AM_MAINTAINER_MODE is a controversial macro. @@ -3556,6 +3598,65 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } +if ${am_cv_prog_cc_c_o+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF + # Make sure it works both with $CC and with simple cc. + # Following AC_PROG_CC_C_O, we do the test twice because some + # compilers refuse to overwrite an existing .o file with -o, + # though they will create one. + am_cv_prog_cc_c_o=yes + for am_i in 1 2; do + if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 + ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } \ + && test -f conftest2.$ac_objext; then + : OK + else + am_cv_prog_cc_c_o=no + break + fi + done + rm -f core conftest* + unset am_i +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +$as_echo "$am_cv_prog_cc_c_o" >&6; } +if test "$am_cv_prog_cc_c_o" != yes; then + # Losing compiler, so override with the script. + # FIXME: It is wrong to rewrite CC. + # But if we don't then we get into trouble of one sort or another. + # A longer-term fix would be to have automake use am__CC in this case, + # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" + CC="$am_aux_dir/compile $CC" +fi +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" @@ -4327,6 +4428,8 @@ ;; *-*-darwin*) LIBS="-liconv" ;; + *-*-solaris*) LIBS="-liconv" +;; esac ac_config_files="$ac_config_files Makefile doc/Makefile outputs/Makefile patches/Makefile src/Makefile tests/Makefile" @@ -4865,7 +4968,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by unrtf $as_me 0.21.9, which was +This file was extended by unrtf $as_me 0.21.10, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4931,7 +5034,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -unrtf config.status 0.21.9 +unrtf config.status 0.21.10 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index c717835..b42ee4a 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([unrtf], [0.21.9], [bug-unrtf@gnu.org]) +AC_INIT([unrtf], [0.21.10], [bug-unrtf@gnu.org]) AC_CONFIG_SRCDIR([src/attr.c]) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_HEADER([config.h]) @@ -46,6 +46,7 @@ *-*-cygwin*) AC_SUBST(LIBS, ["-liconv"]);; *aix*) AC_SUBST(LIBS, ["-liconv"]);; *-*-darwin*) AC_SUBST(LIBS, ["-liconv"]);; + *-*-solaris*) AC_SUBST(LIBS, ["-liconv"]);; esac AC_CONFIG_FILES([Makefile diff --git a/doc/Makefile.in b/doc/Makefile.in index 123dd98..ec63b5b 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,7 +14,17 @@ @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -78,12 +88,11 @@ build_triplet = @build@ host_triplet = @host@ subdir = doc -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(dist_man1_MANS) ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = @@ -139,6 +148,7 @@ NROFF = nroff MANS = $(dist_man1_MANS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(dist_man1_MANS) $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -253,7 +263,6 @@ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu doc/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu doc/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -468,6 +477,8 @@ mostlyclean-generic pdf pdf-am ps ps-am tags-am uninstall \ uninstall-am uninstall-man uninstall-man1 +.PRECIOUS: Makefile + unrtf.1: unrtf.1.in Makefile sed -e 's!@DATADIR@!${datarootdir}/unrtf!g' < ${srcdir}/unrtf.1.in > unrtf.1 diff --git a/outputs/Makefile.in b/outputs/Makefile.in index e055202..b6046ff 100644 --- a/outputs/Makefile.in +++ b/outputs/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -15,7 +15,17 @@ @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -79,12 +89,12 @@ build_triplet = @build@ host_triplet = @host@ subdir = outputs -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(dist_outputs_DATA) ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(dist_outputs_DATA) \ + $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = @@ -138,6 +148,7 @@ am__installdirs = "$(DESTDIR)$(outputsdir)" DATA = $(dist_outputs_DATA) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -260,7 +271,6 @@ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu outputs/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu outputs/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -453,6 +463,8 @@ mostlyclean-generic pdf pdf-am ps ps-am tags-am uninstall \ uninstall-am uninstall-dist_outputsDATA +.PRECIOUS: Makefile + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/outputs/html.conf b/outputs/html.conf index acc6d8c..838f608 100644 --- a/outputs/html.conf +++ b/outputs/html.conf @@ -178,6 +178,14 @@ dbl_strikethru_end +all_caps_begin + +all_caps_end + +small_caps_begin + +small_caps_end + emboss_begin emboss_end @@ -759,3 +767,388 @@ ♥ 9839 ♦ +# non unicode characters in the symbol font +# see http://www.fileformat.info/info/unicode/font/symbol/nonunicode.htm +# 61472 space? +61473 + ! +61474 + ∀ +61475 + \# +61476 + ∃ +61475 + % +61478 + & +61479 + ∋ +61480 + ( +61481 + ) +61482 + * +61483 + + +61484 + , +61485 + — +61486 + . +61487 + / +61488 + 0 +61489 + 1 +61490 + 2 +61491 + 3 +61492 + 4 +61493 + 5 +61494 + 6 +61495 + 7 +61496 + 8 +61497 + 9 +61498 + : +61499 + ; +61500 + < +61501 + = +61502 + > +61503 + ? +61504 + ≅ +61505 + Α +61506 + Β +61507 + Χ +61508 + Δ +61509 + Ε +61510 + Φ +61511 + Γ +61512 + Η +61513 + Ι +61514 + ϕ +61515 + Κ +61516 + Λ +61517 + Μ +61518 + Ν +61519 + Ο +61520 + Π +61521 + Θ +61522 + Ρ +61523 + Σ +61524 + Τ +61525 + Υ +61526 + ς +61527 + Ω +61528 + Ξ +61529 + Ψ +61530 + Ζ +61531 + [ +61532 + ∴ +61533 + ] +61534 + ⊥ +61535 + _ +61536 + ‾ +61537 + α +61538 + β +61539 + χ +61540 + δ +61541 + ε +61542 + φ +61543 + γ +61544 + η +61545 + τ +61546 + ϕ +61547 + κ +61548 + λ +61549 + μ +61550 + ν +61551 + ο +61552 + π +61553 + θ +61554 + ρ +61555 + σ +61556 + τ +61557 + υ +61558 + ϖ +61559 + ω +61560 + ξ +61561 + ψ +61562 + ζ +61563 + { +61564 + | +61565 + } +61566 + ∼ +61600 + € +61601 + ϒ +61602 + ′ +61603 + ≤ +61604 + ⁄ +61605 + ∞ +61606 + ƒ +61607 + ♣ +61608 + ♦ +61609 + ♥ +61610 + ♠ +61611 + ↔ +61612 + ← +61613 + ↑ +61614 + → +61615 + ↓ +61616 + ° +61617 + ± +61618 + ″ +61619 + ≥ +61620 + × +61621 + ∝ +61622 + ∂ +61623 + • +61624 + ÷ +61625 + ≠ +61626 + ≡ +61627 + ≈ +61628 + … +# vertical bar +61629 + | +61630 + — +61631 + ↵ +61632 + ℵ +61633 + ℑ +61634 + ℜ +61635 + ℘ +61636 + ⊗ +61637 + ⊕ +61638 + ∅ +61639 + ∩ +61640 + ∪ +61641 + ⊃ +61642 + ⊇ +61643 + ⊄ +61644 + ⊂ +61645 + ⊆ +61646 + ∈ +61647 + ∉ +61648 + ∠ +61649 + ∇ +61650 + ® +61651 + © +61652 + ™ +61653 + ∏ +61654 + √ +61655 + · +61656 + ¬ +61657 + ∧ +61658 + ∨ +61659 + ⇔ +61660 + ⇐ +61661 + ⇑ +61662 + ⇒ +61663 + ⇓ +61664 + ◊ +61665 + ⟨ +61666 + ® +61667 + © +61668 + ™ +61669 + ∑ +#61670 +# large right parenthesis ceiling +#61671 +# large parenthesis middle +#61672 +# large left parenthesis floor +61673 +# large left square bracket ceiling + ⌈ +#61674 +# large left square bracket middle +61675 +# large left square bracket floor + ⌊ +#61676 +# large left bracket ceiling +# 61677 +# large left bracket middle +#61678 +# large left bracket floor +#61679 +# large vertical bar +#61680 +# appears blank +61681 + ⟩ +61682 +# integral + ∫ +#61683 +# large integral ceiling +#61684 +# large integral middle +#61685 +# large integral floor +#61686 +# large right parenthesis ceiling +#61687 +# large right parenthesis middle +#61688 +# large right parenthesis floor +61689 +# large right square bracket ceiling + ⌉ +#61690 +# large right square bracket middle +61691 +# large right square bracket floor + ⌋ +#61692 +# large right bracket middle +#61694 +# large right bracket floot diff --git a/patches/Makefile.in b/patches/Makefile.in index c463660..ec99a74 100644 --- a/patches/Makefile.in +++ b/patches/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -17,7 +17,17 @@ # this simple Makefile.am just adds the patches to the distributed # tarball in the release. VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -81,11 +91,11 @@ build_triplet = @build@ host_triplet = @host@ subdir = patches -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = @@ -110,6 +120,7 @@ *) (install-info --version) >/dev/null 2>&1;; \ esac am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -223,7 +234,6 @@ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu patches/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu patches/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -391,6 +401,8 @@ maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ pdf-am ps ps-am tags-am uninstall uninstall-am +.PRECIOUS: Makefile + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/Makefile.in b/src/Makefile.in index 5e3feff..a2ab3ae 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -18,7 +18,17 @@ # It all works automagically. VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -83,12 +93,11 @@ host_triplet = @host@ bin_PROGRAMS = unrtf$(EXEEXT) subdir = src -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/config/depcomp ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = @@ -156,6 +165,7 @@ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -286,7 +296,6 @@ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu src/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -377,14 +386,14 @@ @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique @@ -590,6 +599,8 @@ ps ps-am tags tags-am uninstall uninstall-am \ uninstall-binPROGRAMS +.PRECIOUS: Makefile + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/src/attr.c b/src/attr.c index 02b5c81..7b42fb6 100644 --- a/src/attr.c +++ b/src/attr.c @@ -75,7 +75,7 @@ extern int simulate_smallcaps; -#define MAX_ATTRS (10000) +#define MAX_ATTRS 100 /* For each RTF text block (the text within braces) we must keep @@ -85,17 +85,97 @@ * from parent blocks, all new AttrStacks do the same from * their parent AttrStack. */ -typedef struct _stack { +typedef struct _stack +{ unsigned char attr_stack[MAX_ATTRS]; - char *attr_stack_params[MAX_ATTRS]; + char *attr_stack_params[MAX_ATTRS]; int tos; - struct _stack *next; + struct _stack *prev; } AttrStack; /*@null@*/ static AttrStack *stack_of_stacks = NULL; /*@null@*/ static AttrStack *stack_of_stacks_top = NULL; - +static void attr_express_begin(int attr, char *param); +static void attr_express_end(int attr, char *param); + + +/* Iterate from top of given stack looking for findattr */ +static int attr_find(AttrStack *stack, int findattr) +{ + int i; + for (i = stack->tos; i >= 0; i--) + if (stack->attr_stack[i] == findattr) + { + return i; + } + return -1; +} + +/* Iterate all stacks looking for most recent value for attr */ +static int attrstack_find_attr(int findattr, char **paramp) +{ + AttrStack *stack = stack_of_stacks_top; + + while (stack) + { + int index = attr_find(stack, findattr); + if (index >= 0) + { + *paramp = stack->attr_stack_params[index]; + return TRUE; + } + stack = stack->prev; + } + return FALSE; +} + +/* Remove attribute at the given index, unexpressing and reexpressing + the ones above in appropriate order. */ +static void attr_pull_out(AttrStack *stack, int index) +{ + int j; + /* Unexpress all newer attributes, and the one we'll remove */ + for (j = stack->tos; j >= index; j--) + { + attr_express_end(stack->attr_stack[j], stack->attr_stack_params[j]); + } + + /* Delete target attribute and shift the stack down */ + if (stack->attr_stack_params[index]) + my_free(stack->attr_stack_params[index]); + for (j = index; j < stack->tos; j++) + { + stack->attr_stack[j] = stack->attr_stack[j + 1]; + stack->attr_stack_params[j] = stack->attr_stack_params[j + 1]; + } + stack->tos--; + + /* Re-express unexpressed attributes */ + for (j = index; j <= stack->tos; j++) + { + attr_express_begin(stack->attr_stack[j], stack->attr_stack_params[j]); + } + return; +} + +/* Unexpress and remove top attr. Internal version, no checking of args */ +static void attr_pop_internal(AttrStack *stack, int attr) +{ + if (stack->tos >= 0) + { + char *param = stack->attr_stack_params[stack->tos]; + + attr_express_end(attr, param); + + if (param) + { + my_free(param); + } + + stack->tos--; + } +} /*======================================================================== @@ -105,93 +185,157 @@ * Returns: None. *=======================================================================*/ -void -attr_express_begin (int attr, char* param) { - switch(attr) - { - case ATTR_BOLD: - if (safe_printf(0, op->bold_begin)) fprintf(stderr, TOO_MANY_ARGS, "bold_begin");; - break; - case ATTR_ITALIC: - if (safe_printf(0, op->italic_begin)) fprintf(stderr, TOO_MANY_ARGS, "italic_begin");; +static void attr_express_begin(int attr, char *param) +{ + switch (attr) + { + case ATTR_BOLD: + if (safe_printf(0, op->bold_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "bold_begin"); + }; + break; + case ATTR_ITALIC: + if (safe_printf(0, op->italic_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "italic_begin"); + }; break; /* Various underlines, they all resolve to HTML's */ case ATTR_THICK_UL: case ATTR_WAVE_UL: case ATTR_DASH_UL: - case ATTR_DOT_UL: + case ATTR_DOT_UL: case ATTR_DOT_DASH_UL: case ATTR_2DOT_DASH_UL: - case ATTR_WORD_UL: - case ATTR_UNDERLINE: - if (safe_printf(0, op->underline_begin)) fprintf(stderr, TOO_MANY_ARGS, "underline_begin");; - break; - - case ATTR_DOUBLE_UL: - if (safe_printf(0, op->dbl_underline_begin)) fprintf(stderr, TOO_MANY_ARGS, "dbl_underline_begin");; - break; - - case ATTR_FONTSIZE: - op_begin_std_fontsize (op, atoi (param)); - break; - - case ATTR_FONTFACE: - if (safe_printf(1, op->font_begin,param)) fprintf(stderr, TOO_MANY_ARGS, "font_begin");; - break; - - case ATTR_FOREGROUND: - if (safe_printf(1, op->foreground_begin, param)) fprintf(stderr, TOO_MANY_ARGS, "foreground_begin");; - break; - - case ATTR_BACKGROUND: + case ATTR_WORD_UL: + case ATTR_UNDERLINE: + if (safe_printf(0, op->underline_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "underline_begin"); + }; + break; + + case ATTR_DOUBLE_UL: + if (safe_printf(0, op->dbl_underline_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "dbl_underline_begin"); + }; + break; + + case ATTR_FONTSIZE: + op_begin_std_fontsize(op, atoi(param)); + break; + + case ATTR_FONTFACE: + if (safe_printf(1, op->font_begin, param)) + { + fprintf(stderr, TOO_MANY_ARGS, "font_begin"); + }; + break; + + case ATTR_FOREGROUND: + if (safe_printf(1, op->foreground_begin, param)) + { + fprintf(stderr, TOO_MANY_ARGS, "foreground_begin"); + }; + break; + + case ATTR_BACKGROUND: if (!simple_mode) - if (safe_printf(1, op->background_begin,param)) fprintf(stderr, TOO_MANY_ARGS, "background_begin");; - break; - - case ATTR_SUPER: - if (safe_printf(0, op->superscript_begin)) fprintf(stderr, TOO_MANY_ARGS, "superscript_begin");; - break; - case ATTR_SUB: - if (safe_printf(0, op->subscript_begin)) fprintf(stderr, TOO_MANY_ARGS, "subscript_begin");; - break; - - case ATTR_STRIKE: - if (safe_printf(0, op->strikethru_begin)) fprintf(stderr, TOO_MANY_ARGS, "strikethru_begin");; - break; - - case ATTR_DBL_STRIKE: - if (safe_printf(0, op->dbl_strikethru_begin)) fprintf(stderr, TOO_MANY_ARGS, "dbl_strikethru_begin");; - break; - - case ATTR_EXPAND: - if (safe_printf(1, op->expand_begin, param)) fprintf(stderr, TOO_MANY_ARGS, "expand_begin");; - break; - - case ATTR_OUTLINE: - if (safe_printf(0, op->outline_begin)) fprintf(stderr, TOO_MANY_ARGS, "outline_begin");; - break; - case ATTR_SHADOW: - if (safe_printf(0, op->shadow_begin)) fprintf(stderr, TOO_MANY_ARGS, "shadow_begin");; - break; - case ATTR_EMBOSS: - if (safe_printf(0, op->emboss_begin)) fprintf(stderr, TOO_MANY_ARGS, "emboss_begin");; - break; - case ATTR_ENGRAVE: - if (safe_printf(0, op->engrave_begin)) fprintf(stderr, TOO_MANY_ARGS, "engrave_begin");; + if (safe_printf(1, op->background_begin, param)) + { + fprintf(stderr, TOO_MANY_ARGS, "background_begin"); + }; + break; + + case ATTR_SUPER: + if (safe_printf(0, op->superscript_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "superscript_begin"); + }; + break; + case ATTR_SUB: + if (safe_printf(0, op->subscript_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "subscript_begin"); + }; + break; + + case ATTR_STRIKE: + if (safe_printf(0, op->strikethru_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "strikethru_begin"); + }; + break; + + case ATTR_DBL_STRIKE: + if (safe_printf(0, op->dbl_strikethru_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "dbl_strikethru_begin"); + }; + break; + + case ATTR_EXPAND: + if (safe_printf(1, op->expand_begin, param)) + { + fprintf(stderr, TOO_MANY_ARGS, "expand_begin"); + }; + break; + + case ATTR_OUTLINE: + if (safe_printf(0, op->outline_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "outline_begin"); + }; + break; + case ATTR_SHADOW: + if (safe_printf(0, op->shadow_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "shadow_begin"); + }; + break; + case ATTR_EMBOSS: + if (safe_printf(0, op->emboss_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "emboss_begin"); + }; + break; + case ATTR_ENGRAVE: + if (safe_printf(0, op->engrave_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "engrave_begin"); + }; break; case ATTR_CAPS: if (op->simulate_all_caps) + { simulate_allcaps = TRUE; - break; - - case ATTR_SMALLCAPS: + } + else + { + if (op->all_caps_begin) + if (safe_printf(0, op->all_caps_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "all_caps_begin"); + } + } + break; + + case ATTR_SMALLCAPS: if (op->simulate_small_caps) + { simulate_smallcaps = TRUE; - else { + } + else + { if (op->small_caps_begin) - if (safe_printf(0, op->small_caps_begin)) fprintf(stderr, TOO_MANY_ARGS, "small_caps_begin");; + if (safe_printf(0, op->small_caps_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "small_caps_begin"); + }; } break; } @@ -205,93 +349,156 @@ * Returns: None. *=======================================================================*/ -void -attr_express_end (int attr, char *param) -{ - switch(attr) - { - case ATTR_BOLD: - if (safe_printf(0, op->bold_end)) fprintf(stderr, TOO_MANY_ARGS, "bold_end");; - break; - case ATTR_ITALIC: - if (safe_printf(0, op->italic_end)) fprintf(stderr, TOO_MANY_ARGS, "italic_end");; +static void attr_express_end(int attr, char *param) +{ + switch (attr) + { + case ATTR_BOLD: + if (safe_printf(0, op->bold_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "bold_end"); + }; + break; + case ATTR_ITALIC: + if (safe_printf(0, op->italic_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "italic_end"); + }; break; /* Various underlines, they all resolve to HTML's */ case ATTR_THICK_UL: case ATTR_WAVE_UL: case ATTR_DASH_UL: - case ATTR_DOT_UL: + case ATTR_DOT_UL: case ATTR_DOT_DASH_UL: - case ATTR_2DOT_DASH_UL: - case ATTR_WORD_UL: - case ATTR_UNDERLINE: - if (safe_printf(0, op->underline_end)) fprintf(stderr, TOO_MANY_ARGS, "underline_end");; - break; - - case ATTR_DOUBLE_UL: - if (safe_printf(0, op->dbl_underline_end)) fprintf(stderr, TOO_MANY_ARGS, "dbl_underline_end");; - break; - - case ATTR_FONTSIZE: - op_end_std_fontsize (op, atoi (param)); - break; - - case ATTR_FONTFACE: - if (safe_printf(0, op->font_end)) fprintf(stderr, TOO_MANY_ARGS, "font_end");; - break; - - case ATTR_FOREGROUND: - if (safe_printf(0, op->foreground_end)) fprintf(stderr, TOO_MANY_ARGS, "foreground_end");; - break; - case ATTR_BACKGROUND: + case ATTR_2DOT_DASH_UL: + case ATTR_WORD_UL: + case ATTR_UNDERLINE: + if (safe_printf(0, op->underline_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "underline_end"); + }; + break; + + case ATTR_DOUBLE_UL: + if (safe_printf(0, op->dbl_underline_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "dbl_underline_end"); + }; + break; + + case ATTR_FONTSIZE: + op_end_std_fontsize(op, atoi(param)); + break; + + case ATTR_FONTFACE: + if (safe_printf(0, op->font_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "font_end"); + }; + break; + + case ATTR_FOREGROUND: + if (safe_printf(0, op->foreground_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "foreground_end"); + }; + break; + case ATTR_BACKGROUND: if (!simple_mode) - if (safe_printf(0, op->background_end)) fprintf(stderr, TOO_MANY_ARGS, "background_end");; - break; - - case ATTR_SUPER: - if (safe_printf(0, op->superscript_end)) fprintf(stderr, TOO_MANY_ARGS, "superscript_end");; - break; - case ATTR_SUB: - if (safe_printf(0, op->subscript_end)) fprintf(stderr, TOO_MANY_ARGS, "subscript_end");; - break; - - case ATTR_STRIKE: - if (safe_printf(0, op->strikethru_end)) fprintf(stderr, TOO_MANY_ARGS, "strikethru_end");; - break; - - case ATTR_DBL_STRIKE: - if (safe_printf(0, op->dbl_strikethru_end)) fprintf(stderr, TOO_MANY_ARGS, "dbl_strikethru_end");; - break; - - case ATTR_OUTLINE: - if (safe_printf(0, op->outline_end)) fprintf(stderr, TOO_MANY_ARGS, "outline_end");; - break; - case ATTR_SHADOW: - if (safe_printf(0, op->shadow_end)) fprintf(stderr, TOO_MANY_ARGS, "shadow_end");; - break; - case ATTR_EMBOSS: - if (safe_printf(0, op->emboss_end)) fprintf(stderr, TOO_MANY_ARGS, "emboss_end");; - break; - case ATTR_ENGRAVE: - if (safe_printf(0, op->engrave_end)) fprintf(stderr, TOO_MANY_ARGS, "engrave_end");; - break; - - case ATTR_EXPAND: - if (safe_printf(0, op->expand_end)) fprintf(stderr, TOO_MANY_ARGS, "expand_end");; + if (safe_printf(0, op->background_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "background_end"); + }; + break; + + case ATTR_SUPER: + if (safe_printf(0, op->superscript_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "superscript_end"); + }; + break; + case ATTR_SUB: + if (safe_printf(0, op->subscript_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "subscript_end"); + }; + break; + + case ATTR_STRIKE: + if (safe_printf(0, op->strikethru_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "strikethru_end"); + }; + break; + + case ATTR_DBL_STRIKE: + if (safe_printf(0, op->dbl_strikethru_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "dbl_strikethru_end"); + }; + break; + + case ATTR_OUTLINE: + if (safe_printf(0, op->outline_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "outline_end"); + }; + break; + case ATTR_SHADOW: + if (safe_printf(0, op->shadow_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "shadow_end"); + }; + break; + case ATTR_EMBOSS: + if (safe_printf(0, op->emboss_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "emboss_end"); + }; + break; + case ATTR_ENGRAVE: + if (safe_printf(0, op->engrave_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "engrave_end"); + }; + break; + + case ATTR_EXPAND: + if (safe_printf(0, op->expand_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "expand_end"); + }; break; case ATTR_CAPS: if (op->simulate_all_caps) + { simulate_allcaps = FALSE; - break; - - case ATTR_SMALLCAPS: + } + else + { + if (op->all_caps_end) + if (safe_printf(0, op->all_caps_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "all_caps_end"); + }; + } + break; + + case ATTR_SMALLCAPS: if (op->simulate_small_caps) + { simulate_smallcaps = FALSE; - else { + } + else + { if (op->small_caps_end) - if (safe_printf(0, op->small_caps_end)) fprintf(stderr, TOO_MANY_ARGS, "small_caps_end");; + if (safe_printf(0, op->small_caps_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "small_caps_end"); + }; } break; } @@ -306,16 +513,28 @@ * Returns: None. *=======================================================================*/ -void -attr_push(int attr, char* param) +void attr_push(int attr, char *param) { AttrStack *stack = stack_of_stacks_top; - if (!stack) { + int i; + char *oldparam; + + /*fprintf(stderr, "attr_push: [%d] [%s]\n", attr, param);*/ + + if (!stack) + { warning_handler("No stack to push attribute onto"); return; } - if (stack->tos >= MAX_ATTRS -1) { + /* Remove any current value of the same attr in the top stack */ + if ((i = attr_find(stack, attr)) != -1) + { + attr_pull_out(stack, i); + } + + if (stack->tos >= MAX_ATTRS - 1) + { fprintf(stderr, "Too many attributes!\n"); return; } @@ -327,14 +546,38 @@ ++stack->tos; stack->attr_stack[stack->tos] = attr; - if (param) + if (param) + { stack->attr_stack_params[stack->tos] = my_strdup(param); + } else + { stack->attr_stack_params[stack->tos] = NULL; + } attr_express_begin(attr, param); } +/* Unexpress and remove an attribute which is not the top one */ +int attr_find_pop(int findattr) +{ + int i; + AttrStack *stack = stack_of_stacks_top; + + if (!stack) + { + warning_handler("no stack to pop attributes from"); + return FALSE; + } + + /* Check whether findattr is on stack at all; if not, just give up */ + if ((i = attr_find(stack, findattr)) < 0) + { + return FALSE; + } + attr_pull_out(stack, i); + return TRUE; +} /*======================================================================== * Name: attr_get_param @@ -343,13 +586,15 @@ * Returns: string. *=======================================================================*/ -char * -attr_get_param(int attr) +char * +attr_get_param(int attr) { int i; AttrStack *stack = stack_of_stacks_top; - if (!stack) { - if (attr != ATTR_ENCODING) { + if (!stack) + { + if (attr != ATTR_ENCODING) + { /* * attr_get_param(ATTR_ENCODING) is always called * called once without a stack being available. @@ -359,17 +604,8 @@ return NULL; } - i=stack->tos; - while (i>=0) - { - if(stack->attr_stack [i] == attr) - { - if(stack->attr_stack_params [i] != NULL) - return stack->attr_stack_params [i]; - else - return NULL; - } - i--; + if ((i = attr_find(stack, attr)) >= 0) { + return stack->attr_stack_params[i]; } return NULL; } @@ -382,27 +618,27 @@ * Returns: None. *=======================================================================*/ -void -attrstack_copy_all (AttrStack *src, AttrStack *dest) +void +attrstack_copy_all(AttrStack *src, AttrStack *dest) { int i; - int total; CHECK_PARAM_NOT_NULL(src); CHECK_PARAM_NOT_NULL(dest); - total = src->tos + 1; - - for (i=0; iattr_stack [i]; - char *param=src->attr_stack_params [i]; - - dest->attr_stack[i] = attr; + for (i = 0; i <= src->tos; i++) + { + dest->attr_stack[i] = src->attr_stack[i]; + + char *param = src->attr_stack_params[i]; if (param) - dest->attr_stack_params[i] = my_strdup (param); + { + dest->attr_stack_params[i] = my_strdup(param); + } else + { dest->attr_stack_params[i] = NULL; + } } dest->tos = src->tos; @@ -415,25 +651,20 @@ * Args: Stack whose contents should be unexpressed. * Returns: None. * Notes: This is needed by attrstack_push, but also for \cell, which - * often occurs within a brace group, yet HTML uses + * often occurs within a brace group, yet HTML uses * which clear attribute info within that block. *=======================================================================*/ -void -attrstack_unexpress_all (AttrStack *stack) +void +attrstack_unexpress_all(AttrStack *stack) { int i; CHECK_PARAM_NOT_NULL(stack); - i=stack->tos; - while (i>=0) - { - int attr=stack->attr_stack [i]; - char *param=stack->attr_stack_params [i]; - - attr_express_end (attr, param); - i--; + for (i = stack->tos; i >= 0; i--) + { + attr_express_end(stack->attr_stack[i], stack->attr_stack_params[i]); } } @@ -445,57 +676,67 @@ * Args: None. * Returns: None. *=======================================================================*/ -void -attrstack_push () +void +attrstack_push() { AttrStack *new_stack; - new_stack = (AttrStack*) my_malloc (sizeof (AttrStack)); - memset ((void*) new_stack, 0, sizeof (AttrStack)); - - if (!stack_of_stacks) { + new_stack = (AttrStack *) my_malloc(sizeof(AttrStack)); + + if (new_stack == NULL) + { + warning_handler("out of memory"); + return; + } + + memset((void *) new_stack, 0, sizeof(AttrStack)); + + if (!stack_of_stacks) + { stack_of_stacks = new_stack; - } else { - stack_of_stacks_top->next = new_stack; - } + new_stack->tos = -1; + } + else + { + /* Parent stack exists. Copy all attributes. This means that they + will be unexpressed when we exit this group, which is why there + is a call to re-express the parent context in attrstack_drop */ + attrstack_copy_all(stack_of_stacks_top, new_stack); + } + + /* stack_of_stacks_top is NULL if this is the first stack */ + new_stack->prev = stack_of_stacks_top; stack_of_stacks_top = new_stack; - new_stack->tos = -1; -} - - - -/*======================================================================== - * Name: attr_pop +} + +/*======================================================================== + * Name: attr_pop * Purpose: Removes and undoes the effect of the top attribute of * the current AttrStack. * Args: The top attribute's number, for verification. * Returns: Success/fail flag. *=======================================================================*/ -int -attr_pop (int attr) +int +attr_pop(int attr) { AttrStack *stack = stack_of_stacks_top; - if (!stack) { - warning_handler ("no stack to pop attribute from"); + if (!stack) + { + warning_handler("no stack to pop attribute from"); return FALSE; } - if(stack->tos>=0 && stack->attr_stack[stack->tos]==attr) - { - char *param = stack->attr_stack_params [stack->tos]; - - attr_express_end (attr, param); - - if (param) my_free(param); - - stack->tos--; - + if (stack->tos >= 0 && stack->attr_stack[stack->tos] == attr) + { + attr_pop_internal(stack, attr); return TRUE; } else + { return FALSE; + } } @@ -508,44 +749,52 @@ * Returns: Attribute number. *=======================================================================*/ -int -attr_read() { +int +attr_read() +{ AttrStack *stack = stack_of_stacks_top; - if (!stack) { - warning_handler ("no stack to read attribute from"); + if (!stack) + { + warning_handler("no stack to read attribute from"); return FALSE; } - if(stack->tos>=0) + if (stack->tos >= 0) { int attr = stack->attr_stack [stack->tos]; return attr; } else + { return ATTR_NONE; -} - - -/*======================================================================== - * Name: attr_drop_all - * Purpose: Undoes all attributes that an AttrStack contains. + } +} + + +/*======================================================================== + * Name: attr_drop_all + * Purpose: Empty top attr stack without unexpressing attributes. * Args: None. * Returns: None. *=======================================================================*/ -void -attr_drop_all () +void +attr_drop_all() { AttrStack *stack = stack_of_stacks_top; - if (!stack) { - warning_handler ("no stack to drop all attributes from"); + if (!stack) + { + warning_handler("no stack to drop all attributes from"); return; } - while (stack->tos>=0) - { - char *param=stack->attr_stack_params [stack->tos]; - if (param) my_free(param); + while (stack->tos >= 0) + { + char *param = stack->attr_stack_params [stack->tos]; + if (param) + { + my_free(param); + } stack->tos--; } } @@ -559,64 +808,56 @@ * Returns: None. *=======================================================================*/ -void -attrstack_drop () +void +attrstack_drop() { AttrStack *stack = stack_of_stacks_top; - AttrStack *prev_stack; - if (!stack) { - warning_handler ("no attr-stack to drop"); + if (!stack) + { + warning_handler("no attr-stack to drop"); return; } - attr_pop_all (); - prev_stack = stack_of_stacks; - - while(prev_stack && prev_stack->next && prev_stack->next != stack) - prev_stack = prev_stack->next; - - /* prev_stack == stack_of_stacks_top if there was only one - element. We'll be empty. Note that prev_stack can't be - actually NULL here, this would happen with an empty stack, - which would have been detected by the !stack test above. - */ - if (prev_stack && (prev_stack != stack_of_stacks_top)) { - stack_of_stacks_top = prev_stack; - prev_stack->next = NULL; - } else { - stack_of_stacks_top = NULL; + attr_pop_all(); + + if (stack->prev == NULL) + { stack_of_stacks = NULL; } - - my_free ((void*) stack); + stack_of_stacks_top = stack->prev; + + my_free((void *) stack); + + /* Re-set attributes for parent state */ + if (stack_of_stacks_top) + { + attrstack_express_all(/*stack_of_stacks_top*/); + } } /*======================================================================== * Name: attr_pop_all - * Purpose: Routine to undo all attributes heretofore applied, + * Purpose: Routine to undo all attributes heretofore applied, * also reversing the order in which they were applied. * Args: None. * Returns: None. *=======================================================================*/ -void -attr_pop_all() +void +attr_pop_all() { AttrStack *stack = stack_of_stacks_top; - if (!stack) { - warning_handler ("no stack to pop from"); + if (!stack) + { + warning_handler("no stack to pop from"); return; } - while (stack->tos>=0) { - int attr=stack->attr_stack [stack->tos]; - char *param=stack->attr_stack_params [stack->tos]; - attr_express_end (attr,param); - if (param) my_free(param); - stack->tos--; - } -} - + while (stack->tos >= 0) + { + attr_pop_internal(stack, stack->attr_stack[stack->tos]); + } +} /*======================================================================== * Name: attrstack_express_all @@ -624,54 +865,25 @@ * Args: None. * Returns: None. * Notes: This is needed by attrstack_push, but also for \cell, which - * often occurs within a brace group, yet HTML uses + * often occurs within a brace group, yet HTML uses * which clear attribute info within that block. *=======================================================================*/ -void -attrstack_express_all() { +void +attrstack_express_all() +{ AttrStack *stack = stack_of_stacks_top; int i; - if (!stack) { - warning_handler ("no stack to pop from"); + if (!stack) + { + warning_handler("no stack to pop from"); return; } - i=0; - while (i<=stack->tos) - { - int attr=stack->attr_stack [i]; - char *param=stack->attr_stack_params [i]; - attr_express_begin (attr, param); - i++; - } -} - - -/*======================================================================== - * Name: attr_pop_dump - * Purpose: Routine to un-express all attributes heretofore applied. - * Args: None. - * Returns: None. - * Notes: This is needed for \cell, which often occurs within a - * brace group, yet HTML uses which clear attribute - * info within that block. - *=======================================================================*/ - -void -attr_pop_dump() { - AttrStack *stack = stack_of_stacks_top; - int i; - - if (!stack) return; - - i=stack->tos; - while (i>=0) - { - int attr=stack->attr_stack [i]; - attr_pop (attr); - i--; + for (i = 0; i <= stack->tos; i++) + { + attr_express_begin(stack->attr_stack[i], stack->attr_stack_params[i]); } } @@ -702,10 +914,12 @@ for (; nr > 0; nr--) { - while (string[i] != '\0' && (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i-1] == '\\')))) + while (string[i] != '\0' && (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i - 1] == '\\')))) { - if (string[i] != '\\' || string[i+1] != '%') + if (string[i] != '\\' || string[i + 1] != '%') + { printf("%c", string[i]); + } i++; } @@ -720,12 +934,16 @@ while (string[i] != '\0') { - if (string[i] != '\\' || (string[i] == '\\' && string[i+1] != '%')) + if (string[i] != '\\' || (string[i] == '\\' && string[i + 1] != '%')) { - if (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i-1] == '\\'))) + if (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i - 1] == '\\'))) + { printf("%c", string[i]); + } else + { ret_code = -1; + } } i++; } @@ -746,35 +964,45 @@ assemble_string(char *string, int nr) { - char *s, tmp[12];/* Number of characters that can be in int type (including '\0') - AF */ + char *s, tmp[20]; int i = 0, j = 0; if (string == NULL) + { return NULL; - else { + } + else + { s = my_malloc(strlen(string) + 1 + 12/* Number of characters that can be in int type (including '\0') - AF */); - while(string[i] != '\0' && (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i-1] == '\\')))) { - if (string[i] != '\\' || string[i+1] != '%') { - s[j] = string[i]; + while (string[i] != '\0' && (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i - 1] == '\\')))) + { + if (string[i] != '\\' || string[i + 1] != '%') + { + s[j] = string[i]; j++; } i++; } - if (string[i] != '\0') { - sprintf(tmp, "%d", nr); + if (string[i] != '\0') + { + snprintf(tmp, 20, "%d", nr); strcpy(&s[j], tmp); j = j + strlen(tmp); } - while (string[i] != '\0') { - if (string[i] != '\\' || (string[i] == '\\' && string[i+1] != '%')) { - if (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i-1] == '\\'))) { - s[j] = string[i]; + while (string[i] != '\0') + { + if (string[i] != '\\' || (string[i] == '\\' && string[i + 1] != '%')) + { + if (string[i] != '%' || (string[i] == '%' && (i != 0 && string[i - 1] == '\\'))) + { + s[j] = string[i]; j++; } - else { - /* More than one char % occured */ + else + { + /* More than one char % occured */ } } i++; @@ -808,21 +1036,25 @@ } else { - do { + do + { if (c->nr == nr) { -/* Here is a memory leak but not heavy. Do we need to care about this? - my_free(a->alias.text); -*/ + /* Here is a memory leak but not heavy. Do we need to care about this? + my_free(a->alias.text); + */ c->text = text; return col; } - if (c->next == NULL) - break; + if (c->next == NULL) + { + break; + } c = c->next; - } while (1); + } + while (1); c->next = (Collection *)my_malloc(sizeof(Collection)); c->next->nr = nr; @@ -846,7 +1078,9 @@ while (c != NULL) { if (c->nr == nr) + { return c->text; + } c = c->next; } @@ -858,7 +1092,7 @@ * Name: free_collection * Purpose: Release memory used by collection. * Args: Needless collection. - * Returns: + * Returns: *=======================================================================*/ void @@ -873,66 +1107,3 @@ c = c2; } } - -#define SUPPORT_UNNESTED -#ifdef SUPPORT_UNNESTED - -// Push onto AttrStack generally, without extra bells and whistles -void attr_push_gen(AttrStack *stack, int attr, char *param) { - stack->tos++; - stack->attr_stack[stack->tos] = attr; - if (param) - stack->attr_stack_params[stack->tos] = param; - else - stack->attr_stack_params[stack->tos] = NULL; -} - -// Pop from AttrStack generally, without extra bells and whistles -void attr_pop_gen(AttrStack *stack, int *attr, char **param) { - *attr = stack->attr_stack[stack->tos]; - *param = stack->attr_stack_params[stack->tos]; - stack->tos--; -} - -// Iterate through stack looking for findattr -int attr_find(AttrStack *stack, int findattr) { - int i; - for (i = 0; i <= stack->tos; ++i) - if (stack->attr_stack[i] == findattr) return i; - return -1; -} - -// Pop attrs until we find the match, then push the non-matches back -static AttrStack temp_stack; -int attr_find_pop(int findattr) { - temp_stack.tos = -1; // initialize temp_stack if necessary - - AttrStack *stack = stack_of_stacks_top; - if (!stack) { - warning_handler ("no stack to pop attributes from"); - return FALSE; - } - - // Check whether findattr is on stack at all; if not, just give up - if (attr_find(stack, findattr) < 0) return FALSE; - - // Get findattr from stack, expressing endings. - // Store any non-matches to temp_stack. - int attr = ATTR_NONE; - char *param = NULL; - while (stack->tos >= 0) { - attr_pop_gen(stack, &attr, ¶m); - attr_express_end(attr, param); - if (attr == findattr) break; - attr_push_gen(&temp_stack, attr, param); - } - - // Put the non-matches back, reexpressing beginnings - while (temp_stack.tos >= 0) { - attr_pop_gen(&temp_stack, &attr, ¶m); - attr_push(attr, param); - } - - return TRUE; -} -#endif /* SUPPORT_UNNESTED */ diff --git a/src/attr.h b/src/attr.h index 11958b4..1191053 100644 --- a/src/attr.h +++ b/src/attr.h @@ -39,13 +39,14 @@ * 07 Oct 11, jf@dockes.org: removed unused protocols, added _ATTR_H_INCLUDED_ *--------------------------------------------------------------------*/ -enum { - ATTR_NONE=0, +enum +{ + ATTR_NONE = 0, ATTR_BOLD, ATTR_ITALIC, - ATTR_UNDERLINE, ATTR_DOUBLE_UL, ATTR_WORD_UL, + ATTR_UNDERLINE, ATTR_DOUBLE_UL, ATTR_WORD_UL, - ATTR_THICK_UL, ATTR_WAVE_UL, + ATTR_THICK_UL, ATTR_WAVE_UL, ATTR_DOT_UL, ATTR_DASH_UL, ATTR_DOT_DASH_UL, ATTR_2DOT_DASH_UL, @@ -56,16 +57,16 @@ ATTR_SMALLCAPS, ATTR_SHADOW, - ATTR_OUTLINE, - ATTR_EMBOSS, - ATTR_ENGRAVE, + ATTR_OUTLINE, + ATTR_EMBOSS, + ATTR_ENGRAVE, - ATTR_SUPER, ATTR_SUB, - ATTR_STRIKE, - ATTR_DBL_STRIKE, + ATTR_SUPER, ATTR_SUB, + ATTR_STRIKE, + ATTR_DBL_STRIKE, ATTR_EXPAND, - ATTR_ENCODING, + ATTR_ENCODING, /* ATTR_CONDENSE */ }; @@ -80,7 +81,7 @@ const char *get_from_collection(Collection *c, int nr); void free_collection(Collection *c); -extern void attr_push(int attr, char* param); +extern void attr_push(int attr, char *param); extern void attrstack_push(); extern void attrstack_drop(); @@ -91,13 +92,13 @@ extern int attr_read(); -extern void attr_drop_all (); +extern void attr_drop_all(); extern void attr_pop_all(); extern void attr_pop_dump(); -char * attr_get_param(int attr); +char *attr_get_param(int attr); int safe_printf(int nr, char *string, ...); char *assemble_string(char *string, int nr); diff --git a/src/convert.c b/src/convert.c index c76d7d6..a15b9e3 100644 --- a/src/convert.c +++ b/src/convert.c @@ -48,7 +48,7 @@ * 08 Sep 01, tuorfa@yahoo.com: added use of UnRTF * 11 Sep 01, tuorfa@yahoo.com: added support for JPEG and PNG pictures * 19 Sep 01, tuorfa@yahoo.com: added output personality support - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 23 Sep 01, tuorfa@yahoo.com: fixed translation of \'XX expressions * 08 Oct 03, daved@physiol.usyd.edu.au: more special character code * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith @@ -103,7 +103,7 @@ #ifdef HAVE_STRING_H /* For strcasestr() */ -#define __USE_GNU +#define __USE_GNU #include #endif @@ -120,14 +120,16 @@ #include "convert.h" #include "attr.h" -typedef struct { +typedef struct +{ char *name; - int (*func)(Word*, int, char, int); + int (*func)(Word *, int, char, int); char *debug_print; } HashItem; static HashItem *find_command(const char *cmdpp, int *hasparamp, int *paramp); extern int nopict_mode; +extern int quiet; /* #define BINARY_ATTRS @@ -139,22 +141,23 @@ */ static int coming_pars_that_are_tabular = 0; static int within_table = FALSE; -static int have_printed_row_begin=FALSE; -static int have_printed_cell_begin=FALSE; -static int have_printed_row_end=FALSE; -static int have_printed_cell_end=FALSE; +static int have_printed_row_begin = FALSE; +static int have_printed_cell_begin = FALSE; +static int have_printed_row_end = FALSE; +static int have_printed_cell_end = FALSE; static void check_for_table(); -/* Previously in word_print_core function +/* Previously in word_print_core function */ -static int total_chars_this_line=0; /* for simulating \tab */ +static int total_chars_this_line = 0; /* for simulating \tab */ /* Paragraph alignment (kludge) */ -enum { - ALIGN_LEFT=0, +enum +{ + ALIGN_LEFT = 0, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_JUSTIFY @@ -162,15 +165,16 @@ -/* This value is set by attr_push and attr_pop +/* This value is set by attr_push and attr_pop */ int simulate_smallcaps; int simulate_allcaps; /* Most pictures must be written to files. */ -enum { - PICT_UNKNOWN=0, +enum +{ + PICT_UNKNOWN = 0, PICT_WM, PICT_MAC, PICT_PM, @@ -180,21 +184,21 @@ PICT_PNG, PICT_EMF, }; -static int within_picture=FALSE; +static int within_picture = FALSE; static int within_picture_depth; -static int picture_file_number=1; +static int picture_file_number = 1; static char picture_path[255]; static int picture_width; static int picture_height; -static int picture_bits_per_pixel=1; -static int picture_type=PICT_UNKNOWN; +static int picture_bits_per_pixel = 1; +static int picture_type = PICT_UNKNOWN; static int picture_wmetafile_type; static char *picture_wmetafile_type_str; -static int EndNoteCitations=FALSE; - -static int have_printed_body=FALSE; -static int within_header=TRUE; +static int EndNoteCitations = FALSE; + +static int have_printed_body = FALSE; +static int within_header = TRUE; static const char *hyperlink_base = NULL; @@ -202,9 +206,9 @@ void starting_body(); void starting_text(); -void print_with_special_exprs (const char *s); - -static int banner_printed=FALSE; +void print_with_special_exprs(const char *s); + +static int banner_printed = FALSE; /*======================================================================== @@ -215,15 +219,23 @@ *=======================================================================*/ void -print_banner () { - if (!banner_printed) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf(" Translation from RTF performed by "); +print_banner() +{ + if (!banner_printed) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf(" Translation from RTF performed by "); printf("UnRTF, version "); printf("%s ", PACKAGE_VERSION); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - } - banner_printed=TRUE; + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } + banner_printed = TRUE; } @@ -235,12 +247,20 @@ *=======================================================================*/ void -starting_body () -{ - if (!have_printed_body) { - if (!inline_mode) { - if (safe_printf(0, op->header_end)) fprintf(stderr, TOO_MANY_ARGS, "header_end"); - if (safe_printf(0, op->body_begin)) fprintf(stderr, TOO_MANY_ARGS, "body_begin"); +starting_body() +{ + if (!have_printed_body) + { + if (!inline_mode) + { + if (safe_printf(0, op->header_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "header_end"); + } + if (safe_printf(0, op->body_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "body_begin"); + } } within_header = FALSE; have_printed_body = TRUE; @@ -253,30 +273,31 @@ /*-------------------------------------------------------------------*/ -static char *month_strings[12]= { +static char *month_strings[12] = +{ #ifdef ENGLISH - "January","February","March","April","May","June","July","August", - "September","October","November","December" + "January", "February", "March", "April", "May", "June", "July", "August", + "September", "October", "November", "December" #endif #ifdef FRANCAIS - "Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre", - "Octobre","Novembre","Decembre" + "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", + "Octobre", "Novembre", "Decembre" #endif #ifdef ITALIANO - "Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno", - "Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre" + "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", + "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre" #endif #ifdef ESPANOL /* amaral - 0.19.2 */ - "Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto", - "Septiembre","Octubre","Noviembre","Diciembre" + "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", + "Septiembre", "Octubre", "Noviembre", "Diciembre" #endif #ifdef DEUTSCH /* daved - 0.21.6 */ - "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", - "September", "Oktober", "November", "Dezember" + "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", + "September", "Oktober", "November", "Dezember" #endif #ifdef PORTUGUES /* amaral - 0.19.2 */ - "Janeiro","Fevereiro","Marco","Abril","Maio","Junho","Julho","Agosto", - "Setembro","Outubro","Novembro","Dezembro" + "Janeiro", "Fevereiro", "Marco", "Abril", "Maio", "Junho", "Julho", "Agosto", + "Setembro", "Outubro", "Novembro", "Dezembro" #endif }; @@ -289,47 +310,56 @@ * Returns: None. *=======================================================================*/ -void -word_dump_date (Word *w) -{ - int year=0, month=0, day=0, hour=0, minute=0; +void +word_dump_date(Word *w) +{ + int year = 0, month = 0, day = 0, hour = 0, minute = 0; CHECK_PARAM_NOT_NULL(w); while (w) { - const char *s = word_string (w); + const char *s = word_string(w); if (!s) + { return; - if (*s == '\\') { + } + if (*s == '\\') + { ++s; - if (!strncmp (s, "yr", 2) && isdigit(s[2])) { - year = atoi (&s[2]); + if (!strncmp(s, "yr", 2) && isdigit(s[2])) + { + year = atoi(&s[2]); } - else if (!strncmp (s, "mo", 2) && isdigit(s[2])) + else if (!strncmp(s, "mo", 2) && isdigit(s[2])) { - month= atoi (&s[2]); - if(month > 12) + month = atoi(&s[2]); + if (month > 12) { warning_handler("bogus month"); return; } } - else if (!strncmp (s, "dy", 2) && isdigit(s[2])) { - day= atoi (&s[2]); + else if (!strncmp(s, "dy", 2) && isdigit(s[2])) + { + day = atoi(&s[2]); } - else if (!strncmp (s, "min", 3) && isdigit(s[3])) { - minute= atoi (&s[3]); + else if (!strncmp(s, "min", 3) && isdigit(s[3])) + { + minute = atoi(&s[3]); } - else if (!strncmp (s, "hr", 2) && isdigit(s[2])) { - hour= atoi (&s[2]); + else if (!strncmp(s, "hr", 2) && isdigit(s[2])) + { + hour = atoi(&s[2]); } } - w=w->next; - } - if (year && month > 0 && month <= 12 && day) { - printf("%d %s %d ", day, month_strings[month-1], year); - } - if (hour && minute) { + w = w->next; + } + if (year && month > 0 && month <= 12 && day) + { + printf("%d %s %d ", day, month_strings[month - 1], year); + } + if (hour && minute) + { printf("%02d:%02d ", hour, minute); } } @@ -338,16 +368,17 @@ /*-------------------------------------------------------------------*/ -typedef struct { +typedef struct +{ int num; char *name; - char *encoding; + char *encoding; } FontEntry; static char *default_encoding = "CP1252"; /* current_encoding not NULL to be safe. "" is detected to avoid free() on 1st call */ -static char *current_encoding = ""; +static char *current_encoding = ""; /* Encoding expected by op_translate_buffer. Until we find a way to specify transparent UTF-8 passthrough */ static char *output_encoding = "UTF-32BE"; @@ -355,30 +386,35 @@ static int had_ansicpg; #define MAX_FONTS (8192) static FontEntry font_table[MAX_FONTS]; -static int total_fonts=0; +static int total_fonts = 0; static void flush_iconv_input(); static void accumulate_iconv_input(int ch); -static void +static void set_current_encoding(char *encoding) { - if (current_encoding && *current_encoding) - my_free(current_encoding); - current_encoding = my_strdup(encoding); -} - -static void + if (current_encoding && *current_encoding) + { + my_free(current_encoding); + } + current_encoding = my_strdup(encoding); +} + +static void maybeopeniconv() { - if (!my_iconv_is_valid(desc)) { - /* This may happen if output begins without a font command */ - char *encoding = attr_get_param(ATTR_ENCODING); - if (!encoding || !*encoding) - encoding = default_encoding; - desc = my_iconv_open(output_encoding, encoding); - set_current_encoding(encoding); - } + if (!my_iconv_is_valid(desc)) + { + /* This may happen if output begins without a font command */ + char *encoding = attr_get_param(ATTR_ENCODING); + if (!encoding || !*encoding) + { + encoding = default_encoding; + } + desc = my_iconv_open(output_encoding, encoding); + set_current_encoding(encoding); + } } @@ -389,22 +425,28 @@ * Returns: Font name. *=======================================================================*/ FontEntry * -lookup_font (int num) -{ - int i; - if (total_fonts) - for(i=0;iname; +lookup_font(int num) +{ + int i; + if (total_fonts) + for (i = 0; i < total_fonts; i++) + { + if (font_table[i].num == num) + { + return &font_table[i]; + } + } + return NULL; +} +char * +lookup_fontname(int num) +{ + FontEntry *e = lookup_font(num); + if (e == NULL) + { + return NULL; + } + return e->name; } // Extract name and parameter from command. RTF spec says name is max @@ -413,121 +455,357 @@ // Returns 0 for error, 1 if ok no parm, 0 else static int controlToNameParm(const char *s, char *name, int maxlen, int *parm) { - const char *cp = s; - int len = 0; - - if (s == 0) - return 0; - while (isalpha(*cp) && len < maxlen) { - *name++ = *cp++; - len++; - } - if (len == maxlen) - return 0; - *name = 0; - if (!*cp) - return 1; - if (!(*cp == '-') && !isdigit(*cp)) - return 0; - *parm=atoi(cp); - return 2; + const char *cp = s; + int len = 0; + + if (s == 0) + { + return 0; + } + while (isalpha(*cp) && len < maxlen) + { + *name++ = *cp++; + len++; + } + if (len == maxlen) + { + return 0; + } + *name = 0; + if (!*cp) + { + return 1; + } + if (!(*cp == '-') && !isdigit(*cp)) + { + return 0; + } + *parm = atoi(cp); + return 2; } // translate \fcharset parameter value to code page. See MS RTF doc static const int fcharsetparmtocp(int parm) { - switch (parm) { - case 0: return 1252; - case 1: return 0; - case 2: return 42; - case 77: return 10000; - case 78: return 10001; - case 79: return 10003; - case 80: return 10008; - case 81: return 10002; - case 83: return 10005; - case 84: return 10004; - case 85: return 10006; - case 86: return 10081; - case 87: return 10021; - case 88: return 10029; - case 89: return 10007; - case 128: return 932; - case 129: return 949; - case 130: return 1361; - case 134: return 936; - case 136: return 950; - case 161: return 1253; - case 162: return 1254; - case 163: return 1258; - case 177: return 1255; - case 178: return 1256; - case 186: return 1257; - case 204: return 1251; - case 222: return 874; - case 238: return 1250; - case 254: return 437; - default: return 1252; - } + switch (parm) + { + case 0: + return 1252; + case 1: + return 0; + case 2: + return 42; + case 77: + return 10000; + case 78: + return 10001; + case 79: + return 10003; + case 80: + return 10008; + case 81: + return 10002; + case 83: + return 10005; + case 84: + return 10004; + case 85: + return 10006; + case 86: + return 10081; + case 87: + return 10021; + case 88: + return 10029; + case 89: + return 10007; + case 128: + return 932; + case 129: + return 949; + case 130: + return 1361; + case 134: + return 936; + case 136: + return 950; + case 161: + return 1253; + case 162: + return 1254; + case 163: + return 1258; + case 177: + return 1255; + case 178: + return 1256; + case 186: + return 1257; + case 204: + return 1251; + case 222: + return 874; + case 238: + return 1250; + case 254: + return 437; + default: + return 1252; + } } // Translate code page to encoding name hopefully suitable as iconv input -static char *cptoencoding(parm) -{ - // Note that CP0 is supposed to mean current system default, which does - // not make any sense as a stored value, we don't handle it. - - // It's quite possible that some of the CPxx values had better be - // replaced in some case by an equivalent better understood by - // iconv. Need testing - switch (parm) { - case 42: return "SYMBOL"; - case 437: return "CP437"; /* United States IBM */ - case 708: return "CP708"; /* Arabic (ASMO 708) */ - case 709: return "CP709"; /* Arabic (ASMO 449+, BCON V4) */ - case 710: return "CP710"; /* Arabic (transparent Arabic) */ - case 711: return "CP711"; /* Arabic (Nafitha Enhanced) */ - case 720: return "CP720"; /* Arabic (transparent ASMO) */ - case 819: return "CP819"; /* Windows 3.1 (United States and Western Europe) */ - case 850: return "CP850"; /* IBM multilingual */ - case 852: return "CP852"; /* Eastern European */ - case 860: return "CP860"; /* Portuguese */ - case 862: return "CP862"; /* Hebrew */ - case 863: return "CP863"; /* French Canadian */ - case 864: return "CP864"; /* Arabic */ - case 865: return "CP865"; /* Norwegian */ - case 866: return "CP866"; /* Soviet Union */ - case 874: return "CP874"; /* Thai */ - case 932: return "CP932"; /* Japanese */ - case 936: return "CP936"; /* Simplified Chinese */ - case 949: return "CP949"; /* Korean */ - case 950: return "CP950"; /* Traditional Chinese */ - case 1250: return "CP1250"; /* Eastern European */ - case 1251: return "CP1251"; /* Cyrillic */ - case 1252: return "CP1252"; /* Western European */ - case 1253: return "CP1253"; /* Greek */ - case 1254: return "CP1254"; /* Turkish */ - case 1255: return "CP1255"; /* Hebrew */ - case 1256: return "CP1256"; /* Arabic */ - case 1257: return "CP1257"; /* Baltic */ - case 1258: return "CP1258"; /* Vietnamese */ - case 1361: return "CP1361"; /* Johab */ - case 10000: return "MAC"; /* MAC Roman */ - case 10001: return "CP10001"; /* MAC Japan ?? Iconv does not know this*/ - case 10004: return "MACARABIC"; /* MAC Arabic */ - case 10005: return "MACHEBREW"; /* MAC Hebrew */ - case 10006: return "MACGREEK"; /* MAC Greek */ - case 10007: return "MACCYRILLIC"; /* MAC Cyrillic */ - case 10029: return "MACCENTRALEUROPE"; /* MAC Latin2 */ - case 10081: return "MACTURKISH"; /* MAC Turkish */ - case 57002: return "CP57002"; /* Devanagari */ - case 57003: return "CP57003"; /* Bengali */ - case 57004: return "CP57004"; /* Tamil */ - case 57005: return "CP57005"; /* Telugu */ - case 57006: return "CP57006"; /* Assamese */ - case 57007: return "CP57007"; /* Oriya */ - default: return "CP1252"; - } +static char *cptoencoding(int parm) +{ + // Note that CP0 is supposed to mean current system default, which does + // not make any sense as a stored value, we don't handle it. + + // It's quite possible that some of the CPxx values had better be + // replaced in some case by an equivalent better understood by + // iconv. Need testing + switch (parm) + { + case 42: + return "SYMBOL"; + case 437: + return "CP437"; /* United States IBM */ + case 708: + return "CP708"; /* Arabic (ASMO 708) */ + case 709: + return "CP709"; /* Arabic (ASMO 449+, BCON V4) */ + case 710: + return "CP710"; /* Arabic (transparent Arabic) */ + case 711: + return "CP711"; /* Arabic (Nafitha Enhanced) */ + case 720: + return "CP720"; /* Arabic (transparent ASMO) */ + case 819: + return "CP819"; /* Windows 3.1 (United States and Western Europe) */ + case 850: + return "CP850"; /* IBM multilingual */ + case 852: + return "CP852"; /* Eastern European */ + case 860: + return "CP860"; /* Portuguese */ + case 862: + return "CP862"; /* Hebrew */ + case 863: + return "CP863"; /* French Canadian */ + case 864: + return "CP864"; /* Arabic */ + case 865: + return "CP865"; /* Norwegian */ + case 866: + return "CP866"; /* Soviet Union */ + case 874: + return "CP874"; /* Thai */ + case 932: + return "CP932"; /* Japanese */ + case 936: + return "CP936"; /* Simplified Chinese */ + case 949: + return "CP949"; /* Korean */ + case 950: + return "CP950"; /* Traditional Chinese */ + case 1250: + return "CP1250"; /* Eastern European */ + case 1251: + return "CP1251"; /* Cyrillic */ + case 1252: + return "CP1252"; /* Western European */ + case 1253: + return "CP1253"; /* Greek */ + case 1254: + return "CP1254"; /* Turkish */ + case 1255: + return "CP1255"; /* Hebrew */ + case 1256: + return "CP1256"; /* Arabic */ + case 1257: + return "CP1257"; /* Baltic */ + case 1258: + return "CP1258"; /* Vietnamese */ + case 1361: + return "CP1361"; /* Johab */ + case 10000: + return "MAC"; /* MAC Roman */ + case 10001: + return "CP10001"; /* MAC Japan ?? Iconv does not know this*/ + case 10004: + return "MACARABIC"; /* MAC Arabic */ + case 10005: + return "MACHEBREW"; /* MAC Hebrew */ + case 10006: + return "MACGREEK"; /* MAC Greek */ + case 10007: + return "MACCYRILLIC"; /* MAC Cyrillic */ + case 10029: + return "MACCENTRALEUROPE"; /* MAC Latin2 */ + case 10081: + return "MACTURKISH"; /* MAC Turkish */ + case 57002: + return "CP57002"; /* Devanagari */ + case 57003: + return "CP57003"; /* Bengali */ + case 57004: + return "CP57004"; /* Tamil */ + case 57005: + return "CP57005"; /* Telugu */ + case 57006: + return "CP57006"; /* Assamese */ + case 57007: + return "CP57007"; /* Oriya */ + default: + return "CP1252"; + } +} + +/*======================================================================== + * Name: read_font_decl + * Purpose: Reads exactly one font declaration from the font table: e.g. + * \f\froman\fcharset204\fprq2 Times New Roman Cyr; + * We are only interested in the font number, encoding and name, and skip the + * other commands. The font decl can be alone in a group, or part of + * a semicolon-separated list, in which case we take care to stop input just + * after the semi-colon + * Args: Group containing one or several font decls + * Returns: None. + *=======================================================================*/ + +Word *read_font_decl(Word *w) +{ + int num; + char name[BUFSIZ]; + const char *tmp; + int cpgcp = -1; + int fcharsetcp = -1; + int l; + int i; + + name[0] = 0; + + /* Read font number ('\fxx'). There can be an optional + entry (e.g. '\flomajor') before the font number */ + for (i = 0; i < 2; i++) + { + tmp = word_string(w); + if (!tmp || strlen(tmp) < 3 || strncmp("\\f", tmp, 2)) + { + return 0; + } + if (isdigit(tmp[2])) + { + num = atoi(&tmp[2]); + break; + } else if (i == 1) { + return 0; + } + w = w->next; + } + + /* Read other font entry elements, e.g. encoding, and name. The + loop is weird because it would allow interleaving commands and + name words. We should read command words until non command, the + rest until the semi-colon being the font name. Kept this way + for minimal perturbation of existing code. We stop at the + semi-colon in all cases, which is not necessary if we are + reading from a single-entry group which seems to be now the + standard way, but we also support groups with multiple + semicolon-separated entries */ + while (w) + { + int needbreak = 0; + tmp = word_string(w); + + if (tmp && tmp[0] != '\\') + { + /* Read font name word. Note: the parser breaks the input + at every space char. */ + if (strchr(tmp, ';')) + needbreak = 1; + if (strlen(tmp) + strlen(name) > BUFSIZ - 1) + { + fprintf(stderr, "Invalid font table entry\n"); + name[0] = 0; + } + else + { + strncat(name, tmp, sizeof(name) - strlen(name) - 1); + } + } + else if (tmp) + { + char nm[MAX_CONTROL_LEN + 1]; + int parm; + int ret = controlToNameParm(tmp + 1, nm, MAX_CONTROL_LEN, &parm); + if (ret == 2) + { + if (!strcmp(nm, "fcharset")) + { + fcharsetcp = fcharsetparmtocp(parm); + } + else if (!strcmp(nm, "cpg")) + { + cpgcp = parm; + } + /* not interested by stuff like \froman */ + } + } + w = w->next; + if (needbreak) + break; + } + + /* We probably read the semi-colon, remove it from the font name */ + { + char *t = strchr(name, ';'); + if (t) + *t = 0; + } + + font_table[total_fonts].num = num; + font_table[total_fonts].name = my_strdup(name); + + /* Explicit cpg parameter has priority on fcharset one */ + if (cpgcp == -1) + { + cpgcp = fcharsetcp; + } + + if (cpgcp != -1) + { + font_table[total_fonts].encoding = cptoencoding(cpgcp); + } + else + { + /* If there is "symbol" in the font name, use + * symbol encoding, else no local encoding */ + if (strcasestr(name, "symbol")) + { + font_table[total_fonts].encoding = "SYMBOL"; + } + else + { + font_table[total_fonts].encoding = 0; + } + } + + /* Need to have this outside last block as it must be detected + even if cpgcp is set */ + if (strcasecmp(name, "symbol") == 0) + { + font_table[total_fonts].encoding = "SYMBOL"; + } + if (safe_printf(0, assemble_string(op->fonttable_fontnr, num))) + { + fprintf(stderr, TOO_MANY_ARGS, "fonttable_fontnr"); + } + if (safe_printf(1, op->fonttable_fontname, name)) + { + fprintf(stderr, TOO_MANY_ARGS, "fonttable_fontname"); + } + total_fonts++; + return w; } /*======================================================================== @@ -538,117 +816,90 @@ *=======================================================================*/ void -process_font_table (Word *w) -{ - Word *w2; - CHECK_PARAM_NOT_NULL(w); - - if (safe_printf(0, op->fonttable_begin)) fprintf(stderr, TOO_MANY_ARGS, "fonttable_begin"); - - while (w) { - int num; - char name[BUFSIZ]; - const char *tmp; - - if ((w2 = w->child)) - { - tmp = word_string(w2); - if(!tmp) - return; - if (!strncmp("\\f", tmp, 2)) { - num = atoi(&tmp[2]); - name[0] = 0; - int cpgcp = -1; - int fcharsetcp = -1; - w2 = w2->next; - while (w2) { - tmp = word_string (w2); - if (tmp && tmp[0] != '\\') { - if (strlen(tmp) + strlen(name) > BUFSIZ - 1) { - fprintf(stderr, "Invalid font table entry\n"); - name[0] = 0; - } - else - strncat(name,tmp,sizeof(name) - strlen(name) - 1); - } else if (tmp) { - char nm[MAX_CONTROL_LEN+1]; - int parm; - int ret = - controlToNameParm(tmp+1,nm, MAX_CONTROL_LEN, &parm); - if (ret == 2) { - if (!strcmp(nm, "fcharset")) { - fcharsetcp = fcharsetparmtocp(parm); - } else if (!strcmp(nm, "cpg")) { - cpgcp = parm; - } - } - } - w2 = w2->next; - } - - /* Chop the gall-derned semicolon. */ - { char *t; - if ((t = strchr(name, ';'))) - *t = 0; - } - - font_table[total_fonts].num=num; - font_table[total_fonts].name=my_strdup(name); - // Explicit cpg parameter has priority on fcharset one - if (cpgcp == -1) - cpgcp = fcharsetcp; - if (cpgcp != -1) - font_table[total_fonts].encoding = cptoencoding(cpgcp); - else { - /* If there is "symbol" in the font name, use - * symbol encoding, else no local encoding */ - if (strcasestr(name, "symbol")) - font_table[total_fonts].encoding = "SYMBOL"; - else - font_table[total_fonts].encoding = 0; - } - // need to have this outside last block as it must be detected - // even if cpgcp is set - if (strcasecmp(name, "symbol") == 0) - font_table[total_fonts].encoding = "SYMBOL"; - if (safe_printf(0, assemble_string(op->fonttable_fontnr, num))) fprintf(stderr, TOO_MANY_ARGS, "fonttable_fontnr"); - if (safe_printf(1, op->fonttable_fontname, name)) fprintf(stderr, TOO_MANY_ARGS, "fonttable_fontname"); - total_fonts++; - } - } - w=w->next; - } - - if (safe_printf(0, op->fonttable_end)) fprintf(stderr, TOO_MANY_ARGS, "fonttable_end"); - - /* - * If the default font has an encoding, set it as default - * encoding. The default font number was set by the \deff command - * in the header (or not in which case it is o). Don't do it if - * we had an explicit ansicpg command (no logic in this, just works). - */ - if (total_fonts > 0 && !had_ansicpg) { - FontEntry *e = lookup_font(default_font_number); - if (e && e->encoding && *e->encoding) - default_encoding = e->encoding; - } - - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("font table contains %d fonts total",total_fonts); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - - if (debug_mode) { - int i; - - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("font table dump: \n"); - for (i=0; icomment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - } +process_font_table(Word *w) +{ + CHECK_PARAM_NOT_NULL(w); + + if (safe_printf(0, op->fonttable_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fonttable_begin"); + } + + /* We may be reading from a group with multiple entries separated + by semi-colons, or multiple subgroups, each with one + entry. Handle both */ + while (w) + { + if (w->child) + { + read_font_decl(w->child); + w = w->next; + } + else if (word_string(w)) + { + w = read_font_decl(w); + } + else + { + /* Not sure that we should not bail out here. Every + element should have string or child */ + w = w->next; + } + } + + if (safe_printf(0, op->fonttable_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fonttable_end"); + } + + /* + * If the default font has an encoding, set it as default + * encoding. The default font number was set by the \deff command + * in the header (or not in which case it is o). Don't do it if + * we had an explicit ansicpg command (no logic in this, just works). + */ + if (total_fonts > 0 && !had_ansicpg) + { + FontEntry *e = lookup_font(default_font_number); + if (e && e->encoding && *e->encoding) + { + default_encoding = e->encoding; + } + } + + if (!quiet) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("font table contains %d fonts total", total_fonts); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } + + if (debug_mode) + { + int i; + + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("font table dump: \n"); + for (i = 0; i < total_fonts; i++) + { + printf(" font %d = %s encoding = %s\n", font_table[i].num, + font_table[i].name, font_table[i].encoding); + } + + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } } @@ -660,23 +911,32 @@ *=======================================================================*/ void -process_index_entry (Word *w) +process_index_entry(Word *w) { Word *w2; CHECK_PARAM_NOT_NULL(w); - while(w) { - if ((w2=w->child)) { - const char *str = word_string (w2); - - if (debug_mode && str) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("index entry word: %s ", str); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + while (w) + { + if ((w2 = w->child)) + { + const char *str = word_string(w2); + + if (debug_mode && str) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("index entry word: %s ", str); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } } - w=w->next; + w = w->next; } } @@ -689,26 +949,35 @@ *=======================================================================*/ void -process_toc_entry (Word *w, int include_page_num) +process_toc_entry(Word *w, int include_page_num) { Word *w2; CHECK_PARAM_NOT_NULL(w); - while(w) { - if ((w2=w->child)) { - const char *str = word_string (w2); - - if (debug_mode && str) { - - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("toc %s entry word: %s ", - include_page_num ? "page#":"no page#", - str); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + while (w) + { + if ((w2 = w->child)) + { + const char *str = word_string(w2); + + if (debug_mode && str) + { + + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("toc %s entry word: %s ", + include_page_num ? "page#" : "no page#", + str); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } } - w=w->next; + w = w->next; } } @@ -721,148 +990,268 @@ *=======================================================================*/ void -process_info_group (Word *w) +process_info_group(Word *w) { Word *child; - maybeopeniconv(); - /* amaral - 0.19.2 */ - /* CHECK_PARAM_NOT_NULL(w); */ - if (!w) printf("AUTHOR'S COMMENT: \\info command is null!\n"); - - while(w) + if (!w) + { + /* Happens. Means empty info group, like {\info} */ + return; + } + + maybeopeniconv(); + + while (w) { child = w->child; - if (child) { + if (child) + { Word *w2; const char *s; s = word_string(child); - if(!s) + if (!s) + { return; - - if (!inline_mode) { - if (!strcmp("\\title", s)) { - - if (safe_printf(0, op->document_title_begin)) fprintf(stderr, TOO_MANY_ARGS, "document_title_begin"); - w2=child->next; - while (w2) { + } + + if (!inline_mode) + { + if (!strcmp("\\title", s)) + { + + if (safe_printf(0, op->document_title_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_title_begin"); + } + w2 = child->next; + while (w2) + { const char *s2 = word_string(w2); - if (s2 && s2[0] != '\\') + if (s2 && s2[0] != '\\') { - print_with_special_exprs (s2); + print_with_special_exprs(s2); } else if (s2 && s2[1] == '\'' && s2[2] && s2[3]) { - int ch = h2toi (&s2[2]); + int ch = h2toi(&s2[2]); accumulate_iconv_input(ch); } w2 = w2->next; } - flush_iconv_input(); - if (safe_printf(0, op->document_title_end)) fprintf(stderr, TOO_MANY_ARGS, "document_title_end"); + flush_iconv_input(); + if (safe_printf(0, op->document_title_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_title_end"); + } } - else if (!strcmp("\\keywords", s)) { - if (safe_printf(0, op->document_keywords_begin)) fprintf(stderr, TOO_MANY_ARGS, "document_keywords_begin"); - w2=child->next; - while (w2) { + else if (!strcmp("\\keywords", s)) + { + if (safe_printf(0, op->document_keywords_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_keywords_begin"); + } + w2 = child->next; + while (w2) + { const char *s2 = word_string(w2); - if (s2 && s2[0] != '\\') + if (s2 && s2[0] != '\\') + { printf("%s,", s2); + } w2 = w2->next; } - if (safe_printf(0, op->document_keywords_end)) fprintf(stderr, TOO_MANY_ARGS, "document_keywords_end"); + if (safe_printf(0, op->document_keywords_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_keywords_end"); + } } - else if (!strcmp("\\author", s)) { - if (safe_printf(0, op->document_author_begin)) fprintf(stderr, TOO_MANY_ARGS, "document_author_begin"); - w2=child->next; - while (w2) { + else if (!strcmp("\\author", s)) + { + if (safe_printf(0, op->document_author_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_author_begin"); + } + w2 = child->next; + while (w2) + { const char *s2 = word_string(w2); - if (s2 && s2[0] != '\\') + if (s2 && s2[0] != '\\') + { printf("%s", s2); + } w2 = w2->next; } - if (safe_printf(0, op->document_author_end)) fprintf(stderr, TOO_MANY_ARGS, "document_author_end"); + if (safe_printf(0, op->document_author_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_author_end"); + } } - else if (!strcmp("\\comment", s)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + else if (!strcmp("\\comment", s)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("comments: "); - w2=child->next; - while (w2) { + w2 = child->next; + while (w2) + { const char *s2 = word_string(w2); - if (s2 && s2[0] != '\\') + if (s2 && s2[0] != '\\') + { printf("%s", s2); + } w2 = w2->next; } - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strncmp("\\nofpages", s, 9)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("total pages: %s",&s[9]); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + else if (!strncmp("\\nofpages", s, 9)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("total pages: %s", &s[9]); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strncmp("\\nofwords", s, 9)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("total words: %s",&s[9]); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + else if (!strncmp("\\nofwords", s, 9)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("total words: %s", &s[9]); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strncmp("\\nofchars", s, 9) && isdigit(s[9])) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("total chars: %s",&s[9]); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + else if (!strncmp("\\nofchars", s, 9) && isdigit(s[9])) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("total chars: %s", &s[9]); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strcmp("\\creatim", s)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + else if (!strcmp("\\creatim", s)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("creation date: "); - if (child->next) word_dump_date (child->next); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (child->next) + { + word_dump_date(child->next); + } + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strcmp("\\printim", s)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + else if (!strcmp("\\printim", s)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("last printed: "); - if (child->next) word_dump_date (child->next); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (child->next) + { + word_dump_date(child->next); + } + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strcmp("\\buptim", s)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + else if (!strcmp("\\buptim", s)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("last backup: "); - if (child->next) word_dump_date (child->next); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (child->next) + { + word_dump_date(child->next); + } + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } - else if (!strcmp("\\revtim", s)) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + else if (!strcmp("\\revtim", s)) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("revision date: "); - if (child->next) word_dump_date (child->next); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (child->next) + { + word_dump_date(child->next); + } + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } } /* Irregardless of whether we're in inline mode, * we want to process the following. */ - if (!strcmp("\\hlinkbase", s)) { + if (!strcmp("\\hlinkbase", s)) + { const char *linkstr = NULL; - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("hyperlink base: "); - if (child->next) { + if (child->next) + { Word *nextword = child->next; - if (nextword) - linkstr=word_string (nextword); + if (nextword) + { + linkstr = word_string(nextword); + } } if (linkstr) + { printf("%s", linkstr); + } else + { printf("(none)"); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } /* Store the pointer, it will remain good. */ - hyperlink_base = linkstr; + hyperlink_base = linkstr; } - } + } w = w->next; } } @@ -871,13 +1260,14 @@ /* RTF color table colors are RGB */ -typedef struct { - unsigned char r,g,b; +typedef struct +{ + unsigned char r, g, b; } Color; #define MAX_COLORS (1024) static Color color_table[MAX_COLORS]; -static int total_colors=0; +static int total_colors = 0; /*======================================================================== @@ -888,61 +1278,90 @@ *=======================================================================*/ void -process_color_table (Word *w) -{ - int r,g,b; +process_color_table(Word *w) +{ + int r, g, b; CHECK_PARAM_NOT_NULL(w); /* Sometimes, RTF color tables begin with a semicolon, - * i.e. an empty color entry. This seems to indicate that color 0 + * i.e. an empty color entry. This seems to indicate that color 0 * will not be used, so here I set it to black. */ - r=g=b=0; - - while(w) - { - const char *s = word_string (w); - if(s == 0 || total_colors >= MAX_COLORS) + r = g = b = 0; + + while (w) + { + const char *s = word_string(w); + if (s == 0 || total_colors >= MAX_COLORS) + { break; - - if (!strncmp("\\red",s,4)) { + } + + if (!strncmp("\\red", s, 4)) + { r = atoi(&s[4]); - while(r>255) r>>=8; - } - else if (!strncmp("\\green",s,6)) { + while (r > 255) + { + r >>= 8; + } + } + else if (!strncmp("\\green", s, 6)) + { g = atoi(&s[6]); - while(g>255) g>>=8; - } - else if (!strncmp("\\blue",s,5)) { + while (g > 255) + { + g >>= 8; + } + } + else if (!strncmp("\\blue", s, 5)) + { b = atoi(&s[5]); - while(b>255) b>>=8; + while (b > 255) + { + b >>= 8; + } } else - /* If we find the semicolon which denotes the end of - * a color entry then store the color, even if we don't - * have all of it. - */ - if (!strcmp (";", s)) { - color_table[total_colors].r = r; - color_table[total_colors].g = g; - color_table[total_colors++].b = b; - if (debug_mode) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("storing color entry %d: %02x%02x%02x", - total_colors-1, r,g,b); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + /* If we find the semicolon which denotes the end of + * a color entry then store the color, even if we don't + * have all of it. + */ + if (!strcmp(";", s)) + { + color_table[total_colors].r = r; + color_table[total_colors].g = g; + color_table[total_colors++].b = b; + if (debug_mode) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("storing color entry %d: %02x%02x%02x", + total_colors - 1, r, g, b); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } + r = g = b = 0; } - r=g=b=0; - } - - w=w->next; - } - - if (debug_mode) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("color table had %d entries", total_colors); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + + w = w->next; + } + + if (debug_mode) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("color table had %d entries", total_colors); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } } @@ -953,22 +1372,22 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_cf (Word *w, int align, char has_param, int num) +static int +cmd_cf(Word *w, int align, char has_param, int num) { char str[40]; - if (!has_param || num<0 || num>=total_colors) - { - warning_handler ("font color change attempted is invalid"); + if (!has_param || num < 0 || num >= total_colors) + { + warning_handler("font color change attempted is invalid"); } else { - sprintf(str,"#%02x%02x%02x", - color_table[num].r, - color_table[num].g, - color_table[num].b); - attr_push(ATTR_FOREGROUND,str); + snprintf(str, 40, "#%02x%02x%02x", + color_table[num].r, + color_table[num].g, + color_table[num].b); + attr_push(ATTR_FOREGROUND, str); } return FALSE; } @@ -982,22 +1401,22 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_cb (Word *w, int align, char has_param, int num) +static int +cmd_cb(Word *w, int align, char has_param, int num) { char str[40]; - if (!has_param || num<0 || num>=total_colors) - { - warning_handler ("font color change attempted is invalid"); + if (!has_param || num < 0 || num >= total_colors) + { + warning_handler("font color change attempted is invalid"); } else { - sprintf(str,"#%02x%02x%02x", - color_table[num].r, - color_table[num].g, - color_table[num].b); - attr_push(ATTR_BACKGROUND,str); + snprintf(str, 40, "#%02x%02x%02x", + color_table[num].r, + color_table[num].g, + color_table[num].b); + attr_push(ATTR_BACKGROUND, str); } return FALSE; } @@ -1009,17 +1428,21 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_fs (Word *w, int align, char has_param, int points) { +static int +cmd_fs(Word *w, int align, char has_param, int points) +{ char str[20]; - if (!has_param) return FALSE; + if (!has_param) + { + return FALSE; + } /* Note, fs20 means 10pt */ points /= 2; - sprintf(str,"%d",points); - attr_push(ATTR_FONTSIZE,str); + snprintf(str, 20, "%d", points); + attr_push(ATTR_FONTSIZE, str); return FALSE; } @@ -1034,109 +1457,139 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_field (Word *w, int align, char has_param, int num) { +static int +cmd_field(Word *w, int align, char has_param, int num) +{ Word *child; CHECK_PARAM_NOT_NULL(w); - maybeopeniconv(); - while(w) { + maybeopeniconv(); + while (w) + { child = w->child; - if (child) { + if (child) + { Word *w2; const char *s; s = word_string(child); if (!s) + { return TRUE; + } #if 1 /* daved experimenting with fldrslt */ - if(!strcmp("\\fldrslt", s)) + if (!strcmp("\\fldrslt", s)) + { return FALSE; + } #endif if (!strcmp("\\*", s)) { - w2=child->next; - while (w2) - { - const char *s2 = word_string(w2); - if (s2 && !strcmp("\\fldinst", s2)) + w2 = child->next; + while (w2) { - Word *w3; - const char *s; - const char *s4; - Word *w4; - w3=w2->next; - s = word_string(w3); - if (s && !strcmp(s, "SYMBOL") ) - { - w4=w3->next; - while(w4 && word_string(w4) && !strcmp(word_string(w4), " ")) - w4 = w4->next; - s4 = word_string(w4); - if (s4) - { - int char_num; - const char *string; - char_num = atoi(s4); - - string = op_translate_char(op, - FONT_SYMBOL, char_num); - if (string != NULL) - printf("%s", string); - else - fprintf(stderr, "unrtf: Error in translation SYMBOL character %d\n", char_num); - } - } - while (w3 && !w3->child) { - w3=w3->next; - } - if (w3) w3=w3->child; - while (w3) - { - const char *s3=word_string(w3); - if (s3 && !strcmp("EN.CITE", s3)) - { - EndNoteCitations = TRUE; - } - /* - ** If we have a file with EndNote - ** citations, we don't want to - ** insert "hyperlink", we want the - ** citation text, so we return - ** FALSE. (We could extract "" - ** for a link, but probably not - ** wanted.) - */ - - if (s3 && !strcmp("HYPERLINK",s3) && !EndNoteCitations) { - Word *w4; - const char *s4; - w4=w3->next; - while (w4 && word_string(w4) && !strcmp(" ", word_string(w4))) - w4=w4->next; - if (w4) { - s4=word_string(w4); - if (safe_printf(0, op->hyperlink_begin)) fprintf(stderr, TOO_MANY_ARGS, "hyperlink_begin"); - printf("%s", s4); - if (safe_printf(0, op->hyperlink_end)) fprintf(stderr, TOO_MANY_ARGS, "hyperlink_end"); - return TRUE; - } - - } - else - return FALSE; - w3=w3->next; - } + const char *s2 = word_string(w2); + if (s2 && !strcmp("\\fldinst", s2)) + { + Word *w3; + const char *s; + const char *s4; + Word *w4; + w3 = w2->next; + s = word_string(w3); + if (s && !strcmp(s, "SYMBOL")) + { + w4 = w3->next; + while (w4 && word_string(w4) && !strcmp(word_string(w4), " ")) + { + w4 = w4->next; + } + s4 = word_string(w4); + if (s4) + { + int char_num; + const char *string; + char_num = atoi(s4); + + string = op_translate_char(op, + FONT_SYMBOL, char_num); + if (string != NULL) + { + printf("%s", string); + my_free(string); + } + else + { + fprintf(stderr, "unrtf: Error in translation SYMBOL character %d\n", char_num); + } + } + } + while (w3 && !w3->child) + { + w3 = w3->next; + } + if (w3) + { + w3 = w3->child; + } + while (w3) + { + const char *s3 = word_string(w3); + if (s3 && !strcmp("EN.CITE", s3)) + { + EndNoteCitations = TRUE; + } + /* + ** If we have a file with EndNote + ** citations, we don't want to + ** insert "hyperlink", we want the + ** citation text, so we return + ** FALSE. (We could extract "" + ** for a link, but probably not + ** wanted.) + */ + + if (s3 && !strcmp("HYPERLINK", s3) && !EndNoteCitations) + { + Word *w4; + const char *s4; + w4 = w3->next; + while (w4 && word_string(w4) && !strcmp(" ", word_string(w4))) + { + w4 = w4->next; + } + if (w4) + { + s4 = word_string(w4); + if (safe_printf(0, op->hyperlink_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "hyperlink_begin"); + } + printf("%s", s4); + if (safe_printf(0, op->hyperlink_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "hyperlink_end"); + } + return TRUE; + } + + } + else + { + return FALSE; + } + w3 = w3->next; + } + } + w2 = w2->next; } - w2 = w2->next; - } - + } } - w=w->next; + w = w->next; } return TRUE; } @@ -1147,43 +1600,57 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_f (Word *w, int align, char has_param, int num) -{ - char *name; - - /* no param exit early XX */ - if (!has_param) - return FALSE; - FontEntry *e = lookup_font(num); - name = e ? e->name : NULL; - if (!e || !name) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("invalid font number %d",num); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - } else { - if (op->fonttable_begin != NULL) - { - // TOBEDONE: WHAT'S THIS ??? - name = my_malloc(12); - sprintf(name, "%d", num); - } - - /* we are going to output entities, so should not output font */ - if(strstr(name,"Symbol") == NULL) - attr_push(ATTR_FONTFACE,name); - - desc = my_iconv_close(desc); - char *encoding = default_encoding; - if (e->encoding && *e->encoding) { - encoding = e->encoding; - attr_push(ATTR_ENCODING, encoding); - } - desc = my_iconv_open(output_encoding, encoding); - set_current_encoding(encoding); - } - - return FALSE; +static int +cmd_f(Word *w, int align, char has_param, int num) +{ + char *name; + + /* no param exit early XX */ + if (!has_param) + { + return FALSE; + } + FontEntry *e = lookup_font(num); + name = e ? e->name : NULL; + if (!e || !name) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("invalid font number %d", num); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } + else + { + if (op->fonttable_begin != NULL) + { + // TOBEDONE: WHAT'S THIS ??? + name = my_malloc(12); + snprintf(name, 12, "%d", num); + } + + /* we are going to output entities, so should not output font */ + if (strstr(name, "Symbol") == NULL) + { + attr_push(ATTR_FONTFACE, name); + } + + desc = my_iconv_close(desc); + char *encoding = default_encoding; + if (e->encoding && *e->encoding) + { + encoding = e->encoding; + attr_push(ATTR_ENCODING, encoding); + } + desc = my_iconv_open(output_encoding, encoding); + set_current_encoding(encoding); + } + + return FALSE; } /*======================================================================== @@ -1192,12 +1659,14 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_deff (Word *w, int align, char has_param, int num) -{ - if (has_param) - default_font_number = num; - return FALSE; +static int +cmd_deff(Word *w, int align, char has_param, int num) +{ + if (has_param) + { + default_font_number = num; + } + return FALSE; } /*======================================================================== @@ -1207,22 +1676,22 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_highlight (Word *w, int align, char has_param, int num) +static int +cmd_highlight(Word *w, int align, char has_param, int num) { char str[40]; - if (!has_param || num<0 || num>=total_colors) - { - warning_handler ("font background color change attempted is invalid"); + if (!has_param || num < 0 || num >= total_colors) + { + warning_handler("font background color change attempted is invalid"); } else { - sprintf(str,"#%02x%02x%02x", - color_table[num].r, - color_table[num].g, - color_table[num].b); - attr_push(ATTR_BACKGROUND,str); + snprintf(str, 40, "#%02x%02x%02x", + color_table[num].r, + color_table[num].g, + color_table[num].b); + attr_push(ATTR_BACKGROUND, str); } return FALSE; } @@ -1236,19 +1705,23 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_tab (Word *w, int align, char has_param, int param) +static int +cmd_tab(Word *w, int align, char has_param, int param) { /* Tab presents a genuine problem - * since some output formats don't have - * an equivalent. As a kludge fix, I shall + * since some output formats don't have + * an equivalent. As a kludge fix, I shall * assume the font is fixed width and that * the tabstops are 8 characters apart. */ - int need= 8-(total_chars_this_line%8); + int need = 8 - (total_chars_this_line % 8); total_chars_this_line += need; - while(need>0) { - if (safe_printf(0, op->forced_space)) fprintf(stderr, TOO_MANY_ARGS, "forced_space"); + while (need > 0) + { + if (safe_printf(0, op->forced_space)) + { + fprintf(stderr, TOO_MANY_ARGS, "forced_space"); + } need--; } printf("\n"); @@ -1263,8 +1736,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_plain (Word *w, int align, char has_param, int param) { +static int +cmd_plain(Word *w, int align, char has_param, int param) +{ attr_pop_all(); return FALSE; } @@ -1276,9 +1750,10 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_fnil (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTNIL_STR); +static int +cmd_fnil(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTNIL_STR); return FALSE; } @@ -1290,9 +1765,10 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_froman (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTROMAN_STR); +static int +cmd_froman(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTROMAN_STR); return FALSE; } @@ -1304,9 +1780,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_fswiss (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTSWISS_STR); +static int +cmd_fswiss(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTSWISS_STR); return FALSE; } @@ -1318,9 +1795,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_fmodern (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTMODERN_STR); +static int +cmd_fmodern(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTMODERN_STR); return FALSE; } @@ -1332,9 +1810,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_fscript (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTSCRIPT_STR); +static int +cmd_fscript(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTSCRIPT_STR); return FALSE; } @@ -1345,9 +1824,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_fdecor (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTDECOR_STR); +static int +cmd_fdecor(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTDECOR_STR); return FALSE; } @@ -1358,9 +1838,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_ftech (Word *w, int align, char has_param, int param) { - attr_push(ATTR_FONTFACE,FONTTECH_STR); +static int +cmd_ftech(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_FONTFACE, FONTTECH_STR); return FALSE; } @@ -1371,15 +1852,21 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_expand (Word *w, int align, char has_param, int param) { - char str[10]; - if (has_param) { - sprintf(str, "%d", param/4); - if (!param) +static int +cmd_expand(Word *w, int align, char has_param, int param) +{ + char str[20]; + if (has_param) + { + snprintf(str, 20, "%d", param / 4); + if (!param) + { attr_pop(ATTR_EXPAND); - else + } + else + { attr_push(ATTR_EXPAND, str); + } } return FALSE; } @@ -1392,9 +1879,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_emboss (Word *w, int align, char has_param, int param) { - char str[10]; +static int +cmd_emboss(Word *w, int align, char has_param, int param) +{ + char str[20]; if (has_param && !param) #ifdef SUPPORT_UNNESTED attr_find_pop(ATTR_EMBOSS); @@ -1403,7 +1891,7 @@ #endif else { - sprintf(str, "%d", param); + snprintf(str, 20, "%d", param); attr_push(ATTR_EMBOSS, str); } return FALSE; @@ -1417,14 +1905,17 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_engrave (Word *w, int align, char has_param, int param) { - char str[10]; - if (has_param && !param) +static int +cmd_engrave(Word *w, int align, char has_param, int param) +{ + char str[20]; + if (has_param && !param) + { attr_pop(ATTR_ENGRAVE); + } else { - sprintf(str, "%d", param); + snprintf(str, 20, "%d", param); attr_push(ATTR_ENGRAVE, str); } return FALSE; @@ -1437,12 +1928,17 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_caps (Word *w, int align, char has_param, int param) { +static int +cmd_caps(Word *w, int align, char has_param, int param) +{ if (has_param && !param) + { attr_pop(ATTR_CAPS); - else - attr_push(ATTR_CAPS,NULL); + } + else + { + attr_push(ATTR_CAPS, NULL); + } return FALSE; } @@ -1453,12 +1949,17 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_scaps (Word *w, int align, char has_param, int param) { +static int +cmd_scaps(Word *w, int align, char has_param, int param) +{ if (has_param && !param) + { attr_pop(ATTR_SMALLCAPS); - else - attr_push(ATTR_SMALLCAPS,NULL); + } + else + { + attr_push(ATTR_SMALLCAPS, NULL); + } return FALSE; } @@ -1469,10 +1970,15 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_bullet (Word *w, int align, char has_param, int param) { - if (op->chars.bullet) { - if (safe_printf(0, op->chars.bullet)) fprintf(stderr, TOO_MANY_ARGS, "chars.bullet"); +static int +cmd_bullet(Word *w, int align, char has_param, int param) +{ + if (op->chars.bullet) + { + if (safe_printf(0, op->chars.bullet)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.bullet"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1484,10 +1990,15 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_ldblquote (Word *w, int align, char has_param, int param) { - if (op->chars.left_dbl_quote) { - if (safe_printf(0, op->chars.left_dbl_quote)) fprintf(stderr, TOO_MANY_ARGS, "chars.left_dbl_quote"); +static int +cmd_ldblquote(Word *w, int align, char has_param, int param) +{ + if (op->chars.left_dbl_quote) + { + if (safe_printf(0, op->chars.left_dbl_quote)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.left_dbl_quote"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1501,10 +2012,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_rdblquote (Word *w, int align, char has_param, int param) { - if (op->chars.right_dbl_quote) { - if (safe_printf(0, op->chars.right_dbl_quote)) fprintf(stderr, TOO_MANY_ARGS, "chars.right_dbl_quote"); +static int +cmd_rdblquote(Word *w, int align, char has_param, int param) +{ + if (op->chars.right_dbl_quote) + { + if (safe_printf(0, op->chars.right_dbl_quote)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.right_dbl_quote"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1517,10 +2033,15 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_lquote (Word *w, int align, char has_param, int param) { - if (op->chars.left_quote) { - if (safe_printf(0, op->chars.left_quote)) fprintf(stderr, TOO_MANY_ARGS, "chars.left_quote"); +static int +cmd_lquote(Word *w, int align, char has_param, int param) +{ + if (op->chars.left_quote) + { + if (safe_printf(0, op->chars.left_quote)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.left_quote"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1534,10 +2055,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_nonbreaking_space (Word *w, int align, char has_param, int param) { - if (op->chars.nonbreaking_space) { - if (safe_printf(0, op->chars.nonbreaking_space)) fprintf(stderr, TOO_MANY_ARGS, "chars.nonbreaking_space"); +static int +cmd_nonbreaking_space(Word *w, int align, char has_param, int param) +{ + if (op->chars.nonbreaking_space) + { + if (safe_printf(0, op->chars.nonbreaking_space)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.nonbreaking_space"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1551,10 +2077,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_nonbreaking_hyphen (Word *w, int align, char has_param, int param) { - if (op->chars.nonbreaking_hyphen) { - if (safe_printf(0, op->chars.nonbreaking_hyphen)) fprintf(stderr, TOO_MANY_ARGS, "chars.nonbreaking_hyphen"); +static int +cmd_nonbreaking_hyphen(Word *w, int align, char has_param, int param) +{ + if (op->chars.nonbreaking_hyphen) + { + if (safe_printf(0, op->chars.nonbreaking_hyphen)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.nonbreaking_hyphen"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1568,10 +2099,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_optional_hyphen (Word *w, int align, char has_param, int param) { - if (op->chars.optional_hyphen) { - if (safe_printf(0, op->chars.optional_hyphen)) fprintf(stderr, TOO_MANY_ARGS, "chars.optional_hyphen"); +static int +cmd_optional_hyphen(Word *w, int align, char has_param, int param) +{ + if (op->chars.optional_hyphen) + { + if (safe_printf(0, op->chars.optional_hyphen)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.optional_hyphen"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1584,10 +2120,15 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_emdash (Word *w, int align, char has_param, int param) { - if (op->chars.emdash) { - if (safe_printf(0, op->chars.emdash)) fprintf(stderr, TOO_MANY_ARGS, "chars.emdash"); +static int +cmd_emdash(Word *w, int align, char has_param, int param) +{ + if (op->chars.emdash) + { + if (safe_printf(0, op->chars.emdash)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.emdash"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1601,10 +2142,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_endash (Word *w, int align, char has_param, int param) { - if (op->chars.endash) { - if (safe_printf(0, op->chars.endash)) fprintf(stderr, TOO_MANY_ARGS, "chars.endash"); +static int +cmd_endash(Word *w, int align, char has_param, int param) +{ + if (op->chars.endash) + { + if (safe_printf(0, op->chars.endash)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.endash"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1618,10 +2164,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_rquote (Word *w, int align, char has_param, int param) { - if (op->chars.right_quote) { - if (safe_printf(0, op->chars.right_quote)) fprintf(stderr, TOO_MANY_ARGS, "chars.right_quote"); +static int +cmd_rquote(Word *w, int align, char has_param, int param) +{ + if (op->chars.right_quote) + { + if (safe_printf(0, op->chars.right_quote)) + { + fprintf(stderr, TOO_MANY_ARGS, "chars.right_quote"); + } ++total_chars_this_line; /* \tab */ } return FALSE; @@ -1634,10 +2185,15 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_par (Word *w, int align, char has_param, int param) { - if (op->line_break) { - if (safe_printf(0, op->line_break)) fprintf(stderr, TOO_MANY_ARGS, "line_break"); +static int +cmd_par(Word *w, int align, char has_param, int param) +{ + if (op->line_break) + { + if (safe_printf(0, op->line_break)) + { + fprintf(stderr, TOO_MANY_ARGS, "line_break"); + } total_chars_this_line = 0; /* \tab */ } return FALSE; @@ -1651,10 +2207,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int -cmd_line (Word *w, int align, char has_param, int param) { - if (op->line_break) { - if (safe_printf(0, op->line_break)) fprintf(stderr, TOO_MANY_ARGS, "line_break"); +static int +cmd_line(Word *w, int align, char has_param, int param) +{ + if (op->line_break) + { + if (safe_printf(0, op->line_break)) + { + fprintf(stderr, TOO_MANY_ARGS, "line_break"); + } total_chars_this_line = 0; /* \tab */ } return FALSE; @@ -1668,9 +2229,14 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_page (Word *w, int align, char has_param, int param) { - if (op->page_break) { - if (safe_printf(0, op->page_break)) fprintf(stderr, TOO_MANY_ARGS, "page_break"); +static int cmd_page(Word *w, int align, char has_param, int param) +{ + if (op->page_break) + { + if (safe_printf(0, op->page_break)) + { + fprintf(stderr, TOO_MANY_ARGS, "page_break"); + } total_chars_this_line = 0; /* \tab */ } return FALSE; @@ -1684,7 +2250,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_intbl (Word *w, int align, char has_param, int param) { +static int cmd_intbl(Word *w, int align, char has_param, int param) +{ ++coming_pars_that_are_tabular; check_for_table(); @@ -1700,35 +2267,17 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ulnone (Word *w, int align, char has_param, int param) -{ - -#ifdef BINARY_ATTRS - attr_remove_underlining()) fprintf(stderr, TOO_MANY_ARGS, ); -#else - do { - int attr = attr_read(); - if (attr==ATTR_UNDERLINE || - attr==ATTR_DOT_UL || - attr==ATTR_DASH_UL || - attr==ATTR_DOT_DASH_UL || - attr==ATTR_2DOT_DASH_UL || - attr==ATTR_WORD_UL || - attr==ATTR_WAVE_UL || - attr==ATTR_THICK_UL || - attr==ATTR_DOUBLE_UL) - { - /* Top attr is some kind of underline. Pop it */ - if (!attr_pop(attr)) { - /* ?? Have to break, else we're looping */ - break; - } - } else { - /* Top attr not underline, done */ - break; - } - } while (1); -#endif +static int cmd_ulnone(Word *w, int align, char has_param, int param) +{ + attr_find_pop(ATTR_UNDERLINE); + attr_find_pop(ATTR_DOT_UL); + attr_find_pop(ATTR_DASH_UL); + attr_find_pop(ATTR_DOT_DASH_UL); + attr_find_pop(ATTR_2DOT_DASH_UL); + attr_find_pop(ATTR_WORD_UL); + attr_find_pop(ATTR_WAVE_UL); + attr_find_pop(ATTR_THICK_UL); + attr_find_pop(ATTR_DOUBLE_UL); return FALSE; } @@ -1739,10 +2288,14 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ul (Word *w, int align, char has_param, int param) { - if (has_param && param == 0) { +static int cmd_ul(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { cmd_ulnone(w, align, has_param, param); - } else { + } + else + { attr_push(ATTR_UNDERLINE, NULL); } return FALSE; @@ -1755,7 +2308,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_uld (Word *w, int align, char has_param, int param) { +static int cmd_uld(Word *w, int align, char has_param, int param) +{ attr_push(ATTR_DOUBLE_UL, NULL); return FALSE; } @@ -1767,7 +2321,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_uldb (Word *w, int align, char has_param, int param) { +static int cmd_uldb(Word *w, int align, char has_param, int param) +{ attr_push(ATTR_DOT_UL, NULL); return FALSE; } @@ -1780,7 +2335,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_uldash (Word *w, int align, char has_param, int param) { +static int cmd_uldash(Word *w, int align, char has_param, int param) +{ attr_push(ATTR_DASH_UL, NULL); return FALSE; } @@ -1793,8 +2349,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_uldashd (Word *w, int align, char has_param, int param) { - attr_push(ATTR_DOT_DASH_UL,NULL); +static int cmd_uldashd(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_DOT_DASH_UL, NULL); return FALSE; } @@ -1806,8 +2363,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_uldashdd (Word *w, int align, char has_param, int param) { - attr_push(ATTR_2DOT_DASH_UL,NULL); +static int cmd_uldashdd(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_2DOT_DASH_UL, NULL); return FALSE; } @@ -1819,8 +2377,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ulw (Word *w, int align, char has_param, int param) { - attr_push(ATTR_WORD_UL,NULL); +static int cmd_ulw(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_WORD_UL, NULL); return FALSE; } @@ -1832,8 +2391,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ulth (Word *w, int align, char has_param, int param) { - attr_push(ATTR_THICK_UL,NULL); +static int cmd_ulth(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_THICK_UL, NULL); return FALSE; } @@ -1845,7 +2405,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ulthd (Word *w, int align, char has_param, int param) { +static int cmd_ulthd(Word *w, int align, char has_param, int param) +{ attr_push(ATTR_THICK_UL, NULL); return FALSE; } @@ -1858,7 +2419,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ulthdash (Word *w, int align, char has_param, int param) { +static int cmd_ulthdash(Word *w, int align, char has_param, int param) +{ attr_push(ATTR_THICK_UL, NULL); return FALSE; } @@ -1871,8 +2433,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ulwave (Word *w, int align, char has_param, int param) { - attr_push(ATTR_WAVE_UL,NULL); +static int cmd_ulwave(Word *w, int align, char has_param, int param) +{ + attr_push(ATTR_WAVE_UL, NULL); return FALSE; } @@ -1884,11 +2447,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_strike (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_strike(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_STRIKE); + } else - attr_push(ATTR_STRIKE,NULL); + { + attr_push(ATTR_STRIKE, NULL); + } return FALSE; } @@ -1899,11 +2467,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_strikedl (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_strikedl(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_DBL_STRIKE); + } else - attr_push(ATTR_DBL_STRIKE,NULL); + { + attr_push(ATTR_DBL_STRIKE, NULL); + } return FALSE; } @@ -1915,11 +2488,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_striked (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_striked(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_DBL_STRIKE); + } else - attr_push(ATTR_DBL_STRIKE,NULL); + { + attr_push(ATTR_DBL_STRIKE, NULL); + } return FALSE; } @@ -1931,7 +2509,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_rtf (Word *w, int align, char has_param, int param) { +static int cmd_rtf(Word *w, int align, char has_param, int param) +{ return FALSE; } @@ -1942,7 +2521,7 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_shppict (Word *w, int align, char has_param, int param) +static int cmd_shppict(Word *w, int align, char has_param, int param) { return FALSE; } @@ -1954,11 +2533,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_up (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_up(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_SUPER); + } else - attr_push(ATTR_SUPER,NULL); + { + attr_push(ATTR_SUPER, NULL); + } return FALSE; } @@ -1969,27 +2553,28 @@ * Returns: Flag, always false *=======================================================================*/ -static int cmd_u (Word *w, int align, char has_param, int param) { -/* TODO: Unicode characters won't be correctly preprocessed if sizeof(int) < 4 - * and document have unicode character which value is greater than 65536 - */ - - short done=0; +static int cmd_u(Word *w, int align, char has_param, int param) +{ + /* TODO: Unicode characters won't be correctly preprocessed if sizeof(int) < 4 + * and document have unicode character which value is greater than 65536 + */ + + short done = 0; long unicode_number = (long) param; /* On 16bit architectures int is too small to store unicode characters. - AF */ - char tmp[12]; /* Number of characters that can be in int type (including '\0'). If int size is greater than 4 bytes change this value. - AF */ + char tmp[20]; /* Number of characters that can be in int type (including '\0'). If int size is greater than 4 bytes change this value. - AF */ const char *alias; #define DEBUG 0 #if DEBUG char *str; if (has_param == TRUE) { - fprintf(stderr,"param is %d (x%x) (0%o)\n", param, - param, param); + fprintf(stderr, "param is %d (x%x) (0%o)\n", param, + param, param); } if (w->hash_index) { - str=hash_get_string (w->hash_index); - fprintf(stderr,"string is %s\n", str); + str = hash_get_string(w->hash_index); + fprintf(stderr, "string is %s\n", str); } #endif /* 0.20.3 - daved added missing function call for unprocessed chars */ @@ -1998,28 +2583,32 @@ printf("%s", alias); done++; } - else - if(!done && op->unisymbol_print) - { - if (unicode_number < 0) - { - /* RTF spec: Unicode values beyond 32767 are represented by negative numbers */ - unicode_number += 65536; - } - sprintf(tmp, "%ld", unicode_number); - - if (safe_printf(1, op->unisymbol_print, tmp)) fprintf(stderr, TOO_MANY_ARGS, "unisymbol_print"); - done++; - } - + else if (!done && op->unisymbol_print) + { + if (unicode_number < 0) + { + /* RTF spec: Unicode values beyond 32767 are represented by negative numbers */ + unicode_number += 65536; + } + snprintf(tmp, 20, "%ld", unicode_number); + + if (safe_printf(1, op->unisymbol_print, tmp)) + { + fprintf(stderr, TOO_MANY_ARGS, "unisymbol_print"); + } + done++; + } + /* ** if we know how to represent the unicode character in the ** output language, we need to skip the next word, otherwise ** we will output that alternative. */ if (done) - return(SKIP_ONE_WORD); - return(FALSE); + { + return (SKIP_ONE_WORD); + } + return (FALSE); } /*======================================================================== @@ -2029,11 +2618,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_dn (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_dn(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_SUB); + } else - attr_push(ATTR_SUB,NULL); + { + attr_push(ATTR_SUB, NULL); + } return FALSE; } @@ -2044,7 +2638,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_nosupersub (Word *w, int align, char has_param, int param) { +static int cmd_nosupersub(Word *w, int align, char has_param, int param) +{ attr_pop(ATTR_SUPER); attr_pop(ATTR_SUB); return FALSE; @@ -2057,11 +2652,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_super (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_super(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_SUPER); + } else - attr_push(ATTR_SUPER,NULL); + { + attr_push(ATTR_SUPER, NULL); + } return FALSE; } @@ -2072,11 +2672,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_sub (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_sub(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_SUB); + } else - attr_push(ATTR_SUB,NULL); + { + attr_push(ATTR_SUB, NULL); + } return FALSE; } @@ -2087,11 +2692,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_shad (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_shad(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_SHADOW); + } else - attr_push(ATTR_SHADOW,NULL); + { + attr_push(ATTR_SHADOW, NULL); + } return FALSE; } @@ -2103,9 +2713,11 @@ *=======================================================================*/ #define SUPPORT_UNNESTED -static int -cmd_b (Word *w, int align, char has_param, int param) { - if (has_param && param==0) { +static int +cmd_b(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { #ifdef SUPPORT_UNNESTED attr_find_pop(ATTR_BOLD); #else @@ -2113,7 +2725,9 @@ #endif } else - attr_push(ATTR_BOLD,NULL); + { + attr_push(ATTR_BOLD, NULL); + } return FALSE; } @@ -2124,15 +2738,18 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_i (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_i(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) #ifdef SUPPORT_UNNESTED attr_find_pop(ATTR_ITALIC); #else attr_pop(ATTR_ITALIC); #endif else - attr_push(ATTR_ITALIC,NULL); + { + attr_push(ATTR_ITALIC, NULL); + } return FALSE; } @@ -2142,7 +2759,8 @@ * Args: Word, paragraph align info, and numeric param if any. * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_s (Word *w, int align, char has_param, int param) { +static int cmd_s(Word *w, int align, char has_param, int param) +{ return FALSE; } @@ -2153,10 +2771,15 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_sect (Word *w, int align, char has_param, int param) { +static int cmd_sect(Word *w, int align, char has_param, int param) +{ /* XX kludge */ - if (op->paragraph_begin) { - if (safe_printf(0, op->paragraph_begin)) fprintf(stderr, TOO_MANY_ARGS, "paragraph_begin"); + if (op->paragraph_begin) + { + if (safe_printf(0, op->paragraph_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "paragraph_begin"); + } } return FALSE; } @@ -2168,11 +2791,19 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_shp (Word *w, int align, char has_param, int param) { - if (op->comment_begin) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); +static int cmd_shp(Word *w, int align, char has_param, int param) +{ + if (op->comment_begin) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("Drawn Shape (ignored-not implemented yet)"); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } return FALSE; @@ -2185,11 +2816,16 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_outl (Word *w, int align, char has_param, int param) { - if (has_param && param==0) +static int cmd_outl(Word *w, int align, char has_param, int param) +{ + if (has_param && param == 0) + { attr_pop(ATTR_OUTLINE); + } else - attr_push(ATTR_OUTLINE,NULL); + { + attr_push(ATTR_OUTLINE, NULL); + } return FALSE; } @@ -2200,9 +2836,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ansi (Word *w, int align, char has_param, int param) { - default_encoding = "CP1252"; - return FALSE; +static int cmd_ansi(Word *w, int align, char has_param, int param) +{ + default_encoding = "CP1252"; + return FALSE; } /*======================================================================== @@ -2212,10 +2849,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_ansicpg (Word *w, int align, char has_param, int param) -{ - default_encoding = cptoencoding(param); - had_ansicpg = 1; +static int cmd_ansicpg(Word *w, int align, char has_param, int param) +{ + default_encoding = cptoencoding(param); + had_ansicpg = 1; return FALSE; } @@ -2226,10 +2863,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_pc (Word *w, int align, char has_param, int param) -{ - default_encoding = "CP437"; - return FALSE; +static int cmd_pc(Word *w, int align, char has_param, int param) +{ + default_encoding = "CP437"; + return FALSE; } /*======================================================================== @@ -2239,10 +2876,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_pca (Word *w, int align, char has_param, int param) -{ - default_encoding = "CP850"; - return FALSE; +static int cmd_pca(Word *w, int align, char has_param, int param) +{ + default_encoding = "CP850"; + return FALSE; } /*======================================================================== @@ -2252,10 +2889,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_mac (Word *w, int align, char has_param, int param) -{ - default_encoding = "MAC"; - return FALSE; +static int cmd_mac(Word *w, int align, char has_param, int param) +{ + default_encoding = "MAC"; + return FALSE; } /*======================================================================== @@ -2265,8 +2902,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_colortbl (Word *w, int align, char has_param, int param) { - if (w->next) { +static int cmd_colortbl(Word *w, int align, char has_param, int param) +{ + if (w->next) + { process_color_table(w->next); } return TRUE; @@ -2279,8 +2918,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_fonttbl (Word *w, int align, char has_param, int param) { - if (w->next) { +static int cmd_fonttbl(Word *w, int align, char has_param, int param) +{ + if (w->next) + { process_font_table(w->next); } return TRUE; @@ -2293,7 +2934,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_header (Word *w, int align, char has_param, int param) { +static int cmd_header(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2304,7 +2946,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_headerl (Word *w, int align, char has_param, int param) { +static int cmd_headerl(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2315,7 +2958,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_headerr (Word *w, int align, char has_param, int param) { +static int cmd_headerr(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2326,7 +2970,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_headerf (Word *w, int align, char has_param, int param) { +static int cmd_headerf(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2337,7 +2982,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_footer (Word *w, int align, char has_param, int param) { +static int cmd_footer(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2348,7 +2994,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_footerl (Word *w, int align, char has_param, int param) { +static int cmd_footerl(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2359,7 +3006,8 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_footerr (Word *w, int align, char has_param, int param) { +static int cmd_footerr(Word *w, int align, char has_param, int param) +{ return TRUE; } @@ -2370,58 +3018,61 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_footerf (Word *w, int align, char has_param, int param) { +static int cmd_footerf(Word *w, int align, char has_param, int param) +{ return TRUE; } /*======================================================================== * Name: cmd_ignore - * Purpose: Dummy function to get rid of subgroups - * Args: Word, paragraph align info, and numeric param if any. - * Returns: Flag, true only if rest of Words on line should be ignored. - *=======================================================================*/ - -static int cmd_ignore (Word *w, int align, char has_param, int param) + * Purpose: Dummy function to get rid of subgroups + * Args: Word, paragraph align info, and numeric param if any. + * Returns: Flag, true only if rest of Words on line should be ignored. + *=======================================================================*/ + +static int cmd_ignore(Word *w, int align, char has_param, int param) { return TRUE; } - /*======================================================================== - * Name: cmd_maybe_ignore - * Purpose: Called when encountering {\* which specifies that the whole - * group should be discarded if the immediately following command is - * not known. - * Args: Word, paragraph align info, and numeric param if any. - * Returns: Flag, true only if rest of Words on line should be ignored. - *=======================================================================*/ - -static int cmd_maybe_ignore (Word *w, int align, char has_param, int param) -{ - /* If the next command is known, we let it decide what to do +/*======================================================================== + * Name: cmd_maybe_ignore + * Purpose: Called when encountering {\* which specifies that the whole + * group should be discarded if the immediately following command is + * not known. + * Args: Word, paragraph align info, and numeric param if any. + * Returns: Flag, true only if rest of Words on line should be ignored. + *=======================================================================*/ + +static int cmd_maybe_ignore(Word *w, int align, char has_param, int param) +{ + /* If the next command is known, we let it decide what to do * (which may still be to discard the group. If it is not found * we return TRUE to discard the next elements. */ - if(w && w->next) + if (w && w->next) { int hasparam, param; const char *s = word_string(w->next); if (s && s[0] == '\\' && find_command(s + 1, &hasparam, ¶m)) + { return FALSE; - } - + } + } + return TRUE; } /*======================================================================== * Name: cmd_blipuid - * Purpose: Dummy function to get rid of uid - * Args: Word, paragraph align info, and numeric param if any. - * Returns: Flag, true only if rest of Words on line should be ignored. - *=======================================================================*/ - -static int cmd_blipuid (Word *w, int align, char has_param, int param) -{ - CHECK_PARAM_NOT_NULL (w); + * Purpose: Dummy function to get rid of uid + * Args: Word, paragraph align info, and numeric param if any. + * Returns: Flag, true only if rest of Words on line should be ignored. + *=======================================================================*/ + +static int cmd_blipuid(Word *w, int align, char has_param, int param) +{ + CHECK_PARAM_NOT_NULL(w); return TRUE; } @@ -2432,8 +3083,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_info (Word *w, int align, char has_param, int param) { - process_info_group (w->next); +static int cmd_info(Word *w, int align, char has_param, int param) +{ + process_info_group(w->next); return TRUE; } @@ -2444,12 +3096,12 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_pict (Word *w, int align, char has_param, int param) -{ - within_picture=TRUE; +static int cmd_pict(Word *w, int align, char has_param, int param) +{ + within_picture = TRUE; picture_width = picture_height = 0; picture_type = PICT_WB; - return FALSE; + return FALSE; } /*======================================================================== * Name: cmd_picprop @@ -2458,9 +3110,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_picprop (Word *w, int align, char has_param, int param) -{ - return TRUE; +static int cmd_picprop(Word *w, int align, char has_param, int param) +{ + return TRUE; } @@ -2471,8 +3123,9 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_bin (Word *w, int align, char has_param, int param) { - return FALSE; +static int cmd_bin(Word *w, int align, char has_param, int param) +{ + return FALSE; } @@ -2483,9 +3136,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_macpict (Word *w, int align, char has_param, int param) { +static int cmd_macpict(Word *w, int align, char has_param, int param) +{ picture_type = PICT_MAC; - return FALSE; + return FALSE; } /*======================================================================== @@ -2495,9 +3149,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_jpegblip (Word *w, int align, char has_param, int param) { +static int cmd_jpegblip(Word *w, int align, char has_param, int param) +{ picture_type = PICT_JPEG; - return FALSE; + return FALSE; } /*======================================================================== @@ -2507,9 +3162,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_pngblip (Word *w, int align, char has_param, int param) { +static int cmd_pngblip(Word *w, int align, char has_param, int param) +{ picture_type = PICT_PNG; - return FALSE; + return FALSE; } /*======================================================================== @@ -2519,9 +3175,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_emfblip (Word *w, int align, char has_param, int param) { +static int cmd_emfblip(Word *w, int align, char has_param, int param) +{ picture_type = PICT_EMF; - return FALSE; + return FALSE; } /*======================================================================== @@ -2531,9 +3188,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_pnmetafile (Word *w, int align, char has_param, int param) { +static int cmd_pnmetafile(Word *w, int align, char has_param, int param) +{ picture_type = PICT_PM; - return FALSE; + return FALSE; } /*======================================================================== @@ -2543,23 +3201,44 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_wmetafile (Word *w, int align, char has_param, int param) { +static int cmd_wmetafile(Word *w, int align, char has_param, int param) +{ picture_type = PICT_WM; - if (within_picture && has_param) { - picture_wmetafile_type=param; - switch(param) { - case 1: picture_wmetafile_type_str="MM_TEXT"; break; - case 2: picture_wmetafile_type_str="MM_LOMETRIC"; break; - case 3: picture_wmetafile_type_str="MM_HIMETRIC"; break; - case 4: picture_wmetafile_type_str="MM_LOENGLISH"; break; - case 5: picture_wmetafile_type_str="MM_HIENGLISH"; break; - case 6: picture_wmetafile_type_str="MM_TWIPS"; break; - case 7: picture_wmetafile_type_str="MM_ISOTROPIC"; break; - case 8: picture_wmetafile_type_str="MM_ANISOTROPIC"; break; - default: picture_wmetafile_type_str="default:MM_TEXT"; break; - } - } - return FALSE; + if (within_picture && has_param) + { + picture_wmetafile_type = param; + switch (param) + { + case 1: + picture_wmetafile_type_str = "MM_TEXT"; + break; + case 2: + picture_wmetafile_type_str = "MM_LOMETRIC"; + break; + case 3: + picture_wmetafile_type_str = "MM_HIMETRIC"; + break; + case 4: + picture_wmetafile_type_str = "MM_LOENGLISH"; + break; + case 5: + picture_wmetafile_type_str = "MM_HIENGLISH"; + break; + case 6: + picture_wmetafile_type_str = "MM_TWIPS"; + break; + case 7: + picture_wmetafile_type_str = "MM_ISOTROPIC"; + break; + case 8: + picture_wmetafile_type_str = "MM_ANISOTROPIC"; + break; + default: + picture_wmetafile_type_str = "default:MM_TEXT"; + break; + } + } + return FALSE; } /*======================================================================== @@ -2569,10 +3248,13 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_wbmbitspixel (Word *w, int align, char has_param, int param) { - if (within_picture && has_param) +static int cmd_wbmbitspixel(Word *w, int align, char has_param, int param) +{ + if (within_picture && has_param) + { picture_bits_per_pixel = param; - return FALSE; + } + return FALSE; } /*======================================================================== @@ -2582,10 +3264,13 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_picw (Word *w, int align, char has_param, int param) { - if (within_picture && has_param) +static int cmd_picw(Word *w, int align, char has_param, int param) +{ + if (within_picture && has_param) + { picture_width = param; - return FALSE; + } + return FALSE; } /*======================================================================== @@ -2595,10 +3280,13 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_pich (Word *w, int align, char has_param, int param) { - if (within_picture && has_param) +static int cmd_pich(Word *w, int align, char has_param, int param) +{ + if (within_picture && has_param) + { picture_height = param; - return FALSE; + } + return FALSE; } @@ -2609,9 +3297,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_xe (Word *w, int align, char has_param, int param) { - process_index_entry (w); - return TRUE; +static int cmd_xe(Word *w, int align, char has_param, int param) +{ + process_index_entry(w); + return TRUE; } /*======================================================================== @@ -2621,9 +3310,10 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_tc (Word *w, int align, char has_param, int param) { - process_toc_entry (w, TRUE); - return TRUE; +static int cmd_tc(Word *w, int align, char has_param, int param) +{ + process_toc_entry(w, TRUE); + return TRUE; } /*======================================================================== @@ -2633,21 +3323,23 @@ * Returns: Flag, true only if rest of Words on line should be ignored. *=======================================================================*/ -static int cmd_tcn (Word *w, int align, char has_param, int param) { - process_toc_entry (w, FALSE); - return TRUE; +static int cmd_tcn(Word *w, int align, char has_param, int param) +{ + process_toc_entry(w, FALSE); + return TRUE; } /* All of the possible commands that RTF might recognize. */ -static HashItem hashArray_other [] = { -/* 0.21.7 - * the "*" command was ignored in earlier versions, but included pictures - * seem to often start with \*\shppict{\pict so if "*" is ignored, so is - * the picture, so I have defined a new function "cmd_maybe_ignore" which - * tests whether the next word is shppict and if so does not ignore what - * follows. On simple tests this seems to work. - daved - */ +static HashItem hashArray_other [] = +{ + /* 0.21.7 + * the "*" command was ignored in earlier versions, but included pictures + * seem to often start with \*\shppict{\pict so if "*" is ignored, so is + * the picture, so I have defined a new function "cmd_maybe_ignore" which + * tests whether the next word is shppict and if so does not ignore what + * follows. On simple tests this seems to work. - daved + */ #if 0 { "*", cmd_ignore, NULL }, #else @@ -2658,12 +3350,14 @@ { "~", cmd_nonbreaking_space, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_a [] = { +static HashItem hashArray_a [] = +{ { "ansi", &cmd_ansi , NULL }, { "ansicpg", &cmd_ansicpg , NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_b [] = { +static HashItem hashArray_b [] = +{ { "b", &cmd_b, NULL }, { "bullet", &cmd_bullet, NULL }, { "bin", &cmd_bin, "picture is binary" }, @@ -2692,7 +3386,8 @@ #endif { NULL, NULL, NULL} }; -static HashItem hashArray_c [] = { +static HashItem hashArray_c [] = +{ { "caps", &cmd_caps, NULL }, { "cb", cmd_cb, NULL }, { "cf", cmd_cf, NULL }, @@ -2728,7 +3423,8 @@ { "cs", NULL, "character style (not implemented)"}, { NULL, NULL, NULL} }; -static HashItem hashArray_d [] = { +static HashItem hashArray_d [] = +{ { "deff", cmd_deff, "Default Font" }, { "dn", &cmd_dn, NULL }, #if 0 @@ -2736,7 +3432,8 @@ #endif { NULL, NULL, NULL} }; -static HashItem hashArray_e [] = { +static HashItem hashArray_e [] = +{ { "emdash", cmd_emdash, NULL }, { "endash", cmd_endash, NULL }, { "embo", &cmd_emboss, NULL }, @@ -2745,7 +3442,8 @@ { "emfblip", &cmd_emfblip, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_f [] = { +static HashItem hashArray_f [] = +{ { "f", cmd_f, NULL }, { "fdecor", cmd_fdecor, NULL }, { "fmodern", cmd_fmodern, NULL }, @@ -2763,7 +3461,8 @@ { "footerr", cmd_footerr, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_h [] = { +static HashItem hashArray_h [] = +{ { "highlight", &cmd_highlight, NULL }, { "header", cmd_header, NULL }, { "headerf", cmd_headerf, NULL }, @@ -2772,7 +3471,8 @@ { "hl", cmd_ignore, "hyperlink within object" }, { NULL, NULL, NULL} }; -static HashItem hashArray_i [] = { +static HashItem hashArray_i [] = +{ { "i", &cmd_i, NULL }, { "info", &cmd_info, NULL }, { "insrsid", NULL, "Revision Mark (ignore)" }, @@ -2780,31 +3480,37 @@ { "impr", &cmd_engrave, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_j [] = { +static HashItem hashArray_j [] = +{ { "jpegblip", &cmd_jpegblip, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_l [] = { +static HashItem hashArray_l [] = +{ { "ldblquote", &cmd_ldblquote, NULL }, { "line", &cmd_line, NULL }, { "lquote", &cmd_lquote, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_m [] = { +static HashItem hashArray_m [] = +{ { "mac", &cmd_mac , NULL }, { "macpict", &cmd_macpict, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_n [] = { +static HashItem hashArray_n [] = +{ { "nosupersub", &cmd_nosupersub, NULL }, { "nonshppict", &cmd_ignore, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_o [] = { +static HashItem hashArray_o [] = +{ { "outl", &cmd_outl, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_p [] = { +static HashItem hashArray_p [] = +{ { "page", &cmd_page, NULL }, { "par", &cmd_par, NULL }, { "pc", &cmd_pc , NULL }, @@ -2830,13 +3536,15 @@ #endif { NULL, NULL, NULL} }; -static HashItem hashArray_r [] = { +static HashItem hashArray_r [] = +{ { "rdblquote", &cmd_rdblquote, NULL }, { "rquote", &cmd_rquote, NULL }, { "rtf", &cmd_rtf, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_s [] = { +static HashItem hashArray_s [] = +{ { "s", cmd_s, "style" }, { "sect", &cmd_sect, "section break"}, { "scaps", &cmd_scaps, NULL }, @@ -2854,14 +3562,16 @@ #endif { NULL, NULL, NULL} }; -static HashItem hashArray_t [] = { +static HashItem hashArray_t [] = +{ { "tab", &cmd_tab, NULL }, { "tc", cmd_tc, "TOC entry" }, { "tcn", cmd_tcn, "TOC entry" }, { "trowd", NULL, "start new row in table" }, { NULL, NULL, NULL} }; -static HashItem hashArray_u [] = { +static HashItem hashArray_u [] = +{ { "u", &cmd_u, NULL }, { "ul", &cmd_ul, NULL }, { "up", &cmd_up, NULL }, @@ -2879,23 +3589,27 @@ { NULL, NULL, NULL} }; -static HashItem hashArray_v [] = { +static HashItem hashArray_v [] = +{ { "v", NULL, "Hidden Text" }, { NULL, NULL, NULL } }; -static HashItem hashArray_w [] = { +static HashItem hashArray_w [] = +{ { "wbmbitspixel", &cmd_wbmbitspixel, NULL }, { "wmetafile", &cmd_wmetafile, NULL }, { NULL, NULL, NULL} }; -static HashItem hashArray_x [] = { +static HashItem hashArray_x [] = +{ { "xe", cmd_xe, "index entry" }, { NULL, NULL, NULL} }; -static HashItem *hash [26] = { +static HashItem *hash [26] = +{ hashArray_a, hashArray_b, hashArray_c, @@ -2919,7 +3633,7 @@ hashArray_u, hashArray_v, hashArray_w, - hashArray_x, + hashArray_x, NULL, NULL }; @@ -2947,41 +3661,66 @@ /* Look for a parameter */ *hasparamp = FALSE; p = cmdpp; - while (*p && (!isdigit(*p) && *p != '-')) + while (*p && (!isdigit(*p) && *p != '-')) + { p++; - if (*p && (isdigit(*p) || *p == '-')) { - *hasparamp = TRUE; + } + if (*p && (isdigit(*p) || *p == '-')) + { + *hasparamp = TRUE; *paramp = atoi(p); } len = p - cmdpp; /* Generate a hash index */ ch = tolower(*cmdpp); - if (ch >= 'a' && ch <= 'z') + if (ch >= 'a' && ch <= 'z') + { hip = hash[ch - 'a']; + } else + { hip = hashArray_other; - - if (!hip) { - if (debug_mode) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + + if (!hip) + { + if (debug_mode) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("Unfamiliar RTF command: %s (HashIndex not found)", cmdpp); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } return NULL; } - while (hip->name) { + while (hip->name) + { /* Don't change the order of tests ! */ if (!strncmp(cmdpp, hip->name, len) && hip->name[len] == 0) + { return hip; + } hip++; } - if (debug_mode) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + if (debug_mode) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } printf("Unfamiliar RTF command: %s", cmdpp); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } } return NULL; } @@ -3005,57 +3744,80 @@ * Returns: None. *=======================================================================*/ -void -print_with_special_exprs (const char *s) { +void +print_with_special_exprs(const char *s) +{ int ch; int state; -enum { SMALL=0, BIG=1 }; + enum { SMALL = 0, BIG = 1 }; CHECK_PARAM_NOT_NULL(s); - // Not sure that there are cases where the flush is needed, - // but this is conceivable, and can't hurt in any case. - flush_iconv_input(); - - maybeopeniconv(); - - state=SMALL; /* Pacify gcc, st001906 - 0.19.6 */ - if (simulate_smallcaps) { - if (*s >= 'a' && *s <= 'z') { - state=SMALL; - if (safe_printf(0, op->smaller_begin)) fprintf(stderr, TOO_MANY_ARGS, "smaller_begin"); + // Not sure that there are cases where the flush is needed, + // but this is conceivable, and can't hurt in any case. + flush_iconv_input(); + + maybeopeniconv(); + + state = SMALL; /* Pacify gcc, st001906 - 0.19.6 */ + if (simulate_smallcaps) + { + if (*s >= 'a' && *s <= 'z') + { + state = SMALL; + if (safe_printf(0, op->smaller_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "smaller_begin"); + } } else - state=BIG; - } - - while ((ch=*s)) { + { + state = BIG; + } + } + + while ((ch = *s)) + { const char *post_trans = NULL; if (simulate_allcaps || simulate_smallcaps) - ch = toupper (ch); - - if (ch >= 0x20 && ch < 0x80) { - post_trans= op_translate_char(op, current_encoding, ch); - if(post_trans) - printf("%s",post_trans); + { + ch = toupper(ch); + } + + if (ch >= 0x20 && ch < 0x80) + { + post_trans = op_translate_char(op, current_encoding, ch); + if (post_trans) + { + printf("%s", post_trans); + my_free(post_trans); + } } s++; - if (simulate_smallcaps) { + if (simulate_smallcaps) + { ch = *s; - if (ch >= 'a' && ch <= 'z') { - if (state==BIG) - if (safe_printf(0, op->smaller_begin)) fprintf(stderr, TOO_MANY_ARGS, "smaller_begin"); - state=SMALL; + if (ch >= 'a' && ch <= 'z') + { + if (state == BIG) + if (safe_printf(0, op->smaller_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "smaller_begin"); + } + state = SMALL; } else { - if (state==SMALL) - if (safe_printf(0, op->smaller_end)) fprintf(stderr, TOO_MANY_ARGS, "smaller_end"); - state=BIG; + if (state == SMALL) + if (safe_printf(0, op->smaller_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "smaller_end"); + } + state = BIG; } } } @@ -3064,23 +3826,26 @@ /*======================================================================== - * Name: - * Purpose: + * Name: + * Purpose: * Args: None. * Returns: None. *=======================================================================*/ -static void +static void begin_table() { - within_table=TRUE; + within_table = TRUE; have_printed_row_begin = FALSE; have_printed_cell_begin = FALSE; have_printed_row_end = FALSE; have_printed_cell_end = FALSE; attrstack_push(); starting_body(); - if (safe_printf(0, op->table_begin)) fprintf(stderr, TOO_MANY_ARGS, "table_begin"); + if (safe_printf(0, op->table_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_begin"); + } } @@ -3091,19 +3856,31 @@ * Returns: None. *=======================================================================*/ -void -end_table () -{ - if (within_table) { - if (!have_printed_cell_end) { - attr_pop_dump(); - if (safe_printf(0, op->table_cell_end)) fprintf(stderr, TOO_MANY_ARGS, "table_cell_end"); - } - if (!have_printed_row_end) { - if (safe_printf(0, op->table_row_end)) fprintf(stderr, TOO_MANY_ARGS, "table_row_end"); - } - if (safe_printf(0, op->table_end)) fprintf(stderr, TOO_MANY_ARGS, "table_end"); - within_table=FALSE; +void +end_table() +{ + if (within_table) + { + if (!have_printed_cell_end) + { + attr_pop_all(); + if (safe_printf(0, op->table_cell_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_cell_end"); + } + } + if (!have_printed_row_end) + { + if (safe_printf(0, op->table_row_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_row_end"); + } + } + if (safe_printf(0, op->table_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_end"); + } + within_table = FALSE; have_printed_row_begin = FALSE; have_printed_cell_begin = FALSE; have_printed_row_end = FALSE; @@ -3135,58 +3912,79 @@ } /*======================================================================== - * Name: - * Purpose: + * Name: + * Purpose: * Args: None. * Returns: None. *=======================================================================*/ -void -starting_text() { - if (within_table) { - if (!have_printed_row_begin) { - if (safe_printf(0, op->table_row_begin)) fprintf(stderr, TOO_MANY_ARGS, "table_row_begin"); - have_printed_row_begin=TRUE; - have_printed_row_end=FALSE; - have_printed_cell_begin=FALSE; - } - if (!have_printed_cell_begin) { - if (safe_printf(0, op->table_cell_begin)) fprintf(stderr, TOO_MANY_ARGS, "table_cell_begin"); +void +starting_text() +{ + if (within_table) + { + if (!have_printed_row_begin) + { + if (safe_printf(0, op->table_row_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_row_begin"); + } + have_printed_row_begin = TRUE; + have_printed_row_end = FALSE; + have_printed_cell_begin = FALSE; + } + if (!have_printed_cell_begin) + { + if (safe_printf(0, op->table_cell_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_cell_begin"); + } attrstack_express_all(); - have_printed_cell_begin=TRUE; - have_printed_cell_end=FALSE; - } - } -} - - - - -/*======================================================================== - * Name: - * Purpose: + have_printed_cell_begin = TRUE; + have_printed_cell_end = FALSE; + } + } +} + + + + +/*======================================================================== + * Name: + * Purpose: * Args: None. * Returns: None. *=======================================================================*/ static void -starting_paragraph_align (int align) +starting_paragraph_align(int align) { if (within_header && align != ALIGN_LEFT) + { starting_body(); - - switch (align) + } + + switch (align) { case ALIGN_CENTER: - if (safe_printf(0, op->center_begin)) fprintf(stderr, TOO_MANY_ARGS, "center_begin"); + if (safe_printf(0, op->center_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "center_begin"); + } break; case ALIGN_LEFT: break; case ALIGN_RIGHT: - if (safe_printf(0, op->align_right_begin)) fprintf(stderr, TOO_MANY_ARGS, "align_right_begin"); + if (safe_printf(0, op->align_right_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "align_right_begin"); + } break; case ALIGN_JUSTIFY: - if (safe_printf(0, op->justify_begin)) fprintf(stderr, TOO_MANY_ARGS, "justify_begin"); /* But this is correct */ + if (safe_printf(0, op->justify_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "justify_begin"); /* But this is correct */ + } break; } } @@ -3194,26 +3992,36 @@ /*======================================================================== - * Name: - * Purpose: + * Name: + * Purpose: * Args: None. * Returns: None. *=======================================================================*/ static void -ending_paragraph_align (int align) -{ - switch (align) { +ending_paragraph_align(int align) +{ + switch (align) + { case ALIGN_CENTER: - if (safe_printf(0, op->center_end)) fprintf(stderr, TOO_MANY_ARGS, "center_end"); + if (safe_printf(0, op->center_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "center_end"); + } break; case ALIGN_LEFT: break; case ALIGN_RIGHT: - if (safe_printf(0, op->align_right_end)) fprintf(stderr, TOO_MANY_ARGS, "align_right_end"); + if (safe_printf(0, op->align_right_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "align_right_end"); + } break; case ALIGN_JUSTIFY: - if (safe_printf(0, op->justify_end)) fprintf(stderr, TOO_MANY_ARGS, "justify_end"); + if (safe_printf(0, op->justify_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "justify_end"); + } break; } } @@ -3225,73 +4033,83 @@ static void flush_iconv_input() { -/* fprintf(stderr, "flush_iconv_input: iconv_cur %d\n", iconv_cur);*/ - if (iconv_cur <= 0) { - iconv_cur = 0; - return; - } - maybeopeniconv(); - if (!my_iconv_is_valid(desc)) { - fprintf(stderr, "unrtf: flush: iconv not ready!\n"); - return; - } - - char obuf[IIBS]; - size_t isiz = iconv_cur; - char *ip = iconv_buffer; - while (isiz > 0) { - size_t osiz; - char *ocp; - - osiz = IIBS; - ocp = obuf; - errno = 0; - if(my_iconv(desc, &ip, &isiz, &ocp, &osiz) == (size_t)-1 && errno != E2BIG) { - if (errno == EINVAL) { - // Incomplete input sequence. Copy it to the - // beginning of the buffer and leave it around - // (more data probably coming) - // iconv leaves ip pointing at the - // beginning of the sequence. - int cnt = iconv_cur - (ip - iconv_buffer); -/* fprintf(stderr, "flush_iconv: incomp. input remain %d\n", cnt);*/ - memcpy(obuf, ip, cnt); - memcpy(iconv_buffer, obuf, cnt); - iconv_cur = cnt; - return; - } else { -/* fprintf(stderr, "flush_iconv: rem. %d errno %d\n", isiz, errno);*/ - iconv_cur = 0; - return; - } - } -/* fprintf(stderr, "flush_iconv: ok: isiz %d out %d errno %d\n", - isiz, IIBS - osiz, errno); */ - - -/* fwrite(obuf, 1, IIBS - osiz, stdout);*/ - char *out = op_translate_buffer(op, obuf, IIBS - osiz); - if (out == 0) { - iconv_cur = 0; - return; - } - fprintf(stdout, "%s", out); - my_free(out); - } - iconv_cur = 0; + /* fprintf(stderr, "flush_iconv_input: iconv_cur %d\n", iconv_cur);*/ + if (iconv_cur <= 0) + { + iconv_cur = 0; + return; + } + maybeopeniconv(); + if (!my_iconv_is_valid(desc)) + { + fprintf(stderr, "unrtf: flush: iconv not ready!\n"); + return; + } + + char obuf[IIBS]; + size_t isiz = iconv_cur; + char *ip = iconv_buffer; + while (isiz > 0) + { + size_t osiz; + char *ocp; + + osiz = IIBS; + ocp = obuf; + errno = 0; + if (my_iconv(desc, &ip, &isiz, &ocp, &osiz) == (size_t) - 1 && errno != E2BIG) + { + if (errno == EINVAL) + { + // Incomplete input sequence. Copy it to the + // beginning of the buffer and leave it around + // (more data probably coming) + // iconv leaves ip pointing at the + // beginning of the sequence. + int cnt = iconv_cur - (ip - iconv_buffer); + /* fprintf(stderr, "flush_iconv: incomp. input remain %d\n", cnt);*/ + memcpy(obuf, ip, cnt); + memcpy(iconv_buffer, obuf, cnt); + iconv_cur = cnt; + return; + } + else + { + /* fprintf(stderr, "flush_iconv: rem. %d errno %d\n", isiz, errno);*/ + iconv_cur = 0; + return; + } + } + /* fprintf(stderr, "flush_iconv: ok: isiz %d out %d errno %d\n", + isiz, IIBS - osiz, errno); */ + + + /* fwrite(obuf, 1, IIBS - osiz, stdout);*/ + char *out = op_translate_buffer(op, obuf, IIBS - osiz); + if (out == 0) + { + iconv_cur = 0; + return; + } + fprintf(stdout, "%s", out); + my_free(out); + } + iconv_cur = 0; } static void accumulate_iconv_input(int ch) { -/* fprintf(stderr, "accumulate_iconv_input: 0x%x\n", ch);*/ - if (iconv_cur >= IIBS-1) - flush_iconv_input(); - iconv_buffer[iconv_cur++] = ch; -} - -/*======================================================================== - * Name: + /* fprintf(stderr, "accumulate_iconv_input: 0x%x\n", ch);*/ + if (iconv_cur >= IIBS - 1) + { + flush_iconv_input(); + } + iconv_buffer[iconv_cur++] = ch; +} + +/*======================================================================== + * Name: * Purpose: Recursive routine to produce the output in the target * format given on a tree of words. * Args: Word* (the tree). @@ -3299,276 +4117,390 @@ *=======================================================================*/ static void -word_print_core (Word *w, int groupdepth) +word_print_core(Word *w, int groupdepth) { const char *s; const char *alias; - FILE *pictfile=NULL; - int is_cell_group=FALSE; - int paragraph_begined=FALSE; - int paragraph_align=ALIGN_LEFT; - - if (groupdepth > MAX_GROUP_DEPTH) { - warning_handler ("Max group depth reached"); + FILE *pictfile = NULL; + int is_cell_group = FALSE; + int paragraph_begined = FALSE; + int paragraph_align = ALIGN_LEFT; + + if (groupdepth > MAX_GROUP_DEPTH) + { + warning_handler("Max group depth reached"); return; - } + } CHECK_PARAM_NOT_NULL(w); //if (!coming_pars_that_are_tabular && within_table) { - //end_table(); + //end_table(); //} //else if (coming_pars_that_are_tabular && !within_table) { - //begin_table(); + //begin_table(); //} check_for_table(); /* Mark our place in the stack */ attrstack_push(); - while (w) { - - s = word_string (w); - // If we have hex data and we're getting out of the hex area - // flush it. - if (iconv_cur > 0 && s && strncmp(s, "\\'", 2)) - flush_iconv_input(); - - if (s) { + while (w) + { + + s = word_string(w); + // If we have hex data and we're getting out of the hex area + // flush it. + if (iconv_cur > 0 && s && strncmp(s, "\\'", 2)) + { + flush_iconv_input(); + } + + if (s) + { /*--Ignore whitespace in header--------------------*/ - if (*s==' ' && within_header) { + if (*s == ' ' && within_header) + { /* no op */ - } + } else - /*--Handle word -----------------------------------*/ - if (s[0] != '\\') - { - starting_body(); - starting_text(); - - if (!paragraph_begined) { - starting_paragraph_align (paragraph_align); - paragraph_begined=TRUE; - } - - /*----------------------------------------*/ - if (within_picture) + /*--Handle word -----------------------------------*/ + if (s[0] != '\\') { - if (within_picture_depth == 0) - within_picture_depth = groupdepth; starting_body(); - if (!pictfile && !nopict_mode) { - char *ext=NULL; - switch (picture_type) { - case PICT_WB: ext="bmp"; break; - case PICT_WM: ext="wmf"; break; - case PICT_MAC: ext="pict"; break; - case PICT_JPEG: ext="jpg"; break; - case PICT_PNG: ext="png"; break; - case PICT_DI: ext="dib"; break; /* Device independent bitmap=??? */ - case PICT_PM: ext="pmm"; break; /* OS/2 metafile=??? */ - case PICT_EMF: ext="emf"; break; /* Enhanced MetaFile */ + starting_text(); + + if (!paragraph_begined) + { + starting_paragraph_align(paragraph_align); + paragraph_begined = TRUE; + } + + /*----------------------------------------*/ + if (within_picture) + { + if (within_picture_depth == 0) + { + within_picture_depth = groupdepth; } - sprintf(picture_path, "pict%03d.%s", - picture_file_number++,ext); - pictfile=fopen(picture_path,"wb"); - } - - if (s[0]!=' ') { - const char *s2; - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("picture data found, "); - if (picture_wmetafile_type_str) { - printf("WMF type is %s, ", - picture_wmetafile_type_str); + starting_body(); + if (!pictfile && !nopict_mode) + { + char *ext = NULL; + switch (picture_type) + { + case PICT_WB: + ext = "bmp"; + break; + case PICT_WM: + ext = "wmf"; + break; + case PICT_MAC: + ext = "pict"; + break; + case PICT_JPEG: + ext = "jpg"; + break; + case PICT_PNG: + ext = "png"; + break; + case PICT_DI: + ext = "dib"; + break; /* Device independent bitmap=??? */ + case PICT_PM: + ext = "pmm"; + break; /* OS/2 metafile=??? */ + case PICT_EMF: + ext = "emf"; + break; /* Enhanced MetaFile */ + } + snprintf(picture_path, 255, "pict%03d.%s", + picture_file_number++, ext); + pictfile = fopen(picture_path, "wb"); } - printf("picture dimensions are %d by %d, depth %d", - picture_width, picture_height, picture_bits_per_pixel); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - if (picture_width && picture_height && picture_bits_per_pixel) { - s2=s; - /* Convert hex char pairs. Guard against odd byte count from garbled file */ - while (*s2 && *(s2+1)) { - unsigned int tmp,value; - tmp=tolower(*s2++); - if (tmp>'9') tmp-=('a'-10); - else tmp-='0'; - value=16*tmp; - tmp=tolower(*s2++); - if (tmp>'9') tmp-=('a'-10); - else tmp-='0'; - value+=tmp; - if (pictfile) { - fprintf(pictfile,"%c", value); + + if (s[0] != ' ') + { + const char *s2; + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("picture data found, "); + if (picture_wmetafile_type_str) + { + printf("WMF type is %s, ", + picture_wmetafile_type_str); + } + printf("picture dimensions are %d by %d, depth %d", + picture_width, picture_height, picture_bits_per_pixel); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + if (picture_width && picture_height && picture_bits_per_pixel) + { + s2 = s; + /* Convert hex char pairs. Guard against odd byte count from garbled file */ + while (*s2 && *(s2 + 1)) + { + unsigned int tmp, value; + tmp = tolower(*s2++); + if (tmp > '9') + { + tmp -= ('a' - 10); + } + else + { + tmp -= '0'; + } + value = 16 * tmp; + tmp = tolower(*s2++); + if (tmp > '9') + { + tmp -= ('a' - 10); + } + else + { + tmp -= '0'; + } + value += tmp; + if (pictfile) + { + fprintf(pictfile, "%c", value); + } } } } } + /*----------------------------------------*/ + else + { + total_chars_this_line += strlen(s); + + if (op->word_begin) + if (safe_printf(0, op->word_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "word_begin"); + } + + print_with_special_exprs(s); + + if (op->word_end) + if (safe_printf(0, op->word_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "word_end"); + } + } + + } - /*----------------------------------------*/ - else { - total_chars_this_line += strlen(s); - - if (op->word_begin) - if (safe_printf(0, op->word_begin)) fprintf(stderr, TOO_MANY_ARGS, "word_begin"); - - print_with_special_exprs (s); - - if (op->word_end) - if (safe_printf(0, op->word_end)) fprintf(stderr, TOO_MANY_ARGS, "word_end"); - } - - - } /* output an escaped backslash */ /* do we need special handling for latex? */ /* we do for troff where we want the string for 92 */ - else if (*(s+1) == '\\') - { - s++; - if ((alias = get_alias(op, 92)) != NULL) + else if (*(s + 1) == '\\') { - printf("%s", alias); + s++; + if ((alias = get_alias(op, 92)) != NULL) + { + printf("%s", alias); + } + else + { + putchar('\\'); + } } + else if (*(s + 1) == '{') + { + s++; + putchar('{'); + } + else if (*(s + 1) == '}') + { + s++; + putchar('}'); + } + /*---Handle RTF keywords---------------------------*/ else { - putchar('\\'); + s++; + /*----Paragraph alignment----------------------------------------------------*/ + if (!strcmp("ql", s)) + { + paragraph_align = ALIGN_LEFT; + } + else if (!strcmp("qr", s)) + { + paragraph_align = ALIGN_RIGHT; + } + else if (!strcmp("qj", s)) + { + paragraph_align = ALIGN_JUSTIFY; + } + else if (!strcmp("qc", s)) + { + paragraph_align = ALIGN_CENTER; + } + else if (!strcmp("pard", s)) + { + /* Clear out all font attributes. + */ + attr_pop_all(); + + if (coming_pars_that_are_tabular) + { + --coming_pars_that_are_tabular; + } + + /* Clear out all paragraph attributes. + */ + ending_paragraph_align(paragraph_align); + paragraph_align = ALIGN_LEFT; + paragraph_begined = FALSE; + } + /*----Table keywords---------------------------------------------------------*/ + else if (!strcmp(s, "cell")) + { + + is_cell_group = TRUE; + if (!have_printed_cell_begin) + { + /* Need this with empty cells */ + if (safe_printf(0, op->table_cell_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_cell_begin"); + } + attrstack_express_all(); + } + attr_pop_all(); + if (safe_printf(0, op->table_cell_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_cell_end"); + } + have_printed_cell_begin = FALSE; + have_printed_cell_end = TRUE; + } + else if (!strcmp(s, "row")) + { + + if (within_table) + { + if (safe_printf(0, op->table_row_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "table_row_end"); + } + have_printed_row_begin = FALSE; + have_printed_row_end = TRUE; + } + else + { + if (debug_mode) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("end of table row"); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } + } + } + + /*----Special chars---------------------------------------------------------*/ + else if (*s == '\'' && s[1] && s[2]) + { + /* \'XX is a hex char code expression */ + + int ch = h2toi(&s[1]); + accumulate_iconv_input(ch); + } + else + /*----Search the RTF command hash-------------------------------------------*/ + { + int have_param = FALSE, param = 0; + HashItem *hip = find_command(s, &have_param, ¶m); + if (hip) + { + int terminate_group; + + if (hip->func) + { + terminate_group = hip->func(w, paragraph_align, have_param, param); + /* daved - 0.19.4 - unicode support may need to skip only one word */ + if (terminate_group == SKIP_ONE_WORD) + { + w = w->next; + } + else if (terminate_group) + while (w) + { + w = w->next; + } + } + + if (hip->debug_print && debug_mode) + { + if (safe_printf(0, op->comment_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); + } + printf("%s", hip->debug_print); + if (safe_printf(0, op->comment_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "comment_end"); + } + } + + } + } } + /*-------------------------------------------------------------------------*/ + } + else + { + + Word *child; + + child = w->child; + + if (!paragraph_begined) + { + starting_paragraph_align(paragraph_align); + paragraph_begined = TRUE; } - else if (*(s+1) == '{') + + if (child) { - s++; - putchar('{'); + word_print_core(child, groupdepth + 1); } - else if (*(s+1) == '}') + } + + if (w) + { + w = w->next; + } + } + + if (within_picture && within_picture_depth == groupdepth) + { + within_picture_depth = 0; + if (pictfile) + { + fclose(pictfile); + if (safe_printf(0, op->imagelink_begin)) { - s++; - putchar('}'); + fprintf(stderr, TOO_MANY_ARGS, "imagelink_begin"); } - /*---Handle RTF keywords---------------------------*/ - else { - s++; -/*----Paragraph alignment----------------------------------------------------*/ - if (!strcmp ("ql", s)) - paragraph_align = ALIGN_LEFT; - else if (!strcmp ("qr", s)) - paragraph_align = ALIGN_RIGHT; - else if (!strcmp ("qj", s)) - paragraph_align = ALIGN_JUSTIFY; - else if (!strcmp ("qc", s)) - paragraph_align = ALIGN_CENTER; - else if (!strcmp ("pard", s)) - { - /* Clear out all font attributes. - */ - attr_pop_all(); - - if (coming_pars_that_are_tabular) { - --coming_pars_that_are_tabular; - } - - /* Clear out all paragraph attributes. - */ - ending_paragraph_align(paragraph_align); - paragraph_align = ALIGN_LEFT; - paragraph_begined = FALSE; - } -/*----Table keywords---------------------------------------------------------*/ - else - if (!strcmp (s, "cell")) { - - is_cell_group=TRUE; - if (!have_printed_cell_begin) { - /* Need this with empty cells */ - if (safe_printf(0, op->table_cell_begin)) fprintf(stderr, TOO_MANY_ARGS, "table_cell_begin"); - attrstack_express_all(); - } - attr_pop_dump(); - if (safe_printf(0, op->table_cell_end)) fprintf(stderr, TOO_MANY_ARGS, "table_cell_end"); - have_printed_cell_begin = FALSE; - have_printed_cell_end=TRUE; - } - else if (!strcmp (s, "row")) { - - if (within_table) { - if (safe_printf(0, op->table_row_end)) fprintf(stderr, TOO_MANY_ARGS, "table_row_end"); - have_printed_row_begin = FALSE; - have_printed_row_end=TRUE; - } else { - if (debug_mode) { - if (safe_printf(0, op->comment_begin)) fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("end of table row"); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - } - } - } - -/*----Special chars---------------------------------------------------------*/ - else if (*s == '\'' && s[1] && s[2]) { - /* \'XX is a hex char code expression */ - - int ch = h2toi (&s[1]); - accumulate_iconv_input(ch); - } - else -/*----Search the RTF command hash-------------------------------------------*/ - { - int have_param = FALSE, param = 0; - HashItem *hip = find_command(s, &have_param, ¶m); - if (hip) { - int terminate_group; - - if (hip->func) { - terminate_group = hip->func (w,paragraph_align, have_param, param); - /* daved - 0.19.4 - unicode support may need to skip only one word */ - if (terminate_group == SKIP_ONE_WORD) - w=w->next; - else - if (terminate_group) - while(w) w=w->next; - } - - if (hip->debug_print && debug_mode) { - if (safe_printf(0, op->comment_begin)) - fprintf(stderr, TOO_MANY_ARGS, "comment_begin"); - printf("%s", hip->debug_print); - if (safe_printf(0, op->comment_end)) fprintf(stderr, TOO_MANY_ARGS, "comment_end"); - } - - } - } + printf("%s", picture_path); + if (safe_printf(0, op->imagelink_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "imagelink_end"); } -/*-------------------------------------------------------------------------*/ - } else { - - Word *child; - - child = w->child; - - if (!paragraph_begined) { - starting_paragraph_align (paragraph_align); - paragraph_begined=TRUE; - } - - if (child) - word_print_core (child, groupdepth+1); - } - - if (w) - w = w->next; - } - - if (within_picture && within_picture_depth == groupdepth) - { - within_picture_depth = 0; - if(pictfile) - { - fclose(pictfile); - if (safe_printf(0, op->imagelink_begin)) fprintf(stderr, TOO_MANY_ARGS, "imagelink_begin"); - printf("%s", picture_path); - if (safe_printf(0, op->imagelink_end)) fprintf(stderr, TOO_MANY_ARGS, "imagelink_end"); - } - within_picture=FALSE; + } + within_picture = FALSE; } /* Undo font attributes UNLESS we're doing table cells @@ -3576,61 +4508,89 @@ */ if (!is_cell_group) + { attr_pop_all(); + } else + { attr_drop_all(); + } /* Undo paragraph alignment */ if (paragraph_begined) - ending_paragraph_align (paragraph_align); + { + ending_paragraph_align(paragraph_align); + } attrstack_drop(); - // Flush iconv input - flush_iconv_input(); - iconv_cur = 0; - - // If there is an encoding in the stacks, restore it, else - // restore default. - desc = my_iconv_close(desc); - char *encoding = attr_get_param(ATTR_ENCODING); - if (!encoding || !*encoding) - encoding = default_encoding; - desc = my_iconv_open(output_encoding, encoding); - set_current_encoding(encoding); -} - - -/*======================================================================== - * Name: - * Purpose: + // Flush iconv input + flush_iconv_input(); + iconv_cur = 0; + + // If there is an encoding in the stacks, restore it, else + // restore default. + desc = my_iconv_close(desc); + char *encoding = attr_get_param(ATTR_ENCODING); + if (!encoding || !*encoding) + { + encoding = default_encoding; + } + desc = my_iconv_open(output_encoding, encoding); + set_current_encoding(encoding); +} + + +/*======================================================================== + * Name: + * Purpose: * Args: None. * Returns: None. *=======================================================================*/ -void -word_print (Word *w) -{ - CHECK_PARAM_NOT_NULL (w); - - if (!inline_mode) { - if (safe_printf(0, op->document_begin)) fprintf(stderr, TOO_MANY_ARGS, "document_begin"); - if (safe_printf(0, op->header_begin)) fprintf(stderr, TOO_MANY_ARGS, "header_begin"); - if (safe_printf(0, op->utf8_encoding)) fprintf(stderr, TOO_MANY_ARGS, "utf8_encoding"); - } - - print_banner (); - - within_header=TRUE; - have_printed_body=FALSE; - within_table=FALSE; - simulate_allcaps=FALSE; - word_print_core (w, 1); +void +word_print(Word *w) +{ + CHECK_PARAM_NOT_NULL(w); + + if (!inline_mode) + { + if (safe_printf(0, op->document_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_begin"); + } + if (safe_printf(0, op->header_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "header_begin"); + } + if (safe_printf(0, op->utf8_encoding)) + { + fprintf(stderr, TOO_MANY_ARGS, "utf8_encoding"); + } + } + + if (!quiet) + { + print_banner(); + } + + within_header = TRUE; + have_printed_body = FALSE; + within_table = FALSE; + simulate_allcaps = FALSE; + word_print_core(w, 1); end_table(); - if (!inline_mode) { - if (safe_printf(0, op->body_end)) fprintf(stderr, TOO_MANY_ARGS, "body_end"); - if (safe_printf(0, op->document_end)) fprintf(stderr, TOO_MANY_ARGS, "document_end"); - } -} + if (!inline_mode) + { + if (safe_printf(0, op->body_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "body_end"); + } + if (safe_printf(0, op->document_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "document_end"); + } + } +} diff --git a/src/convert.h b/src/convert.h index 4710e87..ab68522 100644 --- a/src/convert.h +++ b/src/convert.h @@ -39,14 +39,15 @@ #include "word.h" -enum { - CHARSET_ANSI=1, +enum +{ + CHARSET_ANSI = 1, CHARSET_MAC, CHARSET_CP437, CHARSET_CP850, }; -extern void word_print (Word*); +extern void word_print(Word *); #define FONT_GREEK "cp1253" #define FONT_SYMBOL "SYMBOL" diff --git a/src/error.c b/src/error.c index 642d845..a625995 100644 --- a/src/error.c +++ b/src/error.c @@ -31,7 +31,7 @@ * 10 Oct 00, tuorfa@yahoo.com: added usage() * 15 Oct 00, tuorfa@yahoo.com: improved output readability * 22 Sep 01, tuorfa@yahoo.com: removed mention of line number in handlers - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 08 Oct 03, daved@physiol.usyd.edu.au: added stdlib.h for linux * 25 Sep 04, st001906@hrz1.hrz.tu-darmstadt.de: added stdlib.h for djgpp * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith @@ -64,7 +64,7 @@ *=======================================================================*/ void -usage () +usage() { fprintf(stderr, "Usage: %s\n", USAGE); exit(-3); @@ -80,7 +80,7 @@ *=======================================================================*/ void -error_handler (char* message) +error_handler(char *message) { #if 1 fprintf(stderr, "Error (line %d): %s\n", lineno, message); @@ -99,7 +99,7 @@ *=======================================================================*/ void -warning_handler (char* message) +warning_handler(char *message) { fprintf(stderr, "Warning: %s\n", message); } diff --git a/src/error.h b/src/error.h index 5271649..3236c69 100644 --- a/src/error.h +++ b/src/error.h @@ -43,8 +43,8 @@ extern void usage(void); -extern void error_handler (char*); -extern void warning_handler (char*); +extern void error_handler(char *); +extern void warning_handler(char *); diff --git a/src/hash.c b/src/hash.c index 8acd029..bb8e846 100644 --- a/src/hash.c +++ b/src/hash.c @@ -33,7 +33,7 @@ * 08 Apr 01, tuorfa@yahoo.com: check for out of memory after malloc. * 21 Apr 01, tuorfa@yahoo.com: signed to conversion unsigned bug * 03 Aug 01, tuorfa@yahoo.com: fixes for using 16-bit compiler - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 08 Oct 03, daved@physiol.usyd.edu.au: some type fixes * 29 Mar 05, daved@physiol.usyd.edu.au: changes requsted by ZT Smith * 06 Jan 06, marcossamaral@terra.com.br: changes hash_stats function @@ -62,7 +62,8 @@ #include "malloc.h" -typedef struct _hi { +typedef struct _hi +{ struct _hi *next; char str[1]; } HashItem; @@ -81,14 +82,16 @@ *=======================================================================*/ unsigned long -hash_stats () +hash_stats() { int i; - unsigned long total=0; + unsigned long total = 0; HashItem *hi; - for (i=0; i<256; i++) { + for (i = 0; i < 256; i++) + { hi = hash[i]; - while (hi) { + while (hi) + { total++; hi = hi->next; } @@ -106,16 +109,18 @@ *=======================================================================*/ static HashItem * -hashitem_new (char *str) +hashitem_new(char *str) { HashItem *hi; - /* We already have a char[1], so allocating strlen() does - yield space for the ending 0 */ - unsigned int l = sizeof(HashItem)+strlen(str); - hi=(HashItem*) my_malloc(l); + /* We already have a char[1], so allocating strlen() does + yield space for the ending 0 */ + unsigned int l = sizeof(HashItem) + strlen(str); + hi = (HashItem *) my_malloc(l); if (!hi) + { error_handler("Out of memory"); + } strcpy(hi->str, str); hi->next = NULL; @@ -132,17 +137,22 @@ *=======================================================================*/ const char * -hash_store (char *str) +hash_store(char *str) { - unsigned char ch = (unsigned char)*str; + unsigned char ch = (unsigned char) * str; HashItem *hi; - if (ch=='\\' && *(str+1)) - ch = *(str+1); + if (ch == '\\' && *(str + 1)) + { + ch = *(str + 1); + } hi = hash[ch]; - while (hi) { + while (hi) + { if (!strcmp(hi->str, str)) + { return hi->str; + } hi = hi->next; } /* not in hash */ diff --git a/src/hash.h b/src/hash.h index 02c0219..11cd100 100644 --- a/src/hash.h +++ b/src/hash.h @@ -34,15 +34,15 @@ *---------------------------------------------------------------------- * Changes: * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith - * 06 Jan 06, marcossamaral@terra.com.br: changes hash_stats() + * 06 Jan 06, marcossamaral@terra.com.br: changes hash_stats() * 16 Dec 07, daved@physiol.usyd.edu.au: updated to GPL v3 * 07 Oct 11, jf@dockes.org, added _HASH_H_INCLUDED_ * Further: see VCS log *--------------------------------------------------------------------*/ -extern unsigned long hash_stats (void); +extern unsigned long hash_stats(void); /* Store/find string, returns address of stored copy */ -extern const char *hash_store (char *); +extern const char *hash_store(char *); #endif /* _HASH_H_INCLUDED_ */ diff --git a/src/main.c b/src/main.c index ab5f51d..c7e298f 100644 --- a/src/main.c +++ b/src/main.c @@ -7,7 +7,7 @@ the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + 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. @@ -28,19 +28,19 @@ *---------------------------------------------------------------------- * Changes: * 14 Oct 00, tuorfa@yahoo.com: added -nopict option - * 15 Oct 00, tuorfa@yahoo.com: added verify_file_type() + * 15 Oct 00, tuorfa@yahoo.com: added verify_file_type() * 08 Apr 01, tuorfa@yahoo.com: more GNU-like switches implemented * 24 Jul 01, tuorfa@yahoo.com: removed verify_file_type() * 03 Aug 01, tuorfa@yahoo.com: added --inline switch * 08 Sep 01, tuorfa@yahoo.com: added use of UnRTF * 19 Sep 01, tuorfa@yahoo.com: addition of output personalities - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 23 Sep 01, tuorfa@yahoo.com: added wpml switch * 08 Oct 03, daved@physiol.usyd.edu.au: added stdlib.h for linux * 07 Jan 04, tuorfa@yahoo.com: removed broken PS support * 25 Sep 04, st001906@hrz1.hrz.tu-darmstadt.de: added stdlib.h for djgpp * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith - * 06 Jan 06, marcossamaral@terra.com.br: includes verbose mode + * 06 Jan 06, marcossamaral@terra.com.br: includes verbose mode * 16 Dec 07, daved@physiol.usyd.edu.au: updated to GPL v3 * 17 Dec 07, daved@physiol.usyd.edu.au: support for --noremap from * David Santinoli @@ -69,7 +69,9 @@ #include #endif +#ifdef HAVE_UNISTD_H #include +#endif #include "defs.h" #include "error.h" @@ -112,21 +114,21 @@ OutputPersonality * get_config(char *name, OutputPersonality *op) { - char *configfile = 0; - if(!path_checked && check_dirs() == 0) - { - fprintf(stderr,"No config directories. Searched: %s\n", search_path); - exit(1); - } - configfile = search_in_path(name, "conf"); - if (configfile == NULL) - { - fprintf(stderr, "failed to find %s.conf in search path dirs\n", name); - exit(1); - } - op = user_init(op, configfile); - free(configfile); - return op; + char *configfile = 0; + if (!path_checked && check_dirs() == 0) + { + fprintf(stderr, "No config directories. Searched: %s\n", search_path); + exit(1); + } + configfile = search_in_path(name, "conf"); + if (configfile == NULL) + { + fprintf(stderr, "failed to find %s.conf in search path dirs\n", name); + exit(1); + } + op = user_init(op, configfile); + free(configfile); + return op; } /*======================================================================== @@ -137,35 +139,59 @@ *=======================================================================*/ int -main (int argc, char **argv) +main(int argc, char **argv) { FILE *f; - Word * word; + Word *word; char *path = NULL; - char *env_path_p = '\0'; + char *env_path_p = NULL; int i; - nopict_mode = debug_mode = dump_mode = inline_mode = no_remap_mode = FALSE; + nopict_mode = debug_mode = dump_mode = inline_mode = no_remap_mode = quiet = FALSE; /* initialize search path to compiled-in value */ search_path = DEFAULT_UNRTF_SEARCH_PATH; - if((env_path_p = getenv("UNRTF_SEARCH_PATH")) != NULL) - { - if(verbose_mode) + if ((env_path_p = getenv("UNRTF_SEARCH_PATH")) != NULL) + { + if (verbose_mode) + { fprintf(stderr, "got environment path: %s\n", env_path_p); - search_path=env_path_p; + } + search_path = env_path_p; } /* Handle arguments */ - for (i = 1; i < argc; i++) { - if (!strcmp("--dump", argv[i])) dump_mode = TRUE; - else if (!strcmp("-d", argv[i])) dump_mode = TRUE; - else if (!strcmp("--debug", argv[i])) debug_mode = TRUE; - else if (!strcmp("--verbose", argv[i])) verbose_mode = TRUE; - else if (!strcmp("--quiet", argv[i])) quiet = TRUE; - else if (!strcmp("--simple", argv[i])) simple_mode = TRUE; - else if (!strcmp("--noremap", argv[i])) no_remap_mode = TRUE; + for (i = 1; i < argc; i++) + { + if (!strcmp("--dump", argv[i])) + { + dump_mode = TRUE; + } + else if (!strcmp("-d", argv[i])) + { + dump_mode = TRUE; + } + else if (!strcmp("--debug", argv[i])) + { + debug_mode = TRUE; + } + else if (!strcmp("--verbose", argv[i])) + { + verbose_mode = TRUE; + } + else if (!strcmp("--quiet", argv[i])) + { + quiet = TRUE; + } + else if (!strcmp("--simple", argv[i])) + { + simple_mode = TRUE; + } + else if (!strcmp("--noremap", argv[i])) + { + no_remap_mode = TRUE; + } else if (!strcmp("-t", argv[i])) { if ((i + 1) < argc && *argv[i + 1] != '-') @@ -173,54 +199,81 @@ i++; op = get_config(argv[i], op); } - } + } else if (!strcmp("-P", argv[i])) { - if(i+1 > argc) - { - fprintf(stderr,"-P needs a path argument\n"); + if (i + 1 > argc) + { + fprintf(stderr, "-P needs a path argument\n"); exit(1); } - search_path=argv[++i]; - } - else if (!strcmp("--inline", argv[i])) inline_mode = TRUE; - else if (!strcmp("--help", argv[i])) { + search_path = argv[++i]; + } + else if (!strcmp("--inline", argv[i])) + { + inline_mode = TRUE; + } + else if (!strcmp("--help", argv[i])) + { usage(); } - else if (!strcmp("--version", argv[i])) { + else if (!strcmp("--version", argv[i])) + { fprintf(stderr, "%s\n", PACKAGE_VERSION); fprintf(stderr, "search path is: %s\n", search_path); exit(0); } - else if (!strcmp("--nopict", argv[i])) nopict_mode = TRUE; - else if (!strcmp("-n", argv[i])) nopict_mode = TRUE; + else if (!strcmp("--nopict", argv[i])) + { + nopict_mode = TRUE; + } + else if (!strcmp("-n", argv[i])) + { + nopict_mode = TRUE; + } else if (!strncmp("--", argv[i], 2)) + { op = get_config(&argv[i][2], op); + } else { - if (*argv[i] == '-') usage(); - - if (path) + if (*argv[i] == '-') + { usage(); - else + } + + if (path) + { + usage(); + } + else + { path = argv[i]; + } } } if (op == NULL) + { op = get_config(DEFAULT_OUTPUT, op); - if(!path_checked && check_dirs() == 0) - { - fprintf(stderr,"no config directories\n"); + } + if (op == NULL) { + fprintf(stderr, "Initialization error: no output format\n"); exit(1); } - - - + if (!path_checked && check_dirs() == 0) + { + fprintf(stderr, "no config directories\n"); + exit(1); + } + + + /* Program information */ - if (verbose_mode || debug_mode) { + if (verbose_mode || debug_mode) + { fprintf(stderr, "This is UnRTF "); fprintf(stderr, "version %s\n", PACKAGE_VERSION); fprintf(stderr, "By Dave Davey, Marcos Serrou do Amaral and Arkadiusz Firus\n"); @@ -228,26 +281,40 @@ show_dirs(); } - if (debug_mode) fprintf(stderr, "Debug mode.\n"); - if (dump_mode) fprintf(stderr, "Dump mode.\n"); + if (debug_mode) + { + fprintf(stderr, "Debug mode.\n"); + } + if (dump_mode) + { + fprintf(stderr, "Dump mode.\n"); + } /* Open file for reading. Append ".rtf" to file name if not supplied. */ if (path == NULL) + { f = stdin; + } else { f = fopen(path, "r"); - if (!f) { + if (!f) + { char path2[200]; strcpy(path2, path); strcat(path2, ".rtf"); f = fopen(path2, "r"); if (!f) + { error_handler("Cannot open input file"); - } - } - - if (verbose_mode || debug_mode) fprintf(stderr, "Processing %s...\n", path); + } + } + } + + if (verbose_mode || debug_mode) + { + fprintf(stderr, "Processing %s...\n", path); + } /* Keep track of lines processed. This is arbitrary to the user as * RTF ignores newlines. May be helpful in error tracking. */ @@ -257,11 +324,14 @@ * the end of the file. */ word = word_read(f); - if (dump_mode) { + if (dump_mode) + { word_dump(word); printf("\n"); - } else { -/* Should we also optimize word before dump? - AF */ + } + else + { + /* Should we also optimize word before dump? - AF */ word = optimize_word(word, 1); word_print(word); } @@ -269,16 +339,18 @@ fclose(f); /* marcossamaral - 0.19.9 */ - if(verbose_mode || debug_mode) { - unsigned long total=0; + if (verbose_mode || debug_mode) + { + unsigned long total = 0; total = hash_stats(); fprintf(stderr, "Done.\n"); - fprintf(stderr, "%lu words were hashed.\n", total); - } - - if (debug_mode) { - fprintf(stderr, "Total memory allocated %ld bytes.\n", - total_malloced()); + fprintf(stderr, "%lu words were hashed.\n", total); + } + + if (debug_mode) + { + fprintf(stderr, "Total memory allocated %ld bytes.\n", + total_malloced()); } /* May as well */ diff --git a/src/malloc.c b/src/malloc.c index ea4dcb3..1bca97a 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -30,7 +30,7 @@ * Changes: * 14 Aug 01, tuorfa@yahoo.com: added Turbo C support. * 16 Aug 01, Lars Unger : added Amiga/GCC support. - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 28 Sep 01, tuorfa@yahoo.com: removed Turbo C support. * 08 Oct 03, daved@physiol.usyd.edu.au: added stdlib.h for linux * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith @@ -57,7 +57,7 @@ #include "error.h" #include "malloc.h" -static unsigned long count=0; +static unsigned long count = 0; /*======================================================================== * Name: my_malloc @@ -66,13 +66,16 @@ * Returns: Pointer. *=======================================================================*/ -char * -my_malloc (unsigned long size) { +char * +my_malloc(unsigned long size) +{ char *ptr; - ptr = malloc (size); + ptr = malloc(size); if (ptr) + { count += size; + } return ptr; } @@ -84,11 +87,12 @@ * Returns: None. *=======================================================================*/ -void -my_free (char* ptr) { +void +my_free(char *ptr) +{ CHECK_PARAM_NOT_NULL(ptr); - free (ptr); + free(ptr); } #if 1 /* AK3 - AF */ @@ -104,7 +108,9 @@ char *new_ptr = my_malloc(new_size); if (new_ptr != NULL) + { memcpy(new_ptr, ptr, old_size); + } my_free(ptr); @@ -120,8 +126,9 @@ * Returns: Amount. *=======================================================================*/ -unsigned long -total_malloced (void) { +unsigned long +total_malloced(void) +{ return count; } @@ -135,33 +142,41 @@ *=======================================================================*/ char * -my_strdup (char *src) { +my_strdup(char *src) +{ unsigned long len; char *ptr; CHECK_PARAM_NOT_NULL(src); len = strlen(src); - ptr = my_malloc (len+1); + ptr = my_malloc(len + 1); if (!ptr) - error_handler ("out of memory in strdup()"); + { + error_handler("out of memory in strdup()"); + } - strcpy (ptr, src); + strcpy(ptr, src); return ptr; } + +#ifndef _WIN32 /* added by daved */ #include #undef malloc - -void *malloc (); - + +void *malloc(); + /* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */ void * -rpl_malloc (size_t n) -{ - if (n == 0) - n = 1; -return malloc (n); -} +rpl_malloc(size_t n) +{ + if (n == 0) + { + n = 1; + } + return malloc(n); +} +#endif \ No newline at end of file diff --git a/src/malloc.h b/src/malloc.h index c2e92f1..df24241 100644 --- a/src/malloc.h +++ b/src/malloc.h @@ -32,9 +32,9 @@ * 09 Nov 08, arkadiusz.firus@gmail.com: added my_realloc *--------------------------------------------------------------------*/ -extern char * my_malloc (unsigned long); -extern void my_free (char*); -extern char * my_realloc(char*, unsigned long, unsigned long); -extern unsigned long total_malloced (void); -extern char * my_strdup (char*); +extern char *my_malloc(unsigned long); +extern void my_free(char *); +extern char *my_realloc(char *, unsigned long, unsigned long); +extern unsigned long total_malloced(void); +extern char *my_strdup(char *); diff --git a/src/my_iconv.c b/src/my_iconv.c index 678ee6f..d030ba6 100644 --- a/src/my_iconv.c +++ b/src/my_iconv.c @@ -12,7 +12,9 @@ #include #include +#ifndef _WIN32 #include +#endif #include #include @@ -24,8 +26,8 @@ extern int verbose_mode; -/* Convert from charmap file entry to charmap table one. - 1st byte in table entry is code length +/* Convert from charmap file entry to charmap table one. + 1st byte in table entry is code length */ static char * get_code_str(FILE *f, iconv_t desc) @@ -35,26 +37,35 @@ char *obuf; char *utf8 = get_unicode_utf8(f); - if (utf8 == NULL || *utf8 == 0) { + if (utf8 == NULL || *utf8 == 0) + { /* fprintf(stderr, "get_code_str: NULL entry\n");*/ + my_free(utf8); return NULL; } - #if 0 /* debug */ +#if 0 /* debug */ fprintf(stderr, "get_code_str: utf8: "); for (ocp = utf8; *ocp; ocp++) - fprintf(stderr, "%x", (unsigned)*ocp); + { + fprintf(stderr, "%x", (unsigned)*ocp); + } fprintf(stderr, "\n"); - #endif +#endif obytes = 10; ibytes = strlen(utf8); obuf = malloc(obytes); if (obuf == NULL) + { + my_free(utf8); return NULL; + } icp = utf8; ocp0 = ocp = obuf + 1; - if (iconv(desc, &icp, &ibytes, &ocp, &obytes) == -1) { + if (iconv(desc, &icp, &ibytes, &ocp, &obytes) == -1) + { /* fprintf(stderr, "unrtf: my_iconv: iconv error\n");*/ + my_free(utf8); return NULL; } @@ -70,38 +81,46 @@ FILE *f; my_iconv_t cd = MY_ICONV_T_CLEAR; int c, i; -/* fprintf(stderr, "my_iconv_open: from %s to %s\n", fromcode, tocode);*/ - if ((cd.desc = iconv_open(tocode, fromcode)) == (iconv_t) -1) { - char *path = search_in_path(fromcode, "charmap"); - if (path == NULL) { - return cd; - } - if((f = fopen(path, "r")) == NULL && verbose_mode) - fprintf(stderr, "failed to open charmap file %s\n", path); - - if (f != NULL) { - /* Open iconv utf8->tocode conversion */ - iconv_t desc; - if ((desc = iconv_open(tocode, "UTF-8")) == (iconv_t) -1) { - fclose(f); - return cd; - } - cd.char_table = (char **)my_malloc(char_table_size * - sizeof(char *)); - c = fgetc(f); - - for (i = 0; i < char_table_size && c != EOF; i++) - { - if (c == '<') - cd.char_table[i] = get_code_str(f, desc); - leave_line(f);//read up to including \n or eof - c = fgetc(f); - } - iconv_close(desc); - fclose(f); - } - - my_free(path); + /* fprintf(stderr, "my_iconv_open: from %s to %s\n", fromcode, tocode);*/ + if ((cd.desc = iconv_open(tocode, fromcode)) == (iconv_t) - 1) + { + char *path = search_in_path(fromcode, "charmap"); + if (path == NULL) + { + return cd; + } + if ((f = fopen(path, "r")) == NULL && verbose_mode) + { + fprintf(stderr, "failed to open charmap file %s\n", path); + } + + if (f != NULL) + { + /* Open iconv utf8->tocode conversion */ + iconv_t desc; + if ((desc = iconv_open(tocode, "UTF-8")) == (iconv_t) - 1) + { + fclose(f); + return cd; + } + cd.char_table = (char **)my_malloc(char_table_size * + sizeof(char *)); + c = fgetc(f); + + for (i = 0; i < char_table_size && c != EOF; i++) + { + if (c == '<') + { + cd.char_table[i] = get_code_str(f, desc); + } + leave_line(f);//read up to including \n or eof + c = fgetc(f); + } + iconv_close(desc); + fclose(f); + } + + my_free(path); } return cd; @@ -113,40 +132,46 @@ int c, i; size_t result = 0; **outbuf = 0; - if (cd.desc == (iconv_t) -1) { - if (cd.char_table != NULL) - { - while (*inbytesleft > 0 && *outbytesleft > 0) - { - c = **(unsigned char**)inbuf; - if (cd.char_table[c] != NULL) - { - for (i = 0; i < cd.char_table[c][0] && *outbytesleft > 0; i++) + if (cd.desc == (iconv_t) - 1) + { + if (cd.char_table != NULL) + { + while (*inbytesleft > 0 && *outbytesleft > 0) + { + c = **(unsigned char **)inbuf; + if (cd.char_table[c] != NULL) { - **outbuf = cd.char_table[c][i+1]; - (*outbytesleft)--; - (*outbuf)++; + for (i = 0; i < cd.char_table[c][0] && *outbytesleft > 0; i++) + { + **outbuf = cd.char_table[c][i + 1]; + (*outbytesleft)--; + (*outbuf)++; + } } - } else { - /* fprintf(stderr, "my_iconv: no conversion for 0x%x\n", - (unsigned)c);*/ - errno = EILSEQ; - return (size_t)-1; - } - - (*inbuf)++; - (*inbytesleft)--; - result++; - } - - if (*outbytesleft == 0 && *inbytesleft > 0) { - errno = E2BIG; - result = (size_t)-1; - } - } + else + { + /* fprintf(stderr, "my_iconv: no conversion for 0x%x\n", + (unsigned)c);*/ + errno = EILSEQ; + return (size_t) - 1; + } + + (*inbuf)++; + (*inbytesleft)--; + result++; + } + + if (*outbytesleft == 0 && *inbytesleft > 0) + { + errno = E2BIG; + result = (size_t) - 1; + } + } } else + { result = iconv(cd.desc, inbuf, inbytesleft, outbuf, outbytesleft); + } return result; } @@ -160,28 +185,32 @@ { for (i = 0; i < char_table_size; i++) { - if (cd.char_table[i] != NULL) - my_free(cd.char_table[i]); + if (cd.char_table[i] != NULL) + { + my_free(cd.char_table[i]); + } } my_free((void *)cd.char_table); cd.char_table = NULL; } - if (cd.desc != (iconv_t) -1) + if (cd.desc != (iconv_t) - 1) { iconv_close(cd.desc); - cd.desc = (iconv_t) -1; + cd.desc = (iconv_t) - 1; } return cd; } -int -my_iconv_is_valid (my_iconv_t cd) -{ - if (cd.desc != (iconv_t) -1 || cd.char_table != NULL) +int +my_iconv_is_valid(my_iconv_t cd) +{ + if (cd.desc != (iconv_t) - 1 || cd.char_table != NULL) + { return 1; + } return 0; } @@ -189,7 +218,7 @@ void my_iconv_t_make_invalid(my_iconv_t *cd) { - cd->desc = (iconv_t) -1; + cd->desc = (iconv_t) - 1; cd->char_table = NULL; } diff --git a/src/output.c b/src/output.c index 86d8b5c..8b71de7 100644 --- a/src/output.c +++ b/src/output.c @@ -28,11 +28,11 @@ *---------------------------------------------------------------------- * Changes: * 22 Sep 01, tuorfa@yahoo.com: addition of functions to change font size - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 08 Oct 03, daved@physiol.usyd.edu.au: added stdlib.h for linux * 25 Sep 04, st001906@hrz1.hrz.tu-darmstadt.de: added stdlib.h for djgpp * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith - * 06 Jan 06, marcossamaral@terra.com.br: changes in STDOUT + * 06 Jan 06, marcossamaral@terra.com.br: changes in STDOUT * 16 Dec 07, daved@physiol.usyd.edu.au: updated to GPL v3 * 17 Dec 07, daved@physiol.usyd.edu.au: added support for --noremap from * David Santinoli @@ -58,7 +58,9 @@ #include #endif +#ifndef _WIN32 #include +#endif #include "malloc.h" #include "defs.h" @@ -76,16 +78,18 @@ * Returns: Output personality struct. *=======================================================================*/ -OutputPersonality* -op_create () +OutputPersonality * +op_create() { - OutputPersonality* new_op; - - new_op = (OutputPersonality*) my_malloc (sizeof(OutputPersonality)); + OutputPersonality *new_op; + + new_op = (OutputPersonality *) my_malloc(sizeof(OutputPersonality)); if (!new_op) - error_handler ("cannot allocate output personality"); - - memset ((void*) new_op, 0, sizeof (OutputPersonality)); + { + error_handler("cannot allocate output personality"); + } + + memset((void *) new_op, 0, sizeof(OutputPersonality)); return new_op; } @@ -98,11 +102,11 @@ *=======================================================================*/ void -op_free (OutputPersonality *op) +op_free(OutputPersonality *op) { CHECK_PARAM_NOT_NULL(op); - my_free ((void*) op); + my_free((void *) op); } @@ -114,140 +118,183 @@ * computation of Symbol code point in fields). * We cache a local iconv descriptor for efficiency. * Args: OutputPersonality, encoding, character. - * Returns: String. + * Returns: malloced string to be freed by caller. *=======================================================================*/ const char * -op_translate_char (OutputPersonality *op, char *encoding, int ch) +op_translate_char(OutputPersonality *op, char *encoding, int ch) { - static my_iconv_t m_desc = MY_ICONV_T_CLEAR; - static char *m_encoding = NULL; - const char *result = NULL; - static char output_buffer[2]={ 0, 0 }; - - CHECK_PARAM_NOT_NULL(op); - - if (ch < 0 || ch > 255) { - fprintf(stderr, "op_translate_char called with bad char 0x%x\n", - ch); - return NULL; - } - if (no_remap_mode == TRUE && ch < 256) { - /* Kept for historical reason, makes no sense in a multi-encoding - document */ - output_buffer[0] = ch; - result = output_buffer; - } else { - if (!m_encoding || strcasecmp(encoding, m_encoding)) { - // Using UTF-32BE to avoid BOM - if (my_iconv_is_valid(m_desc)) - my_iconv_close(m_desc); - m_desc = my_iconv_open("UTF-32BE", encoding); - if (!my_iconv_is_valid(m_desc)) { - return NULL; - } - if (m_encoding) - my_free(m_encoding); - m_encoding = my_strdup(encoding); - } - size_t inbytes = 1, outbytes = 4; - char inbuf[1]; - uint32_t outbuf; - char *icp = inbuf, *ocp = (char*)&outbuf; - int unicode; - inbuf[0] = ch; - - if (my_iconv(m_desc, &icp, &inbytes, &ocp, &outbytes) == -1) - { -/* fprintf(stderr, "unrtf: iconv error %s->UTF-32BE for 0x%x\n", - encoding, ch);*/ - return NULL; - } - - /* Conversion from UTF-32BE string to int */ - unicode = ntohl(outbuf); + static my_iconv_t m_desc = MY_ICONV_T_CLEAR; + static char *m_encoding = NULL; + char *result = NULL; + + CHECK_PARAM_NOT_NULL(op); + + if (ch < 0 || ch > 255) + { + fprintf(stderr, "op_translate_char called with bad char 0x%x\n", + ch); + return NULL; + } + if (no_remap_mode == TRUE && ch < 256) + { + /* Kept for historical reason, makes no sense in a multi-encoding + document */ + result = my_malloc(2); + if (result) + { + result[0] = ch; + result[1] = 0; + } + } + else + { + if (!m_encoding || strcasecmp(encoding, m_encoding)) + { + // Using UTF-32BE to avoid BOM + if (my_iconv_is_valid(m_desc)) + { + my_iconv_close(m_desc); + } + m_desc = my_iconv_open("UTF-32BE", encoding); + if (!my_iconv_is_valid(m_desc)) + { + return NULL; + } + if (m_encoding) + { + my_free(m_encoding); + } + m_encoding = my_strdup(encoding); + } + size_t inbytes = 1, outbytes = 4; + char inbuf[1]; + uint32_t outbuf; + char *icp = inbuf, *ocp = (char *)&outbuf; + int unicode; + inbuf[0] = ch; + + if (my_iconv(m_desc, &icp, &inbytes, &ocp, &outbytes) == -1) + { + /* fprintf(stderr, "unrtf: iconv error %s->UTF-32BE for 0x%x\n", + encoding, ch);*/ + return NULL; + } + + /* Conversion from UTF-32BE string to int */ +#ifdef _WIN32 + unicode = unrtf_ntohl(outbuf); +#else + unicode = ntohl(outbuf); +#endif #if 0 - if (unicode != ch) - fprintf(stderr, "op_translate: 0x%x -> unicode 0x%x\n", - (unsigned)ch, (unsigned)unicode); -#endif - /* Output Unicode value as decided by output personality */ - result = get_alias(op, unicode); /* Try for ie, entity */ - if (result == NULL) { - if (ch > 127 && op->unisymbol_print) { - /* TODO: memory leak here. Impossible to fix easily as we can - return either a static or allocated buffer */ - result = assemble_string(op->unisymbol_print, unicode); - } else { - /* Single byte unicode char needs no translation ever?*/ - output_buffer[0] = ch; - result = output_buffer; - } - } - } - - return result; + if (unicode != ch) + fprintf(stderr, "op_translate: 0x%x -> unicode 0x%x\n", + (unsigned)ch, (unsigned)unicode); +#endif + /* Output Unicode value as decided by output personality */ + result = get_alias(op, unicode); /* Try for ie, entity */ + if (result) + result = strdup(result); + if (result == NULL) + { + if (ch > 127 && op->unisymbol_print) + { + result = assemble_string(op->unisymbol_print, unicode); + } + else + { + /* Single byte unicode char needs no translation ever?*/ + result = my_malloc(2); + if (result) + { + result[0] = ch; + result[1] = 0; + } + } + } + } + + return result; } /*======================================================================== * Name: op_translate_buffer * Purpose: Translate buffer built out of \' commands in convert.c - * The data comes in as UTF-32BE, which we change to unicode positions + * The data comes in as UTF-32BE, which we change to unicode positions * (just the byte order), then transform according to outputpersonality * TOBEDONE: have a way to specify direct UTF-8 output for a personality * (then produce utf-8 in convert.c and do nothing special here. - * + * * Args: OutputPersonality, encoding, character. * Returns: malloced string. *=======================================================================*/ char * op_translate_buffer(OutputPersonality *op, char *buffer, int bytescnt) { - int wordcnt = bytescnt / 4; - int i; - int opos = 0; - char *out = 0; - int outsz; - if ((out = (char *)allocmem(out, 1, &outsz, 1000, 100000)) == NULL) { - fprintf(stderr, "unrtf: out of memory (op_translate_buffer 1, %d)\n", outsz); - return NULL; - } - - for (i = 0; i < wordcnt; i++) { - char tbuf[2]; - const char *result; - int incsz; - int unicode = ntohl(*(int*)(buffer + 4 * i)); - - result = get_alias(op, unicode); /* Try for ie, entity */ - if (result != NULL) { - incsz = strlen(result); - } else { - if (unicode > 127 && op->unisymbol_print) { - /* TODO: fix memory leak */ - result = assemble_string(op->unisymbol_print, unicode); - incsz = strlen(result); - } else { - /* Single byte unicode char needs no translation ever?*/ - tbuf[0] = unicode; - tbuf[1] = 0; - result = tbuf; - incsz = 1; - } - } - if (opos + incsz + 1 >= outsz) { - if ((out = (char *)allocmem(out, 1, &outsz, 1000, 100000)) == NULL) { - fprintf(stderr, "unrtf: out of memory (op_translate_buffer 2, %d)\n", outsz); - return NULL; - } - } - strcpy(out + opos, result); - opos += incsz; - } - return out; + int wordcnt = bytescnt / 4; + int i; + int opos = 0; + char *out = 0; + int outsz; + if ((out = (char *)allocmem(out, 1, &outsz, 1000, 100000)) == NULL) + { + fprintf(stderr, "unrtf: out of memory (op_translate_buffer 1, %d)\n", outsz); + return NULL; + } + out[0] = 0; + + for (i = 0; i < wordcnt; i++) + { + char tbuf[2]; + const char *result; + int freeresult = 0; + int incsz; +#ifdef _WIN32 + int unicode = unrtf_ntohl(*(int *)(buffer + 4 * i)); +#else + int unicode = ntohl(*(int *)(buffer + 4 * i)); +#endif + + result = get_alias(op, unicode); /* Try for ie, entity */ + if (result != NULL) + { + incsz = strlen(result); + } + else + { + if (unicode > 127 && op->unisymbol_print) + { + result = assemble_string(op->unisymbol_print, unicode); + freeresult = 1; + incsz = strlen(result); + } + else + { + /* Single byte unicode char needs no translation ever?*/ + tbuf[0] = unicode; + tbuf[1] = 0; + result = tbuf; + incsz = 1; + } + } + if (opos + incsz + 1 >= outsz) + { + if ((out = (char *)allocmem(out, 1, &outsz, 1000, 100000)) == NULL) + { + fprintf(stderr, "unrtf: out of memory (op_translate_buffer 2, %d)\n", outsz); + return NULL; + } + } + strcpy(out + opos, result); + if (freeresult) + my_free(result); + opos += incsz; + } + return out; } /*======================================================================== - * Name: op_begin_std_fontsize + * Name: op_begin_std_fontsize * Purpose: Prints whatever is necessary to perform a change in the * current font size. * Args: OutputPersonality, desired size. @@ -255,7 +302,7 @@ *=======================================================================*/ void -op_begin_std_fontsize (OutputPersonality *op, int size) +op_begin_std_fontsize(OutputPersonality *op, int size) { int found_std_expr = FALSE; @@ -263,52 +310,85 @@ /* Look for an exact match with a standard point size. */ - switch (size) { + switch (size) + { case 8: - if (op->fontsize8_begin) { - if (safe_printf(0, op->fontsize8_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize8_begin"); + if (op->fontsize8_begin) + { + if (safe_printf(0, op->fontsize8_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize8_begin"); + } found_std_expr = TRUE; } break; case 10: - if (op->fontsize10_begin) { - if (safe_printf(0, op->fontsize10_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize10_begin"); + if (op->fontsize10_begin) + { + if (safe_printf(0, op->fontsize10_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize10_begin"); + } found_std_expr = TRUE; } break; case 12: - if (op->fontsize12_begin) { - if (safe_printf(0, op->fontsize12_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize12_begin"); + if (op->fontsize12_begin) + { + if (safe_printf(0, op->fontsize12_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize12_begin"); + } found_std_expr = TRUE; } break; case 14: - if (op->fontsize14_begin) { - if (safe_printf(0, op->fontsize14_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize14_begin"); + if (op->fontsize14_begin) + { + if (safe_printf(0, op->fontsize14_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize14_begin"); + } found_std_expr = TRUE; } break; case 18: - if (op->fontsize18_begin) { - if (safe_printf(0, op->fontsize18_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize18_begin"); + if (op->fontsize18_begin) + { + if (safe_printf(0, op->fontsize18_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize18_begin"); + } found_std_expr = TRUE; } break; case 24: - if (op->fontsize24_begin) { - if (safe_printf(0, op->fontsize24_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize24_begin"); + if (op->fontsize24_begin) + { + if (safe_printf(0, op->fontsize24_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize24_begin"); + } found_std_expr = TRUE; } break; case 36: - if (op->fontsize36_begin) { - if (safe_printf(0, op->fontsize36_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize36_begin"); + if (op->fontsize36_begin) + { + if (safe_printf(0, op->fontsize36_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize36_begin"); + } found_std_expr = TRUE; } break; case 48: - if (op->fontsize48_begin) { - if (safe_printf(0, op->fontsize48_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize48_begin"); + if (op->fontsize48_begin) + { + if (safe_printf(0, op->fontsize48_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize48_begin"); + } found_std_expr = TRUE; } break; @@ -317,48 +397,122 @@ /* If no exact match, try to write out a change to the * exact point size. */ - if (!found_std_expr) { - if (op->fontsize_begin) { + if (!found_std_expr) + { + if (op->fontsize_begin) + { char expr[16]; - sprintf (expr, "%d", size); - if (safe_printf (1, op->fontsize_begin, expr)) fprintf(stderr, TOO_MANY_ARGS, "fontsize_begin"); - } else { + snprintf(expr, 16, "%d", size); + if (safe_printf(1, op->fontsize_begin, expr)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize_begin"); + } + } + else + { /* If we cannot write out a change for the exact * point size, we must approximate to a standard * size. */ - if (size<9 && op->fontsize8_begin) { - if (safe_printf(0, op->fontsize8_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize8_begin"); - } else if (size<11 && op->fontsize10_begin) { - if (safe_printf(0, op->fontsize10_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize10_begin"); - } else if (size<13 && op->fontsize12_begin) { - if (safe_printf(0, op->fontsize12_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize12_begin"); - } else if (size<16 && op->fontsize14_begin) { - if (safe_printf(0, op->fontsize14_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize14_begin"); - } else if (size<21 && op->fontsize18_begin) { - if (safe_printf(0, op->fontsize18_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize18_begin"); - } else if (size<30 && op->fontsize24_begin) { - if (safe_printf(0, op->fontsize24_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize24_begin"); - } else if (size<42 && op->fontsize36_begin) { - if (safe_printf(0, op->fontsize36_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize36_begin"); - } else if (size>40 && op->fontsize48_begin) { - if (safe_printf(0, op->fontsize48_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize48_begin"); - } else { + if (size < 9 && op->fontsize8_begin) + { + if (safe_printf(0, op->fontsize8_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize8_begin"); + } + } + else if (size < 11 && op->fontsize10_begin) + { + if (safe_printf(0, op->fontsize10_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize10_begin"); + } + } + else if (size < 13 && op->fontsize12_begin) + { + if (safe_printf(0, op->fontsize12_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize12_begin"); + } + } + else if (size < 16 && op->fontsize14_begin) + { + if (safe_printf(0, op->fontsize14_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize14_begin"); + } + } + else if (size < 21 && op->fontsize18_begin) + { + if (safe_printf(0, op->fontsize18_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize18_begin"); + } + } + else if (size < 30 && op->fontsize24_begin) + { + if (safe_printf(0, op->fontsize24_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize24_begin"); + } + } + else if (size < 42 && op->fontsize36_begin) + { + if (safe_printf(0, op->fontsize36_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize36_begin"); + } + } + else if (size > 40 && op->fontsize48_begin) + { + if (safe_printf(0, op->fontsize48_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize48_begin"); + } + } + else + { /* If we can't even produce a good approximation, * just try to get a font size near 12 point. */ - if (op->fontsize12_begin) { - if (safe_printf(0, op->fontsize12_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize12_begin"); - } else if (op->fontsize14_begin) { - if (safe_printf(0, op->fontsize14_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize14_begin"); - } else if (op->fontsize10_begin) { - if (safe_printf(0, op->fontsize10_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize10_begin"); - } else if (op->fontsize18_begin) { - if (safe_printf(0, op->fontsize18_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize18_begin"); - } else if (op->fontsize8_begin) { - if (safe_printf(0, op->fontsize8_begin)) fprintf(stderr, TOO_MANY_ARGS, "fontsize8_begin"); - } else { - error_handler ("output personality lacks sufficient font size change capability"); + if (op->fontsize12_begin) + { + if (safe_printf(0, op->fontsize12_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize12_begin"); + } + } + else if (op->fontsize14_begin) + { + if (safe_printf(0, op->fontsize14_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize14_begin"); + } + } + else if (op->fontsize10_begin) + { + if (safe_printf(0, op->fontsize10_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize10_begin"); + } + } + else if (op->fontsize18_begin) + { + if (safe_printf(0, op->fontsize18_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize18_begin"); + } + } + else if (op->fontsize8_begin) + { + if (safe_printf(0, op->fontsize8_begin)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize8_begin"); + } + } + else + { + error_handler("output personality lacks sufficient font size change capability"); } } } @@ -367,7 +521,7 @@ /*======================================================================== - * Name: op_end_std_fontsize + * Name: op_end_std_fontsize * Purpose: Prints whatever is necessary to perform a change in the * current font size. * Args: OutputPersonality, desired size. @@ -375,7 +529,7 @@ *=======================================================================*/ void -op_end_std_fontsize (OutputPersonality *op, int size) +op_end_std_fontsize(OutputPersonality *op, int size) { int found_std_expr = FALSE; @@ -383,52 +537,85 @@ /* Look for an exact match with a standard point size. */ - switch (size) { + switch (size) + { case 8: - if (op->fontsize8_end) { - if (safe_printf(0, op->fontsize8_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize8_end"); + if (op->fontsize8_end) + { + if (safe_printf(0, op->fontsize8_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize8_end"); + } found_std_expr = TRUE; } break; case 10: - if (op->fontsize10_end) { - if (safe_printf(0, op->fontsize10_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize10_end"); + if (op->fontsize10_end) + { + if (safe_printf(0, op->fontsize10_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize10_end"); + } found_std_expr = TRUE; } break; case 12: - if (op->fontsize12_end) { - if (safe_printf(0, op->fontsize12_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize12_end"); + if (op->fontsize12_end) + { + if (safe_printf(0, op->fontsize12_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize12_end"); + } found_std_expr = TRUE; } break; case 14: - if (op->fontsize14_end) { - if (safe_printf(0, op->fontsize14_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize14_end"); + if (op->fontsize14_end) + { + if (safe_printf(0, op->fontsize14_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize14_end"); + } found_std_expr = TRUE; } break; case 18: - if (op->fontsize18_end) { - if (safe_printf(0, op->fontsize18_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize18_end"); + if (op->fontsize18_end) + { + if (safe_printf(0, op->fontsize18_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize18_end"); + } found_std_expr = TRUE; } break; case 24: - if (op->fontsize24_end) { - if (safe_printf(0, op->fontsize24_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize24_end"); + if (op->fontsize24_end) + { + if (safe_printf(0, op->fontsize24_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize24_end"); + } found_std_expr = TRUE; } break; case 36: - if (op->fontsize36_end) { - if (safe_printf(0, op->fontsize36_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize36_end"); + if (op->fontsize36_end) + { + if (safe_printf(0, op->fontsize36_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize36_end"); + } found_std_expr = TRUE; } break; case 48: - if (op->fontsize48_end) { - if (safe_printf(0, op->fontsize48_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize48_end"); + if (op->fontsize48_end) + { + if (safe_printf(0, op->fontsize48_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize48_end"); + } found_std_expr = TRUE; } break; @@ -437,55 +624,122 @@ /* If no exact match, try to write out a change to the * exact point size. */ - if (!found_std_expr) { - if (op->fontsize_end) { + if (!found_std_expr) + { + if (op->fontsize_end) + { char expr[16]; - sprintf (expr, "%d", size); - if (safe_printf(1, op->fontsize_end, expr)) fprintf(stderr, TOO_MANY_ARGS, "fontsize_end"); - } else { + snprintf(expr, 16, "%d", size); + if (safe_printf(1, op->fontsize_end, expr)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize_end"); + } + } + else + { /* If we cannot write out a change for the exact * point size, we must approximate to a standard * size. */ - if (size<9 && op->fontsize8_end) { - if (safe_printf(0, op->fontsize8_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize8_end"); - } else - if (size<11 && op->fontsize10_end) { - if (safe_printf(0, op->fontsize10_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize10_end"); - } else - if (size<13 && op->fontsize12_end) { - if (safe_printf(0, op->fontsize12_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize12_end"); - } else - if (size<16 && op->fontsize14_end) { - if (safe_printf(0, op->fontsize14_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize14_end"); - } else - if (size<21 && op->fontsize18_end) { - if (safe_printf(0, op->fontsize18_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize18_end"); - } else - if (size<30 && op->fontsize24_end) { - if (safe_printf(0, op->fontsize24_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize24_end"); - } else - if (size<42 && op->fontsize36_end) { - if (safe_printf(0, op->fontsize36_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize36_end"); - } else - if (size>40 && op->fontsize48_end) { - if (safe_printf(0, op->fontsize48_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize48_end"); - } else { - /* If we can't even produce a good approximation, - * just try to get a font size near 12 point. - */ - if (op->fontsize12_end) { - if (safe_printf(0, op->fontsize12_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize12_end"); - } else if (op->fontsize14_end) { - if (safe_printf(0, op->fontsize14_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize14_end"); - } else if (op->fontsize10_end) { - if (safe_printf(0, op->fontsize10_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize10_end"); - } else if (op->fontsize18_end) { - if (safe_printf(0, op->fontsize18_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize18_end"); - } else if (op->fontsize8_end) { - if (safe_printf(0, op->fontsize8_end)) fprintf(stderr, TOO_MANY_ARGS, "fontsize8_end"); - } else { - error_handler ("output personality lacks sufficient font size change capability"); + if (size < 9 && op->fontsize8_end) + { + if (safe_printf(0, op->fontsize8_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize8_end"); + } + } + else if (size < 11 && op->fontsize10_end) + { + if (safe_printf(0, op->fontsize10_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize10_end"); + } + } + else if (size < 13 && op->fontsize12_end) + { + if (safe_printf(0, op->fontsize12_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize12_end"); + } + } + else if (size < 16 && op->fontsize14_end) + { + if (safe_printf(0, op->fontsize14_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize14_end"); + } + } + else if (size < 21 && op->fontsize18_end) + { + if (safe_printf(0, op->fontsize18_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize18_end"); + } + } + else if (size < 30 && op->fontsize24_end) + { + if (safe_printf(0, op->fontsize24_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize24_end"); + } + } + else if (size < 42 && op->fontsize36_end) + { + if (safe_printf(0, op->fontsize36_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize36_end"); + } + } + else if (size > 40 && op->fontsize48_end) + { + if (safe_printf(0, op->fontsize48_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize48_end"); + } + } + else + { + /* If we can't even produce a good approximation, + * just try to get a font size near 12 point. + */ + if (op->fontsize12_end) + { + if (safe_printf(0, op->fontsize12_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize12_end"); + } + } + else if (op->fontsize14_end) + { + if (safe_printf(0, op->fontsize14_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize14_end"); + } + } + else if (op->fontsize10_end) + { + if (safe_printf(0, op->fontsize10_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize10_end"); + } + } + else if (op->fontsize18_end) + { + if (safe_printf(0, op->fontsize18_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize18_end"); + } + } + else if (op->fontsize8_end) + { + if (safe_printf(0, op->fontsize8_end)) + { + fprintf(stderr, TOO_MANY_ARGS, "fontsize8_end"); + } + } + else + { + error_handler("output personality lacks sufficient font size change capability"); } } } diff --git a/src/output.h b/src/output.h index ff8184d..811e156 100644 --- a/src/output.h +++ b/src/output.h @@ -42,7 +42,8 @@ typedef Collection Aliases; -typedef struct { +typedef struct +{ char *comment_begin; char *comment_end; @@ -183,6 +184,9 @@ char *outline_begin; char *outline_end; + + char *all_caps_begin; + char *all_caps_end; char *small_caps_begin; char *small_caps_end; @@ -216,7 +220,8 @@ /* XX These should really be replaced by references * to one of the charsets. */ - struct { + struct + { char *bullet; char *left_quote; char *right_quote; @@ -244,14 +249,14 @@ OutputPersonality; -extern OutputPersonality* op_create(void); -extern void op_free (OutputPersonality*); -extern const char *op_translate_char (OutputPersonality *op, char *encoding, int ch); -extern char *op_translate_buffer(OutputPersonality *op, char *buffer, +extern OutputPersonality *op_create(void); +extern void op_free(OutputPersonality *); +extern const char *op_translate_char(OutputPersonality *op, char *encoding, int ch); +extern char *op_translate_buffer(OutputPersonality *op, char *buffer, int bytescnt); -extern void op_begin_std_fontsize (OutputPersonality*, int); -extern void op_end_std_fontsize (OutputPersonality*, int); +extern void op_begin_std_fontsize(OutputPersonality *, int); +extern void op_end_std_fontsize(OutputPersonality *, int); void add_alias(OutputPersonality *op, int nr, char *text); const char *get_alias(OutputPersonality *op, int nr); diff --git a/src/parse.c b/src/parse.c index f6bdbd6..82b4de3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -33,7 +33,7 @@ * 03 Aug 01, tuorfa@yahoo.com: added input buffering * 19 Sep 01, tuorfa@yahoo.com: cleaned up read_word() * 22 Sep 01, tuorfa@yahoo.com: moved word_dump() to word.c - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 08 Sep 03, daved@physiol.usyd.edu.au: type fixes; ANSI C fixes * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith * 16 Dec 07, daved@physiol.usyd.edu.au: updated to GPL v3 @@ -82,10 +82,12 @@ * Returns: None. *=======================================================================*/ -static void my_unget_char (int ch) +static void my_unget_char(int ch) { - if (ungot_char>=0 && ungot_char2>=0 && ungot_char3>=0) + if (ungot_char >= 0 && ungot_char2 >= 0 && ungot_char3 >= 0) + { error_handler("More than 3 ungot chars"); + } ungot_char3 = ungot_char2; ungot_char2 = ungot_char; @@ -93,7 +95,7 @@ } -static int last_returned_ch=0; +static int last_returned_ch = 0; #define READ_BUF_LEN 2048 @@ -113,64 +115,78 @@ * Returns: Character, or EOF. *=======================================================================*/ -static int my_getchar (FILE* f) +static int my_getchar(FILE *f) { int ch; CHECK_PARAM_NOT_NULL(f); - if (ungot_char>=0) { - ch = ungot_char; - ungot_char = ungot_char2; + if (ungot_char >= 0) + { + ch = ungot_char; + ungot_char = ungot_char2; ungot_char2 = ungot_char3; ungot_char3 = -1; last_returned_ch = ch; - if(ch > 255) + if (ch > 255) { fprintf(stderr, "returning bad ch = '%c' (0%o)\n", - ch, ch); + ch, ch); } return ch; } - do { - if (read_buf_index >= read_buf_end) { - if (!read_buf) { + do + { + if (read_buf_index >= read_buf_end) + { + if (!read_buf) + { buffer_size = READ_BUF_LEN; - read_buf = my_malloc (buffer_size); - if (!read_buf) { + read_buf = my_malloc(buffer_size); + if (!read_buf) + { buffer_size /= 4; - read_buf = my_malloc (buffer_size); - if (!read_buf) + read_buf = my_malloc(buffer_size); + if (!read_buf) + { error_handler("Cannot allocate read buffer"); + } } } - read_buf_end = fread (read_buf, 1, buffer_size, f); + read_buf_end = fread(read_buf, 1, buffer_size, f); read_buf_index = 0; if (!read_buf_end) + { return EOF; + } } ch = read_buf [read_buf_index++]; - if (ch=='\n') { + if (ch == '\n') + { lineno++; /* Convert \(newline) into \par here */ - if (last_returned_ch=='\\') { - my_unget_char (' '); - my_unget_char ('r'); - my_unget_char ('a'); + if (last_returned_ch == '\\') + { + my_unget_char(' '); + my_unget_char('r'); + my_unget_char('a'); ch = 'p'; break; } } - } - while (ch=='\r' /* || ch=='\n' */ ); - - if (ch=='\t') ch = ' '; + } + while (ch == '\r' /* || ch=='\n' */); + + if (ch == '\t') + { + ch = ' '; + } last_returned_ch = ch; - if(ch > 255) - { - fprintf(stderr,"returning bad ch '%c' (0%o)\n", ch, ch); + if (ch > 255) + { + fprintf(stderr, "returning bad ch '%c' (0%o)\n", ch, ch); exit(1); } return ch; @@ -184,7 +200,7 @@ * Returns: None. *=======================================================================*/ -static void my_skip (FILE *f, long n) +static void my_skip(FILE *f, long n) { n += read_buf_index; if (n >= 0 && n < read_buf_end) @@ -194,7 +210,9 @@ } read_buf_end = read_buf_index = 0; if (fseek(f, n - read_buf_end, SEEK_CUR)) + { error_handler("Cannot seek"); + } return; } @@ -213,19 +231,23 @@ *=======================================================================*/ static int -expand_word_buffer () +expand_word_buffer() { char *new_ptr; unsigned long old_length; if (!input_str) + { error_handler("No input buffer allocated"); + } old_length = current_max_length; current_max_length *= 2; - new_ptr = my_malloc (current_max_length); + new_ptr = my_malloc(current_max_length); if (!new_ptr) + { error_handler("Out of memory while resizing buffer"); - - memcpy (new_ptr, input_str, old_length); + } + + memcpy(new_ptr, input_str, old_length); my_free(input_str); input_str = new_ptr; return TRUE; @@ -242,50 +264,57 @@ * Note: The word buffer is static and local to this file. *=======================================================================*/ -static int -read_word (FILE *f) +static int +read_word(FILE *f) { int ch, ch2; - unsigned long ix=0; - int have_whitespace=FALSE; - int is_control_word=FALSE; - int has_numeric_param=FALSE; /* if is_control_word==TRUE */ - int need_unget=FALSE; + unsigned long ix = 0; + int have_whitespace = FALSE; + int is_control_word = FALSE; + int has_numeric_param = FALSE; /* if is_control_word==TRUE */ + int need_unget = FALSE; CHECK_PARAM_NOT_NULL(f); - current_max_length = 10; /* XX */ - - /* Get some storage for a word. - */ - input_str = my_malloc (current_max_length); - if (!input_str) - error_handler("Cannot allocate word storage"); - - do { + if (input_str == NULL) + { + /* Get some storage for a word. + */ + current_max_length = 10; /* XX */ + input_str = my_malloc(current_max_length); + if (!input_str) + { + error_handler("Cannot allocate word storage"); + } + } + + do + { ch = my_getchar(f); - } - while (ch=='\n'); - - if (ch==' ') + } + while (ch == '\n'); + + if (ch == ' ') { /* Compress multiple space chars down to one. */ - while (ch == ' ') { + while (ch == ' ') + { ch = my_getchar(f); - have_whitespace=TRUE; - } - if (have_whitespace) { - my_unget_char (ch); - input_str[0]=' '; - input_str[1]=0; + have_whitespace = TRUE; + } + if (have_whitespace) + { + my_unget_char(ch); + input_str[0] = ' '; + input_str[1] = 0; return 1; } } - switch(ch) - { - case EOF: + switch (ch) + { + case EOF: return 0; case '\\': @@ -293,10 +322,10 @@ /* Look for two-character command words. */ - switch (ch2) + switch (ch2) { case '\n': - strcpy (input_str, "\\par"); + strcpy(input_str, "\\par"); return 4; case '~': case '{': @@ -311,75 +340,90 @@ case '\'': /* Preserve \'## expressions (hex char exprs) for later. */ - input_str[0]='\\'; - input_str[1]='\''; - ix=2; - if(ix==current_max_length) { - if (!expand_word_buffer ()) + input_str[0] = '\\'; + input_str[1] = '\''; + ix = 2; + if (ix == current_max_length) + { + if (!expand_word_buffer()) + { error_handler("Word too long"); + } } ch = my_getchar(f); - input_str[ix++]=ch; - if(ix==current_max_length) { - if (!expand_word_buffer ()) + input_str[ix++] = ch; + if (ix == current_max_length) + { + if (!expand_word_buffer()) + { error_handler("Word too long"); + } } ch = my_getchar(f); - input_str[ix++]=ch; - if(ix==current_max_length) { - if (!expand_word_buffer ()) + input_str[ix++] = ch; + if (ix == current_max_length) + { + if (!expand_word_buffer()) + { error_handler("Word too long"); - } - input_str[ix]=0; + } + } + input_str[ix] = 0; return ix; } - is_control_word=TRUE; - ix=1; - input_str[0]=ch; - ch=ch2; + is_control_word = TRUE; + ix = 1; + input_str[0] = ch; + ch = ch2; break; case '\t': /* In RTF, a tab char is the same as \tab. */ - strcpy (input_str, "\\tab"); + strcpy(input_str, "\\tab"); return 4; case '{': case '}': case ';': - input_str[0]=ch; - input_str[1]=0; + input_str[0] = ch; + input_str[1] = 0; return 1; } - while (ch!=EOF) + while (ch != EOF) { /* Several chars always ends a word, and we need to save them. */ - if (ch=='\t' || ch=='{' || ch=='}' || ch=='\\') { - need_unget=TRUE; + if (ch == '\t' || ch == '{' || ch == '}' || ch == '\\') + { + need_unget = TRUE; break; } - /* A newline always ends a command word; we don't save it. + /* A newline always ends a command word; we don't save it. * A newline is ignored if this is not a command word. */ - if (ch=='\n') { - if (is_control_word) + if (ch == '\n') + { + if (is_control_word) + { break; - ch = my_getchar(f); - continue; - } - - /* A semicolon always ends a command word; we do save it. + } + ch = my_getchar(f); + continue; + } + + /* A semicolon always ends a command word; we do save it. * A semicolon never ends a regular word. */ - if (ch==';') { - if (is_control_word) { - need_unget=TRUE; + if (ch == ';') + { + if (is_control_word) + { + need_unget = TRUE; break; } } @@ -388,40 +432,55 @@ * any word, and if it does not follow a command, * then it is a word in itself. */ - if (ch==' ') { + if (ch == ' ') + { if (!is_control_word) - need_unget=TRUE; + { + need_unget = TRUE; + } break; } /* Identify a control word's numeric parameter. */ - if (is_control_word) { - if (!has_numeric_param && (isdigit(ch) || ch=='-')) + if (is_control_word) + { + if (!has_numeric_param && (isdigit(ch) || ch == '-')) + { has_numeric_param = TRUE; - else - if (has_numeric_param && !isdigit(ch)) { - if (ch!=' ') - need_unget=TRUE; + } + else if (has_numeric_param && !isdigit(ch)) + { + if (ch != ' ') + { + need_unget = TRUE; + } break; } } - + input_str[ix++] = ch; - if (ix==current_max_length) { - if (!expand_word_buffer ()) + if (ix == current_max_length) + { + if (!expand_word_buffer()) + { error_handler("Word too long"); - } - ch = my_getchar (f); + } + } + ch = my_getchar(f); } if (need_unget) + { my_unget_char(ch); - - input_str[ix]=0; + } + + input_str[ix] = 0; if (!memcmp(input_str, "\\bin", 4) && isdigit(input_str[4])) + { my_skip(f, atoi(input_str + 4)); + } return ix; } @@ -430,51 +489,67 @@ /*======================================================================== * Name: word_read - * Purpose: This is the recursive metareader which pieces together the + * Purpose: This is the recursive metareader which pieces together the * structure of Word objects. * Args: Input file. * Returns: Tree of Word objects. *=======================================================================*/ Word * -word_read (FILE* f) { - Word * prev_word = NULL; - Word * first_word = NULL; - Word * new_word = NULL; /* temp */ +word_read(FILE *f) +{ + Word *prev_word = NULL; + Word *first_word = NULL; + Word *new_word = NULL; /* temp */ CHECK_PARAM_NOT_NULL(f); - do { + do + { if (!read_word(f)) + { return first_word; - - if (input_str[0] == '{') { + } + + if (input_str[0] == '{') + { /* Process subwords */ /* Create a dummy word to point to a sublist */ new_word = word_new(NULL); if (!new_word) + { error_handler("Cannot allocate word"); + } /* Get the sublist */ new_word->child = word_read(f); - } else if (input_str[0] == '}') { + } + else if (input_str[0] == '}') + { return first_word; - } else { + } + else + { new_word = word_new(input_str); } if (prev_word) + { prev_word->next = new_word; + } if (!first_word) + { first_word = new_word; + } prev_word = new_word; /* Free up the memory allocated by read_word. */ my_free(input_str); input_str = NULL; - } while (1); + } + while (1); } diff --git a/src/parse.h b/src/parse.h index 911675e..6cb8c9d 100644 --- a/src/parse.h +++ b/src/parse.h @@ -39,7 +39,7 @@ #include "word.h" #include -extern Word *word_read(FILE*); +extern Word *word_read(FILE *); #endif /* _PARSE_H_INCLUDED_ */ diff --git a/src/path.c b/src/path.c index d2713b6..2c082ec 100644 --- a/src/path.c +++ b/src/path.c @@ -1,6 +1,15 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include +#ifdef HAVE_UNISTD_H #include +#else +#include "safeunistd.h" +#endif + #include #include "path.h" @@ -14,101 +23,126 @@ char *search_in_path(const char *name, char *suffix) { - int maxplen = 0; - int l; - char *fullname = 0; - char *path = 0; - struct path_dir *path_dir_p; + int maxplen = 0; + int l; + char *fullname = 0; + char *path = 0; + struct path_dir *path_dir_p; - if (n_path_dirs == 0) { - fprintf(stderr,"no directories to search for %s\n", name); + if (n_path_dirs == 0) + { + fprintf(stderr, "no directories to search for %s\n", name); + return NULL; + } + l = strlen(name) + (suffix ? strlen(suffix) : 0) + 2; + if ((fullname = my_malloc(l)) == NULL) + { + fprintf(stderr, "Out of memory\n"); + return NULL; + } + strcpy(fullname, name); + if (suffix && *suffix && suffix[0] != '.') + { + strcat(fullname, "."); + } + if (suffix && *suffix) + { + strcat(fullname, suffix); + } + maxplen = 0; + + for (path_dir_p = &topdir; path_dir_p->dir_name; + path_dir_p = path_dir_p->next) + { + l = strlen(path_dir_p->dir_name); + if (maxplen < l) + { + maxplen = l; + } + } + maxplen += strlen(fullname) + 2; /* final 0 + possible '/' */ + if ((path = my_malloc(maxplen)) == NULL) + { + fprintf(stderr, "Out of memory\n"); + return NULL; + } + + for (path_dir_p = &topdir; path_dir_p->dir_name; + path_dir_p = path_dir_p->next) + { + + strcpy(path, path_dir_p->dir_name); + + if (path[strlen(path) - 1] != '/') + { + strcat(path, "/"); + } + strcat(path, fullname); + /* fprintf(stderr, "Testing for [%s]\n", path); */ + if (access(path, F_OK | R_OK)) + { + continue; + } + my_free(fullname); + return path; + } + my_free(fullname); + my_free(path); return NULL; - } - l = strlen(name) + (suffix?strlen(suffix):0) + 2; - if ((fullname = my_malloc(l)) == NULL) { - fprintf(stderr, "Out of memory\n"); - return NULL; - } - strcpy(fullname, name); - if (suffix && *suffix && suffix[0] != '.') - strcat(fullname, "."); - if (suffix && *suffix) - strcat(fullname, suffix); - maxplen = 0; - - for(path_dir_p = &topdir; path_dir_p->dir_name; - path_dir_p = path_dir_p->next) { - l = strlen(path_dir_p->dir_name); - if (maxplen < l) - maxplen = l; - } - maxplen += strlen(fullname) + 2; /* final 0 + possible '/' */ - if ((path = my_malloc(maxplen)) == NULL) { - fprintf(stderr, "Out of memory\n"); - return NULL; - } - - for (path_dir_p = &topdir; path_dir_p->dir_name; - path_dir_p = path_dir_p->next) { - - strcpy(path, path_dir_p->dir_name); - - if(path[strlen(path)-1] != '/') - strcat(path, "/"); - strcat(path, fullname); - /* fprintf(stderr, "Testing for [%s]\n", path); */ - if(access(path, F_OK|R_OK)) - continue; - my_free(fullname); - return path; - } - my_free(fullname); - my_free(path); - return NULL; } int check_dirs() { - char *p; - char *colon; - char *dir_name; - struct path_dir *path_dir_p = &topdir; + char *p; + char *colon; + char *dir_name; + struct path_dir *path_dir_p = &topdir; - /*fprintf(stderr, "check_dirs: search_path: [%s]\n", search_path);*/ + /*fprintf(stderr, "check_dirs: search_path: [%s]\n", search_path);*/ - for (p = search_path; *p != '\0';) { - dir_name = p; - if((colon = strchr(p, ':')) != NULL) { - p = colon; - *p++ = '\0'; - } else - p += strlen(p); + for (p = search_path; *p != '\0';) + { + dir_name = p; + if ((colon = strchr(p, ':')) != NULL) + { + p = colon; + *p++ = '\0'; + } + else + { + p += strlen(p); + } - if(access(dir_name, R_OK|X_OK)) - continue; - path_dir_p->dir_name = dir_name; - if((path_dir_p->next = (struct path_dir *)malloc(sizeof(struct path_dir))) == NULL) - { - fprintf(stderr,"Out of memory\n"); - exit(1); - } - path_dir_p = path_dir_p->next; - path_dir_p->dir_name = 0; - n_path_dirs++; - } - path_checked = 1; - return(n_path_dirs); + if (access(dir_name, R_OK | X_OK)) + { + continue; + } + path_dir_p->dir_name = dir_name; + if ((path_dir_p->next = (struct path_dir *)malloc(sizeof(struct path_dir))) == NULL) + { + fprintf(stderr, "Out of memory\n"); + exit(1); + } + path_dir_p = path_dir_p->next; + path_dir_p->dir_name = 0; + n_path_dirs++; + } + path_checked = 1; + return (n_path_dirs); } void show_dirs() { - struct path_dir *path_dir_p; - if(n_path_dirs == 0) { - fprintf(stderr,"no directories to show\n"); - exit(1); - } - fprintf(stderr,"show_dirs: %d directories\n", n_path_dirs); - for(path_dir_p = &topdir; path_dir_p->dir_name; - path_dir_p = path_dir_p->next) - fprintf(stderr,"directory = %s\n", path_dir_p->dir_name); + struct path_dir *path_dir_p; + if (n_path_dirs == 0) + { + fprintf(stderr, "no directories to show\n"); + exit(1); + } + fprintf(stderr, "show_dirs: %d directories\n", n_path_dirs); + for (path_dir_p = &topdir; path_dir_p->dir_name; + path_dir_p = path_dir_p->next) + { + fprintf(stderr, "directory = %s\n", path_dir_p->dir_name); + } } diff --git a/src/path.h b/src/path.h index 3cccf00..447c534 100644 --- a/src/path.h +++ b/src/path.h @@ -1,15 +1,17 @@ #ifndef _PATH_H_INCLUDED_ #define _PATH_H_INCLUDED_ +#ifndef DEFAULT_UNRTF_SEARCH_PATH #define DEFAULT_UNRTF_SEARCH_PATH CONFIG_DIR +#endif extern char *search_path; extern int path_checked; struct path_dir { - char *dir_name; - struct path_dir *next; + char *dir_name; + struct path_dir *next; }; extern int check_dirs(); diff --git a/src/unicode.c b/src/unicode.c index 3ec5228..534aba3 100644 --- a/src/unicode.c +++ b/src/unicode.c @@ -27,11 +27,13 @@ int get_unicode(char *string) { - unsigned long uc; - if (string[0] == 'U' || string[0] == 'u') - string++; - uc = strtoul(string, 0, 16); - return uc; + unsigned long uc; + if (string[0] == 'U' || string[0] == 'u') + { + string++; + } + uc = strtoul(string, 0, 16); + return uc; } /*======================================================================== @@ -43,7 +45,7 @@ char * unicode_to_utf8(unsigned int uc) { - unsigned char *string = NULL; + unsigned char *string = NULL; if (uc < 0x7f) { string = (unsigned char *)my_malloc(2 * sizeof(char)); @@ -52,14 +54,14 @@ } else if (uc < 0x7ff) { - string = (unsigned char *)my_malloc(3 * sizeof(char)); + string = (unsigned char *)my_malloc(3 * sizeof(char)); string[0] = (unsigned char) 192 + (uc / 64); string[1] = (unsigned char) 128 + (uc % 64); string[2] = '\0'; } else if (uc < 0xffff) { - string = (unsigned char *)my_malloc(4 * sizeof(char)); + string = (unsigned char *)my_malloc(4 * sizeof(char)); string[0] = (unsigned char) 224 + (uc / (64 * 64)); string[1] = (unsigned char) 128 + ((uc / 64) % 64); string[2] = (unsigned char) 128 + (uc % 64); @@ -67,7 +69,7 @@ } else if (uc < 0x1FFFFF) { - string = (unsigned char *)my_malloc(5 * sizeof(char)); + string = (unsigned char *)my_malloc(5 * sizeof(char)); string[0] = (unsigned char) 240 + (uc / (64 * 64 * 64)); string[1] = (unsigned char) 128 + ((uc / (64 * 64)) % 64); string[2] = (unsigned char) 128 + ((uc / 64) % 64); @@ -76,7 +78,7 @@ } else if (uc < 0x3FFFFFF) { - string = (unsigned char *)my_malloc(6 * sizeof(char)); + string = (unsigned char *)my_malloc(6 * sizeof(char)); string[0] = (unsigned char) 248 + (uc / (64 * 64 * 64 * 64)); string[1] = (unsigned char) 128 + ((uc / (64 * 64 * 64)) % 64); string[2] = (unsigned char) 128 + ((uc / (64 * 64)) % 64); @@ -86,7 +88,7 @@ } else if (uc < 0x7FFFFFFF) { - string = (unsigned char *)my_malloc(7 * sizeof(char)); + string = (unsigned char *)my_malloc(7 * sizeof(char)); string[0] = (unsigned char) 252 + (uc / (64 * 64 * 64 * 64 * 64)); string[1] = (unsigned char) 128 + ((uc / (64 * 64 * 64 * 64)) % 64); string[2] = (unsigned char) 128 + ((uc / (64 * 64 * 64)) % 64); @@ -102,18 +104,21 @@ /*======================================================================== * Name get_unicode_int * Purpose: Reads unicode character (in format and translates - it to printable unicode character. + it to printable unicode character. We are reading from our charmaps, + not from the rtf file. * Caution: This function should be executed after char '<' was read. It reads until char '>' was found or EOL or EOF. * Args: File to read from. - * Returns: Unicode character encoded in UTF-8 + * Returns: integer Unicode code point *=======================================================================*/ int get_unicode_int(FILE *file) { - int allocated = 5, len = 0; - char c, *unicode_number = my_malloc(allocated * sizeof(char)); +#define MAX_CHARMAP_UC_LEN 20 + char unicode_number[MAX_CHARMAP_UC_LEN]; + int len = 0; + char c; c = fgetc(file); @@ -123,15 +128,17 @@ c = fgetc(file); len++; - if (len == allocated) + if (len == MAX_CHARMAP_UC_LEN-1) { - allocated *= 2; - unicode_number = my_realloc(unicode_number, allocated / 2, allocated); + fprintf(stderr, "Buffer overflow in get_unicode_int\n"); + return 0; } } if (c != '>') + { ungetc(c, file); + } unicode_number[len] = '\0'; return get_unicode(unicode_number); @@ -140,6 +147,6 @@ char * get_unicode_utf8(FILE *file) { - int uc = get_unicode_int(file); - return unicode_to_utf8(uc); + int uc = get_unicode_int(file); + return unicode_to_utf8(uc); } diff --git a/src/user.c b/src/user.c index eb1fd32..0ec1d99 100644 --- a/src/user.c +++ b/src/user.c @@ -60,7 +60,9 @@ my_FILE *f = (my_FILE *) malloc(sizeof(my_FILE)); if ((f->file = fopen(file_name, "r")) == NULL || (f->name = my_malloc((strlen(file_name) + 1) * sizeof(char))) == NULL) - return NULL; + { + return NULL; + } f->line_nr = 1; strcpy(f->name, file_name); @@ -106,7 +108,7 @@ C = fgetc(F); \ if (feof(F) || ferror(F)) \ goto inputend; \ - } + } char * give_definition(my_FILE *file) @@ -116,14 +118,18 @@ unsigned long def_buffer_length = STANDARD_BUFFER_LENGTH, chars_nr = 0; if ((def = my_malloc(def_buffer_length)) == NULL) + { return NULL; + } GETC_OR_END(file->file, c); while (c == '\t' || c == '#') { if (c == '#') + { leave_line(file->file); + } else { GETC_OR_END(file->file, c); @@ -136,7 +142,7 @@ for (i = 0; unicode_char[i] != '\0'; i++) ADD_CHAR(unicode_char[i]) - GETC_OR_END(file->file, c); + GETC_OR_END(file->file, c); c2 = 0; c3 = 0; c4 = 0; @@ -147,7 +153,7 @@ { ADD_CHAR('<'); } - /* daved - 0.21.3 - allow escaping a backslash */ + /* daved - 0.21.3 - allow escaping a backslash */ if (c == '\\' && c2 == '\\') { ADD_CHAR('\\'); @@ -157,16 +163,15 @@ } else - /* daved - support \n in definitions */ - if (c == 'n' && c2 == '\\') - { - ADD_CHAR('\n'); - } - else - if ((c != '<' && c != '\\') || (c == '\\' && c2 == '\\')) - { - ADD_CHAR(c) - } + /* daved - support \n in definitions */ + if (c == 'n' && c2 == '\\') + { + ADD_CHAR('\n'); + } + else if ((c != '<' && c != '\\') || (c == '\\' && c2 == '\\')) + { + ADD_CHAR(c) + } c4 = c3; c3 = c2; @@ -189,9 +194,13 @@ } if (chars_nr > 0) + { def[chars_nr - 1] = '\0'; + } else + { def[0] = '\0'; + } return def; } @@ -206,7 +215,7 @@ *=======================================================================*/ int -match_name (char *name, OutputPersonality *op, my_FILE *file) +match_name(char *name, OutputPersonality *op, my_FILE *file) { struct definition { @@ -230,18 +239,23 @@ i = strtol(name, &endptr, 10); if (*endptr == '\0') + { add_alias(op, i, give_definition(file)); + } else if (name[0] == '<' && name[1] == 'U') + { add_alias(op, get_unicode(&name[2]), give_definition(file)); + } else - { + { fprintf(stderr, "unrtf: unknown name \"%s\" in line %d of \"%s\"\n", name, file->line_nr, file->name); return 1; } } - else - if ((*defs[i].variable = give_definition(file)) == NULL) - return -1; + else if ((*defs[i].variable = give_definition(file)) == NULL) + { + return -1; + } return 0; } @@ -254,44 +268,56 @@ *=======================================================================*/ OutputPersonality * -user_init (OutputPersonality *op, char *definitions_file_path) -{ - my_FILE *f; +user_init(OutputPersonality *op, char *definitions_file_path) +{ + my_FILE *f = NULL; char name_buffer[BUFFER_SIZE]; + int err = 1; if (op == NULL) + { op = op_create(); + } if ((f = my_fopen(definitions_file_path, "r")) == NULL) { perror(definitions_file_path); - return op; - } - - while (fgets(name_buffer, BUFFER_SIZE - 1, f->file) != NULL - && !feof(f->file) && !ferror(f->file)) - { - if (name_buffer[strlen(name_buffer) - 1] != '\n') - leave_line(f->file); + goto out; + } + + while (fgets(name_buffer, BUFFER_SIZE - 1, f->file) != NULL + && !feof(f->file) && !ferror(f->file)) + { + int ll = strlen(name_buffer); + if (ll <= 0 || name_buffer[ll - 1] != '\n') + { + /* Something is very wrong. There is no reason to continue + parsing a bad config file. Bail out */ + fprintf(stderr, "%s: bad line at %d\n", definitions_file_path, + f->line_nr); + goto out; + } f->line_nr++; if (name_buffer[0] != '#' && name_buffer[0] != '\n') { - name_buffer[strlen(name_buffer) - 1] = '\0'; + name_buffer[ll - 1] = '\0'; if (match_name(name_buffer, op, f) == -1) { - my_fclose(f); - free(f); - return NULL; + goto out; } } } - my_fclose(f); - free(f); - - return op; -} - + err = 0; +out: + if (f) { + my_fclose(f); + free(f); + } + + return err ? NULL : op; +} + diff --git a/src/user.h b/src/user.h index 61d2cd1..e8bdd80 100644 --- a/src/user.h +++ b/src/user.h @@ -113,6 +113,8 @@ DEFS_ARRAY_ENTRY(shadow_end, op),\ DEFS_ARRAY_ENTRY(outline_begin, op),\ DEFS_ARRAY_ENTRY(outline_end, op),\ + DEFS_ARRAY_ENTRY(all_caps_begin, op),\ + DEFS_ARRAY_ENTRY(all_caps_end, op),\ DEFS_ARRAY_ENTRY(small_caps_begin, op),\ DEFS_ARRAY_ENTRY(small_caps_end, op),\ DEFS_ARRAY_ENTRY(pointlist_begin, op),\ @@ -158,7 +160,7 @@ #ifndef _USER -extern OutputPersonality* user_init(OutputPersonality *, char *tags_file_path); +extern OutputPersonality *user_init(OutputPersonality *, char *tags_file_path); #define _USER diff --git a/src/util.c b/src/util.c index b113131..46c00a4 100644 --- a/src/util.c +++ b/src/util.c @@ -27,7 +27,7 @@ * Purpose: Utility functions. *---------------------------------------------------------------------- * Changes: - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith * 16 Dec 07, daved@physiol.usyd.edu.au: updated to GPL v3 * 09 Nov 08, arkadiusz.firus@gmail.com: added leave_line @@ -63,17 +63,30 @@ /* Convert a two-char hexadecimal expression to an integer */ int -h2toi (const char *s) { +h2toi(const char *s) +{ int tmp; int ch; tmp = tolower(*s++); - if (tmp>'9') tmp-=('a'-10); - else tmp-='0'; - ch=16*tmp; + if (tmp > '9') + { + tmp -= ('a' - 10); + } + else + { + tmp -= '0'; + } + ch = 16 * tmp; tmp = tolower(*s++); - if (tmp>'9') tmp-=('a'-10); - else tmp-='0'; - ch+=tmp; + if (tmp > '9') + { + tmp -= ('a' - 10); + } + else + { + tmp -= '0'; + } + ch += tmp; return ch; } @@ -85,14 +98,15 @@ *=======================================================================*/ void -leave_line (FILE *f) +leave_line(FILE *f) { int c; do { c = fgetc(f); - } while (c != '\n' && c != EOF); + } + while (c != '\n' && c != EOF); return; } @@ -104,12 +118,14 @@ * Returns: String. *=======================================================================*/ char * -concatenate (const char *s1, const char *s2) +concatenate(const char *s1, const char *s2) { char *result; if ((result = my_malloc((strlen(s1) + strlen(s2) + 1) * sizeof(char))) == 0) - return 0; + { + return 0; + } strcpy(result, s1); strcat(result, s2); @@ -126,10 +142,10 @@ /* * Note: This is designed for programs that use contiguous blocks of * increasing size. The problem when using a simple realloc is that a lot of - * memory is lost to fragmentation if many fixed size reallocations are + * memory is lost to fragmentation if many fixed size reallocations are * performed. - * This routine doubles the memory space every time it is called, - * Algorithm: + * This routine doubles the memory space every time it is called, + * Algorithm: * - 1st call (cp = 0), allocate min *sz * - next calls double current size * - Until current size is maxinc * sz, then increment by maxinc*sz everytime @@ -137,29 +153,40 @@ void * allocmem ( - void *cp, /* The array to grow. may be NULL */ - int sz, /* Unit size in bytes */ - int *np, /* Pointer to current allocation number */ - int min, /* Number to allocate the first time */ - int maxinc /* Maximum increment */ + void *cp, /* The array to grow. may be NULL */ + int sz, /* Unit size in bytes */ + int *np, /* Pointer to current allocation number */ + int min, /* Number to allocate the first time */ + int maxinc /* Maximum increment */ ) { - int inc; + int inc; - if (cp == NULL) { - cp = malloc(min * sz); - if (cp) - *np = min; - else - *np = 0; - return(cp); - } - if (*np > maxinc) - inc = maxinc; - else - inc = *np; - cp = realloc(cp, (*np + inc) * sz); - if (cp) - *np += inc; - return cp; + if (cp == NULL) + { + cp = malloc(min * sz); + if (cp) + { + *np = min; + } + else + { + *np = 0; + } + return (cp); + } + if (*np > maxinc) + { + inc = maxinc; + } + else + { + inc = *np; + } + cp = realloc(cp, (*np + inc) * sz); + if (cp) + { + *np += inc; + } + return cp; } diff --git a/src/util.h b/src/util.h index b23a30e..8fc50d3 100644 --- a/src/util.h +++ b/src/util.h @@ -39,20 +39,20 @@ #include #endif -extern int h2toi (const char *); +extern int h2toi(const char *); -void leave_line (FILE *f); -extern char *concatenate (const char *, const char *); +void leave_line(FILE *f); +extern char *concatenate(const char *, const char *); /* Help managing a growing contiguous array */ extern void * allocmem ( - void *cp, /* The array to grow. Can be NULL */ - int sz, /* Unit size in bytes */ - int *np, /* Pointer to current allocation number (units) */ - int min, /* Number of units to allocate the first time */ - int maxinc /* Maximum increment in units (maxinc*sz bytes) */ + void *cp, /* The array to grow. Can be NULL */ + int sz, /* Unit size in bytes */ + int *np, /* Pointer to current allocation number (units) */ + int min, /* Number of units to allocate the first time */ + int maxinc /* Maximum increment in units (maxinc*sz bytes) */ ); #endif /* _UTIL_H_INCLUDED_ */ diff --git a/src/word.c b/src/word.c index ee3a63c..8ec893e 100644 --- a/src/word.c +++ b/src/word.c @@ -43,7 +43,7 @@ * 21 Apr 01, tuorfa@yahoo.com: fix for words getting lost after \par * 24 Jul 01, tuorfa@yahoo.com: moved conversion code to convert.c * 22 Sep 01, tuorfa@yahoo.com: moved word_dump to here from parse.c - * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks + * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks * 29 Mar 05, daved@physiol.usyd.edu.au: changes requested by ZT Smith * 16 Dec 07, daved@physiol.usyd.edu.au: updated to GPL v3 *--------------------------------------------------------------------*/ @@ -78,7 +78,7 @@ /* For word_dump */ -static int indent_level=0; +static int indent_level = 0; /*======================================================================== @@ -90,7 +90,8 @@ *=======================================================================*/ const char * -word_string (Word *w) { +word_string(Word *w) +{ CHECK_PARAM_NOT_NULL(w); return w->str; } @@ -104,17 +105,26 @@ * Returns: Word*. *=======================================================================*/ -Word * -word_new (char *str) { - Word * w; +Word * +word_new(char *str) +{ + Word *w; w = (Word *) my_malloc(sizeof(Word)); if (!w) - error_handler ("out of memory"); - memset ((void*) w, 0, sizeof(Word)); - if (!w) error_handler ("cannot allocate a Word"); - - if (str) w->str = hash_store (str); + { + error_handler("out of memory"); + } + memset((void *) w, 0, sizeof(Word)); + if (!w) + { + error_handler("cannot allocate a Word"); + } + + if (str) + { + w->str = hash_store(str); + } return w; } @@ -127,20 +137,24 @@ * Returns: None. *=======================================================================*/ -void word_free (Word *w) { +void word_free(Word *w) +{ Word *prev; Word *w2; CHECK_PARAM_NOT_NULL(w); - while (w) { + while (w) + { w2 = w->child; if (w2) + { word_free(w2); + } prev = w; w = w->next; - my_free((char*) prev); + my_free((char *) prev); } } @@ -156,15 +170,20 @@ *=======================================================================*/ static void -print_indentation (int level) +print_indentation(int level) { int i; - if (level) { - for (i=0;ichild) { - word_dump (w->child); - printf ("\n"); - print_indentation (indent_level); + print_indentation(indent_level); + + while (w) + { + s = word_string(w); + if (s) + { + printf("\"%s\" ", s); + } + else + { + if (w->child) + { + word_dump(w->child); + printf("\n"); + print_indentation(indent_level); } else - warning_handler ("Word object has no string and no children"); + { + warning_handler("Word object has no string and no children"); + } } w = w->next; } @@ -210,7 +236,8 @@ /*======================================================================== * Name: optimize_word - * Purpose: Function tries to optimize Word. + * Purpose: Function tries to optimize group by eliminating redundant commands + * consecutively setting same attribute to same value. * Args: Word to optimize. * Returns: Optimized word. *=======================================================================*/ @@ -223,11 +250,12 @@ Tag tags_to_opt[] = OPT_ARRAY; Word *root = w, *w2 = 0; - if (depth > MAX_GROUP_DEPTH) { + if (depth > MAX_GROUP_DEPTH) + { /* Have to be reasonable at some point */ - warning_handler ("Max group depth reached"); + warning_handler("Max group depth reached"); return w; - } + } for (; w != NULL; w = w->next) { @@ -239,11 +267,14 @@ { len = strlen(tags_to_opt[i].name); if (!strncmp(tags_to_opt[i].name, s, len) && (isdigit(s[len]) || s[len] == '-')) + { break; + } } - else - if (!strcmp(tags_to_opt[i].name, s)) - break; + else if (!strcmp(tags_to_opt[i].name, s)) + { + break; + } } if (tags_to_opt[i].name[0] != '\0') @@ -257,12 +288,16 @@ w = w2; } else + { c = add_to_collection(c, i, s); + } } } if (w->child != NULL) - w->child = optimize_word(w->child, depth+1); + { + w->child = optimize_word(w->child, depth + 1); + } w2 = w; } diff --git a/src/word.h b/src/word.h index 59d6470..0e5d6cc 100644 --- a/src/word.h +++ b/src/word.h @@ -36,26 +36,28 @@ * 25 Sep 11, jf@dockes.org: reposition top #ifndef *--------------------------------------------------------------------*/ -typedef struct _w { +typedef struct _w +{ const char *str; - struct _w * next; - struct _w * child; + struct _w *next; + struct _w *child; } Word; -extern Word* word_new (char*); -extern void word_free (Word*); -extern Word* word_read (FILE*); -extern const char* word_string (Word*); -extern void word_dump (Word*); -extern void word_print_html (Word*); +extern Word *word_new(char *); +extern void word_free(Word *); +extern Word *word_read(FILE *); +extern const char *word_string(Word *); +extern void word_dump(Word *); +extern void word_print_html(Word *); #ifndef MAX_GROUP_DEPTH #define MAX_GROUP_DEPTH 1000 #endif - -extern Word* optimize_word(Word*, int depth); -typedef struct _t { +extern Word *optimize_word(Word *, int depth); + +typedef struct _t +{ char *name; int has_param; } Tag; diff --git a/tests/Makefile.in b/tests/Makefile.in index 199ff8e..735c62d 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.13.4 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,7 +14,17 @@ @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ @@ -78,12 +88,11 @@ build_triplet = @build@ host_triplet = @host@ subdir = tests -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/config/test-driver ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = @@ -312,6 +321,8 @@ TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/config/test-driver TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ $(TEST_LOG_FLAGS) +am__DIST_COMMON = $(srcdir)/Makefile.in \ + $(top_srcdir)/config/test-driver DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -567,7 +578,6 @@ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu tests/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --gnu tests/Makefile -.PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ @@ -622,7 +632,7 @@ if test -n "$$am__remaking_logs"; then \ echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ "recursion detected" >&2; \ - else \ + elif test -n "$$redo_logs"; then \ am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ fi; \ if $(am__make_dryrun); then :; else \ @@ -921,6 +931,8 @@ mostlyclean-generic pdf pdf-am ps ps-am recheck tags-am \ uninstall uninstall-am +.PRECIOUS: Makefile + # ensure that the distributed scripts are executable before distribution. # Could be necessary if checking out CVS. diff --git a/tests/character_formatting.rtf b/tests/character_formatting.rtf index 5752ce3..47eeee0 100644 --- a/tests/character_formatting.rtf +++ b/tests/character_formatting.rtf @@ -37,7 +37,7 @@ \par }{\impr\cf8\insrsid4857473 This text is formatted with engrave. \par }{\scaps\insrsid4857473 This text is formatted with small caps. \par }{\caps\insrsid4857473 This text is formatted with all caps. -\par }{\insrsid4857473 BUT THIS TEXT IS WRITTEN SIMPLE WITH THE CAPS LOCK TUNRED ON. +\par }{\insrsid4857473 BUT THIS TEXT IS WRITTEN SIMPLE WITH THE CAPS LOCK TURNED ON. \par }{\v\insrsid4857473 This text is formatted as hidden.}{\insrsid4857473 \par \par Character spacing is 100%