src/Pure/POLY.ML
author clasohm
Fri, 15 Oct 1993 12:51:21 +0100
changeset 58 b30802dfbe80
parent 19 929ad32d63fc
child 66 1b14cd923772
permissions -rw-r--r--
file_info now returns a string that does not contain the path/filename (so the string doesn't change when the relative path does)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title:      Pure/POLY
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1991  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Compatibility file for Poly/ML (AHL release 1.88)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
open PolyML ExtendedIO;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
(*A conditional timing function: applies f to () and, if the flag is true,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
  prints its runtime.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
fun cond_timeit flag f =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
  if flag then
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
    let val before = System.processtime()
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
        val result = f()
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
        val both = real(System.processtime() - before) / 10.0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
    in  output(std_out, "Process time (incl GC): "^
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
                         makestring both ^ " secs\n");
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
        result
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
    end
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
  else f();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
(*Save function: in Poly/ML, ignores filename and commits to present file*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
fun xML filename banner = commit();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
(*Interface for toplevel pretty printers, see also Pure/install_pp.ML*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
fun make_pp _ pprint (str, blk, brk, en) obj =
19
929ad32d63fc Pure/ROOT.ML
wenzelm
parents: 0
diff changeset
    35
  pprint obj (str, fn ind => blk (ind, false), fn wd => brk (wd, 0),
929ad32d63fc Pure/ROOT.ML
wenzelm
parents: 0
diff changeset
    36
    fn () => brk (99999, 0), en);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
(*** File information ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
58
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    41
(*Get a string containing the time of last modification, attributes, owner
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    42
  and size of file (but not the path) *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
fun file_info "" = ""
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
  | file_info name =
58
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    45
      let
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    46
          (*These are functions from library.ML *)
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    47
          fun take_suffix _ [] = ([], [])
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    48
            | take_suffix pred (x :: xs) =
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    49
                (case take_suffix pred xs of
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    50
                  ([], sffx) => if pred x then ([], x :: sffx) else ([x], sffx)
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    51
                | (prfx, sffx) => (x :: prfx, sffx));
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    52
          fun apr (f,y) x = f(x,y);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
58
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    54
          val (is, os) = ExtendedIO.execute ("ls -l " ^ name)
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    55
          val (result, _) = take_suffix (apr(op<>," ")) 
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    56
                              (explode (ExtendedIO.input_line is))
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    57
                (*Remove the part after the last " " (i.e. the path/filename) *)
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    58
        in close_in is;
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    59
           close_out os;
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    60
           implode result
b30802dfbe80 file_info now returns a string that does not contain the path/filename
clasohm
parents: 19
diff changeset
    61
        end;