fixed parser

This commit is contained in:
mmichlol
2026-02-06 18:21:58 +01:00
parent f192c5a367
commit 196140f9b8
3 changed files with 76 additions and 48 deletions

View File

@@ -90,24 +90,31 @@ int main(int argc, char* argv[]) {
// --- ZAPIS I KOMPILACJA ZEWNĘTRZNA ---
std::system("if not exist output mkdir output");
std::string baseName = outputName.empty() ?
inputFile.substr(0, inputFile.find_last_of(".")) : outputName;
// Upewnij się, że nazwa nie ma rozszerzenia .exe w środku ścieżki
// 1. Ustal bazową nazwę (bez rozszerzenia)
std::string baseName;
if (outputName.empty()) {
if (baseName.find(".exe") == std::string::npos) baseName += ".exe";
// Jeśli nie podano -o, weź nazwę pliku wejściowego i utnij .pcc
size_t lastDot = inputFile.find_last_of(".");
if (lastDot != std::string::npos)
baseName = inputFile.substr(0, lastDot);
else
baseName = inputFile;
}
else {
// Jeśli użytkownik podał nazwę bez .exe, dodaj ją
if (outputName.find(".exe") == std::string::npos) outputName += ".exe";
baseName = outputName;
// Jeśli podano -o, sprawdź czy ma .exe i ewentualnie utnij
// (żebyśmy mogli dodać .asm i .obj bez bałaganu)
size_t exePos = outputName.find(".exe");
if (exePos != std::string::npos)
baseName = outputName.substr(0, exePos);
else
baseName = outputName;
}
// Ścieżki wyjściowe
// Uwaga: zakładam proste nazewnictwo, można tu poprawić usuwanie ścieżek z nazwy pliku
// Teraz budujemy ścieżki - czysto i ładnie
std::string asmPath = "output\\" + baseName + ".asm";
std::string objPath = "output\\" + baseName + ".obj";
std::string exePath = "output\\" + baseName;
std::string exePath = "output\\" + baseName + ".exe";
// Zapisz ASM
std::ofstream asmOut(asmPath);