diff options
author | Jeff Bailey <jbailey@gnu.org> | 2002-11-01 17:20:33 +0000 |
---|---|---|
committer | Jeff Bailey <jbailey@gnu.org> | 2002-11-01 17:20:33 +0000 |
commit | 4a703f8271a7b17104f728f0e0a421b2ff65a966 (patch) | |
tree | 05d7a6270f23dc0dabad33feced47bbe14f4e07c | |
parent | 360e5ac69c0372078359a1facd962381e38d33e0 (diff) | |
download | mailutils-4a703f8271a7b17104f728f0e0a421b2ff65a966.tar.gz mailutils-4a703f8271a7b17104f728f0e0a421b2ff65a966.tar.bz2 |
2002-11-01 Jeff Bailey <jbailey@gnu.org>
* mh/Makefile.am: Use MHPROGRAMS and MHLIBRARIES instead of
MH_PROGRAMS and MH_LIBRARIES so that automake doesn't complain.
* mail.remote/Makefile.am: Use SMTPPROGRAMS instead of
SMTP_PROGRAMS so that automake doesn't complain.
* configure.ac: Adjust for above changes.
* mh/Makefile.am: Use AM_YFLAGS instead of YFLAGS.
* libmu_scm/Makefile.am: Use AM_CPPFLAGS instead of CPPFLAGS
* autogen.sh: Redo using 'autoreconf'. This is now the right
tool to use for generating the build environment.
* Makefile.am: Require version 1.7.1, add std-options to
AUTOMAKE_OPTIONS
* configure.in: Require version 2.54. Update quoting. Change
AC_ARG_WITH and AC_ARG_ENABLE to use AC_HELP_STRING
* m4/enable.m4: Change AC_ARG_ENABLE to use AC_HELP_STRING
* lib/Makefile.am: Remove ansi2knr
* lib/ansi2knr.c: Remove
* lib/ansi2knr.1: Remove
-rw-r--r-- | ChangeLog | 40 | ||||
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 156 | ||||
-rw-r--r-- | lib/Makefile.am | 1 | ||||
-rw-r--r-- | lib/ansi2knr.1 | 36 | ||||
-rw-r--r-- | lib/ansi2knr.c | 678 | ||||
-rw-r--r-- | m4/enable.m4 | 10 | ||||
-rw-r--r-- | mail.remote/Makefile.am | 4 | ||||
-rw-r--r-- | mh/Makefile.am | 8 |
9 files changed, 137 insertions, 798 deletions
@@ -1,3 +1,34 @@ +2002-11-01 Jeff Bailey <jbailey@gnu.org> + + * mh/Makefile.am: Use MHPROGRAMS and MHLIBRARIES instead of + MH_PROGRAMS and MH_LIBRARIES so that automake doesn't complain. + + * mail.remote/Makefile.am: Use SMTPPROGRAMS instead of + SMTP_PROGRAMS so that automake doesn't complain. + + * configure.ac: Adjust for above changes. + + * mh/Makefile.am: Use AM_YFLAGS instead of YFLAGS. + + * libmu_scm/Makefile.am: Use AM_CPPFLAGS instead of CPPFLAGS + + * autogen.sh: Redo using 'autoreconf'. This is now the right + tool to use for generating the build environment. + + * Makefile.am: Require version 1.7.1, add std-options to + AUTOMAKE_OPTIONS + + * configure.in: Require version 2.54. Update quoting. Change + AC_ARG_WITH and AC_ARG_ENABLE to use AC_HELP_STRING + + * m4/enable.m4: Change AC_ARG_ENABLE to use AC_HELP_STRING + + * lib/Makefile.am: Remove ansi2knr + + * lib/ansi2knr.c: Remove + + * lib/ansi2knr.1: Remove + 2002-11-01 Sergey Poznyakoff * m4/enable.m4: Fixed action-if-false. @@ -7,15 +38,6 @@ * mh/Makefile.am: Build the targets conditionally. * mail.remote/Makefile.am: Likewise. -2002-10-30 Jeff Bailey <jbailey@gnu.org> - - * mh/Makefile.am: Use AM_YFLAGS instead of YFLAGS - - * libmu_scm/Makefile.am: Use AM_CPPFLAGS instead of CPPFLAGS - - * autogen.sh: Redo using 'autoreconf'. This is now the right - tool to use for generating the build environment. - 2002-10-29 Sergey Poznyakoff Following the proposition of Olivier Bornet diff --git a/Makefile.am b/Makefile.am index f2987e110..02f12b3fe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ # Copyright (C) 2000,2001,2002 Free Software Foundation # See file COPYING in the distribution root directory for copying conditions. -AUTOMAKE_OPTIONS = gnu 1.6 readme-alpha +AUTOMAKE_OPTIONS = gnu 1.7.1 readme-alpha std-options ACLOCAL_AMFLAGS = -I m4 SUBDIRS = include m4 lib testsuite mailbox examples doc \ diff --git a/configure.ac b/configure.ac index 119af41cd..7a3b5e75d 100644 --- a/configure.ac +++ b/configure.ac @@ -17,13 +17,13 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -AC_INIT([GNU Mailutils], [0.1.2], [bug-mailutils@gnu.org]) +AC_INIT([GNU Mailutils],[0.1.2],[bug-mailutils@gnu.org]) AC_CONFIG_SRCDIR([mailbox/mailbox.c]) AC_CANONICAL_TARGET([]) AM_INIT_AUTOMAKE -AM_CONFIG_HEADER(config.h) +AC_CONFIG_HEADERS([config.h]) -AC_PREREQ(2.52) +AC_PREREQ(2.54) dnl Check for programs AC_PROG_CC @@ -42,34 +42,41 @@ MU_DEBUG_MODE AUTHLIBS=../auth/libmuauth.la dnl Check for arguments -AC_ARG_ENABLE(pam, - [ --disable-pam disable pam], - [case "${enableval}" in +AC_ARG_ENABLE([pam], + AC_HELP_STRING([--disable-pam], + [disable pam]), + [ +case "${enableval}" in yes) testpam=yes ;; no) testpam=no ;; - *) AC_MSG_ERROR(bad value ${enableval} for --disable-pam) ;; - esac],[testpam=yes]) - -AC_ARG_ENABLE(pthread, - [ --disable-pthread disable pthread], - [case "${enableval}" in + *) AC_MSG_ERROR([bad value ${enableval} for --disable-pam]) ;; +esac],[testpam=yes]) + +AC_ARG_ENABLE([pthread], + AC_HELP_STRING([--disable-pthread], + [disable pthread]), + [ +case "${enableval}" in yes) usepthread=yes ;; no) usepthread=no ;; *) AC_MSG_ERROR(bad value ${enableval} for --disable-pthread) ;; - esac],[usepthread=yes]) +esac],[usepthread=yes]) -AC_ARG_WITH(readline, - [ --without-readline do not use readline], - [case "${withval}" in +AC_ARG_WITH([readline], + AC_HELP_STRING([--without-readline], + [do not use readline]), + [ +case "${withval}" in yes) usereadline=yes ;; no) usereadline=no ;; *) AC_MSG_ERROR(bad value ${withval} for --without-readline) ;; - esac],[usereadline=yes]) +esac],[usereadline=yes]) -AC_ARG_WITH(gssapi, - [ --with-gssapi use GSSAPI authentication ], - [WITH_GSSAPI=$withval], - [WITH_GSSAPI=no]) +AC_ARG_WITH([gssapi], + AC_HELP_STRING([--with-gssapi], + [use GSSAPI authentication]), + [WITH_GSSAPI=$withval], + [WITH_GSSAPI=no]) if test "x$WITH_GSSAPI" != "xno"; then MU_CHECK_GSSAPI($WITH_GSSAPI) @@ -85,32 +92,38 @@ if test "x$WITH_GSSAPI" != "xno"; then fi AC_SUBST(AUTHOBJS) -AC_ARG_WITH(guile, - [ --without-guile do not build guile interface], - [case "${withval}" in +AC_ARG_WITH([guile], + AC_HELP_STRING([--without-guile], + [do not build guile interface]), + [ +case "${withval}" in yes) useguile=yes ;; no) useguile=no ;; *) AC_MSG_ERROR(bad value ${withval} for --without-guile) ;; - esac],[useguile=yes]) +esac],[useguile=yes]) AC_SUBST(SITE_MAIL_RC) -AC_ARG_WITH(mail-rc, - [ --with-mail-rc=FILE use FILE instead of \$sysconfdir/mail.rc], - [case "${withval}" in +AC_ARG_WITH([mail-rc], + AC_HELP_STRING([--with-mail-rc=FILE], + [use FILE instead of $sysconfdir/mail.rc]), + [ +case "${withval}" in /*) SITE_MAIL_RC="${withval}";; *) SITE_MAIL_RC="\$(sysconfdir)/${withval}";; esac], [SITE_MAIL_RC="\$(sysconfdir)/mail.rc"]) MU_CONF_MAILDIR= -AC_ARG_WITH(mail-spool, - [ --with-mail-spool=PATH use PATH instead of /var/spool/mail], - [case "$withval" in +AC_ARG_WITH([mail-spool], + AC_HELP_STRING([--with-mail-spool=PATH], + [use PATH instead of /var/spool/mail]), + [ +case "$withval" in /*/) MU_CONF_MAILDIR="\"${withval}\"";; /*) MU_CONF_MAILDIR="\"${withval}/\"";; *:*[[/=]]) MU_CONF_MAILDIR="\"${withval}\"";; *) AC_MSG_ERROR(--with-mail-spool must be an absolute path or a valid URL);; - esac]) +esac]) if test "x$MU_CONF_MAILDIR" != x; then AC_DEFINE_UNQUOTED(MU_CONF_MAILDIR,$MU_CONF_MAILDIR, @@ -134,44 +147,53 @@ AH_BOTTOM([ #endif]) use_dbm=no -AC_ARG_WITH(gdbm, - [ --with-gdbm use GDBM], - [case "${withval}" in +AC_ARG_WITH([gdbm], + AC_HELP_STRING([--with-gdbm], + [use GDBM]), + [ +case "${withval}" in yes) use_dbm=GDBM ;; no) use_dbm=no ;; *) AC_MSG_ERROR(bad value ${withval} for --with-gdbm) ;; - esac]) +esac]) -AC_ARG_WITH(db2, - [ --with-db2 use Berkeley DB], - [case "${withval}" in +AC_ARG_WITH([db2], + AC_HELP_STRING([--with-db2], + [use Berkeley DB]), + [ +case "${withval}" in yes) use_dbm=BDB2 ;; no) use_dbm=no ;; *) AC_MSG_ERROR(bad value ${withval} for --with-db) ;; - esac]) +esac]) -AC_ARG_WITH(ndbm, - [ --with-ndbm use NDBM], - [case "${withval}" in +AC_ARG_WITH([ndbm], + AC_HELP_STRING([--with-ndbm], + [use NDBM]), + [ +case "${withval}" in yes) use_dbm=NDBM ;; no) use_dbm=no ;; *) AC_MSG_ERROR(bad value ${withval} for --with-ndbm) ;; - esac]) +esac]) -AC_ARG_WITH(dbm, - [ --with-dbm use old DBM], - [case "${withval}" in +AC_ARG_WITH([dbm], + AC_HELP_STRING([--with-dbm], + [use old DBM]), + [ +case "${withval}" in yes) use_dbm=ODBM ;; no) use_dbm=no ;; *) AC_MSG_ERROR(bad value ${withval} for --with-old-dbm) ;; - esac]) +esac]) AC_MSG_CHECKING(for log facility) log_facility="LOG_MAIL" -AC_ARG_WITH(log-facility, - [ --with-log-facility=facility enable logging to the given facility], - AC_TRY_COMPILE([#include <syslog.h>], int lf = $withval, - log_facility=$withval)) +AC_ARG_WITH([log-facility], + AC_HELP_STRING([--with-log-facility=facility], + [enable logging to the given facility]), + [AC_TRY_COMPILE([#include <syslog.h>], int lf = $withval, + log_facility=$withval)]) AC_DEFINE_UNQUOTED(LOG_FACILITY, $log_facility, [Default syslog facility to use]) AC_MSG_RESULT($log_facility) @@ -308,7 +330,10 @@ AC_CHECK_FUNCS(_obstack_begin, dnl check if mysql support was added AC_SUBST(BUILD_LIBMYSQL) AC_SUBST(MYSQLLIBS) -AC_ARG_ENABLE(mysql, [ --enable-mysql enable mysql support (default no)], [use_mysql="yes"],,) +AC_ARG_ENABLE([mysql], + AC_HELP_STRING([--enable-mysql], + [enable mysql support (default no)]), + [use_mysql="yes"],,) if test x"$use_mysql" = x"yes"; then AC_CHECK_HEADER(mysql/mysql.h, [AUTHLIBS="$AUTHLIBS -lmysqlclient -lm -L/usr/lib/mysql -L/usr/local/lib/mysql" @@ -316,27 +341,32 @@ if test x"$use_mysql" = x"yes"; then fi dnl Virtual domain support, at least for pop3d -AC_ARG_ENABLE(virtual-domains, [ --enable-virtual-domains enable virtual domain support (default no)], [use_virtual_domains="yes"],,) +AC_ARG_ENABLE([virtual-domains], + AC_HELP_STRING([--enable-virtual-domains], + [enable virtual domain support (default no)]), + [use_virtual_domains="yes"],,) if test x"$use_virtual_domains" = x"yes"; then AC_DEFINE(USE_VIRTUAL_DOMAINS,1,[Enable use of virtual domains]) AC_SUBST(SITE_VIRTUAL_PWDDIR) - AC_ARG_WITH(virtual-pwddir, - [ --with-virtual-pwddir=DIR use DIR instead of \$sysconfdir/domain], - [case "${withval}" in + AC_ARG_WITH([virtual-pwddir], + AC_HELP_STRING([--with-virtual-pwddir=DIR], + [use DIR instead of $sysconfdir/domain]), + [ +case "${withval}" in /*) SITE_VIRTUAL_PWDDIR="${withval}";; *) SITE_VIRTUAL_PWDDIR="\$(sysconfdir)/${withval}";; - esac], +esac], [SITE_VIRTUAL_PWDDIR="\$(sysconfdir)/domain"]) fi MU_ENABLE_SUPPORT(imap) MU_ENABLE_SUPPORT(pop) -AC_SUBST(MH_PROGRAMS) -AC_SUBST(MH_LIBRARIES) -MU_ENABLE_SUPPORT(mh, [MH_PROGRAMS='$(MH_PROGRAMS)'; MH_LIBRARIES='$(MH_LIBRARIES)']) -AC_SUBST(SMTP_PROGRAMS) -MU_ENABLE_SUPPORT(smtp, [SMTP_PROGRAMS='$(SMTP_PROGRAMS)']) +AC_SUBST(MHPROGRAMS) +AC_SUBST(MHLIBRARIES) +MU_ENABLE_SUPPORT(mh, [MHPROGRAMS='$(MHPROGRAMS)'; MHLIBRARIES='$(MHLIBRARIES)']) +AC_SUBST(SMTPPROGRAMS) +MU_ENABLE_SUPPORT(smtp, [SMTPPROGRAMS='$(SMTPPROGRAMS)']) MU_ENABLE_SUPPORT(sendmail) if test x"$testpam" = x"yes"; then diff --git a/lib/Makefile.am b/lib/Makefile.am index 86e4aea0e..ed168c68c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2,7 +2,6 @@ # Copyright (C) 2000,2001,2002 Free Software Foundation # See file COPYING in the distribution root directory for copying conditions. -AUTOMAKE_OPTIONS = ansi2knr noinst_LTLIBRARIES = libmailutils.la SUBDIRS = posix diff --git a/lib/ansi2knr.1 b/lib/ansi2knr.1 deleted file mode 100644 index f9ee5a631..000000000 --- a/lib/ansi2knr.1 +++ /dev/null @@ -1,36 +0,0 @@ -.TH ANSI2KNR 1 "19 Jan 1996" -.SH NAME -ansi2knr \- convert ANSI C to Kernighan & Ritchie C -.SH SYNOPSIS -.I ansi2knr -[--varargs] input_file [output_file] -.SH DESCRIPTION -If no output_file is supplied, output goes to stdout. -.br -There are no error messages. -.sp -.I ansi2knr -recognizes function definitions by seeing a non-keyword identifier at the left -margin, followed by a left parenthesis, with a right parenthesis as the last -character on the line, and with a left brace as the first token on the -following line (ignoring possible intervening comments). It will recognize a -multi-line header provided that no intervening line ends with a left or right -brace or a semicolon. These algorithms ignore whitespace and comments, except -that the function name must be the first thing on the line. -.sp -The following constructs will confuse it: -.br - - Any other construct that starts at the left margin and follows the -above syntax (such as a macro or function call). -.br - - Some macros that tinker with the syntax of the function header. -.sp -The --varargs switch is obsolete, and is recognized only for -backwards compatibility. The present version of -.I ansi2knr -will always attempt to convert a ... argument to va_alist and va_dcl. -.SH AUTHOR -L. Peter Deutsch <ghost@aladdin.com> wrote the original ansi2knr and -continues to maintain the current version; most of the code in the current -version is his work. ansi2knr also includes contributions by Francois -Pinard <pinard@iro.umontreal.ca> and Jim Avera <jima@netcom.com>. diff --git a/lib/ansi2knr.c b/lib/ansi2knr.c deleted file mode 100644 index 8142b3856..000000000 --- a/lib/ansi2knr.c +++ /dev/null @@ -1,678 +0,0 @@ -/* Copyright (C) 1989, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. */ - -/*$Id$*/ -/* Convert ANSI C function definitions to K&R ("traditional C") syntax */ - -/* -ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY. No author or distributor accepts responsibility to anyone for the -consequences of using it or for whether it serves any particular purpose or -works at all, unless he says so in writing. Refer to the GNU General Public -License (the "GPL") for full details. - -Everyone is granted permission to copy, modify and redistribute ansi2knr, -but only under the conditions described in the GPL. A copy of this license -is supposed to have been given to you along with ansi2knr so you can know -your rights and responsibilities. It should be in a file named COPYLEFT, -or, if there is no file named COPYLEFT, a file named COPYING. Among other -things, the copyright notice and this notice must be preserved on all -copies. - -We explicitly state here what we believe is already implied by the GPL: if -the ansi2knr program is distributed as a separate set of sources and a -separate executable file which are aggregated on a storage medium together -with another program, this in itself does not bring the other program under -the GPL, nor does the mere fact that such a program or the procedures for -constructing it invoke the ansi2knr executable bring any other part of the -program under the GPL. -*/ - -/* - * Usage: - ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]] - * --filename provides the file name for the #line directive in the output, - * overriding input_file (if present). - * If no input_file is supplied, input is read from stdin. - * If no output_file is supplied, output goes to stdout. - * There are no error messages. - * - * ansi2knr recognizes function definitions by seeing a non-keyword - * identifier at the left margin, followed by a left parenthesis, - * with a right parenthesis as the last character on the line, - * and with a left brace as the first token on the following line - * (ignoring possible intervening comments), except that a line - * consisting of only - * identifier1(identifier2) - * will not be considered a function definition unless identifier2 is - * the word "void", and a line consisting of - * identifier1(identifier2, <<arbitrary>>) - * will not be considered a function definition. - * ansi2knr will recognize a multi-line header provided - * that no intervening line ends with a left or right brace or a semicolon. - * These algorithms ignore whitespace and comments, except that - * the function name must be the first thing on the line. - * The following constructs will confuse it: - * - Any other construct that starts at the left margin and - * follows the above syntax (such as a macro or function call). - * - Some macros that tinker with the syntax of function headers. - */ - -/* - * The original and principal author of ansi2knr is L. Peter Deutsch - * <ghost@aladdin.com>. Other authors are noted in the change history - * that follows (in reverse chronological order): - lpd 1999-04-12 added minor fixes from Pavel Roskin - <pavel_roskin@geocities.com> for clean compilation with - gcc -W -Wall - lpd 1999-03-22 added hack to recognize lines consisting of - identifier1(identifier2, xxx) as *not* being procedures - lpd 1999-02-03 made indentation of preprocessor commands consistent - lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an - endless loop; quoted strings within an argument list - confused the parser - lpd 1999-01-24 added a check for write errors on the output, - suggested by Jim Meyering <meyering@ascend.com> - lpd 1998-11-09 added further hack to recognize identifier(void) - as being a procedure - lpd 1998-10-23 added hack to recognize lines consisting of - identifier1(identifier2) as *not* being procedures - lpd 1997-12-08 made input_file optional; only closes input and/or - output file if not stdin or stdout respectively; prints - usage message on stderr rather than stdout; adds - --filename switch (changes suggested by - <ceder@lysator.liu.se>) - lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with - compilers that don't understand void, as suggested by - Tom Lane - lpd 1996-01-15 changed to require that the first non-comment token - on the line following a function header be a left brace, - to reduce sensitivity to macros, as suggested by Tom Lane - <tgl@sss.pgh.pa.us> - lpd 1995-06-22 removed #ifndefs whose sole purpose was to define - undefined preprocessor symbols as 0; changed all #ifdefs - for configuration symbols to #ifs - lpd 1995-04-05 changed copyright notice to make it clear that - including ansi2knr in a program does not bring the entire - program under the GPL - lpd 1994-12-18 added conditionals for systems where ctype macros - don't handle 8-bit characters properly, suggested by - Francois Pinard <pinard@iro.umontreal.ca>; - removed --varargs switch (this is now the default) - lpd 1994-10-10 removed CONFIG_BROKETS conditional - lpd 1994-07-16 added some conditionals to help GNU `configure', - suggested by Francois Pinard <pinard@iro.umontreal.ca>; - properly erase prototype args in function parameters, - contributed by Jim Avera <jima@netcom.com>; - correct error in writeblanks (it shouldn't erase EOLs) - lpd 1989-xx-xx original version - */ - -/* Most of the conditionals here are to make ansi2knr work with */ -/* or without the GNU configure machinery. */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include <stdio.h> -#include <ctype.h> - -#if HAVE_CONFIG_H - -/* - For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h). - This will define HAVE_CONFIG_H and so, activate the following lines. - */ - -# if STDC_HEADERS || HAVE_STRING_H -# include <string.h> -# else -# include <strings.h> -# endif - -#else /* not HAVE_CONFIG_H */ - -/* Otherwise do it the hard way */ - -# ifdef BSD -# include <strings.h> -# else -# ifdef VMS - extern int strlen(), strncmp(); -# else -# include <string.h> -# endif -# endif - -#endif /* not HAVE_CONFIG_H */ - -#if STDC_HEADERS -# include <stdlib.h> -#else -/* - malloc and free should be declared in stdlib.h, - but if you've got a K&R compiler, they probably aren't. - */ -# ifdef MSDOS -# include <malloc.h> -# else -# ifdef VMS - extern char *malloc(); - extern void free(); -# else - extern char *malloc(); - extern int free(); -# endif -# endif - -#endif - -/* Define NULL (for *very* old compilers). */ -#ifndef NULL -# define NULL (0) -#endif - -/* - * The ctype macros don't always handle 8-bit characters correctly. - * Compensate for this here. - */ -#ifdef isascii -# undef HAVE_ISASCII /* just in case */ -# define HAVE_ISASCII 1 -#else -#endif -#if STDC_HEADERS || !HAVE_ISASCII -# define is_ascii(c) 1 -#else -# define is_ascii(c) isascii(c) -#endif - -#define is_space(c) (is_ascii(c) && isspace(c)) -#define is_alpha(c) (is_ascii(c) && isalpha(c)) -#define is_alnum(c) (is_ascii(c) && isalnum(c)) - -/* Scanning macros */ -#define isidchar(ch) (is_alnum(ch) || (ch) == '_') -#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') - -/* Forward references */ -char *skipspace(); -char *scanstring(); -int writeblanks(); -int test1(); -int convert1(); - -/* The main program */ -int -main(argc, argv) - int argc; - char *argv[]; -{ FILE *in = stdin; - FILE *out = stdout; - char *filename = 0; - char *program_name = argv[0]; - char *output_name = 0; -#define bufsize 5000 /* arbitrary size */ - char *buf; - char *line; - char *more; - char *usage = - "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n"; - /* - * In previous versions, ansi2knr recognized a --varargs switch. - * If this switch was supplied, ansi2knr would attempt to convert - * a ... argument to va_alist and va_dcl; if this switch was not - * supplied, ansi2knr would simply drop any such arguments. - * Now, ansi2knr always does this conversion, and we only - * check for this switch for backward compatibility. - */ - int convert_varargs = 1; - int output_error; - - while ( argc > 1 && argv[1][0] == '-' ) { - if ( !strcmp(argv[1], "--varargs") ) { - convert_varargs = 1; - argc--; - argv++; - continue; - } - if ( !strcmp(argv[1], "--filename") && argc > 2 ) { - filename = argv[2]; - argc -= 2; - argv += 2; - continue; - } - fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name, - argv[1]); - fprintf(stderr, usage); - exit(1); - } - switch ( argc ) - { - default: - fprintf(stderr, usage); - exit(0); - case 3: - output_name = argv[2]; - out = fopen(output_name, "w"); - if ( out == NULL ) { - fprintf(stderr, "%s: Cannot open output file %s\n", - program_name, output_name); - exit(1); - } - /* falls through */ - case 2: - in = fopen(argv[1], "r"); - if ( in == NULL ) { - fprintf(stderr, "%s: Cannot open input file %s\n", - program_name, argv[1]); - exit(1); - } - if ( filename == 0 ) - filename = argv[1]; - /* falls through */ - case 1: - break; - } - if ( filename ) - fprintf(out, "#line 1 \"%s\"\n", filename); - buf = malloc(bufsize); - if ( buf == NULL ) - { - fprintf(stderr, "Unable to allocate read buffer!\n"); - exit(1); - } - line = buf; - while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL ) - { -test: line += strlen(line); - switch ( test1(buf) ) - { - case 2: /* a function header */ - convert1(buf, out, 1, convert_varargs); - break; - case 1: /* a function */ - /* Check for a { at the start of the next line. */ - more = ++line; -f: if ( line >= buf + (bufsize - 1) ) /* overflow check */ - goto wl; - if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL ) - goto wl; - switch ( *skipspace(more, 1) ) - { - case '{': - /* Definitely a function header. */ - convert1(buf, out, 0, convert_varargs); - fputs(more, out); - break; - case 0: - /* The next line was blank or a comment: */ - /* keep scanning for a non-comment. */ - line += strlen(line); - goto f; - default: - /* buf isn't a function header, but */ - /* more might be. */ - fputs(buf, out); - strcpy(buf, more); - line = buf; - goto test; - } - break; - case -1: /* maybe the start of a function */ - if ( line != buf + (bufsize - 1) ) /* overflow check */ - continue; - /* falls through */ - default: /* not a function */ -wl: fputs(buf, out); - break; - } - line = buf; - } - if ( line != buf ) - fputs(buf, out); - free(buf); - if ( output_name ) { - output_error = ferror(out); - output_error |= fclose(out); - } else { /* out == stdout */ - fflush(out); - output_error = ferror(out); - } - if ( output_error ) { - fprintf(stderr, "%s: error writing to %s\n", program_name, - (output_name ? output_name : "stdout")); - exit(1); - } - if ( in != stdin ) - fclose(in); - return 0; -} - -/* Skip over whitespace and comments, in either direction. */ -char * -skipspace(p, dir) - register char *p; - register int dir; /* 1 for forward, -1 for backward */ -{ for ( ; ; ) - { while ( is_space(*p) ) - p += dir; - if ( !(*p == '/' && p[dir] == '*') ) - break; - p += dir; p += dir; - while ( !(*p == '*' && p[dir] == '/') ) - { if ( *p == 0 ) - return p; /* multi-line comment?? */ - p += dir; - } - p += dir; p += dir; - } - return p; -} - -/* Scan over a quoted string, in either direction. */ -char * -scanstring(p, dir) - register char *p; - register int dir; -{ - for (p += dir; ; p += dir) - if (*p == '"' && p[-dir] != '\\') - return p + dir; -} - -/* - * Write blanks over part of a string. - * Don't overwrite end-of-line characters. - */ -int -writeblanks(start, end) - char *start; - char *end; -{ char *p; - for ( p = start; p < end; p++ ) - if ( *p != '\r' && *p != '\n' ) - *p = ' '; - return 0; -} - -/* - * Test whether the string in buf is a function definition. - * The string may contain and/or end with a newline. - * Return as follows: - * 0 - definitely not a function definition; - * 1 - definitely a function definition; - * 2 - definitely a function prototype (NOT USED); - * -1 - may be the beginning of a function definition, - * append another line and look again. - * The reason we don't attempt to convert function prototypes is that - * Ghostscript's declaration-generating macros look too much like - * prototypes, and confuse the algorithms. - */ -int -test1(buf) - char *buf; -{ register char *p = buf; - char *bend; - char *endfn; - int contin; - - if ( !isidfirstchar(*p) ) - return 0; /* no name at left margin */ - bend = skipspace(buf + strlen(buf) - 1, -1); - switch ( *bend ) - { - case ';': contin = 0 /*2*/; break; - case ')': contin = 1; break; - case '{': return 0; /* not a function */ - case '}': return 0; /* not a function */ - default: contin = -1; - } - while ( isidchar(*p) ) - p++; - endfn = p; - p = skipspace(p, 1); - if ( *p++ != '(' ) - return 0; /* not a function */ - p = skipspace(p, 1); - if ( *p == ')' ) - return 0; /* no parameters */ - /* Check that the apparent function name isn't a keyword. */ - /* We only need to check for keywords that could be followed */ - /* by a left parenthesis (which, unfortunately, is most of them). */ - { static char *words[] = - { "asm", "auto", "case", "char", "const", "double", - "extern", "float", "for", "if", "int", "long", - "register", "return", "short", "signed", "sizeof", - "static", "switch", "typedef", "unsigned", - "void", "volatile", "while", 0 - }; - char **key = words; - char *kp; - unsigned len = endfn - buf; - - while ( (kp = *key) != 0 ) - { if ( strlen(kp) == len && !strncmp(kp, buf, len) ) - return 0; /* name is a keyword */ - key++; - } - } - { - char *id = p; - int len; - /* - * Check for identifier1(identifier2) and not - * identifier1(void), or identifier1(identifier2, xxxx). - */ - - while ( isidchar(*p) ) - p++; - len = p - id; - p = skipspace(p, 1); - if (*p == ',' || - (*p == ')' && (len != 4 || strncmp(id, "void", 4))) - ) - return 0; /* not a function */ - } - /* - * If the last significant character was a ), we need to count - * parentheses, because it might be part of a formal parameter - * that is a procedure. - */ - if (contin > 0) { - int level = 0; - - for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1)) - level += (*p == '(' ? 1 : *p == ')' ? -1 : 0); - if (level > 0) - contin = -1; - } - return contin; -} - -/* Convert a recognized function definition or header to K&R syntax. */ -int -convert1(buf, out, header, convert_varargs) - char *buf; - FILE *out; - int header; /* Boolean */ - int convert_varargs; /* Boolean */ -{ char *endfn; - register char *p; - /* - * The breaks table contains pointers to the beginning and end - * of each argument. - */ - char **breaks; - unsigned num_breaks = 2; /* for testing */ - char **btop; - char **bp; - char **ap; - char *vararg = 0; - - /* Pre-ANSI implementations don't agree on whether strchr */ - /* is called strchr or index, so we open-code it here. */ - for ( endfn = buf; *(endfn++) != '('; ) - ; -top: p = endfn; - breaks = (char **)malloc(sizeof(char *) * num_breaks * 2); - if ( breaks == NULL ) - { /* Couldn't allocate break table, give up */ - fprintf(stderr, "Unable to allocate break table!\n"); - fputs(buf, out); - return -1; - } - btop = breaks + num_breaks * 2 - 2; - bp = breaks; - /* Parse the argument list */ - do - { int level = 0; - char *lp = NULL; - char *rp = NULL; - char *end = NULL; - - if ( bp >= btop ) - { /* Filled up break table. */ - /* Allocate a bigger one and start over. */ - free((char *)breaks); - num_breaks <<= 1; - goto top; - } - *bp++ = p; - /* Find the end of the argument */ - for ( ; end == NULL; p++ ) - { switch(*p) - { - case ',': - if ( !level ) end = p; - break; - case '(': - if ( !level ) lp = p; - level++; - break; - case ')': - if ( --level < 0 ) end = p; - else rp = p; - break; - case '/': - if (p[1] == '*') - p = skipspace(p, 1) - 1; - break; - case '"': - p = scanstring(p, 1) - 1; - break; - default: - ; - } - } - /* Erase any embedded prototype parameters. */ - if ( lp && rp ) - writeblanks(lp + 1, rp); - p--; /* back up over terminator */ - /* Find the name being declared. */ - /* This is complicated because of procedure and */ - /* array modifiers. */ - for ( ; ; ) - { p = skipspace(p - 1, -1); - switch ( *p ) - { - case ']': /* skip array dimension(s) */ - case ')': /* skip procedure args OR name */ - { int level = 1; - while ( level ) - switch ( *--p ) - { - case ']': case ')': - level++; - break; - case '[': case '(': - level--; - break; - case '/': - if (p > buf && p[-1] == '*') - p = skipspace(p, -1) + 1; - break; - case '"': - p = scanstring(p, -1) + 1; - break; - default: ; - } - } - if ( *p == '(' && *skipspace(p + 1, 1) == '*' ) - { /* We found the name being declared */ - while ( !isidfirstchar(*p) ) - p = skipspace(p, 1) + 1; - goto found; - } - break; - default: - goto found; - } - } -found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' ) - { if ( convert_varargs ) - { *bp++ = "va_alist"; - vararg = p-2; - } - else - { p++; - if ( bp == breaks + 1 ) /* sole argument */ - writeblanks(breaks[0], |