Parcourir la source

Merge commit 'ba024d3'

Leo il y a 10 ans
Parent
commit
b9fd6c00b2
31 fichiers modifiés avec 1303 ajouts et 403 suppressions
  1. 3 0
      .gitignore
  2. 7 2
      0install.sh
  3. 40 0
      CHANGELOG.md
  4. 1 3
      INSTALL.md
  5. 4 3
      README.md
  6. 8 0
      THANKS.md
  7. 20 9
      TODO.md
  8. 1 1
      VERSION
  9. 12 4
      _oasis
  10. 2 2
      configure
  11. BIN
      logo-128.png
  12. BIN
      logo.png
  13. 271 0
      logo.svg
  14. 52 66
      myocamlbuild.ml
  15. 178 215
      setup.ml
  16. 68 0
      src/add_command.ml
  17. 108 0
      src/command_def.ml
  18. 14 10
      src/const.ml
  19. 6 8
      src/default.ml
  20. 95 0
      src/edit_command.ml
  21. 25 33
      src/exec_cmd.ml
  22. 24 6
      src/file_com.ml
  23. 52 0
      src/list_rc.ml
  24. 3 28
      src/oclaunch.ml
  25. 78 0
      src/remove_command.ml
  26. 1 1
      src/settings.atd
  27. 53 0
      src/state.ml
  28. 45 0
      src/tmp_biniou.atd
  29. 63 12
      src/tmp_file.ml
  30. 46 0
      src/tmp_file.mli
  31. 23 0
      version_set.sh

+ 3 - 0
.gitignore

@@ -3,6 +3,9 @@ oclaunch.byte
 settings_j.ml*
 settings_j.ml*
 settings_t.ml*
 settings_t.ml*
 settings_v.ml*
 settings_v.ml*
+tmp_biniou_b.ml*
+tmp_biniou_t.ml*
+tmp_biniou_v.ml*
 # Oasis
 # Oasis
 _build
 _build
 _tags
 _tags

+ 7 - 2
0install.sh

@@ -2,21 +2,26 @@
 
 
 # Script to create 0install archives
 # Script to create 0install archives
 
 
+# Get and set compilation settings
+./configure --disable-debug --disable-docs --disable-profile --disable-tests > BUILD_INFO.txt
+
 # First compile
 # First compile
 make
 make
 
 
 # Copy in dist
 # Copy in dist
 cp ./_build/src/oclaunch.native ./dist/oclaunch
 cp ./_build/src/oclaunch.native ./dist/oclaunch
+# Move BUILD_INFO
+mv BUILD_INFO.txt ./dist/
 
 
 cd dist
 cd dist
 # Archive name
 # Archive name
 name=oclaunch-v$(cat ../VERSION)
 name=oclaunch-v$(cat ../VERSION)
 mkdir $name
 mkdir $name
 # Put executable in it
 # Put executable in it
-mv oclaunch $name
+mv oclaunch BUILD_INFO.txt $name
 
 
 # XXX Debug
 # XXX Debug
 tree
 tree
 
 
 # Create archive
 # Create archive
-tar -cvjf $name.tar.bz2 $name
+tar -cvaf $name.tar.lzma $name

+ 40 - 0
CHANGELOG.md

@@ -0,0 +1,40 @@
+# Changelog of OcLaunch
+
+## v0.2.1
+ + Add new command line option:
+   + “-c file” allow to read configuration from custom file.
+   + “-m n” allow to edit and add (simultaneously) items to launch in rc file.
+ + Improve “-l”: now display a “\*” next to current state.
+ + Code clean up (Types in records) and code factoring.
+ + When all has been launched, the program explain how to reset.
+
+## v0.2.0
+ + Add new command line option.
+   + “-r” can now take a number to start from.
+   + “-l” list commands of the configuration file with its number.
+   + “-a” add the command given on stdin to configuration file.
+   + “-d n” remove the nth command from rc file.
+   + “-n” display the current state.
+ + Improve some messages.
+ + Display run commands in title bar of the windows terminal.
+ + New tmp file
+   + Biniou format instead of JSON
+   + Now cached
+   + New default name : `/tmp/.oclaunch_trace.dat`
+ + Add logo.
+ + Clean up some code.
+ + Improve utility set given with the repository (developer)
+
+## v0.1.x
+
+### v0.1.3
+ + Correct bug (See commit 4d20125a03c6f8735f39a95bb9e68a0476c89d45).
+
+### v0.1.2
+ + First public usable version.
+   + Create wiki.
+   + Use Oasis
+ + First version to be distributed with 0install.
+
+## Before
+ + Wast and test

+ 1 - 3
INSTALL.md

@@ -1,5 +1,5 @@
 <!--- OASIS_START --->
 <!--- OASIS_START --->
-<!--- DO NOT EDIT (digest: e7b8287f66afa5461baa99be98a80d6d) --->
+<!--- DO NOT EDIT (digest: 788c36d836a82ea33e30031012ae594a) --->
 
 
 This is the INSTALL file for the OcLaunch distribution.
 This is the INSTALL file for the OcLaunch distribution.
 
 
@@ -14,9 +14,7 @@ In order to compile this package, you will need:
 * ocaml
 * ocaml
 * findlib
 * findlib
 * core
 * core
-* yojson
 * atdgen
 * atdgen
-* core_extended
 
 
 Installing
 Installing
 ==========
 ==========

+ 4 - 3
README.md

@@ -1,12 +1,13 @@
 <!--- OASIS_START --->
 <!--- OASIS_START --->
-<!--- DO NOT EDIT (digest: cdb6b073a15c4d6ef412a27f7efc808a) --->
+<!--- DO NOT EDIT (digest: 0ca605b95a7a33ed1adef17372475264) --->
 
 
 OcLaunch - Launch commands automatically
 OcLaunch - Launch commands automatically
 ========================================
 ========================================
 
 
 OcLaunch is a command-line tool to launch successively (each time the program
 OcLaunch is a command-line tool to launch successively (each time the program
 is called) commands. It is designed to be used with any program, interactive
 is called) commands. It is designed to be used with any program, interactive
-or not. This a early version. Feedback is welcomed at leowzukw@vmail.me.
+or not. Feedback is welcomed at leowzukw@vmail.me. Help at
+https://gitlab.com/WzukW/oclaunch/wikis/home.
 
 
 See the file [INSTALL.md](INSTALL.md) for building and installation
 See the file [INSTALL.md](INSTALL.md) for building and installation
 instructions.
 instructions.
@@ -16,7 +17,7 @@ instructions.
 Copyright and license
 Copyright and license
 ---------------------
 ---------------------
 
 
-(C) 2014 Joly Clément
+(C) 2014-2015 Joly Clément
 
 
 OcLaunch is distributed under the terms of the CEA-CNRS-INRIA Logiciel Libre.
 OcLaunch is distributed under the terms of the CEA-CNRS-INRIA Logiciel Libre.
 
 

+ 8 - 0
THANKS.md

@@ -0,0 +1,8 @@
+# Thanks to
+
+## Alexander James Wright and Dario Moriconi, from the noun project
+for the icon on which the logo is based.   
+Thanks also to [ocaml.org](http://www.ocaml.org) for the camel.
+
+The result is licensed under CC-BY.
+

+ 20 - 9
TODO.md

@@ -1,17 +1,20 @@
 # Things to do
 # Things to do
 
 
 ## Users idees
 ## Users idees
+
+ + Add confirmation on delete.
+ + Add undo command ?
+ + Show help in context
+
     **Feel free to add things here (and make a pull request).
     **Feel free to add things here (and make a pull request).
     Or send an email to the author !**
     Or send an email to the author !**
 
 
-    + @RomFouq: Add message on reset
-
+## Major issue
+ + Make multiple tmp file really working by using checksum for rc file.
 
 
 ## Short term
 ## Short term
-
-### Commands
- + Add command to modify configuration file
- + Allow to list all available commands
+ + Use a dedicated module, for user messages. Allow to print in color and to set
+   verbsity level (maybe also script output, in JSON format)
 
 
 ### Configuration value
 ### Configuration value
  + Make displaying command before launching configurable
  + Make displaying command before launching configurable
@@ -23,12 +26,20 @@
     + easy : one entry on each call
     + easy : one entry on each call
     + confirm : ask before launching each entry
     + confirm : ask before launching each entry
     + proportionate : launch by percent.
     + proportionate : launch by percent.
- + Relaunch the terminal detached after (possibole ?)
+ + Relaunch the terminal detached after (possible -> use $TERM &; it resists to
+   program exit)
  + Allow to tag entry and do things according to tags
  + Allow to tag entry and do things according to tags
  + Display text before and after, maybe in color (For example
  + Display text before and after, maybe in color (For example
    "================================================")
    "================================================")
 
 
 ### Misc
 ### Misc
  + Documentation ;-)
  + Documentation ;-)
- + Reuse atdgen for tmp file
- + Use biniou in tmp file
+ + Handle errors in reading rc file
+ + Return error code when necessary
+ + Add build info in binary for 0install
+ + Use color in messages
+
+## Long term
+ + Translate displayed messages.
+ + Better command line interface by grouping commands.
+ + Use Batteries instead of Core to improve apps size?

+ 1 - 1
VERSION

@@ -1 +1 @@
-0.1.3
+0.2.1-rc1

+ 12 - 4
_oasis

@@ -1,12 +1,12 @@
 OASISFormat: 0.4
 OASISFormat: 0.4
 Name:        OcLaunch
 Name:        OcLaunch
-Version:     0.1.3
+Version:     0.2.1-rc1
 Synopsis:    Launch commands automatically
 Synopsis:    Launch commands automatically
 Authors:     Joly Clément <leowzukw@vmail.me>
 Authors:     Joly Clément <leowzukw@vmail.me>
 Maintainers: Joly Clément <leowzukw@vmail.me>
 Maintainers: Joly Clément <leowzukw@vmail.me>
 License:     CeCILL
 License:     CeCILL
 LicenseFile: LICENSE
 LicenseFile: LICENSE
-Copyrights: (C) 2014 Joly Clément
+Copyrights: (C) 2014-2015 Joly Clément
 Homepage: http://www.oclaunch.tuxfamily.org
 Homepage: http://www.oclaunch.tuxfamily.org
 BuildTools: ocamlbuild, camlp4o
 BuildTools: ocamlbuild, camlp4o
 Plugins: StdFiles (0.4), DevFiles (0.4)
 Plugins: StdFiles (0.4), DevFiles (0.4)
@@ -14,14 +14,22 @@ XStdFilesREADME: true
 XStdFilesINSTALL: true
 XStdFilesINSTALL: true
 XStdFilesAUTHORS: true
 XStdFilesAUTHORS: true
 AlphaFeatures: stdfiles_markdown, compiled_setup_ml
 AlphaFeatures: stdfiles_markdown, compiled_setup_ml
-Description: OcLaunch is a command-line tool to launch successively (each time the program is called) commands. It is designed to be used with any program, interactive or not. This a early version. Feedback is welcomed at leowzukw@vmail.me.
+Description: OcLaunch is a command-line tool to launch successively (each time
+the program is called) commands. It is designed to be used with any program,
+interactive or not. Feedback is welcome at leowzukw@vmail.me. Help at
+https://gitlab.com/WzukW/oclaunch/wikis/home. Try it, it works automatically!
 
 
 PreBuildCommand: atdgen -t ./src/settings.atd
 PreBuildCommand: atdgen -t ./src/settings.atd
 PreBuildCommand: atdgen -j ./src/settings.atd
 PreBuildCommand: atdgen -j ./src/settings.atd
 PreBuildCommand: atdgen -v ./src/settings.atd
 PreBuildCommand: atdgen -v ./src/settings.atd
+PreBuildCommand: atdgen -b ./src/tmp_biniou.atd
+PreBuildCommand: atdgen -t ./src/tmp_biniou.atd
+PreBuildCommand: atdgen -v ./src/tmp_biniou.atd
+# Test, to be shure that atgen commands above run
+PreBuildCommand: echo "Atdgen executed"
 
 
 Executable oclaunch
 Executable oclaunch
   Path:       src
   Path:       src
   MainIs:     oclaunch.ml
   MainIs:     oclaunch.ml
-  BuildDepends: core, yojson, atdgen, threads, core_extended
+  BuildDepends: core, atdgen, threads
   CompiledObject: best
   CompiledObject: best

+ 2 - 2
configure

@@ -1,7 +1,7 @@
 #!/bin/sh
 #!/bin/sh
 
 
 # OASIS_START
 # OASIS_START
-# DO NOT EDIT (digest: 6f7b8221311e800a7093dc3b793f67ca)
+# DO NOT EDIT (digest: 82230d61386befb40bc7377608e1f16e)
 set -e
 set -e
 
 
 FST=true
 FST=true
@@ -23,5 +23,5 @@ for i in "$@"; do
   esac
   esac
 done
 done
 
 
-make configure CONFIGUREFLAGS="$*"
+make configure CONFIGUREFLAGS="$@"
 # OASIS_STOP
 # OASIS_STOP

BIN
logo-128.png


BIN
logo.png


Fichier diff supprimé car celui-ci est trop grand
+ 271 - 0
logo.svg


+ 52 - 66
myocamlbuild.ml

@@ -1,7 +1,7 @@
 (* OASIS_START *)
 (* OASIS_START *)
-(* DO NOT EDIT (digest: 2b686a81cec9fb16d1640bda36a68fbd) *)
+(* DO NOT EDIT (digest: 4f240f06ff7a70bb4e3be1240a180aab) *)
 module OASISGettext = struct
 module OASISGettext = struct
-(* # 22 "src/oasis/OASISGettext.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISGettext.ml" *)
 
 
 
 
   let ns_ str =
   let ns_ str =
@@ -30,7 +30,7 @@ module OASISGettext = struct
 end
 end
 
 
 module OASISExpr = struct
 module OASISExpr = struct
-(* # 22 "src/oasis/OASISExpr.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISExpr.ml" *)
 
 
 
 
 
 
@@ -39,10 +39,10 @@ module OASISExpr = struct
   open OASISGettext
   open OASISGettext
 
 
 
 
-  type test = string
+  type test = string 
 
 
 
 
-  type flag = string
+  type flag = string 
 
 
 
 
   type t =
   type t =
@@ -52,10 +52,10 @@ module OASISExpr = struct
     | EOr of t * t
     | EOr of t * t
     | EFlag of flag
     | EFlag of flag
     | ETest of test * string
     | ETest of test * string
+    
 
 
 
 
-
-  type 'a choices = (t * 'a) list
+  type 'a choices = (t * 'a) list 
 
 
 
 
   let eval var_get t =
   let eval var_get t =
@@ -131,7 +131,7 @@ end
 
 
 # 132 "myocamlbuild.ml"
 # 132 "myocamlbuild.ml"
 module BaseEnvLight = struct
 module BaseEnvLight = struct
-(* # 22 "src/base/BaseEnvLight.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseEnvLight.ml" *)
 
 
 
 
   module MapString = Map.Make(String)
   module MapString = Map.Make(String)
@@ -236,7 +236,7 @@ end
 
 
 # 237 "myocamlbuild.ml"
 # 237 "myocamlbuild.ml"
 module MyOCamlbuildFindlib = struct
 module MyOCamlbuildFindlib = struct
-(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
 
 
 
 
   (** OCamlbuild extension, copied from
   (** OCamlbuild extension, copied from
@@ -249,9 +249,6 @@ module MyOCamlbuildFindlib = struct
     *)
     *)
   open Ocamlbuild_plugin
   open Ocamlbuild_plugin
 
 
-  type conf =
-    { no_automatic_syntax: bool;
-    }
 
 
   (* these functions are not really officially exported *)
   (* these functions are not really officially exported *)
   let run_and_read =
   let run_and_read =
@@ -318,7 +315,7 @@ module MyOCamlbuildFindlib = struct
 
 
   (* This lists all supported packages. *)
   (* This lists all supported packages. *)
   let find_packages () =
   let find_packages () =
-    List.map before_space (split_nl & run_and_read (exec_from_conf "ocamlfind" ^ " list"))
+    List.map before_space (split_nl & run_and_read "ocamlfind list")
 
 
 
 
   (* Mock to list available syntaxes. *)
   (* Mock to list available syntaxes. *)
@@ -341,7 +338,7 @@ module MyOCamlbuildFindlib = struct
   ]
   ]
 
 
 
 
-  let dispatch conf =
+  let dispatch =
     function
     function
       | After_options ->
       | After_options ->
           (* By using Before_options one let command line options have an higher
           (* By using Before_options one let command line options have an higher
@@ -360,39 +357,31 @@ module MyOCamlbuildFindlib = struct
            * -linkpkg *)
            * -linkpkg *)
           flag ["ocaml"; "link"; "program"] & A"-linkpkg";
           flag ["ocaml"; "link"; "program"] & A"-linkpkg";
 
 
-          if not (conf.no_automatic_syntax) then begin
-            (* For each ocamlfind package one inject the -package option when
-             * compiling, computing dependencies, generating documentation and
-             * linking. *)
-            List.iter
-              begin fun pkg ->
-                let base_args = [A"-package"; A pkg] in
-                (* TODO: consider how to really choose camlp4o or camlp4r. *)
-                let syn_args = [A"-syntax"; A "camlp4o"] in
-                let (args, pargs) =
-                  (* Heuristic to identify syntax extensions: whether they end in
-                     ".syntax"; some might not.
-                  *)
-                  if Filename.check_suffix pkg "syntax" ||
-                     List.mem pkg well_known_syntax then
-                    (syn_args @ base_args, syn_args)
-                  else
-                    (base_args, [])
-                in
-                flag ["ocaml"; "compile";  "pkg_"^pkg] & S args;
-                flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
-                flag ["ocaml"; "doc";      "pkg_"^pkg] & S args;
-                flag ["ocaml"; "link";     "pkg_"^pkg] & S base_args;
-                flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
-
-                (* TODO: Check if this is allowed for OCaml < 3.12.1 *)
-                flag ["ocaml"; "compile";  "package("^pkg^")"] & S pargs;
-                flag ["ocaml"; "ocamldep"; "package("^pkg^")"] & S pargs;
-                flag ["ocaml"; "doc";      "package("^pkg^")"] & S pargs;
-                flag ["ocaml"; "infer_interface"; "package("^pkg^")"] & S pargs;
-              end
-              (find_packages ());
-          end;
+          (* For each ocamlfind package one inject the -package option when
+           * compiling, computing dependencies, generating documentation and
+           * linking. *)
+          List.iter
+            begin fun pkg ->
+              let base_args = [A"-package"; A pkg] in
+              (* TODO: consider how to really choose camlp4o or camlp4r. *)
+              let syn_args = [A"-syntax"; A "camlp4o"] in
+              let args =
+              (* Heuristic to identify syntax extensions: whether they end in
+                 ".syntax"; some might not.
+               *)
+                if Filename.check_suffix pkg "syntax" ||
+                   List.mem pkg well_known_syntax then
+                  syn_args @ base_args
+                else
+                  base_args
+              in
+              flag ["ocaml"; "compile";  "pkg_"^pkg] & S args;
+              flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
+              flag ["ocaml"; "doc";      "pkg_"^pkg] & S args;
+              flag ["ocaml"; "link";     "pkg_"^pkg] & S base_args;
+              flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
+            end
+            (find_packages ());
 
 
           (* Like -package but for extensions syntax. Morover -syntax is useless
           (* Like -package but for extensions syntax. Morover -syntax is useless
            * when linking. *)
            * when linking. *)
@@ -426,7 +415,7 @@ module MyOCamlbuildFindlib = struct
 end
 end
 
 
 module MyOCamlbuildBase = struct
 module MyOCamlbuildBase = struct
-(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
 
 
 
 
   (** Base functions for writing myocamlbuild.ml
   (** Base functions for writing myocamlbuild.ml
@@ -441,13 +430,13 @@ module MyOCamlbuildBase = struct
   module OC = Ocamlbuild_pack.Ocaml_compiler
   module OC = Ocamlbuild_pack.Ocaml_compiler
 
 
 
 
-  type dir = string
-  type file = string
-  type name = string
-  type tag = string
+  type dir = string 
+  type file = string 
+  type name = string 
+  type tag = string 
 
 
 
 
-(* # 62 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
+(* # 62 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
 
 
 
 
   type t =
   type t =
@@ -459,7 +448,7 @@ module MyOCamlbuildBase = struct
          * directory.
          * directory.
          *)
          *)
         includes:  (dir * dir list) list;
         includes:  (dir * dir list) list;
-      }
+      } 
 
 
 
 
   let env_filename =
   let env_filename =
@@ -557,13 +546,12 @@ module MyOCamlbuildBase = struct
 
 
                    (* When ocaml link something that use the C library, then one
                    (* When ocaml link something that use the C library, then one
                       need that file to be up to date.
                       need that file to be up to date.
-                      This holds both for programs and for libraries.
                     *)
                     *)
-  		 dep ["link"; "ocaml"; tag_libstubs lib]
-  		     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
+                   dep ["link"; "ocaml"; "program"; tag_libstubs lib]
+                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
 
 
-  		 dep  ["compile"; "ocaml"; tag_libstubs lib]
-  		      [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
+                   dep  ["compile"; "ocaml"; "program"; tag_libstubs lib]
+                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
 
 
                    (* TODO: be more specific about what depends on headers *)
                    (* TODO: be more specific about what depends on headers *)
                    (* Depends on .h files *)
                    (* Depends on .h files *)
@@ -592,27 +580,25 @@ module MyOCamlbuildBase = struct
             ()
             ()
 
 
 
 
-  let dispatch_default conf t =
+  let dispatch_default t =
     dispatch_combine
     dispatch_combine
       [
       [
         dispatch t;
         dispatch t;
-        MyOCamlbuildFindlib.dispatch conf;
+        MyOCamlbuildFindlib.dispatch;
       ]
       ]
 
 
 
 
 end
 end
 
 
 
 
-# 606 "myocamlbuild.ml"
+# 594 "myocamlbuild.ml"
 open Ocamlbuild_plugin;;
 open Ocamlbuild_plugin;;
 let package_default =
 let package_default =
   {MyOCamlbuildBase.lib_ocaml = []; lib_c = []; flags = []; includes = []}
   {MyOCamlbuildBase.lib_ocaml = []; lib_c = []; flags = []; includes = []}
   ;;
   ;;
 
 
-let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false}
-
-let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;;
+let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
 
 
-# 617 "myocamlbuild.ml"
+# 603 "myocamlbuild.ml"
 (* OASIS_STOP *)
 (* OASIS_STOP *)
 Ocamlbuild_plugin.dispatch dispatch_default;;
 Ocamlbuild_plugin.dispatch dispatch_default;;

Fichier diff supprimé car celui-ci est trop grand
+ 178 - 215
setup.ml


+ 68 - 0
src/add_command.ml

@@ -0,0 +1,68 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* Module to add command without editing the rc file directly *)
+
+(* Function to create a new list augmented by some commands *)
+let new_list current_list position new_items =
+    match position with
+    | None -> List.append current_list new_items
+    | Some n -> (* If a number is given, add commands after position n by
+    splitting the list and concatenating all. List.split_n works like this :
+        * #let l1 = [1;2;3;4;5;6] in
+        * # List.split_n l1 2;;
+        * - : int list * int list = ([1; 2], [3; 4; 5; 6]) *)
+    let l_begin,l_end = List.split_n current_list n in
+    List.concat [ l_begin ; new_items ; l_end ]
+;;
+
+
+
+(* Function which add the commands (one per line) ridden on stdin to the rc
+ * file, and then display th new configuration *)
+let run ~(rc:File_com.t) position =
+    (* Read command from stdin, as a list. fix_win_eol removes \r\n *)
+    let cmd_list = In_channel.input_lines ~fix_win_eol:true In_channel.stdin in
+    (* Create an updated rc file *)
+    let updated_rc = { rc with Settings_t.progs = (new_list rc.Settings_t.progs position cmd_list)} in
+    File_com.write updated_rc;
+    (* Display the result *)
+    let reread_rc = File_com.init_rc () in
+    List_rc.run ~rc:reread_rc
+;;
+

+ 108 - 0
src/command_def.ml

@@ -0,0 +1,108 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* Module containing the definition of the interface of OcLaunch *)
+
+(* Arguments *)
+let args =
+    let open Command.Spec in
+    (empty
+    (* Flag to use different rc file *)
+    +> flag "-c" (optional_with_default !Const.rc_file file)
+    ~aliases:["--rc" ; "-rc"]
+    ~doc:"file Read configuration from the given file and continue parsing."
+    (* Flag to reset tmp file *)
+    +> flag "-r" no_arg
+        ~aliases:["-reset-tmp" ; "--reset-tmp"]
+        ~doc:"[n] Reinitialises launches by setting a new number in temporal file.
+        If nothing is given, reinitialises to 0 and delete tmp file."
+    (* Flag to list each commands with its number *)
+    +> flag "-l" no_arg
+    ~aliases:["-list" ; "--list"]
+    ~doc:" Print a list of all commands with their number. Useful to launch with number. Displays a star next to next command to launch."
+    (* Flag to add a command to rc file, from stdin or directly *)
+    +> flag "-a" no_arg
+    ~aliases:["-add" ; "--add"]
+    ~doc:"[n] Add the command given on stdin to the configuration file at a given position. If nothing is given, append it."
+    (* Flag to remove a command from rc file *)
+    +> flag "-d" no_arg
+    ~aliases:["-delete" ; "--delete"]
+    ~doc:"[n] remove the nth command from configuration file. If n is absent, remove last one"
+    (* Flag to display current number *)
+    +> flag "-n" no_arg
+    ~aliases:["-number" ; "--number"]
+    ~doc:" Display current state of the program"
+    (* Flag to edit the nth command *)
+    +> flag "-m" no_arg
+    ~aliases:["-modify" ; "--modify"]
+    ~doc:"[n] Edit the nth command of the rc file. [Not working properly]"
+
+    +> anon (maybe ("Command number" %: int)))
+;;
+
+(* Define commands *)
+let commands =
+  Command.basic
+    ~summary:"OcLaunch program is published under CeCILL licence. See
+    https://gitlab.com/WzukW/oclaunch for details."
+    ~readme:(fun () -> "See https://gitlab.com/WzukW/oclaunch for help.")
+    args
+
+    (fun rc_file_name reset_tmp list_commands add delete number modify num_cmd () ->
+       (* Use given rc file, should run the nth argument if present *)
+       Const.rc_file := rc_file_name;
+       (* Obtain data from rc_file *)
+       let rc_content = File_com.init_rc () in
+       (* A default number, corresponding to first item *)
+       let default_n = (Option.value ~default:0 num_cmd) in
+       (* First try to list *)
+       if list_commands then List_rc.run ~rc:rc_content
+       (* To add command to rc file *)
+       else if add then Add_command.run ~rc:rc_content num_cmd
+       (* To delete command from rc file *)
+       else if delete then Remove_command.run ~rc:rc_content num_cmd
+       (* To print current state *)
+       else if number then State.print_current ()
+       (* Reset to a value *)
+       else if reset_tmp then Tmp_file.reset default_n
+       (* Edit the nth command *)
+       else if modify then Edit_command.run ~rc:rc_content default_n
+       (* Else: Run the nth command *)
+       else Default.run ~rc:rc_content num_cmd
+    )
+;;

+ 14 - 10
src/const.ml

@@ -1,5 +1,5 @@
 (******************************************************************************)
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2015                                        *)
 (*                                                                            *)
 (*                                                                            *)
 (*  leowzukw@vmail.me                                                         *)
 (*  leowzukw@vmail.me                                                         *)
 (*                                                                            *)
 (*                                                                            *)
@@ -41,14 +41,18 @@ open Core.Std;;
 (* Get current home *)
 (* Get current home *)
 let home = match (Sys.getenv "HOME") with
 let home = match (Sys.getenv "HOME") with
   | Some x -> x
   | Some x -> x
-  | None -> failwith "Wrong value for home"
+  | None -> failwith "Wrong value for home\n"
 ;;
 ;;
 
 
-(* Some settings variales *)
-let rc_file = home ^ "/" ^ ".oclaunch_rc.json";;
-(* Set tmp file, in witch stock launches *)
-let tmp_file = "/tmp/oclaunch_trace.json";; (* File where launch are logged *)
-(* Template for the tmp file *)
-let (tmp_file_template:Yojson.Basic.json) = `Assoc
-                                              [ "cmd", `List [];
-                                              "num", `Int 0 ];;
+(* Get default editor *)
+let editor = match (Sys.getenv "EDITOR") with
+  | Some x -> x
+  | None -> failwith "Wrong value for $EDITOR\n"
+;;
+
+(* Default place to read settings *)
+let rc_file_default = home ^ "/" ^ ".oclaunch_rc.json";;
+(* Current place to read settings, maybe modified from command line argument *)
+let rc_file = ref rc_file_default;;
+(* Set tmp file, in witch stock launches, in biniou format *)
+let tmp_file = "/tmp/.oclaunch_trace.dat";; (* File where launch are logged *)

+ 6 - 8
src/default.ml

@@ -1,5 +1,5 @@
 (******************************************************************************)
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2015                                        *)
 (*                                                                            *)
 (*                                                                            *)
 (*  leowzukw@vmail.me                                                         *)
 (*  leowzukw@vmail.me                                                         *)
 (*                                                                            *)
 (*                                                                            *)
@@ -41,18 +41,16 @@ open Core.Std;;
 
 
 (* cmd_number is the number of the command the user wants
 (* cmd_number is the number of the command the user wants
  * to execute *)
  * to execute *)
-let run ~rc:rc_content ~tmp:tmp_content cmd_number =
+let run ~rc:rc_content cmd_number =
   match cmd_number with
   match cmd_number with
     | None -> begin
     | None -> begin
         (* Execute each item (one by one) in config file *)
         (* Execute each item (one by one) in config file *)
-        let open Settings_t in (* This prevent warning 40 for ~cmd_list:rc_content.progs *)
-          let cmd_to_exec = Exec_cmd.what_next ~cmd_list:rc_content.progs ~tmp:tmp_content in
+          let cmd_to_exec = Exec_cmd.what_next ~cmd_list:rc_content.Settings_t.progs in
             (* TODO Use display option in rc file *)
             (* TODO Use display option in rc file *)
-            Exec_cmd.execute ~tmp:tmp_content cmd_to_exec;
-            () (* Return nothing, because launched from oclaunch.ml *)
+            Exec_cmd.execute cmd_to_exec;
       end
       end
     | Some num -> begin
     | Some num -> begin
-        let cmd_to_exec = Exec_cmd.num_cmd_to_cmd ~cmd_list:rc_content.progs num in
-          Exec_cmd.execute ~tmp:tmp_content cmd_to_exec;
+        let cmd_to_exec = Exec_cmd.num_cmd_to_cmd ~cmd_list:rc_content.Settings_t.progs num in
+          Exec_cmd.execute cmd_to_exec;
       end
       end
 ;;
 ;;

+ 95 - 0
src/edit_command.ml

@@ -0,0 +1,95 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* Module to edit command without editing the rc file directly *)
+
+(* Function to create a new list augmented by some commands *)
+(* TODO Factorise this *)
+let new_list current_list position new_items =
+    (* If a number is given, add commands after position n by
+    splitting the list and concatenating all. List.split_n works like this :
+        * #let l1 = [1;2;3;4;5;6] in
+        * # List.split_n l1 2;;
+        * - : int list * int list = ([1; 2], [3; 4; 5; 6]) *)
+    let l_begin,l_end = List.split_n current_list position in
+    List.concat [ l_begin ; new_items ; l_end ]
+;;
+
+
+
+(* Function which get the nth element, put it in afile, let the user edit it,
+ * and then remplace with the new result *)
+let run ~(rc:File_com.t) position =
+    (* Current list of commands *)
+    let current_list = rc.Settings_t.progs in
+
+    (* Creating tmp file *)
+    let tmp_filename = [
+        "/tmp/oc_edit_" ;
+        (Int.to_string (Random.int 10000)) ;
+        ".txt" ;
+    ] in
+    let tmp_edit = String.concat tmp_filename in
+    (* Remove item to be edited *)
+    let original_command,shorter_list = Remove_command.remove current_list
+    position in
+    Out_channel.write_all tmp_edit original_command;
+
+
+    (* Edit file *)
+    let edit = String.concat [ Const.editor ; " " ; tmp_edit ] in
+    Sys.command edit
+    |> (function
+        0 -> ()
+        | n -> printf "Error while running %s: error code %i" edit n);
+
+    (* Reading and applying the result *)
+    let new_commands = In_channel.read_lines tmp_edit in
+    let cmd_list = new_list shorter_list position new_commands in
+    let updated_rc = { rc with Settings_t.progs = cmd_list} in
+    File_com.write updated_rc;
+    (* Display the result *)
+    printf "'%s' -> '%s'\n\n" original_command
+        (List.fold
+            ~f:(fun accum item -> String.concat [ accum ; item ; "\n" ])
+            ~init:""
+            new_commands);
+    let reread_rc = File_com.init_rc () in
+    (* Display new rc file *)
+    List_rc.run ~rc:reread_rc
+;;

+ 25 - 33
src/exec_cmd.ml

@@ -1,5 +1,5 @@
 (******************************************************************************)
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2015                                        *)
 (*                                                                            *)
 (*                                                                            *)
 (*  leowzukw@vmail.me                                                         *)
 (*  leowzukw@vmail.me                                                         *)
 (*                                                                            *)
 (*                                                                            *)
@@ -36,41 +36,33 @@
 
 
 open Core.Std;;
 open Core.Std;;
 
 
+(* Function allowing to set the title of the current terminal windows
+ * XXX Maybe better in some lib *)
+(* TODO Allow to set it in configuration file *)
+let set_title new_title =
+    (* Use echo command *)
+    Sys.command (sprintf "echo -en \"\\033]0;%s\\a\"" new_title)
+    |> function | 0 -> () | _ -> printf "Error while setting terminal title"
+;;
+
 (* Function to return the corresponding command to a number *)
 (* Function to return the corresponding command to a number *)
 let num_cmd_to_cmd ~cmd_list number =
 let num_cmd_to_cmd ~cmd_list number =
-  (* Verify that the number is not out of the list *)
-  if (List.length cmd_list) <= number
-  then
-      begin
-          (* TODO Make this printing configurable *)
-          printf "Out of range. Do not do anything.";
-          ""
-      end
-  else
-    begin
-      let cmd_to_exec = List.nth cmd_list number in
-        match cmd_to_exec with
-            | None -> ""
-            | Some x -> x
-    end
+  (* List.nth return None if out of the list *)
+  List.nth cmd_list number
+  |> function
+      (* If in range of the list, return the corresponding command else return
+       * an empty string after displaying error. *)
+      | Some x -> set_title x; x
+      (* TODO Make this printing configurable *)
+      | None -> printf "All has been launched!\n\
+      You can reset with '-r'\n"; ""
 ;;
 ;;
 
 
 (* Function to determinate what is the next command to
 (* Function to determinate what is the next command to
- * execute *)
-let what_next ~tmp ~cmd_list =
-  let tmp_json = Yojson.Basic.from_file tmp in
-  let open Yojson.Basic.Util in
-  let num_next = tmp_json |> member "num" |> to_int in (* Number of the next cmd to run *)
-    num_cmd_to_cmd ~cmd_list:cmd_list num_next
-  ;;
-
-(* Log when a program has been launched in a file in /tmp
-   ~func is the function applied to the value *)
-let log ?(func= (+) 1 ) ~file_name =
-  let file = Yojson.Basic.from_file file_name in
-  match file with
-    | `Assoc [( a, `List b ); ("num", `Int c)] -> let new_value = `Assoc [( a, `List b ); ("num", `Int (c |> func))] in Yojson.Basic.to_file file_name new_value
-    | _ -> failwith "Incorrect format"
+ * execute. It take the current number from tmp file. *)
+let what_next ~cmd_list =
+  let tmp_file = Tmp_file.init () in
+  num_cmd_to_cmd ~cmd_list:cmd_list tmp_file.Tmp_biniou_t.number
 ;;
 ;;
 
 
 (* Display an error message if command can't run
 (* Display an error message if command can't run
@@ -85,8 +77,8 @@ let display_result command status =
 ;;
 ;;
 
 
 (* Execute some command and log it *)
 (* Execute some command and log it *)
-let execute ?(display=true) ~tmp cmd =
-    log ~func:((+) 1) ~file_name:tmp;
+let execute ?(display=true) cmd =
+    Tmp_file.log ~func:((+) 1) ();
     if display then
     if display then
         print_endline cmd;
         print_endline cmd;
     Sys.command cmd
     Sys.command cmd

+ 24 - 6
src/file_com.ml

@@ -1,5 +1,5 @@
 (******************************************************************************)
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2015                                        *)
 (*                                                                            *)
 (*                                                                            *)
 (*  leowzukw@vmail.me                                                         *)
 (*  leowzukw@vmail.me                                                         *)
 (*                                                                            *)
 (*                                                                            *)
@@ -38,13 +38,26 @@ open Core.Std;;
 
 
 (* Read settings and programs to launch from rc file *)
 (* Read settings and programs to launch from rc file *)
 
 
+(* Type of the values *)
+type t = Settings_v.rc_file;;
+
+(* Function to write the rc file *)
+let write (tmp_file:t) =
+        (* Short name *)
+        let name = !Const.rc_file in
+        (* Create string to be written *)
+        let data = (Settings_j.string_of_rc_file tmp_file
+        |> Yojson.Basic.prettify ~std:true) in
+        Out_channel.write_all name ~data
+;;
+
 (* Return the configuration file template *)
 (* Return the configuration file template *)
 let rc_template () =
 let rc_template () =
   Settings_v.create_rc_file ~progs:[] ~settings:[]
   Settings_v.create_rc_file ~progs:[] ~settings:[]
 ;;
 ;;
 
 
 (* Function to create configuration file if it does not
 (* Function to create configuration file if it does not
- * exists *)
+ * exist *)
 let create_rc_file ~name =
 let create_rc_file ~name =
   (* Notify that we initialise config file *)
   (* Notify that we initialise config file *)
   printf "Initializing configuration file in %s\n" name;
   printf "Initializing configuration file in %s\n" name;
@@ -56,10 +69,15 @@ let create_rc_file ~name =
 ;;
 ;;
 
 
 (* Function to read the rc file *)
 (* Function to read the rc file *)
-let rec init_rc ~rc:rc_file =
+let rec init_rc ?(rc=(!Const.rc_file)) () =
   (* Verify that file exist *)
   (* Verify that file exist *)
-  match (Sys.file_exists rc_file) with
-    | `No -> create_rc_file ~name:rc_file; init_rc ~rc:rc_file;
+  match (Sys.file_exists rc) with
+    | `No -> create_rc_file ~name:rc; init_rc ~rc ();
     | `Unknown -> failwith "Error reading configuration file";
     | `Unknown -> failwith "Error reading configuration file";
-    | `Yes -> In_channel.read_all rc_file |> Settings_j.rc_file_of_string
+    | `Yes -> (* Try to read, if there is an error, reset file *)
+            try
+                In_channel.read_all rc |> Settings_j.rc_file_of_string
+            with
+            | Yojson.Json_error _ -> (* Invalid file, delete, so that it will be reseted
+            on next call *) Sys.remove rc; init_rc ~rc ()
 ;;
 ;;

+ 52 - 0
src/list_rc.ml

@@ -0,0 +1,52 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* This modules contains function to list the content of the rc file *)
+
+(* Display the command with its number, with a '*' if it is the current one *)
+let disp_cmd_num current_number number command =
+    (* If number is the global current one print a '*' *)
+    let prepend = (if current_number = number then "* " else "  ") in
+    printf "%s%i: %s\n" prepend number command
+;;
+
+(* Function which list *)
+let run ~(rc:File_com.t) =
+    List.iteri rc.Settings_t.progs ~f:(fun i item ->
+        disp_cmd_num (State.get_current ()) i item)
+;;

+ 3 - 28
src/oclaunch.ml

@@ -1,5 +1,5 @@
 (******************************************************************************)
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2015                                        *)
 (*                                                                            *)
 (*                                                                            *)
 (*  leowzukw@vmail.me                                                         *)
 (*  leowzukw@vmail.me                                                         *)
 (*                                                                            *)
 (*                                                                            *)
@@ -38,38 +38,13 @@ open Core.Std;;
 
 
 (* Variable to store version number *)
 (* Variable to store version number *)
 (* TODO Get value from file *)
 (* TODO Get value from file *)
-let version_number = "0.1.3";;
+let version_number = "0.2.1-rc1";;
 
 
 (* Variable store building information *)
 (* Variable store building information *)
 (* XXX This is fake value, it corresponds to the running
 (* XXX This is fake value, it corresponds to the running
  * information *)
  * information *)
 let build_info = ( "Build with OCaml version " ^ (Sys.ocaml_version) ^ " on " ^ (Sys.os_type) );;
 let build_info = ( "Build with OCaml version " ^ (Sys.ocaml_version) ^ " on " ^ (Sys.os_type) );;
 
 
-(* Obtain data from rc file *)
-let rc_content = File_com.init_rc ~rc:Const.rc_file;;
-
-(* Obtain data from tmp file *)
-let tmp_content = Tmp_file.init ~tmp:Const.tmp_file;;
-
-
-(* Define commands *)
-let commands =
-  Command.basic
-    ~summary:"OcLaunch program is published under CeCILL licence. See
-    https://gitlab.com/WzukW/oclaunch for details."
-    ~readme:(fun () -> "See https://gitlab.com/WzukW/oclaunch for help.")
-    (* TODO if number is out of the mist, return error message *)
-    Command.Spec.(empty
-    +> flag ~aliases:["-reset-tmp" ; "--reset-tmp"] "-r" no_arg
-                    ~doc:" Reinitialises launches by deleting temporal file."
-    +> anon (maybe ("Command number" %: int)))
-    (fun reset_tmp num_cmd () ->
-       match reset_tmp with
-         | true -> Tmp_file.reset ~tmp:tmp_content
-         | false -> Default.run ~rc:rc_content ~tmp:tmp_content num_cmd
-    )
-;;
-
 let () =
 let () =
-  Command.run ~version:version_number ~build_info:build_info commands
+  Command.run ~version:version_number ~build_info:build_info Command_def.commands
 ;;
 ;;

+ 78 - 0
src/remove_command.ml

@@ -0,0 +1,78 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* Module to remove commands without editing the rc file directly *)
+
+(* Function remove nth command in the rc_file, returning the removed one and the
+ * new list *)
+let remove current_list n =
+    let removed = ref "" in
+    (* The list without the nth item *)
+    let new_list = List.filteri current_list ~f:(fun i _ ->
+        if i <> n then
+            (* If it is not nth, return true *)
+            true
+        else
+            begin
+                (* If it is nth, ie the command to be removed, store it and return
+                 * false, to remove the corresponding item *)
+                removed := List.nth_exn current_list i;
+                false
+            end
+    ) in
+    ( !removed, new_list )
+;;
+
+(* Function which add the commands (one per line) ridden on stdin to the rc
+ * file, and then display th new configuration *)
+let run ~(rc:File_com.t) n_to_remove =
+    (* Get actual list of commands *)
+    let actual_list = rc.Settings_t.progs in
+    (* Get nth *)
+    let nth = Option.value n_to_remove
+        ~default:((List.length actual_list) - 1) in
+    (* Remove the nth command, after display it *)
+    let removed,new_list = remove actual_list nth in
+    printf "Removing: %s\n\n" removed;
+    (* Write new list to rc file *)
+    let updated_rc = { rc with Settings_t.progs = new_list } in
+    File_com.write updated_rc;
+    (* Display the result *)
+    let reread_rc = File_com.init_rc () in
+    List_rc.run ~rc:reread_rc
+;;

+ 1 - 1
src/settings.atd

@@ -1,5 +1,5 @@
 (******************************************************************************)
 (******************************************************************************)
-(* Copyright © Joly Clément, 2014                                             *)
+(* Copyright © Joly Clément, 2014-2015                                        *)
 (*                                                                            *)
 (*                                                                            *)
 (*  leowzukw@vmail.me                                                         *)
 (*  leowzukw@vmail.me                                                         *)
 (*                                                                            *)
 (*                                                                            *)

+ 53 - 0
src/state.ml

@@ -0,0 +1,53 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014-2015                                        *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+open Core.Std;;
+
+(* Module to display the current state of the program *)
+
+(* Return current number *)
+let get_current () =
+    (* Read tmp file *)
+    let tmp_file = Tmp_file.init () in
+    (* Return the number *)
+    tmp_file.Tmp_biniou_t.number;
+;;
+
+(* Display current number *)
+let print_current () =
+    (* Display the number *)
+    printf "Current state: %i\n" (get_current ())
+;;

+ 45 - 0
src/tmp_biniou.atd

@@ -0,0 +1,45 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014                                             *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+(* Tmp file is where launch are logged in.
+ * This atd file allow to use biniou easier in tmp file. The purpuse is to save
+ * place, get faster parsing and make harder manual, unwanted modification. A special command line is
+ * available to change current number *)
+
+type tmp_file = {
+    command: string list; (* A list of command, for future use *)
+    number: int; (* The current number/state of the launches *)
+}

+ 63 - 12
src/tmp_file.ml

@@ -36,23 +36,56 @@
 
 
 open Core.Std;;
 open Core.Std;;
 
 
+(* Type of the values *)
+type t = Tmp_biniou_t.tmp_file;;
+
+(* Function to write the tmp file *)
+let write (tmp_file:t) =
+    (* Short name *)
+    let name = Const.tmp_file in
+    let biniou_tmp = Tmp_biniou_b.string_of_tmp_file tmp_file in
+    Out_channel.write_all name ~data:biniou_tmp
+;;
+
+(* XXX Using and keyword because each function can call each other *)
+(* Function to read the tmp file *)
+let rec read () =
+    (* Short name *)
+    let name = Const.tmp_file in
+    (* Get the string corresponding to the file *)
+    let file_content = In_channel.read_all name in
+    try
+        Tmp_biniou_b.tmp_file_of_string file_content
+    (* In previous version, the JSON format was used, otherwise the file can
+     * have a bad format. In this case, the Ag_ob_run.Error("Read error (1)")
+     * exeption is throw. We catch it here *)
+    with _ ->
+        (* If file is not in the right format, delete it and create a new one.
+         * Then, read it *)
+        printf "Reinitialises tmp file\n"; (* TODO Make it settable *)
+        Sys.remove name;
+        create_tmp_file ();
+        read ()
+
 (* Function to create the tmp file *)
 (* Function to create the tmp file *)
-let create_tmp_file ~name =
-  Yojson.Basic.pretty_to_channel (Out_channel.create name) Const.tmp_file_template
+and create_tmp_file () =
+    Tmp_biniou_v.create_tmp_file ~command:[] ~number:0 ()
+    (* Convert it to biniou *)
+    |> write
 ;;
 ;;
 
 
 (* Function to open tmp file *)
 (* Function to open tmp file *)
-let rec init ~tmp =
+let rec init () =
   (* If file do not exists, create it *)
   (* If file do not exists, create it *)
-  let file_exists = (Sys.file_exists tmp) in
+  let file_exists = Sys.file_exists Const.tmp_file in
     match file_exists with
     match file_exists with
-      | `No -> create_tmp_file ~name:tmp;
-          init ~tmp:tmp
+      | `No -> create_tmp_file ();
+          init ()
       | `Unknown -> begin
       | `Unknown -> begin
-          Core_extended.Shell.rm tmp;
-          init ~tmp:tmp
+          Sys.remove Const.tmp_file;
+          init ()
         end
         end
-      | `Yes -> tmp
+      | `Yes -> read ()
 ;;
 ;;
 
 
 (* Verify that the value exist *)
 (* Verify that the value exist *)
@@ -71,7 +104,25 @@ let rec is_prog_in_rc list_from_rc_file program =
     | hd :: tl -> if hd = program then true else is_prog_in_rc tl program
     | hd :: tl -> if hd = program then true else is_prog_in_rc tl program
 ;;
 ;;
 
 
-(* Delete tmp file, to reinitialise program *)
-let reset ~tmp =
-  Sys.remove tmp
+(* Log when a program has been launched in a file in /tmp
+   ~func is the function applied to the value *)
+let log ?(func= (+) 1 ) () =
+  (* Make sure that file exists, otherwise strange things appears *)
+  let file = init () in
+  (* Write the file with the new value *)
+  write { file with Tmp_biniou_t.number = (func file.Tmp_biniou_t.number)}
+;;
+
+(* Reset command number in two ways :
+    * if cmd_num is 0, delete tmp file, to reinitialise program
+    * if cmd_num is 0>, set to this value
+    * else display an error message *)
+let reset cmd_num =
+    match cmd_num with
+    | 0 -> Sys.remove Const.tmp_file; printf "Tmp file removed\n"
+    | n when n > 0 ->
+            (* Set the number *)
+            log ~func:((fun a b -> a) n) ();
+            printf "Tmp file reseted to %i\n" n
+    | _ -> printf "Invalid number\n" (* TODO Make it settable *)
 ;;
 ;;

+ 46 - 0
src/tmp_file.mli

@@ -0,0 +1,46 @@
+(******************************************************************************)
+(* Copyright © Joly Clément, 2014                                             *)
+(*                                                                            *)
+(*  leowzukw@vmail.me                                                         *)
+(*                                                                            *)
+(*  Ce logiciel est un programme informatique servant à exécuter              *)
+(*  automatiquement des programmes à l'ouverture du terminal.                 *)
+(*                                                                            *)
+(*  Ce logiciel est régi par la licence CeCILL soumise au droit français et   *)
+(*  respectant les principes de diffusion des logiciels libres. Vous pouvez   *)
+(*  utiliser, modifier et/ou redistribuer ce programme sous les conditions    *)
+(*  de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA    *)
+(*  sur le site "http://www.cecill.info".                                     *)
+(*                                                                            *)
+(*  En contrepartie de l'accessibilité au code source et des droits de copie, *)
+(*  de modification et de redistribution accordés par cette licence, il n'est *)
+(*  offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons, *)
+(*  seule une responsabilité restreinte pèse sur l'auteur du programme,  le   *)
+(*  titulaire des droits patrimoniaux et les concédants successifs.           *)
+(*                                                                            *)
+(*  A cet égard  l'attention de l'utilisateur est attirée sur les risques     *)
+(*  associés au chargement,  à l'utilisation,  à la modification et/ou au     *)
+(*  développement et à la reproduction du logiciel par l'utilisateur étant    *)
+(*  donné sa spécificité de logiciel libre, qui peut le rendre complexe à     *)
+(*  manipuler et qui le réserve donc à des développeurs et des professionnels *)
+(*  avertis possédant  des  connaissances  informatiques approfondies.  Les   *)
+(*  utilisateurs sont donc invités à charger  et  tester  l'adéquation  du    *)
+(*  logiciel à leurs besoins dans des conditions permettant d'assurer la      *)
+(*  sécurité de leurs systèmes et ou de leurs données et, plus généralement,  *)
+(*  à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.        *)
+(*                                                                            *)
+(*  Le fait que vous puissiez accéder à cet en-tête signifie que vous avez    *)
+(*  pris connaissance de la licence CeCILL, et que vous en avez accepté les   *)
+(*  termes.                                                                   *)
+(******************************************************************************)
+
+type t = Tmp_biniou_t.tmp_file
+val write : t -> unit
+
+(* Use this function to read tmp file, it will be created if necessary *)
+val init : unit -> t
+
+val verify_key_exist : key:'a -> 'a -> bool
+val is_prog_in_rc : 'a list -> 'a -> bool
+val log : ?func:(int -> int) -> unit -> unit
+val reset : int -> unit

+ 23 - 0
version_set.sh

@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# A script to set version number to $1
+# Example: ./version_set.sh 0.1
+
+# Current version number
+current_version=$(cat ./VERSION)
+
+# New, wanted one
+new_version=$1
+
+
+# Print what will be done
+echo "Put" $new_version "instead of" $new_version
+
+# Replace in the three files : VERSION, _oasis, src/oclaunch.ml
+echo $new_version > VERSION
+sed -i -e "s/Version:     .*/Version:     $new_version/" _oasis
+sed -i -e "s/\\(let version_number = \"\\).*\\(\";;\\)/\\1$new_version\\2/" src/oclaunch.ml
+
+# Display the result
+echo "Result"
+git diff