Changeset 21 in code for trunk/lib/file_store.ml
- Timestamp:
- Nov 1, 2022, 5:11:09 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/file_store.ml
r16 r21 4 4 5 5 let extension = ".txt" 6 let def_dir () = try Sys.getenv "txtdir" with Not_found -> 6 7 let txtdir () = try Sys.getenv "txtdir" with Not_found -> 7 8 let share = Filename.concat (Sys.getenv "HOME") ".local/share/texts/" in 8 9 match Sys.is_directory share with true -> share 9 10 | false | exception (Sys_error _) -> "." 11 12 let cfgpath () = match "txt.conf" with 13 | filepath when Sys.file_exists filepath -> filepath 14 | _ -> match Filename.concat (Sys.getenv "HOME") ".config/txt/txt.conf" with 15 | filepath when Sys.file_exists filepath -> filepath 16 | _ -> "" 10 17 11 18 let to_string f = … … 81 88 @@ List.fold_left (fold_valid_text predicate) new_iteration flist 82 89 83 let iter ?(r=false) ?(dir= def_dir ()) ?(predicate=fun _ -> true) ?order ?number fn =90 let iter ?(r=false) ?(dir=txtdir ()) ?(predicate=fun _ -> true) ?order ?number fn = 84 91 let flist = list_fs ~r dir in match order with 85 92 | Some comp -> List.iter fn @@ fold_sort_take ~predicate ~number comp flist … … 87 94 List.fold_left (fold_valid_text predicate) new_iteration flist 88 95 89 let fold ?(r=false) ?(dir= def_dir ()) ?(predicate=fun _ -> true) ?order ?number fn acc =96 let fold ?(r=false) ?(dir=txtdir ()) ?(predicate=fun _ -> true) ?order ?number fn acc = 90 97 let flist = list_fs ~r dir in match order with 91 98 | Some comp -> List.fold_left fn acc @@ fold_sort_take ~predicate ~number comp flist … … 122 129 if Sys.file_exists candidate then Error "Name clash, try again" else Ok candidate 123 130 124 let with_text ?(dir= def_dir ()) new_text =131 let with_text ?(dir=txtdir ()) new_text = 125 132 match id_filename dir extension new_text with 126 133 | Error _ as e -> e … … 134 141 end 135 142 136 let of_kv_file path=143 let of_kv_file ?(path=cfgpath ()) () = 137 144 let open Text_parse in 138 145 let subsyntaxes = Parsers.Key_value.[| … … 140 147 let of_string text acc = 141 148 Parser.parse subsyntaxes { text; pos = 0; right_boundary = String.length text - 1 } acc in 142 of_string (to_string @@ path) Store.KV.empty 149 if path <> "" then of_string (to_string @@ path) Store.KV.empty 150 else Store.KV.empty
Note:
See TracChangeset
for help on using the changeset viewer.