Permalink
Browse files

Adding files equivalent to version 1.0.0 plus some copyright notices

  • Loading branch information...
0 parents commit 372c98f8b1fd78caaa14ff66e1756b23c82b66f7 mjambon committed Apr 27, 2008
Showing with 256 additions and 0 deletions.
  1. +24 −0 LICENSE
  2. +5 −0 META.in
  3. +44 −0 Makefile
  4. +72 −0 README
  5. +111 −0 tophide.ml
24 LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2008 Martin Jambon <martin@mjambon.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,5 @@
+# specifications for "tophide":
+description = "Hiding toplevel _values"
+requires = ""
+archive(byte,toploop) = "tophide.cmo"
+archive(byte,create_toploop) = "tophide.cmo"
@@ -0,0 +1,44 @@
+# Copyright 2008 Martin Jambon. All rights reserved.
+# This file is distributed under the terms stated in file LICENSE.
+
+VERSION = 1.0.0
+export VERSION
+
+.PHONY: all install clean
+
+all: META tophide.cmo
+tophide.cmo: tophide.ml
+ ocamlc -c tophide.ml
+
+install:
+ ocamlfind install tophide META tophide.cmi tophide.cmo
+
+uninstall:
+ ocamlfind remove tophide
+
+clean:
+ rm -f *.cmo *.cmi
+
+META: META.in Makefile
+ cat META.in > META
+ echo 'version = "$(VERSION)"' >> META
+
+archive:
+ rm -rf /tmp/tophide /tmp/tophide-$(VERSION) && \
+ cp -r . /tmp/tophide && \
+ cd /tmp/tophide && \
+ $(MAKE) clean && \
+ $(MAKE) META && \
+ rm -f *~ tophide*.tar* && \
+ cd /tmp && cp -r tophide tophide-$(VERSION) && \
+ tar czf tophide.tar.gz tophide && \
+ tar cjf tophide.tar.bz2 tophide && \
+ tar czf tophide-$(VERSION).tar.gz tophide-$(VERSION) && \
+ tar cjf tophide-$(VERSION).tar.bz2 tophide-$(VERSION)
+ mv /tmp/tophide.tar.gz /tmp/tophide.tar.bz2 ..
+ mv /tmp/tophide-$(VERSION).tar.gz /tmp/tophide-$(VERSION).tar.bz2 ..
+ cp ../tophide.tar.gz ../tophide.tar.bz2 $$WWW/
+ cp ../tophide-$(VERSION).tar.gz ../tophide-$(VERSION).tar.bz2 $$WWW/
+ cp README $$WWW/tophide-readme.txt
+ cp LICENSE $$WWW/tophide-license.txt
+ echo 'let tophide_version = "$(VERSION)"' > $$WWW/tophide-version.ml
72 README
@@ -0,0 +1,72 @@
+Tophide
+=======
+
+Tophide is meant to be loaded in an ocaml toplevel.
+Definitions of values whose name starts with an underscore do not result
+in the typical 'val NAME : TYPE' output but are simply not shown.
+
+This behavior is particularly useful for hiding preprocessor-generated
+values that are not meant to be reviewed by the user/programmer.
+
+
+1. Installation
+
+ make
+ make install # requires ocamlfind
+
+Uninstallation can be performed with
+
+ make uninstall # requires ocamlfind
+
+
+2. Usage
+
+There are two modes: "hide" and "show".
+
+The "hide" mode is automatically triggered when tophide is loaded.
+It is the mode that hides the values whose name starts with "_".
+
+The "show" mode is the regular mode. This mode can be entered using the
+"#hide" directive. It restores the output functions as they were just before
+tophide was loaded.
+The "#hide" directive allows to switch back to the "hide" mode.
+
+
+3. Example
+
+The best way of using this is with findlib.
+Findlib provides the "#require" directive for finding and loading a given
+package.
+
+#use "topfind";; (* just once *)
+- : unit = ()
+Findlib has been successfully loaded. Additional directives:
+ #require "package";; to load a package
+ #list;; to list the available packages
+ #camlp4o;; to load camlp4 (standard syntax)
+ #camlp4r;; to load camlp4 (revised syntax)
+ #predicates "p,q,...";; to set these predicates
+ Topfind.reset();; to force that packages will be reloaded
+ #thread;; to enable threads
+
+- : unit = ()
+# #require "tophide";; (* loads tophide *)
+/home/martin/godi/lib/ocaml/site-lib/tophide: added to search path
+/home/martin/godi/lib/ocaml/site-lib/tophide/tophide.cmo: loaded
+
+
+
+
+It is recommended to put these directives into a .ocamlinit file.
+Then they would be executed at the beginning of each ocaml session.
+(see chapter "The toplevel system (ocaml)" of the Objective Caml reference
+manual)
+
+Let's see what we get:
+
+# let a = 1;;
+val a : int = 1
+# let _a = 2;; (* good, no output for _a! *)
+#
+
+Now you can load your favorite camlp4 extensions.
@@ -0,0 +1,111 @@
+(* $Id$ *)
+
+(*
+ Copyright 2008 Martin Jambon. All rights reserved.
+ This file is distributed under the terms stated in file LICENSE.
+*)
+
+open Toploop
+open Outcometree
+
+type env = {
+ print_out_class_type :
+ Format.formatter -> out_class_type -> unit;
+ print_out_module_type :
+ Format.formatter -> out_module_type -> unit;
+ print_out_phrase :
+ Format.formatter -> out_phrase -> unit;
+ print_out_sig_item :
+ Format.formatter -> out_sig_item -> unit;
+ print_out_signature :
+ Format.formatter -> out_sig_item list -> unit;
+ print_out_type :
+ Format.formatter -> out_type -> unit;
+ print_out_value :
+ Format.formatter -> out_value -> unit;
+}
+
+let save_env () = {
+ print_out_class_type = !print_out_class_type;
+ print_out_module_type = !print_out_module_type;
+ print_out_phrase = !print_out_phrase;
+ print_out_sig_item = !print_out_sig_item;
+ print_out_signature = !print_out_signature;
+ print_out_type = !print_out_type;
+ print_out_value = !print_out_value;
+}
+
+let load_env env =
+ print_out_class_type := env.print_out_class_type;
+ print_out_module_type := env.print_out_module_type;
+ print_out_phrase := env.print_out_phrase;
+ print_out_sig_item := env.print_out_sig_item;
+ print_out_signature := env.print_out_signature;
+ print_out_type := env.print_out_type;
+ print_out_value := env.print_out_value
+
+
+let default_env = save_env ()
+
+let filter_sig_item = function
+ Osig_class (_, _, _, _, _)
+ | Osig_class_type (_, _, _, _, _)
+ | Osig_exception _
+ | Osig_modtype _
+ | Osig_module _
+ | Osig_type _ as x -> Some x
+ | Osig_value (name, _, _) as x ->
+ if name <> "" && name.[0] = '_' then None
+ else Some x
+
+
+let rec select f = function
+ [] -> []
+ | hd :: tl ->
+ match f hd with
+ None -> select f tl
+ | Some x -> x :: select f tl
+
+
+let special_print_out_phrase fmt x0 =
+ let x =
+ match x0 with
+ Ophr_signature l0 ->
+ let l =
+ select (
+ fun (si0, ov) ->
+ match filter_sig_item si0 with
+ None -> None
+ | Some si -> Some (si, ov)
+ ) l0
+ in
+ Ophr_signature l
+
+ | Ophr_eval _
+ | Ophr_exception _ -> x0
+ in
+ default_env.print_out_phrase fmt x
+
+
+let special_env =
+ { default_env with print_out_phrase = special_print_out_phrase }
+
+
+let hide () = load_env special_env
+let show () = load_env default_env
+
+let _ =
+ (* Add "#hide" directive: *)
+ Hashtbl.add
+ directive_table
+ "hide"
+ (Directive_none hide);
+
+ (* Add "#show" directive: *)
+ Hashtbl.add
+ directive_table
+ "show"
+ (Directive_none show);
+
+ (* Enter "hide" mode upon loading *)
+ hide ()

0 comments on commit 372c98f

Please sign in to comment.