Skip to content

Commit

Permalink
Merge pull request #1 from coco33920/new_parser
Browse files Browse the repository at this point in the history
[Parser Update]
  • Loading branch information
vanilla-extracts authored Mar 20, 2022
2 parents b51c121 + 487fa81 commit 133cbd8
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 480 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ _build/
_build/*
*.py
*.tex
out.html
out.html
repl_utils.ml
62 changes: 7 additions & 55 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let filename = ref ""
let glossary_name = ref ""

let name = ref ""
let start_chapter = ref (-1)
let start_chapter = ref (1)
let chapter = ref (-1)
let outname = ref ""
let spec = [
Expand All @@ -11,38 +11,14 @@ let spec = [
("--name", Arg.Set_string name, "Name of the file");
("--start-chapter", Arg.Set_int start_chapter, "Starting chapters");
("--chapter", Arg.Set_int chapter, "compile only a chapter");
("--use-glossary", Arg.Set_string glossary_name, "specify the glossary")
]

let execute_command file outfile start_chapter name chapter =
Htmlfromtexbooks.Htmlgen.print_file ~start_chapter:start_chapter file outfile name chapter
let execute_command file outname start_chapter =
Htmlfromtexbooks.Parser.print_file_in_html ~min_chap:start_chapter file outname;;

let parse_filename file outfile start_chapter name chapter =
let parse_filename file outname start_chapter =
if not (Sys.file_exists file) then (Printf.printf "The %s file do not exists" file; exit 2)
else execute_command file outfile start_chapter name chapter;;

let write_default_configuration channel =
output_string channel "start_chapter=1\n";
flush channel;
output_string channel "name=TeX Generator\n";
flush channel;
output_string channel "";
flush channel;;



let load_configuration () =
let a = Unix.getenv "HOME" in
let b = a ^ (Filename.dir_sep) ^ ".htmlfromtexbooks"
in if not (Sys.file_exists b) then Unix.mkdir b 0o640
else if not (Sys.is_directory b) then (Sys.remove b; Unix.mkdir b 0o755);
let c = b ^ (Filename.dir_sep) ^ ".config" in
if not (Sys.file_exists c) then (let d = open_out c in write_default_configuration d; close_out d;);
let f = open_in c
in let c = input_line f in let d = input_line f
in let d,c = (Str.global_replace (Str.regexp "name=") "" d),(Str.global_replace (Str.regexp "start_chapter=") "" c)
in d,int_of_string c;;

else execute_command file outname start_chapter;;

let find_opt (a : 'a -> bool) (arr: 'a array) =
let arr = Array.to_list arr in
Expand All @@ -63,7 +39,7 @@ let detect_a_file () =
| None -> ""
| Some v -> (Sys.readdir ".").(v);;

let msg = "htmlfromtex --input <file> --output <out_file> [--use-glossary <glossary> | --name <name> | --start-chapter <chapter>]";;
let msg = "htmlfromtex --input <file> --output <out_file> [| --name <name> | --start-chapter <chapter>]";;
let _ =
Arg.parse spec (fun _ -> ()) msg;
if !filename = "" then
Expand All @@ -77,28 +53,4 @@ let _ =
Printf.printf "output filename has been automatically generated to be %s\n" !outname;
else
Printf.printf "output filename is %s\n" !outname;
in let tbl = Htmlfromtexbooks.Parser.detect_prelude !filename
in if String.trim (String.concat "" (Htmlfromtexbooks.Utils.read_file !filename)) = ""
then (print_endline "File is empty"; exit 2 |> ignore;)
else
if !glossary_name = "" then
let a = try Hashtbl.find tbl "gloss" with _ -> "" in
glossary_name := a;
Printf.printf "Glossary have been extracted from the file and is %s\n" !glossary_name;
else
Printf.printf "Glossary filename is %s\n" !glossary_name;
let default_name,default_starting_chapter = load_configuration () in
if !name = "" then
let n = try Hashtbl.find tbl "title" with _ -> default_name in
name := n;
Printf.printf "Name have been automatically extracted as %s\n" !name
else
Printf.printf "Name is %s\n" !name;
if !start_chapter = -1 then
(start_chapter := default_starting_chapter;
Printf.printf "Starting chapter have been automatically generated and is %d\n" !start_chapter)
else
Printf.printf "Starting chapter is %d\n" !start_chapter;

Htmlfromtexbooks.Glossary.init_glossary !glossary_name;
parse_filename !filename !outname !start_chapter !name !chapter;;
parse_filename !filename !outname !start_chapter;;
1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

2 changes: 0 additions & 2 deletions docs/htmlfromtexbooks/index.html

This file was deleted.

Empty file.
Loading

0 comments on commit 133cbd8

Please sign in to comment.