From f6329ae1d15d04f99ce0ab1994d30ea23926cc24 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 2 Oct 2014 11:11:39 +0100 Subject: [PATCH] Detection of cpdflin --- cpdfcommand.ml | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 544bf2f..0aa1713 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -8,6 +8,35 @@ let version_date = "(unreleased, 16th September 2014)" open Pdfutil open Pdfio +(* Find the location of the cpdflin binary, either in a provided place (with +-cpdflin), or using argv[0] or in the current directory *) +let find_cpdflin provided = + match provided with + Some x -> Some x + | None -> + match Sys.argv.(0) with + "cpdf" -> + Printf.printf "Argv no use, looking in current directory\n"; + if Sys.file_exists "cpdflin" then Some "cpdflin" else None + | s -> + Printf.printf "Found location from argv at %s\n%!" s; + try + let fullname = + Filename.dirname s ^ Filename.dir_sep ^ "cpdflin" + in + if Sys.file_exists fullname then Some fullname else None + with + _ -> None + +let _ = + let cpdflin = + (match find_cpdflin None with + None -> "none" + | Some x -> x) + in + print_endline cpdflin; + Sys.command cpdflin + (* Wrap up the file reading functions to exit with code 1 when an encryption problem occurs. This happens when object streams are in an encrypted document and so it can't be read without the right password... The existing error @@ -149,7 +178,6 @@ type op = | RemoveUnusedResources | ExtractFontFile | ExtractText - | PrintLinearization | OpenAtPage of int | OpenAtPageFit of int | AddPageLabels @@ -1743,8 +1771,7 @@ and specs = ("-gs", Arg.String setgspath, ""); ("-debug", Arg.Unit setdebug, ""); ("-fix-prince", Arg.Unit (setop RemoveUnusedResources), ""); - ("-extract-text", Arg.Unit (setop ExtractText), ""); - ("-print-linearization", Arg.Unit (setop PrintLinearization), "")] + ("-extract-text", Arg.Unit (setop ExtractText), "")] and usage_msg = "Syntax: cpdf [-o ] \n\n\ @@ -3432,12 +3459,6 @@ let go () = print_string text; print_newline () end - | Some PrintLinearization -> - begin match args.inputs with - | (InFile inname, _, _, u, o)::_ -> - Pdfread.print_linearization (Pdfio.input_of_channel (open_in_bin inname)) - | _ -> raise (Arg.Bad "-print-linearization: supply a single file name") - end | Some AddPageLabels -> let pdf = get_single_pdf args.op false in let range = parse_pagespec pdf (get_pagespec ()) in