// Initailise for apple events, simpley checks their availible and, if specified inits the PPC tools Boolean InitializeAE(Boolean ppc) { long value; // Store the gestalt result OSErr err; // Check that we have apple events Gestalt(gestaltAppleEventsAttr,&value); if(!(value&(1<<gestaltAppleEventsPresent))) return false; #if !TARGET_API_MAC_CARBON if (ppc) { err=PPCInit(); if (err) return false; } #endif return true; }
// MkTypLib entry point VOID main ( #ifndef NO_MPW int argc, /* Number of strings in array argv */ CHAR *argv[] /* Array of command-line argument strings */ #endif // NO_MPW ) { #ifdef USE_DIMALLOC IMalloc FAR *pmalloc; #endif //USE_DIMALLOC #ifdef NO_MPW #define MAX_ARGS 21 int argc; /* Number of strings in array argv */ CHAR *argv[MAX_ARGS]; /* Array of command-line argument strings */ FILE * hFileArgs; #endif // NO_MPW int fArgErr; HRESULT res; #ifndef MAC OPENFILENAME ofn; #endif #ifdef NODEBUGALERTS WINDEBUGINFO debuginfo; GetWinDebugInfo(&debuginfo, WDI_OPTIONS); Olddebuginfo = debuginfo; // save for restoration debuginfo.dwOptions |= DBO_SILENT; SetWinDebugInfo(&debuginfo); #endif //NODEBUGALERTS // init key fields in the main 'typlib' structure before we use them typlib.pEntry = NULL; // no entries seen so far typlib.pImpLib = NULL; // no imported libraries initially #ifdef MAC #ifdef NO_MPW // Do mysterious MAC init stuff MaxApplZone(); #endif //NO_MPW InitGraf((Ptr) &qd.thePort); #ifdef NO_MPW InitFonts(); InitWindows(); InitMenus(); InitDialogs(nil); InitCursor(); #endif //NO_MPW PPCInit(); // required by OleInitialize // init the OLE Applet if ((res = InitOleManager(0)) != NOERROR) ParseError(ERR_OM); // UNDONE: correct error? fAppletInitialized = TRUE; #ifdef NO_MPW // If a file exists called "MKTYPLIB.ARG", load up argc, argv[] to satisfy // our command line parser. if (hFileArgs = fopen("mktyplib.arg", "r")) { argc = 1; while (argc < MAX_ARGS) { argv[argc] = malloc(50); if (fscanf(hFileArgs, " %s ", argv[argc]) == EOF) break; argc++; } fclose(hFileArgs); } else { // activate to output to file instead of using lame MAC MessageBox's // szOutputFile = "m.log"; // redirected output szInputFile = "m.odl"; // input file fHFile = TRUE; // want a .H file fArgErr = FALSE; // no arg error goto ArgsParsed; } #endif //NO_MPW #endif //MAC InitLeadByteTable(); fArgErr = FParseCl(argc, argv); // parse the command line #ifdef MAC #ifdef NO_MPW ArgsParsed: #endif //NO_MPW #endif //MAC if (szOutputFile) { #ifdef WIN16 // perform in-place conversion to OEM char set AnsiToOem(szOutputFile, szOutputFile); // (don't bother converting back - this string is not used again) #endif // WIN16 hFileOutput = fopen(szOutputFile, "w"); // if problem opening output file, then just revert to normal // MessageBox output. // CONSIDER: give an error, too? } if (!fNologo) { DisplayLine(szBanner); // display the copyright banner // add a blank line in some cases to make it look better if (hFileOutput) fputs("\n", hFileOutput); #ifndef WIN16 #ifndef NO_MPW else printf("\n"); #endif //NO_MPW #endif //!WIN16 } if (fArgErr || fGiveUsage) { GiveUsage: DisplayLine(szUsage); ErrorExit(); // clean up and exit(1) } #ifndef MAC // use common dialog to get input filename if user didn't specify one if (szInputFile == NULL) { szInputFile = malloc(CB_MAX_PATHNAME+1); memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); // ofn.hwndOwner = g_hwndMain; ofn.hwndOwner = NULL; ofn.lpstrFile = szInputFile; ofn.nMaxFile = CB_MAX_PATHNAME+1; *szInputFile = '\0'; ofn.lpstrFilter = "Object Description Lang.\0*.odl\0\0"; ofn.nFilterIndex = 1; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; // if anything went wrong -- just give the usage message if (GetOpenFileName(&ofn) == 0) goto GiveUsage; } #endif //!MAC Assert(szInputFile); // now compute filenames based off the input filename if (szTypeLibFile == NULL) // if output file not specified { // use input filename with ".tlb" extension szTypeLibFile = CloneNameAddExt(szInputFile, ".tlb"); } if (fHFile && szHFile == NULL) // if header filename not specified { // use input filename with ".h" extension szHFile = CloneNameAddExt(szInputFile, ".h"); } // If output file ends up with the same name as the input file, then // the user is screwed. Just give the usage message. if (!strcmp(szInputFile, szTypeLibFile)) goto GiveUsage; // If .h file ends up with the same name as either the input file or output // file, then the user is screwed. Just give the usage message. if (szHFile && (!strcmp(szInputFile, szHFile) || !strcmp(szTypeLibFile, szHFile))) goto GiveUsage; #ifdef USE_DIMALLOC // Use the dimalloc implementation, since the default implementation // doesn't work yet in mac ole. if (!GetDebIMalloc(&pmalloc)) ParseError(ERR_OM); // UNDONE: correct error? res = OLEINITIALIZE(pmalloc); pmalloc->lpVtbl->Release(pmalloc); #else // must init OLE res = OLEINITIALIZE(NULL); #endif if (FAILED(res)) ParseError(ERR_OM); // UNDONE: correct error? fOLEInitialized = TRUE; #ifndef MAC hcrsWait = LoadCursor(NULL, (LPSTR)IDC_WAIT); SetCursor(hcrsWait); // turn on the hourglass cursor // UNDONE: this doesn't always stay on in WIN16, nor does it seem to // UNDONE: have any affect in WIN32. #endif //!MAC #if FV_CPP if (fCPP) // if we're to pre-process input file DoPreProcess(); #endif //FV_CPP strcpy(szFileCur, szInputFile); // init current file name (for // error reporting) #if FV_CPP ParseOdlFile(fCPP ? szTempFile : szInputFile); // parse the input file #else ParseOdlFile(szInputFile); // parse the input file #endif #if FV_CPP if (szTempFile) { SideAssert(MyRemove(szTempFile) == 0); // delete tmp file created above szTempFile = NULL; } #endif //FV_CPP if (fHFile) // output .H file if desired OutputHFile(szHFile); // Now emit the type library OutputTyplib(szTypeLibFile); #ifdef NO_MPW // Now dump the type library DumpTypeLib(szTypeLibFile); #endif CleanupImportedTypeLibs(); // release any imported typelibs OLEUNINITIALIZE(); // terminate OLE #ifdef MAC UninitOleManager(); // clean up applet #endif //MAC DisplaySuccess(szTypeLibFile); // holy *&*%&^%, it worked!!! if (hFileOutput) // close redirected output file fclose(hFileOutput); #ifdef NODEBUGALERTS SetWinDebugInfo(&Olddebuginfo); #endif //NODEBUGALERTS exit(0); }