You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1532 Reporter: administrator Status: closed Resolution: fixed Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
[[email in French]]
Chers developpeurs d'Ocaml
Arg.parse_argv dépend aussi de la valeur de Arg.current qui a été
souvent modifiée par Arg.parse
Je suggère soit de documenter qu'il faut généralement modifier la
valeur de Arg.current avant Arg.parse_argv (car elle a déjà été
modifié par un Arg.parse précédent) soit de l'ajouter à Arg.parse_argv
par
(* code non testé *)
let parse_argv ?(pcurrent=current) argv speclist anonfun errmsg =
let initpos = !pcurrent in
let stop error =
let progname =
if initpos < Array.length argv then argv.(initpos) else "(?)" in
begin match error with
| Unknown "-help" -> ()
| Unknown "--help" -> ()
| Unknown s ->
eprintf "%s: unknown option %s'.\n" progname s | Missing s -> eprintf "%s: option %s' needs an argument.\n" progname s
| Wrong (opt, arg, expected) ->
eprintf "%s: wrong argument %s'; option %s' expects %s.\n"
progname arg opt expected
| Message s ->
eprintf "%s: %s.\n" progname s
end;
usage speclist errmsg;
if error = Unknown "-help" || error = Unknown "--help"
then exit 0
else exit 2
in
let l = Array.length argv in
incr current;
while !pcurrent < l do
let s = argv.(!pcurrent) in
if String.length s >= 1 && String.get s 0 = '-' then begin
let action =
try assoc3 s speclist
with Not_found -> stop (Unknown s)
in
begin try
match action with
| Unit f -> f ();
| Set r -> r := true;
| Clear r -> r := false;
| String f when !pcurrent + 1 < l ->
f argv.(!pcurrent + 1);
incr current;
| Symbol (symb, f) when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
if List.mem arg symb then begin
f argv.(!pcurrent + 1);
incr current;
end else begin
stop (Wrong (s, arg, "one of: " ^ (make_symlist "" " " "" symb)))
end
| Set_string r when !pcurrent + 1 < l ->
r := argv.(!pcurrent + 1);
incr current;
| Int f when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try f (int_of_string arg)
with Failure "int_of_string" -> stop (Wrong (s, arg, "an integer"))
end;
incr current;
| Set_int r when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try r := (int_of_string arg)
with Failure "int_of_string" -> stop (Wrong (s, arg, "an integer"))
end;
incr current;
| Float f when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try f (float_of_string arg);
with Failure "float_of_string" -> stop (Wrong (s, arg, "a float"))
end;
incr current;
| Set_float r when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try r := (float_of_string arg);
with Failure "float_of_string" -> stop (Wrong (s, arg, "a float"))
end;
incr current;
| Rest f ->
while !pcurrent < l - 1 do
f argv.(!pcurrent + 1);
incr current;
done;
| _ -> stop (Missing s)
with Bad m -> stop (Message m);
end;
incr current;
end else begin
(try anonfun s with Bad m -> stop (Message m));
incr current;
end;
done;
;;
Amicalement
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basilestarynkevitchnet
alias: basiletunesorg
8, rue de la Faïencerie, 92340 Bourg La Reine, France
The text was updated successfully, but these errors were encountered:
Arg.parse_argv dépend aussi de la valeur de Arg.current qui a été
souvent modifiée par Arg.parse
Effectivement, c'est une erreur de conception.
Je suggère soit de documenter qu'il faut généralement modifier la
valeur de Arg.current avant Arg.parse_argv (car elle a déjà été
modifié par un Arg.parse précédent) soit de l'ajouter à Arg.parse_argv
par
Nous n'avont fait ni l'un ni l'autre, mais nous avons change parse_argv
pour mettre current a 0 avant de commencer, et pour le recharger
a son ancienne valeur a la fin.
Arg.parse_argv dépend aussi de la valeur de Arg.current qui a été
souvent modifiée par Arg.parse
Je suggère soit de documenter qu'il faut généralement modifier la
valeur de Arg.current avant Arg.parse_argv (car elle a déjà été
modifié par un Arg.parse précédent) soit de l'ajouter à Arg.parse_argv
par
Malheureusement, le changement que j'avais fait s'avere incompatible
avec findlib, donc je l'ai defait et j'ai documente le fait qu'il faut changer
Arg.current avant d'appeler Arg.parse_argv.
Original bug ID: 1532
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
[[email in French]]
Chers developpeurs d'Ocaml
Arg.parse_argv dépend aussi de la valeur de Arg.current qui a été
souvent modifiée par Arg.parse
Je suggère soit de documenter qu'il faut généralement modifier la
valeur de Arg.current avant Arg.parse_argv (car elle a déjà été
modifié par un Arg.parse précédent) soit de l'ajouter à Arg.parse_argv
par
(* code non testé *)
let parse_argv ?(pcurrent=current) argv speclist anonfun errmsg =
let initpos = !pcurrent in
let stop error =
let progname =
if initpos < Array.length argv then argv.(initpos) else "(?)" in
begin match error with
| Unknown "-help" -> ()
| Unknown "--help" -> ()
| Unknown s ->
eprintf "%s: unknown option
%s'.\n" progname s | Missing s -> eprintf "%s: option
%s' needs an argument.\n" progname s| Wrong (opt, arg, expected) ->
eprintf "%s: wrong argument
%s'; option
%s' expects %s.\n"progname arg opt expected
| Message s ->
eprintf "%s: %s.\n" progname s
end;
usage speclist errmsg;
if error = Unknown "-help" || error = Unknown "--help"
then exit 0
else exit 2
in
let l = Array.length argv in
incr current;
while !pcurrent < l do
let s = argv.(!pcurrent) in
if String.length s >= 1 && String.get s 0 = '-' then begin
let action =
try assoc3 s speclist
with Not_found -> stop (Unknown s)
in
begin try
match action with
| Unit f -> f ();
| Set r -> r := true;
| Clear r -> r := false;
| String f when !pcurrent + 1 < l ->
f argv.(!pcurrent + 1);
incr current;
| Symbol (symb, f) when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
if List.mem arg symb then begin
f argv.(!pcurrent + 1);
incr current;
end else begin
stop (Wrong (s, arg, "one of: " ^ (make_symlist "" " " "" symb)))
end
| Set_string r when !pcurrent + 1 < l ->
r := argv.(!pcurrent + 1);
incr current;
| Int f when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try f (int_of_string arg)
with Failure "int_of_string" -> stop (Wrong (s, arg, "an integer"))
end;
incr current;
| Set_int r when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try r := (int_of_string arg)
with Failure "int_of_string" -> stop (Wrong (s, arg, "an integer"))
end;
incr current;
| Float f when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try f (float_of_string arg);
with Failure "float_of_string" -> stop (Wrong (s, arg, "a float"))
end;
incr current;
| Set_float r when !pcurrent + 1 < l ->
let arg = argv.(!pcurrent + 1) in
begin try r := (float_of_string arg);
with Failure "float_of_string" -> stop (Wrong (s, arg, "a float"))
end;
incr current;
| Rest f ->
while !pcurrent < l - 1 do
f argv.(!pcurrent + 1);
incr current;
done;
| _ -> stop (Missing s)
with Bad m -> stop (Message m);
end;
incr current;
end else begin
(try anonfun s with Bad m -> stop (Message m));
incr current;
end;
done;
;;
Amicalement
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basilestarynkevitchnet
alias: basiletunesorg
8, rue de la Faïencerie, 92340 Bourg La Reine, France
The text was updated successfully, but these errors were encountered: