diff --git a/docs/TurboC.md b/docs/TurboC.md index 27bcdbdea..0da3dbcfa 100644 --- a/docs/TurboC.md +++ b/docs/TurboC.md @@ -24,8 +24,3 @@ Note that Turbo C is C only, so it belongs in your `c.local.properties`. Also note that you will immediately get an error with the default example source code, because the compiler doesn't support `//` comments. Also note that in this old C version, you must declare all variables in the first few lines of your functions. - -### Weird behaviour - -* Including default header files seem to break the compilation without error. -* Line numbers for compilation errors always seem to point to line 1 diff --git a/lib/base-compiler.d.ts b/lib/base-compiler.d.ts index aae281ab6..a77438c3d 100644 --- a/lib/base-compiler.d.ts +++ b/lib/base-compiler.d.ts @@ -5,6 +5,7 @@ export declare class BaseCompiler { public outputFilebase: string; protected mtime; protected env; + protected compileFilename; protected getSharedLibraryPathsAsArguments(libraries: object[], libDownloadPath: string); protected getSharedLibraryPathsAsLdLibraryPaths(libraries: object[]); protected getCompilerCacheKey(compiler: string, args: string[], options: object); @@ -12,6 +13,9 @@ export declare class BaseCompiler { protected async newTempDir(); protected filename(fn: string): string; protected optionsForFilter(filters: object, outputFilename: string): string[]; + protected getExtraFilepath(dirPath: string, filename: string): string; + protected async writeAllFiles(dirPath: string, source: string, files: any[], filters: object); + protected async writeMultipleFiles(files: any[], dirPath: string): Promise; public compilerProps: (key: string) => string; public getOutputFilename(dirPath: string, outputFilebase: string, key?: object): string; public async exec(filepath: string, args: string[], execOptions); diff --git a/lib/compilers/dosbox-compiler.ts b/lib/compilers/dosbox-compiler.ts index f6d7db8b2..efdfbab4a 100644 --- a/lib/compilers/dosbox-compiler.ts +++ b/lib/compilers/dosbox-compiler.ts @@ -41,6 +41,37 @@ export class DosboxCompiler extends BaseCompiler { this.root = this.compilerProps(`compiler.${this.compiler.id}.root`); } + protected override async writeMultipleFiles(files: any[], dirPath: string): Promise { + const filesToWrite: any[] = []; + + for (const file of files) { + if (!file.filename) throw new Error('One of more files do not have a filename'); + + const fullpath = this.getExtraFilepath(dirPath, file.filename); + const contents = file.contents.replaceAll(/\n/g, '\r\n'); + filesToWrite.push(fs.outputFile(fullpath, contents)); + } + + return Promise.all(filesToWrite); + } + + protected override async writeAllFiles(dirPath: string, source: string, files: any[], filters: object) { + if (!source) throw new Error(`File ${this.compileFilename} has no content or file is missing`); + + const inputFilename = path.join(dirPath, this.compileFilename); + await fs.writeFile(inputFilename, source.replaceAll(/\n/g, '\r\n')); + + if (files && files.length > 0) { + (filters as any).dontMaskFilenames = true; + + await this.writeMultipleFiles(files, dirPath); + } + + return { + inputFilename, + }; + } + private getDosboxArgs(tempDir: string, compileArgs: string[]) { const binPath = path.relative(this.root, path.dirname(this.compiler.exe)); const exeName = path.basename(this.compiler.exe).replace(/\.exe$/i, ''); diff --git a/lib/compilers/turboc.ts b/lib/compilers/turboc.ts index 4d0f58387..757526da1 100644 --- a/lib/compilers/turboc.ts +++ b/lib/compilers/turboc.ts @@ -25,8 +25,8 @@ import path from 'path'; import {logger} from '../logger'; -import {TurboCParser} from './argument-parsers'; +import {TurboCParser} from './argument-parsers'; import {DosboxCompiler} from './dosbox-compiler'; export class TurboCCompiler extends DosboxCompiler {