#!/usr/bin/env swift; /****************************************************************************** * This program simply copies a file to the console character by * character like the Unix 'cat' program. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ import Foundation import Utils func readTextFile(_ filespec:String) throws -> Void { let ifh:StreamReader? = StreamReader(filespec) if ifh == nil { throw RuntimeError("Problem opening input file!") } var c:Int? c = ifh!.getCodepoint() while c != nil { print(Utils.chr(c!), terminator: "") c = ifh!.getCodepoint() } ifh!.close() } // Begin Main if CommandLine.arguments.count != 2 { print("Syntax: " + CommandLine.arguments[0] + " {filename}") exit(1) } var filespec:String = CommandLine.arguments[1] do { try readTextFile(filespec) } catch let ex as RuntimeError { print("Error: " + ex.localizedDescription) } exit(EXIT_SUCCESS)