Top Prev Next Up Down TEST

ExKhi.adb


001| with Ada.Text_IO; use Ada.Text_IO;
002| with Ada.Command_Line;
003| with Y2018.Text.Core; use Y2018.Text.Core;
004| with Y2018.Text.Core.Str; use Y2018.Text.Core.Str;
005| with Ada.Command_Line;
006| with Y2018.Text.Core.CVarPack; use Y2018.Text.Core.CVarPack;
007| with Y2018.Text.Jets; use Y2018.Text.Jets;
008| with Y2018.Text.Jets.MatchPack;
009| with Y2018.Text.Jets.PatternPack;
010| --with DSECT;
011| procedure ExKhi is
012| __arg:CVar;
013| __inFile : File_Type;
014| __patternvalue : CVar;
015| __sourcevalue : CVar;
016| __p:PatternPack.Pattern_AC:=new PatternPack.Pattern;
017| __m : MatchPack.Match_TY;
018| __cp:PatternPack.Pattern_AC:=new PatternPack.Pattern;
019| __nextPos : Integer:=0;
020| __Qmap:CList.map; -- used by MatchPack.updClist
021| __this:Clist.Cursor; -- used by MatchPack.updClist
022| __val:Celem; -- used by MatchPack.updClist
023| begin
024| __if Ada.Command_Line.Argument_Count = 0 then
025| _____arg:=Null_CVar & "ExKhi.prop";
026| __else
027| _____arg:=Null_CVar & Ada.Command_Line.Argument(1);
028| __end if;
029| __declare
030| _____readFrom : String := "" & arg;--"ExKhi.prop";
031| __begin
032| _____Open (File => inFile,Mode => In_File,Name => readFrom);
033| __exception
034| _____when others =>
035| ________Put_Line (Standard_Error,"Can not open file '" & readFrom & "'.");
036| ________Ada.Command_Line.Set_Exit_Status(Ada.Command_Line.Failure);
037| ________return;
038| __end;
039| __PatternPack.compileU(cp,"^[\s]*(pattern|source)[\s]*=(.*)"c);
040| __while not End_Of_File(inFile) loop
041| _____declare
042| ________line:CFix:= ""c & Get_Line(inFile);
043| _____begin
044| ________if PatternPack.matches(cp,1,nextPos,line,m) then
045| ___________declare
046| ______________r:I_A_ARRAY:=MatchPack.getMatch(m);
047| ______________com:CFix:=To_UC(subIA(line,r(1)));
048| ___________begin
049| ______________if com = "PATTERN"c then
050| _________________patternvalue:=Null_CVar & stripC(subIA(line,r(2)));
051| ______________elsif com = "SOURCE"c then
052| _________________sourcevalue:=Null_CVar & subIA(line,r(2));
053| ______________end if;
054| ______________if Length(sourcevalue) > 0 and Length(patternvalue) > 0 then
055| _________________Put_Line (Standard_Output,"LINE " & line);
056| _________________PatternPack.compileM(p,To_CFix(patternvalue));
057| _________________if PatternPack.matches(p,1,nextPos,To_CFix(sourcevalue),m) then
058| ____________________declare
059| _______________________r:I_A_ARRAY:=MatchPack.getMatch(m);
060| ____________________begin
061| _______________________for i in r'First(1) .. r'Last(1) loop
062| __________________________if r(i)(2) < r(i)(1) then
063| _____________________________Put_Line (Standard_Output,Integer'image(i) & "|");
064| __________________________else
065| _____________________________Put_Line (Standard_Output,Integer'image(i) & "|" & subIA(sourcevalue,r(i)));
066| __________________________end if;
067| _______________________end loop;
068| ____________________end;
069| ____________________Qmap:=MatchPack.getClist(m,To_CFix(patternvalue));
070| ____________________this:=CList.First(Qmap);
071| ____________________while Clist.Has_Element(this) loop
072| _______________________val:=CList.Element(this);
073| _______________________Put_Line (Standard_Output,CVarPack.To_String(val.s));
074| _______________________Clist.Next(this);
075| ____________________end loop;
076| _________________else
077| ____________________Put_Line (Standard_Output,"<No match>");
078| _________________end if;
079| _________________sourcevalue:=Null_CVar;
080| ______________end if;
081| ___________end;
082| ________elsif line'Length(1) > 1 and then line(1) = '>'c then
083| ___________Put_Line (Standard_Output,"" & subC(line,2));
084| ________end if;
085| _____end;
086| __end loop; -- while not End_Of_File(inFile)
087| __close(inFile);
088| end ExKhi;

ExKhi.adb must first be precompiled and after that compiled with gnatmake.
Input for the procedure ExKhi (file ExKhi.prop)


> -- ExKhi 1  --
pattern=^.*?(ABC)
source=prefixABC
#
> == BOTTOM ==

Result

Running export LD_LIBRARY_PATH=lib;bin/exkhi in TEST directory.


 -- ExKhi 1  --
LINE source=prefixABC
 0|prefixABC
 1|ABC
mid= 1[1:9]REQ_PALCAP[2] at pos[2:0]
mid= 2[7:9]REQ_PALCAP[5] at pos[5:9] (ABC)
 == BOTTOM ==