|
@@ -0,0 +1,179 @@
|
|
|
+(******************************************************************************)
|
|
|
+(* Copyright © Joly Clément, 2016 *)
|
|
|
+(* *)
|
|
|
+(* leowzukw@oclaunch.eu.org *)
|
|
|
+(* *)
|
|
|
+(* 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;;
|
|
|
+
|
|
|
+(* Rc files means configuration file. It consist in a list of **entries**, with
|
|
|
+ * settings and common tags. Each entry has a command to be run (used to
|
|
|
+ * identify the entry in tmp file), an id (based on the position in rc file, may
|
|
|
+ * change), a description (the command plus things that tags may add), a number
|
|
|
+ * of launch (stored in tmp file) and tags, which change default behavior *)
|
|
|
+
|
|
|
+(* A “basic” rc file is used to interface with the content actualy written to
|
|
|
+ * the drive, and it’s then transforme to create the rc file used almost
|
|
|
+ * everywhere.
|
|
|
+ * “Basic” may used qualify anything referring to a low-level object *)
|
|
|
+type basic_tag = {
|
|
|
+ name : string;
|
|
|
+ arguments : string sexp_list
|
|
|
+} [@@deriving sexp]
|
|
|
+;;
|
|
|
+type basic_entry = {
|
|
|
+ command : string;
|
|
|
+ tags : basic_tag list
|
|
|
+} [@@deriving sexp]
|
|
|
+;;
|
|
|
+type basic_rc = {
|
|
|
+ entries : basic_entry list;
|
|
|
+ common_tags : basic_tag list;
|
|
|
+ settings : string list;
|
|
|
+} [@@deriving sexp]
|
|
|
+;;
|
|
|
+
|
|
|
+(* Template for the rc_file *)
|
|
|
+let basic_template =
|
|
|
+ "((entries())(common_tags())(settings()))"
|
|
|
+;;
|
|
|
+
|
|
|
+(* XXX Module exposing functions (hidden by the mli file) for tests *)
|
|
|
+module Test : sig
|
|
|
+ val basic_rc_of_sexp : Sexp.t -> basic_rc
|
|
|
+ val basic_template : string
|
|
|
+end
|
|
|
+= struct
|
|
|
+ let basic_rc_of_sexp = basic_rc_of_sexp
|
|
|
+ let basic_template = basic_template
|
|
|
+end;;
|
|
|
+
|
|
|
+(* Message to display on first use, i.e. on initialisation of rc file *)
|
|
|
+let welcome_msg =
|
|
|
+ sprintf
|
|
|
+ "Nice to meet you! Here is some tips to get started with OcLaunch.\n\
|
|
|
+ Use 'help' subcommand to get help (it works both after the name of the \
|
|
|
+ software and with another subcommand). For instance run\n\
|
|
|
+ `oclaunch help add`\n\
|
|
|
+ For further help, see https://oclaunch.eu.org. Report any bug at %s\
|
|
|
+ \n\
|
|
|
+ \n\
|
|
|
+ Feedback is welcome at feedback@oclaunch.eu.org.\n\
|
|
|
+ To get remind for new stable versions, subscribe to our low-traffic mailing \
|
|
|
+ list: announce@oclaunch.eu.org. \
|
|
|
+ More here: https://s.oclaunch.eu.org/ml\n\
|
|
|
+ See you soon! To keep in touch: https://s.oclaunch.eu.org/kt\n"
|
|
|
+ Bug.url
|
|
|
+;;
|
|
|
+
|
|
|
+let create_basic name =
|
|
|
+ sprintf "Initializing empty configuration file in %s." name
|
|
|
+ |> Messages.warning;
|
|
|
+ Messages.tips welcome_msg;
|
|
|
+ Licencing.print ~cecill:false;
|
|
|
+ Out_channel.write_all name basic_template
|
|
|
+;;
|
|
|
+
|
|
|
+let rec get_basic rc_name =
|
|
|
+ match Sys.file_exists rc_name with
|
|
|
+ | `No -> create_basic rc_name; get_basic rc_name
|
|
|
+ | `Unknown -> failwith "Error reading configuration file";
|
|
|
+ | `Yes -> (* Try to read, if there is an error, reset file *)
|
|
|
+ In_channel.read_all rc_name
|
|
|
+ |> Sexp.of_string
|
|
|
+ |> basic_rc_of_sexp
|
|
|
+;;
|
|
|
+
|
|
|
+(* Now transformed objects *)
|
|
|
+let object_of_tag tag = failwith "TODO"
|
|
|
+(* object
|
|
|
+ val name = tag.name;
|
|
|
+ val argument
|
|
|
+ end *)
|
|
|
+;;
|
|
|
+let object_of_tag_list =
|
|
|
+ List.map ~f:object_of_tag
|
|
|
+;;
|
|
|
+let object_of_entry object_common_tags entry = object
|
|
|
+ val command = entry.command;
|
|
|
+ val tags = (object_of_tag_list entry.tags) @ object_common_tags
|
|
|
+end;;
|
|
|
+let object_of_setting setting = failwith "TODO";;
|
|
|
+
|
|
|
+let init ?(rc=(!Const.rc_file)) =
|
|
|
+ let basic_rc = get_basic (Lazy.force rc) in
|
|
|
+ let common_tags = object_of_tag_list basic_rc.common_tags in
|
|
|
+object (self)
|
|
|
+ (* Name of rc file when written to disk *)
|
|
|
+ val name = Lazy.force rc
|
|
|
+ method change_name new_name = {< name = new_name >}
|
|
|
+ (* Write rc file *)
|
|
|
+ method write = failwith "Not implemented"
|
|
|
+
|
|
|
+ val entries = List.map ~f:(object_of_entry common_tags) basic_rc.entries
|
|
|
+ val common_tags = common_tags
|
|
|
+ val settings = List.map ~f:object_of_setting basic_rc.settings
|
|
|
+
|
|
|
+ (* Get entry number n *)
|
|
|
+ method entry ~n = List.nth entries n
|
|
|
+
|
|
|
+ method add_entries new_entries =
|
|
|
+ {< entries = new_entries @ entries >}
|
|
|
+ method add_common_tags tags =
|
|
|
+ {< common_tags = tags @ common_tags >}
|
|
|
+ method add_settings new_settings =
|
|
|
+ {< settings = new_settings @ settings >}
|
|
|
+
|
|
|
+ method filter_map_entries ~f =
|
|
|
+ {< entries = List.filter_mapi entries ~f >}
|
|
|
+ method filter_map_common_tags ~f =
|
|
|
+ {< common_tags = List.filter_map common_tags ~f >}
|
|
|
+ method filter_map_settings ~f =
|
|
|
+ {< settings = List.filter_map settings ~f >}
|
|
|
+
|
|
|
+ (* Shorthand *)
|
|
|
+ method change_entry n ~f =
|
|
|
+ self#filter_map_entries ~f:(fun i e -> if i=n then Some (f e) else Some e)
|
|
|
+ method remove_entry n =
|
|
|
+ self#filter_map_entries ~f:(fun i e -> if i=n then None else Some e)
|
|
|
+ method read_common_tags ~f =
|
|
|
+ self#filter_map_common_tags ~f:(fun e -> f e; Some e)
|
|
|
+ method read_settings ~f =
|
|
|
+ self#filter_map_settings ~f:(fun e -> f e; Some e)
|
|
|
+end;;
|
|
|
+
|
|
|
+(*
|
|
|
+ (* Tools to create new tag *)
|
|
|
+ class enpty_tag = object
|
|
|
+ val
|
|
|
+*)
|