home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / ErrorString / ErrorString.c next >
Encoding:
Text File  |  1995-06-19  |  2.5 KB  |  100 lines  |  [TEXT/CWIE]

  1. //*****************************************************************
  2. //*    Error string ('Estr') resource handler
  3. //*    by Mark Sproul
  4. //*        sproul@eos.ap.org
  5. //*
  6. //*    This is a collection of 'Estr' resources and code to use them
  7. //*    
  8. //*    Simply include the desired resource files in your project and
  9. //*    call the GetErrorString or DisplayErrorCode
  10. //*    as needed with the error number.
  11. //*    
  12. //*    Estr.1.0.rsrc        Came from some ftp site someplace, I dont remember
  13. //*                        This contains most of the basic error strings for most system stuff
  14. //*                        You will probably always need this one,
  15. //*    
  16. //*                        The rest are specific to extras that you may or may not be using
  17. //*                        
  18. //*            The rest of them I created
  19. //*    
  20. //*    Estr.AOCE.rsrc        Error msgs for AOCE
  21. //*    Estr.QuickTake.rsrc    Error msgs for QuickTake camera drivers
  22. //*    Estr.QuickTime.rsrc    Error msgs for QuickTime
  23. //*                        I am working on more and will release them as they are finished
  24. //*                        Also, a greatly enhanced version of the AOCE errors will be 
  25. //*                        available soon. I will also be doing a QD3D version.
  26. //*
  27. //*    Permission is granted to use this for what ever you like in your applications.
  28. //*    If you distribute this to others, please include this notice.
  29. //*
  30. //*    If you create more Estr resource files, please forward them to me so I can
  31. //*    keep a collection of them.
  32. //*****************************************************************
  33.  
  34. #include    <stdio.h>
  35. #include    <string.h>
  36.  
  37.  
  38. #ifndef __TYPES__
  39.     #include    <types.h>
  40. #endif
  41. #ifndef __RESOURCES__
  42.     #include    <resources.h>
  43. #endif
  44. #ifndef __STRINGS__
  45.     #include    <strings.h>
  46. #endif
  47.  
  48. #include    "CtoPfunc.proto.h"
  49. #include    "ErrorString.h"
  50. #include    "utilities.proto.h"
  51.  
  52. #define    kAdviseAlert    9999
  53.  
  54. //*****************************************************
  55. static void    PutAlertMessage(Str255 alrtMsg)
  56. {
  57.     InitCursor();
  58.     ParamText(alrtMsg, "\p", "\p", "\p");
  59.     Alert(kAdviseAlert, nil);
  60. }
  61.  
  62.  
  63.  
  64. //*****************************************************************
  65. void    GetErrorString(OSErr theError, Str255 returnString)
  66. {
  67. Handle    rHandle;
  68. long    byteCount;
  69. char    *strPtr;
  70.  
  71.     rHandle    =    GetResource('Estr', theError);
  72.     if (rHandle)
  73.     {
  74.         strPtr        =    *rHandle;
  75.         byteCount    =    strPtr[0] + 1;
  76.         
  77.         BlockMove(strPtr, returnString, byteCount);
  78.         
  79.         ReleaseResource(rHandle);
  80.     }
  81.     else
  82.     {
  83.         sprintf((char *)returnString, "Unknown Error (%d), Error msg Not Found", theError);
  84.         CtoPstr((char *)returnString);
  85.     }
  86. }
  87.  
  88.  
  89. //*****************************************************************
  90. void    DisplayErrorCode(OSErr theError)
  91. {
  92. Str255    errMsg;
  93.  
  94.     if (theError != 0)
  95.     {
  96.         GetErrorString(theError, errMsg);
  97.         
  98.         PutAlertMessage(errMsg);
  99.     }
  100. }