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

📄 errors.cpp

📁 eC++编译器源码
💻 CPP
字号:
#pragma Errors
/*RPC11-89 SoftwareError call with OpenInput active causes infinite loop
           in debugger reading the rest of the file. */

#include <Help.H>
#include <InOut.H>

/******************************** Errors *********************************/
/*                                                                       */
/* This MODULE is responsible for halting the system when something      */
/* drastic goes wrong.  In general, when the SoftwareError routine is    */
/* called, a diagnostics message will be printed and then all user       */
/* procedures that were registered with this module (via a call of       */
/* OnErrorCall(MyProcedure)) will be called (allowing any clean-up to    */
/* be done prior to halting) and then the system will be halted.         */
/* An example of using this module follows:                              */
/*                                                                       */
/*                                                                       */
/* MODULE testme;                                                        */
/*                                                                       */
/* FROM SYSTEM IMPORT ADDRESS, CODE;                                     */
/* FROM Devices IMPORT SaveInterruptVector, RestoreInterruptVector;      */
/*                                                                       */
/* CONST TICK = 1CH;                                                     */
/* VAR oldVector : ADDRESS;                                              */
/*                                                                       */
/* PROCEDURE MyCleanUp;                                                  */
/* BEGIN                                                                 */
/*   restore the original interrupt vector before the system halts       */
/*   RestoreInterruptVector(TICK, oldVector);                            */
/* END MyCleanUp;                                                        */
/*                                                                       */
/*                                                                       */
/* PROCEDURE MyTickProcedure;                                            */
/* BEGIN                                                                 */
/*      execute this code every tick as long as we are still running     */
/*   .                                                                   */
/*   .                                                                   */
/* END MyTickProcedure;                                                  */
/*                                                                       */
/*                                                                       */
/* VAR                                                                   */
/*   somethingWentReallyWrong : BOOLEAN;                                 */
/* BEGIN                                                                 */
/*      save the address of the original interrupt service routine       */
/*   SaveInterruptVector(TICK, oldVector);                               */
/*      make sure to resotre it before the system halts                  */
/*   OnErrorCall(MyCleanUp);                                             */
/*      then install our interrupt service routine                       */
/*   RestoreInterruptVector(TICK, ADDRESS(MyTickProcedure));             */
/*   .                                                                   */
/*   .                                                                   */
/*   IF somethingWentReallyWrong THEN                                    */
/*        the system is going down.  clean-up and halt.                  */
/*     SoftwareError("testme.INITIALIZATION : I screwed up.");           */
/*   END;                                                                */
/*   .                                                                   */
/*   .                                                                   */
/* END testme.                                                           */
/*                                                                       */
/*************************************************************************/


/************************ MAXcall / callArray ****************************/
/*                                                                       */
/* The callArray variable is an array of procedure variables referencing */
/* procedures that need to be called before we halt the system.          */
/* Initially, all variables reference the "Empty" procedure that does    */
/* nothing.  Users can call the "OnErrorCall" procedure to add one of    */
/* their own routines to the list or the "OffErrorCall" procedure to     */
/* cancel one of their procedures (that was previously added) from       */
/* being called.                                                         */
/*                                                                       */
/*************************************************************************/

const unsigned int MAXcall = 10;
PROC callArray[MAXcall];

/*************************** SoftwareError *******************************/
/*                                                                       */
/* This routine shuts down the system in the event of an unrecoverable   */
/* software error.  It calls all procedures that have been registered    */
/* using the "OnErrorCall" routine so that they may do any remedial      */
/* clean-up to make the shutdown more graceful (i.e. un-install          */
/* interrupt vectors referencing procedures that are about to go away.)  */
/*                                                                       */
/*************************************************************************/

void SoftwareError(char s[])
{
     unsigned int i;

     CloseInput();
     CloseOutput();
     WriteLn();
     WriteLn();
     WriteString("Software Error -- ");
     WriteString(s);
     WriteLn();
     WriteLn();
     Look();
     for(i=0;i<MAXcall;i++)
         callArray[i]();
     WriteString("Gone!");
     WriteLn();
     WriteLn();
     HALT;
};

/****************************** Empty ************************************/
/*                                                                       */
/* This procedure is just a dummy procedure that will be called by the   */
/* SoftwareError routine in the event that no other user procedures need */
/* to be called before shutdown.                                         */
/*                                                                       */
/*************************************************************************/

void Empty()       
{
  WriteString("Going ...  ");
};

/***************************** OnErrorCall *******************************/
/*                                                                       */
/* This procedure adds the specified procedure to the list of procedures */
/* that the SoftwareError routine will call before halting the system.   */
/*                                                                       */
/*************************************************************************/

void OnErrorCall(PROC p)
{
     unsigned int i;

     for(i=0;i<MAXcall;i++)
          if (callArray[i] == Empty)
          {
               callArray[i] = p;
               return;
          }
     SoftwareError("errors.OnErrorCall : callArray full.");
};

/***************************** OffErrorCall ******************************/
/*                                                                       */
/* This procedure deletes the specified procedure from the list of       */
/* procedures that the SoftwareError routine will call before halting    */
/* the system.                                                           */
/*                                                                       */
/*************************************************************************/

void OffErrorCall(PROC p)
{
     unsigned int i;

     for(i=0;i<MAXcall;i++)
          if (callArray[i] == p)
          {
               callArray[i] = Empty;
               return;
          }
     SoftwareError("errors.OffErrorCall : Procedure not registered.");
};

/*********************** MODULE INITIALIZATION ***************************/
/*                                                                       */
/* This routine just initializes the list of procedures to be called     */
/* prior to halting to the empty state (i.e. calling the Empty           */
/* procedure).                                                           */
/*                                                                       */
/*************************************************************************/

void Errors()
{
     unsigned int i;

     for(i=0;i<MAXcall;i++)
          callArray[i] = Empty;
};
/*************************************************************************/

⌨️ 快捷键说明

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