src/Pure/POLY.ML
changeset 100 e95b98536b3d
parent 73 075db6ac7f2f
child 378 85ff48546a05
equal deleted inserted replaced
99:df0cd0fecf86 100:e95b98536b3d
    36     fn () => brk (99999, 0), en);
    36     fn () => brk (99999, 0), en);
    37 
    37 
    38 
    38 
    39 (*** File handling ***)
    39 (*** File handling ***)
    40 
    40 
       
    41 local
       
    42 
       
    43 (*These are functions from library.ML *)
       
    44 fun take_suffix _ [] = ([], [])
       
    45   | take_suffix pred (x :: xs) =
       
    46       (case take_suffix pred xs of
       
    47          ([], sffx) => if pred x then ([], x :: sffx)
       
    48                                  else ([x], sffx)
       
    49        | (prfx, sffx) => (x :: prfx, sffx));
       
    50 
       
    51 fun apr (f,y) x = f(x,y);
       
    52 
       
    53 in
       
    54 
    41 (*Get a string containing the time of last modification, attributes, owner
    55 (*Get a string containing the time of last modification, attributes, owner
    42   and size of file (but not the path) *)
    56   and size of file (but not the path) *)
    43 fun file_info "" = ""
    57 fun file_info "" = ""
    44   | file_info name =
    58   | file_info name =
    45       let
    59       let
    46           (*These are functions from library.ML *)
       
    47           fun take_suffix _ [] = ([], [])
       
    48             | take_suffix pred (x :: xs) =
       
    49                 (case take_suffix pred xs of
       
    50                   ([], sffx) => if pred x then ([], x :: sffx) else ([x], sffx)
       
    51                 | (prfx, sffx) => (x :: prfx, sffx));
       
    52           fun apr (f,y) x = f(x,y);
       
    53 
       
    54           val (is, os) = ExtendedIO.execute ("ls -l " ^ name)
    60           val (is, os) = ExtendedIO.execute ("ls -l " ^ name)
    55           val (result, _) = take_suffix (apr(op<>," ")) 
    61           val (result, _) = take_suffix (apr(op<>," ")) 
    56                               (explode (ExtendedIO.input_line is))
    62                               (explode (ExtendedIO.input_line is))
    57              (*Remove the part after the last " " (i.e. the path/filename) *)
    63              (*Remove the part after the last " " (i.e. the path/filename) *)
    58         in close_in is;
    64         in close_in is;
    60            implode result
    66            implode result
    61         end;
    67         end;
    62 
    68 
    63 (*Delete a file *)
    69 (*Delete a file *)
    64 fun delete_file name =
    70 fun delete_file name =
    65   let val (_,_) = ExtendedIO.execute ("rm " ^ name)
    71   let val (is, os) = ExtendedIO.execute ("rm " ^ name)
    66   in () end;
    72   in close_in is;
       
    73      close_out os
       
    74   end;
       
    75 
       
    76 (*Get pathname of current working directory *)
       
    77 fun pwd () =
       
    78   let val (is, os) = ExtendedIO.execute ("pwd")
       
    79       val (path, _) = take_suffix (apr(op=,"\n"))
       
    80                        (explode (ExtendedIO.input_line is)) (*remove newline *)
       
    81   in close_in is;
       
    82      close_out os;
       
    83      implode path
       
    84   end;
       
    85 
       
    86 end;
       
    87