src/Pure/Thy/symbol_input.ML
author paulson
Tue, 22 Jul 1997 11:14:18 +0200
changeset 3538 ed9de44032e0
parent 2405 e1b946f9c8be
child 3605 d372fb6ec393
permissions -rw-r--r--
Removal of the tactical STATE
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 file_exists name = file_info name <> "";
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    17
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    18
fun fix_name name =
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    19
  if file_exists name then name
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    20
  else if file_exists (name ^ ".ML") then name ^ ".ML"
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    21
  else if file_exists (name ^ ".sml") then name ^ ".sml"
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    22
  else error ("File not found: " ^ quote name);
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    23
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    24
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    25
val use =
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    26
  if not needs_filtered_use then use
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    27
  else
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    28
    fn raw_name =>
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    29
      let
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    30
        val name = fix_name raw_name;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    31
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    32
        val infile = TextIO.openIn name;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    33
        val txt = TextIO.inputAll infile;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    34
        val _ = TextIO.closeIn infile;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    35
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    36
        val txt_out = implode (SymbolFont.write_charnames' (explode txt));
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    37
      in
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    38
        if txt = txt_out then use name
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    39
        else
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    40
          let
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    41
            val tmp_name = "/tmp/" ^ base_name name;  (* FIXME unique prefix (!?) *)
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    42
            val outfile = TextIO.openOut tmp_name;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    43
            val _ = TextIO.output (outfile, txt_out);
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    44
            val _ = TextIO.closeOut outfile;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    45
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    46
            val rm = OS.FileSys.remove;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    47
          in
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    48
            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
    49
            rm tmp_name
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    50
          end
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    51
      end;
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    52
e1b946f9c8be symbol_input.ML: Defines 'use' command with symbol input filtering.
wenzelm
parents:
diff changeset
    53
end;