src/Pure/ML/ml_system.ML
author paulson <lp15@cam.ac.uk>
Sun, 20 May 2018 18:37:34 +0100
changeset 68239 0764ee22a4d1
parent 62508 d0b68218ea55
child 69701 b5ecabcfb780
permissions -rw-r--r--
tidy up of Derivative
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62508
d0b68218ea55 discontinued RAW session: bootstrap directly from isabelle_process RAW_ML_SYSTEM;
wenzelm
parents: 62468
diff changeset
     1
(*  Title:      Pure/ML/ml_system.ML
43948
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     3
48416
5787e1c911d0 more ML_System operations;
wenzelm
parents: 43948
diff changeset
     4
ML system and platform operations.
43948
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     5
*)
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     6
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     7
signature ML_SYSTEM =
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     8
sig
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
     9
  val name: string
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    10
  val platform: string
60962
faa452d8e265 basic setup for native Windows (RAW session without image);
wenzelm
parents: 48416
diff changeset
    11
  val platform_is_windows: bool
62468
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    12
  val platform_path: string -> string
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    13
  val standard_path: string -> string
43948
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    14
end;
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    15
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    16
structure ML_System: ML_SYSTEM =
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    17
struct
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    18
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    19
val SOME name = OS.Process.getEnv "ML_SYSTEM";
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    20
val SOME platform = OS.Process.getEnv "ML_PLATFORM";
60962
faa452d8e265 basic setup for native Windows (RAW session without image);
wenzelm
parents: 48416
diff changeset
    21
val platform_is_windows = String.isSuffix "windows" platform;
43948
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    22
62468
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    23
val platform_path =
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    24
  if platform_is_windows then
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    25
    fn path =>
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    26
      if String.isPrefix "/" path andalso not (String.isPrefix "//" path) then
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    27
        (case String.tokens (fn c => c = #"/") path of
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    28
          "cygdrive" :: drive :: arcs =>
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    29
            let
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    30
              val vol =
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    31
                (case Char.fromString drive of
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    32
                  NONE => drive ^ ":"
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    33
                | SOME d => String.str (Char.toUpper d) ^ ":");
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    34
            in String.concatWith "\\" (vol :: arcs) end
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    35
        | arcs =>
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    36
            (case OS.Process.getEnv "CYGWIN_ROOT" of
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    37
              SOME root => OS.Path.concat (root, String.concatWith "\\" arcs)
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    38
            | NONE => raise Fail "Unknown environment variable CYGWIN_ROOT"))
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    39
      else String.translate (fn #"/" => "\\" | c => String.str c) path
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    40
  else fn path => path;
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    41
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    42
val standard_path =
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    43
  if platform_is_windows then
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    44
    fn path =>
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    45
      let
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    46
        val {vol, arcs, isAbs} = OS.Path.fromString path;
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    47
        val path' = String.translate (fn #"\\" => "/" | c => String.str c) path;
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    48
      in
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    49
        if isAbs then
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    50
          (case String.explode vol of
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    51
            [d, #":"] =>
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    52
              String.concatWith "/" ("/cygdrive" :: String.str (Char.toLower d) :: arcs)
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    53
          | _ => path')
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    54
        else path'
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    55
      end
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    56
  else fn path => path;
d97e13e5ea5b clarified modules;
wenzelm
parents: 62467
diff changeset
    57
43948
8f5add916a99 explicit structure ML_System;
wenzelm
parents:
diff changeset
    58
end;