src/Pure/Thy/symbol_input.ML
author wenzelm
Wed, 12 Nov 1997 16:23:11 +0100
changeset 4216 419113535e48
parent 3626 d91708377b6a
permissions -rw-r--r--
File system operations.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2405
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/symbol_input.ML
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     3
    Author:     David von Oheimb and Markus Wenzel, TU Muenchen
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     4
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     5
Defines 'use' command with symbol input filtering.
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     6
*)
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     7
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     8
signature SYMBOL_INPUT =
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
     9
sig
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    10
  val use: string -> unit
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    11
end;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    12
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    13
structure SymbolInput: SYMBOL_INPUT =
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    14
struct
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    15
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    16
fun fix_name name =
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    17
  if file_exists name then name
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    18
  else if file_exists (name ^ ".ML") then name ^ ".ML"
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    19
  else if file_exists (name ^ ".sml") then name ^ ".sml"
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    20
  else error ("File not found: " ^ quote name);
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    21
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    22
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    23
val use =
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    24
  if not needs_filtered_use then use
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    25
  else
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    26
    fn raw_name =>
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    27
      let
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    28
        val name = fix_name raw_name;
3626
wenzelm
parents: 3605
diff changeset
    29
        val txt = read_file name;
2405
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    30
        val txt_out = implode (SymbolFont.write_charnames' (explode txt));
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    31
      in
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    32
        if txt = txt_out then use name
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    33
        else
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    34
          let
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    35
            val tmp_name = "/tmp/" ^ base_name name;  (* FIXME unique prefix (!?) *)
3626
wenzelm
parents: 3605
diff changeset
    36
            val _ = write_file tmp_name txt_out;
2405
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    37
            val rm = OS.FileSys.remove;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    38
          in
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    39
            use tmp_name handle exn => (rm tmp_name; raise exn);
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    40
            rm tmp_name
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    41
          end
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    42
      end;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    43
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    44
end;