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

📄 cslib.shar

📁 书名:C语言科学与艺术,以前交钱下载的
💻 SHAR
📖 第 1 页 / 共 5 页
字号:
X * Most of the implementation of the exception mechanism isX * actually done in the macros defined by this file.X * Clients should ordinarily be able to read the descriptionX * above and ignore the detailed code below.X */XX#include <setjmp.h>X#include <string.h>X#include "genlib.h"XX/* Define parameters and error status indicators */XX#define MaxExceptionsPerScope 10X#define ETooManyExceptClauses 101X#define EUnhandledException 102XX/* Codes to keep track of the state of the try handler */XX#define ES_Initialize 0X#define ES_EvalBody 1X#define ES_Exception 2XX/*X * Type: exceptionX * ---------------X * Exceptions are specified by their address, so that theX * actual structure does not matter.  Strings are used hereX * so that exporters of exceptions can store the exceptionX * name for the use of debuggers and other tools.X */XXtypedef struct { string name; } exception;XX/*X * Type: context_blockX * -------------------X * This structure is used internally to maintain a chain ofX * exception scopes on the control stack.X */XXtypedef struct ctx_block {X    jmp_buf jmp;X    int nx;X    exception *array[MaxExceptionsPerScope];X    exception *id;X    void *value;X    string name;X    struct ctx_block *link;X} context_block;XX/* Declare the built-in exceptions */XXextern exception ErrorException;Xextern exception ANY;XX/* Declare a global pointer to the context stack */XXextern context_block *exceptionStack;XX/*X * Function: RaiseExceptionX * Usage: RaiseException(&e, name, value);X * ---------------------------------------X * This function is called by the raise macro and does theX * work necessary to raise the exception.  See the exception.c fileX * for details.  Clients do not ordinarily call this directly.X */XXvoid RaiseException(exception *e, string name, void *value);XX/*X * Function: HandlerExistsX * Usage: if (HandlerExists(&e)) ...X * ---------------------------------X * Determines whether a handler exists for an exception inX * the dynamically enclosing scope.  Intended only for useX * by special clients, such as the Error package.X */XXbool HandlerExists(exception *e);XX/* Define the pseudo-functions for raise and try */XX#define raise(e) RaiseException(&e, #e, NULL)XX#define try \X      { \X          jmp_buf _jmp_; \X          context_block _ctx_; \X          volatile int _es_; \X          _es_ = ES_Initialize; \X          _ctx_.nx = 0; \X          _ctx_.link = exceptionStack; \X          exceptionStack = (context_block *) &_ctx_; \X          if (setjmp(_jmp_) != 0) _es_ = ES_Exception; \X          memcpy((void *) _ctx_.jmp, (void *) _jmp_, sizeof(jmp_buf)); \X          while (1) { \X              if (_es_ == ES_EvalBody)XX#define except(e) \X                  if (_es_ == ES_EvalBody) exceptionStack = _ctx_.link; \X                  break; \X              } \X              if (_es_ == ES_Initialize) { \X                  if (_ctx_.nx >= MaxExceptionsPerScope) \X                      exit(ETooManyExceptClauses); \X                  _ctx_.array[_ctx_.nx++] = &e; \X              } else if (_ctx_.id == &e || &e == &ANY) { \X                  exceptionStack = _ctx_.link;XX#define endtry \X              if (_es_ != ES_Initialize) break; \X              _es_ = ES_EvalBody; \X          } \X      }XX#define GetExceptionName() _ctx_.nameX#define GetExceptionValue() _ctx_.valueX#define GetCurrentException() _ctx_.idXX#endifEND_OF_FILEif test 7990 -ne `wc -c <'cslib/exception.h'`; then    echo shar: \"'cslib/exception.h'\" unpacked with wrong size!fi# end of 'cslib/exception.h'fiif test -f 'cslib/extgraph.h' -a "${1}" != "-c" ; then   echo shar: Will not clobber existing file \"'cslib/extgraph.h'\"elseecho shar: Extracting \"'cslib/extgraph.h'\" \(14869 characters\)sed "s/^X//" >'cslib/extgraph.h' <<'END_OF_FILE'X/*X * File: extgraph.hX * Version: 3.0X * Last modified on Tue Oct  4 11:24:41 1994 by erobertsX * -----------------------------------------------------X * This interface is the extended graphics interface.X * It includes all of the facilities in graphics.h, plusX * several additional functions that are designed toX * support more sophisticated, interactive graphics.X */XX#ifndef _extgraph_hX#define _extgraph_hXX#include "genlib.h"XX/* Exported functions */XX/* Section 1 -- Basic functions from graphics.h */XX#include "graphics.h"XX/* Section 2 -- Elliptical arcs */XX/*X * Function: DrawEllipticalArcX * Usage: DrawEllipticalArc(rx, ry, start, sweep);X * -----------------------------------------------X * This procedure draws an elliptical arc.  It is exactlyX * the same in its operation as DrawArc in the graphics.hX * interface, except that the radius is different along theX * two axes.X */XXvoid DrawEllipticalArc(double rx, double ry,X                       double start, double sweep);XX/* Section 3 -- Graphical regions*/XX/*X * Functions: StartFilledRegion, EndFilledRegionX * Usage: StartFilledRegion(density);X *        . . . other calls . . .X *        EndFilledRegion();X * ------------------------------X * These calls make it possible to draw filled shapes on theX * display.  After calling StartFilledRegion, any calls toX * DrawLine and DrawArc are used to create a shape definitionX * and do not appear on the screen until EndFilledRegion isX * called.  The lines and arcs must be consecutive, in theX * sense that each new element must start where the lastX * one ended.  MovePen calls may occur at the beginningX * or the end of the region, but not in the interior. WhenX * EndFilledRegion is called, the entire region appears on theX * screen, with its interior filled in.  The density parameterX * is a number between 0 and 1 and indicates how the dot densityX * to be used for the fill pattern.  If density is 1, the shapeX * will be filled in a solid color; if it is 0, the fill will beX * invisible.  In between, the implementation will use a dotX * pattern that colors some of the screen dots but not others.X */XXvoid StartFilledRegion(double density);Xvoid EndFilledRegion(void);XX/* Section 4 -- String functions */XX/*X * Function: DrawTextStringX * Usage: DrawTextString(text);X * ----------------------------X * This function displays the string text at the current pointX * in the current font and size.  The current point is updatedX * so that the next DrawTextString command would continue fromX * the next character position.  The string may not include theX * newline character.X */XXvoid DrawTextString(string text);XX/*X * Function: TextStringWidthX * Usage: w = TextStringWidth(text);X * ---------------------------------X * This function returns the width of the text string if displayedX * at the current font and size.X */XXdouble TextStringWidth(string text);XX/*X * Function: SetFontX * Usage: SetFont(font);X * ---------------------X * This function sets a new font according to the font string,X * which is case-independent.  Different systems support differentX * fonts, although common ones like "Times" and "Courier" are oftenX * supported.  Initially, the font is set to "Default" which isX * always supported, although the underlying font is systemX * dependent.  If the font name is unrecognized, no error isX * generated, and the font remains unchanged.  If you need toX * detect this condition, you can call GetFont to see if theX * change took effect.  By not generating an error in this case,X * programs become more portable.X */XXvoid SetFont(string font);XX/*X * Function: GetFontX * Usage: font = GetFont();X * ------------------------X * This function returns the current font name as a string.X */XXstring GetFont(void);XX/*X * Function: SetPointSizeX * Usage: SetPointSize(size);X * --------------------------X * This function sets a new point size.  If the point size isX * not supported for a particular font, the closest existingX * size is selected.X */XXvoid SetPointSize(int size);XX/*X * Function: GetPointSizeX * Usage: size = GetPointSize();X * -----------------------------X * This function returns the current point size.X */XXint GetPointSize(void);XX/*X * Text style constantsX * --------------------X * The constants Bold and Italic are used in the SetStyleX * command to specify the desired text style.  They may alsoX * be used in combination by adding these constants together,X * as in Bold + Italic.  The constant Normal indicates theX * default style.X */XX#define Normal  0X#define Bold    1X#define Italic  2XX/*X * Function: SetStyleX * Usage: SetStyle(style);X * -----------------------X * This function establishes the current style propertiesX * for text based on the parameter style, which is an integerX * representing the sum of any of the text style constants.X */XXvoid SetStyle(int style);XX/*X * Function: GetStyleX * Usage: style = GetStyle();X * --------------------------X * This function returns the current style.X */XXint GetStyle(void);XX/*X * Functions: GetFontAscent, GetFontDescent, GetFontHeightX * Usage: ascent = GetFontAscent();X *        descent = GetFontDescent();X *        height = GetFontHeight();X * -------------------------------------------------------X * These functions return properties of the current font that areX * used to calculate how to position text vertically on the page.X * The ascent of a font is the distance from the baseline to theX * top of the largest character; the descent is the maximumX * distance any character extends below the baseline.  The heightX * is the total distance between two lines of text, including theX * interline space (which is called leading).X *X * Examples:X *   To change the value of y so that it indicates the next textX *   line, you need to executeX *X *        y -= GetFontHeight();X *X *   To center text vertically around the coordinate y, you needX *   to start the pen atX *X *       y - GetFontAscent() / 2X */XXdouble GetFontAscent(void);Xdouble GetFontDescent(void);Xdouble GetFontHeight(void);XX/* Section 5 -- Mouse support */XX/*X * Functions: GetMouseX, GetMouseYX * Usage: x = GetMouseX();X *        y = GetMouseY();X * -------------------------------X * These functions return the x and y coordinates of the mouse,X * respectively.  The coordinate values are real numbers measuredX * in inches from the origin and therefore match the drawingX * coordinates.X */XXdouble GetMouseX(void);Xdouble GetMouseY(void);XX/*X * Functions: MouseButtonIsDownX * Usage: if (MouseButtonIsDown()) . . .X * -------------------------------------X * This function returns TRUE if the mouse button is currentlyX * down.  For maximum compatibility among implementations, theX * mouse is assumed to have one button.  If the mouse has moreX * than one button, this function returns TRUE if any buttonX * is down.X */XXbool MouseButtonIsDown(void);XX/*X * Functions: WaitForMouseDown, WaitForMouseUpX * Usage: WaitForMouseDown();X *        WaitForMouseUp();X * -------------------------------------------X * The WaitForMouseDown function waits until the mouse buttonX * is pressed and then returns.  WaitForMouseUp waits for theX * button to be released.X */XXvoid WaitForMouseDown(void);Xvoid WaitForMouseUp(void);XX/* Section 6 -- Color support */XX/*X * Function: HasColorX * Usage: if (HasColor()) . . .X * ----------------------------X * This function returns TRUE if the graphics window can display aX * color image.  Note that this condition is stronger than simplyX * checking whether a color display is available.  Because colorX * windows require more memory than black and white ones, thisX * function will return FALSE with a color screen if there isX * not enough memory to store a colored image.  On the Macintosh,X * for example, it is usually necessary to increase the partitionX * size to at least 1MB before color windows can be created.X */XXbool HasColor(void);XX/*X * Function: SetPenColorX * Usage: SetPenColor(color);X * --------------------------X * This function sets the color of the pen used for any drawing,X * including lines, text, and filled regions.  The color is aX * string, which will ordinarily be one of the followingX * predefined color names:X *X *    Black, Dark Gray, Gray, Light Gray, White,X *    Red, Yellow, Green, Cyan, Blue, MagentaX *X * The first line corresponds to standard gray scales and theX * second to the primary and secondary colors of light.  TheX * built-in set is limited to these colors because they areX * likely to be the same on all hardware devices.  For finerX * color control, you can use the DefineColor function toX * create new color names as well.X */XXvoid SetPenColor(string color);XX/*X * Function: GetPenColorX * Usage: color = GetPenColor();X * -----------------------------X * This function returns the current pen color as a string.X */XXstring GetPenColor(void);XX/*X * Function: DefineColorX * Usage: DefineColor(name, red, green, blue);X * -------------------------------------------X * This function allows the client to define a new color nameX * by supplying intensity levels for the colors red, green,X * and blue, which are the primary colors of light.  TheX * color values are provided as real numbers between 0 and 1,X * indicating the intensity of that color.  For example,X * the predefined color Magenta has full intensity red andX * blue but no green and is therefore defined as:X *X *      DefineColor("Magenta", 1, 0, 1);X *X * DefineColor allows you to create intermediate colors onX * many displays, although the results vary significantlyX * depending on the hardware.  For example, the followingX * usually gives a reasonable approximation of brown:X *X *      DefineColor("Brown", .35, .20, .05);X */XXvoid DefineColor(string name,X                 double red, double green, double blue);XX/* Section 7 -- Miscellaneous functions */X

⌨️ 快捷键说明

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