Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "share/atspre_staload.hats"
- #include "libats/libc/DATS/dirent.dats"
- #include "libats/ML/DATS/filebas_dirent.dats"
- staload "libats/ML/DATS/string.dats"
- fun
- bad_dir(next: string) : bool =
- case next of
- | "." => true | ".." => true | _ => false
- fun
- step_stream
- (file: string, acc: int) : int =
- (
- if
- test_file_isdir(file) = 1
- then flow_stream(file, acc) else acc + 1
- )
- and
- step_stream_
- (file: Strptr1, acc: int): int =
- let
- val acc =
- step_stream
- ($UN.strptr2string(file), acc) in free(file); acc
- end // end of [step_stream_]
- and
- flow_stream
- (dir: string, acc: int) : int =
- let
- val
- files =
- streamize_dirname_fname(dir)
- val
- files =
- $UN.castvwtp0
- {stream_vt(Strptr1)}(files)
- // end of [val]
- in
- fold_stream(dir, files, acc)
- end
- and
- fold_stream
- ( dir: string
- , files: stream_vt(Strptr1), acc: int): int =
- (
- case+ !files of
- | ~stream_vt_nil
- ((*void*)) => acc
- | ~stream_vt_cons
- (file, files) =>
- if
- bad_dir
- ($UN.strptr2string(file))
- then let
- val () = free(file)
- in
- fold_stream(dir, files, acc)
- end
- else let
- val
- dir_file =
- string0_append3
- ( dir, "/"
- , $UN.strptr2string(file))
- val acc =
- step_stream_(dir_file, acc)
- val () = free(file)
- in
- fold_stream(dir, files, acc)
- end // end of [stream_vt_con]
- )
- implement main0() = println! ("step_stream(.) = ", step_stream(".", 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement