void PC_AppendCmd(pcd_t command) { MS_Message(MSG_DEBUG, "AC> %06d = #%d:%s\n", pc_Address, command, PCDNames[command]); command = MS_LittleULONG(command); Append(&command, sizeof(U_LONG)); }
void TK_AddProgramIncludePath(char *progname) { if(NumIncludePaths < MAX_INCLUDE_PATHS) { #ifdef _WIN32 #ifdef _MSC_VER #if _MSC_VER >= 1300 if (_get_pgmptr(&progname) != 0) { return; } #else progname = _pgmptr; #endif #else char progbuff[1024]; GetModuleFileName(0, progbuff, sizeof(progbuff)); progbuff[sizeof(progbuff)-1] = '\0'; progname = progbuff; #endif #else char progbuff[PATH_MAX]; if (realpath(progname, progbuff) != NULL) { progname = progbuff; } #endif strcpy(IncludePaths[NumIncludePaths], progname); if(MS_StripFilename(IncludePaths[NumIncludePaths])) { MS_Message(MSG_DEBUG, "Program include path is %d: \"%s\"\n", NumIncludePaths, IncludePaths[NumIncludePaths]); NumIncludePaths++; } } }
void PC_WriteCmd(pcd_t command, int address) { MS_Message(MSG_DEBUG, "WC> %06d = #%d:%s\n", address, command, PCDNames[command]); command = MS_LittleULONG(command); Write(&command, sizeof(U_LONG), address); }
static boolean CheckForConstant(void) { symbolNode_t *sym; sym = SY_FindGlobal(tk_String); if(sym == NULL) { return FALSE; } if(sym->type != SY_CONSTANT) { return FALSE; } if(sym->info.constant.strValue != NULL) { MS_Message(MSG_DEBUG, "Constant string: %s\n", sym->info.constant.strValue); tk_Token = TK_STRING; tk_String = sym->info.constant.strValue; } else { tk_Token = TK_NUMBER; tk_Number = sym->info.constant.value; } return TRUE; }
static int PopNestedSource(enum ImportModes *prevMode) { nestInfo_t *info; MS_Message(MSG_DEBUG, "*Leaving %s\n", tk_SourceName); free(FileStart); SY_FreeConstants(NestDepth); tk_IncludedLines += tk_Line; info = &OpenFiles[--NestDepth]; tk_SourceName = info->name; FileStart = info->start; FileEnd = info->end; FilePtr = info->position; tk_Line = info->line; IncLineNumber = info->incLineNumber; Chr = info->lastChar; tk_Token = TK_NONE; AlreadyGot = FALSE; // Pascal 12/11/08 // Set the first include path back to this file directory SetLocalIncludePath(tk_SourceName); *prevMode = info->prevMode; return info->imported ? 2 : 0; }
int STR_Find(char *name) { int i; for(i = 0; i < str_StringCount; i++) { if(strcmp(StringInfo[i].name, name) == 0) { return i; } } // Add to list if(str_StringCount == MAX_STRINGS) { ERR_Exit(ERR_TOO_MANY_STRINGS, YES, "Current maximum: %d", MAX_STRINGS); } MS_Message(MSG_DEBUG, "Adding string %d:\n \"%s\"\n", str_StringCount, name); StringInfo[str_StringCount].name = MS_Alloc(strlen(name)+1, ERR_OUT_OF_MEMORY); strcpy(StringInfo[str_StringCount].name, name); str_StringCount++; return str_StringCount-1; }
int main(int argc, char **argv) { int i; ArgCount = argc; ArgVector = argv; DisplayBanner(); Init(); TK_OpenSource(acs_SourceFileName); PC_OpenObject(ObjectFileName, DEFAULT_OBJECT_SIZE, 0); PA_Parse(); PC_CloseObject(); TK_CloseSource(); MS_Message(MSG_NORMAL, "\n\"%s\":\n %d line%s (%d included)\n", acs_SourceFileName, tk_Line, tk_Line == 1 ? "" : "s", tk_IncludedLines); MS_Message(MSG_NORMAL, " %d function%s\n %d script%s\n", pc_FunctionCount, pc_FunctionCount == 1 ? "" : "s", pa_ScriptCount, pa_ScriptCount == 1 ? "" : "s"); for (i = 0; pa_TypedScriptCounts[i].TypeName; i++) { if (pa_TypedScriptCounts[i].TypeCount > 0) { MS_Message(MSG_NORMAL, "%5d %s\n", pa_TypedScriptCounts[i].TypeCount, pa_TypedScriptCounts[i].TypeName); } } MS_Message(MSG_NORMAL, " %d global variable%s\n" " %d world variable%s\n" " %d map variable%s\n" " %d global array%s\n" " %d world array%s\n", pa_GlobalVarCount, pa_GlobalVarCount == 1 ? "" : "s", pa_WorldVarCount, pa_WorldVarCount == 1 ? "" : "s", pa_MapVarCount, pa_MapVarCount == 1 ? "" : "s", pa_GlobalArrayCount, pa_GlobalArrayCount == 1 ? "" : "s", pa_WorldArrayCount, pa_WorldArrayCount == 1 ? "" : "s" ); MS_Message(MSG_NORMAL, " object \"%s\": %d bytes\n", ObjectFileName, pc_Address); ERR_RemoveErrorFile(); return 0; }
void PC_AppendString(char *string) { int length; length = strlen(string)+1; MS_Message(MSG_DEBUG, "AS> %06d = \"%s\" (%d bytes)\n", pc_Address, string, length); Append(string, length); }
void PC_WriteString(char *string, int address) { int length; length = strlen(string)+1; MS_Message(MSG_DEBUG, "WS> %06d = \"%s\" (%d bytes)\n", address, string, length); Write(string, length, address); }
void STR_WriteList(void) { int i; MS_Message(MSG_DEBUG, "---- STR_WriteList ----\n"); PC_AppendLong((U_LONG)str_StringCount); for(i = 0; i < str_StringCount; i++) { PC_AppendLong((U_LONG)StringInfo[i].address); } }
void PC_CloseObject(void) { int i; scriptInfo_t *info; MS_Message(MSG_DEBUG, "---- PC_CloseObject ----\n"); STR_WriteStrings(); PC_WriteLong((U_LONG)pc_Address, 4); PC_AppendLong((U_LONG)pc_ScriptCount); for(i = 0; i < pc_ScriptCount; i++) { info = &ScriptInfo[i]; MS_Message(MSG_DEBUG, "Script %d, address = %d, arg count = %d\n", info->number, info->address, info->argCount); PC_AppendLong((U_LONG)info->number); PC_AppendLong((U_LONG)info->address); PC_AppendLong((U_LONG)info->argCount); } STR_WriteList(); if(MS_SaveFile(ObjectName, pc_Buffer, pc_Address) == FALSE) { ERR_Exit(ERR_SAVE_OBJECT_FAILED, NO, NULL); } }
void TK_AddIncludePath(char *sourcePath) { if(NumIncludePaths < MAX_INCLUDE_PATHS) { // Add to list strcpy(IncludePaths[NumIncludePaths], sourcePath); // Not ending with directory delimiter? if(!MS_IsDirectoryDelimiter(*(IncludePaths[NumIncludePaths] + strlen(IncludePaths[NumIncludePaths]) - 1))) { // Add a directory delimiter to the include path strcat(IncludePaths[NumIncludePaths], "/"); } MS_Message(MSG_DEBUG, "Add include path %d: \"%s\"\n", NumIncludePaths, IncludePaths[NumIncludePaths]); NumIncludePaths++; } }
void STR_WriteStrings(void) { int i; U_LONG pad; MS_Message(MSG_DEBUG, "---- STR_WriteStrings ----\n"); for(i = 0; i < str_StringCount; i++) { StringInfo[i].address = pc_Address; PC_AppendString(StringInfo[i].name); } if(pc_Address%4 != 0) { // Need to align pad = 0; PC_Append((void *)&pad, 4-(pc_Address%4)); } }
static void Init(void) { short endianTest = 1; if (*(char *)&endianTest) acs_BigEndianHost = NO; else acs_BigEndianHost = YES; acs_VerboseMode = YES; acs_DebugMode = NO; acs_DebugFile = NULL; TK_Init(); SY_Init(); STR_Init(); ProcessArgs(); MS_Message(MSG_NORMAL, "Host byte order: %s endian\n", acs_BigEndianHost ? "BIG" : "LITTLE"); }
void PC_Write(void *buffer, size_t size, int address) { MS_Message(MSG_DEBUG, "WD> %06d = (%d bytes)\n", address, size); Write(buffer, size, address); }
void TK_Include(char *fileName) { char sourceName[MAX_FILE_NAME_LENGTH]; int size, i; nestInfo_t *info; boolean foundfile = FALSE; MS_Message(MSG_DEBUG, "*Including %s\n", fileName); if(NestDepth == MAX_NESTED_SOURCES) { ERR_Exit(ERR_INCL_NESTING_TOO_DEEP, YES, fileName); } info = &OpenFiles[NestDepth++]; info->name = tk_SourceName; info->start = FileStart; info->end = FileEnd; info->position = FilePtr; info->line = tk_Line; info->incLineNumber = IncLineNumber; info->lastChar = Chr; info->imported = NO; // Pascal 30/11/08 // Handle absolute paths if(MS_IsPathAbsolute(fileName)) { #if defined(_WIN32) || defined(__MSDOS__) sourceName[0] = '\0'; if(MS_IsDirectoryDelimiter(fileName[0])) { // The source file is absolute for the drive, but does not // specify a drive. Use the path for the current file to // get the drive letter, if it has one. if(IncludePaths[0][0] != '\0' && IncludePaths[0][1] == ':') { sourceName[0] = IncludePaths[0][0]; sourceName[1] = ':'; sourceName[2] = '\0'; } } strcat(sourceName, fileName); #else strcpy(sourceName, fileName); #endif foundfile = MS_FileExists(sourceName); } else { // Pascal 12/11/08 // Find the file in the include paths for(i = 0; i < NumIncludePaths; i++) { strcpy(sourceName, IncludePaths[i]); strcat(sourceName, fileName); if(MS_FileExists(sourceName)) { foundfile = TRUE; break; } } } if(!foundfile) { ERR_ErrorAt(tk_SourceName, tk_Line); ERR_Exit(ERR_CANT_FIND_INCLUDE, YES, fileName, tk_SourceName, tk_Line); } MS_Message(MSG_DEBUG, "*Include file found at %s\n", sourceName); // Now change the first include path to the file directory SetLocalIncludePath(sourceName); tk_SourceName = AddFileName(sourceName); size = MS_LoadFile(tk_SourceName, &FileStart); FileEnd = FileStart+size; FilePtr = FileStart; tk_Line = 1; IncLineNumber = FALSE; tk_Token = TK_NONE; AlreadyGot = FALSE; BumpMasterSourceLine('x',TRUE); // dummy x NextChr(); }
void PC_Append(void *buffer, size_t size) { MS_Message(MSG_DEBUG, "AD> %06d = (%d bytes)\n", pc_Address, size); Append(buffer, size); }
void PC_SkipLong(void) { MS_Message(MSG_DEBUG, "SL> %06d (skip long)\n", pc_Address); Skip(sizeof(U_LONG)); }
void PC_Skip(size_t size) { MS_Message(MSG_DEBUG, "SD> %06d (skip %d bytes)\n", pc_Address, size); Skip(size); }
void PC_AppendLong(U_LONG val) { MS_Message(MSG_DEBUG, "AL> %06d = %d\n", pc_Address, val); val = MS_LittleULONG(val); Append(&val, sizeof(U_LONG)); }
void PC_WriteLong(U_LONG val, int address) { MS_Message(MSG_DEBUG, "WL> %06d = %d\n", address, val); val = MS_LittleULONG(val); Write(&val, sizeof(U_LONG), address); }