diff options
author | Ash Wolf <ninji@wuffs.org> | 2022-10-07 20:02:27 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2022-10-07 20:02:27 +0100 |
commit | 97f6a2438df1eaeb4128ce36f29346ea38a3db4a (patch) | |
tree | 78260f8f0f2b84fc70fadb1e50e7fc104390eee4 | |
download | MWCC-97f6a2438df1eaeb4128ce36f29346ea38a3db4a.tar.gz MWCC-97f6a2438df1eaeb4128ce36f29346ea38a3db4a.zip |
first very unfinished commit lol
-rw-r--r-- | Arguments.c | 604 | ||||
-rw-r--r-- | CError.c | 319 | ||||
-rw-r--r-- | CInt64.c | 893 | ||||
-rw-r--r-- | CInt64.h | 85 | ||||
-rw-r--r-- | CompilerTools.c | 1230 | ||||
-rw-r--r-- | CompilerTools.h | 134 | ||||
-rw-r--r-- | Help.c | 564 | ||||
-rw-r--r-- | Option.c | 630 | ||||
-rw-r--r-- | PCode.c | 286 | ||||
-rw-r--r-- | PCode.h | 110 | ||||
-rw-r--r-- | PCodeInfo.c | 55 | ||||
-rw-r--r-- | PCodeInfo.h | 462 | ||||
-rw-r--r-- | ParserFace.c | 226 | ||||
-rw-r--r-- | UCLTMain.c | 384 | ||||
-rw-r--r-- | UMain.c | 110 | ||||
-rw-r--r-- | mwcc_decomp.h | 1918 | ||||
-rwxr-xr-x | sdk_hdrs/CWDropInPanel.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CWPluginErrors.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CWPlugins.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CWRuntimeFeatures.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CWUnixPluginPrefix.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CWWinPluginPrefix.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CatTypes.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/CompilerMapping.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/DropInCompilerLinker.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/DropInPanel.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/DropInPanelWin32.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/DropInVCS.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/MWBrowse.h | 1 | ||||
-rwxr-xr-x | sdk_hdrs/MWLangDefs.h | 1 | ||||
-rw-r--r-- | setup.sh | 3 |
31 files changed, 8027 insertions, 0 deletions
diff --git a/Arguments.c b/Arguments.c new file mode 100644 index 0000000..2f66ee9 --- /dev/null +++ b/Arguments.c @@ -0,0 +1,604 @@ +#include "mwcc_decomp.h" + +char compat; +char *MAINOPTCHAR; +char *FIRSTARGCHAR; +char *SEPOPTSTR; +char SEPOPTCHAR; +char SEP1; +char SEP2; +char SEP3; +char RESPFILECHAR; +char *RESPFILESTR; +static ArgToken *argtoks; +static int numargtoks; +static int maxargtoks; +unsigned char parserDebug; +static unsigned char in_response_file; +static int margc; +static int margind; +static char **margv; +static OSFileHandle respfilehandle; +static char *respfile; +static char *respfilestart; +static unsigned long respfilesize; +static int scantok; +anon0_50 linkargs; +anon0_50 prelinkargs; +anon0_50 postlinkargs; + +// TODO move me +/*extern int OS_MakeFileSpec(const char *name, struct OSSpec *spec); +extern int OS_NewFileHandle(struct OSSpec *spec, int a, int b, OSFileHandle *fh); +extern int OS_AppendHandle(struct OSHandle *h, const void *, long); +extern int OS_LockFileHandle(OSFileHandle *fh, char **h, unsigned long *size); +extern void OS_FreeFileHandle(OSFileHandle *fh); +extern void CLPOSAlert(short code, short code2, ...); +extern void CLPReportError(short code, ...); +extern void CLPReportWarning(short code, ...); +extern void CLPFatalError(const char *format, ...); +extern int ustrncmp(const char *a, const char *b, int len);*/ +// TODO move me + +static void Arg_AddToken(short val, char *text); +static void Arg_Setup(int argc, char **argv); +static void Arg_SkipRespFileWS(); +static unsigned char Arg_OpenRespFile(const char *name); +static void Arg_CloseRespFile(); +static char *Arg_GetRespFileToken(); +static char *Arg_GetNext(unsigned char allow_resp); +static unsigned char Arg_GotMore(); +static void Arg_Parse(); +static void Arg_GrowArgs(anon0_50 *ta); +static void Arg_GrowArg(anon0_50 *ta, char *txt); + +static void Arg_AddToken(short val, char *text) { + ArgToken *cur; + ArgToken *prev; + ArgToken *pprev; + ArgToken *ppprev; + ArgToken *pppprev; + + if (numargtoks > 0) + prev = &argtoks[numargtoks - 1]; + else + prev = 0; + + if (prev && prev->val == ATK_2 && prev->text[0] == 0) { + pppprev = ppprev = pprev = 0; + if (numargtoks > 3) + pppprev = &argtoks[numargtoks - 4]; + if (numargtoks > 2) + ppprev = &argtoks[numargtoks - 3]; + if (numargtoks > 1) + pprev = &argtoks[numargtoks - 2]; + + if (pprev) { + if ((int) val == ATK_1 && (pprev->val == ATK_5 || pprev->val == ATK_4) && (ppprev->val != ATK_2 || pppprev->val != ATK_3)) { + if (parserDebug) + printf("Coalescing args with '%s'\n", Arg_GetTokenName(pprev)); + val = pprev->val; + numargtoks -= 2; + } else if (pprev->val == ATK_1 && ((int) val == ATK_5 || (int) val == ATK_4)) { + if (parserDebug) + printf("Coalescing args, removing '%s'\n", Arg_GetTokenName(pprev)); + numargtoks -= 2; + } + } + } + + if (numargtoks >= maxargtoks) { + argtoks = (ArgToken *) xrealloc("argument list", argtoks, sizeof(ArgToken) * (maxargtoks + 16)); + maxargtoks += 16; + } + + cur = &argtoks[numargtoks]; + cur->val = val; + if (text) + cur->text = xstrdup(text); + else + cur->text = 0; + numargtoks++; +} + +static void Arg_Setup(int argc, char **argv) { + in_response_file = 0; + respfile = 0; + margc = argc; + margv = argv; + margind = 1; +} + +static void Arg_SkipRespFileWS() { +restart: + while (respfile[0] && isspace(respfile[0])) + ++respfile; + + if (respfile[0] == '\\' && respfile[1] == '#') { + ++respfile; + return; + } + + if (respfile[0] == '#') { + if ((respfile > respfilestart) ? (respfile[-1] != '\\') : 1) { + while (respfile[0] && respfile[0] != 10 && respfile[0] != 13) + ++respfile; + + while (respfile[0] == 13 || respfile[0] == 10) + ++respfile; + + goto restart; + } + } +} + +static unsigned char Arg_OpenRespFile(const char *name) { + struct OSSpec spec; + int err; + + if ( + (err = OS_MakeFileSpec(name, &spec)) + || (err = OS_NewFileHandle(&spec, 0, 0, &respfilehandle)) + || (err = OS_AppendHandle(&respfilehandle.hand, "", 1)) + || (err = OS_LockFileHandle(&respfilehandle, &respfile, &respfilesize)) + ) { + CLPOSAlert(74, (short) err, "response ", name); + return 0; + } else { + respfilestart = respfile; + Arg_SkipRespFileWS(); + in_response_file = 1; + return 1; + } +} + +static void Arg_CloseRespFile() { + in_response_file = 0; + OS_FreeFileHandle(&respfilehandle); +} + +static char *Arg_GetRespFileToken() { + char *start; + char *ptr; + int quoting; + + quoting = 0; + if (respfile[0] == 0) + return 0; + + start = ptr = respfile; + while (respfile[0]) { + if (!quoting && isspace(respfile[0])) + break; + + if (respfile[0] == '"') { + quoting = !quoting; + respfile++; + } else if (respfile[0] == '\\' && respfile[1] == '"') { + *ptr = '"'; + respfile += 2; + ptr++; + } else { + *(ptr++) = *(respfile++); + } + } + + if (respfile[0]) + Arg_SkipRespFileWS(); + *ptr = 0; + return start; +} + +static char *Arg_GetNext(unsigned char allow_resp) { + char *ret; + int rfclen; + char *rfcequ; + +restart: + if (!in_response_file) { + rfclen = 1; + ret = margv[margind++]; + if (ret[0] == '\\' && ret[1] == RESPFILECHAR) { + ret++; + } else if (allow_resp) { + if (ret[0] == RESPFILECHAR || (RESPFILESTR[0] && !ustrncmp(ret, RESPFILESTR, rfclen = strlen(RESPFILESTR))) && ret[rfclen]) { + rfcequ = strchr(ret + rfclen, '='); + if (rfcequ) + rfclen = (rfcequ + 1) - ret; + if (Arg_OpenRespFile(ret + rfclen)) + goto restart; + ret = 0; + } + } + } else { + ret = Arg_GetRespFileToken(); + if (!ret) { + Arg_CloseRespFile(); + goto restart; + } + } + + if (parserDebug) + fprintf(stderr, "Got arg = '%s'\n", ret ? ret : "<NULL>"); + + return ret; +} + +static unsigned char Arg_GotMore() { + if (!in_response_file) + return margind < margc; + else if (respfile[0]) + return 1; + else + return margind < margc; +} + +static void Arg_Parse() { + unsigned char isOpt; + unsigned char isList; + char *arg; + char *argstart; + char buffer[4096]; + char *bufptr; + char ch; + + isOpt = 0; + isList = 0; + while (Arg_GotMore()) { + argstart = arg = Arg_GetNext(1); + if (!arg) + break; + + bufptr = buffer; + buffer[0] = 0; + isList = 0; + + if (arg[0] && arg[1] && strchr(MAINOPTCHAR, arg[0])) { + if (isOpt) + Arg_AddToken(ATK_1, 0); + buffer[0] = arg[1]; + buffer[1] = 0; + isOpt = 1; + isList = 0; + bufptr++; + arg += 2; + } else { + isOpt = 0; + } + + while (arg && arg[0]) { + ch = arg[0]; + if (arg[0] == '\\' && (arg[1] == SEP1 || arg[1] == SEP2 || arg[1] == SEP3)) { + ch = 0x80 | *(++arg); + } else if (compat == 1 && arg[0] == ':' && arg[1] == '\\') { + ch |= 0x80; + } + + if (ch != SEP1 && ch != SEP2 && ch != SEP3) { + if ((ch & 0x7F) == SEP1 || (ch & 0x7F) == SEP2 || (ch & 0x7F) == SEP3) + ch &= 0x7F; + *(bufptr++) = ch; + if (bufptr >= &buffer[sizeof(buffer)]) { + CLPReportError(2, argstart, argstart + strlen(argstart) - 15, sizeof(buffer)); + } + *bufptr = 0; + } else { + if (isOpt) { + Arg_AddToken(ATK_3, buffer); + Arg_AddToken(ATK_2, buffer); + } else { + Arg_AddToken(ATK_2, buffer); + } + + Arg_AddToken( + (unsigned char) ((ch == ',') ? ATK_5 : (((ch == '=') || (ch == SEP3)) ? ATK_4 : ATK_0)), + 0 + ); + + bufptr = buffer; + buffer[0] = 0; + + if (ch == SEP1 || ch == SEP2 || ch == SEP3) + isOpt = 0; + isList = 1; + } + + arg++; + } + + // 1799C8 + if (isOpt && bufptr > &buffer[0]) { + Arg_AddToken(ATK_3, buffer + (isList && strchr(MAINOPTCHAR, buffer[0]))); + Arg_AddToken(ATK_2, buffer + (isList && strchr(MAINOPTCHAR, buffer[0])) + 1); + } else { + Arg_AddToken(ATK_2, buffer); + Arg_AddToken(ATK_1, 0); + } + } + + if (isOpt || isList) + Arg_AddToken(ATK_1, 0); + Arg_AddToken(ATK_0, 0); +} + +enum { + COMPAT_0, + COMPAT_1, + COMPAT_2 +}; + +void Arg_Init(int theargc, char **theargv) { + int p; + int x; + + maxargtoks = 0; + numargtoks = 0; + parserDebug = 0; + if (theargc > 1 && !strcmp(theargv[1], "--parser-debug")) { + parserDebug = 1; + memmove(&theargv[1], &theargv[2], sizeof(char *) * (theargc - 1)); + theargc--; + } + + if ((int) compat == COMPAT_0) { + MAINOPTCHAR = "-"; + FIRSTARGCHAR = "="; + SEPOPTSTR = " "; + SEP1 = ','; + SEP2 = '='; + SEP3 = '='; + RESPFILECHAR = '@'; + RESPFILESTR = ""; + } else if ((int) compat == COMPAT_1) { + MAINOPTCHAR = "/-"; + FIRSTARGCHAR = ":"; + SEPOPTSTR = ":"; + SEP1 = ','; + SEP2 = '='; + SEP3 = ':'; + RESPFILECHAR = '@'; + RESPFILESTR = ""; + } else if ((int) compat == COMPAT_2) { + if (!MAINOPTCHAR) + MAINOPTCHAR = "-"; + if (!FIRSTARGCHAR) + FIRSTARGCHAR = "="; + if (!SEPOPTSTR) + SEPOPTSTR = " "; + if (!SEP1) + SEP1 = ','; + if (!SEP2) + SEP2 = '='; + if (!SEP3) + SEP3 = '='; + if (!RESPFILECHAR) + RESPFILECHAR = '@'; + if (!RESPFILESTR) + RESPFILESTR = ""; + } else { + CLPFatalError("Unknown parser compatibility type (%d)\n", (int) compat); + } + + if (parserDebug) { + printf("Incoming arguments: \n"); + for (p = 0; p < theargc; p++) { + printf("[%s] ", theargv[p]); + } + printf("\n"); + } + + Arg_Setup(theargc, theargv); + Arg_Parse(); + Arg_Reset(); + + if (parserDebug) { + for (x = 0; x < numargtoks; x++) { + printf("TOKEN: '%s'\n", Arg_GetTokenName(&argtoks[x])); + } + } +} + +void Arg_Terminate() { + ArgToken *cur; + + while (numargtoks > 0) { + cur = &argtoks[--numargtoks]; + if (cur->text) + free(cur->text); + } + + if (maxargtoks) + free(argtoks); + maxargtoks = 0; +} + +void Arg_Reset() { + scantok = 0; +} + +void Arg_Stop(ArgToken *where) { + ArgToken *cur; + + while (&argtoks[numargtoks] > where) { + cur = &argtoks[--numargtoks]; + if (cur->text) + free(cur->text); + cur->val = ATK_0; + cur->text = 0; + } + + argtoks[numargtoks++].val = ATK_1; + argtoks[numargtoks++].val = ATK_0; + scantok = numargtoks - 2; +} + +ArgToken *Arg_PeekToken() { + if (scantok >= numargtoks) + return 0; + else + return &argtoks[scantok]; +} + +ArgToken *Arg_UsedToken() { + if (scantok < numargtoks) + scantok++; + return Arg_PeekToken(); +} + +int Arg_IsEmpty() { + ArgToken *tok; + + tok = Arg_PeekToken(); + return (tok == 0 || tok->val == ATK_0); +} + +ArgToken *Arg_GetToken() { + ArgToken *ret; + + ret = Arg_PeekToken(); + if (ret) + scantok++; + return ret; +} + +ArgToken *Arg_UndoToken() { + if (scantok > 0) { + scantok--; + return Arg_PeekToken(); + } else { + return 0; + } +} + +const char *Arg_GetTokenName(ArgToken *tok) { + if ((int) tok->val == ATK_2) + return tok->text; + + return + ((int) tok->val == ATK_3) ? "option" : + ((int) tok->val == ATK_5) ? "comma" : + (((int) compat == COMPAT_1 && (int) tok->val == ATK_4)) ? "colon or equals" : + (((int) compat != COMPAT_1 && (int) tok->val == ATK_4)) ? "equals" : + ((int) tok->val == ATK_1) ? "end of argument" : + ((int) tok->val == ATK_0) ? "end of command line" : + "<error>"; +} + +const char *Arg_GetTokenText(ArgToken *tok, char *buffer, int maxlen, unsigned char warn) { + const char *ptr; + char *bptr; + int curlen; + + bptr = buffer; + curlen = 0; + if (tok->val == ATK_2 || tok->val == ATK_3) + ptr = tok->text; + else + ptr = Arg_GetTokenName(tok); + + while (*ptr && curlen++ < maxlen) { + *(bptr++) = *(ptr++); + } + + if (curlen < maxlen) { + bptr[0] = 0; + } else { + bptr[-1] = 0; + if (warn) + CLPReportWarning(56, buffer, ptr + strlen(ptr) - ((maxlen <= 32) ? maxlen : 32), maxlen); + } + + return buffer; +} + +static void Arg_GrowArgs(anon0_50 *ta) { + int len; + + if (!ta->argv || (ta->argc + 1) >= ta->nargv) { + len = ta->nargv; + ta->nargv = len + 16; + ta->argv = xrealloc("argument list", ta->argv, sizeof(char *) * (ta->nargv + 1)); + while (len <= ta->nargv) { + ta->argv[len++] = 0; + } + } + + ta->argc++; +} + +static void Arg_GrowArg(anon0_50 *ta, char *txt) { + char **ptr; + int ptrlen; + + ptr = &ta->argv[ta->argc]; + + if (*ptr == 0) { + *ptr = xstrdup(txt); + } else { + ptrlen = strlen(*ptr); + *ptr = xrealloc("command line", *ptr, ptrlen + strlen(txt) + 1); + strcpy(*ptr + ptrlen, txt); + } +} + +void Arg_InitToolArgs(anon0_50 *ta) { + ta->argc = 0; + ta->nargv = 0; + ta->argv = 0; + Arg_GrowArgs(ta); +} + +void Arg_AddToToolArgs(anon0_50 *ta, short tokval, char *toktxt) { + switch (tokval) { + case ATK_0: + Arg_FinishToolArgs(ta); + break; + case ATK_1: + if (ta->argv && ta->argv[ta->argc]) + Arg_GrowArgs(ta); + break; + case ATK_2: + Arg_GrowArg(ta, toktxt); + break; + case ATK_3: + Arg_GrowArg(ta, "-"); + break; + case ATK_4: + Arg_GrowArg(ta, "="); + break; + case ATK_5: + Arg_GrowArg(ta, ","); + break; + default: +#line 787 + CLPFatalError(__FILE__, __LINE__, "Unknown token (%d)", tokval); + break; + } +} + +void Arg_FinishToolArgs(anon0_50 *ta) { + Arg_GrowArgs(ta); + ta->argv[ta->argc] = 0; +} + +void Arg_ToolArgsForPlugin(anon0_50 *ta, struct CWCommandLineArgs *args) { + args->argc = 1; + args->argv = ta->argv; + + while (args->argv[args->argc]) + args->argc++; + + args->envp = 0; +} + +void Arg_FreeToolArgs(anon0_50 *ta) { + int x; + + if (ta->argv) { + for (x = 1; x < ta->argc; x++) { + if (ta->argv[x]) + free(ta->argv[x]); + } + free(ta->argv); + } +} diff --git a/CError.c b/CError.c new file mode 100644 index 0000000..5179463 --- /dev/null +++ b/CError.c @@ -0,0 +1,319 @@ +#include "CError.h" +#include "CompilerTools.h" + +// TODO MOVE ME +extern char *CMangler_GetOperator(StringNode *str); +extern jmp_buf errorreturn; +extern unsigned char cprep_nomem_exit; +extern unsigned char anyerrors; +extern unsigned char fatalerrors; +extern char string[256]; +// TODO MOVE ME + +Token *cerror_locktoken; +static Token *cerror_token; +static short cerror_errorcount; +static int cerror_lasterrorline; +// cerror_synchdata +// cerror_synchoffset +int CError_BreakPointcount; + +void CError_Init() { + cerror_errorcount = 0; + cerror_lasterrorline = -1; + cerror_token = 0; + cerror_locktoken = 0; +} + +void CError_SetErrorToken(Token *token) { + if (token && token->x4) + cerror_token = token; +} + +void CError_SetNullErrorToken() { + cerror_token = (Token *) -1; +} + +void CError_LockErrorPos(Token *token, Token **saved) { + *saved = cerror_locktoken; + if (token && token->x4) + cerror_locktoken = token; +} + +void CError_UnlockErrorPos(Token **saved) { + cerror_locktoken = *saved; +} + +void CError_ResetErrorSkip() { + cerror_lasterrorline = -1; +} + +void CError_GetErrorString(char *buf, short code) { + // This feels dirty, surely this can't have been the solution... + int code_ = code; +#line 142 + CError_ASSERT(code_ >= 100 && code_ < 393); + COS_GetString(buf, 10000, (short) (code_ - 99)); +} + +void CError_BufferInit(CErrorBuffer *eb, char *buf, long bufSize) { + eb->start = eb->end = buf; + eb->size = eb->remaining = bufSize - 1; +} + +void CError_BufferGrow(CErrorBuffer *eb, long amount) { + char *newBuf; + + newBuf = lalloc(eb->size + amount); + memcpy(newBuf, eb->start, eb->size); + eb->start = newBuf; + eb->end = newBuf + eb->size - eb->remaining; + eb->size += amount; + eb->remaining += amount; +} + +void CError_BufferAppendChar(CErrorBuffer *eb, char ch) { + if (eb) { + if (!eb->remaining) + CError_BufferGrow(eb, 256); + *(eb->end++) = ch; + eb->remaining--; + } +} + +void CError_BufferAppendString(CErrorBuffer *eb, const char *str) { + size_t len; + + if (eb) { + len = strlen(str); + if (eb->remaining < len) + CError_BufferGrow(eb, len); + memcpy(eb->end, str, len); + eb->end += len; + eb->remaining -= len; + } +} + +void CError_BufferTerminate(CErrorBuffer *eb) { + if (eb->remaining == 0) + CError_BufferGrow(eb, 1); + *eb->end = 0; + eb->remaining = 0; +} + +void CError_BufferAppendQualifier(CErrorBuffer *eb, int quals) { + +} + +void CError_BufferAppendTemplArgExpr(CErrorBuffer *eb, void *targExpr) { + +} + +void CError_BufferAppendTemplArg(CErrorBuffer *eb, void *targ) { + +} + +void CError_BufferAppendTemplArgs(CErrorBuffer *eb, void *targs) { + +} + +void CError_BufferAppendNameSpace(CErrorBuffer *eb, void *ns) { + +} + +void CError_BufferAppendPType(CErrorBuffer *eb, void *ty) { + +} + +void CError_BufferAppendTemplDepType(CErrorBuffer *eb, void *ty) { + +} + +void CError_BufferAppendFuncArgs(CErrorBuffer *eb, void *args, unsigned char flag) { + +} + +void CError_BufferAppendType(CErrorBuffer *eb, void *ty, int quals) { + +} + +char *CError_GetTypeName(void *ty, int quals, unsigned char useGlobalHeap) { + CErrorBuffer eb; + char buf[256]; + char *ptr; + + CError_BufferInit(&eb, buf, sizeof(buf)); + CError_BufferAppendType(&eb, ty, quals); + CError_BufferTerminate(&eb); + + if (useGlobalHeap) + ptr = galloc(eb.size + 1); + else + ptr = lalloc(eb.size + 1); + + return strcpy(ptr, eb.start); +} + +void CError_AppendUnqualFunctionName(CErrorBuffer *eb, void *unk1, void *unk2, void *unk3) { + +} + +void CError_AppendFunctionName(CErrorBuffer *eb, void *unk1, void *unk2, void *unk3, void *unk4) { + +} + +void CError_AppendObjectName(CErrorBuffer *eb, void *obj) { + +} + +void CError_AppendMethodName(CErrorBuffer *eb, void *obj) { + +} + +char *CError_GetQualifiedName(void *ns, StringNode *name) { + CErrorBuffer eb; + char buf[256]; + char *ptr; + + CError_BufferInit(&eb, buf, sizeof(buf)); + CError_BufferAppendNameSpace(&eb, ns); + CError_BufferAppendString(&eb, name->data); + CError_BufferTerminate(&eb); + + ptr = lalloc(eb.size + 1); + return strcpy(ptr, eb.start); +} + +char *CError_GetFunctionName(void *a, void *b, void *c) { + CErrorBuffer eb; + char buf[256]; + char *ptr; + + CError_BufferInit(&eb, buf, sizeof(buf)); + CError_AppendFunctionName(&eb, a, b, 0, c); + CError_BufferTerminate(&eb); + + ptr = lalloc(eb.size + 1); + return strcpy(ptr, eb.start); +} + +char *CError_GetObjectName(void *obj) { + CErrorBuffer eb; + char buf[256]; + char *ptr; + + CError_BufferInit(&eb, buf, sizeof(buf)); + CError_AppendObjectName(&eb, obj); + CError_BufferTerminate(&eb); + + ptr = lalloc(eb.size + 1); + return strcpy(ptr, eb.start); +} + +char *CError_GetNameString(void *obj, StringNode *operatorName) { + CErrorBuffer eb; + char buf[256]; + char *ptr; + char *opStr; + + CError_ASSERT(operatorName); + + // TODO lolol + CError_BufferInit(&eb, buf, sizeof(buf)); + CError_AppendObjectName(&eb, obj); + CError_BufferTerminate(&eb); + + ptr = lalloc(eb.size + 1); + return strcpy(ptr, eb.start); +} + +void CError_ErrorMessage(int errTable, char *buf, unsigned char flag1, unsigned char flag2) { + +} + +void CError_BufferAppendTemplateStack(CErrorBuffer *eb) { + +} + +void CError_ErrorMessageVA(short code, char *buf, va_list list, unsigned char flag1, unsigned char flag2) { + +} + +void CError_VAErrorMessage(short code, va_list list, unsigned char flag1, unsigned char flag2) { + char buf[256]; + + CError_GetErrorString(buf, code); + CError_ErrorMessageVA(code + 10000, buf, list, flag1, flag2); +} + +void CError_Error(short code, ...) { + +} + +void CError_ErrorTerm(short code) { + CError_GetErrorString(string, code); + CError_ErrorMessage(code + 10000, string, 0, 0); + longjmp(errorreturn, 1); +} + +void CError_ErrorSkip(short code, ...) { + // TODO trychain, tk +} + +void CError_ErrorFuncCall(short code, void *aa, void *bb) { + +} + +void CError_OverloadedFunctionError2(void *aa, void *bb, void *cc) { + +} + +void CError_OverloadedFunctionError(void *aa, void *bb) { + +} + +void CError_AbstractClassError() { + // TODO CClass +} + +void CError_Warning(short code, ...) { + // TODO lol +} + +void CError_BreakPoint(const char *a, const char *b) { + if (!a || !strcmp(a, b)) + CError_BreakPointcount++; +} + +void CError_Internal(char *filename, int line) { + char tmp[128]; + CompilerGetCString(5, tmp); + sprintf(string, tmp, filename, line); + CError_ErrorMessage(10001, string, 1, 0); + longjmp(errorreturn, 1); + CError_BreakPoint(0, 0); +} + +void CError_ExpressionTooComplex() { + CompilerGetCString(6, string); + CError_ErrorMessage(10002, string, 1, 0); + longjmp(errorreturn, 1); +} + +void CError_NoMem() { + cprep_nomem_exit = 1; + longjmp(errorreturn, 1); +} + +void CError_UserBreak() { + CompilerGetCString(8, string); + longjmp(errorreturn, 1); +} + +void CError_CannotOpen() { + // TODO +} + +void CError_QualifierCheck(int quals) { + +} diff --git a/CInt64.c b/CInt64.c new file mode 100644 index 0000000..9b793bd --- /dev/null +++ b/CInt64.c @@ -0,0 +1,893 @@ +#include <MacHeadersMach-O> +#include "CInt64.h" + +const CInt64 cint64_negone = {0xFFFFFFFF, 0xFFFFFFFF}; +const CInt64 cint64_zero = {0, 0}; +const CInt64 cint64_one = {0, 1}; +const CInt64 cint64_max = {0x7FFFFFFF, 0xFFFFFFFF}; +const CInt64 cint64_min = {0x80000000, 0}; + +#define SHIFT_LEFT_ONE(a, b) do { a <<= 1; if (b & 0x80000000) { a |= 1; } b <<= 1; } while(0) + +void CInt64_Init() { +} + +CInt64 CInt64_Not(CInt64 input) { + CInt64 output; + unsigned char c; + + c = (input.a == 0 && input.b == 0); + CInt64_SetLong(&output, c); + + return output; +} + +CInt64 CInt64_Inv(CInt64 input) { + CInt64 output; + output.a = ~input.a; + output.b = ~input.b; + return output; +} + +CInt64 CInt64_Add(CInt64 lhs, CInt64 rhs) { + if (lhs.b & 0x80000000) { + if (rhs.b & 0x80000000) { + lhs.b += rhs.b; + lhs.a += 1; + } else { + lhs.b += rhs.b; + if (!(lhs.b & 0x80000000)) + lhs.a += 1; + } + } else { + if (rhs.b & 0x80000000) { + lhs.b += rhs.b; + if (!(lhs.b & 0x80000000)) + lhs.a += 1; + } else { + lhs.b += rhs.b; + } + } + lhs.a += rhs.a; + return lhs; +} + +CInt64 CInt64_Neg(CInt64 input) { + CInt64 result; + result = CInt64_Add(CInt64_Inv(input), cint64_one); + return result; +} + +CInt64 CInt64_Sub(CInt64 lhs, CInt64 rhs) { + lhs = CInt64_Add(lhs, CInt64_Neg(rhs)); + return lhs; +} + +CInt64 CInt64_MulU(CInt64 lhs, CInt64 rhs) { + CInt64 result; + CInt64 work1; + unsigned long aaaa; + unsigned long bbbb; + unsigned long cccc; + unsigned long dddd; + unsigned long eeee; + + aaaa = rhs.b; + result.a = result.b = 0; + bbbb = lhs.b; + cccc = rhs.a; + dddd = rhs.b; + + while (bbbb != 0) { + if (bbbb & 1) { + work1.a = cccc; + work1.b = dddd; + result = CInt64_Add(result, work1); + } + cccc <<= 1; + if (dddd & 0x80000000) + cccc |= 1; + dddd <<= 1; + bbbb >>= 1; + } + + eeee = lhs.a; + while (eeee != 0 && aaaa != 0) { + if (eeee & 1) + result.a += aaaa; + aaaa <<= 1; + eeee >>= 1; + } + + return result; +} + +CInt64 CInt64_Mul(CInt64 lhs, CInt64 rhs) { + if (CInt64_IsNegative(&rhs)) { + if (CInt64_IsNegative(&lhs)) { + return CInt64_MulU(CInt64_Neg(lhs), CInt64_Neg(rhs)); + } + return CInt64_Neg(CInt64_MulU(lhs, CInt64_Neg(rhs))); + } + if (CInt64_IsNegative(&lhs)) { + return CInt64_Neg(CInt64_MulU(CInt64_Neg(lhs), rhs)); + } + return CInt64_MulU(lhs, rhs); +} + +void CInt64_DivMod(const CInt64 *lhs, const CInt64 *rhs, CInt64 *pDiv, CInt64 *pMod) { + unsigned char bad; + unsigned long workA; + unsigned long workB; + unsigned long leftA; + unsigned long leftB; + unsigned long rightA; + unsigned long rightB; + unsigned long outA; + unsigned long outB; + CInt64 work; + int counter; + + bad = (rhs->a == 0) && (rhs->b == 0); + if (!bad) { + workA = 0; + workB = 0; + leftA = lhs->a; + leftB = lhs->b; + rightA = rhs->a; + rightB = rhs->b; + outA = 0; + outB = 0; + counter = 0; + + do { + workA <<= 1; + if (workB & 0x80000000) + workA |= 1; + workB <<= 1; + if (leftA & 0x80000000) + workB |= 1; + leftA <<= 1; + if (leftB & 0x80000000) + leftA |= 1; + leftB <<= 1; + + outA <<= 1; + if (outB & 0x80000000) + outA |= 1; + outB <<= 1; + + if (workA <= rightA) { + if (workA != rightA) + continue; + if (workB < rightB) + continue; + } + + outB |= 1; + + work.a = workA; + work.b = workB; + work = CInt64_Sub(work, *rhs); + workA = work.a; + workB = work.b; + } while (++counter < 64); + + if (pDiv) { + pDiv->a = outA; + pDiv->b = outB; + } + if (pMod) { + pMod->a = workA; + pMod->b = workB; + } + } +} + +CInt64 CInt64_Div(CInt64 lhs, CInt64 rhs) { + CInt64 result; + if (CInt64_IsNegative(&rhs)) { + rhs = CInt64_Neg(rhs); + if (CInt64_IsNegative(&lhs)) { + lhs = CInt64_Neg(lhs); + CInt64_DivMod(&lhs, &rhs, &result, 0); + return result; + } else { + CInt64_DivMod(&lhs, &rhs, &result, 0); + return CInt64_Neg(result); + } + } else { + if (CInt64_IsNegative(&lhs)) { + lhs = CInt64_Neg(lhs); + CInt64_DivMod(&lhs, &rhs, &result, 0); + return CInt64_Neg(result); + } else { + CInt64_DivMod(&lhs, &rhs, &result, 0); + return result; + } + } +} + +CInt64 CInt64_DivU(CInt64 lhs, CInt64 rhs) { + CInt64 result; + CInt64_DivMod(&lhs, &rhs, &result, 0); + return result; +} + +CInt64 CInt64_Mod(CInt64 lhs, CInt64 rhs) { + CInt64 result; + if (CInt64_IsNegative(&lhs)) { + lhs = CInt64_Neg(lhs); + if (CInt64_IsNegative(&rhs)) + rhs = CInt64_Neg(rhs); + CInt64_DivMod(&lhs, &rhs, 0, &result); + return CInt64_Neg(result); + } else { + if (CInt64_IsNegative(&rhs)) + rhs = CInt64_Neg(rhs); + CInt64_DivMod(&lhs, &rhs, 0, &result); + return result; + } +} + +CInt64 CInt64_ModU(CInt64 lhs, CInt64 rhs) { + CInt64 result; + CInt64_DivMod(&lhs, &rhs, 0, &result); + return result; +} + +CInt64 CInt64_Shl(CInt64 lhs, CInt64 rhs) { + int counter; + unsigned long a; + unsigned long b; + + if (rhs.a == 0 && rhs.b < 64) { + a = lhs.a; + b = lhs.b; + for (counter = rhs.b; counter != 0; --counter) { + a <<= 1; + if (b & 0x80000000) + a |= 1; + b <<= 1; + } + lhs.a = a; + lhs.b = b; + } else { + lhs.a = 0; + lhs.b = 0; + } + return lhs; +} + +CInt64 CInt64_Shr(CInt64 lhs, CInt64 rhs) { + int counter; + long a; + unsigned long b; + + if (rhs.a == 0 && rhs.b < 64) { + a = lhs.a; + b = lhs.b; + for (counter = rhs.b; counter != 0; --counter) { + b >>= 1; + if (a & 1) + b |= 0x80000000; + a >>= 1; + } + lhs.a = a; + lhs.b = b; + } else { + if (lhs.a & 0x80000000) { + lhs.a = 0xFFFFFFFF; + lhs.b = 0xFFFFFFFF; + } else { + lhs.a = 0; + lhs.b = 0; + } + } + return lhs; +} + +CInt64 CInt64_ShrU(CInt64 lhs, CInt64 rhs) { + int counter; + unsigned long a; + unsigned long b; + + if (rhs.a == 0 && rhs.b < 64) { + a = lhs.a; + b = lhs.b; + for (counter = rhs.b; counter != 0; --counter) { + b >>= 1; + if (a & 1) + b |= 0x80000000; + a >>= 1; + } + lhs.a = a; + lhs.b = b; + } else { + lhs.a = 0; + lhs.b = 0; + } + return lhs; +} + +int CInt64_UnsignedCompare(const CInt64 *lhs, const CInt64 *rhs) { + if (lhs->a == rhs->a) { + if (lhs->b < rhs->b) + return -1; + else + return lhs->b > rhs->b; + } else { + return ((unsigned long) lhs->a < rhs->a) ? -1 : 1; + } +} + +int CInt64_SignedCompare(const CInt64 *lhs, const CInt64 *rhs) { + CInt64 lhs_; + CInt64 rhs_; + + lhs_ = CInt64_Xor(*lhs, cint64_min); + rhs_ = CInt64_Xor(*rhs, cint64_min); + return CInt64_UnsignedCompare(&lhs_, &rhs_); +} + +unsigned char CInt64_Less(CInt64 lhs, CInt64 rhs) { + return CInt64_SignedCompare(&lhs, &rhs) < 0; +} + +unsigned char CInt64_LessU(CInt64 lhs, CInt64 rhs) { + return CInt64_UnsignedCompare(&lhs, &rhs) < 0; +} + +unsigned char CInt64_Greater(CInt64 lhs, CInt64 rhs) { + return CInt64_SignedCompare(&lhs, &rhs) > 0; +} + +unsigned char CInt64_GreaterU(CInt64 lhs, CInt64 rhs) { + return CInt64_UnsignedCompare(&lhs, &rhs) > 0; +} + +unsigned char CInt64_LessEqual(CInt64 lhs, CInt64 rhs) { + return CInt64_SignedCompare(&lhs, &rhs) <= 0; +} + +unsigned char CInt64_LessEqualU(CInt64 lhs, CInt64 rhs) { + return CInt64_UnsignedCompare(&lhs, &rhs) <= 0; +} + +unsigned char CInt64_GreaterEqual(CInt64 lhs, CInt64 rhs) { + return CInt64_SignedCompare(&lhs, &rhs) >= 0; +} + +unsigned char CInt64_GreaterEqualU(CInt64 lhs, CInt64 rhs) { + return CInt64_UnsignedCompare(&lhs, &rhs) >= 0; +} + +unsigned char CInt64_Equal(CInt64 lhs, CInt64 rhs) { + return lhs.a == rhs.a && lhs.b == rhs.b; +} + +unsigned char CInt64_NotEqual(CInt64 lhs, CInt64 rhs) { + return lhs.a != rhs.a || lhs.b != rhs.b; +} + +unsigned char CInt64_IsInRange(CInt64 value, short len) { + CInt64 bound; + + if (value.a & 0x80000000) { + switch (len) { + case 1: + bound.b = 0xFFFFFF80; + bound.a = 0xFFFFFFFF; + break; + case 2: + bound.b = 0xFFFF8000; + bound.a = 0xFFFFFFFF; + break; + case 4: + bound.b = 0x80000000; + bound.a = 0xFFFFFFFF; + break; + case 8: + return 1; + default: + return 0; + } + return CInt64_GreaterEqual(value, bound); + } else { + switch (len) { + case 1: + bound.b = 0x7F; + bound.a = 0; + break; + case 2: + bound.b = 0x7FFF; + bound.a = 0; + break; + case 4: + bound.b = 0x7FFFFFFF; + bound.a = 0; + break; + case 8: + return 1; + default: + return 0; + } + return CInt64_LessEqual(value, bound); + } +} + +unsigned char CInt64_IsInURange(CInt64 value, short len) { + switch (len) { + case 1: + return value.a == 0 && (value.b & 0xFFFFFF00) == 0; + case 2: + return value.a == 0 && (value.b & 0xFFFF0000) == 0; + case 4: + return value.a == 0; + case 8: + return 1; + default: + return 0; + } +} + +CInt64 CInt64_And(CInt64 lhs, CInt64 rhs) { + lhs.a &= rhs.a; + lhs.b &= rhs.b; + return lhs; +} + +CInt64 CInt64_Xor(CInt64 lhs, CInt64 rhs) { + lhs.a ^= rhs.a; + lhs.b ^= rhs.b; + return lhs; +} + +CInt64 CInt64_Or(CInt64 lhs, CInt64 rhs) { + lhs.a |= rhs.a; + lhs.b |= rhs.b; + return lhs; +} + +void CInt64_ConvertInt32(CInt64 *i) { + CInt64_Extend32(i); +} + +void CInt64_ConvertUInt32(CInt64 *i) { + CInt64_SetULong(i, (unsigned long) i->b); +} + +void CInt64_ConvertInt16(CInt64 *i) { + i->b = (short) i->b; + CInt64_Extend32(i); +} + +void CInt64_ConvertUInt16(CInt64 *i) { + CInt64_SetULong(i, (unsigned short) i->b); +} + +void CInt64_ConvertInt8(CInt64 *i) { + i->b = (char) i->b; + CInt64_Extend32(i); +} + +void CInt64_ConvertUInt8(CInt64 *i) { + CInt64_SetULong(i, (unsigned char) i->b); +} + +void CInt64_ConvertUFromLongDouble(CInt64 *pResult, double value) { + union { float f; unsigned long l; } cvt; + unsigned long a, b; + float threshold; + int bits; + + if (value <= 0.0) { + pResult->a = 0; + pResult->b = 0; + return; + } + + cvt.l = 0x5F800000; + if (value >= cvt.f) { + pResult->a = 0xFFFFFFFF; + pResult->b = 0xFFFFFFFF; + return; + } + + a = b = 0; + for (bits = 63; bits >= 0; bits--) { + a <<= 1; + if (b & 0x80000000) + a |= 1; + b <<= 1; + + if ((short) bits == 0) { + threshold = 1.0f; + } else { + cvt.l = (((short) bits + 127) & 255) << 23; + threshold = cvt.f; + } + + if (threshold <= value) { + b |= 1; + value -= threshold; + } + } + + pResult->a = a; + pResult->b = b; +} + +void CInt64_ConvertFromLongDouble(CInt64 *pResult, double value) { + if (value < 0.0) { + CInt64_ConvertUFromLongDouble(pResult, -value); + *pResult = CInt64_Neg(*pResult); + } else { + CInt64_ConvertUFromLongDouble(pResult, value); + } +} + +double CInt64_ConvertUToLongDouble(const CInt64 *value) { + unsigned char bad; + unsigned long work; + int counter; + double result; + + bad = (value->a == 0) && (value->b == 0); + if (bad) { + return 0.0; + } else { + result = 0.0; + + work = value->a; + if (work != 0) { + for (counter = 0; counter < 32; counter++) { + result += result; + if (work & 0x80000000) + result += 1.0; + work <<= 1; + } + } + + counter = 0; + work = value->b; + for (; counter < 32; counter++) { + result += result; + if (work & 0x80000000) + result += 1.0; + work <<= 1; + } + + return result; + } +} + +double CInt64_ConvertToLongDouble(const CInt64 *value) { + CInt64 tmp; + if (value->a & 0x80000000) { + tmp = CInt64_Neg(*value); + return -CInt64_ConvertUToLongDouble(&tmp); + } else { + return CInt64_ConvertUToLongDouble(value); + } +} + +char *CInt64_ScanOctString(CInt64 *pResult, char *str, unsigned char *pFail) { + int ch; + CInt64 tmp; + unsigned long a; + unsigned long b; + + *pFail = 0; + pResult->a = pResult->b = 0; + + while ((ch = *str) >= '0' && *str <= '7') { + a = pResult->a; + b = pResult->b; + if (a & 0xE0000000) + *pFail = 1; + + SHIFT_LEFT_ONE(a, b); + SHIFT_LEFT_ONE(a, b); + SHIFT_LEFT_ONE(a, b); + + pResult->a = a; + pResult->b = b; + + CInt64_SetLong(&tmp, ch - '0'); + *pResult = CInt64_Add(*pResult, tmp); + ++str; + } + + return str; +} + +char *CInt64_ScanDecString(CInt64 *pResult, char *str, unsigned char *pFail) { + int ch; + CInt64 tmp; + unsigned long a; + unsigned long b; + + *pFail = 0; + pResult->a = pResult->b = 0; + + while ((ch = *str) >= '0' && *str <= '9') { + a = pResult->a; + b = pResult->b; + if (a & 0xE0000000) + *pFail = 1; + + SHIFT_LEFT_ONE(a, b); + tmp.a = a; + tmp.b = b; + SHIFT_LEFT_ONE(a, b); + SHIFT_LEFT_ONE(a, b); + pResult->a = a; + pResult->b = b; + + if (CInt64_IsNegative(pResult)) { + *pResult = CInt64_Add(*pResult, tmp); + if (!CInt64_IsNegative(pResult)) + *pFail = 1; + } else { + *pResult = CInt64_Add(*pResult, tmp); + } + + CInt64_SetLong(&tmp, ch - '0'); + if (CInt64_IsNegative(pResult)) { + *pResult = CInt64_Add(*pResult, tmp); + if (!CInt64_IsNegative(pResult)) + *pFail = 1; + } else { + *pResult = CInt64_Add(*pResult, tmp); + } + + ++str; + } + + return str; +} + +char *CInt64_ScanHexString(CInt64 *pResult, char *str, unsigned char *pFail) { + /* NOT MATCHING */ + int digit; + CInt64 tmp; + unsigned long a; + unsigned long b; + + *pFail = 0; + pResult->a = pResult->b = 0; + + for (;;) { + if ((digit = str[0]) >= '0' && digit <= '9') + digit = digit - '0'; + else if (digit >= 'A' && digit <= 'F') + digit = digit - 'A' + 10; + else if (digit >= 'a' && digit <= 'f') + digit = digit - 'a' + 10; + else + break; + + a = pResult->a; + b = pResult->b; + ++str; + + if (a & 0xF0000000) + *pFail = 1; + + SHIFT_LEFT_ONE(a, b); + SHIFT_LEFT_ONE(a, b); + SHIFT_LEFT_ONE(a, b); + SHIFT_LEFT_ONE(a, b); + + pResult->a = a; + pResult->b = b; + + CInt64_SetLong(&tmp, (char) digit); + *pResult = CInt64_Add(*pResult, tmp); + } + + return str; +} + +char *CInt64_ScanBinString(CInt64 *pResult, char *str, unsigned char *pFail) { + char digit; + unsigned long a; + unsigned long b; + + *pFail = 0; + pResult->a = pResult->b = 0; + + for (;;) { + if (*str == '0') + digit = 0; + else if (*str == '1') + digit = 1; + else + break; + + a = pResult->a; + b = pResult->b; + ++str; + + if (a & 0x80000000) + *pFail = 1; + + SHIFT_LEFT_ONE(a, b); + + pResult->a = a; + pResult->b = b; + + if (digit == 1) + *pResult = CInt64_Add(*pResult, cint64_one); + } + + return str; +} + +char *CInt64_ScanAsmNumber(CInt64 *pResult, char *str, unsigned char *pFail) { + unsigned char isMaybeBin; + unsigned char isOct; + unsigned char isMaybeDec; + unsigned char isBin; + char *p; + + isMaybeBin = 1; + isOct = *str == '0'; + isMaybeDec = 1; + isBin = 0; + p = str; + + for (;;) { + if (*p == 0) + break; + + if (strchr("01", p[0])) { + if (isBin) + isMaybeBin = 0; + } else if (strchr("bB", p[0])) { + isBin = 1; + isMaybeDec = 0; + isOct = 0; + } else if (strchr("234567", p[0])) { + isMaybeBin = 0; + } else if (strchr("89", p[0])) { + isOct = 0; + isMaybeBin = 0; + } else if (strchr("acdefACEDF", p[0])) { + isMaybeDec = 0; + isMaybeBin = 0; + } else { + break; + } + + ++p; + } + + if (isMaybeBin && isBin) { + return CInt64_ScanBinString(pResult, str, pFail) + 1; + } else if (p[0] == 'h' || p[0] == 'H') { + return CInt64_ScanHexString(pResult, str, pFail) + 1; + } else if (isOct) { + return CInt64_ScanOctString(pResult, str, pFail); + } else if (isMaybeDec) { + return CInt64_ScanDecString(pResult, str, pFail); + } else { + *pFail = 1; + return p; + } +} + +int CInt64_PrintDec(char *output, CInt64 value) { + int length; + CInt64 rem; + CInt64 divisor; + char buf[40]; + char *bufp; + + length = 0; + if (CInt64_IsNegative(&value)) { + value = CInt64_Neg(value); + *output = '-'; + length++; + output++; + } + + if (!CInt64_IsZero(&value)) { + divisor.b = 10; + divisor.a = 0; + + bufp = buf; + for (;;) { + rem = CInt64_ModU(value, divisor); + *(bufp++) = rem.b + '0'; + value = CInt64_DivU(value, divisor); + if (CInt64_IsZero(&value) != 0) + break; + } + + while (--bufp >= buf) { + *(output++) = *bufp; + length++; + } + } else { + *(output++) = '0'; + length++; + } + + *output = 0; + return length; +} + +int CInt64_PrintHex(char *output, CInt64 value) { + int length; + CInt64 rem; + CInt64 shift; + CInt64 mask; + char buf[32]; + char *bufp; + + length = 0; + if (!CInt64_IsZero(&value)) { + shift.b = 4; + shift.a = 0; + mask.b = 0xF; + mask.a = 0; + + bufp = buf; + for (;;) { + rem = CInt64_And(value, mask); + if ((long) rem.b >= 10) + *(bufp++) = rem.b + 'A'; + else + *(bufp++) = rem.b + '0'; + value = CInt64_ShrU(value, shift); + if (CInt64_IsZero(&value) != 0) + break; + } + + while (--bufp >= buf) { + *(output++) = *bufp; + length++; + } + } else { + *(output++) = '0'; + length++; + } + + *output = 0; + return length; +} + +int CInt64_PrintBin(char *output, CInt64 value) { + int length; + CInt64 rem; + char buf[64]; + char *bufp; + + length = 0; + if (!CInt64_IsZero(&value)) { + bufp = buf; + for (;;) { + rem = CInt64_And(value, cint64_one); + if (CInt64_Equal(rem, cint64_one)) + *(bufp++) = '1'; + else + *(bufp++) = '0'; + value = CInt64_ShrU(value, cint64_one); + if (CInt64_IsZero(&value) != 0) + break; + } + + while (--bufp >= buf) { + *(output++) = *bufp; + length++; + } + } else { + *(output++) = '0'; + length++; + } + + *output = 0; + return length; +} diff --git a/CInt64.h b/CInt64.h new file mode 100644 index 0000000..37030f9 --- /dev/null +++ b/CInt64.h @@ -0,0 +1,85 @@ +#pragma once + +typedef struct _CInt64 { + long a; + unsigned long b; +} CInt64; + +// make sure this is in the right place +extern const CInt64 cint64_negone; +extern const CInt64 cint64_zero; +extern const CInt64 cint64_one; +extern const CInt64 cint64_max; +extern const CInt64 cint64_min; + +inline int CInt64_IsNegative(const CInt64 *n) { + return (n->a & 0x80000000) != 0; +} +inline void CInt64_SetLong(CInt64 *pN, long n) { + pN->b = n; + pN->a = (n < 0) ? 0xFFFFFFFF : 0; +} +inline void CInt64_SetULong(CInt64 *pN, unsigned long n) { + pN->b = n; + pN->a = 0; +} + +// i don't think this one is real lol +inline int CInt64_IsZero(CInt64 *n) { + return n->a == 0 && n->b == 0; +} +inline void CInt64_Extend32(CInt64 *n) { // assumed name + n->a = (n->b >> 31) ? 0xFFFFFFFF : 0; +} + +extern void CInt64_Init(); +extern CInt64 CInt64_Not(CInt64 input); +extern CInt64 CInt64_Inv(CInt64 input); +extern CInt64 CInt64_Add(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Neg(CInt64 input); +extern CInt64 CInt64_Sub(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_MulU(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Mul(CInt64 lhs, CInt64 rhs); +extern void CInt64_DivMod(const CInt64 *lhs, const CInt64 *rhs, CInt64 *pDiv, CInt64 *pMod); +extern CInt64 CInt64_Div(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_DivU(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Mod(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_ModU(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Shl(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Shr(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_ShrU(CInt64 lhs, CInt64 rhs); +extern int CInt64_UnsignedCompare(const CInt64 *lhs, const CInt64 *rhs); +extern int CInt64_SignedCompare(const CInt64 *lhs, const CInt64 *rhs); +extern unsigned char CInt64_Less(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_LessU(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_Greater(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_GreaterU(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_LessEqual(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_LessEqualU(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_GreaterEqual(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_GreaterEqualU(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_Equal(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_NotEqual(CInt64 lhs, CInt64 rhs); +extern unsigned char CInt64_IsInRange(CInt64 value, short len); +extern unsigned char CInt64_IsInURange(CInt64 value, short len); +extern CInt64 CInt64_And(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Xor(CInt64 lhs, CInt64 rhs); +extern CInt64 CInt64_Or(CInt64 lhs, CInt64 rhs); +extern void CInt64_ConvertInt32(CInt64 *i); +extern void CInt64_ConvertUInt32(CInt64 *i); +extern void CInt64_ConvertInt16(CInt64 *i); +extern void CInt64_ConvertUInt16(CInt64 *i); +extern void CInt64_ConvertInt8(CInt64 *i); +extern void CInt64_ConvertUInt8(CInt64 *i); +extern void CInt64_ConvertUFromLongDouble(CInt64 *pResult, double value); +extern void CInt64_ConvertFromLongDouble(CInt64 *pResult, double value); +extern double CInt64_ConvertUToLongDouble(const CInt64 *value); +extern double CInt64_ConvertToLongDouble(const CInt64 *value); +extern char *CInt64_ScanOctString(CInt64 *pResult, char *str, unsigned char *pFail); +extern char *CInt64_ScanDecString(CInt64 *pResult, char *str, unsigned char *pFail); +extern char *CInt64_ScanHexString(CInt64 *pResult, char *str, unsigned char *pFail); +extern char *CInt64_ScanBinString(CInt64 *pResult, char *str, unsigned char *pFail); +extern char *CInt64_ScanAsmNumber(CInt64 *pResult, char *str, unsigned char *pFail); +extern int CInt64_PrintDec(char *output, CInt64 value); +extern int CInt64_PrintHex(char *output, CInt64 value); +extern int CInt64_PrintBin(char *output, CInt64 value);
\ No newline at end of file diff --git a/CompilerTools.c b/CompilerTools.c new file mode 100644 index 0000000..daba8df --- /dev/null +++ b/CompilerTools.c @@ -0,0 +1,1230 @@ +#include "CompilerTools.h" + +static short lheaplockcount; +static void (*heaperror)(); +static Allocator bheap; +static Allocator oheap; +static Allocator aheap; +static Allocator lheap; +static Allocator gheap; +long hash_name_id; +StringNode **name_hash_nodes; +void (*GListErrorProc)(); + +void CompilerGetPString(short index, unsigned char *str) { + COS_GetPString(str, 10100, index); +} + +void CompilerGetCString(short index, char *str) { + COS_GetString(str, 10100, index); +} + +unsigned char *CTool_CtoPstr(char *input) { + char *work = input; + int length = 0; + int i; + + while (*work) { + ++length; + ++work; + } + + for (i = length; i > 0; i--) { + work[0] = work[-1]; + --work; + } + + input[0] = length; + return (unsigned char *) input; +} + +static void GListError() { + if (GListErrorProc) + GListErrorProc(); +} + +int InitGList(GList *list, long capacity) { + if ((list->data = COS_NewOSHandle(capacity)) == 0) + if ((list->data = COS_NewHandle(capacity)) == 0) + return -1; + list->size = 0; + list->expansion = capacity >> 1; + list->capacity = capacity; + return 0; +} + +void FreeGList(GList *list) { + if (list->data != 0) { + COS_FreeHandle(list->data); + list->data = 0; + } + list->capacity = 0; + list->size = 0; +} + +void LockGList(GList *list) { + COS_LockHandleHi(list->data); +} + +void UnlockGList(GList *list) { + COS_UnlockHandle(list->data); +} + +void ShrinkGList(GList *list) { + COS_ResizeHandle(list->data, list->capacity = list->size); +} + +void AppendGListData(GList *list, const void *data, long size) { + if ((list->size + size) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += size + list->expansion)) + GListError(); + } + + memcpy(*list->data + list->size, data, size); + list->size += size; +} + +void AppendGListNoData(GList *list, long size) { + if ((list->size + size) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += size + list->expansion)) + GListError(); + } + + list->size += size; +} + +void AppendGListByte(GList *list, char v) { + if ((list->size + 1) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += 1 + list->expansion)) + GListError(); + } + + (*list->data)[list->size++] = v; +} + +void AppendGListWord(GList *list, short v) { + char *p; + + if ((list->size + 2) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += 2 + list->expansion)) + GListError(); + } + + p = *list->data + list->size; + list->size += 2; + *(p++) = ((unsigned char *) &v)[0]; + *(p++) = ((unsigned char *) &v)[1]; +} + +void AppendGListTargetEndianWord(GList *list, short v) { + char *p; + + if ((list->size + 2) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += 2 + list->expansion)) + GListError(); + } + + p = *list->data + list->size; + list->size += 2; + *(p++) = ((unsigned char *) &v)[0]; + *(p++) = ((unsigned char *) &v)[1]; +} + +void AppendGListLong(GList *list, long v) { + char *p; + + if ((list->size + 4) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += 4 + list->expansion)) + GListError(); + } + + p = *list->data + list->size; + list->size += 4; + *(p++) = ((unsigned char *) &v)[0]; + *(p++) = ((unsigned char *) &v)[1]; + *(p++) = ((unsigned char *) &v)[2]; + *(p++) = ((unsigned char *) &v)[3]; +} + +void AppendGListTargetEndianLong(GList *list, long v) { + char *p; + + if ((list->size + 4) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += 4 + list->expansion)) + GListError(); + } + + p = *list->data + list->size; + list->size += 4; + *(p++) = ((unsigned char *) &v)[0]; + *(p++) = ((unsigned char *) &v)[1]; + *(p++) = ((unsigned char *) &v)[2]; + *(p++) = ((unsigned char *) &v)[3]; +} + +void AppendGListID(GList *list, const char *str) { + unsigned long size = strlen(str) + 1; + if ((list->size + size) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += size + list->expansion)) + GListError(); + } + + memcpy(*list->data + list->size, str, size); + list->size += size; +} + +void AppendGListName(GList *list, const char *str) { + unsigned long size = strlen(str); + if ((list->size + size) > list->capacity) { + if (!COS_ResizeHandle(list->data, list->capacity += size + list->expansion)) + GListError(); + } + + memcpy(*list->data + list->size, str, size); + list->size += size; +} + +void RemoveGListData(GList *list, long size) { + list->size -= size; + if (list->capacity > (list->size + list->expansion * 2)) + COS_ResizeHandle(list->data, list->capacity = list->size + list->expansion); +} + +char GetGListByte(GList *list) { + unsigned char *p; + + p = (unsigned char *) (*list->data + list->size); + list->size++; + return p[0]; +} + +short GetGListWord(GList *list) { + unsigned char *p; + union { unsigned char bytes[2]; short s; } data; + + p = (unsigned char *) (*list->data + list->size); + list->size += 2; + data.bytes[0] = p[0]; + data.bytes[1] = p[1]; + return data.s; +} + +long GetGListLong(GList *list) { + unsigned char *p; + union { unsigned char bytes[4]; long l; } data; + + p = (unsigned char *) (*list->data + list->size); + list->size += 4; + data.bytes[0] = p[0]; + data.bytes[1] = p[1]; + data.bytes[2] = p[2]; + data.bytes[3] = p[3]; + return data.l; +} + +short GetGListID(GList *list, char *buf) { + short len; + char *p; + + len = 1; + p = *list->data + list->size; + while (*p) { + *(buf++) = *(p++); + len++; + } + + *buf = *p; + list->size += len; + return len; +} + +void GetGListData(GList *list, char *buf, long size) { + memcpy(buf, *list->data + list->size, size); + list->size += size; +} + +static long hashpjw(const char *str) { + unsigned long work = 0; + unsigned long tmp; + + while (*str) { + work = (work << 4) + *str; + tmp = work & 0xF0000000; + if (tmp) { + work ^= (tmp >> 24); + work ^= tmp; + } + str++; + } + + return work % 0xFFFFFD; +} + +static short PHash(const unsigned char *str) { + short result; + short counter; + unsigned char work; + const unsigned char *p; + + result = str[0]; + result &= 0xFF; + p = &str[1]; + if (str[0]) { + counter = result; + work = 0; + while (counter > 0) { + work = (work >> 3) | (work << 5); + work += *p; + --counter; + ++p; + } + + result = (result << 8) | work; + } + + return result & 0x7FF; +} + +short CHash(const char *str) { + /* not matching :( */ + short result; // orig r4 + unsigned char work; // orig r5 + short counter; // orig r3 + + // i am: r4 = result, r5 = counter, r3 = work + + if (result = strlen(str) & 0xFF) { + counter = result; + work = 0; + while (counter > 0) { + work = (work >> 3) | (work << 5); + work = work + *(str++); + counter--; + } + result = (result << 8) | work; + } + + return result & 0x7FF; +} + +StringNode *GetHashNameNode(const char *str) { + StringNode *node; + short hash; + + hash = CHash(str); + node = name_hash_nodes[hash]; + if (node == 0) { + node = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + name_hash_nodes[hash] = node; + node->next = 0; + node->index = hash_name_id++; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + for (;;) { + if (strcmp(str, node->data) == 0) { + if (node->index < 0) + node->index = hash_name_id++; + return node; + } + + if (node->next == 0) { + node->next = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + node = node->next; + node->next = 0; + node->index = hash_name_id++; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + node = node->next; + } + } + } +} + +StringNode *GetHashNameNodeHash(const char *str, short hash) { + StringNode *node; + + node = name_hash_nodes[hash]; + if (node == 0) { + node = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + name_hash_nodes[hash] = node; + node->next = 0; + node->index = hash_name_id++; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + for (;;) { + if (strcmp(str, node->data) == 0) + return node; + + if (node->next == 0) { + node->next = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + node = node->next; + node->next = 0; + node->index = hash_name_id++; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + node = node->next; + } + } + } +} + +StringNode *GetHashNameNodeHash2(const char *str, short hash) { + StringNode *node; + + node = name_hash_nodes[hash]; + if (node == 0) { + node = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + name_hash_nodes[hash] = node; + node->next = 0; + node->index = -1; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + for (;;) { + if (strcmp(str, node->data) == 0) + return node; + + if (node->next == 0) { + node->next = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + node = node->next; + node->next = 0; + node->index = -1; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + node = node->next; + } + } + } +} + +StringNode *GetHashNameNodeExport(const char *str) { + // not matching + StringNode *node; + short hash; + + hash = CHash(str); + if ((node = name_hash_nodes[hash]) == 0) { + node = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + name_hash_nodes[hash] = node; + node->next = 0; + node->index = -1; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + for (;;) { + if (strcmp(str, node->data) == 0) + return node; + + if (node->next == 0) { + node->next = (StringNode *) galloc(strlen(str) + sizeof(StringNode)); + node = node->next; + node->next = 0; + node->index = -1; + node->hash = hash; + strcpy(node->data, str); + return node; + } else { + node = node->next; + } + } + } +} + +long GetHashNameNodeExportID(StringNode *node) { + if (node->index < 0) + node->index = hash_name_id++; + return node->index; +} + +StringNode *GetHashNameNodeByID(long id) { + StringNode *node; + short i; + + for (i = 0; i < 2048; i++) { + for (node = name_hash_nodes[i]; node; node = node->next) { + if (id == node->index) + return node; + } + } + + return 0; +} + +void NameHashExportReset() { + short i; + StringNode *node; + + for (i = 0; i < 0x800; i++) { + node = name_hash_nodes[i]; + while (node) { + node->index = -1; + node = node->next; + } + } + + hash_name_id = 1; +} + +void NameHashWriteNameTable(GList *list) { + StringNode *node; + StringNode **nodes; + short grp; + int i; + + nodes = (StringNode **) galloc(sizeof(StringNode *) * hash_name_id); + + for (grp = 0; grp < 0x800; grp++) { + node = name_hash_nodes[grp]; + while (node) { + if (node->index > 0) + nodes[node->index] = node; + node = node->next; + } + } + + for (i = 1; i < hash_name_id; i++) { + node = nodes[i]; + AppendGListWord(list, node->hash); + AppendGListID(list, node->data); + } + + if (list->size & 1) + AppendGListByte(list, 0); +} + +void NameHashWriteTargetEndianNameTable(GList *list) { + StringNode *node; + StringNode **nodes; + short grp; + int i; + + nodes = (StringNode **) galloc(sizeof(StringNode *) * hash_name_id); + memclrw(nodes, sizeof(StringNode *) * hash_name_id); + + for (grp = 0; grp < 0x800; grp++) { + node = name_hash_nodes[grp]; + while (node) { + if (node->index > 0) + nodes[node->index] = node; + node = node->next; + } + } + + for (i = 1; i < hash_name_id; i++) { + node = nodes[i]; + if (node == 0) { + AppendGListTargetEndianWord(list, 0); + AppendGListID(list, ""); + } else { + AppendGListTargetEndianWord(list, node->hash); + AppendGListID(list, node->data); + } + } + + if (list->size & 1) + AppendGListByte(list, 0); +} + +void InitNameHash() { + name_hash_nodes = (StringNode **) galloc(0x800 * sizeof(StringNode *)); + memclrw(name_hash_nodes, 0x800 * sizeof(StringNode *)); + hash_name_id = 1; +} + +long CTool_TotalHeapSize() { + long total = 0; + AllocatorBlock *block; + + for (block = gheap.blockList; block; block = block->nextBlock) { + total += block->size; + } + for (block = lheap.blockList; block; block = block->nextBlock) { + total += block->size; + } + for (block = aheap.blockList; block; block = block->nextBlock) { + total += block->size; + } + for (block = oheap.blockList; block; block = block->nextBlock) { + total += block->size; + } + for (block = bheap.blockList; block; block = block->nextBlock) { + total += block->size; + } + + return total; +} + +static void getheapinfo(HeapInfo *result, Allocator *heap) { + AllocatorBlock *block; + + result->_4 = heap->paddingSize; + for (block = heap->blockList; block; block = block->nextBlock) { + result->_8 += block->size - sizeof(AllocatorBlock); + result->xx_C += block->remaining; + result->_0++; + if (block->remaining > result->_18) + result->_18 = block->remaining; + } + + result->_10 = result->_8 / result->_0; + result->_14 = result->xx_C / result->_0; +} + +void CTool_GetHeapInfo(HeapInfo *result, unsigned char heapID) { + memclrw(result, sizeof(HeapInfo)); + + switch (heapID) { + case 0: + getheapinfo(result, &gheap); + break; + case 1: + getheapinfo(result, &lheap); + break; + case 2: + getheapinfo(result, &aheap); + break; + case 3: + getheapinfo(result, &oheap); + break; + case 4: + getheapinfo(result, &bheap); + break; + case 5: + getheapinfo(result, &gheap); + getheapinfo(result, &lheap); + getheapinfo(result, &aheap); + getheapinfo(result, &oheap); + getheapinfo(result, &bheap); + break; + } +} + +static void MoreHeapSpace(Allocator *alloc, long size) { + Handle blockHandle; + long blockSize; + AllocatorBlock *block; + + block = alloc->blockList; + if (block) { + alloc->lastBlockUsed->remaining = alloc->remaining; + while (block) { + if (block->remaining >= size) + goto gotBlock; + block = block->nextBlock; + } + } + + /* create new block */ + blockSize = size + alloc->paddingSize; + if (systemHandles) { + blockHandle = COS_NewOSHandle(blockSize << 1); + if (blockHandle != 0) + goto createdTempDoubleBlock; + blockHandle = COS_NewOSHandle(blockSize); + if (blockHandle != 0) + goto createdBlock; + } + blockHandle = COS_NewHandle(blockSize); + if (blockHandle != 0) + goto createdBlock; + + if (heaperror) + heaperror(); + return; + + createdTempDoubleBlock: + blockSize <<= 1; + goto createdBlock; + createdBlock: + COS_LockHandleHi(blockHandle); + block = (AllocatorBlock *) *blockHandle; + block->nextBlock = alloc->blockList; + alloc->blockList = block; + block->handle = blockHandle; + block->size = blockSize; + block->remaining = blockSize - sizeof(AllocatorBlock); + gotBlock: + alloc->lastBlockUsed = block; + alloc->remaining = block->remaining; + alloc->ptrToFreeArea = ((char *) block) + block->size - block->remaining; +} + +int initheaps(heaperror_t failureCallback) { + heaperror = 0; + lheaplockcount = 0; + + memclrw(&gheap, sizeof(Allocator)); + memclrw(&lheap, sizeof(Allocator)); + memclrw(&aheap, sizeof(Allocator)); + memclrw(&oheap, sizeof(Allocator)); + memclrw(&bheap, sizeof(Allocator)); + + gheap.paddingSize = 0x38000; + lheap.paddingSize = 0x10000; + aheap.paddingSize = 0x4000; + oheap.paddingSize = 0x40000; + bheap.paddingSize = 0x4000; + + MoreHeapSpace(&gheap, 0); + MoreHeapSpace(&lheap, 0); + MoreHeapSpace(&aheap, 0); + MoreHeapSpace(&oheap, 0); + MoreHeapSpace(&bheap, 0); + + gheap.paddingSize = 0x8000; + lheap.paddingSize = 0x8000; + + heaperror = failureCallback; + + if (!gheap.lastBlockUsed || !lheap.lastBlockUsed || !aheap.lastBlockUsed || !oheap.lastBlockUsed || !bheap.lastBlockUsed) + return -1; + else + return 0; +} + +int initgheap(heaperror_t failureCallback) { + heaperror = 0; + lheaplockcount = 0; + + memclrw(&gheap, sizeof(Allocator)); + memclrw(&lheap, sizeof(Allocator)); + memclrw(&aheap, sizeof(Allocator)); + memclrw(&oheap, sizeof(Allocator)); + memclrw(&bheap, sizeof(Allocator)); + + gheap.paddingSize = 0x38000; + MoreHeapSpace(&gheap, 0); + gheap.paddingSize = 0x8000; + + heaperror = failureCallback; + + if (!gheap.lastBlockUsed) + return -1; + else + return 0; +} + +heaperror_t getheaperror() { + return heaperror; +} + +void setheaperror(heaperror_t failureCallback) { + heaperror = failureCallback; +} + +static void relheap(Allocator *alloc) { + AllocatorBlock *block; + Handle handle; + + block = alloc->blockList; + while (block) { + handle = block->handle; + block = block->nextBlock; + COS_FreeHandle(handle); + } + + memclrw(alloc, sizeof(Allocator)); +} + +void releaseheaps() { + relheap(&gheap); + relheap(&lheap); + relheap(&aheap); + relheap(&oheap); + relheap(&bheap); +} + +void releasegheap() { + relheap(&gheap); +} + +void releaseoheap() { + relheap(&gheap); + oheap.paddingSize = 0x40000; + MoreHeapSpace(&oheap, 0); +} + +char *galloc(long size) { + long alignedSize; + char *ptr; + + alignedSize = (size & ~7) + 8; + if (gheap.remaining < alignedSize) + MoreHeapSpace(&gheap, alignedSize); + + gheap.remaining -= alignedSize; + ptr = (char *) gheap.ptrToFreeArea; + gheap.ptrToFreeArea = ptr + alignedSize; + return ptr; +} + +char *lalloc(long size) { + long alignedSize; + char *ptr; + + alignedSize = (size & ~7) + 8; + if (lheap.remaining < alignedSize) + MoreHeapSpace(&lheap, alignedSize); + + lheap.remaining -= alignedSize; + ptr = (char *) lheap.ptrToFreeArea; + lheap.ptrToFreeArea = ptr + alignedSize; + return ptr; +} + +char *aalloc(long size) { + long alignedSize; + char *ptr; + + alignedSize = (size & ~7) + 8; + if (aheap.remaining < alignedSize) + MoreHeapSpace(&aheap, alignedSize); + + aheap.remaining -= alignedSize; + ptr = (char *) aheap.ptrToFreeArea; + aheap.ptrToFreeArea = ptr + alignedSize; + return ptr; +} + +char *oalloc(long size) { + long alignedSize; + char *ptr; + + alignedSize = (size & ~7) + 8; + if (oheap.remaining < alignedSize) + MoreHeapSpace(&oheap, alignedSize); + + oheap.remaining -= alignedSize; + ptr = (char *) oheap.ptrToFreeArea; + oheap.ptrToFreeArea = ptr + alignedSize; + return ptr; +} + +char *balloc(long size) { + long alignedSize; + char *ptr; + + alignedSize = (size & ~7) + 8; + if (bheap.remaining < alignedSize) + MoreHeapSpace(&bheap, alignedSize); + + bheap.remaining -= alignedSize; + ptr = (char *) bheap.ptrToFreeArea; + bheap.ptrToFreeArea = ptr + alignedSize; + return ptr; +} + +void locklheap() { + lheaplockcount++; +} + +void unlocklheap() { + if (lheaplockcount > 0) + --lheaplockcount; +} + +void freelheap() { + AllocatorBlock *block; + + if (lheaplockcount == 0) { + block = lheap.blockList; + lheap.lastBlockUsed = block; + lheap.ptrToFreeArea = ((char *) block) + sizeof(AllocatorBlock); + lheap.remaining = block->size - sizeof(AllocatorBlock); + + while (block) { + block->remaining = block->size - sizeof(AllocatorBlock); + block = block->nextBlock; + } + } +} + +void freeaheap() { + AllocatorBlock *block; + + block = aheap.blockList; + aheap.lastBlockUsed = block; + aheap.ptrToFreeArea = ((char *) block) + sizeof(AllocatorBlock); + aheap.remaining = block->size - sizeof(AllocatorBlock); + + while (block) { + block->remaining = block->size - sizeof(AllocatorBlock); + block = block->nextBlock; + } +} + +void freeoheap() { + AllocatorBlock *block; + + block = oheap.blockList; + oheap.lastBlockUsed = block; + oheap.ptrToFreeArea = ((char *) block) + sizeof(AllocatorBlock); + oheap.remaining = block->size - sizeof(AllocatorBlock); + + while (block) { + block->remaining = block->size - sizeof(AllocatorBlock); + block = block->nextBlock; + } +} + +void freebheap() { + AllocatorBlock *block; + + block = bheap.blockList; + bheap.lastBlockUsed = block; + bheap.ptrToFreeArea = ((char *) block) + sizeof(AllocatorBlock); + bheap.remaining = block->size - sizeof(AllocatorBlock); + + while (block) { + block->remaining = block->size - sizeof(AllocatorBlock); + block = block->nextBlock; + } +} + +char *ScanHex(char *str, long *output, Boolean *overflow) { + long work; + int ch; + + work = 0; + *overflow = 0; + + for (;;) { + ch = *str; + if (ch >= '0' && ch <= '9') { + ch = ch - '0'; + } else if (ch >= 'A' && ch <= 'F') { + ch = ch - 'A' + 10; + } else if (ch >= 'a' && ch <= 'f') { + ch = ch - 'a' + 10; + } else { + break; + } + + if (work & 0xF0000000) + *overflow = 1; + work = (work << 4) | (short) ch; + ++str; + } + + *output = work; + return str; +} + +char *ScanOct(char *str, long *output, Boolean *overflow) { + short digit; + long work; + + work = 0; + *overflow = 0; + + for (;;) { + digit = *str - '0'; + if (digit >= 0 && digit <= 9) { + if (digit >= 8) { + *overflow = 1; + ++str; + break; + } + } else { + break; + } + + if (work & 0xE0000000) + *overflow = 1; + work = (work << 3) | digit; + ++str; + } + + *output = work; + return str; +} + +char *ScanDec(char *str, long *output, Boolean *overflow) { + short digit; + unsigned long work; + + work = 0; + *overflow = 0; + + for (;;) { + digit = *str - '0'; + if (digit >= 0 && digit <= 9) { + if (work >= 0x19999999 && (work > 0x19999999 || digit > 5)) + *overflow = 1; + } else { + break; + } + + work = (work << 3) + (work << 1) + digit; + ++str; + } + + *output = work; + return str; +} + +static char *UnmangleClassname(char *work, char **pNameStart, short *pNameLength, char **a4, short *a5, Boolean a6) { + char ch; + short len; + char *p2; + short len2; + short i; + short wtf; + + *pNameLength = 0; + if (*(work++) != '_') + return work; + if (*(work++) != '_') { + return work; + } else { + len = 0; + while (work[0] >= '0' && work[0] <= '9') { + len = (len * 10) + work[0] - '0'; + ++work; + } + + if (len > 0) { + *pNameStart = work; + *pNameLength = len; + + if (a6) { + p2 = *a4; + len2 = *a5; + i = 0; + wtf = len; + while (i < wtf && len2 < 255) { + *(p2++) = work[i]; + ++i; + ++len2; + } + if (len2 < 255) { + *(p2++) = ':'; + len2++; + } + if (len2 < 255) { + *(p2++) = ':'; + len2++; + } + *a4 = p2; + *a5 = len2; + } + } + + return work + len; + } +} + +static char *UnmangleAppend(char *src, char srcLen, char **pOutput, short *pOutputLen) { + char *output; + short i; + short outputLen; + + output = *pOutput; + outputLen = *pOutputLen; + + for (i = 0; i < srcLen && outputLen < 255; i++, outputLen++) { + *(output++) = src[i]; + } + + *pOutput = output; + *pOutputLen = outputLen; +} + +void OldUnmangle(char *input, char *output, Boolean flag) { + short var26; + char *nameStart; + short nameLength; + char *saved; + int i; + + if (*input == '.') + ++input; + + var26 = 0; + saved = input; + if (input[0] == '_' && input[1] == '_') { + if (input[2] == 'c' && input[3] == 't') { + saved = UnmangleClassname(&input[4], &nameStart, &nameLength, &output, &var26, flag); + if (nameLength == 0) + goto invalid; + UnmangleAppend(nameStart, nameLength, &output, &var26); + } else if (input[2] == 'd' && input[3] == 't') { + saved = UnmangleClassname(&input[4], &nameStart, &nameLength, &output, &var26, flag); + if (nameLength == 0) + goto invalid; + if (var26 <= 255) { + *(output++) = '~'; + var26++; + } + UnmangleAppend(nameStart, nameLength, &output, &var26); + } else if (input[2] == 'n' && input[3] == 'w') { + saved = UnmangleClassname(&input[4], &nameStart, &nameLength, &output, &var26, flag); + UnmangleAppend("operator new", 15, &output, &var26); + } else if (input[2] == 'd' && input[3] == 'l') { + saved = UnmangleClassname(&input[4], &nameStart, &nameLength, &output, &var26, flag); + UnmangleAppend("operator delete", 15, &output, &var26); + } else { + invalid: + strncpy(output, input, 256); + return; + } + } else { + i = 0; + while (*saved) { + ++saved; + ++i; + if (saved[0] == '_' && saved[1] == '_') { + saved = UnmangleClassname(saved, &nameStart, &nameLength, &output, &var26, flag); + break; + } + } + UnmangleAppend(input, i, &output, &var26); + } + + if (flag && saved[0] == 'F') { + if (saved[1] == 'v') { + UnmangleAppend("(void)", 6, &output, &var26); + } else { + UnmangleAppend("(...)", 5, &output, &var26); + } + } + + *output = 0; +} + +short hash(char *str) { + char hash = 0; + + while (*str) { + hash = hash << 1; + hash ^= *(str++); + } + + return hash & 0x7F; +} + +void memclr(void *buffer, long size) { + memset(buffer, 0, size); +} + +void memclrw(void *buffer, long size) { + memset(buffer, 0, size); +} + +void CToLowercase(char *src, char *dst) { + char ch; + + do { + ch = tolower(*(src++)); + *(dst++) = ch; + } while (ch); +} + +int getbit(long v) { + switch (v) { + case 0: return -1; + case 1: return 0; + case 2: return 1; + case 4: return 2; + case 8: return 3; + case 0x10: return 4; + case 0x20: return 5; + case 0x40: return 6; + case 0x80: return 7; + case 0x100: return 8; + case 0x200: return 9; + case 0x400: return 10; + case 0x800: return 11; + case 0x1000: return 12; + case 0x2000: return 13; + case 0x4000: return 14; + case 0x8000: return 15; + case 0x10000: return 16; + case 0x20000: return 17; + case 0x40000: return 18; + case 0x80000: return 19; + case 0x100000: return 20; + case 0x200000: return 21; + case 0x400000: return 22; + case 0x800000: return 23; + case 0x1000000: return 24; + case 0x2000000: return 25; + case 0x4000000: return 26; + case 0x8000000: return 27; + case 0x10000000: return 28; + case 0x20000000: return 29; + case 0x40000000: return 30; + case 0x80000000: return 31; + default: return -2; + } +} + +void CTool_EndianConvertWord64(WtfWord64 value, unsigned long long *p) { + union { unsigned char bytes[8]; WtfWord64 w; } data; + data.w.a = value.a; + data.w.b = value.b; + memcpy(p, data.bytes, 8); +} + +unsigned short CTool_EndianConvertInPlaceWord16Ptr(unsigned short *p) { + unsigned short v; + v = *p; + // this probably has a conversion on non-ppc + *p = v; + return v; +} + +unsigned long CTool_EndianConvertInPlaceWord32Ptr(unsigned long *p) { + unsigned long v; + v = *p; + // this probably has a conversion on non-ppc + *p = v; + return v; +} + +void CTool_EndianConvertVector128() { + // not correct but idc +} + +StringNode *CTool_GetPathName(const FSSpec *spec, long *mdDat) { + char buffer[256]; + COS_FileGetPathName(buffer, spec, mdDat); + return GetHashNameNodeExport(buffer); +} + +Boolean strcat_safe(char *dst, const char *src, int maxLen) { + int len; + char ch; + + len = strlen(dst); + dst += len; + maxLen -= len; + if (maxLen < 0) + return 1; + + while (maxLen != 0) { + ch = *(dst++) = *(src++); + if (ch == 0) + break; + --maxLen; + } + + if (maxLen == 0 && dst[-1]) { + dst[-1] = 0; + return 1; + } else { + return 0; + } +} diff --git a/CompilerTools.h b/CompilerTools.h new file mode 100644 index 0000000..5c6607e --- /dev/null +++ b/CompilerTools.h @@ -0,0 +1,134 @@ +#include "mwcc_decomp.h" +#pragma once + +extern void CompilerGetPString(short index, unsigned char *str); +extern void CompilerGetCString(short index, char *str); +extern unsigned char *CTool_CtoPstr(char *input); + +typedef struct _AllocatorBlock { + struct _AllocatorBlock *nextBlock; + char **handle; + long size; + long remaining; +} AllocatorBlock; + +typedef struct _Allocator { + AllocatorBlock *blockList; + long paddingSize; + AllocatorBlock *lastBlockUsed; + void *ptrToFreeArea; + long remaining; +} Allocator; + +typedef struct _HeapInfo { + long _0; + long _4; + long _8; + long xx_C; + long _10; + long _14; + long _18; +} HeapInfo; + +typedef struct _StringNode { + struct _StringNode *next; + long index; + short hash; + char data[1]; +} StringNode; + +typedef struct _GList { + char **data; + long size; + long capacity; + long expansion; +} GList; + +extern long hash_name_id; +extern StringNode **name_hash_nodes; +extern void (*GListErrorProc)(); + +// extern void GListError(); +extern int InitGList(GList *list, long capacity); +extern void FreeGList(GList *list); +extern void LockGList(GList *list); +extern void UnlockGList(GList *list); +extern void ShrinkGList(GList *list); +extern void AppendGListData(GList *list, const void *data, long size); +extern void AppendGListNoData(GList *list, long size); +extern void AppendGListByte(GList *list, char v); +extern void AppendGListWord(GList *list, short v); +extern void AppendGListTargetEndianWord(GList *list, short v); +extern void AppendGListLong(GList *list, long v); +extern void AppendGListTargetEndianLong(GList *list, long v); +extern void AppendGListID(GList *list, const char *str); +extern void AppendGListName(GList *list, const char *str); +extern void RemoveGListData(GList *list, long size); +extern char GetGListByte(GList *list); +extern short GetGListWord(GList *list); +extern long GetGListLong(GList *list); +extern short GetGListID(GList *list, char *buf); +extern void GetGListData(GList *list, char *buf, long size); +// extern long hashpjw(const char *str); +// extern short PHash(const unsigned char *str); +extern short CHash(const char *str); +extern StringNode *GetHashNameNode(const char *str); +extern StringNode *GetHashNameNodeHash(const char *str, short hash); +extern StringNode *GetHashNameNodeHash2(const char *str, short hash); +extern StringNode *GetHashNameNodeExport(const char *str); +extern long GetHashNameNodeExportID(StringNode *node); +extern StringNode *GetHashNameNodeByID(long id); +extern void NameHashExportReset(); +extern void NameHashWriteNameTable(GList *list); +extern void NameHashWriteTargetEndianNameTable(GList *list); +extern void InitNameHash(); + +typedef void (*heaperror_t)(); + +extern long CTool_TotalHeapSize(); +// extern void getheapinfo(HeapInfo *result, Allocator *heap); +extern void CTool_GetHeapInfo(HeapInfo *result, unsigned char heapID); +// extern void MoreHeapSpace(Allocator *alloc, long size); +extern int initheaps(heaperror_t failureCallback); +extern int initgheap(heaperror_t failureCallback); +extern heaperror_t getheaperror(); +extern void setheaperror(heaperror_t failureCallback); +// extern void relheap(Allocator *alloc); +extern void releaseheaps(); +extern void releasegheap(); +extern void releaseoheap(); +extern char *galloc(long size); +extern char *lalloc(long size); +extern char *aalloc(long size); +extern char *oalloc(long size); +extern char *balloc(long size); + +extern void locklheap(); +extern void unlocklheap(); +extern void freelheap(); +extern void freeaheap(); +extern void freeoheap(); +extern void freebheap(); + +extern char *ScanHex(char *str, long *output, Boolean *overflow); +extern char *ScanOct(char *str, long *output, Boolean *overflow); +extern char *ScanDec(char *str, long *output, Boolean *overflow); + +// extern char *UnmangleClassname(char *work, char **pNameStart, short *pNameLength, char **a4, short *a5, Boolean a6); +// extern char *UnmangleAppend(char *src, char srcLen, char **pOutput, short *pOutputLen); +extern void OldUnmangle(char *input, char *output, Boolean flag); + +extern short hash(char *str); +extern void memclr(void *buffer, long size); +extern void memclrw(void *buffer, long size); +extern void CToLowercase(char *src, char *dst); +extern int getbit(long v); +typedef struct { + unsigned long a, b; +} WtfWord64; // this has to make sense, somehow... but how? +extern void CTool_EndianConvertWord64(WtfWord64 value, unsigned long long *p); +extern unsigned short CTool_EndianConvertInPlaceWord16Ptr(unsigned short *p); +extern unsigned long CTool_EndianConvertInPlaceWord32Ptr(unsigned long *p); +extern void CTool_EndianConvertVector128(); // not correct but idc +extern StringNode *CTool_GetPathName(const FSSpec *spec, long *mdDat); +extern Boolean strcat_safe(char *dst, const char *src, int maxLen); @@ -0,0 +1,564 @@ +#include "mwcc_decomp.h" +typedef struct _Side { + short offset; + short width; + char buffer[1024]; + short bptr; + short blen; + short indent; + short vrow; + short vcol; + unsigned char atEOL; + unsigned char impInd; +} Side; + +short helpExtras; +unsigned char showedHelp; +Side left; +Side right; +Side all; +char **helptext; +static char outLine[256]; + +static void Help_Output(Side *left, Side *right); +static void Help_OutputSingle(Side *all); +static void Help_Flush(); + +static void Side_Init(Side *s, short offset, short width) { + memset(s, 0, sizeof(Side)); + s->offset = offset; + s->width = width; +} + +static void Side_Print(Side *s, const char *format, ...) { + char c; + char *text; + char buffer[1024]; + va_list args; + + va_start(args, format); + vsprintf(buffer, format, args); + va_end(args); + + text = buffer; + while (*text) { + if (s->blen < 1024) { + c = *(text++); + if (c == '~' && *text == '~') { + c = *MAINOPTCHAR; + text++; + } + + s->buffer[(s->bptr + s->blen) & 1023] = c; + s->blen++; + } else { + if (s == &left) + Help_Output(&left, &right); + else + Help_OutputSingle(&all); + } + } +} + +static void Side_NewLine(Side *s) { + Side_Print(s, "\n"); +} + +static void Side_Indent(Side *s, short how) { + if ((s->width - s->indent - how) > (parseopts.ioCols / 8)) + s->indent += how; + else if ((s->width - s->indent - 1) > (parseopts.ioCols / 10)) + s->indent++; +} + +static void Side_Outdent(Side *s, short how) { + if ((s->width - s->indent) < (parseopts.ioCols / 8)) + s->indent++; + else if (s->indent >= how) + s->indent -= how; +} + +static unsigned char isBreaker(char c) { + return (c == 10) || (c == 13) || (c == 32) || (c == 9) || (c == 8) || (c == '|'); +} + +static void Side_DumpLine(Side *s) { + short col; + short len; + short afterspace; + short eol; + short ind; + char c; + + eol = 0; + ind = 0; + col = s->offset + s->indent; + s->vcol = s->indent; + len = 0; + afterspace = s->width - s->indent; + + while (s->blen > 0 && s->vcol < s->width && !eol && !ind) { + c = s->buffer[s->bptr]; + outLine[col + len] = c; + s->vcol++; + len++; + + if (isBreaker(c)) { + afterspace = len; + eol = (c == '\n') || (c == '\r'); + eol += (c == '\r'); + ind = (c == '\b') || (c == '\t'); + ind += (c == '\b'); + } + + s->bptr = (s->bptr + 1) & 1023; + s->blen--; + } + + if (s->blen || eol || ind) { + s->blen += len - afterspace; + s->bptr = (s->bptr - (len - afterspace)) & 1023; + if (eol || ind) { + len++; + afterspace--; + } + + while (len > afterspace) { + outLine[col + --len] = ' '; + } + } + + s->vcol = 0; + s->vrow++; + s->atEOL = (eol == 1) || ind || !s->blen; + if ((s->atEOL || ind) && s->impInd) { + Side_Outdent(s, parseopts.ioCols / 40); + s->impInd = 0; + } + if (ind) { + if (ind == 1) + Side_Indent(s, parseopts.ioCols / 25); + else + Side_Outdent(s, parseopts.ioCols / 25); + } else if (!s->atEOL && s != &all && !s->impInd) { + Side_Indent(s, parseopts.ioCols / 40); + s->impInd = 1; + } +} + +static void Help_PrintLine() { + HPrintF(helptext, "%.*s\n", parseopts.ioCols - 1, outLine); +} + +static void Help_Output(Side *left, Side *right) { + while (left->blen || right->blen) { + memset(outLine, ' ', parseopts.ioCols); + outLine[left->offset + left->width + 1] = '#'; + if (left->atEOL && right->atEOL) + left->atEOL = right->atEOL = 0; + if (!left->atEOL) + Side_DumpLine(left); + if (!right->atEOL) + Side_DumpLine(right); + Help_PrintLine(); + } +} + +static void Help_OutputSingle(Side *all) { + while (all->blen) { + memset(outLine, ' ', parseopts.ioCols); + if (all->atEOL) + all->atEOL = 0; + if (!all->atEOL) + Side_DumpLine(all); + Help_PrintLine(); + } +} + +static void Help_Flush() { + Help_Output(&left, &right); +} + +static void Help_NewLine() { + Side_NewLine(&left); + Side_NewLine(&right); +} + +int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const char *keyword) { + char pfbuf[512]; + char slflags; + int listFlags; + Boolean allNoArgs; + PARAM_T *lastparam; + Boolean print; + Boolean printMe; + + if (!opt->names[0] && !(lst->flags & LISTFLAGS_4)) + return 0; + + if (keyword && keyword[0] && !strstr(opt->names, keyword) && (!opt->help || !strstr(opt->help, keyword))) + return 0; + + if ((opt->avail & OTF_SECRET) && !(parseopts.helpFlags & HELPFLAGS_SECRET)) + return 0; + + if ((opt->avail & OTF_OBSOLETE) && !(parseopts.helpFlags & HELPFLAGS_OBSOLETE)) + return 0; + + if ((opt->avail & OTF_DEPRECATED) && !(parseopts.helpFlags & HELPFLAGS_DEPRECATED)) + return 0; + + if ((opt->avail & OTF_IGNORED) && !(parseopts.helpFlags & HELPFLAGS_IGNORED)) + return 0; + + if ((opt->avail & OTF_MEANINGLESS) && !(parseopts.helpFlags & HELPFLAGS_MEANINGLESS)) + return 0; + + if (!(parseopts.helpFlags & HELPFLAGS_NORMAL) && !(opt->avail & OTF_ALL_HIDDEN_BY_DEFAULT)) + return 0; + + if (opt->help || (opt->avail & OTF8000)) { + allNoArgs = 1; + lastparam = 0; + if (parseopts.helpFlags & HELPFLAGS_SPACES) + Help_NewLine(); + if ((opt->avail & OTF_GLOBAL) && !subprint) + Side_Print(&right, "global; "); + if (compat != 1 && (opt->avail & OTF_CASED)) + Side_Print(&right, "cased; "); + + slflags = (subprint == 0) ? SLFLAGS_1 : SLFLAGS_2; + switch (opt->avail & OTF_SLFLAGS_MASK) { + case OTF_SLFLAGS_8: + slflags = slflags | SLFLAGS_8; + break; + case OTF_SLFLAGS_10: + slflags = slflags | SLFLAGS_10; + break; + case OTF_SLFLAGS_20: + slflags = slflags | SLFLAGS_20; + break; + } + if (opt->avail & OTF2) + slflags = slflags | SLFLAGS_40; + + Utils_SpellList(opt->names[0] ? opt->names : "...", pfbuf, slflags); + Side_Print(&left, pfbuf); + + if (opt->avail & OTF_OBSOLETE) + Side_Print(&right, "obsolete;\r"); + if (opt->avail & OTF_COMPATIBILITY) + Side_Print(&right, "compatibility;\r"); + if (opt->avail & OTF_IGNORED) + Side_Print(&right, "ignored;\r"); + + listFlags = ((lst->flags & LISTFLAGS_COMPILER) ? OTF_TOOL_COMPILER : 0) | ((lst->flags & LISTFLAGS_LINKER) ? OTF_TOOL_LINKER : 0) | ((lst->flags & LISTFLAGS_DISASSEMBLER) ? OTF_TOOL_DISASSEMBLER : 0); + if (!Option_ForThisTool(opt) || Option_AlsoPassedFromThisTool(opt) || listFlags != Option_ThisTool()) { + print = 0; + printMe = 1; + if ((opt->avail & OTF_TOOL_MASK) != (unsigned int) listFlags) + print = 1; + if (Option_ForThisTool(opt) && Option_AlsoPassedFromThisTool(opt)) + printMe = 0; + + if (print) { + char opttool[64] = ""; // stack 0x44 + if ((opt->avail & OTF_TOOL_MASK) == (unsigned int) OTF_TOOL_MASK) { + strcat(opttool, "all tools"); + } else { + if (Option_ForTool(opt, OTF_TOOL_COMPILER) && ((Option_ThisTool() != (unsigned int) OTF_TOOL_COMPILER) || printMe)) { + strcat(opttool, "this tool"); + } + if (Option_ForTool(opt, OTF_TOOL_LINKER) && ((Option_ThisTool() != (unsigned int) OTF_TOOL_LINKER) || printMe)) { + if (opttool[0]) + strcat(opttool, ", "); + strcat(opttool, "linker"); + } + if (Option_ForTool(opt, OTF_TOOL_DISASSEMBLER) && ((Option_ThisTool() != (unsigned int) OTF_TOOL_DISASSEMBLER) || printMe)) { + if (opttool[0]) + strcat(opttool, ", "); + strcat(opttool, "disassembler"); + } + if (!Option_ForTool(opt, OTF_TOOL_MASK)) + strcat(opttool, "another tool"); + } + + if (printMe || !Option_ForThisTool(opt)) { + Side_Print(&right, "for %s;\r", opttool); + } else if (parseopts.passingArgs) { + Side_Print(&right, "passed to %s;\r", opttool); + } + } + } + + if (opt->avail & OTF_WARNING) + Side_Print(&right, "warning:\r"); + + if (opt->avail & OTF_DEPRECATED) + Side_Print(&right, "deprecated;\rinstead use "); + else if (opt->avail & OTF_SUBSTITUTED) + Side_Print(&right, "substituted with "); + + if (opt->help) + Side_Print(&right, "%s", opt->help); + + if (opt->param && !(opt->avail & OTF_IGNORED)) { + PARAM_T *scan = opt->param; + PARAM_T *firstparam = 0; + const char *desc; + const char *help; + const char *defaul; + while (scan) { + if ((scan->flags & PARAMFLAGS_3) != PARAMFLAGS_1) { + if (!firstparam) + firstparam = scan; + + allNoArgs = 0; + Param_DescHelp(scan, &desc, &help, &defaul); + if (desc) { + if (((scan->flags & PARAMFLAGS_3) == PARAMFLAGS_2) && scan->which != PARAMWHICH_Setting && scan->which != PARAMWHICH_IfArg) { + if (SEPOPTSTR[0] == ' ') { + Side_Print(&left, (scan != firstparam) ? "[," : subprint ? "[=" : " ["); + } else { + Side_Print(&left, "[%s", (scan != firstparam) ? "," : subprint ? "=" : SEPOPTSTR); + } + } else { + Side_Print(&left, (scan != firstparam) ? "," : subprint ? "=" : ((opt->avail & OTF2) && !strchr(opt->names, '|')) ? "" : SEPOPTSTR); + } + Side_Print(&left, "%s", desc); + if (((scan->flags & PARAMFLAGS_3) == PARAMFLAGS_2) && scan->which != PARAMWHICH_Setting && scan->which != PARAMWHICH_IfArg) { + Side_Print(&left, "]"); + } + if (help) { + if ((scan->flags & PARAMFLAGS_3) != PARAMFLAGS_2) + Side_Print(&right, "; for '%s', %s", desc, help); + else + Side_Print(&right, "; if parameter specified, %s", help); + } + if (defaul && !(opt->avail & OTF2000)) { + if (firstparam == scan) + Side_Print(&right, "; default is %s", defaul); + else + Side_Print(&right, ",%s", defaul); + } + } + } + lastparam = scan; + scan = scan->next; + } + + if (allNoArgs && !(opt->avail & OTF2000)) { + PARAM_T *scan = opt->param; + Boolean isdefault = scan ? 1 : 0; + while (scan && isdefault) { + isdefault &= Param_Compare(scan); + scan = scan->next; + } + + if (isdefault) + Side_Print(&right, "; default"); + } + } + + if (opt->avail & OTF_MEANINGLESS) + Side_Print(&right, "; meaningless for this target"); + + if ((opt->avail & OTF8000) && opt->sub) { + if (!allNoArgs) { + Side_Print( + &left, + "%s", + (opt->avail & OTF10000) ? ((lastparam->flags & PARAMFLAGS_8) ? "[=" : "[,") : ((lastparam->flags & PARAMFLAGS_8) ? "," : "=") + ); + } else if (!(opt->avail & OTF2)) { + if (opt->avail & OTF10000) { + if (SEPOPTSTR[0] == ' ') + Side_Print(&left, subprint ? "[=" : " ["); + else + Side_Print(&left, "[%s", subprint ? "=" : SEPOPTSTR); + } else { + Side_Print(&left, "%c", subprint ? '=' : SEPOPTSTR[0]); + } + } else { + if (opt->avail & OTF10000) { + Side_Print(&left, subprint ? "[" : (SEPOPTSTR[0] == ' ') ? " [" : "["); + } + } + + Side_Print( + &left, + "%s%s%s", + opt->sub->help ? opt->sub->help : "keyword", + (opt->sub->flags & PARAMFLAGS_1) ? "" : "[,...]", + (opt->avail & OTF10000) ? "]" : "" + ); + + Side_Print(&left, "\t"); + Side_Print(&right, "\t"); + Help_Options(opt->sub, 1, ""); + Side_Print(&left, "\b"); + Side_Print(&right, "\b"); + } else { + Side_Print(&left, "\n"); + Side_Print(&right, "\n"); + } + } + + Help_Flush(); + return 1; +} + +inline int IsCompiler() { + return (Option_ThisTool() == (unsigned int) OTF_TOOL_COMPILER) ? LISTFLAGS_COMPILER : LISTFLAGS_LINKER; +} + +void Help_Options(struct OptionList *lst, int subprint, const char *keyword) { + Option **opts; + int toolflags; + Boolean show; + + opts = lst->list; + toolflags = 0; + if (Option_ThisTool() == (unsigned int) OTF_TOOL_COMPILER) { + toolflags |= LISTFLAGS_COMPILER; + } else { + toolflags |= LISTFLAGS_LINKER; + } + + // review me maybe? + if (!subprint && (parseopts.helpFlags & HELPFLAGS_TOOL)) { + if ((parseopts.helpFlags & HELPFLAGS_TOOL_BOTH) == HELPFLAGS_TOOL_THIS && (lst->flags & LISTFLAGS_TOOL_MASK) && !(lst->flags & toolflags)) + return; + if ((parseopts.helpFlags & HELPFLAGS_TOOL_BOTH) == HELPFLAGS_TOOL_OTHER && (((lst->flags & LISTFLAGS_TOOL_MASK) == (unsigned int) toolflags) || ((lst->flags & LISTFLAGS_TOOL_MASK) == (unsigned int) LISTFLAGS_NONE))) + return; + } + + if (lst->help && !subprint && opts[0]) { + Help_Line('-'); + Side_Print(&all, "%s", lst->help); + Help_OutputSingle(&all); + Help_Line('-'); + } + + while (*opts) { + show = 0; + if (!(parseopts.helpFlags & HELPFLAGS_TOOL)) { + if (((parseopts.helpFlags & HELPFLAGS_TOOL_BOTH) == HELPFLAGS_TOOL_BOTH) && (parseopts.passingArgs ? (Option_ForTool(*opts, OTF_TOOL_LINKER) || Option_ForTool(*opts, OTF_TOOL_DISASSEMBLER)) : 1) && Option_ForThisTool(*opts)) + show = 1; + } else if ((parseopts.helpFlags & HELPFLAGS_TOOL_BOTH) == HELPFLAGS_TOOL_BOTH) { + show = 1; + } else if ((parseopts.helpFlags & HELPFLAGS_TOOL_THIS) && Option_ForThisTool(*opts)) { + show = 1; + } else if ((parseopts.helpFlags & HELPFLAGS_TOOL_OTHER) && !Option_ForThisTool(*opts)) { + show = 1; + } else if ((parseopts.helpFlags & HELPFLAGS_TOOL_OTHER) && Option_ForTool(*opts, ~Option_ThisTool() & OTF_TOOL_MASK)) { + show = 1; + } + + if (show) + Help_Option(lst, *opts, subprint, keyword); + + ++opts; + } + + if (subprint && (parseopts.helpFlags & HELPFLAGS_SPACES)) + Help_NewLine(); + Help_Flush(); + if (!subprint) + HPrintF(helptext, "\n"); +} + +void Help_Usage() { + Side_Print( + &all, + "\tGuide to help:\b" + "\tWhen an option is specified as '~~xxx | yy[y] | zzz', then either '~~xxx', '~~yy', '~~yyy', or '~~zzz' matches the option.\b" + "\tAn option given as '~~[no]xxx' may be given as '~~xxx' or '~~noxxx'; '~~noxxx' reverses the meaning of the option.\b" + ); + Help_OutputSingle(&all); + + Side_Print( + &all, + "\tFor most options, the option and the parameters are separated by a %sspace. When the option's name is '~~xxx+', however, the parameter must directly follow the option, without the '+' (as in '~~xxx45').\b", + (compat != 1) ? "" : "colon or " + ); + Side_Print( + &all, + "\tA parameter included in brackets '[]' is optional. An ellipsis '...' indicates that the previous type of parameter may be repeated as a list.\b" + ); + Help_OutputSingle(&all); + + Side_Print( + &all, + "\t%s-- \"compatability\" indicates that the option is borrowed from another vendor's tool and may only approximate its counterpart.\r" + "-- \"global\" indicates that the option has an effect over the entire command line and is parsed before any other options. When several global options are specified, they are interpreted in order.\r" + "-- \"deprecated\" indicates that the option will be eliminated in the future and should not be used any longer. An alternative form is supplied.\r", + (compat != 1) ? "-- \"cased\" indicates that the option is case-sensitive. By default, no options are case-sensitive.\r" : ""); + Help_OutputSingle(&all); + + Side_Print( + &all, + "-- \"ignored\" means the option will be accepted but has no effect on the tool.\r" + "-- \"meaningless\" means the option is accepted but probably has no meaning for the target OS.\r" + "-- \"obsolete\" means the option was once deprecated and is now gone.\r" + "-- \"substituted\" means the option has the same effect as another. This points out a preferred form and prevents confusion when similar options appear in the help.\r" + "-- \"default\" in the help text indicates that the given value or variation of an option will be used unless otherwise overridden. \b" + ); + Help_OutputSingle(&all); + + Side_Print( + &all, + "\tThe symbols ',' %s separate options and parameters unconditionally; to include one of these symbols in a parameter or filename, escape it (e.g., as '\\,' in mwcc file.c\\,v).\b\n", + (compat != 1) ? "and '='" : ", ':', and '='" + ); + Help_OutputSingle(&all); + + if (parseopts.passingArgs && pTool->TYPE == CWDROPINCOMPILERTYPE) + Side_Print( + &all, + "\tThis tool calls the linker (unless a compiler option such as ~~c prevents it) and understands linker options -- use '~~help tool=other' to see them. Options marked \"passed to linker\" are used by the compiler and the linker; options marked \"for linker\" are used only by the linker. When using the compiler and linker separately, you must pass the common options to both.\b\n" + ); + Help_OutputSingle(&all); +} + +void Help_Null() { + Side_Print(&all, + "%s [options, filenames...]\n\nExecute '%s %shelp' for more information.", + OS_GetFileNamePtr(parseopts.args->argv[0]), + OS_GetFileNamePtr(parseopts.args->argv[0]), + MAINOPTCHAR + ); + Help_OutputSingle(&all); +} + +void Help_Init() { + short lb; + short le; + short rb; + short re; + + if (!(helptext = NewHandle(0))) { + fprintf(stderr, "\n*** Out of memory\n"); + exit(-23); + } + + lb = parseopts.ioCols / 40; + le = (parseopts.ioCols / 3) + lb; + rb = le + 3 + ((parseopts.ioCols / 60) & ~1); + re = parseopts.ioCols - 1; + Side_Init(&left, lb, le - lb); + Side_Init(&right, rb, re - rb); + Side_Init(&all, 0, re); +} + +void Help_Line(char ch) { + char line[256]; + memset(line, ch, 255); + line[255] = 0; + HPrintF(helptext, "%.*s\n", parseopts.ioCols - 1, line); +} + +void Help_Term() { + ShowTextHandle(0, helptext); + DisposeHandle(helptext); +} diff --git a/Option.c b/Option.c new file mode 100644 index 0000000..4a09705 --- /dev/null +++ b/Option.c @@ -0,0 +1,630 @@ +#include "mwcc_decomp.h" + +#define OPTION_ASSERT(cond) do { if (!(cond)) { printf("%s:%u: failed assertion\n", __FILE__, __LINE__); abort(); } } while(0) + +#define MAXSTACK 8 + +int oStackPtr; +Opt48 oStack[8]; +char curopt[1024]; +int maxlegalset; +int numlegalset; +int numinternalset; +static OptionList legalset; +static OptionList internalset; +int numoptionlists; +static OptionList *optionlists[32]; + +enum { + ARGFLAG_1 = 1, + ARGFLAG_2 = 2, + ARGFLAG_4 = 4, + ARGFLAG_8 = 8, + ARGFLAG_10 = 0x10, + ARGFLAG_20 = 0x20, + ARGFLAG_40 = 0x40, + ARGFLAG_80 = 0x80 +}; + +enum { + ARGSPELLFLAG_1 = 1, + ARGSPELLFLAG_2 = 2, + ARGSPELLFLAG_4 = 4, + ARGSPELLFLAG_8 = 8, + ARGSPELLFLAG_10 = 0x10, + ARGSPELLFLAG_20 = 0x20, + ARGSPELLFLAG_40 = 0x40, + ARGSPELLFLAG_80 = 0x80 +}; + +enum { + OPTSPELLFLAG_1 = 1, + OPTSPELLFLAG_2 = 2, + OPTSPELLFLAG_4 = 4, + OPTSPELLFLAG_8 = 8, + OPTSPELLFLAG_10 = 0x10, + OPTSPELLFLAG_20 = 0x20, + OPTSPELLFLAG_40 = 0x40, + OPTSPELLFLAG_80 = 0x80 +}; + +static void Option_PushList(OptionList *lst) { + Args_Push(1, lst, 0); +} + +static void Option_PushOpt(Option *opt, const char *optname) { + char *cpy; + short flags = ARGFLAG_2; + if (opt && (opt->avail & OTF2)) { + if (Utils_CompareOptionString(opt->names, optname, opt->avail & OTF_CASED, OTF2)) { + flags |= ARGFLAG_80; + } + } + cpy = xstrdup(optname); + Args_Push(flags, opt, cpy); +} + +static void Option_PopOpt(char *optname) { + Opt48 *os = Args_Pop(ARGFLAG_2); + if (optname) + strcpy(optname, os->e.o.curopt); + free(os->e.o.curopt); +} + +static void Option_PopList() { + Args_Pop(ARGFLAG_1); +} + +void Args_InitStack() { + oStackPtr = 0; +} +int Args_StackSize() { + return oStackPtr; +} + +void Args_Push(short flags, void *first, void *second) { +#line 104 + OPTION_ASSERT(oStackPtr<MAXSTACK); + if (oStackPtr > 0) + { + short prev = + (flags & ARGFLAG_1) ? ARGFLAG_2 : + (flags & ARGFLAG_2) ? ARGFLAG_1 : + (flags & ARGFLAG_4) ? ARGFLAG_2 : -1; + OPTION_ASSERT(oStack[oStackPtr-1].flags & prev); + } + + oStack[oStackPtr].e.v.first = first; + oStack[oStackPtr].e.v.second = second; + oStack[oStackPtr].flags = flags; + oStackPtr++; +} + +Opt48 *Args_Pop(short flags) +{ + OPTION_ASSERT(oStackPtr>0); + --oStackPtr; + OPTION_ASSERT(oStack[oStackPtr].flags & flags); + return &oStack[oStackPtr]; +} + +void Args_SpellStack(char *buffer, short flags) { + char *bptr; + Opt48 *os; + int sp; + int level; + + bptr = buffer; + sp = 0; + level = 0; + os = &oStack[sp]; + + while (sp < oStackPtr) { + if (!flags || !(os->flags & ARGFLAG_20)) { + if (os->flags & ARGFLAG_4) { + Opt48 *po = os - 1; + if (!(os[-1].flags & ARGFLAG_40)) { + if ((level == 1 || level == 2) && !(po->flags & ARGFLAG_80)) + *(bptr++) = (flags & ARGSPELLFLAG_20) ? '\n' : ' '; + os[-1].flags |= ARGFLAG_40; + } else if (level == 2) { + *(bptr++) = ','; + } else if (level == 3) { + *(bptr++) = '='; + } + strcpy(bptr, os->e.param); + bptr += strlen(bptr); + } else if (os->flags & ARGFLAG_2) { + if (level == 1) { + *(bptr++) = MAINOPTCHAR[0]; + } else if (level == 2) { + Opt48 *po = os - 2; + if (!(os[-1].flags & ARGFLAG_40) && !(po->flags & ARGFLAG_80)) + *(bptr++) = (flags & ARGSPELLFLAG_20) ? '\n' : ' '; + } + + if (os[-1].flags & ARGFLAG_40) { + if (level == 2) { + if (flags & ARGSPELLFLAG_20) + *(bptr++) = ','; + else + *(bptr++) = ' '; + } + } else { + if (level == 3) { + *(bptr++) = '='; + } + } + + os[-1].flags |= ARGFLAG_40; + strcpy(bptr, os->e.o.curopt); + bptr += strlen(bptr); + } + + if (flags & ARGSPELLFLAG_20) + os->flags |= ARGFLAG_20; + } + + if (os->flags & ARGFLAG_1) + level++; + + ++sp; + ++os; + } +} + +void Args_AddToToolArgs(anon0_50 *ta) { + char buffer[4096]; + char *nptr; + + Args_SpellStack(buffer, ARGSPELLFLAG_20); + nptr = strchr(buffer, '\n'); + if (nptr) { + *(nptr++) = 0; + Arg_AddToToolArgs(ta, 2, buffer); + Arg_AddToToolArgs(ta, 1, 0); + } else { + nptr = buffer; + } + Arg_AddToToolArgs(ta, 2, nptr); +} + +void Options_Init() { + numoptionlists = 0; + maxlegalset = 0; + numlegalset = 0; + numinternalset = 0; + + if (legalset.list) + free(legalset.list); + if (internalset.list) + free(internalset.list); + + legalset.list = 0; + legalset.flags = + ((Option_ThisTool() & OTF_TOOL_COMPILER) ? LISTFLAGS_COMPILER : 0) | + ((Option_ThisTool() & OTF_TOOL_LINKER) ? LISTFLAGS_LINKER : 0) | + ((Option_ThisTool() & OTF_TOOL_DISASSEMBLER) ? LISTFLAGS_DISASSEMBLER : 0); + internalset.list = 0; + internalset.flags = + ((Option_ThisTool() & OTF_TOOL_COMPILER) ? LISTFLAGS_COMPILER : 0) | + ((Option_ThisTool() & OTF_TOOL_LINKER) ? LISTFLAGS_LINKER : 0) | + ((Option_ThisTool() & OTF_TOOL_DISASSEMBLER) ? LISTFLAGS_DISASSEMBLER : 0); + + Args_InitStack(); +} + +OptionList *Options_GetOptions() { + return &legalset; +} + +void Options_SortOptions() { + int r; + + if (numinternalset > 0) { + legalset.list = (Option **) xrealloc("options", legalset.list, sizeof(Option *) * (numinternalset + 1)); + for (r = 0; r < numinternalset; r++) { + if (internalset.list[r]->avail & (OTF2 | OTF_CASED)) + legalset.list[numlegalset++] = internalset.list[r]; + } + for (r = 0; r < numinternalset; r++) { + if (!(internalset.list[r]->avail & (OTF2 | OTF_CASED))) + legalset.list[numlegalset++] = internalset.list[r]; + } + legalset.list[numlegalset] = 0; + + if (internalset.list) + free(internalset.list); + internalset.list = 0; + numinternalset = 0; + } +} + +static void Options_AddOption(Option *opt) { + if (numinternalset >= maxlegalset) { + maxlegalset += 32; + internalset.list = (Option **) xrealloc("options", internalset.list, sizeof(Option *) * (maxlegalset + 1)); + } + + internalset.list[numinternalset++] = opt; + internalset.list[numinternalset] = 0; +} + +int Options_AddList(OptionList *optlst) { + Option **ptr; + + if (numoptionlists >= 32) + CLPFatalError("Too many option lists defined!"); + + optionlists[numoptionlists++] = optlst; + for (ptr = optlst->list; *ptr; ptr++) + Options_AddOption(*ptr); + + return 1; +} + +int Options_AddLists(OptionList **optlst) { + int ret = 1; + OptionList **ptr; + + for (ptr = optlst; *ptr; ptr++) { + ret = Options_AddList(*ptr); + if (!ret) + return ret; + } + + return ret; +} + +static void Options_Reset(OptionList *optlst) { + Option **os; + + os = optlst->list; + if (os) { + for (; *os; os++) { + (*os)->avail &= ~(OTF80000000 | OTF40000000); + } + } +} + +static void Option_SpellList(char *buffer, OptionList *conflicts, int flags) { + // r25: buffer + // r0: conflicts + // r26: flags + + Option **scan; // r30 + Boolean first; // r29 + int total; // r28 + char tmp[256]; // stack 0x58 + Option **next; // r27 + int slflags; // r6 + + scan = conflicts->list; + first = 1; + total = 0; + while (*scan) { + next = scan + 1; + if (!((*scan)->avail & (((parseopts.helpFlags & HELPFLAGS_SECRET) ? 0 : OTF_SECRET) | ((parseopts.helpFlags & HELPFLAGS_DEPRECATED) ? 0 : OTF_DEPRECATED) | OTF_SUBSTITUTED)) && (*scan)->names[0]) { + // 17C1BC + if (!first) + buffer += sprintf(buffer, ", "); + if (first) + first = 0; + + if (total > 1) { + while (*next && (((*next)->avail & (((parseopts.helpFlags & HELPFLAGS_SECRET) ? 0 : OTF_SECRET) | ((parseopts.helpFlags & HELPFLAGS_DEPRECATED) ? 0 : OTF_DEPRECATED) | OTF_SUBSTITUTED)) || !(*next)->names[0])) { + ++next; + } + + if (!*next) + buffer += sprintf(buffer, "or "); + } + + slflags = (flags & OPTSPELLFLAG_2) ? SLFLAGS_2 : SLFLAGS_1; + switch ((*scan)->avail & OTF_SLFLAGS_MASK) { + case OTF_SLFLAGS_8: + slflags |= SLFLAGS_8; + break; + case OTF_SLFLAGS_20: + slflags |= SLFLAGS_20; + break; + case OTF_SLFLAGS_10: + slflags |= SLFLAGS_10; + break; + } + + Utils_SpellList((*scan)->names, tmp, slflags); + total++; + buffer += sprintf(buffer, "%s", tmp); + + if ((*scan)->avail & OTF8000) + buffer += sprintf(buffer, " ..."); + } + scan++; + } +} + +int Option_ForTool(Option *opt, int which) { + return !which || (opt->avail & which); +} + +int Option_ThisTool() { + return (pTool->TYPE == CWDROPINCOMPILERTYPE) ? OTF_TOOL_COMPILER : OTF_TOOL_LINKER; +} + +int Option_ForThisTool(Option *opt) { + return !Option_ForTool(opt, OTF_TOOL_MASK) || Option_ForTool(opt, Option_ThisTool()); +} + +int Option_AlsoPassedToTool(Option *opt, int which) { + return Option_ForThisTool(opt) && Option_ForTool(opt, which); +} + +int Option_AlsoPassedFromThisTool(Option *opt) { + return Option_ForThisTool(opt) && Option_ForTool(opt, ~Option_ThisTool() & OTF_TOOL_MASK); +} + +static Boolean Option_ContinuesThisLevel(int level, ArgToken *tok) { + // tok: r30 + ArgToken *tmp; // r0 + int ret; // not in stabs but i think this exists + + if (level == 1) { + return (tok->val == ATK_1) || (tok->val == ATK_3) || (tok->val == ATK_2); + } else if (level == 2) { + tmp = Arg_UsedToken(); + ret = (tok->val == ATK_5 && tmp->val != ATK_3) || (tok->val == ATK_2 && tmp->val != ATK_1); + Arg_UndoToken(); + return ret; + } else if (level == 3) { + return (tok->val == ATK_4) || (tok->val == ATK_2); + } else { + return 0; + } +} + +static short endingStack[5][3]; +static Boolean Option_IsEndingThisLevel(int level, ArgToken *tok) { + // level, tok: r0 + ArgToken *tmp; // r0 + + if (!tok) + return 0; + // todo +} + +static Boolean Option_IsEndingLevel(int level, ArgToken *tok) { + // level: r30 + // tok: r31 +} + +int Option_Parse(Option *opt, int oflags) { + // opt: r24 + // oflags: r25 + int ret; // r29 + int pushed; // r28 + int samelevel; // r30 + int subparse; // r27 + int flags; // r26 + char errstr[1024]; // stack 0x3C + Option **cscan; // r30 + Option **scan; // r5 + int goingtosubparse; // r30 + ArgToken *tok; // r0 +} + +static int Option_MatchString(char *list, char *str, int flags, int *result) { + // list: r26 + // str: r27 + // flags: r0 + // result: r28 + int str_len; // r0 + char cpy[64]; // stack 0x3C +} + +static Option *Option_Lookup(OptionList *search, int unk, int *flags) { + // search: r0 + // flags: r25 + Option **os; // r29 + Option *stickyopt; // r28 + int stickyflags; // r27 + Boolean matched; // r0 + char *names; // r26 +} + +static int Options_DoParse(OptionList *search, int flags) { + // search: r26 + // flags: r28 + int haderrors; // r30 + int parsedany; // r23 + int failed; // r24 + int matchflags; // stack 0x3C + int subparse; // r20 + ArgToken *starttok; // r0 + ArgToken *tok; // r25 + ArgToken *opttok; // r27 + Option *opt; // r16 + Boolean isOpt; // r0 + char *lptr; // r17 + char *optname; // r16 + char saveopt[1024]; // stack 0xBC + // Option *opt; // r3 + // char saveopt[64]; // stack 0x7C + // ArgToken *prev; // r0 + // char sticky[64]; // stack 0x3C + // ArgToken *prev; // r16 +} + +int Options_Parse(OptionList *options, int flags) { + // options: r30 + // flags: r31 + int ret; // r31 + char savecuropt[64]; // stack 0x3C + + Options_Reset(options); + Option_PushList(options); + + if (!(flags & 2)) { + ret = Options_DoParse(options, flags); + if (Option_ThisTool() == OTF_TOOL_COMPILER) + Arg_AddToToolArgs(&linkargs, 1, 0); + } else { + strcpy(savecuropt, curopt); + ret = Options_DoParse(options, flags); + strcpy(curopt, savecuropt); + } + + Option_PopList(); + return ret; +} + +int Option_ParseDefaultOption(OptionList *options) { + // options: r31 + int ret; // r31 + Option *dopt; // r0 + int matchflags; // 0x3C + + Options_Reset(options); + Option_PushList(options); + + strcpy(curopt, "defaultoptions"); + dopt = Option_Lookup(options, 0, &matchflags); + if (!dopt) { + CLPFatalError("Default options not defined"); + ret = 1; + } else { + ret = Option_Parse(dopt, 0); + } + + Option_PopList(); + return ret; +} + +void Option_ParamError(short id, va_list ap) { + char buf[4096]; + + CLPGetErrorString(id, buf); + sprintf(&buf[strlen(buf)], "\nwhile parsing option '"); + Args_SpellStack(&buf[strlen(buf)], 0); + sprintf(&buf[strlen(buf)], "'"); + CLPReportError_V(buf, ap); +} + +void Option_ParamWarning(short id, va_list ap) { + char buf[1024]; + + CLPGetErrorString(id, buf); + sprintf(&buf[strlen(buf)], "\nwhile parsing option '"); + Args_SpellStack(&buf[strlen(buf)], 0); + sprintf(&buf[strlen(buf)], "'"); + CLPReportWarning_V(buf, ap); +} + +void Option_OptionError(short id, va_list ap) { + char buf[1024]; + + CLPGetErrorString(id, buf); + if (Args_StackSize() >= 2) { + sprintf(&buf[strlen(buf)], "\nwhile parsing option '"); + Args_SpellStack(&buf[strlen(buf)], 0); + sprintf(&buf[strlen(buf)], "'"); + } + CLPReportError_V(buf, ap); +} + +void Option_OptionWarning(short id, va_list ap) { + char buf[1024]; + + CLPGetErrorString(id, buf); + if (Args_StackSize() >= 2) { + sprintf(&buf[strlen(buf)], "\nwhile parsing option '"); + Args_SpellStack(&buf[strlen(buf)], 0); + sprintf(&buf[strlen(buf)], "'"); + } + CLPReportWarning_V(buf, ap); +} + +void Option_Error(short id, ...) { + va_list va; + va_start(va, id); + Option_OptionError(id, va); + va_end(va); +} + +void Option_Warning(short id, ...) { + va_list va; + va_start(va, id); + Option_OptionWarning(id, va); + va_end(va); +} + +int Options_Help(const char *keyword) { + // keyword: r31 + int scan; // r26 + OptionList *lst; // r25 + + Help_Init(); + + if (parseopts.helpFlags & HELPFLAGS_USAGE) { + ShowVersion(1); + Help_Line('='); + Help_Usage(); + } else { + ShowVersion(1); + for (scan = 0; scan < numoptionlists; scan++) { + if ((lst = optionlists[scan])) { + if (parseopts.helpFlags & HELPFLAGS_8000) { + if (keyword && keyword[0] && lst->help && strstr(lst->help, keyword)) + Help_Options(lst, 0, ""); + } else { + Help_Options(lst, 0, keyword); + } + } + } + } + + Help_Term(); + return 1; +} + +int Option_Help(const char *opt) { + // opt: r31 + Option *find; // r29 + int matchflags; // stack 0x3C + int ret; // r29 + + find = 0; + Option_PushList(Options_GetOptions()); + Option_PushOpt(0, "help"); + if (opt[0] == MAINOPTCHAR[0]) + strcpy(curopt, opt + 1); + else + strcpy(curopt, opt); + + if (!curopt[1]) + find = Option_Lookup(Options_GetOptions(), 0x700002, &matchflags); + if (!find) + find = Option_Lookup(Options_GetOptions(), 0x700000, &matchflags); + + if (find) { + Help_Init(); + if (!Help_Option(Options_GetOptions(), find, 0, "")) + CLPReportWarning(38, opt); + Help_Term(); + ret = 1; + } else { + Option_Error(19, opt); + ret = 0; + } + + Option_PopOpt(curopt); + Option_PopList(); + return ret; +} + +int Options_DisplayHelp() { + if (parseopts.helpFlags & HELPFLAGS_1) + Option_Help(parseopts.helpKey); + else + Options_Help(parseopts.helpKey); +} @@ -0,0 +1,286 @@ +#include "CompilerTools.h" +#include "PCode.h" + +// TODO RESOLVE ME +extern void initialize_aliases(); +extern void *current_statement; +extern PCode *vformatpcode(short op, va_list args); + +PCBlock *pcbasicblocks; +PCBlock *pclastblock; +void *prologue; +void *epilogue; +PCBlock **depthfirstordering; +int pcblockcount; +int pcloopweight; +static unsigned short pclabelcount; + +void initpcode() { + pclastblock = 0; + pcbasicblocks = 0; + pcblockcount = 0; + pclabelcount = 0; + pcloopweight = 1; + initialize_aliases(); +} + +PCode *makepcode(short op, ...) { + PCode *pcode; + va_list list; + + va_start(list, op); + pcode = vformatpcode(op, list); + // TODO + return pcode; +} + +void emitpcode(short op, ...) { + PCode *pcode; + va_list list; + + va_start(list, op); + pcode = vformatpcode(op, list); + // TODO + appendpcode(pclastblock, pcode); +} + +PCode *copypcode(PCode *pcode) { + PCode *newpc; + int flag; + + flag = 0; + // TODO + + return newpc; +} + +PCLabel *makepclabel() { + PCLabel *label; + + label = (PCLabel *) lalloc(sizeof(PCLabel)); + memclrw(label, sizeof(PCLabel)); + label->index = pclabelcount++; + return label; +} + +PCBlock *makepcblock() { + PCBlock *block; + + block = (PCBlock *) lalloc(sizeof(PCBlock)); + memclrw(block, sizeof(PCBlock)); + block->loopWeight = pcloopweight; + block->blockIndex = pcblockcount++; + if (pclastblock) { + pclastblock->nextBlock = block; + block->prevBlock = pclastblock; + } else { + pcbasicblocks = block; + } + pclastblock = block; + return block; +} + +void pclabel(PCBlock *block, PCLabel *label) { + PCLink *iter; + PCLink *next; + + iter = (PCLink *) label->block; + while (iter) { + next = (PCLink *) iter->block; + iter->block = block; + iter = next; + } + + label->block = block; + label->resolved = 1; + label->nextLabel = block->labels; + block->labels = label; +} + +void pcbranch(PCBlock *block, PCLabel *label) { + PCLink *link; + + link = (PCLink *) lalloc(sizeof(PCLink)); + memclrw(link, sizeof(PCLink)); + + link->block = label->block; + if (!label->resolved) + label->block = (PCBlock *) link; + link->nextLink = block->successors; + block->successors = link; +} + +void pccomputepredecessors() { + PCBlock *block; + PCLink *succ; + PCLink *pred; + + for (block = pcbasicblocks; block; block = block->nextBlock) { + for (succ = block->successors; succ; succ = succ->nextLink) { + pred = (PCLink *) lalloc(sizeof(PCLink)); + memclrw(pred, sizeof(PCLink)); + + pred->block = block; + pred->nextLink = succ->block->predecessors; + succ->block->predecessors = pred; + } + } +} + +void deleteblock(PCBlock *block) { + block->prevBlock->nextBlock = block->nextBlock; + if (block->nextBlock) + block->nextBlock->prevBlock = block->prevBlock; + block->flags |= fPCBlockFlag20; +} + +void deleteunreachableblocks() { + PCBlock *block; + + computedepthfirstordering(); + + for (block = pcbasicblocks->nextBlock; block; block = block->nextBlock) { + if (!(block->flags & fPCBlockFlag4)) + deleteblock(block); + } +} + +void appendpcode(PCBlock *block, PCode *pcode) { + if (block->firstPCode) { + pcode->nextPCode = 0; + pcode->prevPCode = block->lastPCode; + block->lastPCode->nextPCode = pcode; + block->lastPCode = pcode; + } else { + block->lastPCode = pcode; + block->firstPCode = pcode; + pcode->prevPCode = 0; + pcode->nextPCode = 0; + } + pcode->block = block; + block->pcodeCount++; +} + +void deletepcode(PCode *pcode) { + PCBlock *block; + + block = pcode->block; + if (pcode->prevPCode) + pcode->prevPCode->nextPCode = pcode->nextPCode; + else + block->firstPCode = pcode->nextPCode; + if (pcode->nextPCode) + pcode->nextPCode->prevPCode = pcode->prevPCode; + else + block->lastPCode = pcode->prevPCode; + + pcode->block = 0; + block->pcodeCount--; + block->flags &= ~fPCBlockFlag8; +} + +void insertpcodebefore(PCode *anchor, PCode *newpcode) { + PCBlock *block; + + block = anchor->block; + if (anchor->prevPCode) + anchor->prevPCode->nextPCode = newpcode; + else + block->firstPCode = newpcode; + newpcode->nextPCode = anchor; + newpcode->prevPCode = anchor->prevPCode; + anchor->prevPCode = newpcode; + newpcode->_1C = anchor->_1C; + + newpcode->block = block; + block->pcodeCount++; + block->flags &= ~fPCBlockFlag8; +} + +void insertpcodeafter(PCode *anchor, PCode *newpcode) { + PCBlock *block; + + block = anchor->block; + if (anchor->nextPCode) + anchor->nextPCode->prevPCode = newpcode; + else + block->lastPCode = newpcode; + newpcode->prevPCode = anchor; + newpcode->nextPCode = anchor->nextPCode; + anchor->nextPCode = newpcode; + newpcode->_1C = anchor->_1C; + + newpcode->block = block; + block->pcodeCount++; + block->flags &= ~fPCBlockFlag8; +} + +void setpcodeflags(int flags) { + pclastblock->lastPCode->flags |= flags; + if (flags & fSideEffects) + pclastblock->lastPCode->flags &= ~(fIsCSE | fCommutative | fPCodeFlag10); +} + +void clearpcodeflags(int flags) { + pclastblock->lastPCode->flags &= ~flags; +} + +int pccomputeoffsets() { + int offset; + PCBlock *block; + + offset = 0; + for (block = pcbasicblocks; block; block = block->nextBlock) { + block->codeOffset = offset; + offset += block->pcodeCount * 4; + } + + return offset; +} + +typedef struct _DFO { + PCBlock *block; + PCLink *link; +} DFO; + +static int depthfirstorder; + +void computedepthfirstordering() { + PCBlock *block; + PCLink *link; + DFO *dfo; + int index; + + depthfirstordering = (PCBlock **) lalloc(sizeof(PCBlock *) * pcblockcount); + memclrw(depthfirstordering, sizeof(PCBlock *) * pcblockcount); + depthfirstorder = pcblockcount; + + for (block = pcbasicblocks; block; block = block->nextBlock) { + block->flags &= ~fPCBlockFlag4; + } + + dfo = (DFO *) oalloc(sizeof(DFO) * pcblockcount); + pcbasicblocks->flags |= fPCBlockFlag4; + + dfo->block = pcbasicblocks; + dfo->link = pcbasicblocks->successors; + index = 1; + while (index) { + if ((link = dfo[index - 1].link)) { + dfo[index - 1].link = link->nextLink; + block = link->block; + if (!(block->flags & fPCBlockFlag4)) { + block->flags |= fPCBlockFlag4; + dfo[index].block = block; + dfo[index].link = block->successors; + index++; + } + } else { + depthfirstordering[--depthfirstorder] = dfo[--index].block; + } + } + + while (depthfirstorder) { + depthfirstordering[--depthfirstorder] = 0; + } +} @@ -0,0 +1,110 @@ +#pragma once + +typedef struct _PCodeArg { + unsigned int _0; + unsigned int _4; + unsigned int _8; +} PCodeArg; + +typedef struct _PCode { + struct _PCode *nextPCode; + struct _PCode *prevPCode; + struct _PCBlock *block; + unsigned int xx_C; + unsigned int _10; + int flags; + unsigned int _18; + unsigned int _1C; + short op; + short argCount; + PCodeArg args[0]; +} PCode; + +typedef struct _PCLabel { + struct _PCLabel *nextLabel; + struct _PCBlock *block; + short resolved; + short index; +} PCLabel; + +typedef struct _PCLink { + struct _PCLink *nextLink; + struct _PCBlock *block; +} PCLink; + +typedef struct _PCBlock { + struct _PCBlock *nextBlock; + struct _PCBlock *prevBlock; + PCLabel *labels; + PCLink *predecessors; + PCLink *successors; + PCode *firstPCode; + PCode *lastPCode; + int blockIndex; + int codeOffset; // in bytes + int loopWeight; + short pcodeCount; + unsigned short flags; +} PCBlock; + +/* PCode Flags */ +enum { + fPCodeFlag1 = 1, + fPCodeFlag2 = 2, + fPCodeFlag4 = 4, + fPCodeFlag8 = 8, + fPCodeFlag10 = 0x10, + fIsPtrOp = 0x20, + fIsConst = 0x40, + fIsVolatile = 0x80, + fSideEffects = 0x100, + fPCodeFlag200 = 0x200, + fPCodeFlag400 = 0x400, + fPCodeFlag800 = 0x800, + fPCodeFlag1000 = 0x1000, + fCommutative = 0x2000, + fIsCSE = 0x4000, + fOverflow = 0x800000, + fLink = 0x1000000, + fBranchNotTaken = 0x4000000, + fBranchTaken = 0x8000000, + fAbsolute = 0x10000000, + fSetsCarry = 0x10000000, +}; + +enum { + fPCBlockFlag1 = 1, + fPCBlockFlag2 = 2, + fPCBlockFlag4 = 4, + fPCBlockFlag8 = 8, + fPCBlockFlag10 = 0x10, + fPCBlockFlag20 = 0x20 +}; + +extern PCBlock *pcbasicblocks; +extern PCBlock *pclastblock; +extern void *prologue; +extern void *epilogue; +extern PCBlock **depthfirstordering; +extern int pcblockcount; +extern int pcloopweight; + +extern void initpcode(); +extern PCode *makepcode(short op, ...); +extern void emitpcode(short op, ...); +extern PCode *copypcode(PCode *pcode); +extern PCLabel *makepclabel(); +extern PCBlock *makepcblock(); +extern void pclabel(PCBlock *block, PCLabel *label); +extern void pcbranch(PCBlock *block, PCLabel *label); +extern void pccomputepredecessors(); +extern void deleteblock(PCBlock *block); +extern void deleteunreachableblocks(); +extern void appendpcode(PCBlock *block, PCode *pcode); +extern void deletepcode(PCode *pcode); +extern void insertpcodebefore(PCode *anchor, PCode *newpcode); +extern void insertpcodeafter(PCode *anchor, PCode *newpcode); +extern void setpcodeflags(int flags); +extern void clearpcodeflags(int flags); +extern int pccomputeoffsets(); +extern void computedepthfirstordering(); diff --git a/PCodeInfo.c b/PCodeInfo.c new file mode 100644 index 0000000..9d469bc --- /dev/null +++ b/PCodeInfo.c @@ -0,0 +1,55 @@ +#include "PCodeInfo.h" + +void pcode_get_hi_lo(int a1, char a2, int *pA, int *pB) { + +} + +int pcode_check_imm_bits(int a1, int a2, int a3) { + +} + +int pcode_const_from_format(char *buf, int *pResult) { + +} + +PCode *vformatpcode(short opcode, va_list argList) { + +} + +int expectandformatoperand(PCodeArg *operand, unsigned char expectedKind, char a3, int bitCount, char *buf) { +} + +int formatoperand(PCodeArg *operand, char *buf) { + +} + +void formatoperands(PCode *pcode, char *buf, int showBasicBlocks) { + +} + +PCode *makecopyinstruction(PCodeArg *a, PCodeArg *b) { + +} + +int is_location_independent(PCode *pcode) { + +} + +int can_reuse_stored_value(PCode *a, PCode *b) { + +} + +int nbytes_loaded_or_stored_by(PCode *pcode) { + +} + +void change_num_operands(PCode *pcode, int newNum) { + +} + +void change_opcode(PCode *pcode, short opcode) { + pcode->flags = (pcode->flags & ~(opcodeinfo[pcode->op].flags & ~fIsPtrOp)) | opcodeinfo[opcode].flags; + if ((pcode->flags & fPCodeFlag10) && (pcode->flags & (fPCodeFlag1 | fPCodeFlag8))) + pcode->flags &= ~fPCodeFlag10; + pcode->op = opcode; +} diff --git a/PCodeInfo.h b/PCodeInfo.h new file mode 100644 index 0000000..9e3b048 --- /dev/null +++ b/PCodeInfo.h @@ -0,0 +1,462 @@ +#pragma once + +#include "PCode.h" + +typedef struct _OpcodeInfo { + const char *name; + const char *format; + unsigned char x8; + unsigned char x9; + int xA; + unsigned int insn; +} OpcodeInfo; + +enum { + PC_B = 0x0, + PC_BL = 0x1, + PC_BC = 0x2, + PC_BCLR = 0x3, + PC_BCCTR = 0x4, + PC_BT = 0x5, + PC_BTLR = 0x6, + PC_BTCTR = 0x7, + PC_BF = 0x8, + PC_BFLR = 0x9, + PC_BFCTR = 0xA, + PC_BDNZ = 0xB, + PC_BDNZT = 0xC, + PC_BDNZF = 0xD, + PC_BDZ = 0xE, + PC_BDZT = 0xF, + PC_BDZF = 0x10, + PC_BLR = 0x11, + PC_BCTR = 0x12, + PC_BCTRL = 0x13, + PC_BLRL = 0x14, + PC_LBZ = 0x15, + PC_LBZU = 0x16, + PC_LBZX = 0x17, + PC_LBZUX = 0x18, + PC_LHZ = 0x19, + PC_LHZU = 0x1A, + PC_LHZX = 0x1B, + PC_LHZUX = 0x1C, + PC_LHA = 0x1D, + PC_LHAU = 0x1E, + PC_LHAX = 0x1F, + PC_LHAUX = 0x20, + PC_LHBRX = 0x21, + PC_LWZ = 0x22, + PC_LWZU = 0x23, + PC_LWZX = 0x24, + PC_LWZUX = 0x25, + PC_LWBRX = 0x26, + PC_LMW = 0x27, + PC_STB = 0x28, + PC_STBU = 0x29, + PC_STBX = 0x2A, + PC_STBUX = 0x2B, + PC_STH = 0x2C, + PC_STHU = 0x2D, + PC_STHX = 0x2E, + PC_STHUX = 0x2F, + PC_STHBRX = 0x30, + PC_STW = 0x31, + PC_STWU = 0x32, + PC_STWX = 0x33, + PC_STWUX = 0x34, + PC_STWBRX = 0x35, + PC_STMW = 0x36, + PC_DCBF = 0x37, + PC_DCBST = 0x38, + PC_DCBT = 0x39, + PC_DCBTST = 0x3A, + PC_DCBZ = 0x3B, + PC_ADD = 0x3C, + PC_ADDC = 0x3D, + PC_ADDE = 0x3E, + PC_ADDI = 0x3F, + PC_ADDIC = 0x40, + PC_ADDICR = 0x41, + PC_ADDIS = 0x42, + PC_ADDME = 0x43, + PC_ADDZE = 0x44, + PC_DIVW = 0x45, + PC_DIVWU = 0x46, + PC_MULHW = 0x47, + PC_MULHWU = 0x48, + PC_MULLI = 0x49, + PC_MULLW = 0x4A, + PC_NEG = 0x4B, + PC_SUBF = 0x4C, + PC_SUBFC = 0x4D, + PC_SUBFE = 0x4E, + PC_SUBFIC = 0x4F, + PC_SUBFME = 0x50, + PC_SUBFZE = 0x51, + PC_CMPI = 0x52, + PC_CMP = 0x53, + PC_CMPLI = 0x54, + PC_CMPL = 0x55, + PC_ANDI = 0x56, + PC_ANDIS = 0x57, + PC_ORI = 0x58, + PC_ORIS = 0x59, + PC_XORI = 0x5A, + PC_XORIS = 0x5B, + PC_AND = 0x5C, + PC_OR = 0x5D, + PC_XOR = 0x5E, + PC_NAND = 0x5F, + PC_NOR = 0x60, + PC_EQV = 0x61, + PC_ANDC = 0x62, + PC_ORC = 0x63, + PC_EXTSB = 0x64, + PC_EXTSH = 0x65, + PC_CNTLZW = 0x66, + PC_RLWINM = 0x67, + PC_RLWNM = 0x68, + PC_RLWIMI = 0x69, + PC_SLW = 0x6A, + PC_SRW = 0x6B, + PC_SRAWI = 0x6C, + PC_SRAW = 0x6D, + PC_CRAND = 0x6E, + PC_CRANDC = 0x6F, + PC_CREQV = 0x70, + PC_CRNAND = 0x71, + PC_CRNOR = 0x72, + PC_CROR = 0x73, + PC_CRORC = 0x74, + PC_CRXOR = 0x75, + PC_MCRF = 0x76, + PC_MTXER = 0x77, + PC_MTCTR = 0x78, + PC_MTLR = 0x79, + PC_MTCRF = 0x7A, + PC_MTMSR = 0x7B, + PC_MTSPR = 0x7C, + PC_MFMSR = 0x7D, + PC_MFSPR = 0x7E, + PC_MFXER = 0x7F, + PC_MFCTR = 0x80, + PC_MFLR = 0x81, + PC_MFCR = 0x82, + PC_MFFS = 0x83, + PC_MTFSF = 0x84, + PC_EIEIO = 0x85, + PC_ISYNC = 0x86, + PC_SYNC = 0x87, + PC_RFI = 0x88, + PC_LI = 0x89, + PC_LIS = 0x8A, + PC_MR = 0x8B, + PC_NOP = 0x8C, + PC_NOT = 0x8D, + PC_LFS = 0x8E, + PC_LFSU = 0x8F, + PC_LFSX = 0x90, + PC_LFSUX = 0x91, + PC_LFD = 0x92, + PC_LFDU = 0x93, + PC_LFDX = 0x94, + PC_LFDUX = 0x95, + PC_STFS = 0x96, + PC_STFSU = 0x97, + PC_STFSX = 0x98, + PC_STFSUX = 0x99, + PC_STFD = 0x9A, + PC_STFDU = 0x9B, + PC_STFDX = 0x9C, + PC_STFDUX = 0x9D, + PC_FMR = 0x9E, + PC_FABS = 0x9F, + PC_FNEG = 0xA0, + PC_FNABS = 0xA1, + PC_FADD = 0xA2, + PC_FADDS = 0xA3, + PC_FSUB = 0xA4, + PC_FSUBS = 0xA5, + PC_FMUL = 0xA6, + PC_FMULS = 0xA7, + PC_FDIV = 0xA8, + PC_FDIVS = 0xA9, + PC_FMADD = 0xAA, + PC_FMADDS = 0xAB, + PC_FMSUB = 0xAC, + PC_FMSUBS = 0xAD, + PC_FNMADD = 0xAE, + PC_FNMADDS = 0xAF, + PC_FNMSUB = 0xB0, + PC_FNMSUBS = 0xB1, + PC_FRES = 0xB2, + PC_FRSQRTE = 0xB3, + PC_FSEL = 0xB4, + PC_FRSP = 0xB5, + PC_FCTIW = 0xB6, + PC_FCTIWZ = 0xB7, + PC_FCMPU = 0xB8, + PC_FCMPO = 0xB9, + PC_LWARX = 0xBA, + PC_LSWI = 0xBB, + PC_LSWX = 0xBC, + PC_STFIWX = 0xBD, + PC_STSWI = 0xBE, + PC_STSWX = 0xBF, + PC_STWCX = 0xC0, + PC_ECIWX = 0xC1, + PC_ECOWX = 0xC2, + PC_DCBI = 0xC3, + PC_ICBI = 0xC4, + PC_MCRFS = 0xC5, + PC_MCRXR = 0xC6, + PC_MFTB = 0xC7, + PC_MFSR = 0xC8, + PC_MTSR = 0xC9, + PC_MFSRIN = 0xCA, + PC_MTSRIN = 0xCB, + PC_MTFSB0 = 0xCC, + PC_MTFSB1 = 0xCD, + PC_MTFSFI = 0xCE, + PC_SC = 0xCF, + PC_FSQRT = 0xD0, + PC_FSQRTS = 0xD1, + PC_TLBIA = 0xD2, + PC_TLBIE = 0xD3, + PC_TLBLD = 0xD4, + PC_TLBLI = 0xD5, + PC_TLBSYNC = 0xD6, + PC_TW = 0xD7, + PC_TRAP = 0xD8, + PC_TWI = 0xD9, + PC_OPWORD = 0xDA, + PC_MFROM = 0xDB, + PC_DSA = 0xDC, + PC_ESA = 0xDD, + PC_DCCCI = 0xDE, + PC_DCREAD = 0xDF, + PC_ICBT = 0xE0, + PC_ICCCI = 0xE1, + PC_ICREAD = 0xE2, + PC_RFCI = 0xE3, + PC_TLBRE = 0xE4, + PC_TLBSX = 0xE5, + PC_TLBWE = 0xE6, + PC_WRTEE = 0xE7, + PC_WRTEEI = 0xE8, + PC_MFDCR = 0xE9, + PC_MTDCR = 0xEA, + PC_DCBA = 0xEB, + PC_DSS = 0xEC, + PC_DSSALL = 0xED, + PC_DST = 0xEE, + PC_DSTT = 0xEF, + PC_DSTST = 0xF0, + PC_DSTSTT = 0xF1, + PC_LVEBX = 0xF2, + PC_LVEHX = 0xF3, + PC_LVEWX = 0xF4, + PC_LVSL = 0xF5, + PC_LVSR = 0xF6, + PC_LVX = 0xF7, + PC_LVXL = 0xF8, + PC_STVEBX = 0xF9, + PC_STVEHX = 0xFA, + PC_STVEWX = 0xFB, + PC_STVX = 0xFC, + PC_STVXL = 0xFD, + PC_MFVSCR = 0xFE, + PC_MTVSCR = 0xFF, + PC_VADDCUW = 0x100, + PC_VADDFP = 0x101, + PC_VADDSBS = 0x102, + PC_VADDSHS = 0x103, + PC_VADDSWS = 0x104, + PC_VADDUBM = 0x105, + PC_VADDUBS = 0x106, + PC_VADDUHM = 0x107, + PC_VADDUHS = 0x108, + PC_VADDUWM = 0x109, + PC_VADDUWS = 0x10A, + PC_VAND = 0x10B, + PC_VANDC = 0x10C, + PC_VAVGSB = 0x10D, + PC_VAVGSH = 0x10E, + PC_VAVGSW = 0x10F, + PC_VAVGUB = 0x110, + PC_VAVGUH = 0x111, + PC_VAVGUW = 0x112, + PC_VCFSX = 0x113, + PC_VCFUX = 0x114, + PC_VCMPBFP = 0x115, + PC_VCMPEQFP = 0x116, + PC_VCMPEQUB = 0x117, + PC_VCMPEQUH = 0x118, + PC_VCMPEQUW = 0x119, + PC_VCMPGEFP = 0x11A, + PC_VCMPGTFP = 0x11B, + PC_VCMPGTSB = 0x11C, + PC_VCMPGTSH = 0x11D, + PC_VCMPGTSW = 0x11E, + PC_VCMPGTUB = 0x11F, + PC_VCMPGTUH = 0x120, + PC_VCMPGTUW = 0x121, + PC_VCTSXS = 0x122, + PC_VCTUXS = 0x123, + PC_VEXPTEFP = 0x124, + PC_VLOGEFP = 0x125, + PC_VMAXFP = 0x126, + PC_VMAXSB = 0x127, + PC_VMAXSH = 0x128, + PC_VMAXSW = 0x129, + PC_VMAXUB = 0x12A, + PC_VMAXUH = 0x12B, + PC_VMAXUW = 0x12C, + PC_VMINFP = 0x12D, + PC_VMINSB = 0x12E, + PC_VMINSH = 0x12F, + PC_VMINSW = 0x130, + PC_VMINUB = 0x131, + PC_VMINUH = 0x132, + PC_VMINUW = 0x133, + PC_VMRGHB = 0x134, + PC_VMRGHH = 0x135, + PC_VMRGHW = 0x136, + PC_VMRGLB = 0x137, + PC_VMRGLH = 0x138, + PC_VMRGLW = 0x139, + PC_VMULESB = 0x13A, + PC_VMULESH = 0x13B, + PC_VMULEUB = 0x13C, + PC_VMULEUH = 0x13D, + PC_VMULOSB = 0x13E, + PC_VMULOSH = 0x13F, + PC_VMULOUB = 0x140, + PC_VMULOUH = 0x141, + PC_VNOR = 0x142, + PC_VOR = 0x143, + PC_VPKPX = 0x144, + PC_VPKSHSS = 0x145, + PC_VPKSHUS = 0x146, + PC_VPKSWSS = 0x147, + PC_VPKSWUS = 0x148, + PC_VPKUHUM = 0x149, + PC_VPKUHUS = 0x14A, + PC_VPKUWUM = 0x14B, + PC_VPKUWUS = 0x14C, + PC_VREFP = 0x14D, + PC_VRFIM = 0x14E, + PC_VRFIN = 0x14F, + PC_VRFIP = 0x150, + PC_VRFIZ = 0x151, + PC_VRLB = 0x152, + PC_VRLH = 0x153, + PC_VRLW = 0x154, + PC_VRSQRTEFP = 0x155, + PC_VSL = 0x156, + PC_VSLB = 0x157, + PC_VSLH = 0x158, + PC_VSLO = 0x159, + PC_VSLW = 0x15A, + PC_VSPLTB = 0x15B, + PC_VSPLTH = 0x15C, + PC_VSPLTW = 0x15D, + PC_VSPLTISB = 0x15E, + PC_VSPLTISH = 0x15F, + PC_VSPLTISW = 0x160, + PC_VSR = 0x161, + PC_VSRAB = 0x162, + PC_VSRAH = 0x163, + PC_VSRAW = 0x164, + PC_VSRB = 0x165, + PC_VSRH = 0x166, + PC_VSRO = 0x167, + PC_VSRW = 0x168, + PC_VSUBCUW = 0x169, + PC_VSUBFP = 0x16A, + PC_VSUBSBS = 0x16B, + PC_VSUBSHS = 0x16C, + PC_VSUBSWS = 0x16D, + PC_VSUBUBM = 0x16E, + PC_VSUBUBS = 0x16F, + PC_VSUBUHM = 0x170, + PC_VSUBUHS = 0x171, + PC_VSUBUWM = 0x172, + PC_VSUBUWS = 0x173, + PC_VSUMSWS = 0x174, + PC_VSUM2SWS = 0x175, + PC_VSUM4SBS = 0x176, + PC_VSUM4SHS = 0x177, + PC_VSUM4UBS = 0x178, + PC_VUPKHPX = 0x179, + PC_VUPKHSB = 0x17A, + PC_VUPKHSH = 0x17B, + PC_VUPKLPX = 0x17C, + PC_VUPKLSB = 0x17D, + PC_VUPKLSH = 0x17E, + PC_VXOR = 0x17F, + PC_VMADDFP = 0x180, + PC_VMHADDSHS = 0x181, + PC_VMHRADDSHS = 0x182, + PC_VMLADDUHM = 0x183, + PC_VMSUMMBM = 0x184, + PC_VMSUMSHM = 0x185, + PC_VMSUMSHS = 0x186, + PC_VMSUMUBM = 0x187, + PC_VMSUMUHM = 0x188, + PC_VMSUMUHS = 0x189, + PC_VNMSUBFP = 0x18A, + PC_VPERM = 0x18B, + PC_VSEL = 0x18C, + PC_VSLDOI = 0x18D, + PC_VMR = 0x18E, + PC_VMRP = 0x18F, + PC_SLE = 0x190, + PC_SLEQ = 0x191, + PC_SLIQ = 0x192, + PC_SLLIQ = 0x193, + PC_SLLQ = 0x194, + PC_SLQ = 0x195, + PC_SRAIQ = 0x196, + PC_SRAQ = 0x197, + PC_SRE = 0x198, + PC_SREA = 0x199, + PC_SREQ = 0x19A, + PC_SRIQ = 0x19B, + PC_SRLIQ = 0x19C, + PC_SRLQ = 0x19D, + PC_SRQ = 0x19E, + PC_MASKG = 0x19F, + PC_MASKIR = 0x1A0, + PC_LSCBX = 0x1A1, + PC_DIV = 0x1A2, + PC_DIVS = 0x1A3, + PC_DOZ = 0x1A4, + PC_MUL = 0x1A5, + PC_NABS = 0x1A6, + PC_ABS = 0x1A7, + PC_CLCS = 0x1A8, + PC_DOZI = 0x1A9, + PC_RLMI = 0x1AA, + PC_RRIB = 0x1AB, + PC_PENTRY = 0x1AC, + PC_PEXIT = 0x1AD, + OPCODE_MAX = 0x1AE +}; + +extern OpcodeInfo opcodeInfo[OPCODE_MAX]; + +extern void pcode_get_hi_lo(int a1, char a2, int *pA, int *pB); +extern int pcode_check_imm_bits(int a1, int a2, int a3); +extern int pcode_const_from_format(char *buf, int *pResult); +extern PCode *vformatpcode(short opcode, va_list argList); +extern int expectandformatoperand(PCodeArg *operand, unsigned char expectedKind, char a3, int bitCount, char *buf); +extern int formatoperand(PCodeArg *operand, char *buf); +extern void formatoperands(PCode *pcode, char *buf, int showBasicBlocks); +extern PCode *makecopyinstruction(PCodeArg *a, PCodeArg *b); +extern int is_location_independent(PCode *pcode); +extern int can_reuse_stored_value(PCode *a, PCode *b); +extern int nbytes_loaded_or_stored_by(PCode *pcode); +extern void change_num_operands(PCode *pcode, int newNum); +extern void change_opcode(PCode *pcode, short opcode); diff --git a/ParserFace.c b/ParserFace.c new file mode 100644 index 0000000..7ce84e5 --- /dev/null +++ b/ParserFace.c @@ -0,0 +1,226 @@ +#include "UCWInterface.h" + +struct ParseOptsType parseopts; + +// TODO move me imports +extern CWResult CWSecretGetNamedPreferences(CWPluginContext context, const char *name, Handle *pHandle); +extern CWResult CWParserSetNamedPreferences(CWPluginContext context, const char *name, Handle pHandle); +extern CWResult CWParserGetCommandLine(CWPluginContext context, CWCommandLineArgs **pArgs); +extern CWResult CWParserGetToolInfo(CWPluginContext context, struct ToolVersionInfo **pToolVersion); +extern CWResult CWParserGetTargetInfo(CWPluginContext context, unsigned long *pCpu, unsigned long *pOs); +extern CWResult CWParserGetPanels(CWPluginContext context, int *pNumPanels, char ***pPanelNames); +extern CWResult CWParserGetPlugins(CWPluginContext context, int *pNumPlugins, struct CLPluginInfo **pPlugins); +extern void/*?*/ CWGetPluginRequest(CWPluginContext context, long *request); +extern void/*?*/ CWDonePluginRequest(CWPluginContext context, CWResult result); +extern void *pTool; +extern void SetupParserToolOptions(); +extern void CLPReportError(short code, ...); +extern unsigned char ParserToolMatchesPlugin(unsigned long plugintype, unsigned long language, unsigned long cpu, unsigned long os); +extern unsigned char ParserToolHandlesPanels(int numPanels, char **panelNames); +// TODO move me imports + +char *failedCallback; + +static CWResult SetupParamBlock(CWPluginContext context) { + struct PCmdLineEnvir cle; + Handle h; + int x; + CWResult result; + + memset(&parseopts, 0, sizeof(parseopts)); + parseopts.context = context; + + result = CWSecretGetNamedPreferences(context, "CmdLine Environment", &h); + if (result) + return result; + + cle = **((struct PCmdLineEnvir **) h); + parseopts.underIDE = cle.underIDE; + parseopts.ioRows = cle.rows; + parseopts.ioCols = cle.cols; + + result = CWParserGetCommandLine(context, &parseopts.args); + if (result) + return result; + + result = CWParserGetToolInfo(context, &parseopts.toolVersion); + if (result) + return result; + + result = CWParserGetTargetInfo(context, &parseopts.cpu, &parseopts.os); + if (result) + return result; + + result = CWParserGetPanels(context, &parseopts.numPanels, &parseopts.panelNames); + if (result) + return result; + + result = CWParserGetPlugins(context, &parseopts.numPlugins, &parseopts.plugins); + if (result) + return result; + + parseopts.passingArgs = 0; + for (x = 0; x < parseopts.numPlugins; x++) { + if (parseopts.plugins[x].storeCommandLine) + parseopts.passingArgs = 1; + } + + return 0; +} + +static CWResult SetupOptions(CWPluginContext context) { + if (!pTool) { + return 2; + } else { + SetupParserToolOptions(); + return 0; + } +} + +static CWResult Parse(CWPluginContext context) { + CWResult result; + + // TODO + return result; +} + +Handle Parser_FindPrefPanel(char *name) { + Handle h; + int idx; + + // TODO pTool +} + +CWResult Parser_StorePanels(CWPluginContext context) { + int idx; + CWResult result; + char *name; + Handle h; + + for (idx = 0; idx < parseopts.numPanels; idx++) { + name = parseopts.panelNames[idx]; + h = Parser_FindPrefPanel(name); + if (h) { + result = CWParserSetNamedPreferences(parseopts.context, name, h); + if (result) { + CLPReportError(68, name); + return result; + } + } + } + + return 0; +} + +static CWResult StoreResults(CWPluginContext context) { + // TODO Arg +} + +short CWParser_GetDropInFlags(const DropInFlags **flags, long *flagsSize) { + static const DropInFlags sFlags = { + kCurrentDropInFlagsVersion, + CWFOURCHAR('P','a','r','s'), + 7, + 0, + 'Seep', + 12 + }; + *flags = &sFlags; + *flagsSize = sizeof(sFlags); + return 0; +} + +short CWParser_GetDropInName(const char **dropinName) { + static const char *sDropInName = "Command-Line Parser"; + *dropinName = sDropInName; + return 0; +} + +short CWParser_GetDisplayName(const char **displayName) { + static const char *sDisplayName = "Command-Line Parser"; + *displayName = sDisplayName; + return 0; +} + +short CWParser_GetPanelList(const CWPanelList **panelList) { + static const CWPanelList sPanelList = { + kCurrentCWFamilyListVersion, + 0, + 0 + }; + *panelList = &sPanelList; + return 0; +} + +short CWParser_GetTargetList(const CWTargetList **targetList) { + static const unsigned long sCPU = '****'; + static const unsigned long sOS = '****'; + static const CWTargetList sTargetList = { + kCurrentCWTargetListVersion, + 1, + &sCPU, + 1, + &sOS + }; + *targetList = &sTargetList; + return 0; +} + +short CWParser_GetVersionInfo(const VersionInfo **versioninfo) { + static const VersionInfo vi = { + 1, 1, 0, 0 + }; + *versioninfo = &vi; + return 0; +} + +short Parser_SupportsPlugin(struct CLPluginInfo *pluginfo, CWDataType cpu, CWDataType os, Boolean *isSupported) { + *isSupported = ParserToolMatchesPlugin(pluginfo->plugintype, pluginfo->language, cpu, os); + return 0; +} + +short Parser_SupportsPanels(int numPanels, char **panelNames, Boolean *isSupported) { + *isSupported = ParserToolHandlesPanels(numPanels, panelNames); + return 0; +} + +jmp_buf exit_plugin; + +short parser_main(CWPluginContext context) { + long request; + CWResult result; + + CWGetPluginRequest(context, &request); + result = setjmp(exit_plugin); + if (result == 0) { + switch (request) { + case reqInitialize: + result = 0; + break; + case 0: + break; + case 1: + result = SetupParamBlock(context); + if (!result) + result = Parser_StorePanels(context); + break; + case 2: + result = SetupParamBlock(context); + if (!result) { + result = SetupOptions(context); + if (!result) { + result = Parse(context); + if (!result) + result = StoreResults(context); + } + } + break; + } + } else { + if (failedCallback && result != 1) + fprintf(stderr, "Unexpected error in %s [%d]\n", failedCallback, result); + } + CWDonePluginRequest(context, result); + + return result; +} diff --git a/UCLTMain.c b/UCLTMain.c new file mode 100644 index 0000000..7da89af --- /dev/null +++ b/UCLTMain.c @@ -0,0 +1,384 @@ +#include "UCWInterface.h" + +static short CLT_dummymain() { + return 0; +} + +static short CLT_GetDropInFlags(const DropInFlags **flags, long *flagsSize) { + static const DropInFlags sFlags = { + kCurrentDropInFlagsVersion, + CWFOURCHAR('c','l','d','r'), + 7, + 0, + 0, + 12 + }; + *flags = &sFlags; + *flagsSize = sizeof(sFlags); + return 0; +} + +static short CLT_GetDropInName(const char **dropInName) { + static const char *sDropInName = "Command-Line Driver"; + *dropInName = sDropInName; + return 0; +} + +static short CLT_GetDisplayName(const char **displayName) { + static const char *sDisplayName = "Command-Line Driver"; + *displayName = sDisplayName; + return 0; +} + +static short CLT_GetPanelList(const CWPanelList **panelList) { + static const char *sPanelNames[4]; + static CWPanelList sPanelList = { + kCurrentCWPanelListVersion, + 4, + sPanelNames + }; + + sPanelNames[0] = "CmdLine Panel"; + if (clState.plugintype == CWDROPINCOMPILERTYPE) { + sPanelNames[1] = "CmdLine Compiler Panel"; + sPanelNames[2] = "CmdLine Linker Panel"; + sPanelList.count = 3; + } else { + sPanelNames[1] = "CmdLine Linker Panel"; + sPanelList.count = 2; + } + *panelList = &sPanelList; + return 0; +} + +static short CLT_GetTargetList(const CWTargetList **targetList) { + static CWDataType sCPU = CWFOURCHAR('*','*','*','*'); + static CWDataType sOS = CWFOURCHAR('*','*','*','*'); + static CWTargetList sTargetList = { + kCurrentCWTargetListVersion, + 1, + &sCPU, + 1, + &sOS + }; + *targetList = &sTargetList; + return 0; +} + +static short CLT_GetVersionInfo(const VersionInfo **versioninfo) { + static const VersionInfo vi = { + 3, 0, 0, 0 + }; + *versioninfo = &vi; + return 0; +} + +static short CLT_GetFileTypeMappings(const OSFileTypeMappingList **mappingList) { + static const OSFileTypeMapping ftmes[2] = { + {CWFOURCHAR('B','r','w','s'), "DubL", 4, 0, 0}, + {CWFOURCHAR('M','M','P','r'), "looc", 4, 0, 0} + }; + static const OSFileTypeMappingList ftml = { + 2, + ftmes + }; + *mappingList = &ftml; + return 0; +} + +static BasePluginCallbacks clcb = { + CLT_dummymain, + CLT_GetDropInFlags, + CLT_GetDisplayName, + CLT_GetDropInName, + CLT_GetPanelList, + 0, + 0, + CLT_GetVersionInfo, + CLT_GetFileTypeMappings +}; + +static int RegisterStaticCmdLinePlugin() { + return RegisterStaticPlugin(&clcb); +} + +const char *STR12000[100]; // TODO do me later + +static int RegisterCmdLineResources() { + return RegisterResource("Command-line strings", 12000, &STR12000); +} + +static int special_debug(unsigned char flag, char *) { + if (flag) { + SetupDebuggingTraps(); + return 1; + } else { + return 0; + } +} + +static int special_plugin_debug(unsigned char flag, char *) { + if (flag) { + clState.pluginDebug = 1; + return 1; + } else { + return clState.pluginDebug; + } +} + +static int special_stdout_base(unsigned char flag, char *) { + if (flag) { + return 1; + } else { + return clState.stdoutBase != 0; + } +} + +struct SpecialOption { + const char *name; + char **location; + int (*callback)(unsigned char a, char *b); +}; +static struct SpecialOption special_options[3] = { + {"", 0, special_debug}, + {"--plugin-debug", 0, special_plugin_debug}, + {"--stdout", /*TODO clState*/ 0, special_stdout_base} +}; + +void Main_PreParse(int *pArgc, char ***pArgv) { + int i; + struct SpecialOption *opt; + + if (*pArgc > 1) { + restart: + for (i = 0, opt = &special_options[0]; i < 3; i++, opt++) { + if (!strcmp(opt->name, (*pArgv)[1])) { + if (opt->location) { + *opt->location = (*pArgv)[2]; + opt->callback(1, *opt->location); + (*pArgv)[1] = (*pArgv)[0]; + (*pArgc)--; + (*pArgv)++; + + (*pArgv)[1] = (*pArgv)[0]; + (*pArgc)--; + (*pArgv)++; + } else { + opt->callback(1, 0); + (*pArgv)[1] = (*pArgv)[0]; + (*pArgc)--; + (*pArgv)++; + } + break; + } + } + + if ((*pArgc) > 1 && i < 3) + goto restart; + } +} + +void Main_PassSpecialArgs(void *unk1, void *unk2) { + int i; + struct SpecialOption *opt; + + for (i = 0; i < 3; i++) { + opt = &special_options[i]; + if (opt->callback(0, 0)) { + AppendArgumentList(unk1, unk2, opt->name); + if (opt->location) + AppendArgumentList(unk1, unk2, (*opt->location) ? *opt->location : ""); + } + } +} + +static int MainInitialized; +void *gProj; +PCmdLine optsCmdLine; +PCmdLineEnvir optsEnvir; +PCmdLineCompiler optsCompiler; +PCmdLineLinker optsLinker; + +int Main_Initialize(int argc, const char **argv) { + static char secret[8]; + char buf[256]; + + OS_InitProgram(&argc, &argv); + memset(&clState, 0, sizeof(CLState)); + special_options[0].name = secret; + secret[7] = 0; + secret[4] = 'b'; + secret[1] = '-'; + secret[5] = 'u'; + secret[2] = 'd'; + secret[0] = '-'; + secret[3] = 'e'; + secret[6] = 'g'; + + Main_PreParse(&argc, &argv); + clState.argc = argc; + clState.argv = argv; + // TODO more shite + + MainInitialized = 1; + return 0; +} + +int Main_Terminate(int code) { + if (MainInitialized) { + Plugins_Term(); + License_Terminate(); + Proj_Terminate(gProj); + IO_Terminate(); + MainInitialized = 0; + } + return code; +} + +static int Main_ParseCommandLine() { + // TODO: clState, Plugins, gTarg, ... +} + +static int Main_SetupParamBlock() { + // TODO: OS, PrefPanes, clState, ... + PrefPanelsChangedCallback(0); +} + +static int Main_ResolveProject() { + // TODO: Various project things +} + +static int UpdatePCmdLineFromVersion(const PCmdLine *oldVer, PCmdLine *newVer) { + static unsigned char warned; + short ver = oldVer->version; + *newVer = *oldVer; + + // TODO: clState + return 0; +} + +static int UpdatePCmdLineEnvirFromVersion(const PCmdLineEnvir *oldVer, PCmdLineEnvir *newVer) { + static unsigned char warned; + short ver = oldVer->version; + *newVer = *oldVer; + + // TODO: clState + return 0; +} + +static int UpdatePCmdLineCompilerFromVersion(const PCmdLineCompiler *oldVer, PCmdLineCompiler *newVer) { + static unsigned char warned; + short ver = oldVer->version; + *newVer = *oldVer; + + // TODO: clState + return 0; +} + +static int UpdatePCmdLineLinkerFromVersion(const PCmdLineLinker *oldVer, PCmdLineLinker *newVer) { + static unsigned char warned; + short ver = oldVer->version; + *newVer = *oldVer; + + // TODO: clState + return 0; +} + +static int UpdatePrefPanels(const char *name) { + PrefPanel *panel; + Handle handle; + + if (!name || !ustrcmp(name, "CmdLine Panel")) { + if ((panel = Prefs_FindPanel("CmdLine Panel")) && (handle = PrefPanel_GetHandle(panel))) { + if (name) { + if (!UpdatePCmdLineFromVersion((PCmdLine *) *handle, &optsCmdLine)) + return 0; + } + } else { + CLReportError(91, "CmdLine Panel"); + return 0; + } + } + + if (!name || !ustrcmp(name, "CmdLine Environment")) { + if ((panel = Prefs_FindPanel("CmdLine Environment")) && (handle = PrefPanel_GetHandle(panel))) { + if (name) { + if (!UpdatePCmdLineEnvirFromVersion((PCmdLineEnvir *) *handle, &optsEnvir)) + return 0; + } + } else { + CLReportError(91, "CmdLine Environment"); + return 0; + } + } + + if (!name || !ustrcmp(name, "CmdLine Compiler Panel")) { + if ((panel = Prefs_FindPanel("CmdLine Compiler Panel")) && (handle = PrefPanel_GetHandle(panel))) { + if (name) { + if (!UpdatePCmdLineCompilerFromVersion((PCmdLineCompiler *) *handle, &optsCompiler)) + return 0; + } + } else { + CLReportError(91, "CmdLine Compiler Panel"); + return 0; + } + } + + if (!name || !ustrcmp(name, "CmdLine Linker Panel")) { + if ((panel = Prefs_FindPanel("CmdLine Linker Panel")) && (handle = PrefPanel_GetHandle(panel))) { + if (name) { + if (!UpdatePCmdLineLinkerFromVersion((PCmdLineLinker *) *handle, &optsLinker)) + return 0; + } + } else { + CLReportError(91, "CmdLine Linker Panel"); + return 0; + } + } + + return 1; +} + +static int SetupCmdLinePrefPanels() { + int result; + + PrefPanelsChangedCallback = UpdatePrefPanels; + result = Prefs_AddPanel( + PrefPanel_New("CmdLine Environment", &optsEnvir, sizeof(PCmdLineEnvir)) + ); + result |= ( + Prefs_AddPanel(PrefPanel_New("CmdLine Panel", 0, sizeof(PCmdLine))) + && Prefs_AddPanel(PrefPanel_New("CmdLine Compiler Panel", 0, sizeof(PCmdLineCompiler))) + && Prefs_AddPanel(PrefPanel_New("CmdLine Linker Panel", 0, sizeof(PCmdLineLinker))) + ); + + return result; +} + +static int Main_SetupContext() { + // TODO Target, Plugins, clState + return 1; +} + +jmp_buf exit_program; + +int Main_Driver() { + volatile int result; + + result = setjmp(exit_program); + if (!result) { + if (!SetupCmdLinePrefPanels()) + CLFatalError("Could not initialize preferences"); + + Main_SetupContext(); + if (!(result = Main_ParseCommandLine())) { + if (!(result = Main_SetupParamBlock())) + result = Main_ResolveProject(); + } + } else { + result = 1; + } + + return result; +} + @@ -0,0 +1,110 @@ +#include "UCWInterface.h" + +// 1C40 to 2008 + +// TODO move me +// TODO move me + +// unsure where this is, may be here, maybe not? +extern char cmdline_build_date[32]; +extern char cmdline_build_time[32]; + +int main(int argc, const char **argv) { + unsigned long cpu; + unsigned long os; + unsigned long language; + unsigned long plugintype; + unsigned long style; + int result; + + if (CmdLine_Initialize(argc, argv, CMDLINE_BUILD_DATE, CMDLINE_BUILD_TIME)) + exit(1); + + if (!RegisterStaticParserResources() || !RegisterStaticTargetResources()) { + fprintf(stderr, "\nFATAL ERROR: Could not initialize resource strings\n"); + exit(1); + } + + if (!RegisterStaticParserPlugins() || !RegisterStaticTargetPlugins()) { + fprintf(stderr, "\nFATAL ERROR: Could not initialize built-in plugins\n"); + exit(1); + } + + if (!RegisterStaticParserToolInfo()) { + fprintf(stderr, "\nFATAL ERROR: Could not initialize options\n"); + exit(1); + } + + GetStaticTarget(&cpu, &os); + SetBuildTarget(cpu, os); + GetStaticPluginType(&language, &plugintype); + SetPluginType(language, plugintype); + GetStaticParserPluginType(&style); + SetParserType(style); + + result = CmdLine_Driver(); + if (result) { + if (result == 2) + fprintf(stderr, "\nUser break, cancelled...\n"); + else + fprintf(stderr, "\nErrors caused tool to abort.\n"); + } + CmdLine_Terminate(result); + return result; +} + +int RegisterResource(const char *name, short index, void *data) { + Handle r; + + if (data == 0) { + r = GetResource('STR#', index); + if (r == 0) { + CLFatalError("Resource ('STR#',%d) '%s' not found in executable\n", index, name); + return 0; + } + ReleaseResource(r); + return 1; + } else { + return Res_AddResource(name, index, data); + } +} + +int RegisterStaticPlugin(const BasePluginCallbacks *cb) { + return Plugins_Add(Plugin_New(cb, 0, 0)); +} + +int RegisterStaticCompilerLinkerPlugin(const BasePluginCallbacks *cb, void *b) { + return Plugins_Add(Plugin_New(cb, b, 0)); +} + +int RegisterStaticParserPlugin(const BasePluginCallbacks *cb, void *b) { + return Plugins_Add(Plugin_New(cb, 0, b)); +} + +void SetBuildTarget(CWDataType cpu, CWDataType os) { + clState.cpu = cpu; + clState.os = os; +} + +void SetParserType(CWDataType style) { + clState.style = style; +} + +void SetPluginType(CWDataType language, CWDataType plugintype) { + clState.language = language; + clState.plugintype = plugintype; +} + +int CmdLine_Initialize(int argc, const char **argv, const char *buildDate, const char *buildTime) { + strncpy(cmdline_build_date, buildDate, sizeof(cmdline_build_date)); + strncpy(cmdline_build_time, buildTime, sizeof(cmdline_build_time)); + return Main_Initialize(argc, argv); +} + +int CmdLine_Driver() { + return Main_Driver(); +} + +int CmdLine_Terminate(int code) { + return Main_Terminate(code); +} diff --git a/mwcc_decomp.h b/mwcc_decomp.h new file mode 100644 index 0000000..f0bd518 --- /dev/null +++ b/mwcc_decomp.h @@ -0,0 +1,1918 @@ +#pragma once +#include <MacHeadersMach-O> +#define macintosh +#include "sdk_hdrs/CompilerMapping.h" +#include "sdk_hdrs/DropInCompilerLinker.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/********************************/ +/* OS Garbage */ +typedef struct OSPathSpec { + char s[256]; +} OSPathSpec; +typedef struct OSNameSpec { + char s[64]; +} OSNameSpec; +typedef struct OSSpec { + OSPathSpec path; + OSNameSpec name; +} OSSpec; +typedef struct OSHandle { + void *addr; + unsigned long used; + unsigned long size; +} OSHandle; +typedef struct { + OSSpec spec; + OSHandle hand; + unsigned char loaded; + unsigned char changed; + unsigned char writeable; +} OSFileHandle; // assumed name + +/********************************/ +/* Option Fuckery */ +#ifdef __MWERKS__ +#pragma options align=packed +#endif +typedef struct PARAM_T { + char which; + char flags; + char *myname; + struct PARAM_T *next; +} PARAM_T; +typedef struct MASK_T { + char which; + char flags; + char *myname; + PARAM_T *next; + char size; + unsigned long ormask; + unsigned long andmask; + void *num; +} MASK_T; +typedef struct STRING_T { + char which; + char flags; + char *myname; + PARAM_T *next; + short maxlen; + unsigned char pstring; + char *str; +} STRING_T; +typedef struct SET_T { + char which; + char flags; + char *myname; + PARAM_T *next; + char size; + unsigned long value; + char *num; +} SET_T; +typedef struct SETSTRING_T { + char which; + char flags; + char *myname; + PARAM_T *next; + char *value; + char pstring; + void *var; +} SETSTRING_T; +typedef struct GENERIC_T { + char which; + char flags; + char *myname; + PARAM_T *next; + void (*parse)(); // TODO missing sig + void *var; + char *help; +} GENERIC_T; +typedef struct SETTING_T { + char which; + char flags; + char *myname; + PARAM_T *next; + void (*parse)(); // TODO missing sig + char *valuename; +} SETTING_T; +typedef struct TOGGLE_T { + char which; + char flags; + char *myname; + PARAM_T *next; + char size; + unsigned long mask; + void *num; +} TOGGLE_T; +typedef struct NUM_T { + char which; + char flags; + char *myname; + PARAM_T *next; + char size; + char fit; + unsigned long lo; + unsigned long hi; + void *num; +} NUM_T; +typedef struct FILEPATH_T { + char which; + char flags; + char *myname; + PARAM_T *next; + char fflags; + char *defaultstr; + void *filename; + int maxlen; +} FILEPATH_T; +typedef struct IFARG_T { + char which; + char flags; + char *myname; + PARAM_T *next; + PARAM_T *parg; + char *helpa; + PARAM_T *pnone; + char *helpn; +} IFARG_T; +typedef struct ONOFF_T { + char which; + char flags; + char *myname; + PARAM_T *next; + unsigned char *var; +} ONOFF_T; +typedef struct OFFON_T { + char which; + char flags; + char *myname; + PARAM_T *next; + unsigned char *var; +} OFFON_T; +typedef struct FTYPE_T { + char which; + char flags; + char *myname; + PARAM_T *next; + unsigned long *fc; + unsigned char iscreator; +} FTYPE_T; +typedef struct OptionList { + char *help; + int flags; + struct Option **list; +} OptionList; +typedef struct Option { + char *names; + int avail; + PARAM_T *param; + OptionList *sub; + OptionList *conflicts; + char *help; +} Option; +enum { + HELPFLAGS_1 = 1, + HELPFLAGS_IGNORED = 2, + HELPFLAGS_OBSOLETE = 4, + HELPFLAGS_DEPRECATED = 8, + HELPFLAGS_SECRET = 0x10, + HELPFLAGS_MEANINGLESS = 0x20, + HELPFLAGS_COMPATIBLE = 0x40, + HELPFLAGS_NORMAL = 0x80, // andmask = 0xE? + HELPFLAGS_SPACES = 0x100, + HELPFLAGS_TOOL = 0x200, + HELPFLAGS_TOOL_THIS = 0x400, + HELPFLAGS_TOOL_OTHER = 0x800, + HELPFLAGS_TOOL_BOTH = 0xC00, + HELPFLAGS_1000 = 0x1000, + HELPFLAGS_2000 = 0x2000, + HELPFLAGS_USAGE = 0x4000, + HELPFLAGS_8000 = 0x8000, + HELPFLAGS_10000 = 0x10000, + HELPFLAGS_20000 = 0x20000, + HELPFLAGS_40000 = 0x40000, + HELPFLAGS_80000 = 0x80000, + HELPFLAGS_100000 = 0x100000, + HELPFLAGS_200000 = 0x200000, + HELPFLAGS_400000 = 0x400000, + HELPFLAGS_700000 = 0x700000, + HELPFLAGS_800000 = 0x800000, + HELPFLAGS_801828 = 0x801828, + HELPFLAGS_1000000 = 0x1000000, + HELPFLAGS_2000000 = 0x2000000, + HELPFLAGS_4000000 = 0x4000000, + HELPFLAGS_8000000 = 0x8000000, + HELPFLAGS_10000000 = 0x10000000, + HELPFLAGS_20000000 = 0x20000000, + HELPFLAGS_40000000 = 0x40000000, + HELPFLAGS_80000000 = 0x80000000 +}; +enum { + OTF_GLOBAL = 1, + OTF2 = 2, + OTF_CASED = 4, + OTF_OBSOLETE = 8, + OTF_SUBSTITUTED = 0x10, + OTF_DEPRECATED = 0x20, + OTF_TOOL_LINKER = 0x40, + OTF_TOOL_DISASSEMBLER = 0x80, + OTF_TOOL_COMPILER = 0x100, + OTF_TOOL_MASK = OTF_TOOL_LINKER | OTF_TOOL_DISASSEMBLER | OTF_TOOL_COMPILER, + OTF200 = 0x200, + OTF400 = 0x400, + OTF700 = 0x700, + OTF_IGNORED = 0x800, + OTFC00 = 0xC00, + OTF_SECRET = 0x1000, + OTF2000 = 0x2000, + OTF_COMPATIBILITY = 0x4000, + OTF8000 = 0x8000, + OTF10000 = 0x10000, + OTF20000 = 0x20000, + OTF40000 = 0x40000, + OTF_WARNING = 0x80000, + OTF_SLFLAGS_8 = 0x100000, + OTF_SLFLAGS_10 = 0x200000, + OTF_SLFLAGS_20 = 0x400000, + OTF_SLFLAGS_MASK = OTF_SLFLAGS_8 | OTF_SLFLAGS_10 | OTF_SLFLAGS_20, + OTF_MEANINGLESS = 0x800000, + OTF_ALL_HIDDEN_BY_DEFAULT = OTF_OBSOLETE | OTF_DEPRECATED | OTF_IGNORED | OTF_SECRET | OTF_MEANINGLESS, + OTF1000000 = 0x1000000, + OTF2000000 = 0x2000000, + OTF4000000 = 0x4000000, + OTF8000000 = 0x8000000, + OTF10000000 = 0x10000000, + OTF20000000 = 0x20000000, + OTF40000000 = 0x40000000, + OTF80000000 = 0x80000000 +}; + +enum { + PARAMWHICH_None = 0, + PARAMWHICH_FTypeCreator = 1, + PARAMWHICH_FilePath = 2, + PARAMWHICH_Number = 3, + PARAMWHICH_String = 4, + PARAMWHICH_5 = 5, + PARAMWHICH_6 = 6, + PARAMWHICH_OnOff = 7, + PARAMWHICH_OffOn = 8, + PARAMWHICH_Mask = 9, + PARAMWHICH_Toggle = 0xA, + PARAMWHICH_Set = 0xB, + PARAMWHICH_SetString = 0xC, + PARAMWHICH_Generic = 0xD, + PARAMWHICH_IfArg = 0xE, + PARAMWHICH_Setting = 0xF +}; +enum { + PARAMFLAGS_1 = 1, + PARAMFLAGS_2 = 2, + PARAMFLAGS_3 = 3, + PARAMFLAGS_4 = 4, + PARAMFLAGS_8 = 8 +}; +enum { + SLFLAGS_1 = 1, + SLFLAGS_2 = 2, + SLFLAGS_4 = 4, // displays =... + SLFLAGS_8 = 8, // displays [no] -- produces e.g. [no]err[or] | [no]iserr[or], [no]implicit[conv] + SLFLAGS_10 = 0x10, // displays [-] + SLFLAGS_20 = 0x20, // displays [no-] + SLFLAGS_40 = 0x40 +}; +enum { + LISTFLAGS_NONE = 0, + LISTFLAGS_4 = 4, + LISTFLAGS_COMPILER = 0x100, + LISTFLAGS_LINKER = 0x200, + LISTFLAGS_DISASSEMBLER = 0x400, + LISTFLAGS_TOOL_MASK = LISTFLAGS_COMPILER | LISTFLAGS_LINKER | LISTFLAGS_DISASSEMBLER +}; +#ifdef __MWERKS__ +#pragma options align=reset +#endif + + +struct IDEAccessPath { + FSSpec pathSpec; + unsigned char recursive; + long subdirectoryCount; + FSSpec *subdirectories; +}; + +struct IDEAccessPathList { + long userPathCount; + struct IDEAccessPath *userPaths; + long systemPathCount; + struct IDEAccessPath *systemPaths; + unsigned char alwaysSearchUserPaths; + unsigned char convertPaths; +}; + +#ifdef __MWERKS__ +#pragma options align=mac68k +#endif +typedef struct CWObjectFlags { + short version; + long flags; + const char *objFileExt; + const char *brsFileExt; + const char *ppFileExt; + const char *disFileExt; + const char *depFileExt; + const char *pchFileExt; + CWDataType objFileCreator; + CWDataType objFileType; + CWDataType brsFileCreator; + CWDataType brsFileType; + CWDataType ppFileCreator; + CWDataType ppFileType; + CWDataType disFileCreator; + CWDataType disFileType; + CWDataType depFileCreator; + CWDataType depFileType; +} CWObjectFlags; +#ifdef __MWERKS__ +#pragma options align=reset +#endif + +struct CW_BasePluginCallbacks { + void (*cbGetFileInfo)(); + void (*cbFindAndLoadFile)(); + void (*cbGetFileText)(); + void (*cbReleaseFileText)(); + void (*cbGetSegmentInfo)(); + void (*cbGetOverlay1GroupInfo)(); + void (*cbGetOverlay1Info)(); + void (*cbGetOverlay1FileInfo)(); + void (*cbReportMessage)(); + void (*cbAlert)(); + void (*cbShowStatus)(); + void (*cbUserBreak)(); + void (*cbGetNamedPreferences)(); + void (*cbStorePluginData)(); + void (*cbGetPluginData)(); + void (*cbSetModDate)(); + void (*cbAddProjectEntry)(); + void (*cbCreateNewTextDocument)(); + void (*cbAllocateMemory)(); + void (*cbFreeMemory)(); + void (*cbAllocMemHandle)(); + void (*cbFreeMemHandle)(); + void (*cbGetMemHandleSize)(); + void (*cbResizeMemHandle)(); + void (*cbLockMemHandle)(); + void (*cbUnlockMemHandle)(); + void *cbInternal[8]; + void (*cbGetTargetName)(); + void (*cbCacheAccessPathList)(); + void (*cbPreDialog)(); + void (*cbPostDialog)(); + void (*cbPreFileAction)(); + void (*cbPostFileAction)(); + void (*cbCheckoutLicense)(); + void (*cbCheckinLicense)(); + void (*cbResolveRelativePath)(); +}; + +struct CWPluginPrivateContext { + long request; + long apiVersion; + void *shellContext; + void *pluginStorage; + FSSpec projectFile; + FSSpec outputFileDirectory; + long shellSignature; + long pluginType; + long numFiles; + long numOverlayGroups; + short callbackOSError; + short pluginOSError; + CWIDEInfo *shellInfo; + struct IDEAccessPathList *accessPathList; + long dontEatEvents; + struct FSSpec *targetDataDirectorySpec; + long reserved[17]; + struct CW_BasePluginCallbacks *callbacks; +}; + +// Pref panels +#ifdef __MWERKS__ +#pragma options align=mac68k +#endif +typedef struct PCmdLine { + short version; + short state; + short stages; + short toDisk; + short outNameOwner; + unsigned char dryRun; + unsigned char debugInfo; + short verbose; + unsigned char showLines; + unsigned char timeWorking; + unsigned char noWarnings; + unsigned char warningsAreErrors; + unsigned short maxErrors; + unsigned short maxWarnings; + short msgStyle; + unsigned char noWrapOutput; + unsigned char stderr2stdout; + unsigned char noCmdLineWarnings; +} PCmdLine; +typedef struct PCmdLineCompiler { + short version; + unsigned char noSysPath; + unsigned char noFail; + short includeSearch; + char linkerName[64]; + char objFileExt[15]; + char brsFileExt[15]; + char ppFileExt[15]; + char disFileExt[15]; + char depFileExt[15]; + char pchFileExt[15]; + CWDataType objFileCreator; + CWDataType objFileType; + CWDataType brsFileCreator; + CWDataType brsFileType; + CWDataType ppFileCreator; + CWDataType ppFileType; + CWDataType disFileCreator; + CWDataType disFileType; + CWDataType depFileCreator; + CWDataType depFileType; + unsigned char compileIgnored; + unsigned char relPathInOutputDir; + unsigned char browserEnabled; + unsigned char depsOnlyUserFiles; + char outMakefile[256]; + char forcePrecompile; + unsigned char ignoreMissingFiles; + unsigned char printHeaderNames; + char sbmState; + char sbmPath[256]; + unsigned char canonicalIncludes; + unsigned char keepObjects; +} PCmdLineCompiler; +typedef struct PCmdLineLinker { + short version; + unsigned char callPreLinker; + unsigned char callPostLinker; + unsigned char keepLinkerOutput; + unsigned char callLinker; +} PCmdLineLinker; +typedef struct PCmdLineEnvir { + short version; + short cols; + short rows; + unsigned char underIDE; +} PCmdLineEnvir; +typedef struct PBackEnd { + short version; + unsigned char structalignment; + unsigned char tracebacktables; + unsigned char processor; + unsigned char readonlystrings; + unsigned char profiler; + unsigned char fpcontract; + unsigned char schedule; + unsigned char peephole; + unsigned char processorspecific; + unsigned char altivec; + unsigned char vrsave; + unsigned char autovectorize; + unsigned char usebuiltins; + unsigned char pic; + unsigned char dynamic; + unsigned char common; + unsigned char implicit_templates; + unsigned char reserved[3]; +} PBackEnd; +typedef struct PDisassembler { + short version; + unsigned char showcode; + unsigned char extended; + unsigned char mix; + unsigned char nohex; + unsigned char showdata; + unsigned char showexceptions; + unsigned char showsym; + unsigned char shownames; +} PDisassembler; +typedef struct PMachOLinker { + short version; + unsigned char linksym; + unsigned char symfullpath; + unsigned char suppresswarn; + unsigned char linkmap; + unsigned char multisymerror; + unsigned char whatfileloaded; + unsigned char whyfileloaded; + unsigned char use_objectivec_semantics; + char undefinedsymbols; + char readonlyrelocs; + char reserved_value1; + char reserved_value2; + short exports; + short reserved_short1; + unsigned long currentversion; + unsigned long compatibleversion; + long reserved_long1; + char mainname[64]; + unsigned char prebind; + unsigned char dead_strip; + unsigned char twolevel_namespace; + unsigned char strip_debug_symbols; +} PMachOLinker; +typedef struct PMachOProject { + short version; + short type; + unsigned char outfile[64]; + long filecreator; + long filetype; + long stacksize; + long stackaddress; + unsigned long reserved1; + unsigned long reserved2; + unsigned long reserved3; + unsigned long reserved4; + unsigned long reserved5; + unsigned long reserved6; + unsigned long reserved7; + unsigned long reserved8; + unsigned long reserved9; + unsigned long reserved10; + unsigned long reserved11; + unsigned long reserved12; + unsigned long reserved13; + unsigned long reserved14; + unsigned long reserved15; + unsigned long reserved16; + unsigned long reserved17; + unsigned long reserved18; + unsigned long reserved19; + unsigned long reserved20; + unsigned char flatrsrc; + unsigned char filler1; + unsigned char filler2; + unsigned char filler3; + unsigned char separateflatfile[64]; + unsigned char installpath[256]; +} PMachOProject; +typedef struct { + short version; + unsigned char userSetCreator; + unsigned char userSetType; + unsigned char gPrintMapToStdOutput; + unsigned char mapfilename[256]; + unsigned char symfilename[256]; +} PCLTExtras; +#ifdef __MWERKS__ +#pragma options align=reset +#endif + +typedef struct CWCommandLineArgs { + int argc; + char **argv; + char **envp; +} CWCommandLineArgs; + +typedef struct VersionInfo { + unsigned short major; + unsigned short minor; + unsigned short patch; + unsigned short build; +} VersionInfo; + +typedef struct CLPluginInfo { + unsigned long plugintype; + unsigned long language; + long dropinflags; + char *version; + unsigned char storeCommandLine; +} CLPluginInfo; + +typedef struct ToolVersionInfo { + char *company; + char *product; + char *tool; + char *copyright; + char *version; +} ToolVersionInfo; + +// may not actually be named this +struct ParseOptsType { + CWPluginContext context; + char helpKey[64]; + long helpFlags; + unsigned short ioCols; + unsigned short ioRows; + CWCommandLineArgs *args; + ToolVersionInfo *toolVersion; + int numPlugins; + CLPluginInfo *plugins; + int numPanels; + char **panelNames; + unsigned long cpu; + unsigned long os; + char lastoutputname[256]; + long currentSegment; + long currentOverlayGroup; + long currentOverlay; + int possibleFiles; + int userSpecifiedFiles; + int unusedFiles; + unsigned char hadAnyOutput; + unsigned char hadErrors; + unsigned char showHelp; + unsigned char underIDE; + unsigned char alwaysUsePaths; + unsigned char noOptions; + unsigned char printedVersion; + unsigned char passingArgs; + unsigned char disToFile; + unsigned char ppToFile; + unsigned char initBefore; + unsigned char weakImport; + unsigned char mergeIntoOutput; + unsigned char success; + unsigned char ignoreUnknown; + unsigned char unused[2]; +}; + +// assumed name +typedef struct CLState { + int argc; + const char **argv; + CWDataType cpu; + CWDataType os; + CWDataType plugintype; + CWDataType language; + CWDataType style; + OSSpec programPath; + const char *programName; + short numWarnings; + short numErrors; + Boolean pluginDebug; + Boolean userBreak; + Boolean reachedWarningThreshold; + Boolean reachedErrorThreshold; + OSSpec makefileSpec; + OSPathSpec sbmPathSpec; + OSHandle browseHandle; + const char *stdoutBase; + int appendToStdoutBase; +} CLState; + +typedef struct OSFileTypeMapping { + CWDataType mactype; + const char *magic; + char length; + const char *mimetype; + char executable; // not sure why this is rearranged +} OSFileTypeMapping; + +typedef struct OSFileTypeMappingList { + short numMappings; + const OSFileTypeMapping *mappings; +} OSFileTypeMappingList; + +typedef struct BasePluginCallbacks { + short (*main)(); + short (*GetDropInFlags)(const DropInFlags **flags, long *flagsSize); + short (*GetDisplayName)(const char **displayName); + short (*GetDropInName)(const char **dropInName); + short (*GetPanelList)(const CWPanelList **panelList); + short (*GetFamilyList)(const CWFamilyList **familyList); + short (*GetHelpInfo)(const CWHelpInfo **helpInfo); + short (*GetVersionInfo)(const VersionInfo **versionInfo); + short (*GetFileTypeMappings)(const OSFileTypeMappingList **mappingList); +} BasePluginCallbacks; + +typedef struct CompilerLinkerPluginCallbacks { + short (*GetTargetList)(const struct CWTargetList **targetList); + short (*GetDefaultMappingList)(); + short (*Unmangle)(); + short (*BrSymbolEntryPoint)(); + short (*GetObjectFlags)(); + short (*WriteObjectFile)(); +} CompilerLinkerPluginCallbacks; + +typedef struct ParserPluginCallbacks { + short (*SupportsPlugin)(); + short (*SupportsPanels)(); +} ParserPluginCallbacks; + +typedef struct { + char *name; + void *ptr; + long size; +} PrefDataPanel; // assumed name + +typedef struct { + CWDataType TYPE; + CWDataType LANG; + CWDataType CPU; + CWDataType OS; + int numPrefPanels; + char **prefPanels; + char *toolInfo; + char *copyright; + int numOptionLists; + OptionList **optionLists; + int numPrefDataPanels; + PrefDataPanel *prefDataPanels; + int (*PreParse)(); // sig? + int (*MidParse)(); // sig? + int (*PostParse)(); // sig? +} ParserTool; // assumed name + +typedef struct PrefPanel { // assumed name + char *name; + Handle data; + Handle workData; + struct PrefPanel *next; +} PrefPanel; // assumed name + +// CLAccessPaths +typedef struct Paths { + struct Path **array; + unsigned short capacity; + unsigned short count; +} Paths; // assumed name +typedef struct Frameworks { + struct Framework **array; + unsigned short capacity; + unsigned short count; +} Frameworks; // assumed name +typedef struct Path { + OSPathSpec *spec; + Paths *subpaths; + int x8; + short xC; +} Path; // assumed name +typedef struct Framework { + OSSpec frameworkSpec; + OSPathSpec name; + OSPathSpec version; + Path *containingPath; + Boolean flag344; +} Framework; // assumed name + +// CLFiles +typedef struct File { + struct File *next; + int index; + // TODO fill me up +} File; +typedef struct Files { + File *files; + int count; +} Files; // assumed name +typedef struct VFile { + char name[32]; + Handle hand; + struct VFile *next; +} VFile; // assumed name + +// CLOverlays +typedef struct Overlay { + char name[256]; + int *fileIDList; + int fileCount; + int fileCapacity; + struct Overlay *next; +} Overlay; // assumed name +typedef struct OvlGroup { + char name[256]; + CWAddr64 addr; + Overlay *overlays; + Overlay *lastOverlay; + int overlayCount; + struct OvlGroup *next; +} OvlGroup; // assumed name +typedef struct Overlays { + OvlGroup *groups; + OvlGroup *lastGroup; +} Overlays; // assumed name + +// CLSegs +typedef struct Segment { + char name[32]; + short attributes; +} Segment; // assumed name +typedef struct Segments { + Segment **array; + unsigned short capacity; + unsigned short count; +} Segments; // assumed name + +// CLDependencies +typedef struct Incls { + struct Target *target; + // ... + Paths *paths; +} Incls; // assumed name +typedef struct Deps { + int x0; + int x4; + int x8; + Incls *incls; +} Deps; // assumed name + +// CLTarg +typedef struct Target { + int count0; + int count4; + int count8; + int countC; + CWTargetInfo *targetInfo; + Segments segments; + Overlays overlays; + int x28; + Files accessPathFiles; + Files files2; + Incls incls; + Paths systemPaths; + Paths userPaths; + CWDataType language; + CWDataType cpu; + CWDataType os; + char name[64]; + struct Plugin *preLinker; + struct Plugin *linker; + struct Plugin *postLinker; + unsigned long preLinkerFlags; + unsigned long linkerFlags; + unsigned long postLinkerFlags; + OSPathSpec cwd; + VFile *vfiles; + struct Target *next; +} Target; // assumed name + +typedef struct Plugin { + BasePluginCallbacks *cb; + CompilerLinkerPluginCallbacks *clcb; + ParserPluginCallbacks *pcb; + void *context; + char *versionInfoASCII; + struct Plugin *next; +} Plugin; + +typedef struct Token { + int x0; + void *x4; +} Token; + +/********************************/ +/* UMain.c */ +extern int main(int argc, const char **argv); +extern int RegisterResource(const char *name, short index, void *data); +extern int RegisterStaticPlugin(const BasePluginCallbacks *cb); +extern int RegisterStaticCompilerLinkerPlugin(const BasePluginCallbacks *cb, void *b); +extern int RegisterStaticParserPlugin(const BasePluginCallbacks *cb, void *b); +extern void SetBuildTarget(CWDataType cpu, CWDataType os); +extern void SetParserType(CWDataType style); +extern void SetPluginType(CWDataType language, CWDataType plugintype); +extern int CmdLine_Initialize(int argc, const char **argv, const char *buildDate, const char *buildTime); +extern int CmdLine_Driver(); +extern int CmdLine_Terminate(int code); + +/********************************/ +/* UCLTMain.c */ +extern void Main_PreParse(int *pArgc, char ***pArgv); +extern void Main_PassSpecialArgs(void *unk1, void *unk2); +extern int Main_Initialize(int argc, const char **argv); +extern int Main_Terminate(int code); +extern int Main_Driver(); + +/********************************/ +/* Resources.c */ + +/********************************/ +/* ?? CL Errors */ +//static void CLGetErrorString(short errid, char *buffer); +//static void CLMessageReporter(int kind, short errid, va_list ap); +extern void CLReportError(short errid, ...); +extern void CLReportWarning(short errid, ...); +extern void CLReport(short errid, ...); +extern void CLReportOSError(short errid, long err, ...); +extern void CLReportCError(short errid, long err, ...); +extern void CLInternalError(const char *filename, int linenum, const char *format, ...); +extern void CLFatalError(const char *format, ...); + +/********************************/ +/* ?? Res */ +extern void Res_Initialize(); +extern void Res_AddResource(const char *name, short id, const void *data); +extern const char *Res_GetResource(short listIndex, short strId); +extern void Res_Cleanup(); + +/********************************/ +/* CLPlugins.c */ +//static void GetToolVersionInfo(); +extern const ToolVersionInfo *Plugin_GetToolVersionInfo(); +//static const char *Plugin_GetDisplayName(Plugin *plugin); +extern const char *Plugin_GetDropInName(Plugin *plugin); +extern VersionInfo *Plugin_GetVersionInfo(Plugin *plugin); +extern const char *Plugin_GetVersionInfoASCII(Plugin *plugin); +extern DropInFlags *Plugin_GetDropInFlags(Plugin *plugin); +extern CWDataType Plugin_GetPluginType(Plugin *plugin); +extern const CWTargetList *Plugin_CL_GetTargetList(Plugin *plugin); +extern const CWPanelList *Plugin_GetPanelList(Plugin *plugin); +extern const CWExtMapList *Plugin_CL_GetExtMapList(Plugin *plugin); +extern const OSFileTypeMappingList *Plugin_GetFileTypeMappingList(Plugin *plugin); +extern const CWObjectFlags *Plugin_CL_GetObjectFlags(Plugin *plugin); +extern Boolean Plugin_MatchesName(Plugin *plugin, const char *name); +extern Boolean Plugin_CL_MatchesTarget(Plugin *plugin, CWDataType cpu, CWDataType os, Boolean flag); +extern Boolean Plugins_CL_HaveMatchingTargets(Plugin *a, Plugin *b, Boolean flag); +//static CL_MatchesExtMapping(CWExtensionMapping *em, CWDataType type, const char *extension, Boolean flag); +extern Boolean Plugin_CL_MatchesFileType(Plugin *plugin, CWDataType type, const char *extension, Boolean flag); +extern Boolean Plugin_MatchesType(Plugin *plugin, CWDataType plugintype, CWDataType edit_language, Boolean flag); +extern Boolean Plugin_Pr_MatchesPlugin(Plugin *plugin, void *unk1, void *unk2, void *unk3); // fixme +extern Boolean Plugin_Pr_MatchesPanels(Plugin *plugin, void *unk1, void *unk2); // fixme +extern Boolean Plugin_CL_WriteObjectFile(Plugin *plugin, FSSpec *fss1, FSSpec *fss2, CWDataType creator, CWDataType filetype, Handle h); +extern Boolean Plugin_CL_GetCompilerMapping(Plugin *plugin, CWDataType type, const char *extension, CompilerMappingFlags *flags); +//static Boolean SupportedPlugin(Plugin *plugin, const char **errmsg); +//static Boolean VerifyPanels(Plugin *plugin); +extern Plugin *Plugin_New(const BasePluginCallbacks *cb, const CompilerLinkerPluginCallbacks *clcb, const ParserPluginCallbacks *pcb); +extern void Plugin_Free(Plugin *plugin); +extern int Plugin_VerifyPanels(Plugin *plugin); +extern void Plugins_Init(); +extern void Plugins_Term(); +extern int Plugins_Add(Plugin *plugin); +extern Plugin *Plugins_MatchName(Plugin *first, const char *name); +extern Plugin *Plugins_CL_MatchTarget(Plugin *first, CWDataType cpu, CWDataType os, CWDataType plugintype, CWDataType edit_language); +extern Plugin *Plugins_CL_MatchFileType(Plugin *first, CWDataType type, const char *extension, Boolean flag); +extern Plugin *Plugins_GetPluginForFile(Plugin *first, CWDataType plugintype, CWDataType cpu, CWDataType os, CWDataType type, const char *extension); +extern Plugin *Plugins_GetLinker(Plugin *first, CWDataType cpu, CWDataType os); +extern Plugin *Plugins_GetPreLinker(Plugin *first, CWDataType cpu, CWDataType os); +extern Plugin *Plugins_GetPostLinker(Plugin *first, CWDataType cpu, CWDataType os); +extern Plugin *Plugins_GetParserForPlugin(...); // TODO fixme args +extern Plugin *Plugins_GetCompilerForLinker(Plugin *first, Plugin *linker, CWDataType type, const char *extension, CWDataType edit_language); +extern Boolean Plugins_GetPluginList(Plugin *first, int *count, void **list); // TODO fixme define list struct +extern Boolean Plugins_GetPrefPanelUnion(Plugin *first, int *count, void **list); // TODO fixme define struct +extern Boolean Plugin_AddFileTypeMappings(Plugin *plugin, void *unk); +extern Boolean Plugins_AddFileTypeMappingsForTarget(Plugin *first, void *unk, CWDataType cpu, CWDataType os); +extern short Plugin_Call(Plugin *plugin, void *context); + +/********************************/ +/* ?? parser_cb */ + +/********************************/ +/* CLIO.c */ + +/********************************/ +/* CLToolExec.c */ + +/********************************/ +/* OS TU 1 */ +typedef struct uOSTypePair { // unknown name + short a; + short b; +} uOSTypePair; +extern const char *OS_GetErrText(int errnum); +extern int OS_InitProgram(int *pArgc, const char ***pArgv); +extern int OS_TermProgram(); +extern int OS_Create(const OSSpec *spec, const uOSTypePair *type); +extern int OS_Status(const OSSpec *spec); +extern int OS_GetFileType(const OSSpec *spec, uOSTypePair *type); +extern int OS_SetFileType(const OSSpec *spec, const uOSTypePair *type); +extern int OS_GetFileTime(const OSSpec *spec, time_t *ctime, time_t *mtime); +extern int OS_SetFileTime(const OSSpec *spec, const time_t *ctime, const time_t *mtime); +extern int OS_Open(const OSSpec *spec, unsigned short mode, int *pRef); +extern int OS_Write(int ref, const void *data, long *pLen); +extern int OS_Read(int ref, void *data, long *pLen); +extern int OS_Seek(int ref, unsigned short how, long offset); +extern int OS_Tell(int ref, long *pOffset); +extern int OS_Close(int ref); +extern int OS_GetSize(int ref, long *pSize); +extern int OS_SetSize(int ref, long size); +extern int OS_Delete(const OSSpec *spec); +extern int OS_Rename(const OSSpec *a, const OSSpec *b); +extern int OS_Mkdir(const OSSpec *spec); +extern int OS_Rmdir(const OSPathSpec *spec); +extern int OS_Chdir(const OSPathSpec *spec); +extern int OS_GetCWD(OSPathSpec *spec); +extern int OS_Execute(); // TODO figure out the args for this properly +extern int OS_IsLegalPath(const char *str); +extern int OS_IsFullPath(const char *str); +extern char *OS_GetDirPtr(OSPathSpec *spec); +//extern int OS_CompactPath(const char *spec, char *dest); +extern int OS_EqualPath(const char *a, const char *b); +extern int OS_CanonPath(const char *src, char *dest); +extern int OS_MakeSpec(const char *path, OSSpec *spec, Boolean *pFlag); +extern int OS_MakeFileSpec(const char *path, OSSpec *spec); +extern int OS_MakePathSpec(const char *a, const char *b, OSPathSpec *spec); +extern int OS_MakeNameSpec(const char *src, OSNameSpec *spec); +extern int OS_GetRootSpec(OSPathSpec *spec); +extern char *OS_SpecToString(const OSSpec *spec, char *output, int maxlen); +extern char *OS_PathSpecToString(const OSPathSpec *spec, char *output, int maxlen); +extern char *OS_NameSpecToString(const OSNameSpec *spec, char *output, int maxlen); +extern int OS_SizeOfPathSpec(const OSPathSpec *spec); +extern int OS_SizeOfNameSpec(const OSNameSpec *spec); +extern int OS_EqualSpec(const OSSpec *a, const OSSpec *b); +extern int OS_EqualPathSpec(const OSPathSpec *a, const OSPathSpec *b); +extern int OS_EqualNameSpec(const OSNameSpec *a, const OSNameSpec *b); +extern int OS_IsDir(const OSSpec *spec); +extern int OS_IsFile(const OSSpec *spec); +extern int OS_IsLink(const OSSpec *spec); +extern int OS_ResolveLink(const OSSpec *src, OSSpec *dest); +extern int OS_OpenDir(const OSPathSpec *spec, void *data); // TODO arg type +extern int OS_ReadDir(void *data, OSSpec *spec, OSNameSpec *nameSpec, Boolean *pFlag); +extern int OS_CloseDir(void *data); // TODO arg type +extern long OS_GetMilliseconds(); +extern time_t OS_GetTime(time_t *p); +extern int OS_NewHandle(unsigned long size, OSHandle *hand); +extern int OS_ResizeHandle(OSHandle *hand, unsigned long newSize); +extern void *OS_LockHandle(OSHandle *hand); +extern void OS_UnlockHandle(OSHandle *hand); +extern int OS_FreeHandle(OSHandle *hand); +extern int OS_GetHandleSize(OSHandle *hand, unsigned long *pSize); +extern void OS_InvalidateHandle(OSHandle *handle); +extern Boolean OS_ValidHandle(OSHandle *handle); +extern short OS_MacError(int err); +extern void OS_TimeToMac(time_t t, unsigned long *pMacTime); +extern time_t OS_MacToTime(unsigned long macTime, time_t *p); +extern short OS_RefToMac(int ref); +extern int OS_MacToRef(short macRef); +extern int OS_OpenLibrary(const char *a, int *p); +extern int OS_GetLibrarySymbol(void *a, void *b, int *p); +extern int OS_CloseLibrary(void *a); +extern int OS_LoadMacResourceFork(const OSSpec *spec, void **unkA, void **unkB); +extern int OS_IsMultiByte(const char *str, int offset); +extern char *strcatn(char *dst, const char *src, int maxlen); +extern char *strcpyn(char *dst, const char *src, int maxlen); +extern int ustrcmp(const char *a, const char *b); +extern int ustrncmp(const char *a, const char *b, int maxlen); + +/********************************/ +/* OS TU 2 */ +extern int WildCardMatch(const char *a, const char *b); +extern OSSpec *OS_MatchPath(const char *path); +extern char *OS_GetFileNamePtr(char *path); +extern char *OS_GetDirName(const OSPathSpec *spec, char *buf, int bufsize); +extern int OS_MakeSpec2(const char *a, const char *b, OSSpec *spec); +extern int OS_MakeSpecWithPath(const char *pathSpec, const char *str, Boolean flag, OSSpec *spec); +extern int OS_NameSpecChangeExtension(OSNameSpec *nameSpec, const char *newExt, Boolean flag); +extern int OS_NameSpecSetExtension(OSNameSpec *nameSpec, const char *newExt); +extern char *OS_CompactPaths(char *str, const char *a, const char *b, int lenmaybe); +extern char *OS_SpecToStringRelative(const OSSpec *spec, const OSPathSpec *pathSpec, char *outbuf, int outlen); +extern int OS_FindFileInPath(const char *filename, const char *paths, OSSpec *spec); +extern int OS_FindProgram(const char *path, OSSpec *spec); +extern int OS_CopyHandle(OSHandle *src, OSHandle *dest); +extern int OS_AppendHandle(OSHandle *hand, const void *data, long size); + +/********************************/ +/* CLProj.c */ +typedef struct Proj { + Target *target; + OSPathSpec projDir; + OSNameSpec projName; +} Proj; +extern int Proj_Initialize(Proj *proj); +extern int Proj_Terminate(Proj *proj); + +/********************************/ +/* ?? License */ +extern void License_Initialize(); +extern void License_Terminate(); +extern long License_Checkout(); +extern void License_Refresh(); +extern void License_Checkin(); +extern void License_AutoCheckin(); + +/********************************/ +/* ?? 'x' funcs */ +extern void *xmalloc(const char *str, size_t amount); +extern void *xcalloc(const char *str, size_t amount); +extern void *xrealloc(const char *str, void *curPtr, size_t amount); +extern char *xstrdup(const char *str); +extern void xfree(void *ptr); + +/********************************/ +/* CLPluginRequests.cpp */ +extern Boolean SendParserRequest( + Plugin *plugin, + Target *target, + CWCommandLineArgs *args, + CWDataType cpu, + CWDataType os, + int numPlugin, + void *pluginInfo, + int numPanels, + void *panelNames, + void *pluginArgs, + void *panelArgs, + const char *cmdlineBuildDate, + const char *cmdlineBuildTime, + ToolVersionInfo *toolVersionInfo + ); +extern Boolean SendCompilerRequest(Plugin *plugin, File *file, short request); +extern Boolean SendTargetInfoRequest(Target *target, Plugin *plugin, int flags); +extern Boolean SendLinkerRequest(Plugin *plugin, int flags, CWTargetInfo *targetInfo); +extern Boolean SendDisassemblerRequest(Plugin *plugin, File *file); +extern Boolean SendInitOrTermRequest(Plugin *plugin, Boolean action); + +/********************************/ +/* ?? LM funcs */ +extern unsigned long LMGetTicks(); +extern unsigned long LMGetTime(); +extern short LMGetMemErr(); +extern void LMSetMemErr(short err); + +/********************************/ +/* CLFileOps.c */ +extern int GetOutputFile(); // TODO args +extern int StoreObjectFile(); // TODO args +extern int CompileFilesInProject(); +extern int LinkProject(); + +/********************************/ +/* CLPrefs.c */ +extern PrefPanel *PrefPanel_New(const char *name, void *data, long dataSize); +extern Handle PrefPanel_GetHandle(PrefPanel *panel); +extern int PrefPanel_PutHandle(PrefPanel *panel, Handle handle); +extern void Prefs_Initialize(); +extern void Prefs_Terminate(); +extern Boolean Prefs_AddPanel(PrefPanel *panel); +extern PrefPanel *Prefs_FindPanel(const char *name); + +/********************************/ +/* CLTarg.c */ +extern Target *Target_New(const char *name, CWDataType cpu, CWDataType os, CWDataType language); +extern void Target_Free(Target *target); +extern void Targets_Term(Target *targets); +extern void Target_Add(Target **targets, Target *targetToAdd); + +/********************************/ +/* CLAccessPaths.c */ +extern Path *Path_Init(const OSPathSpec *pathSpec, Path *path); +extern Path *Path_New(const OSPathSpec *pathSpec); +extern void Path_Free(Path *path); +extern Boolean Paths_Initialize(Paths *paths); +extern Boolean Paths_Terminate(Paths *paths); +//static Boolean Paths_GrowPaths(Paths *paths, unsigned short *pIndex); +extern Boolean Paths_AddPath(Paths *paths, Path *path); +extern Boolean Paths_InsertPath(Paths *paths, unsigned short index, Path *path); +extern Boolean Paths_RemovePath(Paths *paths, unsigned short index); +extern Boolean Paths_DeletePath(Paths *paths, unsigned short index); +extern Path *Paths_GetPath(Paths *paths, unsigned short index); +extern unsigned short Paths_Count(const Paths *paths); +extern Boolean Paths_FindPath(const Paths *paths, const Path *path); +extern Path *Paths_FindPathSpec(const Paths *paths, const OSPathSpec *pathSpec); +//static Boolean GatherRecurse(Paths *paths, Path *path); +extern Boolean Paths_GatherRecurse(Paths *paths); +extern int Paths_CountRecurse(Paths *paths); +//static void CopyRecurseFSS(FSSpec **pFss, Paths *paths, unsigned short *pCount); +extern void Paths_CopyRecurseFSS(FSSpec *fss, Paths *paths, unsigned short count); +//static Boolean Frameworks_Initialize(Frameworks *frameworks); +//static Boolean Frameworks_Grow(Frameworks *frameworks, unsigned short *pIndex); +//static Boolean Frameworks_Add(Frameworks *frameworks, Framework *framework); +//static Framework *Framework_Init(OSSpec *frameworkSpec, const char *name, const char *version, Framework *framework, Path *containingPath, Boolean flag); +//static Framework *Framework_New(OSSpec *frameworkSpec, const char *name, const char *version, Path *containingPath, Boolean flag); +//static Boolean CheckForFileInFrameworkDir(char *buf, const char *dir, OSPathSpec *pathSpec, const char *filename); +//static Boolean CheckForFileInFramework(char *buf, int fwIndex, const char *filename); +extern Boolean MakeFrameworkPath(char *buf, const char *frameworkName, OSPathSpec **pOutputSpec); +extern Boolean Frameworks_AddPath(const OSPathSpec *pathSpec); +extern Boolean Frameworks_AddFramework(const char *frameworkName, const char *version, Boolean flag); +extern void Framework_GetEnvInfo(); +extern int Frameworks_GetCount(); +extern Framework *Frameworks_GetInfo(int index); + +/********************************/ +/* MacSpecs.c */ +// This is pretty much self-contained lol +extern OSErr OS_OSPathSpec_To_VolDir(const OSPathSpec *pathSpec, short *pVol, long *pDir); +extern OSErr OS_OSSpec_To_FSSpec(const OSSpec *spec, FSSpec *fss); +extern OSErr OS_VolDir_To_OSNameSpec(short vol, long dir, OSNameSpec *nameSpec, long *pDir); +extern OSErr OS_VolDir_To_OSPathSpec(short vol, long dir, OSPathSpec *pathSpec); +extern OSErr OS_FSSpec_To_OSSpec(const FSSpec *fss, OSSpec *spec); +extern OSErr OS_GetRsrcOSSpec(const OSSpec *baseSpec, OSSpec *rsrcSpec, Boolean createFlag); + +/********************************/ +/* StringUtils.c */ +extern StringPtr _pstrcpy(StringPtr dst, ConstStringPtr src); +extern StringPtr _pstrcat(StringPtr dst, ConstStringPtr src); +extern StringPtr _pstrcharcat(StringPtr dst, unsigned char c); +extern StringPtr pstrncpy(StringPtr dst, ConstStringPtr src, short maxlen); +extern StringPtr pstrncat(StringPtr dst, ConstStringPtr src, short maxlen); +extern int pstrcmp(ConstStringPtr a, ConstStringPtr b); +extern int pstrchr(ConstStringPtr str, char c); +extern void c2pstrcpy(StringPtr dst, const char *src); +extern void p2cstrcpy(char *dst, ConstStringPtr src); +extern char *mvprintf(char *str, size_t size, const char *format, va_list ap); +extern char *mprintf(char *str, size_t size, const char *format, ...); +extern int HPrintF(Handle hand, const char *format, ...); + +/********************************/ +/* ?? Handle emulation */ +typedef struct MacHandle { + char *addr; + OSHandle hand; +} MacHandle; +extern OSHandle *OS_PeekMacHandle(MacHandle *mh); +//static void FixHandlePtr(MacHandle *mh, char *ptr); +extern MacHandle *OS_CreateMacHandle(OSHandle *hand); +extern MacHandle *OS_CreateMacHandleDup(MacHandle *mh); +extern void OS_DestroyMacHandle(MacHandle *mh, OSHandle *hand); + +extern OSErr MemError(); +extern Handle NewHandle(long byteCount); +extern Handle NewHandleClear(long byteCount); +extern Handle TempNewHandle(long logicalSize, OSErr *resultCode); +extern void DisposeHandle(Handle h); +extern void HLock(Handle h); +extern void HLockHi(Handle h); +extern void HUnlock(Handle h); +extern void HPurge(Handle h); +extern void HNoPurge(Handle h); +extern SInt8 HGetState(Handle h); +extern void HSetState(Handle h, SInt8 flags); +extern long GetHandleSize(Handle h); +extern void SetHandleSize(Handle h, long size); +extern OSErr PtrAndHand(const void *ptr1, Handle hand2, long size); +extern OSErr PtrToHand(const void *srcPtr, Handle *dstHndl, long size); +extern OSErr HandToHand(Handle *theHndl); +extern OSErr HandAndHand(Handle hand1, Handle hand2); +extern void MoveHHi(Handle h); +extern void BlockMove(const void *srcPtr, void *destPtr, long byteCount); +extern void BlockMoveData(const void *srcPtr, void *destPtr, long byteCount); +extern Ptr NewPtr(long byteCount); +extern void DisposePtr(Ptr p); +extern Ptr NewPtrClear(long byteCount); +extern void DebugStr(ConstStringPtr debuggerMsg); +extern OSErr HandleZone(); +extern OSErr ApplicationZone(); + +/********************************/ +/* Files.c */ +typedef struct FileParamInfo { // i think this is internal, move it once i impl Files.c + unsigned long creationDate; + unsigned long modifiedDate; + long logicalLen; + long physicalLen; + long rLogicalLen; + long rPhysicalLen; + long x18; + long x1C; + unsigned char attrib; +} FileParamInfo; // assumed name +//static int OS_GetFileParamInfo(const OSSpec *spec, FileParamInfo *info, FInfo *finfo); +//static int OS_SetFileParamInfo(const OSSpec *spec, FileParamInfo *info, FInfo *finfo); +extern OSErr HCreate(short vRefNum, long dirID, ConstStr255Param fileName, OSType creator, OSType fileType); +extern OSErr HOpen(short vRefNum, long dirID, ConstStr255Param fileName, SInt8 permission, short *refNum); +extern OSErr HOpenDF(short vRefNum, long dirID, ConstStr255Param fileName, SInt8 permission, short *refNum); +extern OSErr HDelete(short vRefNum, long dirID, ConstStr255Param fileName); +extern OSErr HRename(short vRefNum, long dirID, ConstStr255Param oldName, ConstStr255Param newName); +extern OSErr HGetFInfo(short vRefNum, long dirID, ConstStr255Param fileName, FInfo *fndrInfo); +extern OSErr HSetFInfo(short vRefNum, long dirID, ConstStr255Param fileName, const FInfo *fndrInfo); +extern OSErr FSpCreate(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag); +extern OSErr FSpDirCreate(const FSSpec *spec, ScriptCode scriptTag, long *createdDirID); +extern OSErr FSpOpenDF(const FSSpec *spec, SInt8 permission, short *refNum); +extern OSErr FSpDelete(const FSSpec *spec); +extern OSErr FSpRename(const FSSpec *spec, ConstStr255Param newName); +extern OSErr FSpGetFInfo(const FSSpec *spec, FInfo *fndrInfo); +extern OSErr FSpSetFInfo(const FSSpec *spec, const FInfo *fndrInfo); +extern OSErr HGetVol(StringPtr volName, short *vRefNum, long *dirID); +extern OSErr HSetVol(ConstStr63Param volName, short vRefNum, long dirID); +extern OSErr FlushVol(ConstStr63Param volName, short vRefNum); +extern OSErr FSRead(short refNum, long *count, void *buffPtr); +extern OSErr FSWrite(short refNum, long *count, const void *buffPtr); +extern OSErr FSClose(short refNum); +extern OSErr GetEOF(short refNum, long *logEOF); +extern OSErr SetEOF(short refNum, long logEOF); +extern OSErr GetFPos(short refNum, long *filePos); +extern OSErr SetFPos(short refNum, short posMode, long posOff); +extern OSErr GetVInfo(short drvNum, StringPtr volName, short *vRefNum, long *freeBytes); +extern OSErr PBWriteSync(ParmBlkPtr paramBlock); +extern OSErr PBHGetFInfoSync(HParmBlkPtr paramBlock); +extern OSErr PBHSetFInfoSync(HParmBlkPtr paramBlock); +extern OSErr PBGetCatInfoSync(CInfoPBPtr paramBlock); +extern OSErr ResolveAliasFile(FSSpec *theSpec, Boolean resolveAliasChains, Boolean *targetIsFolder, Boolean *wasAliased); +extern OSErr FSMakeFSSpec(short vRefNum, long dirID, ConstStr255Param fileName, FSSpec *spec); +extern OSErr Allocate(short refNum, long *count); +extern StringPtr c2pstr(char *str); +extern char *p2cstr(StringPtr str); +extern short CharacterByteType(Ptr textBuf, short textOffset, ScriptCode script); +extern short CharByte(); +extern void GetDateTime(unsigned long *secs); +extern Boolean EqualString(ConstStr255Param str1, ConstStr255Param str2, Boolean caseSensitive, Boolean diacSensitive); +extern void GetIndString(Str255 theString, short strListID, short index); +extern char *getindstring(char *theString, short strListID, short index); +extern void NumToString(long theNum, Str255 theString); +extern void StringToNum(ConstStr255Param theString, long *theNum); +extern int AddFileTypeMappingList(void *a, void *b); // TODO sig +extern void UseFileTypeMappings(void *a); // TODO sig +extern OSErr SetMacFileType(const FSSpec *fss, void *a); // TODO sig +extern OSErr GetMacFileType(const FSSpec *fss, void *a); // TODO sig + +/********************************/ +/* CLFiles.c */ +extern File *File_New(); +extern void File_Free(File *file); +extern int Files_Initialize(Files *files); +extern int Files_Terminate(Files *files); +extern int Files_AddFile(Files *files, File *file); +extern int Files_InsertFile(Files *files, File *file, int index); +extern File *Files_GetFile(Files *files, int index); +extern File *Files_FindFile(Files *files, OSSpec *spec); +extern int Files_Count(Files *files); +extern int VFiles_Initialize(VFile **vfiles); +extern int VFiles_Terminate(VFile **vfiles); +extern VFile *VFile_New(const char *name, Handle data); +extern int VFiles_Add(VFile **vfiles, VFile *vfile); +extern VFile *VFiles_Find(VFile *vfiles, const char *name); + +/********************************/ +/* CLOverlays.c */ +extern int Overlays_Initialize(Overlays *overlays); +extern int Overlays_Terminate(Overlays *overlays); +extern int Overlays_AddOvlGroup(Overlays *overlays, OvlGroup *group, int *pIndex); +extern OvlGroup *Overlays_GetOvlGroup(Overlays *overlays, int index); +extern int Overlays_CountGroups(Overlays *overlays); +extern int Overlays_AddFileToOverlay(Overlays *overlays, int groupIndex, int overlayIndex, int fileID); +extern Overlay *Overlays_GetOverlayInGroup(Overlays *overlays, int groupIndex, int overlayIndex); +extern int Overlays_GetFileInOverlay(Overlays *overlays, int groupIndex, int overlayIndex, int fileIndex); +extern OvlGroup *OvlGroup_New(const char *name, CWAddr64 addr); +extern void OvlGroup_Delete(OvlGroup *group); +extern int OvlGroup_AddOverlay(OvlGroup *group, Overlay *overlay, int *pIndex); +extern Overlay *OvlGroup_GetOverlay(OvlGroup *group, int index); +extern int OvlGroup_CountOverlays(OvlGroup *group); +extern Overlay *Overlay_New(const char *name); +extern void Overlay_Delete(Overlay *overlay); +extern int Overlay_AddFile(Overlay *overlay, int fileID, int *pIndex); +extern int Overlay_GetFile(Overlay *overlay, int index); +extern int Overlay_CountFiles(Overlay *overlay); + +/********************************/ +/* CLSegs.c */ +extern Segment *Segment_New(const char *name, unsigned short a); +extern void Segment_Free(Segment *segment); +extern int Segments_Initialize(Segments *segments); +extern int Segments_Terminate(Segments *segments); +//static Boolean Segments_GrowSegments(Segments *segments, unsigned short *pIndex); +extern int Segments_AddSegment(Segments *segments, Segment *segment, unsigned short *pIndex); +extern Boolean Segments_InsertSegment(Segments *segments, unsigned short index, Segment *segment); +extern Boolean Segments_DeleteSegment(Segments *segments, unsigned short index); +extern Segment *Segments_GetSegment(Segments *segments, unsigned short index); +extern unsigned short Segments_Count(const Segments *segments); + +/********************************/ +/* CLDropinCallbacks_V10.cpp */ +// TODO + +/********************************/ +/* MacFileTypes.c */ +typedef struct OSFileTypeMappingListNode { + OSFileTypeMappingList *list; + struct OSFileTypeMappingListNode *next; +} OSFileTypeMappingListNode; // assumed name +extern void OS_AddFileTypeMappingList(OSFileTypeMappingListNode **node, OSFileTypeMappingList *list); +extern void OS_UseFileTypeMappings(OSFileTypeMappingListNode *node); +extern void OS_MacType_To_OSType(OSType mactype, uOSTypePair *ostype); +extern int OS_SetMacFileType(const OSSpec *spec, OSType mactype); +extern int OS_GetMacFileTypeMagic(const void *magic, int length, OSType *mactype); +extern int OS_GetMacFileType(const OSSpec *spec, OSType *mactype); +extern int OS_SetMacFileCreatorAndType(const OSSpec *spec, OSType creator, OSType mactype); + +/********************************/ +/* ?? Handles */ +//extern int OS_LoadFileHandle(OSFileHandle *fh); +//extern int OS_WriteFileHandle(OSFileHandle *fh); +extern int OS_NewFileHandle(const OSSpec *spec, OSHandle *hand, Boolean writeable, OSFileHandle *fh); +extern int OS_LockFileHandle(OSFileHandle *fh, Ptr *h, unsigned long *pSize); +extern int OS_UnlockFileHandle(OSFileHandle *fh); +extern int OS_FreeFileHandle(OSFileHandle *fh); +extern void OS_GetFileHandleSpec(const OSFileHandle *fh, OSSpec *spec); + +/********************************/ +/* CLCompilerLinkerDropin_V10.cpp */ +// TODO + +/********************************/ +/* CLDependencies.c */ +extern int Incls_Initialize(Incls *incls); +extern void Incls_Terminate(Incls *incls); +// IsSysIncl +// MakeInclFileSpec +// QuickFindFileInIncls +// SameIncl +// FindOrAddGlobalInclPath +// _FindFileInPath +// FindFileInPaths +// AddFileToIncls +extern int Incls_FindFileInPaths(Incls *incls, ...); // TODO sig +extern int Deps_Initialize(Deps *deps, Incls *incls); +extern void Deps_Terminate(Deps *deps); +extern int Deps_ChangeSpecialAccessPath(OSPathSpec *pathSpec, Boolean flag); +extern Path *Deps_GetSpecialAccessPath(); +//extern void SetSpecialAccessPathFromIncludeStackTOS(); +// FindDepFile +// AddDepFile +extern int Deps_AddDependency(); // TODO sig +// EscapeName +extern int Deps_ListDependencies(); // TODO sig + +/********************************/ +/* CLWriteObjectFile.c */ +extern Boolean WriteObjectFile(File *file, OSType creator, OSType filetype); +extern Boolean WriteBrowseData(File *file); + +/********************************/ +/* CLBrowser.c */ +// GetBrowseTableInfoAndLock +extern int Browser_Initialize(OSHandle *hand); +//static int Destroy(OSHandle *hand); +extern int Browser_Terminate(OSHandle *hand); +extern int Browser_SearchFile(OSHandle *hand, const char *path, short *pIndex); +extern int Browser_SearchAndAddFile(OSHandle *hand, const char *path, short *pIndex); +//static long CalcDiskSpaceRequirements(...); // needs table type +//static int ConvertMemToDisk(...); // needs table type +extern int Browser_PackBrowseFile(Handle h, OSHandle *hand, OSHandle *hand2); + +/********************************/ +/* ?? Include Cache */ +// TODO + +/********************************/ +/* ?? Error */ +extern char *GetSysErrText(short code, char *buffer); + +/********************************/ +/* Might be cc-mach-ppc-mw.c? */ +extern void GetStaticTarget(CWDataType *cpu, CWDataType *os); +extern void GetStaticPluginType(CWDataType *language, CWDataType *plugintype); +extern void GetStaticParserPluginType(CWDataType *style); +extern int RegisterStaticTargetResources(); +extern int RegisterStaticTargetPlugins(); + +/********************************/ +/* Might be ParserGlue-mach-ppc-cc.c? */ +extern int RegisterStaticParserToolInfo(); + +/********************************/ +/* Might be cc-mach-ppc.c? */ +extern pascal short CWPlugin_GetDropInFlags(const DropInFlags **flags, long *flagsSize); +extern pascal short CWPlugin_GetTargetList(const CWTargetList **targetList); +extern pascal short CWPlugin_GetDropInName(const char **dropinName); +extern pascal short CWPlugin_GetDisplayName(const char **displayName); +extern pascal short CWPlugin_GetDefaultMappingList(const CWExtMapList **defaultMappingList); +extern pascal short CWPlugin_GetPanelList(const CWPanelList **panelList); +//_CmdLine_GetObjectFlags +//_CWPlugin_GetVersionInfo +//_CWPlugin_GetFileTypeMappings +//_Linker_GetDropInFlags +//_Linker_GetDropInName +//_Linker_GetDisplayName +//_Linker_GetPanelList +//_Linker_GetTargetList +//_Linker_GetDefaultMappingList +extern int RegisterStaticCompilerPlugin(); +extern int RegisterCompilerResources(); + +/********************************/ +/* libimp-mach-ppc.c */ +// some statics here +extern int RegisterStaticLibImporterPlugin(); +extern int RegisterLibImporterResources(); + +/********************************/ +/* TargetOptimizer-ppc-mach.c */ +extern int TargetSetOptFlags(short val, Boolean set); +extern void TargetDisplayOptimizationOptions(Handle txt); +extern void TargetSetPragmaOptimizationsToUnspecified(); + +/********************************/ +/* OptimizerHelpers.c */ +extern int SetPragmaOptimizationsToUnspecified(); +extern int SetOptFlags(char *opt, void *str, ...); // two unknown args +extern int DisplayOptimizationOptions(); + +/********************************/ +/* Unk name lol */ +extern int TargetSetWarningFlags(short val, Boolean set); +extern int TargetDisplayWarningOptions(Handle txt); + +/********************************/ +/* WarningHelpers.c */ +extern int SetWarningFlags(char *opt, void *str, ...); // two unknown args +extern int DisplayWarningOptions(); + +/********************************/ +/* CCompiler.c */ + +// LOTS OF STUFF + +/********************************/ +/* StaticParserGlue.c */ +extern int RegisterStaticParserResources(); +extern int RegisterStaticParserPlugins(); + +/********************************/ +/* ParserFace.c */ +extern Handle Parser_FindPrefPanel(char *name); +extern CWResult Parser_StorePanels(CWPluginContext context); +extern short CWParser_GetDropInFlags(const DropInFlags **flags, long *flagsSize); +extern short CWParser_GetDropInName(const char **dropinName); +extern short CWParser_GetDisplayName(const char **displayName); +extern short CWParser_GetPanelList(const CWPanelList **panelList); +extern short CWParser_GetTargetList(const CWTargetList **targetList); +extern short CWParser_GetVersionInfo(const VersionInfo **versioninfo); +extern short Parser_SupportsPlugin(struct CLPluginInfo *pluginfo, CWDataType cpu, CWDataType os, Boolean *isSupported); +extern short Parser_SupportsPanels(int numPanels, char **panelNames, Boolean *isSupported); +extern short parser_main(CWPluginContext context); + +extern struct ParseOptsType parseopts; + +/********************************/ +/* ParserHelpers.c */ +extern int FindFileInPath(const char *filename, OSSpec *fss); +extern char *GetEnvVar(const char *name, Boolean warn, char **match); +//static Boolean MatchesExtension(const char *list, const char *filename); +extern int Opt_AddAccessPath(const char *opt, void *var, const char *arg); +extern int Opt_AddFrameworkPath(const char *opt, void *var, const char *arg); +extern int Opt_AddFramework(const char *opt, void *var, const char *arg); +extern void ListParseMessage(void *errprint, const char *envvar, short id); // TODO funcptr sig - same as CLPReportWarning_V, CLPReportError_V +extern int AddAccessPathList(const char *list, char sep1, char sep2, int source, char *text, Boolean system, long position, Boolean recursive); +extern int Opt_FindAndAddFile(const char *opt, void *var, const char *arg); +extern int Opt_FindAndAddFileRef(const char *opt, void *var, const char *arg); +extern int Opt_AddUnixLibraryFile(const char *opt, void *var, const char *arg); +extern int AddFileList(const char *list, char sep1, char sep2, int source, char *text, long position); +extern int IsFileInOutputDirectory(const OSSpec *file); +extern void GetCFileNameInOutputDirectory(const char *input, char *name, int maxlen); +extern void GetPFileNameInOutputDirectory(const char *input, unsigned char *name, int len); +extern void AddStringLenToHandle(Handle h, const char *str, int len); +extern void AddStringToHandle(Handle h, const char *str); +extern int Opt_PrintVersion(const char *opt, void *var, const char *arg); +extern void GetFirstSourceFilenameBase(char *buffer, char *defaul); +extern int Opt_SavePrefs(const char *opt, void *var, const char *arg); +extern int ParseNumber(const char *arg, Boolean emit_error, long *ret, const char **endptr); +extern int Opt_MaybeMoveAccessPaths(const char *opt, void *var, const char *arg); + +/********************************/ +/* ToolHelpers.c */ +extern int Opt_HandleOutputName(const char *opt, void *, const char *filename); +extern int ValidateToolState(Boolean mustHaveFiles); +extern void ToolReportMessage(short errid, short type, va_list va); +extern void ToolReportWarning(short id, ...); +extern void ToolReportError(short id, ...); +extern void ToolReportOSError(short id, ...); +extern void ToolReportInfo(short id, ...); +extern int Opt_DoNotLink(const char *opt, void *var, const char *arg); +extern int Opt_IncreaseVerbosity(const char *opt, void *var, const char *arg); +extern int Opt_SetStage(const char *opt, void *str, const char *arg, void *unk); +// lots of the Opt_ funcs have weird sigs, need to double check them +extern int Opt_RedirectStream(const char *opt, void *file, const char *filename); + +/********************************/ +/* ParserHelpers-cc.c */ +typedef struct { + void *value; + const char *pragma; + int flags; +} Pragma; // assumed name +extern int Opt_AddStringToDefines(const char *opt, void *str, const char *param); +extern int Opt_DefineSymbol(const char *var, const char *value); +extern int Opt_UndefineSymbol(const char *opt, void *, const char *arg); +extern int Opt_AddPrefixFile(const char *opt, void *handle, const char *filename); +extern int Opt_PragmaTrueFalse(const char *, void *flag, const char *, int flags); +extern int Opt_PragmaFalseTrue(const char *, void *flag, const char *, int flags); +extern int Opt_PragmaOnOff(const char *, void *flag, const char *arg); +extern int Opt_PragmaOffOn(const char *, void *flag, const char *arg); +extern int SetupPragmas(const Pragma *pragmas); + +/********************************/ +/* Arguments.c */ +typedef struct { + short val; + char *text; +} ArgToken; +enum { + ATK_0, + ATK_1, + ATK_2, + ATK_3, + ATK_4, + ATK_5 +}; +typedef struct { + int argc; + int nargv; + char **argv; +} anon0_50; + +extern void Arg_Init(int theargc, char **theargv); +extern void Arg_Terminate(); +extern void Arg_Reset(); +extern void Arg_Stop(ArgToken *where); +extern ArgToken *Arg_PeekToken(); +extern ArgToken *Arg_UsedToken(); +extern int Arg_IsEmpty(); +extern ArgToken *Arg_GetToken(); +extern ArgToken *Arg_UndoToken(); +extern const char *Arg_GetTokenName(ArgToken *tok); +extern const char *Arg_GetTokenText(ArgToken *tok, char *buffer, int maxlen, unsigned char warn); +extern void Arg_InitToolArgs(anon0_50 *ta); +extern void Arg_AddToToolArgs(anon0_50 *ta, short tokval, char *toktxt); +extern void Arg_FinishToolArgs(anon0_50 *ta); +extern void Arg_ToolArgsForPlugin(anon0_50 *ta, struct CWCommandLineArgs *args); +extern void Arg_FreeToolArgs(anon0_50 *ta); + +/********************************/ +/* ToolHelpers-cc.c */ +extern int Opt_DummyLinkerRoutine(const char *opt); +extern int Opt_DummyLinkerSettingRoutine(const char *var, const char *val); +extern void FinishCompilerTool(); + +/********************************/ +/* IO.c */ +extern void ShowTextHandle(const char *description, Handle text); +extern void ShowVersion(Boolean decorate); + +/********************************/ +/* Projects.c */ +extern int GetFileCount(); +extern void SetFileOutputName(long position, short which, char *outfilename); +extern int AddFileToProject(OSSpec *oss, short which, char *outfilename, Boolean exists, long position); +extern Boolean GetFileInfo(long position, OSSpec *spec, char *plugin); +extern int AddAccessPath(const OSPathSpec *oss, short type, long position, Boolean recursive); +extern int MoveSystemPathsIntoUserList(); +extern void AddVirtualFile(const char *filename, Handle *text); +extern void GetOutputFileDirectory(OSPathSpec *dir); +extern void SetOutputFileDirectory(const OSPathSpec *dir); +extern void AddOverlayGroup(const char *name, CWAddr64 *addr, long *groupnum, long *overlaynum); +extern void AddOverlay(long groupnum, const char *name, long *overlaynum); +extern void AddSegment(const char *name, short attrs, long *segmentnum); +extern void ChangeSegment(long segmentnum, const char *name, short attrs); +extern int GetSegment(long segmentnum, char *name, short *attrs); + +/********************************/ +/* Targets.c */ +extern int SetParserToolInfo(ParserTool *tool); +extern Boolean ParserToolMatchesPlugin(CWDataType type, CWDataType lang, CWDataType cpu, CWDataType os); +extern Boolean ParserToolHandlesPanels(int numPanels, const char **panelNames); +extern Boolean SetupParserToolOptions(); + +/********************************/ +/* Option.c */ +typedef struct { + void *first; + void *second; +} Opt50; +typedef struct { + Option *opt; + char *curopt; +} Opt52; +typedef struct { + union { + Opt50 v; + OptionList *lst; + Opt52 o; + char *param; + } e; + short flags; +} Opt48; +//static void Option_PushList(OptionList *lst); +//static void Option_PushOpt(Option *opt, const char *optname); +//static void Option_PopOpt(const char *optname); +//static void Option_PopList(); +extern void Args_InitStack(); +extern int Args_StackSize(); +extern void Args_Push(short flags, void *first, void *second); +extern Opt48 *Args_Pop(short flags); +extern void Args_SpellStack(char *buffer, short flags); +extern void Args_AddToToolArgs(anon0_50 *ta); +extern void Options_Init(); +extern OptionList *Options_GetOptions(); +extern void Options_SortOptions(); +//static void Options_AddOption(Option *opt); +extern int Options_AddList(OptionList *optlst); +extern int Options_AddLists(OptionList **optlst); +//static void Options_Reset(OptionList *optlst); +//static void Option_SpellList(char *buffer, OptionList *conflicts, int flags); +extern int Option_ForTool(Option *opt, int which); +extern int Option_ThisTool(); +extern int Option_ForThisTool(Option *opt); +extern int Option_AlsoPassedToTool(Option *opt, int which); +extern int Option_AlsoPassedFromThisTool(Option *opt); +//static Boolean Option_ContinuesThisLevel(int level, ArgToken *tok); +//static Boolean Option_IsEndingThisLevel(int level, ArgToken *tok); +//static Boolean Option_IsEndingLevel(int level, ArgToken *tok); +extern int Option_Parse(Option *opt, int oflags); +//static int Option_MatchString(char *list, char *str, int flags, int *result); +//static Option *Option_Lookup(OptionList *search, void *unk, int *flags); +//static int Options_DoParse(OptionList *search, int flags); +extern int Options_Parse(OptionList *options, int flags); +extern int Option_ParseDefaultOption(OptionList *options); +extern void Option_ParamError(short id, va_list ap); +extern void Option_ParamWarning(short id, va_list ap); +extern void Option_OptionError(short id, va_list ap); +extern void Option_OptionWarning(short id, va_list ap); +extern void Option_Error(short id, ...); +extern void Option_Warning(short id, ...); +extern int Options_Help(const char *keyword); +extern int Option_Help(const char *opt); +extern int Options_DisplayHelp(); + +/********************************/ +/* ParserErrors.c */ +extern void CLPReportError_V(const char *format, va_list ap); +extern void CLPReportWarning_V(const char *format, va_list ap); +extern void CLPReport_V(const char *format, va_list ap); +extern void CLPStatus_V(const char *format, va_list ap); +extern void CLPAlert_V(const char *format, va_list ap); +extern void CLPOSAlert_V(const char *format, long err, va_list ap); +extern void CLPGetErrorString(short errid, char *buffer); +extern void CLPReportError(short errid, ...); +extern void CLPReportWarning(short errid, ...); +extern void CLPReport(short errid, ...); +extern void CLPAlert(short errid, ...); +extern void CLPOSAlert(short errid, short err, ...); +extern void CLPProgress(short errid, ...); +extern void CLPStatus(short errid, ...); +extern void CLPFatalError(const char *format, ...); + +/********************************/ +/* Utils.c */ +extern int my_tolower(char c); +extern int my_isdigit(char c); +extern int my_isalpha(char c); +extern int my_isalnum(char c); +extern int my_isxdigit(char c); +extern char *Utils_SpellList(char *list, char *buffer, char opts); +extern int Utils_CompareOptionString(const char *a, const char *b, int cased, int sticky); + +/********************************/ +/* Parameter.c */ +//static int Param_None(); +//static void DescHelpParam_None(PARAM_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_None(); + +//static void DescHelpParam_Number(NUM_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_Number(); +//static int Param_Number(NUM_T *p, const char *pstr); + +//static void DescHelpParam_FTypeCreator(FTYPE_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_FTypeCreator(); +//static int Param_FTypeCreator(FTYPE_T *p, const char *pstr); + +//static void DescHelpParam_String(STRING_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_String(); +//static int Param_String(STRING_T *p, const char *pstr); + +//static void DescHelpParam_ID_or_SYM(STRING_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_ID_or_SYM(); +//static int Param_ID_or_SYM(STRING_T *p, const char *pstr); + +//static void DescHelpParam_OnOff(ONOFF_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_OnOff(); +//static int Param_OnOff(ONOFF_T *p, const char *pstr); + +//static void DescHelpParam_OffOn(ONOFF_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_OffOn(); +//static int Param_OffOn(OFFON_T *p, const char *pstr); + +//static void DescHelpParam_FilePath(FILEPATH_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_FilePath(); +//static int Param_FilePath(FILEPATH_T *p, const char *pstr); + +//static void DescHelpParam_Mask(MASK_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_Mask(MASK_T *p); +//static int Param_Mask(MASK_T *p, const char *pstr, int flags); + +//static void DescHelpParam_Toggle(TOGGLE_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_Toggle(TOGGLE_T *p); +//static int Param_Toggle(TOGGLE_T *p, const char *pstr); + +//static void DescHelpParam_Set(SET_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_Set(SET_T *p); +//static int Param_Set(SET_T *p, const char *pstr, int flags); + +//static void DescHelpParam_SetString(SETSTRING_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_SetString(SETSTRING_T *p); +//static int Param_SetString(SETSTRING_T *p, const char *pstr, int flags); + +//static void DescHelpParam_Generic(GENERIC_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_Generic(GENERIC_T *p); +//static int Param_Generic(GENERIC_T *p, const char *pstr, int flags); + +//static void DescHelpParam_Setting(SETTING_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_Setting(SETTING_T *p); +//static int Param_Setting(SETTING_T *p, const char *pstr, int flags); + +//static void DescHelpParam_IfArg(IFARG_T *p, const char **desc, const char **help, const char **defaul); +//static int CompareParam_IfArg(IFARG_T *p); +//static int Param_IfArg(IFARG_T *p, const char *pstr, int flags); + +//static int Param_Parse(PARAM_T *param, const char *cparam, int flags); +extern void Param_DescHelp(PARAM_T *param, const char **desc, const char **help, const char **defaul); +extern int Param_Compare(PARAM_T *param); +//static void Param_PushParam(const char *param); +//static void Param_PopParam(); +//static Boolean Param_IsNonTextFile(const char *fname, Boolean warn); +//static int Param_GetArgument(PARAM_T *param, const char *cparam, int exec); +extern int Params_Parse(PARAM_T *param, int flags); +extern void Param_Error(short id, ...); +extern void Param_Warning(short id, ...); + +/********************************/ +/* Help.c */ +extern int Help_Option(struct OptionList *lst, struct Option *opt, int subprint, const char *keyword); +extern void Help_Options(struct OptionList *lst, int subprint, const char *keyword); +extern void Help_Usage(); +extern void Help_Null(); +extern void Help_Init(); +extern void Help_Line(char ch); +extern void Help_Term(); + +/********************************/ +/* */ + +/********************************/ +/* */ + +/********************************/ +/* ?? COS */ +// static COS_pstrcpy +// static COS_pstrcat +// static COS_pstrcharcat +// static COS_pstrcmp +extern Handle COS_NewHandle(long byteCount); +extern Handle COS_NewOSHandle(long logicalSize); +extern void COS_FreeHandle(Handle handle); +extern Boolean COS_ResizeHandle(Handle handle, long newSize); +extern long COS_GetHandleSize(Handle handle); +extern void COS_LockHandle(Handle handle); +extern void COS_LockHandleHi(Handle handle); +extern void COS_UnlockHandle(Handle handle); +extern int COS_GetHandleState(Handle handle); +extern void COS_SetHandleState(Handle handle, int state); +extern Boolean COS_IsLockedState(int state); +extern char *COS_NewPtr(long byteCount); +extern char *COS_NewPtrClear(long byteCount); +extern void COS_FreePtr(char *ptr); +extern void COS_AppendPtrToHandle(char *ptr1, Handle hand2, long size); +extern short COS_GetMemErr(); +extern long COS_GetTicks(); +extern long COS_GetTime(); +extern void COS_GetString(char *buffer, short strListID, short index); +extern void COS_GetPString(unsigned char *buffer, short strListID, short index); +extern Boolean COS_IsMultiByte(char *buffer, char *str); +extern short COS_FileNew(const FSSpec *spec, short *refNum, FourCharCode creator, FourCharCode fileType); +extern short COS_FileOpen(const FSSpec *spec, short *refNum); +extern short COS_FileGetType(const FSSpec *spec, FourCharCode *fileType); +extern short COS_FileGetSize(short refNum, long *logEOF); +extern short COS_FileRead(short refNum, void *buffPtr, long count); +extern short COS_FileWrite(short refNum, const void *buffPtr, long count); +extern short COS_FileGetPos(short refNum, long *filePos); +extern short COS_FileSetPos(short refNum, long filePos); +extern short COS_FileClose(short refNum); +extern void COS_FileSetFSSpec(FSSpec *spec, unsigned char *path); +extern short COS_FileMakeFSSpec(short vRefNum, long dirID, unsigned char *fileName, FSSpec *spec); +extern short COS_FileMakeFSSpecWithPath(const FSSpec *inputSpec, unsigned char *fileName, FSSpec *spec); +extern short COS_FileGetFileInfo(const FSSpec *spec, OSType *creator, OSType *fileType); +extern void COS_FileGetFSSpecInfo(const FSSpec *spec, short *vRefNum, long *dirID, unsigned char *fileName); +//static void COS_MakePath(short vRefNum, long dirID, char *path); +extern void COS_FileGetPathName(char *buffer, const FSSpec *spec, long *mdDat); +extern Boolean COS_EqualFileSpec(const FSSpec *a, const FSSpec *b); + +/********************************/ +/* */ + +// TODO sort me +extern Proj *gProj; +extern ParserTool *pTool; +extern PCmdLine optsCmdLine; +extern PCmdLineEnvir optsEnvir; +extern PCmdLineCompiler optsCompiler; +extern PCmdLineLinker optsLinker; +extern CLState clState; + +/********************************/ +/* CmdLineBuildDate.c */ +extern char CMDLINE_BUILD_DATE[]; +extern char CMDLINE_BUILD_TIME[]; + + +/********************************/ +/* MISC */ +extern void IO_Terminate(); +extern void SetupDebuggingTraps(); +extern void AppendArgumentList(void *unk1, void *unk2, const char *arg); + +extern int (*PrefPanelsChangedCallback)(const char *); +extern Boolean systemHandles; +extern char *MAINOPTCHAR; +extern char *SEPOPTSTR; +extern char compat; +extern anon0_50 linkargs; + +#ifdef __cplusplus +} +#endif diff --git a/sdk_hdrs/CWDropInPanel.h b/sdk_hdrs/CWDropInPanel.h new file mode 100755 index 0000000..4aa7a21 --- /dev/null +++ b/sdk_hdrs/CWDropInPanel.h @@ -0,0 +1 @@ +/*
* CWDropInPanel.h
*
* Copyright © 1999 Metrowerks inc. All rights reserved.
*
* DropIn Preferences Panel Interface for UNIX/WIN32 Metrowerks CodeWarriorª
*/
#ifndef __CWDROPINPANEL_H__
#define __CWDROPINPANEL_H__
#ifdef __MWERKS__
# pragma once
#endif
#ifndef __CWPlugins_H__
#include "CWPlugins.h"
#endif
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* Convenience macros for swapping pref-panel values. Use this macros only if your
* system/libraries do not provide their own public swapping functions/macros.
*
*/
/* Swap 16-bit(short) value */
#define CWPREF_BYTESWAP_SHORT(value) value = \
(((((unsigned short)(value))<<8) & 0xFF00) | \
((((unsigned short)(value))>>8) & 0x00FF))
/* Swap 32-bit(long) value */
#define CWPREF_BYTESWAP_LONG(value) value = \
(((((unsigned long)(value))<<24) & 0xFF000000) | \
((((unsigned long)(value))<< 8) & 0x00FF0000) | \
((((unsigned long)(value))>> 8) & 0x0000FF00) | \
((((unsigned long)(value))>>24) & 0x000000FF))
#ifndef __DROPINPANEL_H__
/* API version numbers */
#define DROPINPANELAPIVERSION_1 1 /* CW7 API version */
#define DROPINPANELAPIVERSION_2 2 /* intermediate version */
#define DROPINPANELAPIVERSION_3 3 /* CW8 API version */
#define DROPINPANELAPIVERSION_4 4 /* CW9 API version */
#define DROPINPANELAPIVERSION_5 5 /* CW Pro 2 API version */
#define DROPINPANELAPIVERSION_7 7 /* CW Pro 3 Mac API version */
#define DROPINPANELAPIVERSION_8 8 /* CW Pro 3 Win32 API version */
#define DROPINPANELAPIVERSION_9 9 /* CW Pro 5 Win32 API version */
#define DROPINPANELAPIVERSION_10 10 /* CW Pro 6 Win32 API version */
#define DROPINPANELAPIVERSION_11 11 /* CW Pro 7 Win32 API version */
#define DROPINPANELAPIVERSION DROPINPANELAPIVERSION_11 /* current API version */
/* Error codes you return to the IDE */
#define kBadPrefVersion 1000 /* panel doesn't know about this version */
#define kMissingPrefErr 1001
#define kSettingNotFoundErr 1002
#define kSettingTypeMismatchErr 1003
#define kInvalidCallbackErr 1004
#define kSettingOutOfRangeErr 1005
/*
* Requests codes - sent by the IDE to your panel
* Note: Many of these are Mac-specific but are included for compatability reasons.
* Future APIs will reimplement many of them is an OS-neutral way.
*/
enum {
reqInitPanel = -2, /* (called when panel is loaded) */
reqTermPanel = -1, /* (called when panel is unloaded) */
reqInitDialog = 0, /* initialize panel's dialog state */
reqTermDialog, /* clean up panel's dialog state */
reqPutData, /* copy options data to dialog items */
reqGetData, /* copy dialog items to options data */
reqFilter, /* filter a dialog event for the panel (Mac only) */
reqItemHit, /* process an itemHit in the panel */
reqAEGetPref, /* get preference setting for AppleEvent request (Mac only) */
reqAESetPref, /* set preference setting from AppleEvent request (Mac only) */
reqValidate, /* tell if current settings force recompile or relink */
reqGetFactory, /* retrieve factory settings */
reqUpdatePref, /* verify and/or modify prefs to fit current version */
reqUpdateProject, /* (only sent to built-in panels) */
reqSetupDebug, /* change settings to reflect debugging status */
reqRenameProject, /* change settings that depend on project name */
reqPrefsLoaded, /* (only sent to built-in panels) */
reqDrawCustomItem, /* draw a custom item (Mac only) */
reqActivateItem, /* activate a custom item (Mac only) */
reqDeactivateItem, /* deactivate a custom item (Mac only) */
reqHandleClick, /* handle mouse down in an active custom item (Mac only) */
reqHandleKey, /* handle key down in an active custom item (Mac only) */
reqFindStatus, /* enable/disable menu items for a custom item (Mac only) */
reqObeyCommand, /* execute a menu command for a custom item (Mac only) */
reqDragEnter, /* the user is dragging into the given item (Mac only) */
reqDragWithin, /* the user is dragging within the given item (Mac only) */
reqDragExit, /* the user is dragging out of the given item (Mac only) */
reqDragDrop, /* the user dropped onto the given item (Mac only) */
reqByteSwapData, /* byte swap the fields in the prefs data */
reqFirstLoad, /* panel has been loaded for the first time */
reqReadSettings, /* read settings from IDE to construct pref data handle */
reqWriteSettings, /* write the individual settings from pref data handle */
reqItemDoubleClick, /* process an double clicked in the panel, currently implemented for listviews */
reqItemIsCellEditable /* currently implemented for listviews, tells whether or not the listview is editable */
};
/* Layout and bit flags for 'Flag' resource for panels */
/* */
/* For the version 3 of these resource, we renamed the 'apiversion' field to */
/* 'earliestCompatibleAPIVersion' and added the 'newestAPIVersion' field. */
/* This allows plugins to support more than one API version and therefore run */
/* under more than one version of the IDE. */
typedef struct PanelFlags {
unsigned short rsrcversion; /* version number of resource */
CWDataType dropintype; /* dropin type ('Comp', 'Link', 'Panl') */
/* earliest API support by this plugin */
unsigned short earliestCompatibleAPIVersion;
unsigned long dropinflags; /* capability flags (see enum below) */
CWDataType panelfamily; /* family of panel (linker, codegen, etc) */
unsigned short newestAPIVersion; /* newest API version supported */
unsigned short dataversion; /* version number of prefs data */
unsigned short panelscope; /* scope of panel (see enum below) */
} PanelFlags;
/* capability flags, as used in member dropinflags of PanelFlags struct */
enum {
usesStrictAPI = 1 << 31, /* this panel is built with the strict API */
supportsByteSwapping = 1 << 30, /* this panel support the byte-swapping request */
supportsTextSettings = 1 << 29, /* this panel supports the read & write settings requests */
usesCrossPlatformAPI = 1 << 28 /* uses the cross-platform API rather than Mac API */
/* remaining flags are reserved for future use and should be zero-initialized */
};
/* panel scopes, as used in member panelscope of PanelFlags struct */
/* */
/* The scope of a panel tells the IDE which settings window to display the panel. */
/* Currently, only panels for debugger plug-ins use panelScopeGlobal and only */
/* panels for VCS plug-ins use panelScopeProject. A panel for a compiler or linker */
/* must use panelScopeTarget. */
enum {
panelScopeGlobal, /* this panel is scoped to the global preferences window */
panelScopeProject, /* this panel is scoped to the VCS settings window */
panelScopeTarget /* this panel is scoped to the target settings window */
};
/* pre-defined panel families, used in panelfamily field of PanelFlags struct */
enum {
panelFamilyProject = CWFOURCHAR('p', 'r', 'o', 'j'),
panelFamilyFrontEnd = CWFOURCHAR('f', 'e', 'n', 'd'),
panelFamilyBackEnd = CWFOURCHAR('b', 'e', 'n', 'd'),
panelFamilyBrowser = CWFOURCHAR('b', 'r', 'o', 'w'),
panelFamilyEditor = CWFOURCHAR('e', 'd', 'i', 't'),
panelFamilyDebugger = CWFOURCHAR('d', 'b', 'u', 'g'),
panelFamilyLinker = CWFOURCHAR('l', 'i', 'n', 'k'),
panelFamilyMisc = CWFOURCHAR('*', '*', '*', '*')
};
typedef struct MWSetting* CWSettingID;
#define kNoSettingID 0
#endif /* not defined __DROPINPANEL_H__ */
/*-------------------------------------------------------------------------------------
Callbacks to the IDE, in addition to those in CWPlugins.h
-----------------------------------------------------------------------------------*/
/* Dialog related */
CW_CALLBACK CWPanelAppendItems (CWPluginContext context, short ditlID);
CW_CALLBACK CWPanelShowItem (CWPluginContext context, long whichItem, Boolean showIt);
CW_CALLBACK CWPanelEnableItem (CWPluginContext context, long whichItem, Boolean enableIt);
CW_CALLBACK CWPanelActivateItem (CWPluginContext context, long whichItem);
CW_CALLBACK CWPanelGetItemValue (CWPluginContext context, long whichItem, long* value);
CW_CALLBACK CWPanelSetItemValue (CWPluginContext context, long whichItem, long value);
CW_CALLBACK CWPanelGetItemText (CWPluginContext context, long whichItem, char* str, short maxLen);
CW_CALLBACK CWPanelSetItemText (CWPluginContext context, long whichItem, char* str);
CW_CALLBACK CWPanelInsertListItem (CWPluginContext context, long dlgItemID, long index, char* str);
CW_CALLBACK CWPanelDeleteListItem (CWPluginContext context, long dlgItemID, long index);
CW_CALLBACK CWPanelGetListItemSize (CWPluginContext context, long dlgItemID, long* listSize);
CW_CALLBACK CWPanelGetListItemText (CWPluginContext context, long dlgItemID, long index, char* str, short maxLen);
CW_CALLBACK CWPanelSetListItemText (CWPluginContext context, long dlgItemID, long index, char* str);
CW_CALLBACK CWPanelGetPopupItemChecked (CWPluginContext context, long dlgItemID, long index, Boolean* checked);
CW_CALLBACK CWPanelSetPopupItemChecked (CWPluginContext context, long dlgItemID, long index, Boolean checked);
CW_CALLBACK CWPanelSetPopupItemEnabled (CWPluginContext context, long dlgItemID, long index, Boolean enabled);
CW_CALLBACK CWPanelInvalItem (CWPluginContext context, long whichItem);
CW_CALLBACK CWPanelValidItem (CWPluginContext context, long whichItem);
CW_CALLBACK CWPanelGetNumBaseDialogItems(CWPluginContext context, short* baseItems);
CW_CALLBACK CWPanelGetDialogItemHit (CWPluginContext context, short* itemHit);
CW_CALLBACK CWPanelGetItemTextHandle (CWPluginContext context, long whichItem, CWMemHandle* text);
CW_CALLBACK CWPanelSetItemTextHandle (CWPluginContext context, long whichItem, CWMemHandle text);
CW_CALLBACK CWPanelGetItemData (CWPluginContext context, long dlgItemID, void *outData, long *outDataLength);
CW_CALLBACK CWPanelSetItemData (CWPluginContext context, long dlgItemID, void *inData, long inDataLength);
CW_CALLBACK CWPanelGetItemMaxLength (CWPluginContext context, long dlgItemID, short *outLength);
CW_CALLBACK CWPanelSetItemMaxLength (CWPluginContext context, long dlgItemID, short inLength);
CW_CALLBACK CWPanelChooseRelativePath (CWPluginContext context, CWRelativePath *ioPath, Boolean isFolder, short filterCount, void *filterList, char *prompt);
CW_CALLBACK CWPanelGetRelativePathString(CWPluginContext context, CWRelativePath *inPath, char *pathString, long* maxLength);
/* CellView related, with string elements */
// selection
CW_CALLBACK CWPanelListViewSelectCell (CWPluginContext context,long dlgItemID,long col,long row,Boolean addToSelection);
CW_CALLBACK CWPanelListViewUnselectCell (CWPluginContext context,long dlgItemID,long col,long row,Boolean *result);
CW_CALLBACK CWPanelListViewSelectNothing (CWPluginContext context,long dlgItemID);
CW_CALLBACK CWPanelListViewGetSelectionCount (CWPluginContext context,long dlgItemID,long *count);
CW_CALLBACK CWPanelListViewGetSelection (CWPluginContext context,long dlgItemID,long *col,long *row);
// rows
CW_CALLBACK CWPanelListViewAddRows (CWPluginContext context,long dlgItemID,long afterRow,long count);
CW_CALLBACK CWPanelListViewDeleteRows (CWPluginContext context,long dlgItemID,long firstRow,long count);
CW_CALLBACK CWPanelListViewGetRowCount (CWPluginContext context,long dlgItemID,long *count);
// refresh
CW_CALLBACK CWPanelListViewRefreshRow (CWPluginContext context,long dlgItemID,long row);
// columns
CW_CALLBACK CWPanelListViewAddCols (CWPluginContext context,long dlgItemID,long afterCol,long count);
CW_CALLBACK CWPanelListViewDeleteCols (CWPluginContext context,long dlgItemID,long firstCol,long count);
CW_CALLBACK CWPanelListViewGetColCount (CWPluginContext context,long dlgItemID,long *count);
CW_CALLBACK CWPanelListViewGetColWidth (CWPluginContext context,long dlgItemID,long col,short *colWidth);
CW_CALLBACK CWPanelListViewSetColWidth (CWPluginContext context,long dlgItemID,long col,short colWidth);
CW_CALLBACK CWPanelListViewNextCell (CWPluginContext context,long dlgItemID,long *col,long *row,Boolean hNext,Boolean vNext,Boolean selectableOnly,Boolean *result); // col and row is in-> and <-out
CW_CALLBACK CWPanelListViewRefreshCell (CWPluginContext context,long dlgItemID,long col,long row);
CW_CALLBACK CWPanelListViewScrollToCell (CWPluginContext context,long dlgItemID,long col,long row,Boolean inRefresh);
CW_CALLBACK CWPanelListViewGetCellTextValue (CWPluginContext context,long dlgItemID,long col,long row,char* str, short maxLen);
CW_CALLBACK CWPanelListViewSetCellTextValue (CWPluginContext context,long dlgItemID,long col,long row,char* str);
// utilities for giving a answer to a request
CW_CALLBACK CWPanelListViewSetDoubleClickHandled(CWPluginContext context, Boolean value);
CW_CALLBACK CWPanelListViewSetEditable (CWPluginContext context, Boolean value);
CW_CALLBACK CWPanelListViewGetCell (CWPluginContext context, long *col,long *row);
/* Preference data related */
CW_CALLBACK CWPanelGetOriginalPrefs (CWPluginContext context, CWMemHandle* originalPrefs);
CW_CALLBACK CWPanelGetCurrentPrefs (CWPluginContext context, CWMemHandle* currentPrefs);
CW_CALLBACK CWPanelGetFactoryPrefs (CWPluginContext context, CWMemHandle* factoryPrefs);
CW_CALLBACK CWPanelGetDebugFlag (CWPluginContext context, Boolean* debugOn);
CW_CALLBACK CWPanelSetRevertFlag (CWPluginContext context, Boolean canRevert);
CW_CALLBACK CWPanelSetFactoryFlag (CWPluginContext context, Boolean canFactory);
CW_CALLBACK CWPanelSetResetPathsFlag (CWPluginContext context, Boolean resetPaths);
CW_CALLBACK CWPanelSetRecompileFlag (CWPluginContext context, Boolean recompile);
CW_CALLBACK CWPanelSetRelinkFlag (CWPluginContext context, Boolean relink);
CW_CALLBACK CWPanelSetReparseFlag (CWPluginContext context, Boolean reparse);
CW_CALLBACK CWPanelGetPanelPrefs (CWPluginContext context, const char* panelName, CWMemHandle *prefs, Boolean* requiresByteSwap);
CW_CALLBACK CWPanelGetOldProjectFile (CWPluginContext context, CWFileSpec* projectSpec);
CW_CALLBACK CWPanelGetToEndian (CWPluginContext context, short* toEndian);
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
CW_CALLBACK CWPanelGetAEKeyword (CWPluginContext context, AEKeyword* keyword);
CW_CALLBACK CWPanelGetAEDesc (CWPluginContext context, AEDesc* desc);
CW_CALLBACK CWPanelSetAEDesc (CWPluginContext context, const AEDesc* desc);
CW_CALLBACK CWPanelReadRelativePathAEDesc (CWPluginContext context, CWRelativePath* path, const AEDesc* desc);
CW_CALLBACK CWPanelWriteRelativePathAEDesc (CWPluginContext context, const CWRelativePath* path, AEDesc* desc);
#endif
/* Reading and writing scalar settings */
CW_CALLBACK CWReadBooleanSetting (CWPluginContext context, const char* name, Boolean* value);
CW_CALLBACK CWReadIntegerSetting (CWPluginContext context, const char* name, long* value);
CW_CALLBACK CWReadFloatingPointSetting (CWPluginContext context, const char* name, double* value);
CW_CALLBACK CWReadStringSetting (CWPluginContext context, const char* name, const char** value);
CW_CALLBACK CWReadRelativePathSetting (CWPluginContext context, const char* name, CWRelativePath* value);
CW_CALLBACK CWWriteBooleanSetting (CWPluginContext context, const char* name, Boolean value);
CW_CALLBACK CWWriteIntegerSetting (CWPluginContext context, const char* name, long value);
CW_CALLBACK CWWriteFloatingPointSetting (CWPluginContext context, const char* name, double value);
CW_CALLBACK CWWriteStringSetting (CWPluginContext context, const char* name, const char* value);
CW_CALLBACK CWWriteRelativePathSetting (CWPluginContext context, const char* name, const CWRelativePath* value);
/* Reading and writing array and structure settings */
CW_CALLBACK CWGetNamedSetting (CWPluginContext context, const char* name, CWSettingID* settingID);
CW_CALLBACK CWGetStructureSettingField (CWPluginContext context, CWSettingID settingID, const char* name, CWSettingID* fieldSettingID);
CW_CALLBACK CWGetArraySettingSize (CWPluginContext context, CWSettingID settingID, long* size);
CW_CALLBACK CWGetArraySettingElement (CWPluginContext context, CWSettingID settingID, long index, CWSettingID* elementSettingID);
CW_CALLBACK CWGetBooleanValue (CWPluginContext context, CWSettingID settingID, Boolean* value);
CW_CALLBACK CWGetIntegerValue (CWPluginContext context, CWSettingID settingID, long* value);
CW_CALLBACK CWGetFloatingPointValue (CWPluginContext context, CWSettingID settingID, double* value);
CW_CALLBACK CWGetStringValue (CWPluginContext context, CWSettingID settingID, const char** value);
CW_CALLBACK CWGetRelativePathValue (CWPluginContext context, CWSettingID settingID, CWRelativePath* value);
CW_CALLBACK CWSetBooleanValue (CWPluginContext context, CWSettingID settingID, Boolean value);
CW_CALLBACK CWSetIntegerValue (CWPluginContext context, CWSettingID settingID, long value);
CW_CALLBACK CWSetFloatingPointValue (CWPluginContext context, CWSettingID settingID, double value);
CW_CALLBACK CWSetStringValue (CWPluginContext context, CWSettingID settingID, const char* value);
CW_CALLBACK CWSetRelativePathValue (CWPluginContext context, CWSettingID settingID, const CWRelativePath* value);
#ifdef __cplusplus
}
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#endif /* __CWDROPINPANEL_H__ */
\ No newline at end of file diff --git a/sdk_hdrs/CWPluginErrors.h b/sdk_hdrs/CWPluginErrors.h new file mode 100755 index 0000000..74f93c7 --- /dev/null +++ b/sdk_hdrs/CWPluginErrors.h @@ -0,0 +1 @@ +/*
* CWPluginErrors.h - CW_Result constants for plugin errors
*
* Copyright © 1995-1997 Metrowerks, Inc. All rights reserved.
*
*/
#ifndef __CWPluginErrors_H__
#define __CWPluginErrors_H__
#ifdef __MWERKS__
# pragma once
#endif
enum
{
// common errors for all plugins
cwNoErr, /* successful return */
cwErrUserCanceled, /* operation canceled by user */
cwErrRequestFailed, /* generic failure when plugin fails */
cwErrInvalidParameter, /* one or more callback parameters invalid */
cwErrInvalidCallback, /* invalid given current request and plugin type*/
cwErrInvalidMPCallback, /* this request is not support from MP threads */
cwErrOSError, /* OS-specific, call CWGetCallbackOSError() */
cwErrOutOfMemory, /* not enough memory */
cwErrFileNotFound, /* file not found on disk */
cwErrUnknownFile, /* bad file number, doesn't exist */
cwErrSilent, /* request failed but plugin didn't report any */
/* errors and doesn't want IDE to report that */
/* an unknown error occurred */
cwErrCantSetAttribute, /* plugin requested inapplicable file flags in */
/* CWAddProjectEntry */
cwErrStringBufferOverflow, /* an output string buffer was too small */
cwErrDirectoryNotFound, /* unable to find a directory being sought */
cwErrLastCommonError = 512,
// compiler/linker errors
cwErrUnknownSegment, /* bad segment number, doesn't exist */
cwErrSBMNotFound, /* */
cwErrObjectFileNotStored, /* No external object file has been stored */
cwErrLicenseCheckFailed,/* license check failed, error reported by IDE */
cwErrFileSpecNotSpecified, /* a file spec was unspecified */
cwErrFileSpecInvalid, /* a file spec was invalid */
cwErrLastCompilerLinkerError = 1024
};
#endif // __CWPluginErrors_H__
\ No newline at end of file diff --git a/sdk_hdrs/CWPlugins.h b/sdk_hdrs/CWPlugins.h new file mode 100755 index 0000000..b3dbd2a --- /dev/null +++ b/sdk_hdrs/CWPlugins.h @@ -0,0 +1 @@ +/*
* CWPlugins.h - Common declarations for Metrowerks CodeWarriorª plugins
*
* Copyright © 1995-1997 Metrowerks, Inc. All rights reserved.
*
*/
#ifndef __CWPlugins_H__
#define __CWPlugins_H__
#ifdef __MWERKS__
# pragma once
#endif
#define CWPLUGIN_HOST_MACOS 1
#define CWPLUGIN_HOST_WIN32 2
#define CWPLUGIN_HOST_SOLARIS 3
#define CWPLUGIN_HOST_LINUX 4
#ifndef CWPLUGIN_HOST
# ifdef WIN32
# define CWPLUGIN_HOST CWPLUGIN_HOST_WIN32
# elif defined(macintosh)
# define CWPLUGIN_HOST CWPLUGIN_HOST_MACOS
# elif defined(__sun__)
# define CWPLUGIN_HOST CWPLUGIN_HOST_SOLARIS
# elif defined(__linux__)
# define CWPLUGIN_HOST CWPLUGIN_HOST_LINUX
# else
# error
# endif
#endif
#define CWPLUGIN_API_MACOS 1
#define CWPLUGIN_API_WIN32 2
#define CWPLUGIN_API_UNIX 3
#ifndef CWPLUGIN_API
# ifdef WIN32
# define CWPLUGIN_API CWPLUGIN_API_WIN32
# elif defined(macintosh)
# define CWPLUGIN_API CWPLUGIN_API_MACOS
# elif defined(__sun__) || defined(__linux__)
# define CWPLUGIN_API CWPLUGIN_API_UNIX
# else
# error
# endif
#endif
/*
** Radix 256 notation where a 32-bit integer is created from four
** ASCII characters. A four-character constant of this form, say
** 'ABCD', must always be represented with the same pattern, 0x41424344
** in this case, regardless of big/little endian issues.
*/
typedef long CWFourCharType;
#define CWFOURCHAR(a, b, c, d) \
(((CWFourCharType) ((a) & 0xff) << 24) \
| ((CWFourCharType) ((b) & 0xff) << 16) \
| ((CWFourCharType) ((c) & 0xff) << 8) \
| ((CWFourCharType) ((d) & 0xff)))
#if CWPLUGIN_API == CWPLUGIN_API_UNIX
#include <sys/param.h>
#endif
#ifndef CW_USE_PRAGMA_EXPORT
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
#define CW_USE_PRAGMA_EXPORT 1
#else
#define CW_USE_PRAGMA_EXPORT 0
#endif
#endif
#ifndef CW_USE_PRAGMA_IMPORT
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
#define CW_USE_PRAGMA_IMPORT 1
#else
#define CW_USE_PRAGMA_IMPORT 0
#endif
#endif
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if CW_USE_PRAGMA_IMPORT
#pragma import on
#endif
/* These constants specify the action the IDE is asking the plugin to execute */
enum {
reqInitialize = -2, /* called when the plugin is loaded */
reqTerminate = -1, /* called when the plugin is unloaded */
reqIdle = -100, /* called periodically to allow for plugin tasks EP 6/24/98 */
reqAbout = -101, /* called to ask plugin to display about dialog EP 6/24/98 */
reqPrefsChange = -102 /* called when an associated pref panel changes EP 6/24/98 */
};
/* Used in CWFileInfo.dependencyType to indicate what type of make */
/* dependency to establish between files */
typedef enum CWDependencyType {
cwNoDependency, /* do not establish a dependency */
cwNormalDependency, /* recompile dependent whenever prereq changes */
cwInterfaceDependency /* recompile only if interface to file changes */
} CWDependencyType;
/* Used in CWFileInfo.filedatatype to indicate the type of data in a loaded file */
enum {
cwFileTypeUnknown, /* unknown binary data */
cwFileTypeText, /* normal text file */
cwFileTypePrecompiledHeader /* cached precompiled header */
};
/* constant for CWFileInfo.isdependentoffile */
#define kCurrentCompiledFile -1L
/* constant for CWStorePluginData/CWGetPluginData */
#define kTargetGlobalPluginData -1L
/* constant for CWNewProjectEntryInfo link order, segment, and overlay values */
#define kDefaultLinkPosition -1L
/* Selectors for CWFindLogicalDirectory */
enum {
kIDEDirectorySelector = 1, /* parent directory of IDE application; "bin" folder on Win32 */
kCodeWarriorDirectorySelector, /* root CodeWarrior directory */
kSystemDirectorySelector, /* system directory */
kProjectDirectorySelector, /* parent directory of current project */
kProjectDataDirectorySelector, /* project data directory */
kTargetDataDirectorySelector, /* target data directory (within project data directory) */
kTargetObjectCodeDirectorySelector, /* object code directory (within target data directory) */
kDebuggerCacheDirectorySelector, /* "CW Debugging Cache" directory */
kHelperAppsDirectorySelector, /* "(Helper Apps)" directory */
kPluginsDirectorySelector, /* "CodeWarrior Plugins" (Mac) or "plugins" (Win32) directory */
kPluginParentDirectorySelector, /* parent directory of current plugin */
kStationeryDirectorySelector, /* "(Project Stationery)" directory */
kRADStationeryDirectorySelector, /* "RAD Stationery" directory */
kLocalizedResourcesDirectorySelector /* "resources" directory */
};
/* CWPluginContext is a magic cookie passed to all plugins. It must */
/* be passed back to all IDE callbacks */
typedef struct CWPluginPrivateContext* CWPluginContext;
/* CWResult is the error/status result returned by all IDE API routine. */
/* The most common errors are returned directly. For OS-specific errors, the */
/* CWResult is cwErrOSError, and the OS-specific error can be obtained by */
/* calling CWGetOSError() */
typedef long CWResult;
/* CWMemHandle is an abstraction for memory used in some parts */
/* of the plugin API. API routines must be used to allocate */
/* and free CWMemHandles, or to convert them to pointers. */
typedef struct CWMemHandlePrivateStruct* CWMemHandle;
/* Used to identify custom data associated by a plugin with */
/* a project file or a target as a whole. Must be a four character */
/* constant. All lower case constants are reserved by the IDE */
typedef unsigned long CWDataType;
/* Some information used in the compiler/linker API is platform-dependent */
/* We use some typedefs to isolate the differences */
/* CWFileSpec contains the native platform file specifier. */
/* CWFileName contains the string type for a native file name */
/* CWFileTime contains the native platform file timestamp */
/* CWOSResult contains the native platform error return value */
/* CWResult contains an API routine error/status result */
/* CW_CALLBACK is a macro defining the calling convention and return type for */
/* IDE callback routines. */
/* CW_PLUGINENTRY is a macro defining the calling convention and return type for */
/* plugin entry points. */
/* CWSUCCESS is a macro that evaluates to true when given a CWResult indicating an */
/* routine succeeded */
#if CWPLUGIN_API == CWPLUGIN_API_MACOS
typedef FSSpec CWFileSpec;
typedef char CWFileName[32];
typedef unsigned long CWFileTime;
typedef OSErr CWOSResult;
#elif CWPLUGIN_API == CWPLUGIN_API_WIN32
typedef unsigned char Boolean;
typedef struct CWFileSpec { char path[MAX_PATH]; } CWFileSpec;
typedef char CWFileName[65];
typedef FILETIME CWFileTime;
typedef DWORD CWOSResult;
#elif CWPLUGIN_API == CWPLUGIN_API_UNIX
#define MAX_PATH MAXPATHLEN
#ifndef __MACTYPES__
typedef unsigned char Boolean;
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef struct CWFileSpec { char path[MAX_PATH]; } CWFileSpec;
typedef char CWFileName[65];
typedef time_t CWFileTime;
typedef int CWOSResult;
#else
#error Unknown plugin API!
#endif
#define CWSUCCESS(result) ((result) == 0)
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
#define CW_CALLBACK pascal CWResult
#define CW_CALLBACK_PTR(function_name) pascal CWResult (function_name)
#define CWPLUGIN_ENTRY(function_name) pascal short (function_name)
#elif CWPLUGIN_HOST == CWPLUGIN_HOST_WIN32
#define CW_CALLBACK CWResult __stdcall
#define CW_CALLBACK_PTR(function_name) CWResult (__stdcall function_name)
#define CWPLUGIN_ENTRY(function_name) short (__stdcall function_name)
#elif CWPLUGIN_HOST==CWPLUGIN_HOST_SOLARIS || CWPLUGIN_HOST==CWPLUGIN_HOST_LINUX
#define CW_CALLBACK CWResult
#define CW_CALLBACK_PTR(function_name) CWResult (function_name)
#define CWPLUGIN_ENTRY(function_name) short (function_name)
#else
#error Unknown plugin host!
#endif
/* information returned by CWFindAndLoadFile */
typedef struct CWFileInfo {
Boolean fullsearch; /* [<-] do we do a full search of paths for file */
char dependencyType; /* [<-] type CWDependencyType */
long isdependentoffile; /* [<-] this file is a dependent of file id */
/* (zero based) or -1L if of current file */
Boolean suppressload; /* [<-] find but don't load the file */
Boolean padding; /* [**] structure padding */
const char* filedata; /* [->] point to the file text/data, or NULL */
long filedatalength; /* [->] length of filedata */
short filedatatype; /* [->] type of data pointed to by filedata */
/* the remaining members are valid only when called by compilers */
short fileID; /* [->] use in browse records and dependencies */
CWFileSpec filespec; /* [->] specifies the file on disk */
Boolean alreadyincluded; /* [->] TRUE if already included in current compile */
Boolean recordbrowseinfo; /* [->] record browse info for this file? */
} CWFileInfo;
/* information maintained by the IDE for each segment in the project */
typedef struct CWProjectSegmentInfo {
char name[32]; /* segment name */
short attributes; /* segment attributes */
} CWProjectSegmentInfo;
/* 64 bit address */
typedef struct CWAddr64 {
long lo; /* low order longword of address */
long hi; /* high order longword of address */
} CWAddr64;
/* describes an overlay group, Use CWGetOverlayGroup1Info to iterate over overlay groups */
typedef struct CWOverlay1GroupInfo {
char name[256]; /* overlay group name */
CWAddr64 address; /* load address */
long numoverlays; /* number of overlays in this group */
} CWOverlay1GroupInfo;
/* describes an overlay, use CWGetOverlay1Info to iterate over overlays */
typedef struct CWOverlay1Info {
char name[256]; /* name of this overlay */
long numfiles; /* number of files in the overlay */
} CWOverlay1Info;
/* describes a file in an overlay, use CWGetOverlayFile1Info to iterate over files. Use */
/* whichfile in calls taking a file number, e.g. CWLoadObjectData or CWGetFileInfo */
typedef struct CWOverlay1FileInfo {
long whichfile; /* flat file number */
} CWOverlay1FileInfo;
/*
* All compiler errors or warnings which occur at some specific location in some
* source file are identified by a CWMessageRef structure. This structure
* provides sufficient information for the development environment to locate
* and display the exact position associated with a message. For each message,
* the compiler provides:
*
* errorstring: contains a description of the error, e.g. "syntax error"
* errorline: contains a subset of the text containing the error
* errorlevel: indicates if the "error" is an error, warning, or informational message
* CWMessageRef: further info so the IDE can perform two tasks:
* - Display a summary of each message, with the "error token"
* underlined within the compiler-provided errorline. This
* information is provided by the tokenoffset and tokenlength
* fields. If tokenLength is zero then no underlining is performed.
*
* - Open the file containing the error and select the full
* text of the error. This information is provided by the
* selectionoffset and selectionlength fields.
*/
typedef struct CWMessageRef
{
CWFileSpec sourcefile; /* file containing error */
long linenumber; /* error linenumber in file */
short tokenoffset; /* offset into errorline of token underline */
short tokenlength; /* length of error token to be underlined */
long selectionoffset; /* start of error for text selection */
long selectionlength; /* length of error for text selection */
} CWMessageRef;
/* message types, used for errorlevel parameter to message routines */
enum {
messagetypeInfo, /* informational only */
messagetypeWarning, /* warning message */
messagetypeError /* error message */
};
/* information maintained by the IDE for each file in the project */
typedef struct CWProjectFileInfo
{
CWFileSpec filespec; /* CW_FileSpec of file in project */
CWFileTime moddate; /* date source file was last modified */
short segment; /* segment number of file */
Boolean hasobjectcode; /* file has object code to be linked */
Boolean hasresources; /* file has resources to be linked */
Boolean isresourcefile; /* file -is- a resource file to be linked */
Boolean weakimport; /* file has "Import Weak" flag set */
Boolean initbefore; /* file has "Init Before" flag set */
Boolean gendebug; /* file has generate debug info on */
CWFileTime objmoddate; /* date object code was last modified */
CWFileName dropinname; /* name of dropin used to process this file */
short fileID; /* fileID to use in browse records */
Boolean recordbrowseinfo; /* record browse info for this file? */
Boolean reserved; /* reserved and used internally */
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
/* some Macintosh-specific information */
OSType filetype; /* MacOS file type */
OSType filecreator; /* MacOS file creator */
#endif
Boolean hasunitdata; /* file has associated unit data (Pascal) */
Boolean mergeintooutput; /* file has "Merge Into Output" flag set */
unsigned long unitdatadependencytag; /* dependency tag (i.e. checksum) of unit data (Pascal) */
} CWProjectFileInfo;
typedef struct CWNewTextDocumentInfo
{
const char* documentname; /* name for new document, can be NULL */
CWMemHandle text; /* initial text for document */
Boolean markDirty; /* mark doc as needing to be saved? */
} CWNewTextDocumentInfo;
typedef struct CWNewProjectEntryInfo
{ /* use kDefaultLinkPosition to get default link order, overlay, or segment */
long position; /* optional link order position */
long segment; /* optional segment number */
long overlayGroup; /* optional overlay group number */
long overlay; /* optional overlay number */
const char* groupPath; /* optional fully qualified path to file group */
Boolean mergeintooutput; /* set merge into output flag? */
Boolean weakimport; /* set weak import flag? */
Boolean initbefore; /* set initbefore flag? */
} CWNewProjectEntryInfo;
typedef struct CWIDEInfo
{
unsigned short majorVersion;
unsigned short minorVersion;
unsigned short bugFixVersion;
unsigned short buildVersion;
unsigned short dropinAPIVersion;
} CWIDEInfo;
/* Structures for getting the list of access paths. */
/* The callback does the filtering on the host flags, so the list returned */
/* will only contain the paths that are enabled for the host platform. */
/* There are separate APIs to get the Mac OS X framework style access paths. */
typedef enum CWAccessPathType {
cwSystemPath,
cwUserPath
} CWAccessPathType;
typedef struct CWAccessPathInfo
{
CWFileSpec pathSpec;
Boolean recursive;
long subdirectoryCount;
} CWAccessPathInfo;
typedef struct CWAccessPathListInfo
{
long systemPathCount;
long userPathCount;
Boolean alwaysSearchUserPaths;
Boolean convertPaths;
} CWAccessPathListInfo;
/* Structures for getting the list of Mac OS X framework access paths. */
/* The callback does the filtering on the host flags, so the list returned */
/* will only contain the Mac OS X framework style paths that are enabled for */
/* the host platform. */
/* There are separate APIs to get the traditional style access paths. */
typedef struct CWFrameworkAccessPathInfo
{
CWFileSpec pathSpec;
Boolean framework;
} CWFrameworkAccessPathInfo;
typedef struct CWFrameworkAccessPathListInfo
{
long systemPathCount;
long userPathCount;
Boolean alwaysSearchUserPaths;
Boolean convertPaths;
Boolean requireFrameworkIncludes;
} CWFrameworkAccessPathListInfo;
/* constants for different types of plugins */
/* Used in the dropintype in the DropInFlags, as well as for the MacOS file type */
enum
{
CWDROPINLINKERTYPE = CWFOURCHAR('L','i','n','k'), /* type for DropIn linkers */
CWDROPINCOMPILERTYPE= CWFOURCHAR('C','o','m','p'), /* type for DropIn compilers */
CWDROPINPREFSTYPE = CWFOURCHAR('P','a','n','L'), /* type for DropIn panels */
CWDROPINPREFSTYPE_1 = CWFOURCHAR('P','a','n','l'), /* type for 1.x IDE DropIn panels */
CWDROPINVCSTYPE = CWFOURCHAR('V','C','S',' '), /* type for DropIn version control */
CWDROPINCOMTYPE = CWFOURCHAR('C','O','M',' ') /* type for COM-only plugins */
};
typedef long CWPluginType; // one of the above types
/* Format of 'Flag' resources, or data returned by dropin's GetDropinFlags entry */
/* point. */
/* */
/* For the version 2 of these resource, we renamed the 'apiversion' field to */
/* 'earliestCompatibleAPIVersion' and added the 'newestAPIVersion' field. */
/* This allows plugins to support more than one API version and therefore run */
/* under more than one version of the IDE. The CWGetAPIVersion call should be used */
/* to determine what API version the IDE is using to talk to a plugin. */
#define kCurrentDropInFlagsVersion 2
typedef struct DropInFlags {
short rsrcversion; /* version number of resource */
CWDataType dropintype; /* dropin type (compiler, panel, etc) */
/* earliest API support by this plugin */
unsigned short earliestCompatibleAPIVersion;
unsigned long dropinflags; /* capability flags */
CWDataType edit_language; /* language */
unsigned short newestAPIVersion; /* newest API version supported */
} DropInFlags, **DropInFlagsHandle;
#define kCurrentCWPanelListVersion 1
typedef struct CWPanelList {
short version;
short count;
const char** names;
} CWPanelList;
#define kCurrentCWFamilyListVersion 1
#define kCurrentCWFamilyResourceVersion 1
typedef struct CWFamily {
CWDataType type;
const char* name;
} CWFamily;
typedef struct CWFamilyList {
short version;
short count;
CWFamily* families;
} CWFamilyList;
typedef struct CWFamilyResource {
short version;
CWDataType type;
unsigned char name[64];
} CWFamilyResource;
#define kCurrentCWHelpInfoVersion 1
typedef struct CWHelpInfo {
short version;
const char* helpFileName;
} CWHelpInfo;
#define kCurrentCWRelativePathVersion 1
typedef enum CWRelativePathFormat
{
format_Generic = 0, // Simple name, not platform-specific
format_Mac, // Uses : as separator :: for parent directory
format_Win, // Uses \ as separator .. for parent directory
format_Unix // Uses / as separator .. for parent directory
} CWRelativePathFormat;
typedef enum CWRelativePathTypes
{
type_Absolute = 0,
type_Project,
type_Compiler,
type_System,
type_UserDefined
} CWRelativePathTypes;
typedef struct CWRelativePath
{
short version; // version number
unsigned char pathType; // use CWRelativePathTypes
unsigned char pathFormat; // use CWRelativePathFormat
char userDefinedTree[256]; // user-defined tree name
char pathString[512]; // actual path string
} CWRelativePath;
/*
*
*/
#define kCurrentCWPluginInfoVersion 1
typedef struct CWPluginInfo
{
short version; // struct version number
const char* companyName; // i.e. Metrowerks
const char* pluginName; // Defaults to Dropin->GetName()
const char* pluginDisplayName;
const char* familyName; // i.e. Java
unsigned short majorIDEVersion; // Version of IDE Required
unsigned short minorIDEVersion;
} CWPluginInfo;
/* Declaration of plugin entry points that must be implemented by non-MacOS plugins */
/* It can also be implemented for MacOS plugins instead of having a 'Flag' resource */
CWPLUGIN_ENTRY (CWPlugin_GetDropInFlags)(const DropInFlags**, long* flagsSize);
/* Declaration of plugin entry points that may optionally be implemented by plugins */
/* These entry points override the corresponding resources on MacOS */
CWPLUGIN_ENTRY (CWPlugin_GetDropInName)(const char** dropInName);
CWPLUGIN_ENTRY (CWPlugin_GetDisplayName)(const char** displayName);
CWPLUGIN_ENTRY (CWPlugin_GetPanelList)(const CWPanelList** panelList);
CWPLUGIN_ENTRY (CWPlugin_GetFamilyList)(const CWFamilyList** familyList);
CWPLUGIN_ENTRY (CWPlugin_GetHelpInfo)(const CWHelpInfo** helpInfo);
/* Declaration of info plugin entry point that must be implemented by all COM plugins */
CWPLUGIN_ENTRY (CWPlugin_GetPluginInfo)(const CWPluginInfo** pluginInfo);
/* Callback declarations: these callbacks are supported for all CodeWarrior plugins */
/* Get the action the IDE is requesting of the plugin */
CW_CALLBACK CWGetPluginRequest(CWPluginContext context, long* request);
/* Call when finished handling a request, just before returning to the shell */
CW_CALLBACK CWDonePluginRequest(CWPluginContext, CWResult resultCode);
/* Get the version number of API used by the IDE to talk to the plugin */
CW_CALLBACK CWGetAPIVersion(CWPluginContext context, long* version);
/* Get information about the IDE being used */
CW_CALLBACK CWGetIDEInfo(CWPluginContext context, CWIDEInfo* info);
/* Get the OS error associated with the last callback */
CW_CALLBACK CWGetCallbackOSError(CWPluginContext context, CWOSResult* error);
/* Set the OS error associated with a failed plugin request */
CW_CALLBACK CWSetPluginOSError(CWPluginContext context, CWOSResult);
/* Get the file specifier for the current project */
CW_CALLBACK CWGetProjectFile(CWPluginContext context, CWFileSpec* projectSpec);
/* Get the directory where the IDE stores target-specific generated data */
CW_CALLBACK CWGetTargetDataDirectory(CWPluginContext context, CWFileSpec* targetDataDirectorySpec);
/* Get the name of the current target in the current project */
CW_CALLBACK CWGetTargetName(CWPluginContext context, char* name, short maxLength);
/* Get the directory where output files should be stored */
CW_CALLBACK CWGetOutputFileDirectory(CWPluginContext context, CWFileSpec* outputFileDirectory);
/* Get the number of files in the current project */
CW_CALLBACK CWGetProjectFileCount(CWPluginContext context, long* count);
/* Get information about a particular file in the project */
CW_CALLBACK CWGetFileInfo(CWPluginContext context, long whichfile, Boolean checkFileLocation, CWProjectFileInfo* fileinfo);
/* Search for a file by name on the current file's access paths. */
CW_CALLBACK CWFindAndLoadFile(CWPluginContext context, const char* filename, CWFileInfo *fileinfo);
/* Get the access paths for the current target */
CW_CALLBACK CWGetAccessPathListInfo(CWPluginContext context, CWAccessPathListInfo* pathListInfo);
CW_CALLBACK CWGetAccessPathInfo(CWPluginContext context, CWAccessPathType pathType, long whichPath, CWAccessPathInfo* pathInfo);
CW_CALLBACK CWGetAccessPathSubdirectory(CWPluginContext context, CWAccessPathType pathType, long whichPath, long whichSubdirectory, CWFileSpec* subdirectory);
CW_CALLBACK CWGetFrameworkAccessPathListInfo(CWPluginContext context, CWFrameworkAccessPathListInfo* pathListInfo);
CW_CALLBACK CWGetFrameworkAccessPathInfo(CWPluginContext context, CWAccessPathType pathType, long whichPath, CWFrameworkAccessPathInfo* pathInfo);
/* Get file text, from the editor, include file cache, or by reading the file */
CW_CALLBACK CWGetFileText(CWPluginContext context, const CWFileSpec* filespec, const char** text, long* textLength, short* filedatatype);
/* Release file text returned by CWFindAndLoadFile and CWGetFileText */
CW_CALLBACK CWReleaseFileText(CWPluginContext context, const char* text);
/* Get information about a project segment */
CW_CALLBACK CWGetSegmentInfo(CWPluginContext context, long whichsegment, CWProjectSegmentInfo* segmentinfo);
/* Get the number of overlay groups in the target */
CW_CALLBACK CWGetOverlay1GroupsCount(CWPluginContext context, long* count);
/* Get information about a project overlay group */
CW_CALLBACK CWGetOverlay1GroupInfo(CWPluginContext context, long whichgroup, CWOverlay1GroupInfo* groupinfo);
/* Get information about an overlay within a group */
CW_CALLBACK CWGetOverlay1Info(CWPluginContext context, long whichgroup, long whichoverlay, CWOverlay1Info* overlayinfo);
/* Get information about a file in an overlay */
CW_CALLBACK CWGetOverlay1FileInfo(CWPluginContext context, long whichgroup, long whichoverlay, long whichoverlayfile, CWOverlay1FileInfo* fileinfo);
/* Report a error, warning, or informational message */
CW_CALLBACK CWReportMessage(CWPluginContext context, const CWMessageRef* msgRef, const char *line1, const char *line2, short errorlevel, long errorNumber);
/* Display an alert. May actually be put in a message, depending on the plugin request */
CW_CALLBACK CWAlert(CWPluginContext context, const char* msg1, const char* msg2, const char* msg3, const char* msg4);
/* Display one or two status messages to the user */
CW_CALLBACK CWShowStatus(CWPluginContext context, const char *line1, const char *line2);
/* Give to the IDE to handle events and check if user has canceled this operation */
CW_CALLBACK CWUserBreak(CWPluginContext context);
/* Return stored preference data, referenced by name. Typically used for preference */
/* panel settings. */
CW_CALLBACK CWGetNamedPreferences(CWPluginContext context, const char* prefsname, CWMemHandle* prefsdata);
/* Store data referenced by a data type and file number */
CW_CALLBACK CWStorePluginData(CWPluginContext context, long whichfile, CWDataType type, CWMemHandle prefsdata);
/* Return stored data referenced by a data type and file number */
CW_CALLBACK CWGetPluginData(CWPluginContext context, long whichfile, CWDataType type, CWMemHandle* prefsdata);
/* Inform the IDE that a file modification date has changed. isGenerated is for use */
/* by compiler and linker plugins only */
CW_CALLBACK CWSetModDate(CWPluginContext context, const CWFileSpec* filespec, CWFileTime* moddate, Boolean isGenerated);
/* Ask the IDE to add a file to the current target in the current project. isGenerated */
/* is for use by compiler plugins only. */
CW_CALLBACK CWAddProjectEntry(CWPluginContext context, const CWFileSpec* fileSpec, Boolean isGenerated, const CWNewProjectEntryInfo* projectEntryInfo, long* whichfile);
/* Ask the IDE to remove a file from the current target (link-order/segment/overlay) in the current project. */
/* If it's the last target that contains the file, it would be removed from the file list. */
CW_CALLBACK CWRemoveProjectEntry(CWPluginContext context, const CWFileSpec* fileSpec);
/* Create a new editor window, supplying initial text and an optional document name */
CW_CALLBACK CWCreateNewTextDocument(CWPluginContext, const CWNewTextDocumentInfo* docinfo);
/* Allocate memory. Permanent memory is not freed until the plugin is unloaded. */
/* Temporary memory is freed after each plugin request completes. */
CW_CALLBACK CWAllocateMemory(CWPluginContext context, long size, Boolean isPermanent, void** ptr);
/* Free memory allocated via CWAllocateMemory */
CW_CALLBACK CWFreeMemory(CWPluginContext context, void* ptr, Boolean isPermanent);
/* Allocate a memory handle of the requested size. All handles are automatically */
/* freed at the end of each compiler/linker request. useTempMemory is MacOS-specific*/
CW_CALLBACK CWAllocMemHandle(CWPluginContext context, long size, Boolean useTempMemory, CWMemHandle* handle);
/* Free a memory handle */
CW_CALLBACK CWFreeMemHandle(CWPluginContext context, CWMemHandle handle);
/* Return the current size of a memory handle */
CW_CALLBACK CWGetMemHandleSize(CWPluginContext context, CWMemHandle handle, long* size);
/* Resize an existing memory handle */
CW_CALLBACK CWResizeMemHandle(CWPluginContext context, CWMemHandle handle, long newSize);
/* To obtain a pointer to the block, you must lock the handle */
/* moveHi is MacOS-specific */
CW_CALLBACK CWLockMemHandle(CWPluginContext context, CWMemHandle handle, Boolean moveHi, void** ptr);
/* Unlock a memory handle, the pointer returned by locking the handle may no */
/* longer be valid */
CW_CALLBACK CWUnlockMemHandle(CWPluginContext context, CWMemHandle handle);
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
/* Utility function to map MacOS error codes to a CWResult code. Plugins */
/* may internally generate OSErrs, but need to return CWResult to the */
/* CodeWarrior IDE */
CW_CALLBACK CWMacOSErrToCWResult(CWPluginContext context, OSErr err);
#endif
/* Turn off the built in PP window manager while the plugin displays a dialog */
CW_CALLBACK CWPreDialog(CWPluginContext context);
/* Turn on the built in PP window manager after the plugin is through with its */
/* dialog */
CW_CALLBACK CWPostDialog(CWPluginContext context);
/* Notify the IDE that the plugin will be performing actions on a file */
CW_CALLBACK CWPreFileAction(CWPluginContext context, const CWFileSpec *theFile);
/* Notify the IDE that the plugin is finished performing actions on a file */
CW_CALLBACK CWPostFileAction(CWPluginContext context, const CWFileSpec *theFile);
CW_CALLBACK CWResolveRelativePath(CWPluginContext context, const CWRelativePath* relativePath, CWFileSpec* fileSpec, Boolean create);
CW_CALLBACK CWFindLogicalDirectory(CWPluginContext context, long selector, CWFileSpec *dirSpec);
CW_CALLBACK CWOpenFileInEditor(CWPluginContext context, const CWFileSpec *fileSpec);
#if CWPLUGIN_HOST==CWPLUGIN_HOST_SOLARIS || CWPLUGIN_HOST==CWPLUGIN_HOST_LINUX
/* Forward declarations */
struct ICodeWarriorApp;
struct ICodeWarriorProject;
struct ICodeWarriorDesign;
struct ICodeWarriorTarget;
#endif /* CWPLUGIN_HOST==CWPLUGIN_HOST_SOLARIS || CWPLUGIN_HOST==CWPLUGIN_HOST_LINUX */
/* Get the IDE application COM interface. Fails if called from any thread */
/* other than the main IDE thread, e.g. a build thread. */
CW_CALLBACK CWGetCOMApplicationInterface(CWPluginContext context, struct ICodeWarriorApp **app);
/* Get the current project COM interface. Adds a reference upon return. */
/* Only succeeds if the plugin is being called in the context of a */
/* particular project. Fails if called from any thread */
/* other than the main IDE thread, e.g. a build thread. */
CW_CALLBACK CWGetCOMProjectInterface(CWPluginContext context, struct ICodeWarriorProject **project);
/* Get the current design COM interface. Adds a reference upon return. */
/* Only succeeds if the plugin is being called in the context of a */
/* particular target that is associated with a design. */
/* Fails if called from any thread other than the main IDE thread, */
/* e.g. a build thread. */
CW_CALLBACK CWGetCOMDesignInterface(CWPluginContext context, struct ICodeWarriorDesign **design);
/* Get the current target COM interface. Adds a reference upon return. */
/* Only succeeds if the plugin is being called in the context of a */
/* particular target. Fails if called from any thread */
/* other than the main IDE thread, e.g. a build thread. */
CW_CALLBACK CWGetCOMTargetInterface(CWPluginContext context, struct ICodeWarriorTarget **target);
#if CW_USE_PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif /* __CWPlugins_H__ */
\ No newline at end of file diff --git a/sdk_hdrs/CWRuntimeFeatures.h b/sdk_hdrs/CWRuntimeFeatures.h new file mode 100755 index 0000000..003020c --- /dev/null +++ b/sdk_hdrs/CWRuntimeFeatures.h @@ -0,0 +1 @@ +/*****************************************************************************/
/* Name......: CWRuntimeFeatures.h */
/* Purpose...: Macros to parameterize your runtime environment based on */
/* platform-specific compiler macros. Target/host */
/* configurations to set host/target values as well as */
/* CW_HOST, CW_HOSTOS, CW_HOST_ENDIAN, CW_LINE_ENDING, */
/* and CW_UNIX_TYPE, which is used to discriminate among */
/* the various UNIX versions. */
/* Info......: These settings are common enough to factor into a location */
/* that can be shared by all components, including those */
/* used internally and those shared externally. */
/* Copyright.: ©Copyright 2000 by metrowerks inc. All rights reserved. */
/*****************************************************************************/
#ifndef CW_RuntimeFeatures_H
#define CW_RuntimeFeatures_H
/*************************
* Runtime Definitions *
*************************/
/* host / target processors values used to set HOST macro. */
#define CW_MC68K 1
#define CW_POWERPC 2
#define CW_INTEL 3
#define CW_MIPS 4
#define CW_SPARC 5
#define CW_PA_RISC 6
/* host / target operating systems values used to set CW_HOSTOS macro. */
#define CW_MACOS 1
#define CW_BEWORKS 2
#define CW_UNIX 3
#define CW_MSWIN 4
#define CW_MAGIC 5
#define CW_QNX 11
/* UNIX specialization values used to set the CW_UNIX_TYPE macro. */
#define CW_SOLARIS 32 /* Base value to support bit manipulation */
#define CW_LINUX 33
#define CW_RHAPSODY 34
#define CW_HPUX 35
#define CW_IRIX 36
#define CW_AIX 37
#define CW_FREEBSD 38
/* big/little endian values used to set CW_HOST_ENDIAN macro. */
#define CW_ENDIAN_NEUTRAL 0x7fffffff
#define CW_BIG_ENDIAN 1
#define CW_LITTLE_ENDIAN 2
#define CW_EITHER_ENDIAN 3
/*
** Detemine run-time environment settings based on clues from the
** compile time settings given by specific compilers.
*/
#if defined(__MWERKS__)
/* Metrowerks Compiler */
#if macintosh && __MC68K__
/* 68K MacOS */
#define CW_HOST CW_MC68K
#define CW_HOSTOS CW_MACOS
#define CW_HOST_ENDIAN CW_BIG_ENDIAN
#define CW_LINE_ENDING "\r"
#elif macintosh && __POWERPC__
/* PPC MacOS */
#define CW_HOST CW_POWERPC
#define CW_HOSTOS CW_MACOS
#define CW_HOST_ENDIAN CW_BIG_ENDIAN
#define CW_LINE_ENDING "\r"
#elif __INTEL__ && defined(__BEOS__)
/* x86 BeOS */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_BEWORKS
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __INTEL__ && defined(__QNX__)
/* x86 QNX */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_QNX
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __INTEL__ && __linux__
/* x86 Linux */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_UNIX
#define CW_UNIX_TYPE CW_LINUX
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __INTEL__ /* default to Win32 */
/* x86 Assuming Windows */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_MSWIN
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\r\n"
#else
#error "UNKNOWN CW COMPILER USE"
#endif
#elif defined(__GNUC__)
/* GCC/EGCS Compiler */
#if __i386__ && __linux__
/* x86 Linux */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_UNIX
#define CW_UNIX_TYPE CW_LINUX
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __i386__ && __sun__
/* x86 Solaris */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_UNIX
#define CW_UNIX_TYPE CW_SOLARIS
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __sparc__ && __linux__
/* SPARC Linux */
#define CW_HOST CW_SPARC
#define CW_HOSTOS CW_UNIX
#define CW_UNIX_TYPE CW_LINUX
#define CW_HOST_ENDIAN CW_BIG_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __sparc__ && __sun__
/* SPARC Solaris */
#define CW_HOST CW_SPARC
#define CW_HOSTOS CW_UNIX
#define CW_UNIX_TYPE CW_SOLARIS
#define CW_HOST_ENDIAN CW_BIG_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __i386__ && __BEOS__
/* x86 BeOS */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_BEWORKS
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\n"
#elif __powerpc__ && __linux__
/* PPC Linux */
#define CW_HOST CW_POWERPC
#define CW_HOSTOS CW_UNIX
#define CW_UNIX_TYPE CW_LINUX
#define CW_HOST_ENDIAN CW_BIG_ENDIAN
#define CW_LINE_ENDING "\n"
#else
#error "UNKNOWN GNU COMPILER USE"
#endif
#elif defined(_MSC_VER)
/* Microsoft VC Compiler */
#if defined(_M_IX86)
/* x86 Windows */
#define CW_HOST CW_INTEL
#define CW_HOSTOS CW_MSWIN
#define CW_HOST_ENDIAN CW_LITTLE_ENDIAN
#define CW_LINE_ENDING "\r\n"
#else
#error "UNKNOWN MSC COMPILER USE"
#endif
#else
#error "UNKNOWN COMPILER"
#endif
#endif /* CW_RuntimeFeatures_H */
\ No newline at end of file diff --git a/sdk_hdrs/CWUnixPluginPrefix.h b/sdk_hdrs/CWUnixPluginPrefix.h new file mode 100755 index 0000000..a261ea3 --- /dev/null +++ b/sdk_hdrs/CWUnixPluginPrefix.h @@ -0,0 +1 @@ +/*
* CWUnixPluginPrefix.h
*
* Copyright © 1999 Metrowerks, Inc. All rights reserved.
*
*/
#ifndef MW_CWUnixPluginPrefix_H
#define MW_CWUnixPluginPrefix_H
#define CW_USE_PRAGMA_EXPORT 0
#include "CWRuntimeFeatures.h"
#ifdef __MWERKS__
#if !__option(bool)
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#endif
#endif
#endif /* MW_CWUnixPluginPrefix_H */
\ No newline at end of file diff --git a/sdk_hdrs/CWWinPluginPrefix.h b/sdk_hdrs/CWWinPluginPrefix.h new file mode 100755 index 0000000..4ad49af --- /dev/null +++ b/sdk_hdrs/CWWinPluginPrefix.h @@ -0,0 +1 @@ +#include <Win32Headers.mch>
#ifndef WIN32
#define WIN32 1
#endif
#define CW_USE_PRAGMA_EXPORT 0
#ifdef __MWERKS__
#if !__option(bool)
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#endif
#endif
\ No newline at end of file diff --git a/sdk_hdrs/CatTypes.h b/sdk_hdrs/CatTypes.h new file mode 100755 index 0000000..421622b --- /dev/null +++ b/sdk_hdrs/CatTypes.h @@ -0,0 +1 @@ +#ifndef __CATTYPES_H__
#define __CATTYPES_H__
typedef int CatNodeID;
#define NODE_NULL -1
#define NODE_ROOT 0
#define kCatalogClass "CodeWarrior.CatalogModelObject"
#define kFolderClass "CodeWarrior.FolderModelObject"
#define kTrashNodeClass "CodeWarrior.TrashNode"
// internal properties used in the catalog
#define kContentsFolder "ContentsFolder"
#define kClass "Class"
#define kComments "Comments"
#define kFile "File"
#define kNodeLocked "Locked"
#define kModDate "Modified"
#define kName "Name"
#define kID "ID"
#define kFolderSuffix "_Contents"
#define kDefCatalogExt "ctlg"
#define kDefCatalogFolderExt "ctlgf"
// Command group ID for commands in the catalog menu...
const long cmdGroup_CatalogMenu = 10000;
// catalog-specific menu commands to go with those defined by the IDE;
// such as cmd_Cut, cmd_Copy, etc.
const long cmd_CatalogRename = 10000; // plugin commands in the range 10000-10999
const long cmd_CatalogProperties = 10001;
const long cmd_ShowCatalogBrowser = 10002;
const long cmd_ShowCatalogPalette = 10003;
const long cmd_NewCatalog = 10004;
const long cmd_NewFolder = 10005;
const long cmd_OpenCatalog = 10006;
const long cmd_CloseCatalog = 10007;
const long cmd_ImportControls = 10008;
const long cmd_ShowPrevious = 10009;
const long cmd_ShowNext = 10010;
const long cmd_ExpandIndexView = 10011;
const long cmd_CollapseIndexView = 10012;
const long cmd_ToggleIndexView = 10013;
const long cmd_CloseCatalogPalette = 10014;
enum UPDATE_TYPE
{
UPDATE_NONE = 0,
UPDATE_CHILDREN,
UPDATE_DESCENDANTS
};
enum CatTransType
{
CATTRANS_TYPE_UNKNOWN,
CATTRANS_TYPE_ALIAS,
CATTRANS_TYPE_COPY,
CATTRANS_TYPE_DELETE,
CATTRANS_TYPE_DROP,
CATTRANS_TYPE_EDITPROPERTIES,
CATTRANS_TYPE_LOCK,
CATTRANS_TYPE_MOVE,
CATTRANS_TYPE_PASTE,
CATTRANS_TYPE_RENAME,
CATTRANS_TYPE_UNLOCK
};
struct CatWindowData
{
bool fUseDefSize;
bool fUseDefPos;
SIZE size;
POINT pos;
CatWindowData() : fUseDefSize(true), fUseDefPos(true)
{
pos.x = pos.y = 0;
size.cx = size.cy = 0;
}
};
#endif // __CATTYPES_H__
\ No newline at end of file diff --git a/sdk_hdrs/CompilerMapping.h b/sdk_hdrs/CompilerMapping.h new file mode 100755 index 0000000..30ee355 --- /dev/null +++ b/sdk_hdrs/CompilerMapping.h @@ -0,0 +1 @@ +/*
* CompilerMapping.h - File Type & Extension => Compiler Mapping for Metrowerks CodeWarriorª
*
* Copyright © 1995 Metrowerks, Inc. All rights reserved.
*
*/
#ifndef __COMPILERMAPPING_H__
#define __COMPILERMAPPING_H__
#ifdef __MWERKS__
# pragma once
#endif
#ifndef __CWPLUGINS_H__
#include "CWPlugins.h"
#endif
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
const CWDataType Lang_C_CPP = CWFOURCHAR('c','+','+',' ');
const CWDataType Lang_Pascal = CWFOURCHAR('p','a','s','c');
const CWDataType Lang_Rez = CWFOURCHAR('r','e','z',' ');
const CWDataType Lang_Java = CWFOURCHAR('j','a','v','a');
const CWDataType Lang_MISC = CWFOURCHAR('\?','\?','\?','\?');
#else
#define Lang_C_CPP CWFOURCHAR('c','+','+',' ')
#define Lang_Pascal CWFOURCHAR('p','a','s','c')
#define Lang_Rez CWFOURCHAR('r','e','z',' ')
#define Lang_Java CWFOURCHAR('j','a','v','a')
#define Lang_MISC CWFOURCHAR('\?','\?','\?','\?')
#endif
/* Compiler flags, as used in member dropinflags of struct DropInFlags returned by compilers */
enum
{
kGeneratescode = 1L << 31, /* this compiler generates code */
kGeneratesrsrcs = 1L << 30, /* this compiler generates resources */
kCanpreprocess = 1L << 29, /* this compiler can accept a Preprocess request */
kCanprecompile = 1L << 28, /* this compiler can accept a Precompile request */
kIspascal = 1L << 27, /* this is the pascal compiler */
kCanimport = 1L << 26, /* this compiler needs the "Import Weak" popup */
kCandisassemble = 1L << 25, /* this compiler can disassemble */
kPersistent = 1L << 24, /* keep the compiler resident except on context switches*/
kCompAllowDupFileNames = 1L << 23, /* allow multiple project files with the same name */
kCompMultiTargAware = 1L << 22, /* the compiler can be used with multiple targets */
kIsMPAware = 1L << 21, /* the compiler can be run in an MP thread */
kCompUsesTargetStorage = 1L << 20, /* the compiler keeps storage per target */
kCompEmitsOwnBrSymbols = 1L << 19, /* browser info includes compiler-specific symbols */
kCompAlwaysReload = 1L << 18, /* always reload the compiler before request */
kCompRequiresProjectBuildStartedMsg = 1L << 17, /* Compiler listens for project build started messages */
kCompRequiresTargetBuildStartedMsg = 1L << 16, /* Compiler listens for target build started messages */
kCompRequiresSubProjectBuildStartedMsg = 1L << 15, /* Compiler listens for Sub project build started messages */
kCompRequiresFileListBuildStartedMsg = 1L << 14, /* Compiler listens for filelist build started messages */
kCompReentrant = 1L << 13, /* Compiler can use re-entrant DropIn and is re-entry safe */
kCompSavesDbgPreprocess = 1 << 12, /* Compiler will save preprocessed files for debugging needs */
kCompRequiresTargetCompileStartedMsg = 1 << 11 /* Compiler listens for target compile started/ended messages */
/* remaining flags are reserved for future use and should be zero-initialized */
};
/* Compiler mapping flags, used in CompilerMapping.flags & CWExtensionMapping.flags */
typedef unsigned long CompilerMappingFlags;
enum
{
kPrecompile = 1L << 31, /* should this file type be Precompiled? */
kLaunchable = 1L << 30, /* can this file type be double-clicked on? */
kRsrcfile = 1L << 29, /* does this file type contain resources for linking? */
kIgnored = 1L << 28 /* should files of this type be ignored during Make? */
/* remaining flags are reserved for future use and should be zero-initialized */
};
/* Format of data in 'EMap' resource, or as returned by a compiler's */
/* GetExtensionMapping entry point */
typedef struct CWExtensionMapping {
CWDataType type; /* MacOS file type, e.g. 'TEXT' or 0 */
char extension[32]; /* file extension, e.g. .c/.cp/.pch or "" */
CompilerMappingFlags flags; /* see above */
char editlanguage[32]; /* edit language or "" to use default language for plugin */
} CWExtensionMapping;
#define kCurrentCWExtMapListVersion 2
#define kCurrentCWExtMapListResourceVersion 2
typedef struct CWExtMapList {
short version;
short nMappings;
CWExtensionMapping* mappings;
} CWExtMapList;
/* Format of data returned by GetTargetList entry point */
#define kCurrentCWTargetListVersion 1
#define kCurrentCWTargetListResourceVersion 1
typedef struct CWTypeList {
short count;
CWDataType items[1];
} CW_CPUList, CW_OSList;
typedef struct CWTargetList {
short version;
short cpuCount;
CWDataType* cpus;
short osCount;
CWDataType* oss;
} CWTargetList;
typedef struct CWTargetListResource {
short version;
CW_CPUList cpus;
CW_OSList oss;
} CWTargetListResource;
#ifdef __cplusplus
}
#endif
#ifdef _MSC_VER
#pragma pack(pop,2)
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif /* __COMPILERMAPPING_H__ */
\ No newline at end of file diff --git a/sdk_hdrs/DropInCompilerLinker.h b/sdk_hdrs/DropInCompilerLinker.h new file mode 100755 index 0000000..8551a86 --- /dev/null +++ b/sdk_hdrs/DropInCompilerLinker.h @@ -0,0 +1 @@ +/*
* DropInCompilerLinker.h - Drop-In Interface for Metrowerks CodeWarriorª Compilers and Linkers
*
* Copyright © 1996 Metrowerks, Inc. All rights reserved.
*
*/
#ifndef __DROPINCOMPILERLINKER_H__
#define __DROPINCOMPILERLINKER_H__
#ifdef __MWERKS__
# pragma once
#endif
#ifndef __CWPlugins_H__
#include "CWPlugins.h"
#endif
#ifndef __COMPILERMAPPING_H__
#include "CompilerMapping.h"
#endif
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if CW_USE_PRAGMA_IMPORT
#pragma import on
#endif
/* this is the current version number of the API documented herein */
#define DROPINCOMPILERLINKERAPIVERSION_4 4
#define DROPINCOMPILERLINKERAPIVERSION_5 5
#define DROPINCOMPILERLINKERAPIVERSION_6 6
#define DROPINCOMPILERLINKERAPIVERSION_7 7
#define DROPINCOMPILERLINKERAPIVERSION_8 8
#define DROPINCOMPILERLINKERAPIVERSION_9 9
#define DROPINCOMPILERLINKERAPIVERSION_10 10
#define DROPINCOMPILERLINKERAPIVERSION_11 11
#define DROPINCOMPILERLINKERAPIVERSION_12 12
#define DROPINCOMPILERLINKERAPIVERSION_13 13
#define DROPINCOMPILERLINKERAPIVERSION DROPINCOMPILERLINKERAPIVERSION_13
/* deprecated request codes */
enum {
reqInitCompiler = reqInitialize, /* (called when compiler is loaded) */
reqTermCompiler = reqTerminate, /* (called when compiler is unloaded) */
reqInitLinker = reqInitialize, /* (called when linker is loaded) */
reqTermLinker = reqTerminate /* (called when linker is unloaded) */
};
/* request codes (common) */
enum {
reqTargetCompileEnded = -17, /* Sent when target's compile phase ends */
reqTargetCompileStarted = -16, /* Sent when target's compile phase starts */
reqTargetLinkEnded = -15, /* Sent when the link has ended */
reqTargetLinkStarted = -14, /* Sent when the link starts */
reqFileListBuildEnded = -13, /* Sent when the group file build ends */
reqFileListBuildStarted = -12, /* Sent when the group file build starts */
reqSubProjectBuildEnded = -11, /* Sent when subproject's build ends */
reqSubProjectBuildStarted = -10, /* Sent when subproject's build starts */
reqTargetBuildEnded = -9, /* Sent when target's build ends */
reqTargetBuildStarted = -8, /* Sent when target's build starts */
reqProjectBuildEnded = -7, /* Sent when project build ends */
reqProjectBuildStarted = -6, /* Sent when project build starts */
reqTargetLoaded = -5, /* called when the "keeps target info" flag is set */
reqTargetPrefsChanged = -4, /* called when the "keeps target info" flag is set */
reqTargetUnloaded = -3 /* called when the "keeps target info" flag is set */
};
/* requests codes (compilers) */
enum {
reqCompile = 0, /* compile/precompile/preprocess source file */
/* and return results */
reqMakeParse, /* used internally by Metrowerks */
reqCompDisassemble, /* disassemble a specific file in the project */
reqCheckSyntax, /* check syntax, but don't generate code */
reqPreprocessForDebugger /* when preprocess, don't open window w/results */
};
/* requests codes (linkers) */
enum {
reqLink = 0, /* link project and generate executable or library */
reqDisassemble, /* disassemble a specific file in the project */
reqTargetInfo, /* get info about the generated executable */
reqPreRun /* give linker a last chance to modify target info */
};
/* Returned as part of CWFileInfo to indicate the */
/* type of data pointed to by the filedata pointer */
enum {
filetypeText, /* data is text */
filetypeUnknown /* unknown type, could be precompiled header */
};
/* executable linkage types, used in CWTargetInfo.linkType */
enum {
exelinkageFlat, /* flat executable */
exelinkageSegmented, /* uses 68K code segments */
exelinkageOverlay1 /* uses overlay groups and overlays */
};
/* output file type, used in CWTargetInfo.outputType */
enum {
linkOutputNone, /* linker produces no output */
linkOutputFile, /* linker produces a file */
linkOutputDirectory /* linker produces a directory */
};
/* Constants for the targetCPU field of the CWTargetInfo struct */
enum {
targetCPU68K = CWFOURCHAR('6','8','k',' '),
targetCPUPowerPC = CWFOURCHAR('p','p','c',' '),
targetCPUi80x86 = CWFOURCHAR('8','0','8','6'),
targetCPUMips = CWFOURCHAR('m','i','p','s'),
targetCPUNECv800 = CWFOURCHAR('v','8','0','0'),
targetCPUEmbeddedPowerPC = CWFOURCHAR('e','P','P','C'),
targetCPUARM = CWFOURCHAR('a','r','m',' '),
targetCPUSparc = CWFOURCHAR('s','p','r','c'),
targetCPUIA64 = CWFOURCHAR('I','A','6','4'),
targetCPUAny = CWFOURCHAR('*','*','*','*'),
targetCPUMCORE = CWFOURCHAR('m','c','o','r'),
targetCPU_Intent = CWFOURCHAR('n','t','n','t')
};
/* Constants for the targetOS field of the CWTargetInfo struct */
enum {
targetOSMacintosh = CWFOURCHAR('m','a','c',' '),
targetOSWindows = CWFOURCHAR('w','i','n','t'),
targetOSNetware = CWFOURCHAR('n','l','m',' '),
targetOSMagicCap = CWFOURCHAR('m','c','a','p'),
targetOSOS9 = CWFOURCHAR('o','s','9',' '),
targetOSEmbeddedABI = CWFOURCHAR('E','A','B','I'),
targetOSJava = CWFOURCHAR('j','a','v','a'), /* java (no VM specification) */
targetOSJavaMS = CWFOURCHAR('j','v','m','s'), /* Microsoft VM */
targetOSJavaSun = CWFOURCHAR('j','v','s','n'), /* Sun VM */
targetOSJavaMRJ = CWFOURCHAR('j','v','m','r'), /* MRJ VM */
targetOSJavaMW = CWFOURCHAR('j','v','m','w'), /* Metrowerks VM */
targetOSPalm = CWFOURCHAR('p','a','l','m'),
targetOSGTD5 = CWFOURCHAR('g','t','d','5'),
targetOSSolaris = CWFOURCHAR('s','l','r','s'),
targetOSLinux = CWFOURCHAR('l','n','u','x'),
targetOSAny = CWFOURCHAR('*','*','*','*'),
targetOS_Intent = CWFOURCHAR('n','t','n','t')
};
/* linker flags, as used in member dropinflags of DropInFlags struct returned by linkers */
enum {
cantDisassemble = 1L << 31, /* this linker doesn't support 'Disassemble' */
isPostLinker = 1L << 30, /* this is a post linker */
linkAllowDupFileNames = 1L << 29, /* allow multiple project files with the same name */
linkMultiTargAware = 1L << 28, /* the linker can be used with multiple targets */
isPreLinker = 1L << 27, /* this is a pre linker */
linkerUsesTargetStorage = 1L << 26, /* the linker keeps storage per target */
linkerUnmangles = 1L << 25, /* The linker supports unmangling. */
magicCapLinker = 1L << 24, /* Pre- or post-linker is used for MagicCap */
linkAlwaysReload = 1L << 23, /* Always reload the linker before request */
linkRequiresProjectBuildStartedMsg = 1L << 22, /* Linker listens for a Project Build Started/Ended message */
linkRequiresTargetBuildStartedMsg = 1L << 21, /* Linker listens for a Target Build Started/Ended message */
linkRequiresSubProjectBuildStartedMsg = 1L << 20, /* Linker listens for a Sub Project Build Started/Ended message */
linkRequiresFileListBuildStartedMsg = 1L << 19, /* Linker listens for a File List Build Started/Ended message */
linkRequiresTargetLinkStartedMsg = 1L << 18, /* Linker listens for a Target Link Started/Ended message */
linkerWantsPreRunRequest = 1L << 17, /* Linker wants to be sent the pre-run request */
linkerGetTargetInfoThreadSafe = 1L << 16, /* GetTargetInfo call doesn't use any globals, etc. */
linkerUsesCaseInsensitiveSymbols = 1L << 15, /* All languages used by linker contain case insensitive browser symbols */
linkerDisasmRequiresPreprocess = 1L << 14, /* (obsolete) file must be preprocesed before being passed to linker for disasm */
linkerUsesFrameworks = 1L << 13, /* target uses frameworks; enables framework-style file searching */
linkerInitializeOnMainThread = 1L << 12 /* The Linker needs to be intialized on the main thread. */
/* remaining flags are reserved for future use and should be zero-initialized */
};
/* ways to store dependency returned as CWFileSpec in StoreObjectData */
enum {
cwAccessAbsolute,
cwAccessPathRelative,
cwAccessFileName,
cwAccessFileRelative
};
/* specifies what browser information compilers should generate */
/* they should always generate records for globals and functions */
typedef struct CWBrowseOptions {
Boolean recordClasses; /* [<-] do we record info for classes */
Boolean recordEnums; /* [<-] do we record info for enums */
Boolean recordMacros; /* [<-] do we record info for macros */
Boolean recordTypedefs; /* [<-] do we record info for typedefs */
Boolean recordConstants; /* [<-] do we record info for constants */
Boolean recordTemplates; /* [<-] do we record info for templates */
Boolean recordUndefinedFunctions; /* [<-] do we record info for undefined functions */
long reserved1; /* reserved space */
long reserved2; /* reserved space */
} CWBrowseOptions;
/* A dependency tag is associated with unit data in the StoreUnitData callback. It should */
/* change whenever unit data has changed in a way that forces its dependents to be rebuilt. */
/* Typically, it is just a checksum on the unit data. */
typedef unsigned long CWDependencyTag;
/* dependency information passed back in StoreObjectData */
typedef struct CWDependencyInfo {
long fileIndex; /* Another project entry. -1 => use fileSpec */
CWFileSpec fileSpec; /* location of file. Only used if fileIndex < 0 */
short fileSpecAccessType; /* One of cwAccessAbsolute, etc. above. Only */
/* used is specifying via fileSpec. */
short dependencyType; /* cwNormalDependency or cwInterfaceDependency. */
/* Values defined in CWPlugins.h */
} CWDependencyInfo;
/* information used when calling StoreObjectData */
typedef struct CWObjectData {
CWMemHandle objectdata; /* Handle to generated object code, */
/* resource data, or preprocessed text */
CWMemHandle browsedata; /* Handle to generated browse data */
long reserved1; /* reserved for future use, set to zero */
long codesize; /* size of generated code */
long udatasize; /* size of uninitialized data */
long idatasize; /* size of initialized data */
long compiledlines; /* number of lines of source compiled */
Boolean interfaceChanged; /* recompile interface dependents? */
long reserved2; /* reserved for future use, set to zero */
void* compilecontext; /* used internally by Metrowerks */
CWDependencyInfo* dependencies; /* optional array of dependencies */
short dependencyCount; /* overrides those collected by IDE */
CWFileSpec* objectfile; /* external object code file (i.e. .o file) */
} CWObjectData;
/* characteristics of a link target */
typedef struct CWTargetInfo {
short outputType; /* outputs file, directory, or nothing */
CWFileSpec outfile; /* generated executable file/folder spec */
CWFileSpec symfile; /* generated debug file spec */
CWFileSpec runfile; /* file to run, can be same or different from outfile */
short linkType; /* flat, segmented, or overlays */
Boolean canRun; /* "Run" can be performed on this target */
Boolean canDebug; /* "Run with Debugger" can be performed on this target */
CWDataType targetCPU; /* target CPU architecture (e.g. 68K, PowerPC, x86, MIPS)*/
CWDataType targetOS; /* target OS (e.g. MacOS, Windows, Unix) */
#if CWPLUGIN_HOST == CWPLUGIN_HOST_MACOS
OSType outfileCreator; /* file creator, if outputType == linkOutputFile */
OSType outfileType; /* file type, if outputType == linkOutputFile */
OSType debuggerCreator; /* file creator of debugger for this target */
OSType runHelperCreator; /* creator of helper app to use when running this file. */
#endif
#if CWPLUGIN_HOST == CWPLUGIN_HOST_WIN32
Boolean runHelperIsRegKey; /* true if runHelperName is a registry key */
Boolean debugHelperIsRegKey;/* true if debugHelperName is a registry key */
char args[512]; /* command line arguments */
char runHelperName[512]; /* full path to the run helper executable or a reg key */
Boolean runHelperRequiresURL;/* Indicates whether the outfile must be converted to */
/* a file scheme URL before being passed to the run */
/* helper app */
char reserved2;
char debugHelperName[512];/* full path to the debug helper executable or a reg key*/
#endif
// We need the args for Solaris
#if (CWPLUGIN_HOST == CWPLUGIN_HOST_SOLARIS || CWPLUGIN_HOST == CWPLUGIN_HOST_LINUX)
char args[512]; /* command line arguments */
char runHelperName[512]; /* Relative path name from (Helper Apps) to run helper program */
Boolean runHelperRequiresURL; /* Indicates whether the outfile must be converted to */
/* a file scheme URL before being passed to the run */
/* helper app */
char reserved2[3];
char debugHelperName[512]; /* Relative path name from (Helper Apps) to debug helper */
#endif
CWFileSpec linkAgainstFile; /* file parent targets link against (e.g. lib file) */
} CWTargetInfo;
typedef struct CWUnmangleInfo {
void* targetStorage;
const char* mangledName;
char* unmangleBuff;
long unmangleBuffSize;
unsigned short browserClassID;
unsigned char browserLang;
unsigned char filler1;
} CWUnmangleInfo;
/* Types used to get compiler-specific browser symbol information. */
typedef struct CWCompilerBrSymbol {
char symName[32];
char symUIName[32];
} CWCompilerBrSymbol;
typedef struct CWCompilerBrSymbolList {
short count;
CWCompilerBrSymbol items[1];
} CWCompilerBrSymbolList;
typedef struct CWCompilerBrSymbolInfo {
void* targetStorage;
CWCompilerBrSymbolList* symList; /* [<-] Compiler should put a pointer to the read-only list here.*/
} CWCompilerBrSymbolInfo;
typedef struct CWFrameworkInfo {
CWFileSpec fileSpec; /* location of ".framework" directory */
char version[256]; /* which version directory to use; if empty use "Current" sym link */
} CWFrameworkInfo;
/*** Declaration of plugin entry points that must be implemented by non-MacOS plugins ***/
/*** It can also be implemented by a MacOS plugin to override the 'Targ' resource ***/
CWPLUGIN_ENTRY (CWPlugin_GetTargetList)(const struct CWTargetList**);
/*** Optional entry points ***/
CWPLUGIN_ENTRY (CWPlugin_GetDefaultMappingList)(const struct CWExtMapList**);
CWPLUGIN_ENTRY (Helper_Unmangle)(CWUnmangleInfo*);
CWPLUGIN_ENTRY (Helper_GetCompilerBrSymbols)(CWCompilerBrSymbolInfo*);
/*** callbacks to the IDE, in addition to those in CWPlugins.h ***/
CW_CALLBACK CWIsPrecompiling(CWPluginContext context, Boolean* isPrecompiling);
CW_CALLBACK CWIsAutoPrecompiling(CWPluginContext context, Boolean* isAutoPrecompiling);
CW_CALLBACK CWIsPreprocessing(CWPluginContext context, Boolean* isPreprocessing);
CW_CALLBACK CWIsGeneratingDebugInfo(CWPluginContext context, Boolean* isGenerating);
CW_CALLBACK CWIsCachingPrecompiledHeaders(CWPluginContext context, Boolean* isCaching);
CW_CALLBACK CWGetBrowseOptions(CWPluginContext context, CWBrowseOptions* browseOptions);
CW_CALLBACK CWGetBuildSequenceNumber(CWPluginContext context, long* sequenceNumber);
CW_CALLBACK CWGetTargetInfo(CWPluginContext context, CWTargetInfo* targetInfo);
CW_CALLBACK CWSetTargetInfo(CWPluginContext context, CWTargetInfo* targetInfo);
CW_CALLBACK CWGetTargetStorage(CWPluginContext context, void** storage);
CW_CALLBACK CWSetTargetStorage(CWPluginContext context, void* storage);
CW_CALLBACK CWGetMainFileNumber(CWPluginContext context, long* fileNumber);
CW_CALLBACK CWGetMainFileID(CWPluginContext context, short* fileID);
CW_CALLBACK CWGetMainFileSpec(CWPluginContext context, CWFileSpec* fileSpec);
CW_CALLBACK CWGetMainFileText(CWPluginContext context, const char** text, long* textLength);
CW_CALLBACK CWCachePrecompiledHeader(CWPluginContext context, const CWFileSpec* filespec, CWMemHandle pchhandle);
CW_CALLBACK CWLoadObjectData(CWPluginContext context, long whichfile, CWMemHandle* objectdata);
CW_CALLBACK CWFreeObjectData(CWPluginContext context, long whichfile, CWMemHandle objectdata);
CW_CALLBACK CWStoreObjectData(CWPluginContext context, long whichfile, CWObjectData* object);
CW_CALLBACK CWGetSuggestedObjectFileSpec(CWPluginContext context, long whichfile, CWFileSpec* fileSpec);
CW_CALLBACK CWGetStoredObjectFileSpec(CWPluginContext context, long whichfile, CWFileSpec* fileSpec);
CW_CALLBACK CWDisplayLines(CWPluginContext context, long nlines);
CW_CALLBACK CWBeginSubCompile(CWPluginContext context, long whichfile, CWPluginContext* subContext);
CW_CALLBACK CWEndSubCompile(CWPluginContext subContext);
CW_CALLBACK CWGetPrecompiledHeaderSpec(CWPluginContext context, CWFileSpec *pchspec, const char *target);
CW_CALLBACK CWGetResourceFile(CWPluginContext context, CWFileSpec* filespec);
CW_CALLBACK CWPutResourceFile(CWPluginContext context, const char* prompt, const char* name, CWFileSpec* filespec);
/* Metrowerks Pascal support */
CW_CALLBACK CWLookUpUnit(CWPluginContext context, const char* name, Boolean isdependency, const void** unitdata, long* unitdatalength);
CW_CALLBACK CWSBMfiles(CWPluginContext context, short libref);
CW_CALLBACK CWStoreUnit(CWPluginContext context, const char* unitname, CWMemHandle unitdata, CWDependencyTag dependencytag);
CW_CALLBACK CWReleaseUnit(CWPluginContext context, void* unitdata);
CW_CALLBACK CWUnitNameToFileName(CWPluginContext context, const char* unitname, char* filename);
/* obsolete, for MacOS backward compatibility only */
#if CWPLUGIN_API == CWPLUGIN_API_MACOS
CW_CALLBACK CWOSAlert(CWPluginContext context, const char* message, OSErr errorcode);
CW_CALLBACK CWOSErrorMessage(CWPluginContext context, const char *msg, OSErr errorcode);
#endif
CW_CALLBACK CWGetModifiedFiles(CWPluginContext context, long* modifiedFileCount, const long** modifiedFiles);
/* Get information from the "Runtime Settings" panel */
CW_CALLBACK CWGetCommandLineArgs(CWPluginContext context, const char** commandLineArgs);
CW_CALLBACK CWGetWorkingDirectory(CWPluginContext context, CWFileSpec* workingDirectorySpec);
CW_CALLBACK CWGetEnvironmentVariableCount(CWPluginContext context, long* count);
CW_CALLBACK CWGetEnvironmentVariable(CWPluginContext context, long index, const char** name, const char** value);
CW_CALLBACK CWGetFrameworkCount(CWPluginContext context, long* frameworkCount);
CW_CALLBACK CWGetFrameworkInfo(CWPluginContext context, long whichFramework, CWFrameworkInfo* frameworkInfo);
CW_CALLBACK CWGetFrameworkSharedLibrary(CWPluginContext context, long whichFramework, CWFileSpec* frameworkSharedLibrary);
#if CW_USE_PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#ifdef _MSC_VER
#pragma pack(pop,2)
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif /* __DROPINCOMPILERLINKER_H__ */
\ No newline at end of file diff --git a/sdk_hdrs/DropInPanel.h b/sdk_hdrs/DropInPanel.h new file mode 100755 index 0000000..edee6e2 --- /dev/null +++ b/sdk_hdrs/DropInPanel.h @@ -0,0 +1 @@ +/*
* DropInPanel.h - Drop-In Preferences Panel Interface for Metrowerks CodeWarriorª
*
* Copyright © 1995 Metrowerks, Inc. All rights reserved.
*
*/
#ifndef __DROPINPANEL_H__
#define __DROPINPANEL_H__
#ifdef __MWERKS__
# pragma once
#endif
#ifndef CW_STRICT_DIALOGS
# define CW_STRICT_DIALOGS 0
#endif
#if macintosh
#ifndef F_PASCAL
# define F_PASCAL(x) pascal x
#endif
#elif __sun__ || __linux__
#ifndef F_PASCAL
# define F_PASCAL(x) x
#endif
#endif
/* system headers */
#ifndef __APPLEEVENTS__
# include <AppleEvents.h>
#endif
#ifndef __CONTROLS__
# include <Controls.h>
#endif
#ifndef __DIALOGS__
# include <Dialogs.h>
#endif
#ifndef __DRAG__
# include <Drag.h>
#endif
#ifndef __CWPlugins_H__
# include "CWPlugins.h"
#endif
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if CW_USE_PRAGMA_IMPORT
#pragma import on
#endif
/* this is the current version number of the API documented herein */
#define DROPINPANELAPIVERSION_1 1 /* CW7 API version */
#define DROPINPANELAPIVERSION_2 2 /* intermediate version */
#define DROPINPANELAPIVERSION_3 3 /* CW8 API version */
#define DROPINPANELAPIVERSION_4 4 /* CW9 API version */
#define DROPINPANELAPIVERSION_5 5 /* CW10-CW Pro 1 version */
#define DROPINPANELAPIVERSION_6 6 /* CW Pro 2 version */
#define DROPINPANELAPIVERSION_7 7 /* CW Pro 3 version */
#define DROPINPANELAPIVERSION_8 8 /* CW Pro 4 version */
#define DROPINPANELAPIVERSION_9 9 /* CW Pro 5 version */
#define DROPINPANELAPIVERSION_10 10 /* CW Pro 6 version */
#define DROPINPANELAPIVERSION_11 11 /* CW Pro 7 version (listView Support) */
#define DROPINPANELAPIVERSION DROPINPANELAPIVERSION_11 /* current API version */
/* error codes */
#define kBadPrefVersion 1000
#define kMissingPrefErr 1001
#define kSettingNotFoundErr 1002
#define kSettingTypeMismatchErr 1003
#define kInvalidCallbackErr 1004
#define kSettingOutOfRangeErr 1005
/* requests codes */
enum {
reqInitPanel = -2, /* (called when panel is loaded) */
reqTermPanel = -1, /* (called when panel is unloaded) */
reqInitDialog = 0, /* initialize panel's dialog state */
reqTermDialog, /* clean up panel's dialog state */
reqPutData, /* copy options data to dialog items */
reqGetData, /* copy dialog items to options data */
reqFilter, /* filter a dialog event for the panel */
reqItemHit, /* process an itemHit in the panel */
reqAEGetPref, /* get preference setting for AppleEvent request */
reqAESetPref, /* set preference setting from AppleEvent request */
reqValidate, /* tell if current settings force recompile or relink */
reqGetFactory, /* retrieve factory settings */
reqUpdatePref, /* verify and/or modify prefs to fit current version */
reqUpdateProject, /* (only sent to built-in panels) */
reqSetupDebug, /* change settings to reflect debugging status */
reqRenameProject, /* change settings that depend on project name */
reqPrefsLoaded, /* (only sent to built-in panels) */
reqDrawCustomItem, /* draw a custom item */
reqActivateItem, /* activate a custom item */
reqDeactivateItem, /* deactivate a custom item */
reqHandleClick, /* handle mouse down in an active custom item */
reqHandleKey, /* handle key down in an active custom item */
reqFindStatus, /* enable/disable menu items for a custom item */
reqObeyCommand, /* execute a menu command for a custom item */
reqDragEnter, /* the user is dragging into the given item */
reqDragWithin, /* the user is dragging within the given item */
reqDragExit, /* the user is dragging out of the given item */
reqDragDrop, /* the user dropped onto the given item */
reqByteSwapData, /* byte swap the fields in the prefs data */
reqFirstLoad, /* panel has been loaded for the first time */
reqReadSettings, /* read settings from IDE to construct pref data handle */
reqWriteSettings, /* write the individual settings from pref data handle */
reqItemDoubleClick, /* process an double clicked in the panel, currently implemented for listviews */
reqItemIsCellEditable /* currently implemented for listviews, tells whether or not the listview is editable */
};
/* menu command codes */
enum {
menu_Cut = 1,
menu_Copy,
menu_Paste,
menu_Clear,
menu_SelectAll
};
/* Layout and bit flags for 'Flag' resource for panels */
/* */
/* For the version 3 of these resource, we renamed the 'apiversion' field to */
/* 'earliestCompatibleAPIVersion' and added the 'newestAPIVersion' field. */
/* This allows plugins to support more than one API version and therefore run */
/* under more than one version of the IDE. */
typedef struct PanelFlags {
unsigned short rsrcversion; /* version number of resource */
CWDataType dropintype; /* dropin type ('Comp', 'Link', 'Panl') */
/* earliest API support by this plugin */
unsigned short earliestCompatibleAPIVersion;
unsigned long dropinflags; /* capability flags (see enum below) */
CWDataType panelfamily; /* family of panel (linker, codegen, etc) */
unsigned short newestAPIVersion; /* newest API version supported */
unsigned short dataversion; /* version number of prefs data */
unsigned short panelscope; /* scope of panel (see enum below) */
} PanelFlags;
/* capability flags, as used in member dropinflags of PanelFlags struct */
enum {
usesStrictAPI = 1 << 31, /* this panel is built with the strict API */
supportsByteSwapping = 1 << 30, /* this panel support the byte-swapping request */
supportsTextSettings = 1 << 29, /* this panel supports the read & write settings requests */
usesCrossPlatformAPI = 1 << 28 /* uses the cross-platform API rather than Mac API */
/* remaining flags are reserved for future use and should be zero-initialized */
};
/* panel scopes, as used in member panelscope of PanelFlags struct */
/* */
/* The scope of a panel tells the IDE which settings window to display the panel. */
/* Currently, only panels for debugger plug-ins use panelScopeGlobal and only */
/* panels for VCS plug-ins use panelScopeProject. A panel for a compiler or linker */
/* must use panelScopeTarget. */
enum {
panelScopeGlobal, /* this panel is scoped to the global preferences window */
panelScopeProject, /* this panel is scoped to the VCS settings window */
panelScopeTarget, /* this panel is scoped to the target settings window */
panelScopeRConn /* this panel is scoped to configure remote debugging connections */
};
/* pre-defined panel families, used in panelfamily field of PanelFlags struct */
enum {
panelFamilyProject = CWFOURCHAR('p', 'r', 'o', 'j'),
panelFamilyFrontEnd = CWFOURCHAR('f', 'e', 'n', 'd'),
panelFamilyBackEnd = CWFOURCHAR('b', 'e', 'n', 'd'),
panelFamilyBrowser = CWFOURCHAR('b', 'r', 'o', 'w'),
panelFamilyEditor = CWFOURCHAR('e', 'd', 'i', 't'),
panelFamilyDebugger = CWFOURCHAR('d', 'b', 'u', 'g'),
panelFamilyLinker = CWFOURCHAR('l', 'i', 'n', 'k'),
panelFamilyMisc = CWFOURCHAR('*', '*', '*', '*')
};
typedef struct MWSetting* CWSettingID;
#define kNoSettingID 0
/* alias types */
#if CW_STRICT_DIALOGS
typedef struct DummyDialog* CWDialog;
#else
typedef DialogPtr CWDialog;
#endif
/* forward declarations */
typedef struct CWPanelCallbacks CWPanelCallbacks;
/* parameter block -- this is passed to the dropin at each request */
typedef struct PanelParameterBlock {
/* common to all dropins */
long request; /* [->] requested action (see below) */
long version; /* [->] version # of shell's API */
void *context; /* [->] reserved for use by shell */
void *storage; /* [<->] reserved for use by the dropin */
FSSpec targetfile; /* [->] FSSpec of current project */
/* specific to panels */
CWDialog dialog; /* [->] pointer to PreferencesÉ dialog */
Handle originalPrefs; /* [->] panel's original options data */
Handle currentPrefs; /* [<->] panel's current options data */
Handle factoryPrefs; /* [<->] panel's "factory" options data */
EventRecord *event; /* [->] dialog event (for reqFilterEvent) */
short baseItems; /* [->] # of items in dialog shell */
short itemHit; /* [<->] for reqFilterEvent and reqItemHit */
Boolean canRevert; /* [<-] enable Revert button */
Boolean canFactory; /* [<-] enable Factory button */
Boolean reset; /* [<-] access paths must be reset */
Boolean recompile; /* [<-] files must be recompiled */
Boolean relink; /* [<-] project must be relinked */
AEKeyword prefsKeyword; /* [->] for reqAEGetPref and reqAESetPref */
AEDesc prefsDesc; /* [->] for reqAESetPref */
Boolean debugOn; /* [->] turning on debugging? */
FSSpec oldtargfile; /* [->] previous project file FSSpec */
/* version 2 API */
CWPanelCallbacks* callbacks;
/* version 3 API */
Boolean reparse; /* [<-] project must be reparsed */
/* version 4 API */
DragReference dragref; /* [->] for drag-related requests */
Rect dragrect; /* [<-] rect to track mouse in */
Point dragmouse; /* [->] mouse location during drag */
/* version 5 API */
unsigned char toEndian; /* [->] for reqByteSwapData, the endian we are swapping to */
/* CWPro 3 temporary placeholders for opaque references to prefs data.
These will be removed in Pro 4.
*/
CWMemHandle originalPrefsMemHandle;
CWMemHandle currentPrefsMemHandle;
CWMemHandle factoryPrefsMemHandle;
CWMemHandle panelPrefsMemHandle;
/* version 11 api */
long listViewCellRow; /* [->] the cell row of the listView */
long listViewCellCol; /* [->] the cell row of the listView */
} PanelParameterBlock, *PanelParameterBlockPtr;
typedef PanelParameterBlock PanelParamBlk;
typedef PanelParameterBlockPtr PanelParamBlkPtr;
/* callbacks to the IDE */
extern F_PASCAL(OSErr) CWPanlAppendItems(PanelParamBlkPtr ppb, short ditlID);
extern F_PASCAL(OSErr) CWPanlDrawPanelBox(PanelParamBlkPtr ppb, long whichItem, ConstStr255Param title);
extern F_PASCAL(OSErr) CWPanlShowItem(PanelParamBlkPtr ppb, long whichItem, Boolean showIt);
extern F_PASCAL(OSErr) CWPanlEnableItem(PanelParamBlkPtr ppb, long whichItem, Boolean enableIt);
extern F_PASCAL(OSErr) CWPanlActivateItem(PanelParamBlkPtr ppb, long whichItem);
extern F_PASCAL(OSErr) CWPanlGetItemValue(PanelParamBlkPtr ppb, long whichItem, long* value);
extern F_PASCAL(OSErr) CWPanlSetItemValue(PanelParamBlkPtr ppb, long whichItem, long value);
extern F_PASCAL(OSErr) CWPanlGetItemText(PanelParamBlkPtr ppb, long whichItem, StringPtr str, short maxLen);
extern F_PASCAL(OSErr) CWPanlSetItemText(PanelParamBlkPtr ppb, long whichItem, ConstStr255Param str);
extern F_PASCAL(OSErr) CWPanlGetPanelPrefs(PanelParamBlkPtr ppb, StringPtr inPanelName, Handle *prefs, Boolean* requiresByteSwap);
extern F_PASCAL(OSErr) CWPanlGetItemRect(PanelParamBlkPtr ppb, long whichItem, Rect* rect);
extern F_PASCAL(OSErr) CWPanlGetItemControl(PanelParamBlkPtr ppb, long whichItem, ControlRef* control);
extern F_PASCAL(OSErr) CWPanlInvalItem(PanelParamBlkPtr ppb, long whichItem);
extern F_PASCAL(OSErr) CWPanlValidItem(PanelParamBlkPtr ppb, long whichItem);
extern F_PASCAL(OSErr) CWPanlGetMacPort(PanelParamBlkPtr ppb, GrafPtr* port);
extern F_PASCAL(OSErr) CWPanlGetItemTextHandle(PanelParamBlkPtr ppb, long whichItem, Handle *text);
extern F_PASCAL(OSErr) CWPanlSetItemTextHandle(PanelParamBlkPtr ppb, long whichItem, Handle text);
extern F_PASCAL(OSErr) CWPanlGetItemData(PanelParamBlkPtr ppb, long whichItem, void *outData, long *outDataLength);
extern F_PASCAL(OSErr) CWPanlSetItemData(PanelParamBlkPtr ppb, long whichItem, void *inData, long inDataLength);
extern F_PASCAL(OSErr) CWPanlGetItemMaxLength(PanelParamBlkPtr ppb, long whichItem, short *outLength);
extern F_PASCAL(OSErr) CWPanlSetItemMaxLength(PanelParamBlkPtr ppb, long whichItem, short inLength);
extern F_PASCAL(OSErr) CWPanlChooseRelativePath(PanelParamBlkPtr ppb, CWRelativePath* path, Boolean isFolder, short filterCount, void* filterList, char* prompt);
extern F_PASCAL(OSErr) CWPanlGetRelativePathString(PanelParamBlkPtr ppb, CWRelativePath* path, char* pathString, long* maxLength);
#if macintosh
extern F_PASCAL(OSErr) CWPanlReadRelativePathAEDesc(PanelParamBlkPtr ppb, CWRelativePath* path, const AEDesc* desc);
extern F_PASCAL(OSErr) CWPanlWriteRelativePathAEDesc(PanelParamBlkPtr ppb, const CWRelativePath* path, AEDesc* desc);
#endif
/* utility routines */
extern F_PASCAL(OSErr) CWPanlDrawUserItemBox(DialogPtr dialog, short whichItem, ConstStr255Param title);
extern F_PASCAL(OSErr) CWPanlInstallUserItem(PanelParamBlkPtr ppb, short whichItem, UserItemProcPtr proc);
extern F_PASCAL(OSErr) CWPanlRemoveUserItem(PanelParamBlkPtr ppb, short whichItem);
/* reading and writing scalar settings */
extern F_PASCAL(OSErr) CWPanlReadBooleanSetting(PanelParamBlkPtr ppb, const char* name, Boolean* value);
extern F_PASCAL(OSErr) CWPanlReadIntegerSetting(PanelParamBlkPtr ppb, const char* name, long* value);
extern F_PASCAL(OSErr) CWPanlReadFloatingPointSetting(PanelParamBlkPtr ppb, const char* name, double* value);
extern F_PASCAL(OSErr) CWPanlReadStringSetting(PanelParamBlkPtr ppb, const char* name, const char** value);
extern F_PASCAL(OSErr) CWPanlReadRelativePathSetting(PanelParamBlkPtr ppb, const char* name, CWRelativePath* value);
extern F_PASCAL(OSErr) CWPanlWriteBooleanSetting(PanelParamBlkPtr ppb, const char* name, Boolean value);
extern F_PASCAL(OSErr) CWPanlWriteIntegerSetting(PanelParamBlkPtr ppb, const char* name, long value);
extern F_PASCAL(OSErr) CWPanlWriteFloatingPointSetting(PanelParamBlkPtr ppb, const char* name, double value);
extern F_PASCAL(OSErr) CWPanlWriteStringSetting(PanelParamBlkPtr ppb, const char* name, const char* value);
extern F_PASCAL(OSErr) CWPanlWriteRelativePathSetting(PanelParamBlkPtr ppb, const char* name, const CWRelativePath* value);
/* reading and writing array and structure settings */
extern F_PASCAL(OSErr) CWPanlGetNamedSetting(PanelParamBlkPtr ppb, const char* name, CWSettingID* settingID);
extern F_PASCAL(OSErr) CWPanlGetStructureSettingField(PanelParamBlkPtr ppb, CWSettingID settingID, const char* name, CWSettingID* fieldSettingID);
extern F_PASCAL(OSErr) CWPanlGetArraySettingSize(PanelParamBlkPtr ppb, CWSettingID settingID, long* size);
extern F_PASCAL(OSErr) CWPanlGetArraySettingElement(PanelParamBlkPtr ppb, CWSettingID settingID, long index, CWSettingID* elementSettingID);
extern F_PASCAL(OSErr) CWPanlGetBooleanValue(PanelParamBlkPtr ppb, CWSettingID settingID, Boolean* value);
extern F_PASCAL(OSErr) CWPanlGetIntegerValue(PanelParamBlkPtr ppb, CWSettingID settingID, long* value);
extern F_PASCAL(OSErr) CWPanlGetFloatingPointValue(PanelParamBlkPtr ppb, CWSettingID settingID, double* value);
extern F_PASCAL(OSErr) CWPanlGetStringValue(PanelParamBlkPtr ppb, CWSettingID settingID, const char** value);
extern F_PASCAL(OSErr) CWPanlGetRelativePathValue(PanelParamBlkPtr ppb, CWSettingID settingID, CWRelativePath* value);
extern F_PASCAL(OSErr) CWPanlSetBooleanValue(PanelParamBlkPtr ppb, CWSettingID settingID, Boolean value);
extern F_PASCAL(OSErr) CWPanlSetIntegerValue(PanelParamBlkPtr ppb, CWSettingID settingID, long value);
extern F_PASCAL(OSErr) CWPanlSetFloatingPointValue(PanelParamBlkPtr ppb, CWSettingID settingID, double value);
extern F_PASCAL(OSErr) CWPanlSetStringValue(PanelParamBlkPtr ppb, CWSettingID settingID, const char* value);
extern F_PASCAL(OSErr) CWPanlSetRelativePathValue(PanelParamBlkPtr ppb, CWSettingID settingID, const CWRelativePath* value);
#if CW_USE_PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#endif /* __DROPINPANEL_H__ */
\ No newline at end of file diff --git a/sdk_hdrs/DropInPanelWin32.h b/sdk_hdrs/DropInPanelWin32.h new file mode 100755 index 0000000..98d0c8a --- /dev/null +++ b/sdk_hdrs/DropInPanelWin32.h @@ -0,0 +1 @@ +/*
DropInPanelWin32.h
This is the old name for the file that is now called CWDropInPanel.h.
It is here for backward compatibility with older panels. New panels
should include CWDropInPanel.h instead.
*/
#ifndef __DROPINPANELWIN32_H__
#define __DROPINPANELWIN32_H__
#include "CWDropInPanel.h"
#endif
\ No newline at end of file diff --git a/sdk_hdrs/DropInVCS.h b/sdk_hdrs/DropInVCS.h new file mode 100755 index 0000000..6124933 --- /dev/null +++ b/sdk_hdrs/DropInVCS.h @@ -0,0 +1 @@ +/*
DropInVCS.h
Copyright (c) 1996-8, Metrowerks Corporation. All rights reserved.
This include contains the declarations needed to interface a version control system to
the CodeWarrior integrated development environment.
*/
#ifndef __DROPINVCS_H__
#define __DROPINVCS_H__
#ifdef macintosh
#include <OSUtils.h>
#include <Files.h>
#endif
#define VCS_API_VERSION_1 1 // 1.7 IDE through Pro 3
#define VCS_API_VERSION_7 7 // Pro 4
#define VCS_API_VERSION_8 8 // Pro 5
#define VCS_API_VERSION_9 9 // Pro 6
#define VCS_API_CURRENT_VERSION VCS_API_VERSION_9
#ifndef __CWPlugins_H__
#include "CWPlugins.h"
#endif
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifndef __CWPluginErrors_H__
#include "CWPluginErrors.h"
#endif
#ifdef MW_USES_PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if CW_USE_PRAGMA_IMPORT
#pragma import on
#endif
// The following constants are to be used when specifying the flags through a
// flags callback. For version 3 flags.
enum {
vcsDoesntPrePostSingleFile = 1L << 31, /* this VCS plugin does NOT call Pre/PostFileAction routines for calls dealing with a single file (file must be accessible before call) */
vcsDoesntPrePostRecursive = 1L << 30, /* this VCS plugin does NOT call Pre/PostFileAction routines for files during recursive calls (files must be accessible before call) */
vcsRequiresEvents = 1L << 29, /* this flag specifies that the VCS is responding to either AppleEvents or other highLevelEvents and the IDE should not try to handle events during callbacks */
vcsWantsIdle = 1L << 28, /* this flag is turned on when the VCS plugin wants to receive idle events */
vcsSupportsPrefsChanged = 1L << 27, /* this flag is turned on when the VCS plugin supports the reqPrefsChanged request */
vcsDoesntUseLoginSettings = 1L << 26, /* this VCS plugin does not use the login settings in the VCS Setup panel */
vcsDoesntUseDatabaseSetting = 1L << 25, /* this VCS plugin does not use the database path setting in the VCS Setup panel */
vcsDoesntUseLocalRootSetting = 1L << 24 /* this VCS plugin does not use the local root setting in the VCS Setup panel */
};
enum
{
reqDatabaseConnect = 1, // connect to database
reqDatabaseDisconnect, // disconnect from database
reqDatabaseVariables, // database variables list
reqFileAdd, // add file
reqFileCheckin, // checkin file
reqFileCheckout, // checkout file
reqFileComment, // set file comment
reqFileDelete, // delete file
reqFileDestroy, // destroy file
reqFileDifference, // difference file
reqFileGet, // get file
reqFileHistory, // get file history
reqFileLabel, // label file
reqFileProperties, // get file properties
reqFilePurge, // purge file
reqFileRename, // rename file
reqFileRollback, // rollback file
reqFileStatus, // get file status
reqFileUndoCheckout, // cancel file checkout
reqFileVersion, // get file version
reqFileBranch, // branch a shared file
reqFileShare, // share a file
reqFileView // view a file
};
typedef long CWVCSCommand;
enum
{
cwCommandStatusCommandUnknown = -4, // command unknown
cwCommandStatusUnknown = -3, // status unknown
cwCommandStatusUnsupported = -2, // command unsupported
cwCommandStatusSupported = -1, // command supported
cwCommandStatusSucceeded = cwNoErr, // successful
cwCommandStatusFailed = 1, // failed
cwCommandStatusPartial = 2, // partially successful
cwCommandStatusCancelled = 3, // user cancelled
cwCommandStatusConnectionLost = 4, // connection lost
cwCommandStatusInvalidLogin = 5 // invalid username or password
};
typedef long CWVCSCommandStatus;
enum
{
cwItemStatusUnprocessed = -2, // item yet unprocessed
cwItemStatusUnknown = -1, // status unknown
cwItemStatusSucceeded = 0, // operation succeeded
cwItemStatusFailed = 1, // operation failed
cwItemStatusCancelled = 2 // operation cancelled
};
typedef long CWVCSItemStatus;
enum
{
cwCheckoutStateUnknown = 0xFFFFFFFF, // unknown
cwCheckoutStateNotInDatabase = 0x00000002, // not in database
cwCheckoutStateNotCheckedOut = 0x00000000, // not checked out
cwCheckoutStateCheckedOut = 0x00000001, // checked out
cwCheckoutStateMultiplyCheckedOut = 0x00000101, // multiply checked out
cwCheckoutStateNotCheckedOutShared = 0x00010000, // not checked out and shared
cwCheckoutStateCheckedOutShared = 0x00010001, // checked out and shared
cwCheckoutStateMultiplyCheckedOutShared = 0x00010101, // multiply checked out and shared
cwCheckoutStateNotCheckedOutBranched = 0x00020000, // not checked out and branched
cwCheckoutStateCheckedOutBranched = 0x00020001, // checked out and branched
cwCheckoutStateMultiplyCheckedOutBranched = 0x00020101, // checked out and branched
cwCheckoutStateNotCheckedOutSharedBranched = 0x00030000, // not checked out, shared and branched
cwCheckoutStateCheckedOutSharedBranched = 0x00030001, // checked out, shared and branched
cwCheckoutStateMultiplyCheckedSharedOutBranched = 0x00030101, // checked out, shared and branched
cwCheckoutStateCheckedOutExclusive = 0x00040001, // exclusively checked out
cwCheckoutStateCheckedOutExclusiveShared = 0x00050001, // exclusively checked out and shared
cwCheckoutStateCheckedOutExclusiveBranched = 0x00060001, // exclusively checked out and branched
cwCheckoutStateCheckedOutExclusiveSharedBranched = 0x00070001, // exclusively checked out, shared and branched
cwCheckoutStateCheckedOutMask = 0x00000001, // checked out mask
cwCheckoutStateMultiplyCheckedOutMask = 0x00000100, // multiply checked out mask
cwCheckoutStateSharedMask = 0x00010000, // shared mask
cwCheckoutStateBranchedMask = 0x00020000, // branched mask
cwCheckoutStateExclusiveMask = 0x00040000 // exclusive mask
};
typedef long CWVCSCheckoutState;
enum
{
cwVersionFormNone = 0, // no record
cwVersionFormNumeric = 1, // intergral numeric
cwVersionFormAlpha = 2, // alphabetic
cwVersionFormLabel = 4, // label
cwVersionFormDate = 5 // date / time
};
typedef long CWVCSVersionForm;
enum
{
cwCommandDescriptionVersion = 1
};
typedef struct CWVCSCommandDescription
{
long version;
char menuItem[40];
char progressMessage[200];
} CWVCSCommandDescription;
typedef union CWVCSVersionData
{
unsigned long numeric; // integral numeric
char* pAlpha; // alphabetic
CWFileTime date; // date / time
char* pLabel; // label
} CWVCSVersionData, *p_CWVCSVersionData, **h_CWVCSVersionData;
typedef struct CWVCSVersion
{
CWVCSVersionForm eVersionForm; // version form
CWVCSVersionData sVersionData; // version data
} CWVCSVersion, *p_CWVCSVersion, **h_CWVCSVersion;
typedef struct CWVCSItem
{
CWFileSpec fsItem; // item file specification
CWVCSItemStatus eItemStatus; // item status code
CWVCSVersion version; // item version
CWVCSCheckoutState eCheckoutState; // item checkout state
} CWVCSItem, *p_CWVCSItem, **h_CWVCSItem;
typedef struct CWVCSDatabaseConnection
{
CWFileSpec sDatabasePath; // path to the database directory
CWFileSpec sProjectRoot; // path to the local database directory
char* pUsername; // user name
char* pPassword; // user password
} CWVCSDatabaseConnection, *p_CWVCSDatabaseConnection, **h_CWVCSDatabaseConnection;
/* The following callback mechanisms are available for VCS plugins for VCS performing VCS specific
* functions and retrieving VCS specific data from the context passed to the main entry point by the
* IDE. You may also use any of the callbacks for generic plugins.
*
* These callbacks are available only to plugins using version 2 of the API or greater.
*/
/* Call this function as the first thing you do in your main entry point. Check its result. If you pass in
* true, then if the v2 plugin is running under a pre-Pro4 IDE it will set up the compatibillity libraries and
* return cwNoErr. If you pass in false and your v2 plugin is running uner a pre-Pro4 IDE it will return
* cwCommandStatusFailed, at which point you should return this error to the IDE and not process the request
* sent to you.
*
* Note that if you allow v1 compatibility and the result of isV1 is true, your plugin will not receive the V2
* idle requests or preferences changed requests and you must work around accordingly. */
CW_CALLBACK CWAllowV1Compatibility(CWPluginContext context, Boolean canHandleV1Mode, Boolean *isV1);
/* Get a comment from the user */
CW_CALLBACK CWGetComment(CWPluginContext context, const char* pPrompt, char* pComment, const long lBufferSize);
/* Notify IDE if any changes occur to a file's information or checkout state */
CW_CALLBACK CWVCSStateChanged(CWPluginContext context, const CWFileSpec* file,
CWVCSCheckoutState eCheckoutState, const CWVCSVersion* version);
/* Display a IDE visual difference window for the passed files. The first file passed in
* should be an unchangable file and the second file should be the local file. Instead of passing
* a CWFileSpec it is possible to pass in a pointer to text (null terminated) and a title.
* If the file spec is used, set both the title and text pointers to NULL */
CW_CALLBACK CWDoVisualDifference(CWPluginContext context,
const CWFileSpec* file1, const char* pTitle1, const char* pText1, unsigned long lengthText1,
const CWFileSpec* file2, const char* pTitle2, const char* pText2, unsigned long lengthText2);
/* Tell the IDE the current ratio of how many items are completed. If you are able to correctly
* give a completion ratio, the IDE will display a progress bar indicating how far along the
* VCS action has progressed instead of displaying a busy indicator. If you pass -1 as the
* total number of items, the busy indicator will replace any progress bar that you have
* displayed with a prior call to completion ratio during the handling of a single request */
CW_CALLBACK CWCompletionRatio(CWPluginContext context, int totalItems, int completedItems);
/* Get the project file specifier */
CW_CALLBACK CWGetProjectFileSpecifier(CWPluginContext context, CWFileSpec* projectFileSpec);
/* Is the command passed an advanced command? */
CW_CALLBACK CWIsAdvancedRequest(CWPluginContext context, Boolean* isAdvanced);
/* Is the command passed a recursive command? */
CW_CALLBACK CWIsRecursiveRequest(CWPluginContext context, Boolean* isRecursive);
/* Is the command passed simply to check if it is supported? */
CW_CALLBACK CWIsCommandSupportedRequest(CWPluginContext context, Boolean* isCommandSupported);
/* Set the pointer to a new overriding menu title string */
CW_CALLBACK CWSetCommandDescription(CWPluginContext context, CWVCSCommandDescription* descr);
/* Get the pointer to the database connection structure */
CW_CALLBACK CWGetDatabaseConnectionInfo(CWPluginContext context, CWVCSDatabaseConnection* dbConnection);
/* Get the command status code */
CW_CALLBACK CWGetCommandStatus(CWPluginContext context, CWVCSCommandStatus* status);
/* Set the command status code */
CW_CALLBACK CWSetCommandStatus(CWPluginContext context, CWVCSCommandStatus status);
/* Get the number of VCS items passed to the plugin */
CW_CALLBACK CWGetVCSItemCount(CWPluginContext context, unsigned long* count);
/* Get a pointer to the ith entry of the item array, 0 indexed */
CW_CALLBACK CWGetVCSItem(CWPluginContext context, long index, CWVCSItem* item);
/* Change the data for a VCS Item in the item array */
CW_CALLBACK CWSetVCSItem(CWPluginContext context, long index, CWVCSItem* item);
/* Get what's stored in the VCS pointer storage area */
CW_CALLBACK CWGetVCSPointerStorage(CWPluginContext context, void** storage);
/* Store a pointer that will be maintained across calls to the main entry point */
CW_CALLBACK CWSetVCSPointerStorage(CWPluginContext context, void* storage);
#if CW_USE_PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#ifdef _MSC_VER
#pragma pack(pop,2)
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif /* __DROPINVCS_H__ */
\ No newline at end of file diff --git a/sdk_hdrs/MWBrowse.h b/sdk_hdrs/MWBrowse.h new file mode 100755 index 0000000..310a5d0 --- /dev/null +++ b/sdk_hdrs/MWBrowse.h @@ -0,0 +1 @@ +/*
* MWBrowse.h
*
* Copyright © 1993-96 Metrowerks, Inc. All rights reserved.
*
* Types and constants needed for emitting CodeWarrior
* browse information.
*/
#ifndef __MWBROWSE_H__
#define __MWBROWSE_H__
#ifdef __MWERKS__
#pragma once
#endif
#include "MWLangDefs.h"
#ifdef __MWERKS__
#pragma options align=mac68k
#endif
#ifdef _MSC_VER
#pragma pack(push,2)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define BROWSE_HEADER 0xBEABBAEB
#define BROWSE_VERSION 2
#define BROWSE_EARLIEST_COMPATIBLE_VERSION 2
typedef struct BrowseHeader {
long browse_header; // always set to BROWSE_HEADER
long browse_version; // always set to BROWSE_VERSION
short browse_language; // the language of this translation unit, enum ELanguage
short uses_name_table; // TRUE: uses name table from CW object code
long earliest_compatible_version;// always set to BROWSE_EARLIEST_COMPATIBLE_VERSION
long reserved[15]; // for future extensions
} BrowseHeader;
typedef unsigned char EBrowserItem;
enum {
browseFunction, // function, procedure, or method
browseGlobal, // global variable
browseClass, // class, struct, or union
browseMacro, // macro
browseEnum, // enum, enumerated type member
browseTypedef, // user-defined type other than class
browseConstant, // constant value
browseTemplate, // C++ template
browsePackage, // Java package
browseCompSymbolStart = 0x70,
browseEnd = 0xFF // used to denote end-of-list
};
// flag constants for functions, member functions, data members
enum
{
kAbstract = 1, // abstract/pure virtual
kStatic = 2, // static member
kFinal = 4, // final Java class, method, or data member
kMember = 8, // item is a class member
// reserve flags 0x10, 0x20, and 0x40 for other general flags
// flags specific to classes
kInterface = 0x80, // class is Java interface
kPublic = 0x100, // class is public Java class
// flags specific to functions and member functions
kInline = 0x80, // inline function
kPascal = 0x100, // pascal function
kAsm = 0x200, // asm function
kVirtual = 0x400, // virtual member function
kCtor = 0x800, // is constructor
kDtor = 0x1000, // is destructor
kNative = 0x2000, // native Java method
kSynch = 0x4000, // synchronized Java method
kIntrinsic = 0x8000, // intrinsic routine (for General Magic)
kConst = 0x10000, // const function
// flags specific to data members
kTransient = 0x80, // transient Java data member
kVolatile = 0x100 // volatile Java data member
};
typedef enum EAccess
{ // can be used as mask values
accessNone = 0,
accessPrivate = 1,
accessProtected = 2,
accessPublic = 4,
accessAll = accessPrivate+accessProtected+accessPublic
} EAccess;
typedef unsigned char EMember;
enum
{
memberFunction, // member function/method
memberData, // data member/field
memberEnd = 0xFF // denotes end-of-list
};
typedef enum ETemplateType
{ // templates are either class or function templates
templateClass,
templateFunction
} ETemplateType;
/********************************************************************************/
/* Old (pre-CW9) browse data support definitions */
/********************************************************************************/
#define BROWSE_OLD_VERSION 0
enum {
BROWSE_SCOPE_STATIC, // local to this file
BROWSE_SCOPE_EXTERN // global to all files
};
enum {
BROWSE_OBJECT_FUNCTION, // function object
BROWSE_OBJECT_DATA // data object
};
enum { // browse data types
BROWSE_END, // end of browse data
BROWSE_OBJECT // a function/data definition
};
typedef struct BrowseObjectDef {
short type; // always BROWSE_OBJECT
short size; // size of following data
char object_type; // one of: (BROWSE_OBJECT_FUNCTION,BROWSE_OBJECT_DATA)
char object_scope; // one of: (BROWSE_SCOPE_STATIC,BROWSE_SCOPE_EXTERN)
long source_offset; // offset of declartation in source code
// char name[...]; followed by padded object name (c-string)
// char classname[...]; followed by padded class name string (c-string)
} BrowseObjectDef;
typedef struct BrowseHeader_Old {
long browse_header; // always set to BROWSE_HEADER
long browse_version; // always set to BROWSE_VERSION
long reserved[14]; // for future extensions
} BrowseHeader_Old;
#ifdef __cplusplus
}
#endif
#ifdef _MSC_VER
#pragma pack(pop)
#endif
#ifdef __MWERKS__
#pragma options align=reset
#endif
#endif // __MWBROWSE_H__
\ No newline at end of file diff --git a/sdk_hdrs/MWLangDefs.h b/sdk_hdrs/MWLangDefs.h new file mode 100755 index 0000000..6a6a650 --- /dev/null +++ b/sdk_hdrs/MWLangDefs.h @@ -0,0 +1 @@ +/*
* MWLangDefs.h
*
* Copyright © 1994-1996 metrowerks inc. All rights reserved.
*
* Language constants.
*/
#ifndef MWLangDefs_H
#define MWLangDefs_H
enum ELanguage
{
langUnknown,
langC,
langCPlus,
langPascal,
langObjectPascal,
langJava,
langAssembler, // don't care which assembler
langFortran,
langRez
};
#endif // !MWLangDefs_H
\ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..83038c4 --- /dev/null +++ b/setup.sh @@ -0,0 +1,3 @@ +#export MWCIncludes=/Applications/Metrowerks\ CodeWarrior\ 7.0/Metrowerks\ CodeWarrior/MacOS\ Support/Universal/Interfaces/CIncludes:/Applications/Metrowerks\ CodeWarrior\ 7.0/Metrowerks\ CodeWarrior/MSL/MSL_C/MSL_Common/Include +#export MWCIncludes=/usr/include +export MWCIncludes=/Applications/Metrowerks\ CodeWarrior\ 7.0/Metrowerks\ CodeWarrior/MacOS\ X\ Support/MacHeaders\ Mach-O |