summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>1997-03-22 05:40:13 +0000
committerTom Tromey <tromey@redhat.com>1997-03-22 05:40:13 +0000
commit9bac50020eea6ffad2eb8125c23fd5b844fe79c7 (patch)
treee7a5b198a4a0c1962dfd5377c85fc4fc906966ae /lib
parent0d95b33e1ba23a63d49bdf632538c3d23ab5dfa5 (diff)
downloadautomake-9bac50020eea6ffad2eb8125c23fd5b844fe79c7.tar.gz
new files from elsewhere
Diffstat (limited to 'lib')
-rw-r--r--lib/am/progs.am2
-rw-r--r--lib/am/scripts.am8
-rw-r--r--lib/ansi2knr.127
-rw-r--r--lib/ansi2knr.c182
4 files changed, 149 insertions, 70 deletions
diff --git a/lib/am/progs.am b/lib/am/progs.am
index 3d255ef5d..68689e8d0 100644
--- a/lib/am/progs.am
+++ b/lib/am/progs.am
@@ -27,7 +27,7 @@ install-@DIR@PROGRAMS: $(@DIR@_PROGRAMS)
## Note that we explicitly set the libtool mode. This avoids any
## lossage if the install program doesn't have a name that libtool
## expects.
- echo " @LIBTOOL --mode=install@ $(INSTALL_PROGRAM) $$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`"; \
+ echo " @LIBTOOL --mode=install@ $(INSTALL_PROGRAM) $$p@EXEEXT@ $(@DIR@dir)/`echo $$p|sed '$(transform)'`@EXEEXT@"; \
@LIBTOOL --mode=install@ $(INSTALL_PROGRAM) $$p@EXEEXT@ $(@DIR@dir)/`echo $$p|sed '$(transform)'`@EXEEXT@; \
else :; fi; \
done
diff --git a/lib/am/scripts.am b/lib/am/scripts.am
index 6700f4462..9ca60ff26 100644
--- a/lib/am/scripts.am
+++ b/lib/am/scripts.am
@@ -22,11 +22,11 @@ install-@DIR@SCRIPTS: $(@DIR@_SCRIPTS)
## a syntax error in sh.
@list="$(@DIR@_SCRIPTS)"; for p in $$list; do \
if test -f $$p; then \
- echo " $(INSTALL_SCRIPT) $$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`"; \
- $(INSTALL_SCRIPT) $$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`; \
+ echo " $(INSTALL_SCRIPT) $$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`@EXEEXT@"; \
+ $(INSTALL_SCRIPT) $$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`@EXEEXT@; \
else if test -f $(srcdir)/$$p; then \
- echo " $(INSTALL_SCRIPT) $(srcdir)/$$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`"; \
- $(INSTALL_SCRIPT) $(srcdir)/$$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`; \
+ echo " $(INSTALL_SCRIPT) $(srcdir)/$$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`@EXEEXT@"; \
+ $(INSTALL_SCRIPT) $(srcdir)/$$p $(@DIR@dir)/`echo $$p|sed '$(transform)'`@EXEEXT@; \
else :; fi; fi; \
done
diff --git a/lib/ansi2knr.1 b/lib/ansi2knr.1
index 434ce8f04..f9ee5a631 100644
--- a/lib/ansi2knr.1
+++ b/lib/ansi2knr.1
@@ -1,19 +1,36 @@
-.TH ANSI2KNR 1 "31 December 1990"
+.TH ANSI2KNR 1 "19 Jan 1996"
.SH NAME
ansi2knr \- convert ANSI C to Kernighan & Ritchie C
.SH SYNOPSIS
.I ansi2knr
-input_file output_file
+[--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 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.
+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).
+ - 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.
+ - 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
index 22e68e1c8..64a4578a2 100644
--- a/lib/ansi2knr.c
+++ b/lib/ansi2knr.c
@@ -1,5 +1,3 @@
-/* Copyright (C) 1989, 1991, 1993, 1994, 1995 Aladdin Enterprises. All rights reserved. */
-
/* ansi2knr.c */
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
@@ -34,22 +32,33 @@ program under the GPL.
*
* 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 or right brace or a semicolon.
+ * 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.
* 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.
+ * - Some macros that tinker with the syntax of the function header.
*/
/*
* 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 96-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 96-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 95-06-22 removed #ifndefs whose sole purpose was to define
+ undefined preprocessor symbols as 0; changed all #ifdefs
+ for configuration symbols to #ifs
lpd 95-04-05 changed copyright notice to make it clear that
including ansi2knr in a program does not bring the entire
program under the GPL
@@ -67,16 +76,16 @@ program under the GPL.
*/
/* Most of the conditionals here are to make ansi2knr work with */
-/* the GNU configure machinery. */
+/* or without the GNU configure machinery. */
-#ifdef HAVE_CONFIG_H
+#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>
-#ifdef HAVE_CONFIG_H
+#if HAVE_CONFIG_H
/*
For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
@@ -91,40 +100,49 @@ program under the GPL.
#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.
- */
+/* Otherwise do it the hard way */
-# include <string.h>
+# ifdef BSD
+# include <strings.h>
+# else
+# ifdef VMS
+ extern int strlen(), strncmp();
+# else
+# include <string.h>
+# endif
+# endif
#endif /* not HAVE_CONFIG_H */
-#ifdef STDC_HEADERS
+#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.
*/
-char *malloc();
-void free();
+# ifdef MSDOS
+# include <malloc.h>
+# else
+# ifdef VMS
+ extern char *malloc();
+ extern void free();
+# else
+ extern char *malloc();
+ extern int free();
+# endif
+# endif
+
#endif
/*
* The ctype macros don't always handle 8-bit characters correctly.
* Compensate for this here.
*/
-#ifndef STDC_HEADERS
-# define STDC_HEADERS 0
-#endif
#ifdef isascii
# undef HAVE_ISASCII /* just in case */
# define HAVE_ISASCII 1
#else
-# ifndef HAVE_ISASCII
-# define HAVE_ISASCII 0
-# endif
#endif
#if STDC_HEADERS || !HAVE_ISASCII
# define is_ascii(c) 1
@@ -142,7 +160,7 @@ void free();
/* Forward references */
char *skipspace();
-void writeblanks();
+int writeblanks();
int test1();
int convert1();
@@ -155,6 +173,7 @@ main(argc, argv)
#define bufsize 5000 /* arbitrary size */
char *buf;
char *line;
+ char *more;
/*
* In previous versions, ansi2knr recognized a --varargs switch.
* If this switch was supplied, ansi2knr would attempt to convert
@@ -200,26 +219,53 @@ main(argc, argv)
buf = malloc(bufsize);
line = buf;
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
- { switch ( test1(buf) )
+ {
+test: line += strlen(line);
+ 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);
+ /* 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 */
- line = buf + strlen(buf);
if ( line != buf + (bufsize - 1) ) /* overflow check */
- continue;
+ continue;
/* falls through */
default: /* not a function */
- fputs(buf, out);
+wl: fputs(buf, out);
break;
}
line = buf;
}
- if ( line != buf ) fputs(buf, out);
+ if ( line != buf )
+ fputs(buf, out);
free(buf);
fclose(out);
fclose(in);
@@ -232,11 +278,14 @@ 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;
+ { 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?? */
+ { if ( *p == 0 )
+ return p; /* multi-line comment?? */
p += dir;
}
p += dir; p += dir;
@@ -248,13 +297,15 @@ skipspace(p, dir)
* Write blanks over part of a string.
* Don't overwrite end-of-line characters.
*/
-void
+int
writeblanks(start, end)
char *start;
char *end;
{ char *p;
for ( p = start; p < end; p++ )
- if ( *p != '\r' && *p != '\n' ) *p = ' ';
+ if ( *p != '\r' && *p != '\n' )
+ *p = ' ';
+ return 0;
}
/*
@@ -277,25 +328,27 @@ test1(buf)
char *bend;
char *endfn;
int contin;
+
if ( !isidfirstchar(*p) )
- return 0; /* no name at left margin */
+ 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;
+ 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++;
+ while ( isidchar(*p) )
+ p++;
endfn = p;
p = skipspace(p, 1);
if ( *p++ != '(' )
- return 0; /* not a function */
+ return 0; /* not a function */
p = skipspace(p, 1);
if ( *p == ')' )
- return 0; /* no parameters */
+ 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). */
@@ -309,9 +362,10 @@ test1(buf)
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 */
+ return 0; /* name is a keyword */
key++;
}
}
@@ -327,15 +381,21 @@ convert1(buf, out, header, convert_varargs)
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++) != '('; ) ;
+ for ( endfn = buf; *(endfn++) != '('; )
+ ;
top: p = endfn;
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
if ( breaks == 0 )
@@ -352,6 +412,7 @@ top: p = endfn;
char *lp = NULL;
char *rp;
char *end = NULL;
+
if ( bp >= btop )
{ /* Filled up break table. */
/* Allocate a bigger one and start over. */
@@ -364,21 +425,21 @@ top: p = endfn;
for ( ; end == NULL; p++ )
{ switch(*p)
{
- case ',':
+ case ',':
if ( !level ) end = p;
break;
- case '(':
+ case '(':
if ( !level ) lp = p;
level++;
break;
- case ')':
+ case ')':
if ( --level < 0 ) end = p;
else rp = p;
break;
- case '/':
+ case '/':
p = skipspace(p, 1) - 1;
break;
- default:
+ default:
;
}
}
@@ -393,26 +454,27 @@ top: p = endfn;
{ p = skipspace(p - 1, -1);
switch ( *p )
{
- case ']': /* skip array dimension(s) */
- case ')': /* skip procedure args OR name */
+ 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: ;
+ 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;
+ p = skipspace(p, 1) + 1;
goto found;
}
break;
- default: goto found;
+ default:
+ goto found;
}
}
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )