RECHERCHER :
COMMUNAUTE MP
Identifiez vous ...
Devenir Membre
J'ai oublié mon MDP
DOMAINE MP
Bavardages
Langages Généraux
Langages Web
Langages DotNet
Autres langages
Dev. Jeux Video
Sécurité
Sys. Exploitation
Graphismes
Logiciels
Réseaux
Bases de données
Méthodologies
Emplois High-tech
Aide juridique
Articles juridiques
FORUM
Index des forums
Ajouter un sujet
Rechercher sujet
Contact Responsable
Devenir modérateur
CHAT MP IRC
Votre pseudo ...
Serv: irc.irc-land.org
Chan: #MoteurProg
PARTICIPER
Plus de 3500 emplois.
Rechercher un job
Déposez votre CV
Emplois High-tech

Visiteur MP

 Une fonction Command_Line_To_String

Forum : ADA
Sous Catégorie : Aucune
Type du sujet : Sujet Normale
FAQ : FAQ ADA

SUIVI DES SUJETS PAR MAIL

SUIVI PAR MAIL INACTIF

RESOLUTION DU SUJET SUJET RESOLU
BLOQUAGE DU SUJET SUJET ACTIF
APPARTENANCE A LA FAQ N'APPARTIENT PAS A LA FAQ


PAGE : [1]

POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

FORUM ADA

PREMIERE PAGE

PAGE PRECEDENTE

Page précedente

Page suivante

PAGE SUIVANTE

DERNIERE PAGE
jovalise
Nouveau membre
Inscrit : 21/12/2005
Messages : 21
Message
#83263
Posté le 21/12/05 à 15:47
Une fonction Command_Line_To_String qui ne fonctionne pas
raised CONSTRAINT_ERROR : main.adb:37 range check failed

1:-------------------------------------------------------------------------------
2:-- Manuel De Girardi 1970 2006 --
3:-- Laboratoire de recherche en intelligence artificelle --
4:--
5:-- --
6:-- --
7:-- Ce logiciel est sous Copyleft (C) --
8:-------------------------------------------------------------------------------
9:with Text_Io;
10:use Text_Io;
11:with Ada.Strings, Ada.Strings.Fixed;
12:use Ada.Strings, Ada.Strings.Fixed;
13:with Ada.Command_Line;
14:use Ada.Command_Line;
15:procedure Main is
16: function Length return Positive is
17: Count : Positive := 1;
18: begin
19: Count := Command_Name'Length;
20: for I in 1..Argument_Count loop
21: Count := Count + Argument(I)'length + 1;
22: end loop;
23: return Count;
24: end Length;
25:
26:-------------------------------------------------------------------------
27:-- command_line_to_string -----------------------------------------------
28:
29: function Command_Line_To_String return String is
30: String_Command_Line : String (1..Length);
31: K : Positive := Command_Name'Length+1;
32: begin
33: String_Command_Line(1..Command_Name'Length) := Command_Name;
34: for I in 1..Argument_Count loop
35: String_Command_Line(K) := ' ';
36: K := K+1;
37: String_Command_Line(K..K+Argument(I)'length) := Argument(I);
38: K := K + Argument(I)'Length+1;
39: end loop;
40: return String_Command_Line;
41: end Command_Line_To_String;
42:
43: -------------------------------------------------------------------------
44: -------------------------------------------------------------------------
45:
46: procedure Help is
47: begin
48: Put_line(Command_Name & " help : " & Command_Name & " [ Option(s) ]");
49: Put_Line("Options :");
50: Put_Line("--help Affiche l'aide de " & Command_Name);
51: Put_Line("--version Affiche la version de " & Command_Name);
52: end Help;
53: procedure version is
54: begin
55: Put_line(Command_Name & " version : alpha-0.0.0 20060101");
56: end version;
57:begin
58: if Index(Command_Line_To_String, "--help") /= 0 then
59: Help;return;
60: end if;
61: if Index(Command_Line_To_String, "--version") /= 0 then
62: version;return;
63: end if;
64:end Main;

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Publicité
Inscrit : X
Messages : X
Message
#Aucun

HAUT DE PAGE

  

jovalise
Nouveau membre
Inscrit : 21/12/2005
Messages : 21
Message
#83268
Posté le 21/12/05 à 16:16
37: String_Command_Line(K..K+Argument(I)'Length-1) := Argument(I);

Mais ça ne suffit pas ... autre prohblème en vue

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

jovalise
Nouveau membre
Inscrit : 21/12/2005
Messages : 21
Message
#83273
Posté le 21/12/05 à 16:51
J'ai changé le code de la function Command_Line_To_String, voila ce que ça donne :

with Text_Io;
use Text_Io;
with Gnat.Os_Lib;
use Gnat.Os_Lib;

with Ada.Strings, Ada.Strings.Fixed;
use Ada.Strings, Ada.Strings.Fixed;
with Ada.Command_Line;
use Ada.Command_Line;
procedure Main is
function Length return Positive is
Count : Positive := Command_Name'Length;
begin

for I in 1..Argument_Count loop
Count := Count + Argument(I)'length + 1;
end loop;
return Count;
end Length;

-------------------------------------------------------------------------
-- command_line_to_string -----------------------------------------------

function Command_Line_To_String return String is
String_Command_Line : String_Access := new String ' (" ");

begin
for I in 1..Argument_count loop
String_Command_Line := new String ' (Insert(String_Command_Line.all,
String_Command_Line.all'Length,
' ' & Argument(I)));

end loop;

return String_Command_Line.all;
end Command_Line_To_String;

-------------------------------------------------------------------------
-------------------------------------------------------------------------

procedure Help is
begin
Put_line(Command_Name & " help : " & Command_Name & " [ Option(s) ]");
Put_Line("Options :");
Put_Line("--help Affiche l'aide de " & Command_Name);
Put_Line("--version Affiche la version de " & Command_Name);
end Help;
procedure version is
begin
Put_line(Command_Name & " version : alpha-0.0.0 20060101");
end version;
begin
if Index(Command_Line_To_String, "--help") /= 0 then
Help;return;
end if;
if Index(Command_Line_To_String, "--version") /= 0 then
version;return;
end if;
end Main;

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

jovalise
Nouveau membre
Inscrit : 21/12/2005
Messages : 21
Message
#83505
Posté le 24/12/05 à 15:24
La correction de la fonction "command_line_to_string" :

-------------------------------------------------------------------------
-- command_line_to_string -----------------------------------------------

function Command_Line_To_String return String is
String_Command_Line : String (1..Length);
K : Positive := Command_Name'Length;
begin
String_Command_Line(1..Command_Name'Length) := Command_Name;
for I in 1..Argument_Count loop
K := K+1;
String_Command_Line(K) := ' ';
String_Command_Line(K..K+Argument(I)'Length-1) := Argument(I);
K := K + Argument(I)'Length-1;
end loop;
return String_Command_Line;
end Command_Line_To_String;

-------------------------------------------------------------------------
-------------------------------------------------------------------------
Smiley

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 
POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

PREMIERE PAGE

PAGE PRECEDENTE Page précédente

Page suivante

PAGE SUIVANTE DERNIERE PAGE

FORUM ADA



    PAGE : [1]



.: Site Web développé par Julien Pichot et l'équipe MPWG avec www.evolvia-web.com :.