Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis12-cl/src/compiler/gen/file2str/file2str.sml
ViewVC logotype

View of /branches/vis12-cl/src/compiler/gen/file2str/file2str.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3297 - (download) (annotate)
Fri Oct 16 13:57:16 2015 UTC (6 years, 8 months ago) by jhr
File size: 2337 byte(s)
update file2str with UChicago copyright
(* file2str.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *
 * Convert a file to a string embedded in an SML module.
 *)

structure File2Str : sig

    val main : string * string list -> OS.Process.status

    val doit : string * string * string -> unit

  end = struct

    structure F = Format

    val header = "\
          \(* %s\n\
          \ *\n\
          \ * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)\n\
	  \ *\n\
	  \ * COPYRIGHT (c) 2015 The University of Chicago\n\
          \ * All rights reserved.\n\
          \ *\n\
          \ * Generated from %s\n\
          \ *)\n\
          \\n\
          \structure %s =\n\
          \  struct\n\
          \\n\
          \"

    val trailer = "\
          \\n\
          \  end\n\
          \"

    fun load srcFile = let
          val inS = TextIO.openIn srcFile
          fun lp l = (case TextIO.inputLine inS
                 of NONE => List.rev l
                  | SOME ln => lp(ln::l)
                (* end case *))
          in
            (lp [] before TextIO.closeIn inS)
              handle ex => (TextIO.closeIn inS; raise ex)
          end

    fun doit (srcFile, module, outFile) = let
          val text = load srcFile
          val outS = TextIO.openOut outFile
          fun prf (fmt, items) = TextIO.output(outS, F.format fmt items)
          in
            prf (header, [F.STR(OS.Path.file outFile), F.STR srcFile, F.STR module]);
            prf ("    val text = \"\\\n", []);
	    prf ("          \\/*---------- begin %s ----------*/\\n\\\n", [F.STR(srcFile)]);
            List.app (fn ln => prf("          \\%s\\\n", [F.STR(String.toString ln)])) text;
	    prf ("          \\/*---------- end %s ----------*/\\n\\\n", [F.STR(srcFile)]);
            prf ("          \\\"\n", []);
            prf (trailer, []);
            TextIO.closeOut outS
          end

    fun main (_, [srcFile, module, dstFile]) = (
          (doit(srcFile, module, dstFile); OS.Process.success) handle _ => OS.Process.failure)
      | main _ = (
          TextIO.output(TextIO.stdErr, "usage:\n");
          TextIO.output(TextIO.stdErr, "    file2str srcfile module outfile\n");
          OS.Process.failure)

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0