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

📄 cslib.shar

📁 书名:C语言科学与艺术,以前交钱下载的
💻 SHAR
📖 第 1 页 / 共 5 页
字号:
#! /bin/sh# This is a shell archive.  Remove anything before this line, then unpack# it by saving it into a file and typing "sh file".  To overwrite existing# files, type "sh file -c".  You can also feed this as standard input via# unshar, or by typing "sh <file", e.g..  If this archive is complete, you# will see the following message at the end:#		"End of shell archive."# Contents:  cslib cslib/Makefile cslib/config.csh cslib/exception.c#   cslib/exception.h cslib/extgraph.h cslib/gcalloc.h cslib/genlib.c#   cslib/genlib.h cslib/glibrary.c cslib/glibrary.h cslib/graphics.c#   cslib/graphics.h cslib/random.c cslib/random.h cslib/simpio.c#   cslib/simpio.h cslib/strlib.c cslib/strlib.h cslib/xcompat.c#   cslib/xcompat.h cslib/xdisplay.c cslib/xdisplay.h cslib/xmanager.c#   cslib/xmanager.h# Wrapped by eroberts@Eeyore.Stanford.EDU on Fri Feb 24 19:45:03 1995PATH=/bin:/usr/bin:/usr/ucb ; export PATHif test ! -d 'cslib' ; then    echo shar: Creating directory \"'cslib'\"    mkdir 'cslib'fiif test -f 'cslib/Makefile' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'cslib/Makefile'\"elseecho shar: Extracting \"'cslib/Makefile'\" \(2837 characters\)sed "s/^X//" >'cslib/Makefile' <<'END_OF_FILE'X# Makefile for cslib/xwindows directoryX# Last modified on Sat Oct  1 12:56:29 1994 by erobertsX#****************************************************************XXOBJECTS = \X    genlib.o \X    exception.o \X    strlib.o \X    simpio.o \X    random.o \X    graphics.o \X    xmanager.o \X    xdisplay.o \X    xcompat.o \X    glibrary.oXXCSLIB = cslib.aXXCC = gccXCFLAGS = -g -I. $(CCFLAGS)XCONFIG = `csh config.csh -DHasPoll $(CC) -E -DHasPoll xcompat.c`XX# ***************************************************************X# Entry to bring the package up to dateX#    The "make all" entry should be the first real entryXXall: $(CSLIB) gccxXX# ***************************************************************X# Standard entries to remove files from the directoriesX#    tidy    -- eliminate unwanted filesX#    clean   -- delete derived files in preparation for rebuildX#    scratch -- synonym for cleanXXtidy:X	rm -f ,* .,* *~ core a.out *.errXXclean scratch: tidyX	rm -f *.o *.a gccxXX# ***************************************************************X# C compilationsXXgenlib.o: genlib.c genlib.h exception.h gcalloc.hX	$(CC) $(CFLAGS) -c genlib.cXXexception.o: exception.c exception.h genlib.hX	$(CC) $(CFLAGS) -c exception.cXXstrlib.o: strlib.c strlib.h genlib.hX	$(CC) $(CFLAGS) -c strlib.cXXsimpio.o: simpio.c simpio.h strlib.h genlib.hX	$(CC) $(CFLAGS) -c simpio.cXXrandom.o: random.c random.h genlib.hX	$(CC) $(CFLAGS) -c random.cXXgraphics.o: graphics.c graphics.h extgraph.h xmanager.h xcompat.h \X            glibrary.h genlib.h gcalloc.h simpio.h strlib.h MakefileX	$(CC) $(CONFIG) $(CFLAGS) -c graphics.cXXxmanager.o: xmanager.c xmanager.h xdisplay.h xcompat.h glibrary.h \X	    genlib.h exception.h simpio.h MakefileX	$(CC) $(CONFIG) $(CFLAGS) -c xmanager.cXXxdisplay.o: xdisplay.c xdisplay.h xmanager.h glibrary.h genlib.h strlib.h \X            MakefileX	$(CC) $(CONFIG) $(CFLAGS) -c xdisplay.cXXxcompat.o: xcompat.c xcompat.h MakefileX	$(CC) $(CONFIG) $(CFLAGS) -c xcompat.cXXglibrary.o: glibrary.c glibrary.h genlib.hX	$(CC) $(CFLAGS) -c glibrary.cXX# ***************************************************************X# Entry to reconstruct the library archiveXX$(CSLIB): $(OBJECTS)X	-rm -f $(CSLIB)X	ar cr $(CSLIB) $(OBJECTS)X	ranlib $(CSLIB)XX# ***************************************************************X# Entry to reconstruct the gccx scriptXXgccx: MakefileX	@echo '#! /bin/csh -f' > gccxX	@echo 'set INCLUDE =' `pwd` >> gccxX	@echo 'set CSLIB = $$INCLUDE/cslib.a' >> gccxX	@echo 'set LIBRARIES = ($$CSLIB -lX11 -lm)' >> gccxX	@echo 'foreach x ($$*)' >> gccxX	@echo '  if ("x$$x" == "x-c") then' >> gccxX	@echo '    set LIBRARIES = ""' >> gccxX	@echo '    break' >> gccxX	@echo '  endif' >> gccxX	@echo 'end' >> gccxX	@echo 'gcc -g -I$$INCLUDE $$* $$LIBRARIES' >> gccxX	@chmod a+x gccxX	@echo '[gccx script created]'END_OF_FILEif test 2837 -ne `wc -c <'cslib/Makefile'`; then    echo shar: \"'cslib/Makefile'\" unpacked with wrong size!fi# end of 'cslib/Makefile'fiif test -f 'cslib/config.csh' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'cslib/config.csh'\"elseecho shar: Extracting \"'cslib/config.csh'\" \(1035 characters\)sed "s/^X//" >'cslib/config.csh' <<'END_OF_FILE'X#! /bin/csh -fX#! File: config.cshX#! Usage: csh config.csh flag command . . .X#! Last modified on Sat Oct  1 12:54:21 1994 by erobertsX#! -----------------------------------------------------X#! This shell script is used inside Makefiles to parameterizeX#! compilations for different Unix systems.  The effect of theX#! script is to execute the command and its arguments silently,X#! throwing away any output to stdout or stderr.  If the commandX#! succeeds, the config.csh program echoes the flag parameter; if not,X#! it generates no output.  The typical use of the program isX#! within backquotes, as follows:X#! X#!     gcc `csh config.csh -DCFLAG gcc -E -DCFLAG testfile.c` -c file.cX#! X#! If the internal commandX#! X#!     gcc -E -DCFLAG testfile.cX#! X#! succeeds, the outer compilation will define the CFLAG macro;X#! if not, the macro will be undefined.  Thus, if the optionX#! flag works correctly in the test case, it is used in theX#! other compilations as well.X#!Xeval $argv[2-] >& /dev/nullXif ($status == 0) echo $1END_OF_FILEif test 1035 -ne `wc -c <'cslib/config.csh'`; then    echo shar: \"'cslib/config.csh'\" unpacked with wrong size!fichmod +x 'cslib/config.csh'# end of 'cslib/config.csh'fiif test -f 'cslib/exception.c' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'cslib/exception.c'\"elseecho shar: Extracting \"'cslib/exception.c'\" \(3276 characters\)sed "s/^X//" >'cslib/exception.c' <<'END_OF_FILE'X/*X * File: exception.cX * Version: 1.0X * Last modified on Sun Jul 24 10:28:11 1994 by erobertsX * -----------------------------------------------------X * This file implements the C exception handler.  Much of theX * real work is done in the exception.h header file.X */XX#include <stdio.h>X#include <stdarg.h>XX#include "genlib.h"X#include "gcalloc.h"X#include "exception.h"XX/*X * Constant: MaxUnhandledMessageX * -----------------------------X * This constant should be large enough to accommodate theX * unhandled exception message, including the exception name.X */XX#define MaxUnhandledMessage 100XX/* Publically accessible exceptions */XXexception ANY = { "ANY" };Xexception ErrorException = { "ErrorException" };XX/*X * Global variable: exceptionStackX * -------------------------------X * This variable is the head pointer to a linked list ofX * context blocks that act as the exception stack.  The chainX * pointer is referenced by the macros in exception.h and mustX * therefore be exported, but clients should not reference itX * directly.X */XXcontext_block *exceptionStack = NULL;XX/* Private function prototypes */XXstatic context_block *FindHandler(exception *e);XX/* Public entries */XX/*X * Function: RaiseExceptionX * ------------------------X * This function operates by finding an appropriate handlerX * and then using longjmp to return to the context storedX * there after resetting the exception stack.  If no handlerX * exists, the function notes an unhandled exception.  MuchX * of the complexity comes from the fact that allocationX * within the exception handler may fail.X */XXvoid RaiseException(exception *e, string name, void *value)X{X    context_block *cb;X    char errbuf[MaxUnhandledMessage + 1];X    string errmsg;X    int errlen;XX    cb = FindHandler(e);X    if (cb == NULL) {X        sprintf(errbuf, "Unhandled exception (%.30s)", name);X        errlen = strlen(errbuf);X        if (_acb == NULL) {X            errmsg = malloc(errlen + 1);X        } else {X            errmsg = _acb->allocMethod(errlen + 1);X        }X        if (errmsg == NULL) {X            errmsg = "Unhandled exception: unknown";X        } else {X            strcpy(errmsg, errbuf);X        }X        Error(errmsg);X    }X    exceptionStack = cb;X    cb->id = e;X    cb->value = value;X    cb->name = name;X    longjmp(cb->jmp, ES_Exception);X}XX/*X * Function: HandlerExistsX * -----------------------X * This public entry is used primarily by the Error functionX * to determine if ErrorException has been trapped, althoughX * it is available to other clients as well.X */XXbool HandlerExists(exception *e)X{X    return (FindHandler(e) != NULL);X}XX/* Private functions */XX/*X * Function: FindHandlerX * ---------------------X * This function searches the exception stack to find theX * first active handler for the indicated exception.  If aX * match is found, the context block pointer is returned.X * If not, FindHandler returns NULL.X */XXstatic context_block *FindHandler(exception *e)X{X    context_block *cb;X    exception *t;X    int i;XX    for (cb = exceptionStack; cb != NULL; cb = cb->link) {X        for (i = 0; i < cb->nx; i++) {X            t = cb->array[i];X            if (t == e || t == &ANY) return (cb);X        }X    }X    return (NULL);X}END_OF_FILEif test 3276 -ne `wc -c <'cslib/exception.c'`; then    echo shar: \"'cslib/exception.c'\" unpacked with wrong size!fi# end of 'cslib/exception.c'fiif test -f 'cslib/exception.h' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'cslib/exception.h'\"elseecho shar: Extracting \"'cslib/exception.h'\" \(7990 characters\)sed "s/^X//" >'cslib/exception.h' <<'END_OF_FILE'X/*X * File: exception.hX * Version: 1.0X * Last modified on Thu Feb 23 12:45:01 1995 by erobertsX * -----------------------------------------------------X * The exception package provides a general exceptionX * handling mechanism for use with C that is portableX * across a variety of compilers and operating systems.X */XX#ifndef _exception_hX#define _exception_hXX/*X * Overview:X * --------X * The exception package makes it possible for clients toX * specify a handler for an exceptional conditions in aX * syntactically readable way.  As a client, your first stepX * is to declare an exception condition name by declaringX * a variable of type exception, as inX *X *       exception MyException;X *X * Normal visibility rules apply, so that you should declareX * the exception variable at the appropriate level.  ForX * example, if an exception is local to an implementation,X * it should be declared statically within that module.  IfX * an exception condition is shared by many modules, theX * exception variable should be declared in an interfaceX * and exported to all clients that need it.  This packageX * defines and exports the exception ErrorException, whichX * is likely to be sufficient for many clients.X *X * The basic functionality of exceptions is that one pieceX * of code can "raise" an exception so that it can then beX * "handled" by special code in a dynamically enclosingX * section of the program.  Exceptions are raised by callingX * the pseudo-function raise with the exception name, as inX *X *     raise(MyException);X *X * Exceptions are handled using the "try" statementX * (actually implemented using macros), which has the form:X *X *     try {X *        . . . statements in the body of the block . . .X *     except(exception1)X *        . . . statements to handle exception 1 . . .X *     except(exception2)X *        . . . statements to handle exception 2 . . .X *     except(ANY)X *        . . . statements to handle any exception . . .X *     } endtryX *X * Any number of except clauses may appear (up to aX * maximum defined by the constant MaxExceptionsPerScope),X * and the ANY clause is optional.X *X * When the program encounters the "try" statement, theX * statements in the body are executed.  If no exceptionX * conditions are raised during that execution, eitherX * in this block or by a function call nested insideX * this block, control passes to the end of the "try"X * statement when the last statement in the block isX * executed.  If an exception is raised during theX * dynamic execution of the block, control immediatelyX * passes to the statements in the appropriate exceptX * clause.  Only the statements in that clause areX * executed; no break statement is required to exitX * the block.  If no handler for the raised exceptionX * appears anywhere in the control history, the programX * exits with an error.X *X * Examples of use:X *X * 1.  Catching errors.X *X * The following code fragment traps calls to Error, soX * that the program does not quit but instead returnsX * to the top-level read-and-execute loop.X *X *     while (TRUE) {X *         try {X *             printf("> ");X *             cmd = ReadCommand();X *             ExecuteCommand(cmd);X *         except(ErrorException)X *             printf("Error: %s\n", (string) GetExceptionValue());X *             -- additional handling code, if any --X *         } endtryX *     }X *X * If either ReadCommand or ExecuteCommand calls Error,X * control will be passed back to the main loop, afterX * executing any additional handler code.  The errorX * message is passed as the exception value and can beX * printed as shown in the example.X *X * 2.  Handling control-CX *X * The following code extends the example above so thatX * typing ^C also returns to top-level.X *X *     #include <signal.h>X *X *     static exception ControlCException;X *     static int errorCount = 0;X *     static int ControlCHandler();X *X *     main()X *     {X *         string cmd;X *X *         signal(SIGINT, ControlCHandler);X *         while (TRUE) {X *             try {X *                 printf("> ");X *                 cmd = ReadCommand();X *                 ExecuteCommand(cmd);X *             except(ControlCException);X *                 printf("^C\n");X *                 signal(SIGINT, ControlCHandler);X *             except(ErrorException)X *                 errorCount++;X *             } endtryX *         }X *     }X *X *     static int ControlCHandler()X *     {X *         raise(ControlCException);X *     }X */XX/*X * Actual interface specificationX * ------------------------------

⌨️ 快捷键说明

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