Imported from libpng-0.99m.tar
This commit is contained in:
parent
ea3bcd7087
commit
7cd899c707
1
CHANGES
1
CHANGES
@ -267,3 +267,4 @@ version 1.00 [March 7, 1998]
|
|||||||
updated some of the makefiles (Tom Lane)
|
updated some of the makefiles (Tom Lane)
|
||||||
changed some typedefs (s_start, etc.) in pngrutil.c
|
changed some typedefs (s_start, etc.) in pngrutil.c
|
||||||
fixed dimensions of "short_months" array in pngwrite.c
|
fixed dimensions of "short_months" array in pngwrite.c
|
||||||
|
Replaced ansi2knr.c with the one from jpeg-v6
|
||||||
|
373
ansi2knr.c
373
ansi2knr.c
@ -1,26 +1,32 @@
|
|||||||
/* Copyright (C) 1989, 1991, 1993 Aladdin Enterprises. All rights reserved. */
|
|
||||||
|
|
||||||
/* ansi2knr.c */
|
/* ansi2knr.c */
|
||||||
/* Convert ANSI function declarations to K&R syntax */
|
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ansi2knr is distributed in the hope that it will be useful, but
|
ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
|
WARRANTY. No author or distributor accepts responsibility to anyone for the
|
||||||
to anyone for the consequences of using it or for whether it serves any
|
consequences of using it or for whether it serves any particular purpose or
|
||||||
particular purpose or works at all, unless he says so in writing. Refer
|
works at all, unless he says so in writing. Refer to the GNU General Public
|
||||||
to the GNU General Public License for full details.
|
License (the "GPL") for full details.
|
||||||
|
|
||||||
Everyone is granted permission to copy, modify and redistribute
|
Everyone is granted permission to copy, modify and redistribute ansi2knr,
|
||||||
ansi2knr, but only under the conditions described in the GNU
|
but only under the conditions described in the GPL. A copy of this license
|
||||||
General Public License. A copy of this license is supposed to have been
|
is supposed to have been given to you along with ansi2knr so you can know
|
||||||
given to you along with ansi2knr so you can know your rights and
|
your rights and responsibilities. It should be in a file named COPYLEFT.
|
||||||
responsibilities. It should be in a file named COPYING. Among other
|
[In the IJG distribution, the GPL appears below, not in a separate file.]
|
||||||
things, the copyright notice and this notice must be preserved on all
|
Among other things, the copyright notice and this notice must be preserved
|
||||||
copies.
|
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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
---------- Here is the GNU GPL file COPYING, referred to above ----------
|
---------- Here is the GNU GPL file COPYLEFT, referred to above ----------
|
||||||
----- These terms do NOT apply to the JPEG software itself; see README ------
|
----- These terms do NOT apply to the JPEG software itself; see README ------
|
||||||
|
|
||||||
GHOSTSCRIPT GENERAL PUBLIC LICENSE
|
GHOSTSCRIPT GENERAL PUBLIC LICENSE
|
||||||
@ -166,59 +172,142 @@ PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) GHOSTSCRIPT, EVEN IF YOU
|
|||||||
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
|
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM
|
||||||
BY ANY OTHER PARTY.
|
BY ANY OTHER PARTY.
|
||||||
|
|
||||||
-------------------- End of file COPYING ------------------------------
|
-------------------- End of file COPYLEFT ------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
#include <stdio.h>
|
* Usage:
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#ifdef BSD
|
|
||||||
#include <strings.h>
|
|
||||||
#else
|
|
||||||
#ifdef VMS
|
|
||||||
extern int strlen(), strncmp();
|
|
||||||
#else
|
|
||||||
#include <string.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
|
|
||||||
/* Usage:
|
|
||||||
ansi2knr input_file [output_file]
|
ansi2knr input_file [output_file]
|
||||||
* If no output_file is supplied, output goes to stdout.
|
* If no output_file is supplied, output goes to stdout.
|
||||||
* There are no error messages.
|
* There are no error messages.
|
||||||
*
|
*
|
||||||
* ansi2knr recognizes functions by seeing a non-keyword identifier
|
* ansi2knr recognizes function definitions by seeing a non-keyword
|
||||||
* at the left margin, followed by a left parenthesis,
|
* identifier at the left margin, followed by a left parenthesis,
|
||||||
* with a right parenthesis as the last character on the line.
|
* with a right parenthesis as the last character on the line,
|
||||||
* It will recognize a multi-line header provided that the last character
|
* and with a left brace as the first token on the following line
|
||||||
* of the last line of the header is a right parenthesis,
|
* (ignoring possible intervening comments).
|
||||||
* and no intervening line ends with a left brace or a semicolon.
|
* 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
|
* These algorithms ignore whitespace and comments, except that
|
||||||
* the function name must be the first thing on the line.
|
* the function name must be the first thing on the line.
|
||||||
* The following constructs will confuse it:
|
* The following constructs will confuse it:
|
||||||
* - Any other construct that starts at the left margin and
|
* - Any other construct that starts at the left margin and
|
||||||
* follows the above syntax (such as a macro or function call).
|
* 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
|
||||||
|
lpd 94-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 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 */
|
||||||
|
/* 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 */
|
/* Scanning macros */
|
||||||
#define isidchar(ch) (isalnum(ch) || (ch) == '_')
|
#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
|
||||||
#define isidfirstchar(ch) (isalpha(ch) || (ch) == '_')
|
#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
|
||||||
|
|
||||||
/* Forward references */
|
/* Forward references */
|
||||||
char *skipspace();
|
char *skipspace();
|
||||||
@ -227,6 +316,7 @@ int test1();
|
|||||||
int convert1();
|
int convert1();
|
||||||
|
|
||||||
/* The main program */
|
/* The main program */
|
||||||
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
@ -234,46 +324,99 @@ main(argc, argv)
|
|||||||
#define bufsize 5000 /* arbitrary size */
|
#define bufsize 5000 /* arbitrary size */
|
||||||
char *buf;
|
char *buf;
|
||||||
char *line;
|
char *line;
|
||||||
|
char *more;
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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 )
|
switch ( argc )
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
printf("Usage: ansi2knr input_file [output_file]\n");
|
printf("Usage: ansi2knr input_file [output_file]\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
case 2:
|
case 2:
|
||||||
out = stdout; break;
|
out = stdout;
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
out = fopen(argv[2], "w");
|
out = fopen(argv[2], "w");
|
||||||
if ( out == NULL )
|
if ( out == NULL )
|
||||||
{ fprintf(stderr, "Cannot open %s\n", argv[2]);
|
{ fprintf(stderr, "Cannot open output file %s\n", argv[2]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in = fopen(argv[1], "r");
|
in = fopen(argv[1], "r");
|
||||||
if ( in == NULL )
|
if ( in == NULL )
|
||||||
{ fprintf(stderr, "Cannot open %s\n", argv[1]);
|
{ fprintf(stderr, "Cannot open input file %s\n", argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
fprintf(out, "#line 1 \"%s\"\n", argv[1]);
|
fprintf(out, "#line 1 \"%s\"\n", argv[1]);
|
||||||
buf = malloc(bufsize);
|
buf = malloc(bufsize);
|
||||||
line = buf;
|
line = buf;
|
||||||
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
|
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 */
|
case 1: /* a function */
|
||||||
convert1(buf, out);
|
/* 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;
|
break;
|
||||||
case -1: /* maybe the start of a function */
|
case -1: /* maybe the start of a function */
|
||||||
line = buf + strlen(buf);
|
|
||||||
if ( line != buf + (bufsize - 1) ) /* overflow check */
|
if ( line != buf + (bufsize - 1) ) /* overflow check */
|
||||||
continue;
|
continue;
|
||||||
/* falls through */
|
/* falls through */
|
||||||
default: /* not a function */
|
default: /* not a function */
|
||||||
fputs(buf, out);
|
wl: fputs(buf, out);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
line = buf;
|
line = buf;
|
||||||
}
|
}
|
||||||
if ( line != buf ) fputs(buf, out);
|
if ( line != buf )
|
||||||
|
fputs(buf, out);
|
||||||
free(buf);
|
free(buf);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
@ -286,11 +429,14 @@ skipspace(p, dir)
|
|||||||
register char *p;
|
register char *p;
|
||||||
register int dir; /* 1 for forward, -1 for backward */
|
register int dir; /* 1 for forward, -1 for backward */
|
||||||
{ for ( ; ; )
|
{ for ( ; ; )
|
||||||
{ while ( isspace(*p) ) p += dir;
|
{ while ( is_space(*p) )
|
||||||
if ( !(*p == '/' && p[dir] == '*') ) break;
|
p += dir;
|
||||||
|
if ( !(*p == '/' && p[dir] == '*') )
|
||||||
|
break;
|
||||||
p += dir; p += dir;
|
p += dir; p += dir;
|
||||||
while ( !(*p == '*' && 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; p += dir;
|
p += dir; p += dir;
|
||||||
@ -300,13 +446,16 @@ skipspace(p, dir)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Write blanks over part of a string.
|
* Write blanks over part of a string.
|
||||||
|
* Don't overwrite end-of-line characters.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
writeblanks(start, end)
|
writeblanks(start, end)
|
||||||
char *start;
|
char *start;
|
||||||
char *end;
|
char *end;
|
||||||
{ char *p;
|
{ char *p;
|
||||||
for ( p = start; p < end; p++ ) *p = ' ';
|
for ( p = start; p < end; p++ )
|
||||||
|
if ( *p != '\r' && *p != '\n' )
|
||||||
|
*p = ' ';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,8 +465,12 @@ writeblanks(start, end)
|
|||||||
* Return as follows:
|
* Return as follows:
|
||||||
* 0 - definitely not a function definition;
|
* 0 - definitely not a function definition;
|
||||||
* 1 - definitely a function definition;
|
* 1 - definitely a function definition;
|
||||||
|
* 2 - definitely a function prototype (NOT USED);
|
||||||
* -1 - may be the beginning of a function definition,
|
* -1 - may be the beginning of a function definition,
|
||||||
* append another line and look again.
|
* 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
|
int
|
||||||
test1(buf)
|
test1(buf)
|
||||||
@ -326,17 +479,20 @@ test1(buf)
|
|||||||
char *bend;
|
char *bend;
|
||||||
char *endfn;
|
char *endfn;
|
||||||
int contin;
|
int contin;
|
||||||
|
|
||||||
if ( !isidfirstchar(*p) )
|
if ( !isidfirstchar(*p) )
|
||||||
return 0; /* no name at left margin */
|
return 0; /* no name at left margin */
|
||||||
bend = skipspace(buf + strlen(buf) - 1, -1);
|
bend = skipspace(buf + strlen(buf) - 1, -1);
|
||||||
switch ( *bend )
|
switch ( *bend )
|
||||||
{
|
{
|
||||||
|
case ';': contin = 0 /*2*/; break;
|
||||||
case ')': contin = 1; break;
|
case ')': contin = 1; break;
|
||||||
case '{':
|
case '{': return 0; /* not a function */
|
||||||
case ';': return 0; /* not a function */
|
case '}': return 0; /* not a function */
|
||||||
default: contin = -1;
|
default: contin = -1;
|
||||||
}
|
}
|
||||||
while ( isidchar(*p) ) p++;
|
while ( isidchar(*p) )
|
||||||
|
p++;
|
||||||
endfn = p;
|
endfn = p;
|
||||||
p = skipspace(p, 1);
|
p = skipspace(p, 1);
|
||||||
if ( *p++ != '(' )
|
if ( *p++ != '(' )
|
||||||
@ -357,6 +513,7 @@ test1(buf)
|
|||||||
char **key = words;
|
char **key = words;
|
||||||
char *kp;
|
char *kp;
|
||||||
int len = endfn - buf;
|
int len = endfn - buf;
|
||||||
|
|
||||||
while ( (kp = *key) != 0 )
|
while ( (kp = *key) != 0 )
|
||||||
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
|
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
|
||||||
return 0; /* name is a keyword */
|
return 0; /* name is a keyword */
|
||||||
@ -366,10 +523,13 @@ test1(buf)
|
|||||||
return contin;
|
return contin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert a recognized function definition or header to K&R syntax. */
|
||||||
int
|
int
|
||||||
convert1(buf, out)
|
convert1(buf, out, header, convert_varargs)
|
||||||
char *buf;
|
char *buf;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
int header; /* Boolean */
|
||||||
|
int convert_varargs; /* Boolean */
|
||||||
{ char *endfn;
|
{ char *endfn;
|
||||||
register char *p;
|
register char *p;
|
||||||
char **breaks;
|
char **breaks;
|
||||||
@ -377,9 +537,12 @@ convert1(buf, out)
|
|||||||
char **btop;
|
char **btop;
|
||||||
char **bp;
|
char **bp;
|
||||||
char **ap;
|
char **ap;
|
||||||
|
char *vararg = 0;
|
||||||
|
|
||||||
/* Pre-ANSI implementations don't agree on whether strchr */
|
/* Pre-ANSI implementations don't agree on whether strchr */
|
||||||
/* is called strchr or index, so we open-code it here. */
|
/* is called strchr or index, so we open-code it here. */
|
||||||
for ( endfn = buf; *(endfn++) != '('; ) ;
|
for ( endfn = buf; *(endfn++) != '('; )
|
||||||
|
;
|
||||||
top: p = endfn;
|
top: p = endfn;
|
||||||
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
|
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
|
||||||
if ( breaks == 0 )
|
if ( breaks == 0 )
|
||||||
@ -393,7 +556,10 @@ top: p = endfn;
|
|||||||
/* Parse the argument list */
|
/* Parse the argument list */
|
||||||
do
|
do
|
||||||
{ int level = 0;
|
{ int level = 0;
|
||||||
|
char *lp = NULL;
|
||||||
|
char *rp;
|
||||||
char *end = NULL;
|
char *end = NULL;
|
||||||
|
|
||||||
if ( bp >= btop )
|
if ( bp >= btop )
|
||||||
{ /* Filled up break table. */
|
{ /* Filled up break table. */
|
||||||
/* Allocate a bigger one and start over. */
|
/* Allocate a bigger one and start over. */
|
||||||
@ -406,13 +572,27 @@ top: p = endfn;
|
|||||||
for ( ; end == NULL; p++ )
|
for ( ; end == NULL; p++ )
|
||||||
{ switch(*p)
|
{ switch(*p)
|
||||||
{
|
{
|
||||||
case ',': if ( !level ) end = p; break;
|
case ',':
|
||||||
case '(': level++; break;
|
if ( !level ) end = p;
|
||||||
case ')': if ( --level < 0 ) end = p; break;
|
break;
|
||||||
case '/': p = skipspace(p, 1) - 1; break;
|
case '(':
|
||||||
default: ;
|
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 */
|
p--; /* back up over terminator */
|
||||||
/* Find the name being declared. */
|
/* Find the name being declared. */
|
||||||
/* This is complicated because of procedure and */
|
/* This is complicated because of procedure and */
|
||||||
@ -440,10 +620,16 @@ top: p = endfn;
|
|||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: goto found;
|
default:
|
||||||
|
goto found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
||||||
|
{ if ( convert_varargs )
|
||||||
|
{ *bp++ = "va_alist";
|
||||||
|
vararg = p-2;
|
||||||
|
}
|
||||||
|
else
|
||||||
{ p++;
|
{ p++;
|
||||||
if ( bp == breaks + 1 ) /* sole argument */
|
if ( bp == breaks + 1 ) /* sole argument */
|
||||||
writeblanks(breaks[0], p);
|
writeblanks(breaks[0], p);
|
||||||
@ -451,6 +637,7 @@ found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
|||||||
writeblanks(bp[-1] - 1, p);
|
writeblanks(bp[-1] - 1, p);
|
||||||
bp--;
|
bp--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{ while ( isidchar(*p) ) p--;
|
{ while ( isidchar(*p) ) p--;
|
||||||
*bp++ = p+1;
|
*bp++ = p+1;
|
||||||
@ -470,19 +657,37 @@ found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Put out the function name */
|
/* Put out the function name and left parenthesis. */
|
||||||
p = buf;
|
p = buf;
|
||||||
while ( p != endfn ) putc(*p, out), p++;
|
while ( p != endfn ) putc(*p, out), p++;
|
||||||
/* Put out the declaration */
|
/* Put out the declaration. */
|
||||||
for ( ap = breaks+1; ap < bp; ap += 2 )
|
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;
|
{ p = *ap;
|
||||||
while ( isidchar(*p) ) putc(*p, out), p++;
|
while ( isidchar(*p) )
|
||||||
if ( ap < bp - 1 ) fputs(", ", out);
|
putc(*p, out), p++;
|
||||||
|
if ( ap < bp - 1 )
|
||||||
|
fputs(", ", out);
|
||||||
}
|
}
|
||||||
fputs(") ", out);
|
fputs(") ", out);
|
||||||
/* Put out the argument declarations */
|
/* Put out the argument declarations */
|
||||||
for ( ap = breaks+2; ap <= bp; ap += 2 ) (*ap)[-1] = ';';
|
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);
|
fputs(breaks[0], out);
|
||||||
|
}
|
||||||
free((char *)breaks);
|
free((char *)breaks);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ png_warning(png_structp png_ptr, png_const_charp message)
|
|||||||
* if the character is invalid.
|
* if the character is invalid.
|
||||||
*/
|
*/
|
||||||
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
|
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||||
static const char png_digit[16] = {
|
static PNG_CONST char png_digit[16] = {
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
20
pngtest.c
20
pngtest.c
@ -52,7 +52,8 @@ static int status_pass=1;
|
|||||||
static int status_dots_requested=0;
|
static int status_dots_requested=0;
|
||||||
static int status_dots=1;
|
static int status_dots=1;
|
||||||
|
|
||||||
void read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
void
|
||||||
|
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||||
{
|
{
|
||||||
if(png_ptr == NULL || row_number > 0x3fffffffL) return;
|
if(png_ptr == NULL || row_number > 0x3fffffffL) return;
|
||||||
if(status_pass != pass)
|
if(status_pass != pass)
|
||||||
@ -70,7 +71,8 @@ void read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
|||||||
fprintf(stdout, "r");
|
fprintf(stdout, "r");
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
void
|
||||||
|
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||||
{
|
{
|
||||||
if(png_ptr == NULL || row_number > 0x3fffffffL || pass > 7) return;
|
if(png_ptr == NULL || row_number > 0x3fffffffL || pass > 7) return;
|
||||||
fprintf(stdout, "w");
|
fprintf(stdout, "w");
|
||||||
@ -84,8 +86,8 @@ void write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
|||||||
|
|
||||||
static png_uint_32 black_pixels;
|
static png_uint_32 black_pixels;
|
||||||
|
|
||||||
void count_black_pixels(png_structp png_ptr, png_row_infop row_info,
|
void
|
||||||
png_bytep data)
|
count_black_pixels(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||||
{
|
{
|
||||||
png_bytep dp = data;
|
png_bytep dp = data;
|
||||||
if(png_ptr == NULL)return;
|
if(png_ptr == NULL)return;
|
||||||
@ -203,8 +205,8 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|||||||
#define NEAR_BUF_SIZE 1024
|
#define NEAR_BUF_SIZE 1024
|
||||||
#define MIN(a,b) (a <= b ? a : b)
|
#define MIN(a,b) (a <= b ? a : b)
|
||||||
|
|
||||||
static void png_default_read_data(png_structp png_ptr, png_bytep data,
|
static void
|
||||||
png_size_t length)
|
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||||
{
|
{
|
||||||
int check;
|
int check;
|
||||||
png_byte *n_data;
|
png_byte *n_data;
|
||||||
@ -245,7 +247,8 @@ static void png_default_read_data(png_structp png_ptr, png_bytep data,
|
|||||||
#endif /* USE_FAR_KEYWORD */
|
#endif /* USE_FAR_KEYWORD */
|
||||||
|
|
||||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||||
static void png_default_flush(png_structp png_ptr)
|
static void
|
||||||
|
png_default_flush(png_structp png_ptr)
|
||||||
{
|
{
|
||||||
FILE *io_ptr;
|
FILE *io_ptr;
|
||||||
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
||||||
@ -452,7 +455,8 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
|||||||
/* END of code to test memory allocation/deallocation */
|
/* END of code to test memory allocation/deallocation */
|
||||||
|
|
||||||
/* Test one file */
|
/* Test one file */
|
||||||
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
int
|
||||||
|
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||||
{
|
{
|
||||||
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
|
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
|
||||||
png_structp read_ptr, write_ptr;
|
png_structp read_ptr, write_ptr;
|
||||||
|
@ -225,7 +225,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
|||||||
png_charp
|
png_charp
|
||||||
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||||
{
|
{
|
||||||
static const char *short_months[12][4] =
|
static const char short_months[12][4] =
|
||||||
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user