home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-26 | 45.2 KB | 1,269 lines |
- Newsgroups: comp.sources.misc
- From: Lutz Prechelt <prechelt@i41s14.ira.uka.de>
- Subject: v22i066: crefine - C-Refine preprocessor, Part04/04
- Message-ID: <1991Aug26.032439.15277@sparky.IMD.Sterling.COM>
- X-Md4-Signature: 49cda8a68d998752ae112de6e81040ce
- Date: Mon, 26 Aug 1991 03:24:39 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: Lutz Prechelt <prechelt@i41s14.ira.uka.de>
- Posting-number: Volume 22, Issue 66
- Archive-name: crefine/part04
- Environment: UNIX, MS-DOS, TOS, C, C++, Objective-C
-
- #! /bin/sh
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: COPYING Makefile cr_decl.h cr_talk.cr cr_texts.h erato.c
- # erato.cr getargs.h std.h
- # Wrapped by kent@sparky on Sun Aug 25 21:56:47 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 4 (of 4)."'
- if test -f 'COPYING' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'COPYING'\"
- else
- echo shar: Extracting \"'COPYING'\" \(12488 characters\)
- sed "s/^X//" >'COPYING' <<'END_OF_FILE'
- X
- X GNU GENERAL PUBLIC LICENSE
- X Version 1, February 1989
- X
- X Copyright (C) 1989 Free Software Foundation, Inc.
- X 675 Mass Ave, Cambridge, MA 02139, USA
- X Everyone is permitted to copy and distribute verbatim copies
- X of this license document, but changing it is not allowed.
- X
- X Preamble
- X
- X The license agreements of most software companies try to keep users
- Xat the mercy of those companies. By contrast, our General Public
- XLicense is intended to guarantee your freedom to share and change free
- Xsoftware--to make sure the software is free for all its users. The
- XGeneral Public License applies to the Free Software Foundation's
- Xsoftware and to any other program whose authors commit to using it.
- XYou can use it for your programs, too.
- X
- X When we speak of free software, we are referring to freedom, not
- Xprice. Specifically, the General Public License is designed to make
- Xsure that you have the freedom to give away or sell copies of free
- Xsoftware, that you receive source code or can get it if you want it,
- Xthat you can change the software or use pieces of it in new free
- Xprograms; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- Xanyone to deny you these rights or to ask you to surrender the rights.
- XThese restrictions translate to certain responsibilities for you if you
- Xdistribute copies of the software, or if you modify it.
- X
- X For example, if you distribute copies of a such a program, whether
- Xgratis or for a fee, you must give the recipients all the rights that
- Xyou have. You must make sure that they, too, receive or can get the
- Xsource code. And you must tell them their rights.
- X
- X We protect your rights with two steps: (1) copyright the software, and
- X(2) offer you this license which gives you legal permission to copy,
- Xdistribute and/or modify the software.
- X
- X Also, for each author's protection and ours, we want to make certain
- Xthat everyone understands that there is no warranty for this free
- Xsoftware. If the software is modified by someone else and passed on, we
- Xwant its recipients to know that what they have is not the original, so
- Xthat any problems introduced by others will not reflect on the original
- Xauthors' reputations.
- X
- X The precise terms and conditions for copying, distribution and
- Xmodification follow.
- X
- X GNU GENERAL PUBLIC LICENSE
- X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- X
- X 0. This License Agreement applies to any program or other work which
- Xcontains a notice placed by the copyright holder saying it may be
- Xdistributed under the terms of this General Public License. The
- X"Program", below, refers to any such program or work, and a "work based
- Xon the Program" means either the Program or any work containing the
- XProgram or a portion of it, either verbatim or with modifications. Each
- Xlicensee is addressed as "you".
- X
- X 1. You may copy and distribute verbatim copies of the Program's source
- Xcode as you receive it, in any medium, provided that you conspicuously and
- Xappropriately publish on each copy an appropriate copyright notice and
- Xdisclaimer of warranty; keep intact all the notices that refer to this
- XGeneral Public License and to the absence of any warranty; and give any
- Xother recipients of the Program a copy of this General Public License
- Xalong with the Program. You may charge a fee for the physical act of
- Xtransferring a copy.
- X
- X 2. You may modify your copy or copies of the Program or any portion of
- Xit, and copy and distribute such modifications under the terms of Paragraph
- X1 above, provided that you also do the following:
- X
- X a) cause the modified files to carry prominent notices stating that
- X you changed the files and the date of any change; and
- X
- X b) cause the whole of any work that you distribute or publish, that
- X in whole or in part contains the Program or any part thereof, either
- X with or without modifications, to be licensed at no charge to all
- X third parties under the terms of this General Public License (except
- X that you may choose to grant warranty protection to some or all
- X third parties, at your option).
- X
- X c) If the modified program normally reads commands interactively when
- X run, you must cause it, when started running for such interactive use
- X in the simplest and most usual way, to print or display an
- X announcement including an appropriate copyright notice and a notice
- X that there is no warranty (or else, saying that you provide a
- X warranty) and that users may redistribute the program under these
- X conditions, and telling the user how to view a copy of this General
- X Public License.
- X
- X d) You may charge a fee for the physical act of transferring a
- X copy, and you may at your option offer warranty protection in
- X exchange for a fee.
- X
- XMere aggregation of another independent work with the Program (or its
- Xderivative) on a volume of a storage or distribution medium does not bring
- Xthe other work under the scope of these terms.
- X
- X 3. You may copy and distribute the Program (or a portion or derivative of
- Xit, under Paragraph 2) in object code or executable form under the terms of
- XParagraphs 1 and 2 above provided that you also do one of the following:
- X
- X a) accompany it with the complete corresponding machine-readable
- X source code, which must be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X b) accompany it with a written offer, valid for at least three
- X years, to give any third party free (except for a nominal charge
- X for the cost of distribution) a complete machine-readable copy of the
- X corresponding source code, to be distributed under the terms of
- X Paragraphs 1 and 2 above; or,
- X
- X c) accompany it with the information you received as to where the
- X corresponding source code may be obtained. (This alternative is
- X allowed only for noncommercial distribution and only if you
- X received the program in object code or executable form alone.)
- X
- XSource code for a work means the preferred form of the work for making
- Xmodifications to it. For an executable file, complete source code means
- Xall the source code for all modules it contains; but, as a special
- Xexception, it need not include source code for modules which are standard
- Xlibraries that accompany the operating system on which the executable
- Xfile runs, or for standard header files or definitions files that
- Xaccompany that operating system.
- X
- X 4. You may not copy, modify, sublicense, distribute or transfer the
- XProgram except as expressly provided under this General Public License.
- XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
- Xthe Program is void, and will automatically terminate your rights to use
- Xthe Program under this License. However, parties who have received
- Xcopies, or rights to use copies, from you under this General Public
- XLicense will not have their licenses terminated so long as such parties
- Xremain in full compliance.
- X
- X 5. By copying, distributing or modifying the Program (or any work based
- Xon the Program) you indicate your acceptance of this license to do so,
- Xand all its terms and conditions.
- X
- X 6. Each time you redistribute the Program (or any work based on the
- XProgram), the recipient automatically receives a license from the original
- Xlicensor to copy, distribute or modify the Program subject to these
- Xterms and conditions. You may not impose any further restrictions on the
- Xrecipients' exercise of the rights granted herein.
- X
- X 7. The Free Software Foundation may publish revised and/or new versions
- Xof the General Public License from time to time. Such new versions will
- Xbe similar in spirit to the present version, but may differ in detail to
- Xaddress new problems or concerns.
- X
- XEach version is given a distinguishing version number. If the Program
- Xspecifies a version number of the license which applies to it and "any
- Xlater version", you have the option of following the terms and conditions
- Xeither of that version or of any later version published by the Free
- XSoftware Foundation. If the Program does not specify a version number of
- Xthe license, you may choose any version ever published by the Free Software
- XFoundation.
- X
- X 8. If you wish to incorporate parts of the Program into other free
- Xprograms whose distribution conditions are different, write to the author
- Xto ask for permission. For software which is copyrighted by the Free
- XSoftware Foundation, write to the Free Software Foundation; we sometimes
- Xmake exceptions for this. Our decision will be guided by the two goals
- Xof preserving the free status of all derivatives of our free software and
- Xof promoting the sharing and reuse of software generally.
- X
- X NO WARRANTY
- X
- X 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
- XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
- XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
- XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
- XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
- XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
- XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
- XREPAIR OR CORRECTION.
- X
- X 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
- XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
- XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
- XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
- XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
- XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
- XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
- XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
- XPOSSIBILITY OF SUCH DAMAGES.
- X
- X END OF TERMS AND CONDITIONS
- X
- X Appendix: How to Apply These Terms to Your New Programs
- X
- X If you develop a new program, and you want it to be of the greatest
- Xpossible use to humanity, the best way to achieve this is to make it
- Xfree software which everyone can redistribute and change under these
- Xterms.
- X
- X To do so, attach the following notices to the program. It is safest to
- Xattach them to the start of each source file to most effectively convey
- Xthe exclusion of warranty; and each file should have at least the
- X"copyright" line and a pointer to where the full notice is found.
- X
- X <one line to give the program's name and a brief idea of what it does.>
- X Copyright (C) 19yy <name of author>
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- XAlso add information on how to contact you by electronic and paper mail.
- X
- XIf the program is interactive, make it output a short notice like this
- Xwhen it starts in an interactive mode:
- X
- X Gnomovision version 69, Copyright (C) 19xx name of author
- X Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- X This is free software, and you are welcome to redistribute it
- X under certain conditions; type `show c' for details.
- X
- XThe hypothetical commands `show w' and `show c' should show the
- Xappropriate parts of the General Public License. Of course, the
- Xcommands you use may be called something other than `show w' and `show
- Xc'; they could even be mouse-clicks or menu items--whatever suits your
- Xprogram.
- X
- XYou should also get your employer (if you work as a programmer) or your
- Xschool, if any, to sign a "copyright disclaimer" for the program, if
- Xnecessary. Here a sample; alter the names:
- X
- X Yoyodyne, Inc., hereby disclaims all copyright interest in the
- X program `Gnomovision' (a program to direct compilers to make passes
- X at assemblers) written by James Hacker.
- X
- X <signature of Ty Coon>, 1 April 1989
- X Ty Coon, President of Vice
- X
- XThat's all there is to it!
- END_OF_FILE
- if test 12488 -ne `wc -c <'COPYING'`; then
- echo shar: \"'COPYING'\" unpacked with wrong size!
- fi
- # end of 'COPYING'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(1694 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- X#Makefile for C-Refine
- X#Author: Lutz Prechelt, Karlsruhe, Germany
- X#Date : 11.06.91
- X
- X# Usage:
- X# Perhaps change the macro CC below if you want to use a different compiler
- X# and in CFLAGS set 'ansi=1' if it is ANSI-C.
- X# Then call
- X# make crefine
- X# to get a version of crefine that is at first made from
- X# the unC-Refine'd sources of C-Refine.
- X# With this version of C-Refine you can then bootstrap C-Refine by
- X# 'touch'ing the .cr files and again executing
- X# make crefine
- X# You should normally remove the -n0 option from CRFLAGS so to get only such
- X# messages from your compiler that point to the .cr file instead of to
- X# the .c file
- X#
- X# Translation is done in two phases with separate rules:
- X# First from .cr to .c if the .cr file is newer,
- X# then from .c to .o
- X# In the makefiles of bigger projects I usually prefer to hold all the
- X# .c files in some temp directory, so that they don't clobber your working
- X# directory and to have a single rule going from .cr to .o
- X# Be careful to keep a copy of 'crefine' when experimenting
- X# with changes!
- X#
- XCLD= getargs.o crefine.o cr_talk.o cr_getln.o
- XCS= getargs.c crefine.c cr_talk.c cr_getln.c
- XHS= getargs.h crefine.h cr_talk.h cr_getln.h std.h cr_texts.h
- X
- XCR=crefine
- XCRFLAGS= -ac -s- -T8
- XCC=cc
- XCFLAGS= -I"." -DNDEBUG=1 -Ddebug=0 -Dunix=1 -Dms_dos=0 -Dansi=0 -Ddeutsch=0
- XLDFLAGS=
- X
- X%.c: %.cr
- X $(CR) $(CRFLAGS) $*.cr
- X
- X%.o: %.c
- X $(CC) $(CFLAGS) -c $<
- X
- Xcrefine: a.out
- X mv a.out crefine
- X
- Xa.out: $(CLD)
- X $(CC) $(LDFLAGS) $(CLD)
- X
- Xgetargs.o: getargs.h std.h
- X
- Xcrefine.o: cr_decl.h getargs.h std.h
- X
- Xcr_talk.o: cr_decl.h cr_texts.h std.h
- X
- Xcr_getln.o: cr_decl.h std.h
- X
- Xclean:
- X -rm core a.out *~ crefine.c cr_getln.c cr_talk.c *.o
- X
- X
- X
- END_OF_FILE
- if test 1694 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'cr_decl.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'cr_decl.h'\"
- else
- echo shar: Extracting \"'cr_decl.h'\" \(5687 characters\)
- sed "s/^X//" >'cr_decl.h' <<'END_OF_FILE'
- X/*************************************************************************
- XProject : C-Refine Precompiler
- XModule : Declarations for global Functions, Types and Data
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 11.06.91 Version 16
- XCompiler: ANSI C
- X**************************************************************************/
- X/*
- X Copyright (C) 1988,89,90,91 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- X/*************************************************************************
- X*********************** C - R e f i n e **********************************
- X**************************************************************************/
- X
- X#include "std.h"
- X
- X/***************** globale Typen und Konstanten **************************/
- X
- X#define normal 1 /* Types for LINE_INFO */
- X#define empty 2 /* empty line */
- X#define refcall 3 /* refinement call */
- X#define refcallr 4 /* dito with "removed semicolon" */
- X#define refdecl 5 /* refinement declaration */
- X#define leave 6 /* leave construct */
- X
- X#define TAB 9 /* has to be recognized */
- X
- X#if ms_dos
- X#define std_refinementsymbol 175 /* IBM: Double arrow to the right */
- X#else
- X#define std_refinementsymbol 96 /* ASCII: back quote */
- X#endif
- X
- X#if ms_dos
- X#define STD_MAXLINELENGTH 500
- X#define STD_MAXLINE 800 /* max. nr of lines per function */
- X#define STD_MAXREF 100 /* max. nr of refinements per function */
- X#define STD_S_SIZE 60000 /* wanted size of line buffer in bytes */
- X#else
- X#define STD_MAXLINELENGTH 500
- X#define STD_MAXLINE 2500
- X#define STD_MAXREF 200
- X#define STD_S_SIZE 150000
- X#endif
- X#define STD_MAXERRORS 20
- X#define STD_MAXWARNINGS 30
- X
- Xtypedef char *charp; /* Needed: the SUN-OS Compiler is a fool */
- X
- Xtypedef struct { int type, /* see #defines */
- X indent, /* indent+length = width of line */
- X level, /* Level at beginning of line */
- X line_no, /* line number in source file */
- X length; /* stored length in bytes */
- X charp start;
- X } LINE_INFO;
- X
- Xtypedef struct { charp name;
- X int firstentry, /* pointer into LINE_INFO array */
- X calls, /* nr of usages of this refinement */
- X semicolons; /* nr of statements in body */
- X unsigned active:1, /* we are just in it ? */
- X leave_it:1; /* there is a 'leave' for it ? */
- X } REF_INFO;
- X
- Xtypedef LINE_INFO *LINES;
- X
- Xtypedef REF_INFO *REFS;
- X
- X/************************* External Functions ****************************/
- X
- X/***** crefine.c *****/
- Xextern int crefine A((int, charp*));
- X/***** cr_getln.c *****/
- Xextern void get_line A((FILE*, LINE_INFO*, int*));
- X/***** cr_talk *****/
- Xextern void cout A((int));
- Xextern void error A((charp[], charp, int));
- Xextern void fatal_error A((charp[], charp, int));
- Xextern void warning A((charp[], charp, int, int));
- X
- X/************************ globale Daten **********************************/
- X
- X
- X/* Meldungstexte */
- Xextern charp
- X usagestring[],
- X versionstring[],
- X expirestring[],
- X Tlistline[],
- X Tnear[],
- X Thas_expired[],
- X Wempty_function[],
- X Wlong_ref[],
- X Wref_often_used[],
- X Wref_unused[],
- X Wref_empty[],
- X Wcol0[],
- X Wnesting[],
- X Wmuch_indent[],
- X Wlong_string[],
- X Wlong_char[],
- X Eopen[],
- X Ereadinput[],
- X Ewriteoutput[],
- X Elevel0_ref[],
- X Elines_in_func[],
- X Ebytes_in_func[],
- X Eref_not_decl[],
- X Erecursive_ref[],
- X Eunknown_leave[],
- X Eleave_unpresent[],
- X Eref_multi_decl[],
- X Ememory[],
- X Eeof_brace[],
- X Eeof_comment[],
- X Eeof_string[],
- X Eeof_char[],
- X Erefdecl_syntax[],
- X Erefdecl_nested[],
- X Emany_braces[],
- X Erefname_missing[],
- X Emany_errors[],
- X Emany_warnings[];
- X
- X#ifdef DATA_HERE
- X#define extern
- X#endif
- X/***** Control *****/
- X#define FEEDBACK_INTERVAL 64
- Xextern bool option_anyway,
- X option_comment,
- X option_feedback,
- X option_indent,
- X option_ibmchars,
- X option_list,
- X option_cplusplus,
- X option_quiet,
- X option_small,
- X stop_processing;
- X
- Xextern int refinementsymbol,
- X tabsize,
- X numbering_level,
- X msg_type,
- X warning_level,
- X maxerrors,
- X maxwarnings;
- X
- X/***** Buffer *****/
- Xextern charp b, /* Puffer fuer eine Zeile */
- X s, /* Naechste freie Position im Zeilenspeicher */
- X s_root; /* Beginn des Zeilenspeichers */
- Xextern unsigned
- X maxline,
- X maxref,
- X b_size, /* Groesse des Puffers fuer eine Zeile */
- X s_size; /* Gesamtgroesse des Zeilenspeichers */
- X
- X/***** Status *****/
- Xextern int errors, warnings,
- X line_no;
- Xextern bool error_in_this_function;
- Xextern char name_in[200], /* Dateinamen: Eingabedatei/Ausgabedatei */
- X modified_name_in[200], /* (mit verdoppelten Backslashes) */
- X name_out[200];
- X
- X
- X#ifdef DATA_HERE
- X#undef extern
- X#endif
- END_OF_FILE
- if test 5687 -ne `wc -c <'cr_decl.h'`; then
- echo shar: \"'cr_decl.h'\" unpacked with wrong size!
- fi
- # end of 'cr_decl.h'
- fi
- if test -f 'cr_talk.cr' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'cr_talk.cr'\"
- else
- echo shar: Extracting \"'cr_talk.cr'\" \(3405 characters\)
- sed "s/^X//" >'cr_talk.cr' <<'END_OF_FILE'
- X/*************************************************************************
- XProject : C-Refine Precompiler
- XModule : Output functions for messages
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 11.06.91 Version 16
- XCompiler: ANSI C, C-Refine
- X**************************************************************************/
- X/*
- X Copyright (C) 1988,89,90,91 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- X/************************************************************************
- X*********************** C - R e f i n e *********************************
- X*************************************************************************/
- X
- X#include <stdio.h>
- X#include <string.h>
- X
- X#include "cr_decl.h" /* global Functions, Types and Data */
- X#include "cr_texts.h" /* message texts */
- X
- Xstatic void error_message A((charp[], charp[], charp, int));
- X
- X/************************* cout *******************************************/
- X
- Xextern void cout (i)
- X int i;
- X{
- X /* Writes number i on stderr (which is assumed to be a screen)
- X with length five and positions the cursor back to the starting
- X position with five backspaces.
- X This is not very fast, but that doesn't matter.
- X */
- X fprintf (stderr, "%5d\b\b\b\b\b", i);
- X}
- X
- X/************************ error *******************************************/
- X
- Xstatic void error_message (type, message, object, line)
- X charp type[], message[];
- X charp object;
- X int line;
- X{
- X fprintf (stdout, "\"%s\", line %d, %s: %s\n", name_in,
- X line, type[msg_type], message[msg_type]);
- X if (object != NULL) {
- X char *nl = strchr (object, '\n');
- X if (nl != NULL) /* remove newline from object */
- X *nl = 0;
- X fprintf (stdout, " %s \"%s\"\n", Tnear[msg_type], object);
- X if (nl != NULL)
- X *nl = '\n';
- X }
- X}
- X
- X
- Xextern void error (message, object, line)
- X charp message[];
- X charp object;
- X int line;
- X{
- X error_message (Terror, message, object, line);
- X if (++errors > maxerrors)
- X fatal_error (Emany_errors, "(-----ManteldesSchweigens-----)", line);
- X error_in_this_function = true;
- X}
- X
- X/************************ fatal_error *************************************/
- X
- Xextern void fatal_error (message, object, line)
- X charp message[];
- X charp object;
- X int line;
- X{
- X error_message (Tfatal_error, message, object, line);
- X stop_processing = true;
- X errors++;
- X}
- X
- X/************************ warning *****************************************/
- X
- Xextern void warning (message, object, line, level)
- X charp message[];
- X charp object;
- X int line, level;
- X{
- X if (!error_in_this_function && level <= warning_level) {
- X /* don't be too verbose */
- X error_message (Twarning, message, object, line);
- X if (++warnings > maxwarnings)
- X fatal_error (Emany_warnings, NULL, line);
- X }
- X}
- X
- END_OF_FILE
- if test 3405 -ne `wc -c <'cr_talk.cr'`; then
- echo shar: \"'cr_talk.cr'\" unpacked with wrong size!
- fi
- # end of 'cr_talk.cr'
- fi
- if test -f 'cr_texts.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'cr_texts.h'\"
- else
- echo shar: Extracting \"'cr_texts.h'\" \(8508 characters\)
- sed "s/^X//" >'cr_texts.h' <<'END_OF_FILE'
- X/*************************************************************************
- XProject : C-Refine Precompiler
- XModule : Message texts
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 29.01.91 Version 15
- XCompiler: ANSI C
- X**************************************************************************/
- X/*
- X Copyright (C) 1988,89,90,91 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- Xcharp
- X usagestring [] = {
- X "[optionen] eingabedatei [ausgabedatei] [optionen]",
- X "[options] inputfile [outputfile] [options]",
- X "[optionen] eingabedatei [ausgabedatei] [optionen]"
- X },
- X versionstring [] = {
- X "Version 2.4 Januar '91",
- X "Version 2.4 January '91",
- X "Version 2.4 Jaenner '91"
- X },
- X expirestring [] = {
- X "gueltig bis",
- X "expires",
- X "entschlaeft am"
- X },
- X Terror [] = {
- X "Fehler",
- X "error",
- X "Fehler"
- X },
- X Twarning [] = {
- X "Warnung",
- X "warning",
- X "Warnung"
- X },
- X Tfatal_error [] = {
- X "Fataler Fehler",
- X "fatal error",
- X "fatal, fatal"
- X },
- X Tlistline [] = {
- X " /* %s (Ebene %d) */",
- X " /* %s (Level %d) */",
- X " /* %s (Ebene %d) */"
- X },
- X Tnear [] = {
- X "bei",
- X "near",
- X "bei"
- X },
- X Thas_expired [] = {
- X "--- Diese (Test-)Version ist nicht mehr gueltig ---",
- X "--- this (test-)version has expired ---",
- X "--- Diese (Test-)Version ist friedlich entschlafen ---"
- X },
- X Wempty_function [] = {
- X "Leere Funktion (aber mit Refinements)",
- X "function is empty (but has refinements)",
- X "Viel Gelaber und nix dahinter"
- X },
- X Wlong_ref [] = {
- X "Sehr langes Refinement",
- X "very long refinement",
- X "Ist das Refinement nicht a bisserl arg lang ?"
- X },
- X Wref_often_used [] = {
- X "Refinement ueber 5 mal benutzt",
- X "refinement used more than 5 times",
- X "hektisches ich-bin-ueberall-Refinement"
- X },
- X Wref_unused [] = {
- X "Refinement wird nicht benutzt",
- X "refinement unused",
- X "ein Refinement steht im Walde...."
- X },
- X Wref_empty [] = {
- X "Leeres Refinement",
- X "refinement is empty",
- X "Was will uns dieses Refinement sagen ?"
- X },
- X Wcol0 [] = {
- X "Unerwartete Zeichen in Spalte 0",
- X "unexpected character in column 0",
- X "Was tobt denn da in Spalte 0 rum ?"
- X },
- X Wnesting [] = {
- X "Sehr tiefe Blockverschachtelung",
- X "deep block-nesting",
- X "SCHEISS STIL. Verschachtele doch nicht so tief"
- X },
- X Wmuch_indent [] = {
- X "Einrueckung evtl. nicht mehr darstellbar",
- X "perhaps indentation will be reduced",
- X "Das koennte ueber meinen (rechten) Horizont gehen"
- X },
- X Wlong_string [] = {
- X "Langer Stringdenoter hier zu Ende",
- X "end of long string denoter here",
- X "Laaaaaanger Stringdenoter hoert hier auf (na endlich)"
- X },
- X Wlong_char [] = {
- X "Langer Character-Denoter hier zu Ende",
- X "end of long character denoter here",
- X "Laaaaanger Character-Denoter hoert hier auf"
- X },
- X Eopen [] = {
- X "\nKann Datei \"%s\" nicht oeffnen\n",
- X "\nerror opening \"%s\"\n",
- X "\nNa wo isse denn, die Datei \"%s\" ?\n"
- X },
- X Ereadinput [] = {
- X "Kann Eingabedatei nicht lesen",
- X "can't read inputfile",
- X "akutes Eingabedateileseunvermoegen"
- X },
- X Ewriteoutput [] = {
- X "Kann Ausgabedatei nicht beschreiben",
- X "can't write outputfile",
- X "akute Ausgabedateischreiblaehmung"
- X },
- X Elevel0_ref [] = {
- X "Refinements ausserhalb einer Funktion gibts nicht",
- X "refinements illegal outside functions",
- X "Ein Refinement ? Hier draussen in der Wueste ?"
- X },
- X Elines_in_func [] = {
- X "Funktion hat zuviele Zeilen",
- X "too many lines in function",
- X "Soooo viele Zeilen in einer Funktion haelt ja kein Computer aus"
- X },
- X Ebytes_in_func [] = {
- X "Funktion zu lang (in Bytes)",
- X "too many bytes in function",
- X "Tolle Funktion. Aber, in Bytes betrachtet, entschieden zu gross."
- X },
- X Eref_not_decl [] = {
- X "Refinement nicht deklariert",
- X "undeclared refinement",
- X "Wer oder was soll das sein ?"
- X },
- X Erecursive_ref [] = {
- X "Rekursiver Refinementaufruf",
- X "recursive call to refinement",
- X#define _rum_und_rum "und rum und rum und rum und rum und rum und rum\
- X und rum und rum (rekursives Refinement)"
- X _rum_und_rum
- X },
- X Eunknown_leave [] = {
- X "zu verlassendes Refinement unbekannt",
- X "refinement to leave is unknown",
- X "WAS soll da verlassen werden ???"
- X },
- X Eleave_unpresent [] = {
- X#define _unpresent "Wir sind nicht in diesem Refinement, also kann es\
- X auch nicht verlassen werden",
- X _unpresent
- X "you are not within this refinement, thus it's impossible to leave it",
- X#define _wenn_du "Wenn Du denkst zu sein, wo ich denke (und du\
- X schreibst), dass du zu sein denkst, denkst du falsch."
- X _wenn_du
- X },
- X Eref_multi_decl [] = {
- X "Refinement mehrfach deklariert",
- X "refinement declared more than once",
- X "Langweilig! Das Refinement gibts doch laengst"
- X },
- X Ememory [] = {
- X "\n***** Speichermangel *****\n",
- X "\n***** not enough memory *****\n",
- X "\n Des Bissele Speische is mi abe zu wenisch !\n"
- X },
- X Eeof_brace [] = {
- X "Dateiende bei offener geschweifter Klammer",
- X "EOF within block",
- X "In der U-Bahn geboren, oder was ? Mach erst mal alle Bloecke zu."
- X },
- X Eeof_comment [] = {
- X "Dateiende im Kommentar",
- X "EOF in comment",
- X#define _so_toll "So toll sind Deine Kommentare nun auch nicht, dass\
- X sie bis ans Dateiende gehen sollten"
- X _so_toll
- X },
- X Eeof_string [] = {
- X "Dateiende im Stringdenoter",
- X "EOF in string denoter",
- X "Hoerst Du immer mitten im Satz auf ? Da ist noch ein String offen"
- X },
- X Eeof_char [] = {
- X "Dateiende im Character-Denoter",
- X "EOF in character denoter",
- X "EOF in Character-Denoter. Demnaechst halbieren sie noch die Bits...."
- X },
- X Erefdecl_syntax [] = {
- X "falsche Syntax fuer Refinementdeklaration",
- X "illegal syntax for refinement declaration",
- X "Es begann wie eine Refinementdeklaration. Aber dann....."
- X },
- X Erefdecl_nested [] = {
- X "Mehr als ein Block offen bei Refinementdeklaration",
- X "refinement declaration in nested block",
- X#define _du_bist "Du bist an dieser Stelle viel zu tief in dein Programm\
- X verstrickt, um ein Refinement zu deklarieren"
- X _du_bist
- X },
- X Emany_braces [] = {
- X "Zuviel schliessende Blockklammern",
- X "too many closing braces",
- X#define _aufmachen "Wenn Du jetzt noch eine Blockklammer aufmachst,\
- X dann sind gar keine mehr offen"
- X _aufmachen
- X },
- X Erefname_missing [] = {
- X "Refinementsymbol ohne Refinementname",
- X "refinement symbol found without refinement name",
- X "Das Refinementsymbol fuehlt sich einsam so ganz ohne Name"
- X },
- X Emany_errors [] = {
- X "Zu viele Fehler. Uebersetzung wird abgebrochen.",
- X "too many errors, compilation stopped",
- X "Fiel zufiele Feeler"
- X },
- X Emany_warnings [] = {
- X "Zu viele Warnungen. Uebersetzung wird abgebrochen",
- X "too many warnings, compilation stopped",
- X "(So viele Warnungen sind mir nicht geheuer)"
- X };
- X
- X
- END_OF_FILE
- if test 8508 -ne `wc -c <'cr_texts.h'`; then
- echo shar: \"'cr_texts.h'\" unpacked with wrong size!
- fi
- # end of 'cr_texts.h'
- fi
- if test -f 'erato.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'erato.c'\"
- else
- echo shar: Extracting \"'erato.c'\" \(2259 characters\)
- sed "s/^X//" >'erato.c' <<'END_OF_FILE'
- X
- X/*************************************************************************
- XModule : C-Refine example program
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 23.01.91
- X**************************************************************************
- X/*
- X Copyright (C) 1988,90 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- X#define MAX 10000
- X#define PRIME 0
- X#define NON_PRIME 1
- X
- Xstatic int sieve[MAX+1];
- X
- Xint main ()
- X{
- X { /* initialize (Level 1) */
- X int current;
- X for (current = 2; current <= MAX; current++)
- X sieve[current] = PRIME;
- X }
- X { /* do_sieve (Level 1) */
- X int current_prime = 1;
- X for (;;) {
- X { /* find_next_bigger_prime (Level 2) */
- X int current_candidate = current_prime + 1;
- X while (sieve[current_candidate] == NON_PRIME)
- X if (current_candidate == MAX)
- X goto do_sieve_1;
- X /* leave two refinements at once */
- X else
- X current_candidate++;
- X /* now current_candidate is a prime (or we leave `sieve) */
- X current_prime = current_candidate;
- X }
- X /* perhaps STOP here */
- X { /* delete_all_multiples_of_current_prime (Level 2) */
- X int current = (
- X 2 * current_prime);
- X while (current <= MAX) {
- X sieve[current] = NON_PRIME;
- X current += current_prime;
- X }
- X }
- X }
- Xdo_sieve_1: ;
- X }
- X { /* make_output (Level 1) */
- X int current; /* different from 'current' above */
- X printf ("The primes between 2 and %d are\n", MAX);
- X for (current = 2; current <= MAX; current++)
- X if ((
- X sieve[current] == PRIME)
- X )
- X printf ("%5d ", current);
- X }
- X return (0);
- X} /* end of main() */
- END_OF_FILE
- if test 2259 -ne `wc -c <'erato.c'`; then
- echo shar: \"'erato.c'\" unpacked with wrong size!
- fi
- # end of 'erato.c'
- fi
- if test -f 'erato.cr' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'erato.cr'\"
- else
- echo shar: Extracting \"'erato.cr'\" \(2305 characters\)
- sed "s/^X//" >'erato.cr' <<'END_OF_FILE'
- X/*************************************************************************
- XModule : C-Refine example program
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 23.01.91
- X**************************************************************************
- X/*
- X Copyright (C) 1988,90 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- X#define MAX 10000
- X#define PRIME 0
- X#define NON_PRIME 1
- X
- Xstatic int sieve[MAX+1];
- X
- Xint main ()
- X{
- X `initialize;
- X `do sieve;
- X `make output;
- X return (0);
- X
- X`initialize:
- X int current;
- X for (current = 2; current <= MAX; current++)
- X sieve[current] = PRIME;
- X
- X`do sieve:
- X int current_prime = 1;
- X for (;;) {
- X `find next bigger prime; /* perhaps STOP here */
- X `delete all multiples of current_prime;
- X }
- X
- X`find next bigger prime:
- X int current_candidate = current_prime + 1;
- X while (sieve[current_candidate] == NON_PRIME)
- X if (current_candidate == MAX)
- X leave `do sieve; /* leave two refinements at once */
- X else
- X current_candidate++;
- X /* now current_candidate is a prime (or we leave `sieve) */
- X current_prime = current_candidate;
- X
- X`delete all multiples of current_prime:
- X int current = `first multiple of current_prime;
- X while (current <= MAX) {
- X sieve[current] = NON_PRIME;
- X current += current_prime;
- X }
- X
- X`first multiple of current_prime:
- X 2 * current_prime
- X
- X`make output:
- X int current; /* different from 'current' above */
- X printf ("The primes between 2 and %d are\n", MAX);
- X for (current = 2; current <= MAX; current++)
- X if (`current is prime)
- X printf ("%5d ", current);
- X
- X`current is prime:
- X sieve[current] == PRIME
- X
- X} /* end of main() */
- END_OF_FILE
- if test 2305 -ne `wc -c <'erato.cr'`; then
- echo shar: \"'erato.cr'\" unpacked with wrong size!
- fi
- # end of 'erato.cr'
- fi
- if test -f 'getargs.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'getargs.h'\"
- else
- echo shar: Extracting \"'getargs.h'\" \(2150 characters\)
- sed "s/^X//" >'getargs.h' <<'END_OF_FILE'
- X/*************************************************************************
- XModule : getargs -- command line option processor
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 11.06.91 Version 2
- XCompiler: should be portable
- X tried: MS-DOS 3.2, Microsoft C 5.0 (ANSI-C)
- X SUN-OS 4.03, 4.1 (K&R C)
- X**************************************************************************/
- X/*
- X Copyright (C) 1988,91 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- X/************************************************************************
- X*********************** g e t a r g s ***********************************
- X*************************************************************************/
- X
- X#define INTEGER 0
- X#define BOOLEAN 1
- X#define CHARACTER 2
- X#define STRING 3
- X
- Xtypedef struct {
- X char arg;
- X char type;
- X int *variable;
- X char *errmsg;
- X } ARG;
- X
- X#define ARGTABSIZE(a) (sizeof (a) / sizeof (ARG))
- X
- Xextern int getargs A((int *argc, char **argv, ARG argtab[], int argtabsize));
- Xextern void print_usage A((char *progname, char *usage,
- X ARG tabp[], int argtabsize));
- X
- X#if 0
- X
- XExample or template:
- X
- X/* Definition global (Initialization of Array) ! */
- X
- Xstatic ARG argtab[] = {
- X {'x', TYPE, &var_x, "function of option x" },
- X .
- X .
- X};
- X
- X/* Call : */
- X
- X if (getargs (&argc, argv, argtab, ARGTABSIZE (argtab)) || argc != 3)
- X print_usage (argv[0], "[options] inputfile outputfile [options]",
- X argtab, ARGTABSIZE (argtab));
- X
- X#endif
- X
- END_OF_FILE
- if test 2150 -ne `wc -c <'getargs.h'`; then
- echo shar: \"'getargs.h'\" unpacked with wrong size!
- fi
- # end of 'getargs.h'
- fi
- if test -f 'std.h' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'std.h'\"
- else
- echo shar: Extracting \"'std.h'\" \(2012 characters\)
- sed "s/^X//" >'std.h' <<'END_OF_FILE'
- X/*************************************************************************
- XModule : Header file: mothers little helpers --- bool, assert, prototype args
- XAuthor : Lutz Prechelt, Karlsruhe
- XDate : 11.06.91
- XCompiler: ANSI C, K&R C
- X**************************************************************************
- X/*
- X Copyright (C) 1988 by Lutz Prechelt, Karlsruhe
- X
- X This program is free software; you can redistribute it and/or modify
- X it under the terms of the GNU General Public License as published by
- X the Free Software Foundation; either version 1, or (at your option)
- X any later version.
- X This program is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X GNU General Public License for more details.
- X You should have received a copy of the GNU General Public License
- X along with this program; if not, write to the Free Software
- X Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X*/
- X
- X#ifndef stdh_
- X#define stdh_
- X
- X#if ansi
- X#define A(a) a
- X#else
- X#define A(a) ()
- X#endif
- X
- Xtypedef int bool; /* or 'enum' but some debuggers don't like that */
- X#define true 1
- X#define false 0
- X
- X#ifndef NDEBUG
- X
- X#define _assert_str "\nOOPS !! Assertion failed: file \"%s\", line %d\
- X (CR to continue)"
- Xstatic char _assert_string[] = _assert_str;
- X#define _avoid_str "\nOOPS !! %d happened in file \"%s\", line %d\
- X (CR to continue)"
- Xstatic char _avoid_string[] = _avoid_str;
- X
- X#define assert(e) \
- X (!(e) ? ( \
- X fprintf(stderr, _assert_string, __FILE__, __LINE__), \
- X fgetc (stdin) \
- X ) \
- X : 1 \
- X )
- X
- X#define avoid(e,u) \
- X ((e)!=(u) ? ( \
- X fprintf(stderr, _avoid_string, (e), __FILE__, __LINE__), \
- X fgetc (stdin) \
- X ) \
- X : 1 \
- X )
- X
- X#else
- X
- X#define assert(e) 1
- X#define avoid(e,u) 1
- X
- X#endif /* NDEBUG */
- X
- X
- X#endif
- END_OF_FILE
- if test 2012 -ne `wc -c <'std.h'`; then
- echo shar: \"'std.h'\" unpacked with wrong size!
- fi
- # end of 'std.h'
- fi
- echo shar: End of archive 4 \(of 4\).
- cp /dev/null ark4isdone
- MISSING=""
- for I in 1 2 3 4 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 4 archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
-