⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ansi2knr.c

📁 Linux下ztelnet 的rz、sz源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 1989, 1997 Aladdin Enterprises.  All rights reserved. *//* hacked up by uo to get around automake-1.3-problem *//*$Id: ansi2knr.c,v 1.5 1998/12/27 16:09:19 uwe Exp $*//* Convert ANSI C function definitions to K&R ("traditional C") syntax *//*ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY.  No author or distributor accepts responsibility to anyone for theconsequences of using it or for whether it serves any particular purpose orworks at all, unless he says so in writing.  Refer to the GNU General PublicLicense (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 licenseis supposed to have been given to you along with ansi2knr so you can knowyour rights and responsibilities.  It should be in a file named COPYLEFT,or, if there is no file named COPYLEFT, a file named COPYING.  Among otherthings, the copyright notice and this notice must be preserved on allcopies.We explicitly state here what we believe is already implied by the GPL: ifthe ansi2knr program is distributed as a separate set of sources and aseparate executable file which are aggregated on a storage medium togetherwith another program, this in itself does not bring the other program underthe GPL, nor does the mere fact that such a program or the procedures forconstructing it invoke the ansi2knr executable bring any other part of theprogram under the GPL.*//* * ----- not valid at the moment  -- uwe ------ * 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). * 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). *	- 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 97-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 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 */#define isidchar(ch) (is_alnum(ch) || (ch) == '_')#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')/* Forward references */char *skipspace();int writeblanks();int test1();int convert1();/* The main program */intmain(argc, argv)    int argc;    char *argv[];{	FILE *in = stdin;	FILE *out = stdout;	char *filename = 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 = 0;	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, "Unrecognized switch: %s\n", argv[1]);	  fprintf(stderr, usage);	  exit(1);	}	switch ( argc )	   {	default:		fprintf(stderr, usage);		exit(0);	case 2:		out = fopen(argv[1], "w");		if ( out == NULL ) {		  fprintf(stderr, "Cannot open output file %s\n", argv[2]);		  exit(1);		}		/* falls through */	case 1:		break;	   }	if ( filename )	  fprintf(out, "#line 1 \"%s\"\n", filename);	buf = malloc(bufsize);	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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -