#!/usr/bin/env swift; /****************************************************************************** * This program simply writes the bytes 0 - 256 to a binary file. * * Copyright © 2021 Richard Lesh. All rights reserved. *****************************************************************************/ import Foundation import Utils func writeBinaryFile(_ filespec:String) throws -> Void { FileManager.default.createFile(atPath: filespec, contents: nil) let ofh:FileHandle? = FileHandle(forWritingAtPath: filespec) if ofh == nil { throw RuntimeError("Problem opening output file!") } for b:Int in 0...255 { ofh!.write(Data([UInt8(b)])) } try ofh!.close() } // Begin Main if CommandLine.arguments.count != 2 { print("Syntax: " + CommandLine.arguments[0] + " {filename}") exit(1) } var filespec:String = CommandLine.arguments[1] do { try writeBinaryFile(filespec) } catch let ex as RuntimeError { print("Error: " + ex.localizedDescription) } exit(EXIT_SUCCESS)