NOT and CPDF_DEBUG

This commit is contained in:
John Whitington 2021-08-10 20:11:20 +01:00
parent 9997462436
commit 53d0a08422
5 changed files with 44 additions and 27 deletions

View File

@ -1,7 +1,9 @@
2.5 (Upcoming) 2.5 (Upcoming)
o Environment variable CPDF_REPRODUCIBLE_DATES for testing o Environment variable CPDF_REPRODUCIBLE_DATES for testing
o Environment variable CPDF_DEBUG for -debug
o Effectively make stderr unbuffered o Effectively make stderr unbuffered
o Prepend NOT to a page range to invert it
2.4 (June 2021) 2.4 (June 2021)

View File

@ -435,11 +435,18 @@ let fixup_negatives endpage = function
Pdfgenlex.LexInt (endpage + 1 + ~-(int_of_string (implode (tl (explode s))))) Pdfgenlex.LexInt (endpage + 1 + ~-(int_of_string (implode (tl (explode s)))))
| x -> x | x -> x
let parse_pagespec_inner endpage pdf spec = let invert_range endpage r =
option_map (fun p -> if mem p r then None else Some p) (ilist 1 endpage)
let rec parse_pagespec_inner endpage pdf spec =
let spec = space_string spec in let spec = space_string spec in
if endpage < 1 then raise (Pdf.PDFError "This PDF file has no pages and is therefore malformed") else if endpage < 1 then raise (Pdf.PDFError "This PDF file has no pages and is therefore malformed") else
let numbers = let numbers =
try try
match explode spec with
| 'N'::'O'::'T'::r ->
invert_range endpage (parse_pagespec_inner endpage pdf (implode r))
| _ ->
match rev (explode spec) with match rev (explode spec) with
| ['n'; 'e'; 'v'; 'e'] -> | ['n'; 'e'; 'v'; 'e'] ->
keep even (ilist 1 endpage) keep even (ilist 1 endpage)

View File

@ -4408,6 +4408,12 @@ let gs_malformed_force fi fo =
ensure that all memory is cleaned. See clearance of filenames hashtable, for ensure that all memory is cleaned. See clearance of filenames hashtable, for
example. *) example. *)
let process_env_vars () =
match Sys.getenv_opt "CPDF_DEBUG" with
| Some "true" -> args.debug <- true
| Some "false" -> args.debug <- false
| _ -> ()
(* Main function. *) (* Main function. *)
let go_withargv argv = let go_withargv argv =
(* Check for the standalone -gs-malformed-force special command line. This (* Check for the standalone -gs-malformed-force special command line. This
@ -4450,6 +4456,7 @@ let go_withargv argv =
(*Printf.printf "AND:%b, %s\n" islast (Array.fold_left (fun x y -> x ^ " " ^ y) "" s); (*Printf.printf "AND:%b, %s\n" islast (Array.fold_left (fun x y -> x ^ " " ^ y) "" s);
flprint "\n";*) flprint "\n";*)
reset_arguments (); reset_arguments ();
process_env_vars ();
parse_argv () s (align_specs specs) anon_fun usage_msg; parse_argv () s (align_specs specs) anon_fun usage_msg;
parse_argv () (Array.of_list ("cpdf"::!control_args)) (align_specs specs) anon_fun usage_msg; parse_argv () (Array.of_list ("cpdf"::!control_args)) (align_specs specs) anon_fun usage_msg;
let addrange pdf = AlreadyInMemory pdf, args.dashrange, "", "", ref false, None in let addrange pdf = AlreadyInMemory pdf, args.dashrange, "", "", ref false, None in

Binary file not shown.

View File

@ -459,6 +459,7 @@ at least five pages.
\item The word \texttt{all} is the same as \texttt{1-end}. \item The word \texttt{all} is the same as \texttt{1-end}.
\item A range must contain no spaces. \item A range must contain no spaces.
\item A tilde (\texttt{\~{}}) defines a page number counting from the end of the document rather than the beginning. Page \texttt{\~{}1} is the last page, \texttt{\~{}2} the penultimate page etc. \item A tilde (\texttt{\~{}}) defines a page number counting from the end of the document rather than the beginning. Page \texttt{\~{}1} is the last page, \texttt{\~{}2} the penultimate page etc.
\item Prepending \texttt{NOT} to a whole page range inverts it.
\end{itemize} \end{itemize}
\noindent For example: \noindent For example: