home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / LibLook 1.0a / LibLook.cp next >
Encoding:
Text File  |  1996-05-29  |  5.7 KB  |  130 lines  |  [TEXT/CWIE]

  1.  
  2. #include <iostream.h>
  3. #include <types.h>
  4. #include <Errors.h>
  5. #include <CodeFragments.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8.  
  9. #include <sioux.h>
  10.  
  11. void printError(OSErr theError);
  12.  
  13. void main (void)
  14. {
  15.  
  16.     extern tSIOUXSettings    SIOUXSettings;
  17.     SIOUXSettings.asktosaveonclose = false;
  18.  
  19.     OSErr myErr;
  20.     CFragConnectionID myConnection;
  21.     Ptr myMainAddr;
  22.     Str255 myErrName = "\p<n/a>";
  23.     char libName[256];
  24.     Str255 libNameP;
  25.  
  26.      cout << "LibLook 1.0" << endl << endl;
  27.      cout << "Enter the library name (fragment name) of the shared library. " << endl;
  28.      cout << "This is not necessarily the file name, but the name in 'cfrg'  " << endl;
  29.      cout << "resource that was entered on the 'CFM68K' or 'PPC PEF' preference " << endl;
  30.      cout << "page in Code Warrior 7.  The shared library must either be in the " << endl;
  31.      cout << "extensions folder or the same folder as this application.  " << endl << endl;
  32.  
  33.     cout << "Library Name: ";
  34.     gets (libName);
  35.     cout << endl;
  36.     
  37.     libNameP[0] = (unsigned char)strlen(libName);
  38.     strcpy((char *)&libNameP[1],libName);
  39.      
  40.     cout << "Attempting to load shared library: " << libName << endl << endl;
  41.     // dynamicly load the CFM            
  42.     myErr = GetSharedLibrary(libNameP,kAnyCFragArch,kLoadCFrag,&myConnection,&myMainAddr,myErrName);
  43.     if (myErr==fragNoErr)
  44.         {
  45.             cout << "The library opened successfully! [" << myErr << "]" << endl << endl;
  46.             long index, count;
  47.             // Get the number of entry points in the CFM
  48.             myErr = CountSymbols(myConnection, &count);
  49.             if (myErr==fragNoErr)
  50.             {
  51.                 cout << "CountSymbols indicated that there were " << count << " symbols in this shared library." << endl << endl;
  52.                 for (index = 0; index < count; index++)
  53.                 {
  54.                     Str255 mySymName;
  55.                     long (*myFuncPtr)();
  56.                     CFragSymbolClass mySymClass;
  57.                     // Get the info about the entry point
  58.                     myErr = GetIndSymbol(myConnection, index, mySymName, (Ptr *)&myFuncPtr, &mySymClass);
  59.     
  60.                     if (myErr==fragNoErr)
  61.                     {
  62.                         cout << "Symbol #" << index << " Named:'";
  63.                         
  64.                         for (int j = 1; j <= mySymName[0]; j++) { cout << mySymName[j]; }
  65.                         // call the entry point  (we assume all have no params and return a long
  66.                         cout << "' Addr:" << (long)myFuncPtr << " Class:" << mySymClass << endl;
  67.                         
  68.                         //cout << " Returned:" << myFuncPtr() << endl;
  69.     
  70.                     } else { cout << "There was an error callling GetIndSymbol! [" << myErr << "]" << endl << endl; printError(myErr); }
  71.     
  72.                 }
  73.             } else { cout << "There was an error callling CountSymbols! [" << myErr << "]" << endl << endl; printError(myErr); }
  74.             myErr = CloseConnection(&myConnection);
  75.         }
  76.         else
  77.         {
  78.             cout << "There was an error callling GetSharedLibrary! [" << myErr << ":'" << myErrName << "']" << endl << endl;
  79.             printError(myErr);
  80.         }
  81.         cout << endl << "done." << endl;
  82.     }
  83.  
  84.  
  85. void printError(OSErr theError)
  86.     {
  87.         switch (theError) 
  88.         {
  89. #define fragError(name,number,description) case number : { cout <<     "*** Fragment Manager Error ***" << endl\
  90. << "  Error Value : " << number << endl \
  91. << "   Error Name : " << name << endl\
  92. << "  Description : " << description << endl; break; }
  93.                                             /* Reserved values for internal "warnings".*/
  94.             fragError("fragNameNoErr",0," No error, why did you get this msg ");
  95.             fragError("fragNameContextNotFound", -2800," CFM error codes ");
  96.             fragError("fragNameConnectionIDNotFound", -2801," contextID was not valid ");
  97.             fragError("fragNameSymbolNotFound", -2802," connecionID was not valid ");
  98.             fragError("fragNameSectionNotFound", -2803," symbol was not found in connection ");
  99.             fragError("fragNameLibNotFound", -2804," section was not found ");
  100.             fragError("fragNameDupRegLibName", -2805," library name not found in Frag registry ");
  101.             fragError("fragNameFormatUnknown", -2806," registered name already in use ");
  102.             fragError("fragNameHadUnresolveds", -2807," fragment container format unknown ");
  103.             fragError("fragNameUnused1", -2808," loaded fragment had 'hard' unresolved imports ");
  104.             fragError("fragNameNoMem", -2809," unused ");
  105.             fragError("fragNameNoAddrSpace", -2810," out of memory for interal bookkeeping ");
  106.             fragError("fragNameNoContextIDs", -2811," out of memory in user's address space for loadable section ");
  107.             fragError("fragNameObjectInitSeqErr", -2812," no more context id’s ");
  108.             fragError("fragNameImportTooOld", -2813," order error during user initialization function invocation ");
  109.             fragError("fragNameImportTooNew", -2814," import library was too old and therefore incompatible ");
  110.             fragError("fragNameInitLoop", -2815," import library was too new and therefore incompatible ");
  111.             fragError("fragNameInitRtnUsageErr", -2816," circularity detected in mandatory initialization order ");
  112.             fragError("fragNameLibConnErr", -2817," boot library has initialization routine ");
  113.             fragError("fragNameMgrInitErr", -2818," error connecting to library (error occured in sub prepare) ");
  114.             fragError("fragNameConstErr", -2819," error in initailization of this manager ");
  115.             fragError("fragNameCorruptErr", -2820," internal inconstistancy ");
  116.             fragError("fragNameUserInitProcErr", -2821," fragment container corrupted (known format) ");
  117.             fragError("fragNameAppNotFound", -2822," user intialization routine did not return noErr ");
  118.             fragError("fragNameArchError", -2823," no application found in cfrg (for Process Manager) ");
  119.             fragError("fragNameInvalidFragmentUsage", -2824," fragment targeted for an unacceptable architecture ");
  120.             fragError("fragNameLastErrCode", -2899," ie: an application's main fragment had no entry point - or - an accerated resource had no entry point or it had a termination routine, etc... ");
  121.             default : { cout << "*** Fragment Manager Error ***" << endl;
  122.                         cout << "  Error Value : " << theError << endl ;
  123.                         cout << "   Error Name : * unknown *" << endl;
  124.                         cout << "  Description : n/a" << endl; break; }
  125.         }
  126.     }
  127.     
  128.     
  129.     
  130.