home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Telnet 2.7b5 / source / debug⁄errors / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-09  |  6.4 KB  |  227 lines  |  [TEXT/CWIE]

  1. /*
  2. *    errors.c
  3. *    This file handles all of the error printing in one centralized place.
  4. *    There are several classes of errors (network, memory, etc).
  5. *    To Handle an error, just call into DoError with the appropriate
  6. *    mask and error number.  The routine goes from there.
  7. *
  8. *
  9. *****************************************************************
  10. *    NCSA Telnet for the Macintosh                                *
  11. *                                                                *
  12. *    National Center for Supercomputing Applications                *
  13. *    Software Development Group                                    *
  14. *    152 Computing Applications Building                            *
  15. *    605 E. Springfield Ave.                                        *
  16. *    Champaign, IL  61820                                        *
  17. *                                                                *
  18. *    Copyright (c) 1986-1992,                                    *
  19. *    Board of Trustees of the University of Illinois                *
  20. *****************************************************************
  21. *  Revisions:
  22. *  7/92        Telnet 2.6:    Initial version.  Scott Bulmahn
  23. */
  24.  
  25.  
  26. #ifdef MPW
  27. #pragma segment Debug
  28. #endif
  29.  
  30.  
  31. #include "InternalEvents.h"
  32. #include "DlogUtils.proto.h"
  33. #include "mainseg.proto.h"                // for forcequit proto
  34. #include "errors.proto.h"
  35. #include "telneterrors.h"
  36.  
  37. void loadErrors(void) { } // so that we can load this code high and lock it early
  38.  
  39. /*================================= ERROR HANDLING CODE ============================*/
  40. /* This is the main error handling code.  Get all the errors out of the resource    */
  41. /* file.  The resource number that contains the errors depends on what error        */
  42. /* class we are talking about                                                        */
  43. void DoError(short code, short level, char *mess1)
  44. {
  45.     char buffer1[256],buffer2[256];
  46.     short dItem;
  47.     DialogPtr dtemp;
  48.  
  49.     buffer1[0]=0;        /* dont print extraneous garbage to the screen... */
  50.     buffer2[0]=0;
  51.  
  52.     switch (code & ERRORMASK)
  53.         {
  54.         case NET_ERRORCLASS:
  55.         case MEMORY_ERRORCLASS:
  56.         case RESOURCE_ERRORCLASS:
  57.             strncpy( buffer1, geterrstring(code), 255);
  58.             if (mess1) strncpy(buffer2, mess1, 255);
  59.             break;
  60.  
  61.  
  62.         case NOCODE:                        /* no code given, just 2 strings */
  63.             strncpy(buffer1, mess1, 255);
  64.         }
  65.  
  66.     if (level ==2 || level ==3)                
  67.     {                
  68.         c2pstr(buffer1);
  69.         c2pstr(buffer2);
  70.         ParamText((StringPtr) buffer1,(StringPtr) buffer2,"\p","\p");
  71.  
  72.         dtemp=GetNewDialog(OopsDLOG,(Ptr) 0L,kInFront);    /* Put up the error notice */
  73.         ModalDialog(DLOGwOKUPP,&dItem);        /* Get an event */
  74.         DisposDialog(dtemp);            /* Take it off.....all off......*/
  75.     }
  76. }
  77.  
  78. /************************************************************************/
  79. /*  geterrstring
  80. *   returns the string associated with a particular error number
  81. *    NOTE: strings moved to resource # 23237 
  82. *   error number is formatted %4d at the beginning of the string
  83. */
  84.  
  85.  
  86. char *geterrstring(short code)
  87. {
  88.     short i;
  89.     char s[10];
  90.     Str255 ErrorString;                                    /* BYU 2.4.16 */
  91.     short errorResource, numberOfErrors;
  92.     
  93.     switch (code & ERRORMASK)
  94.         {
  95.         case NET_ERRORCLASS:
  96.             errorResource = NETERROR_RESOURCE_ID;
  97.             numberOfErrors = NETERROR_RESOURCE_COUNT;
  98.             break;
  99.         case MEMORY_ERRORCLASS:
  100.             errorResource = MEMERROR_RESOURCE_ID;
  101.             numberOfErrors = MEMERROR_RESOURCE_COUNT;
  102.             break;
  103.         case RESOURCE_ERRORCLASS:
  104.             errorResource = RESERROR_RESOURCE_ID;
  105.             numberOfErrors = RESERROR_RESOURCE_COUNT;
  106.             break;
  107.         }
  108.  
  109.     code &= FLAGMASK;    
  110.     sprintf(s,"%4d",code);
  111.  
  112.  
  113.     for (i=1; i <= numberOfErrors; i++) 
  114.         {            
  115.         GetIndString(ErrorString,errorResource,i);    
  116.         p2cstr(ErrorString);                            
  117.         if (!strncmp((char *) ErrorString,s,4))            
  118.             return((char *) ErrorString + 5);            
  119.         }                                                
  120.         
  121.     GetIndString(ErrorString, errorResource,1);        
  122.     return((char *) ErrorString+5);                        
  123. }
  124.  
  125. void    FatalCancelAlert(short messageID, StringPtr DefaultButtonString, short InternalID, short MacID)
  126. {
  127.     Str255        errorString, numberString, numberString2;
  128.     DialogPtr    theDialog;
  129.     short        Type, ditem = 3;
  130.     Handle        Itemh;
  131.     Rect        Box;
  132.  
  133.     GetIndString(errorString, GENERAL_MESSAGES_ID, messageID);
  134.     NumToString((long)InternalID, numberString);
  135.     NumToString((long)MacID, numberString2);
  136.     ParamText(errorString, numberString, numberString2, NULL);
  137.     
  138.     theDialog = GetNewMyDialog(FATALCANCEL_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  139.  
  140.     GetDItem(theDialog, DLOGOk, &Type, &Itemh, &Box);
  141.     SetCTitle((ControlHandle)Itemh, DefaultButtonString);
  142.     ShowWindow(theDialog);
  143.  
  144.     while (ditem > 2)    ModalDialog(DLOGwOK_CancelUPP, &ditem);
  145.     DisposeDialog(theDialog);
  146.     
  147.     // If the user chose quit, then do it... else return.
  148.     if (ditem == DLOGCancel)    forcequit();
  149. }
  150.  
  151. void    FatalAlert(short messageID, short InternalID, short MacID)
  152. {
  153.     Str255        errorString, numberString, numberString2;
  154.     DialogPtr    theDialog;
  155.     short        ditem = 3;
  156.  
  157.     GetIndString(errorString, GENERAL_MESSAGES_ID, messageID);
  158.     NumToString((long)InternalID, numberString);
  159.     NumToString((long)MacID, numberString2);
  160.     ParamText(errorString, numberString, numberString2, NULL);
  161.     
  162.     theDialog = GetNewMyDialog(FATAL_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  163.     ShowWindow(theDialog);
  164.  
  165.     while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  166.     
  167.     forcequit();        // It's a fatal error, so quit
  168. }
  169.  
  170. void    OperationFailedAlert(short messageID, short InternalID, short MacID)
  171. {
  172.     Str255        errorString, numberString, numberString2;
  173.     DialogPtr    theDialog;
  174.     short        ditem = 3;
  175.  
  176.     GetIndString(errorString, OPFAILED_MESSAGES_ID, messageID);
  177.     NumToString((long)InternalID, numberString);
  178.     NumToString((long)MacID, numberString2);
  179.     ParamText(errorString, numberString, numberString2, NULL);
  180.     
  181.     theDialog = GetNewMyDialog(OPFAILED_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  182.     
  183.     if (theDialog)
  184.         ShowWindow(theDialog);
  185.     else
  186.         return;
  187.     while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  188.     DisposeDialog(theDialog);
  189. }
  190.  
  191. void    OutOfMemory(short InternalID)
  192. {
  193.     OperationFailedAlert(OUT_OF_MEMORY, InternalID, 0);
  194. }
  195.  
  196. // Returns "TRUE" if default button is hit.
  197. Boolean    AskUserAlert(short messageID, Boolean CancelIsDefault)
  198. {
  199.     Str255        errorString;
  200.     DialogPtr    theDialog;
  201.     short        Type, ditem = 3;
  202.     Handle        Itemh;
  203.     Rect        Box;
  204.  
  205.     GetIndString(errorString, GENERAL_MESSAGES_ID, messageID);
  206.     ParamText(errorString, NULL, NULL, NULL);
  207.     
  208.     theDialog = GetNewMyDialog(ASKUSER_ID, NULL, kInFront, (void *)ThirdCenterDialog);
  209.  
  210.     if (!CancelIsDefault) {        // We need to swap cancel and ok buttons
  211.         Str255 temp;
  212.         GetDItem(theDialog, DLOGOk, &Type, &Itemh, &Box);
  213.         GetIndString(temp,MISC_STRINGS,OK_STRING);
  214.         SetCTitle((ControlHandle)Itemh, temp);
  215.         GetDItem(theDialog, DLOGCancel, &Type, &Itemh, &Box);
  216.         GetIndString(temp,MISC_STRINGS,CANCEL_STRING);
  217.         SetCTitle((ControlHandle)Itemh, temp);
  218.         }
  219.         
  220.     ShowWindow(theDialog);
  221.  
  222.     while (ditem > 2)    ModalDialog(DLOGwOK_CancelUPP, &ditem);
  223.     DisposeDialog(theDialog);
  224.     
  225.     if (ditem == 1) return (TRUE);
  226.     else return (FALSE);
  227. }