Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
mac_xpidl.cpp File Reference
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <new.h>
#include <setjmp.h>
#include <Files.h>
#include <Errors.h>
#include <Strings.h>
#include "FullPath.h"
#include "MoreFilesExtras.h"
#include "DropInCompilerLinker.h"
#include "CompilerMapping.h"
#include "CWPluginErrors.h"
#include "mac_xpidl.h"
#include "mac_console.h"
#include "mac_strings.h"
#include "mac_xpidl_panel.h"

Go to the source code of this file.


static CWResult Compile (CWPluginContext context)
static CWResult Disassemble (CWPluginContext context)
static CWResult LocateFile (CWPluginContext context, const char *filename, FSSpec &file)
pascal short xpidl_compiler (CWPluginContext context)
int xpidl_main (int argc, char *argv[])
int xptdump_main (int argc, char *argv[])
FILEFSp_fopen (ConstFSSpecPtr spec, const char *open_mode)
static char * full_path_to (const FSSpec &file)
static CWResult GetSettings (CWPluginContext context, XPIDLSettings &settings)
size_t mac_get_file_length (const char *filename)
 Returns the length of a file, assuming it is always located in the project's output directory.
void mac_warning (const char *warning_message)
void mac_error (const char *error_message)
CWPLUGIN_ENTRY() CWPlugin_GetDropInFlags (const DropInFlags **flags, long *flagsSize)
CWPLUGIN_ENTRY() CWPlugin_GetDropInName (const char **dropinName)
CWPLUGIN_ENTRY() CWPlugin_GetDisplayName (const char **displayName)
CWPLUGIN_ENTRY() CWPlugin_GetPanelList (const CWPanelList **panelList)
CWPLUGIN_ENTRY() CWPlugin_GetTargetList (const CWTargetList **targetList)
CWPLUGIN_ENTRY() CWPlugin_GetDefaultMappingList (const CWExtMapList **defaultMappingList)


jmp_buf exit_jump
int exit_status
CWPluginContext gPluginContext
static CWFileSpec gSourceFile
static char * gSourcePath = NULL
static CWFileSpec gOutputFile

Function Documentation

static CWResult Compile ( CWPluginContext  context) [static]

Definition at line 175 of file mac_xpidl.cpp.

       CWResult err = CWGetMainFileSpec(context, &gSourceFile);
       if (!CWSUCCESS(err))
              return (err);

       long fileNum;
       err = CWGetMainFileNumber(context, &fileNum);
       if (!CWSUCCESS(err))
              return (err);

       // get the name of the source file to compile.
       gSourcePath = p2c_strdup(;
       if (gSourcePath == NULL)
              return cwErrOutOfMemory;
       // build an argument list and call the compiler.
       XPIDLSettings settings = { kXPIDLSettingsVersion, kXPIDLModeHeader, false, false };
       GetSettings(context, settings);

#if 0  
       // if generating .xpt files, let the IDE tell us where to put the output file.
       // otherwise, put them in the project's output directory.
       if (settings.mode == kXPIDLModeTypelib)
              err = CWGetSuggestedObjectFileSpec(context, fileNum, &gOutputFile);
              err = CWGetOutputFileDirectory(gPluginContext, &gOutputFile);
       // always generate the output file into the project target's data directory.
       err = CWGetSuggestedObjectFileSpec(context, fileNum, &gOutputFile);
       if (!CWSUCCESS(err))
              return (err);
       int argc = 3;
       char* modes[] = { "header", "java", "typelib", "doc" };
       char* argv[] = { "xpidl", "-m", modes[settings.mode - 1], NULL, NULL, NULL, NULL, };
       if (settings.warnings) argv[argc++] = "-w";
       if (settings.verbose) argv[argc++] = "-v";
       argv[argc++] = gSourcePath;
       if (setjmp(exit_jump) == 0) {
              if (xpidl_main(argc, argv) != 0)
                     err = cwErrRequestFailed;
       } else {
              // evidently the good old exit function got called.
              if (exit_status != 0)
                     err = cwErrRequestFailed;

       // if the compilation succeeded, tell CodeWarrior about the output file.
       // this ensures several things:  1. if the output file is deleted by the user,
       // then the IDE will know to recompile it, which is good for dirty builds,
       // where the output files may be hand deleted; 2. if the user elects to remove
       // objects, the output files are deleted. Thanks to for
       // pointing this new CWPro4 API out.
       if (err == cwNoErr) {
              CWObjectData objectData;
              BlockZero(&objectData, sizeof(objectData));
              // for fun, show how large the output file is in the data area.
              long dataSize, rsrcSize;
              if (FSpGetFileSize(&gOutputFile, &dataSize, &rsrcSize) == noErr)
                     objectData.idatasize = dataSize;
              // tell the IDE that this file was generated by the compiler.
              objectData.objectfile = &gOutputFile;
              err = CWStoreObjectData(context, fileNum, &objectData);
       } else {
              // an error occured, delete the output file, which might be a partial file.
              if ([0] != 0) {

       delete[] gSourcePath;
       gSourcePath = NULL;

       return (err);

Here is the call graph for this function:

Here is the caller graph for this function:

CWPLUGIN_ENTRY() CWPlugin_GetDefaultMappingList ( const CWExtMapList **  defaultMappingList)

Definition at line 405 of file mac_xpidl.cpp.

       static CWExtensionMapping sExtension = { 'TEXT', ".idl", 0 };
       static CWExtMapList sExtensionMapList = { kCurrentCWExtMapListVersion, 1, &sExtension };
       *defaultMappingList = &sExtensionMapList;
       return cwNoErr;
CWPLUGIN_ENTRY() CWPlugin_GetDisplayName ( const char **  displayName)

Definition at line 375 of file mac_xpidl.cpp.

       static const char* sDisplayName = "xpidl";
       *displayName = sDisplayName;
       return cwNoErr;
CWPLUGIN_ENTRY() CWPlugin_GetDropInFlags ( const DropInFlags **  flags,
long flagsSize 

Definition at line 349 of file mac_xpidl.cpp.

       static const DropInFlags sFlags = {
              (kGeneratescode | /* kCandisassemble | */ kCompMultiTargAware | kCompAlwaysReload),
       *flags = &sFlags;
       *flagsSize = sizeof(sFlags);
       return cwNoErr;
CWPLUGIN_ENTRY() CWPlugin_GetDropInName ( const char **  dropinName)

Definition at line 366 of file mac_xpidl.cpp.

       static const char* sDropInName = "xpidl";
       *dropinName = sDropInName;
       return cwNoErr;
CWPLUGIN_ENTRY() CWPlugin_GetPanelList ( const CWPanelList **  panelList)

Definition at line 384 of file mac_xpidl.cpp.

       static const char* sPanelName = kXPIDLPanelName;
       static CWPanelList sPanelList = { kCurrentCWPanelListVersion, 1, &sPanelName };
       *panelList = &sPanelList;
       return cwNoErr;
CWPLUGIN_ENTRY() CWPlugin_GetTargetList ( const CWTargetList **  targetList)

Definition at line 394 of file mac_xpidl.cpp.

       static CWDataType sCPU = '****';
       static CWDataType sOS = '****';
       static CWTargetList sTargetList = { kCurrentCWTargetListVersion, 1, &sCPU, 1, &sOS };
       *targetList = &sTargetList;
       return cwNoErr;
static CWResult Disassemble ( CWPluginContext  context) [static]

Definition at line 257 of file mac_xpidl.cpp.

       // the disassembly code has moved to the linker.
       return noErr;

Here is the caller graph for this function:

FILE* FSp_fopen ( ConstFSSpecPtr  spec,
const char *  open_mode 

Here is the caller graph for this function:

static char* full_path_to ( const FSSpec file) [static]

Definition at line 138 of file mac_xpidl.cpp.

       short len = 0;
       Handle fullPath = NULL;
       if (FSpGetFullPath(&file, &len, &fullPath) == noErr && fullPath != NULL) {
              char* path = new char[1 + len];
              if (path != NULL) {
                     BlockMoveData(*fullPath, path, len);
                     path[len] = '\0';
              return path;
       return NULL;

Here is the caller graph for this function:

static CWResult GetSettings ( CWPluginContext  context,
XPIDLSettings settings 
) [static]

Definition at line 154 of file mac_xpidl.cpp.

       CWMemHandle   settingsHand;
       CWResult err = CWGetNamedPreferences(context, kXPIDLPanelName, &settingsHand);
       if (!CWSUCCESS(err))
              return (err);
       XPIDLSettings* settingsPtr = NULL;
       err = CWLockMemHandle(context, settingsHand, false, (void**)&settingsPtr);
       if (!CWSUCCESS(err))
              return (err);
       settings = *settingsPtr;
       err = CWUnlockMemHandle(context, settingsHand);
       if (!CWSUCCESS(err))
              return (err);

       return noErr;

Here is the caller graph for this function:

static CWResult LocateFile ( CWPluginContext  context,
const char *  filename,
FSSpec file 
) [static]

Definition at line 263 of file mac_xpidl.cpp.

       /* prefill the CWFileInfo struct */
       CWFileInfo fileinfo;
       BlockZero(&fileinfo, sizeof(fileinfo));
       // memset(&fileinfo, 0, sizeof(fileinfo));
       fileinfo.fullsearch = true;
       fileinfo.suppressload = true;
       fileinfo.dependencyType = cwNormalDependency;
       fileinfo.isdependentoffile = kCurrentCompiledFile;

       /* locate the file name using the project's access paths */
       CWResult err = CWFindAndLoadFile(context, filename, &fileinfo);
       if (err == cwNoErr) {
              file = fileinfo.filespec;
       } else if (err == cwErrFileNotFound) {
              char errmsg[200];
              sprintf(errmsg, "Can't locate file \"%s\".", filename);
              CWResult callbackResult = CWReportMessage(context, 0, errmsg, 0, messagetypeError, 0);
       return (err);
void mac_error ( const char *  error_message)

Definition at line 338 of file mac_xpidl.cpp.

       CWReportMessage(gPluginContext, 0, error_message, 0, messagetypeError, 0);
size_t mac_get_file_length ( const char *  filename)

Returns the length of a file, assuming it is always located in the project's output directory.

Returns the length of a file, assuming it is always located in the project's object code directory.

Definition at line 321 of file mac_xpidl.cpp.

       long dataSize= 0, rsrcSize = 0;
       FSSpec filespec;
       if (CWGetOutputFileDirectory(gPluginContext, &filespec) != noErr)
              return 0;
       c2p_strcpy(, filename);
       if (FSpGetFileSize(&filespec, &dataSize, &rsrcSize) != noErr)
              return 0;
       return dataSize;
void mac_warning ( const char *  warning_message)

Definition at line 333 of file mac_xpidl.cpp.

       CWReportMessage(gPluginContext, 0, warning_message, 0, messagetypeWarning, 0);

Here is the caller graph for this function:

pascal short xpidl_compiler ( CWPluginContext  context)

Definition at line 97 of file mac_xpidl.cpp.

       long request;
       if (CWGetPluginRequest(context, &request) != cwNoErr)
              return cwErrRequestFailed;
       gPluginContext = context;
       short result = cwNoErr;
       /* dispatch on compiler request */
       switch (request) {
       case reqInitCompiler:
              /* compiler has just been loaded into memory */
       case reqTermCompiler:
              /* compiler is about to be unloaded from memory */
       case reqCompile:
              /* compile a source file */
              result = Compile(context);
       case reqCompDisassemble:
              /* disassemble a source file */
              result = Disassemble(context);
              result = cwErrRequestFailed;
       /* is this necessary? */
       CWDonePluginRequest(context, result);
       /* return result code */
       return (result);

Here is the call graph for this function:

int xpidl_main ( int  argc,
char *  argv[] 

Here is the caller graph for this function:

int xptdump_main ( int  argc,
char *  argv[] 

Here is the caller graph for this function:

Variable Documentation

jmp_buf exit_jump

Definition at line 51 of file mac_stdlib.cpp.

Definition at line 52 of file mac_stdlib.cpp.

CWFileSpec gOutputFile [static]

Definition at line 87 of file mac_xpidl.cpp.

CWPluginContext gPluginContext

Definition at line 82 of file mac_xpidl.cpp.

CWFileSpec gSourceFile [static]

Definition at line 85 of file mac_xpidl.cpp.

char* gSourcePath = NULL [static]

Definition at line 86 of file mac_xpidl.cpp.