Verified Commit 7f3fe2ca authored by Camil Staps's avatar Camil Staps 🚀

Add copyfile example (without expected outcome, because it uses file IO)

parent f4db1399
......@@ -6,6 +6,7 @@ brainfuck
cafs
chars
compress
copyfile
curry
e
fills
......
module copyfile
/*
Commandline version of a file copying program.
Run the program using the "Basic Values Only" option.
*/
import StdEnv, StdFile
Start::*World -> *File
Start world = fwrites "\nGoodbye.\n" stdinout`
where
(stdinout`,_) = accFiles (CommandLoop stdinout) world`
(stdinout ,world`) = stdio world
CommandLoop::*File *Files -> (*File,*Files)
CommandLoop stdio files = CommandLoop` stdio` files`
where
(files`,stdio`) = Copy files stdio
CommandLoop`::*File *Files -> (*File,*Files)
CommandLoop` stdio files
| answer<>'y' && answer<>'Y' = (stdio2,files)
= CommandLoop` stdio` files`
where
(files`,stdio`) = Copy files stdio2
answer = FirstChar answ
(answ ,stdio2) = freadline stdio1
stdio1 = fwrites "\nCopy another file (y/n)? " stdio
Copy::*Files *File -> (*Files,*File)
Copy files io
| source == dest = (files, fwrites "\nCopying succeeded.\n" io4)
= CopyFile (StripNewline source) (StripNewline dest) files io4
where
(dest,io4) = freadline io3
io3 = fwrites "\nDestination file: " io2
(source,io2) = freadline io1
io1 = fwrites "\nSource file: " io
CopyFile::String String *Files *File -> (*Files,*File)
CopyFile source dest files io
| not sopen = (files1,alert1)
| not dopen = (files2,alert2)
| io_error = (files4,alert3)
| not dclose = (files4,alert4)
| not sclose = (files4,alert5)
= (files4,alert6)
where
(sclose,files4) = fclose sfile` files3
(dclose,files3) = fclose dfile` files2
(io_error,sfile`,dfile`) = CopyFiles sfile dfile
(dopen,dfile,files2) = fopen dest FWriteText files1
(sopen,sfile,files1) = fopen source FReadData files
alert1 = fwrites "\nCopying failed.\nSource file could not be opened.\n" io
alert2 = fwrites "Copying failed.\nDestination file could not be opened.\n" io
alert3 = fwrites "Copying failed.\nFile I/O error.\n" io
alert4 = fwrites "Copying failed.\nDestination file could not be closed.\n" io
alert5 = fwrites "Copying failed.\nSource file could not be closed.\n" io
alert6 = fwrites "\nCopying succeeded.\n" io
CopyFiles::*File *File -> (Bool, *File, *File)
CopyFiles source dest
| srcend || wrterror = (wrterror,source1,dest1)
= CopyFiles source2 (fwritec byte dest1)
where
(_,byte,source2) = freadc source1
(srcend,source1) = fend source
(wrterror,dest1) = ferror dest
StripNewline::String -> String
StripNewline "" = ""
StripNewline str = str % (0, size str - 2)
FirstChar::String -> Char
FirstChar "" = ' '
FirstChar str = str.[0]
Version: 1.5
Global
ProjectRoot: .
Target: StdEnv
Exec: {Project}/copyfile
ByteCode: {Project}/copyfile.bc
CodeGen
CheckStacks: False
CheckIndexes: True
OptimiseABC: True
GenerateByteCode: True
Application
HeapSize: 409600
StackSize: 102400
ExtraMemory: 81920
IntialHeapSize: 204800
HeapSizeMultiplier: 4096
ShowExecutionTime: False
ShowGC: False
ShowStackSize: False
MarkingCollector: False
DisableRTSFlags: False
StandardRuntimeEnv: True
Profile
Memory: False
MemoryMinimumHeapSize: 0
Time: False
Stack: False
Dynamics: False
GenericFusion: False
DescExL: False
Output
Output: ShowConstructors
Font: Courier
FontSize: 9
WriteStdErr: False
Link
LinkMethod: Static
GenerateRelocations: False
GenerateSymbolTable: False
GenerateLinkMap: False
LinkResources: False
ResourceSource:
GenerateDLL: False
ExportedNames:
StripByteCode: True
KeepByteCodeSymbols: True
PrelinkByteCode: False
Paths
Path: {Project}
Precompile:
Postlink:
MainModule
Name: copyfile
Dir: {Project}
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment