summaryrefslogtreecommitdiffstats
path: root/libidu
diff options
context:
space:
mode:
Diffstat (limited to 'libidu')
-rw-r--r--libidu/Makefile.in57
-rw-r--r--libidu/ansi2knr.119
-rw-r--r--libidu/ansi2knr.c439
3 files changed, 22 insertions, 493 deletions
diff --git a/libidu/Makefile.in b/libidu/Makefile.in
index 9e3d79a..612a6af 100644
--- a/libidu/Makefile.in
+++ b/libidu/Makefile.in
@@ -78,7 +78,6 @@ LANGUAGE_MAP_FILE = @LANGUAGE_MAP_FILE@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LN_S = @LN_S@
-MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MKINSTALLDIRS = @MKINSTALLDIRS@
MSGFMT = @MSGFMT@
@@ -94,7 +93,7 @@ VERSION = @VERSION@
l = @l@
lispdir = @lispdir@
-AUTOMAKE_OPTIONS = ansi2knr
+AUTOMAKE_OPTIONS = ../src/ansi2knr
noinst_LIBRARIES = libidu.a
@@ -106,7 +105,7 @@ idu_DATA = id-lang.map
noinst_HEADERS = dynvec.h hash.h idfile.h scanners.h tokflags.h xnls.h
-INCLUDES = -I. -I$(srcdir) -I../lib -I$(top_srcdir)/lib -I../intl -I$(top_srcdir)/intl -I.. -I$(top_srcdir)
+INCLUDES = -I. -I$(srcdir) -I../lib -I$(top_srcdir)/lib -I../intl -I$(top_srcdir)/intl -I.. -I$(top_srcdir)
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -116,7 +115,7 @@ LIBRARIES = $(noinst_LIBRARIES)
CPPFLAGS = @CPPFLAGS@
LIBS = @LIBS@
-ANSI2KNR = @ANSI2KNR@
+ANSI2KNR = ../src/ansi2knr
libidu_a_LIBADD =
libidu_a_OBJECTS = dynvec$U.o hash$U.o idfile$U.o idread$U.o \
idwrite$U.o fnprint$U.o scanners$U.o walker$U.o
@@ -128,7 +127,7 @@ DATA = $(idu_DATA)
HEADERS = $(noinst_HEADERS)
-DIST_COMMON = Makefile.am Makefile.in ansi2knr.1 ansi2knr.c
+DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
@@ -143,7 +142,7 @@ OBJECTS = $(libidu_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .o .s
-$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnits libidu/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
@@ -175,18 +174,11 @@ distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
+../src/ansi2knr: ../src/ansi2knr.o
+ cd ../src && $(MAKE) $(AM_MAKEFLAGS) ansi2knr
-mostlyclean-krextra:
-
-clean-krextra:
- -rm -f ansi2knr
-
-distclean-krextra:
-
-maintainer-clean-krextra:
-ansi2knr: ansi2knr.o
- $(LINK) ansi2knr.o $(LIBS)
-ansi2knr.o: $(CONFIG_HEADER)
+../src/ansi2knr.o:
+ cd ../src && $(MAKE) $(AM_MAKEFLAGS) ansi2knr.o
mostlyclean-kr:
@@ -340,7 +332,7 @@ install-am: all-am
install: install-am
uninstall-am: uninstall-iduDATA
uninstall: uninstall-am
-all-am: Makefile $(ANSI2KNR) $(LIBRARIES) $(DATA) $(HEADERS)
+all-am: Makefile $(LIBRARIES) $(DATA) $(HEADERS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
@@ -358,27 +350,26 @@ distclean-generic:
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
- mostlyclean-krextra mostlyclean-kr mostlyclean-tags \
- mostlyclean-depend mostlyclean-generic
+ mostlyclean-kr mostlyclean-tags mostlyclean-depend \
+ mostlyclean-generic
mostlyclean: mostlyclean-am
-clean-am: clean-noinstLIBRARIES clean-compile clean-krextra clean-kr \
- clean-tags clean-depend clean-generic mostlyclean-am
+clean-am: clean-noinstLIBRARIES clean-compile clean-kr clean-tags \
+ clean-depend clean-generic mostlyclean-am
clean: clean-am
-distclean-am: distclean-noinstLIBRARIES distclean-compile \
- distclean-krextra distclean-kr distclean-tags \
- distclean-depend distclean-generic clean-am
+distclean-am: distclean-noinstLIBRARIES distclean-compile distclean-kr \
+ distclean-tags distclean-depend distclean-generic \
+ clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
- maintainer-clean-compile maintainer-clean-krextra \
- maintainer-clean-kr maintainer-clean-tags \
- maintainer-clean-depend maintainer-clean-generic \
- distclean-am
+ maintainer-clean-compile maintainer-clean-kr \
+ maintainer-clean-tags maintainer-clean-depend \
+ maintainer-clean-generic distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
@@ -387,9 +378,8 @@ maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
-maintainer-clean-compile mostlyclean-krextra distclean-krextra \
-clean-krextra maintainer-clean-krextra mostlyclean-kr distclean-kr \
-clean-kr maintainer-clean-kr uninstall-iduDATA install-iduDATA tags \
+maintainer-clean-compile mostlyclean-kr distclean-kr clean-kr \
+maintainer-clean-kr uninstall-iduDATA install-iduDATA tags \
mostlyclean-tags distclean-tags clean-tags maintainer-clean-tags \
distdir mostlyclean-depend distclean-depend clean-depend \
maintainer-clean-depend info-am info dvi-am dvi check check-am \
@@ -400,9 +390,6 @@ distclean-generic clean-generic maintainer-clean-generic clean \
mostlyclean distclean maintainer-clean
-ansi2knr.c: $(top_srcdir)/src/ansi2knr.c
- ln $(top_srcdir)/src/ansi2knr.c .
-
# 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.
.NOEXPORT:
diff --git a/libidu/ansi2knr.1 b/libidu/ansi2knr.1
deleted file mode 100644
index 434ce8f..0000000
--- a/libidu/ansi2knr.1
+++ /dev/null
@@ -1,19 +0,0 @@
-.TH ANSI2KNR 1 "31 December 1990"
-.SH NAME
-ansi2knr \- convert ANSI C to Kernighan & Ritchie C
-.SH SYNOPSIS
-.I ansi2knr
-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 functions 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. It will recognize a multi-line header if the last character on each line but the last is a left parenthesis or comma. 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
- - Macros that tinker with the syntax of the function header.
diff --git a/libidu/ansi2knr.c b/libidu/ansi2knr.c
deleted file mode 100644
index 9bcc4ad..0000000
--- a/libidu/ansi2knr.c
+++ /dev/null
@@ -1,439 +0,0 @@
-/* Copyright (C) 1989, 1991, 1993, 1994 Aladdin Enterprises. All rights reserved. */
-
-/* ansi2knr.c */
-/* Convert ANSI function declarations to K&R 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 for full details.
-
-Everyone is granted permission to copy, modify and redistribute
-ansi2knr, but only under the conditions described in the GNU
-General Public License. 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. Among other
-things, the copyright notice and this notice must be preserved on all
-copies.
-*/
-
-/*
- * Usage:
- ansi2knr [--varargs] input_file [output_file]
- * 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.
- * It will recognize a multi-line header provided that the last character
- * of the last line of the header is a right parenthesis,
- * and no intervening line ends with a left 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).
- * - Macros that tinker with the syntax of the function header.
- *
- * If the --varargs switch is supplied, ansi2knr will attempt to
- * convert a ... argument to va_alist and va_dcl. If this switch is not
- * supplied, ansi2knr will simply drop any such arguments.
- */
-
-/*
- * 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 94-10-10 removed CONFIG_BROKETS conditional
- lpd 94-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 89-xx-xx original version
- */
-
-/* Most of the conditionals here are to make ansi2knr work with */
-/* the GNU configure machinery. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdio.h>
-#include <ctype.h>
-
-#ifdef 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 */
-
-/*
- Without AC_CONFIG_HEADER, merely use <string.h> as in the original
- Ghostscript distribution. This loses on older BSD systems.
- */
-
-# include <string.h>
-
-#endif /* not HAVE_CONFIG_H */
-
-#ifdef 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.
- */
-char *malloc();
-void free();
-#endif
-
-/* Scanning macros */
-#define isidchar(ch) (isalnum(ch) || (ch) == '_')
-#define isidfirstchar(ch) (isalpha(ch) || (ch) == '_')
-
-/* Forward references */
-char *skipspace();
-void writeblanks();
-int test1();
-int convert1();
-
-/* The main program */
-int
-main(argc, argv)
- int argc;
- char *argv[];
-{ FILE *in, *out;
-#define bufsize 5000 /* arbitrary size */
- char *buf;
- char *line;
- int convert_varargs = 0;
- if ( argc > 1 && argv[1][0] == '-' )
- { if ( !strcmp(argv[1], "--varargs") )
- { convert_varargs = 1;
- argc--;
- argv++;
- }
- else
- { fprintf(stderr, "Unrecognized switch: %s\n", argv[1]);
- exit(1);
- }
- }
- switch ( argc )
- {
- default:
- printf("Usage: ansi2knr [--varargs] input_file [output_file]\n");
- exit(0);
- case 2:
- out = stdout;
- break;
- case 3:
- out = fopen(argv[2], "w");
- if ( out == NULL )
- { fprintf(stderr, "Cannot open output file %s\n", argv[2]);
- exit(1);
- }
- }
- in = fopen(argv[1], "r");
- if ( in == NULL )
- { fprintf(stderr, "Cannot open input file %s\n", argv[1]);
- exit(1);
- }
- fprintf(out, "#line 1 \"%s\"\n", argv[1]);
- buf = malloc(bufsize);
- line = buf;
- while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
- { switch ( test1(buf) )
- {
- case 2: /* a function header */
- convert1(buf, out, 1, convert_varargs);
- break;
- case 1: /* a function */
- convert1(buf, out, 0, convert_varargs);
- break;
- case -1: /* maybe the start of a function */
- line = buf + strlen(buf);
- if ( line != buf + (bufsize - 1) ) /* overflow check */
- continue;
- /* falls through */
- default: /* not a function */
- fputs(buf, out);
- break;
- }
- line = buf;
- }
- if ( line != buf ) fputs(buf, out);
- free(buf);
- fclose(out);
- fclose(in);
- return 0;
-}
-
-/* Skip over space and comments, in either direction. */
-char *
-skipspace(p, dir)
- register char *p;
- register int dir; /* 1 for forward, -1 for backward */
-{ for ( ; ; )
- { while ( isspace(*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;
-}
-
-/*
- * Write blanks over part of a string.
- * Don't overwrite end-of-line characters.
- */
-void
-writeblanks(start, end)
- char *start;
- char *end;
-{ char *p;
- for ( p = start; p < end; p++ )
- if ( *p != '\r' && *p != '\n' ) *p = ' ';
-}
-
-/*
- * 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 */
- 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;
- int len = endfn - buf;
- while ( (kp = *key) != 0 )
- { if ( strlen(kp) == len && !strncmp(kp, buf, len) )
- return 0; /* name is a keyword */
- key++;
- }
- }
- 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;
- 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 == 0 )
- { /* 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;
- 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 '/':
- p = skipspace(p, 1) - 1;
- break;
- default:
- ;
- }
- }
- /* Erase any embedded prototype parameters. */
- if ( lp )
- 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 '/': p = skipspace(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], p);
- else
- writeblanks(bp[-1] - 1, p);
- bp--;
- }
- }
- else
- { while ( isidchar(*p) ) p--;
- *bp++ = p+1;
- }
- p = end;
- }
- while ( *p++ == ',' );
- *bp = p;
- /* Make a special check for 'void' arglist */
- if ( bp == breaks+2 )
- { p = skipspace(breaks[0], 1);
- if ( !strncmp(p, "void", 4) )
- { p = skipspace(p+4, 1);
- if ( p == breaks[2] - 1 )
- { bp = breaks; /* yup, pretend arglist is empty */
- writeblanks(breaks[0], p + 1);
- }
- }
- }
- /* Put out the function name and left parenthesis. */
- p = buf;
- while ( p != endfn ) putc(*p, out), p++;
- /* Put out the declaration. */
- if ( header )
- { fputs(");", out);
- for ( p = breaks[0]; *p; p++ )
- if ( *p == '\r' || *p == '\n' )
- putc(*p, out);
- }
- else
- { for ( ap = breaks+1; ap < bp; ap += 2 )
- { p = *ap;
- while ( isidchar(*p) )
- putc(*p, out), p++;
- if ( ap < bp - 1 )
- fputs(", ", out);
- }
- fputs(") ", out);
- /* Put out the argument declarations */
- for ( ap = breaks+2; ap <= bp; ap += 2 )
- (*ap)[-1] = ';';
- if ( vararg != 0 )
- { *vararg = 0;
- fputs(breaks[0], out); /* any prior args */
- fputs("va_dcl", out); /* the final arg */
- fputs(bp[0], out);
- }
- else
- fputs(breaks[0], out);
- }
- free((char *)breaks);
- return 0;
-}