int Copy() { auto hsrc = INVALID_HANDLE_VALUE; auto hdst = INVALID_HANDLE_VALUE; LPWSTR reason = L"OpenSource"; UINT64 size; auto hr = OpenSource(hsrc, size); if (!hr) { hr = AdjustSource(hsrc, size); if (hr) return hr; reason = L"OpenDestination"; hr = OpenDest(hdst); if (!hr) { hr = AdjustDest(hdst); if (hr) return hr; reason = L"Copy"; hr = Copy(hsrc, hdst, size); } } if (hsrc!=INVALID_HANDLE_VALUE) CloseHandle(hsrc); if (hdst!=INVALID_HANDLE_VALUE) CloseHandle(hdst); if (hr) return Usage(hr, reason); return 0; }
int main(int argc, char* argv[]) { char buf[MAX_PATH]; int base_encoding; /* added */ char* p; char* logo = "SjASMPlus Z80 Cross-Assembler v1.08 (build 07-04-2016)"; int i = 1; if (argc == 1) { _COUT logo _ENDL; _COUT "based on code of SjASM by Sjoerd Mastijn / http://www.xl2s.tk /" _ENDL; _COUT "Copyright 2004-2008 by Aprisobal / http://sjasmplus.sf.net / [email protected] /" _ENDL; _COUT "Modified 2016 AntonioVillena" _ENDL; _COUT "\nUsage:\nsjasmplus [options] sourcefile(s)" _ENDL; _COUT "\nOption flags as follows:" _ENDL; _COUT " --help Help information (you see it)" _ENDL; _COUT " -i<path> or -I<path> or --inc=<path>" _ENDL; _COUT " Include path" _ENDL; _COUT " --lst=<filename> Save listing to <filename>" _ENDL; _COUT " --lstlab Enable label table in listing" _ENDL; _COUT " --sym=<filename> Save symbols list to <filename>" _ENDL; _COUT " --exp=<filename> Save exports to <filename> (see EXPORT pseudo-op)" _ENDL; _COUT " --raw=<filename> Save all output to <filename> ignoring OUTPUT pseudo-ops" _ENDL; _COUT " Logging:" _ENDL; _COUT " --nologo Do not show startup message" _ENDL; _COUT " --msg=error Show only error messages" _ENDL; _COUT " --msg=all Show all messages (by default)" _ENDL; _COUT " --fullpath Show full path to error file" _ENDL; _COUT " Other:" _ENDL; _COUT " --reversepop Enable reverse POP order (as in base SjASM version)" _ENDL; _COUT " --dirbol Enable processing directives from the beginning of line" _ENDL; _COUT " --dos866 Encode from Windows codepage to DOS 866 (Cyrillic)" _ENDL; exit(1); } // init vars Options::DestionationFName[0] = 0; Options::ListingFName[0] = 0; Options::UnrealLabelListFName[0] = 0; Options::SymbolListFName[0] = 0; Options::ExportFName[0] = 0; Options::RAWFName[0] = 0; Options::NoDestinationFile = true; // not *.out files by default // start counter long dwStart; dwStart = GetTickCount(); // get current directory GetCurrentDirectory(MAX_PATH, buf); CurrentDirectory = buf; // get arguments Options::IncludeDirsList = new CStringsList(".", Options::IncludeDirsList); while (argv[i]) { Options::GetOptions(argv, i); if (argv[i]) { STRCPY(SourceFNames[SourceFNamesCount++], LINEMAX, argv[i++]); } } if (!Options::HideLogo) { _COUT logo _ENDL; } if (!SourceFNames[0][0]) { _COUT "No inputfile(s)" _ENDL; exit(1); } if (!Options::DestionationFName[0]) { STRCPY(Options::DestionationFName, LINEMAX, SourceFNames[0]); if (!(p = strchr(Options::DestionationFName, '.'))) { p = Options::DestionationFName; } else { *p = 0; } STRCAT(p, LINEMAX-(p-Options::DestionationFName), ".out"); } // init some vars InitCPU(); // if memory type != none base_encoding = ConvertEncoding; // init first pass InitPass(1); // open lists OpenList(); // open source filenames for (i = 0; i < SourceFNamesCount; i++) { OpenFile(SourceFNames[i]); } _COUT "Pass 1 complete (" _CMDL ErrorCount _CMDL " errors)" _ENDL; ConvertEncoding = base_encoding; do { pass++; InitPass(pass); if (pass == LASTPASS) { OpenDest(); } for (i = 0; i < SourceFNamesCount; i++) { OpenFile(SourceFNames[i]); } if (PseudoORG) { CurAddress = adrdisp; PseudoORG = 0; } if (pass != LASTPASS) { _COUT "Pass " _CMDL pass _CMDL " complete (" _CMDL ErrorCount _CMDL " errors)" _ENDL; } else { _COUT "Pass 3 complete" _ENDL; } } while (pass < 3);//MAXPASSES); pass = 9999; /* added for detect end of compiling */ if (Options::AddLabelListing) { LabelTable.Dump(); } Close(); if (Options::UnrealLabelListFName[0]) { LabelTable.DumpForUnreal(); } if (Options::SymbolListFName[0]) { LabelTable.DumpSymbols(); } _COUT "Errors: " _CMDL ErrorCount _CMDL ", warnings: " _CMDL WarningCount _CMDL ", compiled: " _CMDL CompiledCurrentLine _CMDL " lines" _END; double dwCount; dwCount = GetTickCount() - dwStart; if (dwCount < 0) { dwCount = 0; } printf(", work time: %.3f seconds", dwCount / 1000); _COUT "" _ENDL; cout << flush; // free RAM if (Devices) { delete Devices; } return (ErrorCount != 0); }
void CapASM::Compile(const char * filename) { std::cout << "&Compilation of " << string(filename).c_str() << endl ; char buf[MAX_PATH]; int base_encoding; /* added */ char* p; int i = 1; CleanUP(); // init LUA LUA = lua_open(); lua_atpanic(LUA, (lua_CFunction)LuaFatalError); luaL_openlibs(LUA); luaopen_pack(LUA); tolua_sjasm_open(LUA); // init vars Options::DestionationFName[0] = 0; STRCPY( Options::ListingFName, LINEMAX, "/tmp/caprice.lst"); //TODO generate file name Options::UnrealLabelListFName[0] = 0; STRCPY( Options::SymbolListFName, LINEMAX, "/tmp/caprice.sym"); Options::ExportFName[0] = 0; Options::RAWFName[0] = 0; Options::NoDestinationFile = true; // not *.out files by default // start counter long dwStart; dwStart = GetTickCount(); // get current directory GetCurrentDirectory(MAX_PATH, buf); CurrentDirectory = buf; STRCPY(SourceFNames[SourceFNamesCount++], LINEMAX, filename); if (!SourceFNames[0][0]) { _COUT "No inputfile(s)" _ENDL; return; } if (!Options::DestionationFName[0]) { STRCPY(Options::DestionationFName, LINEMAX, SourceFNames[0]); if (!(p = strchr(Options::DestionationFName, '.'))) { p = Options::DestionationFName; } else { *p = 0; } STRCAT(p, LINEMAX-(p-Options::DestionationFName), ".out"); } // init some vars InitCPU(); // if memory type != none base_encoding = ConvertEncoding; // init first pass InitPass(1); // open lists OpenList(); // open source filenames for (i = 0; i < SourceFNamesCount; i++) { OpenFile(SourceFNames[i]); } _COUT "Pass 1 complete (" _CMDL ErrorCount _CMDL " errors)" _ENDL; ConvertEncoding = base_encoding; do { pass++; InitPass(pass); if (pass == LASTPASS) { OpenDest(); } for (i = 0; i < SourceFNamesCount; i++) { OpenFile(SourceFNames[i]); } if (PseudoORG) { CurAddress = adrdisp; PseudoORG = 0; } if (pass != LASTPASS) { _COUT "Pass " _CMDL pass _CMDL " complete (" _CMDL ErrorCount _CMDL " errors)" _ENDL; } else { _COUT "Pass 3 complete" _ENDL; } } while (pass < 3);//MAXPASSES); pass = 9999; /* added for detect end of compiling */ if (Options::AddLabelListing) { LabelTable.Dump(); } Close(); if (Options::UnrealLabelListFName[0]) { LabelTable.DumpForUnreal(); } if (Options::SymbolListFName[0]) { LabelTable.DumpSymbols(); } _COUT "Errors: " _CMDL ErrorCount _CMDL ", warnings: " _CMDL WarningCount _CMDL ", compiled: " _CMDL CompiledCurrentLine _CMDL " lines" _END; double dwCount; dwCount = GetTickCount() - dwStart; if (dwCount < 0) { dwCount = 0; } printf(", work time: %.3f seconds", dwCount / 1000); _COUT "" _ENDL; #ifndef UNDER_CE cout << flush; #endif // free RAM delete Devices; Devices = 0; // close Lua lua_close(LUA); //return (ErrorCount != 0); }