Rosetta Code/Find unimplemented tasks: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Minor tidy and rerun) |
JoseAlexis (talk | contribs) m (→{{header|Ada}}) |
||
Line 13: | Line 13: | ||
{{libheader|AWS}} |
{{libheader|AWS}} |
||
Parsing XML with XMLAda from Adacore |
Parsing XML with XMLAda from Adacore |
||
<syntaxhighlight lang="ada">with |
<syntaxhighlight lang="ada">with AWS.Client, AWS.Messages, AWS.Response, AWS.URL; |
||
with |
with DOM.Readers, DOM.Core, DOM.Core.Documents, DOM.Core.Nodes, DOM.Core.Attrs; |
||
with Input_Sources.Strings, Unicode, Unicode. |
with Input_Sources.Strings, Unicode, Unicode.CES.Utf8; |
||
with Ada.Strings.Unbounded, Ada.Text_IO, Ada.Command_Line; |
with Ada.Strings.Unbounded, Ada.Text_IO, Ada.Command_Line; |
||
with Ada.Containers.Vectors; |
with Ada.Containers.Vectors; |
||
use |
use AWS.Client, AWS.Messages, AWS.Response; |
||
use |
use DOM.Readers, DOM.Core, DOM.Core.Documents, DOM.Core.Nodes, DOM.Core.Attrs; |
||
use |
use AWS, Ada.Strings.Unbounded, Input_Sources.Strings; |
||
use Ada.Text_IO, Ada.Command_Line; |
use Ada.Text_IO, Ada.Command_Line; |
||
procedure Not_Coded is |
procedure Not_Coded is |
||
package Members_Vectors is new Ada.Containers.Vectors |
package Members_Vectors is new Ada.Containers.Vectors |
||
(Index_Type => Positive, Element_Type => Unbounded_String); |
|||
Element_Type => Unbounded_String); |
|||
use Members_Vectors; |
use Members_Vectors; |
||
Line 39: | Line 38: | ||
N : Node; |
N : Node; |
||
A : Attr; |
A : Attr; |
||
Page : |
Page : AWS.Response.Data; |
||
S : Messages.Status_Code; |
S : Messages.Status_Code; |
||
-- Query has cmlimit value of |
-- Query has cmlimit value of 500, so we need 2 calls to |
||
-- retrieve the complete list of Programming_category |
-- retrieve the complete list of Programming_category |
||
Uri_Xml : constant String := |
Uri_Xml : constant String := |
||
"https://rosettacode.org/w/api.php?action=query&list=categorymembers" & |
|||
⚫ | |||
& |
|||
⚫ | |||
Cmcontinue : Unbounded_String := Null_Unbounded_String; |
Cmcontinue : Unbounded_String := Null_Unbounded_String; |
||
begin |
begin |
||
loop |
loop |
||
Page := |
Page := |
||
AWS.Client.Get (Uri_Xml & Category & (To_String (Cmcontinue))); |
|||
S := Response.Status_Code (Page); |
S := AWS.Response.Status_Code (Page); |
||
if S not |
if S not in Messages.Success then |
||
Put_Line |
Put_Line |
||
("Unable to retrieve data => Status Code :" & |
("Unable to retrieve data => Status Code :" & Image (S) & |
||
" Reason :" & Reason_Phrase (S)); |
|||
" Reason :" & |
|||
Reason_Phrase (S)); |
|||
raise Connection_Error; |
raise Connection_Error; |
||
end if; |
end if; |
||
declare |
declare |
||
Xml : constant String := Message_Body (Page); |
Xml : constant String := Message_Body (Page); |
||
Line 67: | Line 64: | ||
begin |
begin |
||
Open |
Open |
||
(Xml'Unrestricted_Access, |
(Xml'Unrestricted_Access, Unicode.CES.Utf8.Utf8_Encoding, |
||
Unicode.Ces.Utf8.Utf8_Encoding, |
|||
Source); |
Source); |
||
Parse (Reader, Source); |
Parse (Reader, Source); |
||
Line 79: | Line 75: | ||
A := Get_Named_Item (Attributes (N), "title"); |
A := Get_Named_Item (Attributes (N), "title"); |
||
Members_Vectors.Append |
Members_Vectors.Append |
||
(Mbr_Vector, |
(Mbr_Vector, To_Unbounded_String (Value (A))); |
||
To_Unbounded_String (Value (A))); |
|||
end loop; |
end loop; |
||
Free (List); |
Free (List); |
||
List := Get_Elements_By_Tag_Name (Doc, " |
List := Get_Elements_By_Tag_Name (Doc, "continue"); |
||
if Length (List) = 0 then |
if Length (List) = 0 then |
||
-- we are done |
-- we are done |
||
Free (List); |
Free (List); |
||
Free (Reader); |
Free (Reader); |
||
exit; |
exit; |
||
end if; |
end if; |
||
N := |
N := Item (List, 0); |
||
A := Get_Named_Item (Attributes (N), "cmcontinue"); |
A := Get_Named_Item (Attributes (N), "cmcontinue"); |
||
Cmcontinue := |
Cmcontinue := |
||
To_Unbounded_String ("&cmcontinue=" & AWS.URL.Encode (Value (A))); |
|||
("&cmcontinue=" & Aws.Url.Encode (Value (A))); |
|||
Free (List); |
Free (List); |
||
Free (Reader); |
Free (Reader); |
||
Line 103: | Line 97: | ||
Beginning, Position : Extended_Index; |
Beginning, Position : Extended_Index; |
||
begin |
begin |
||
-- take adavantage that both lists are already sorted |
-- take adavantage that both lists are already sorted |
||
Beginning := First_Index (From); |
Beginning := First_Index (From); |
||
for I in First_Index (Substract) .. Last_Index (Substract) loop |
for I in First_Index (Substract) .. Last_Index (Substract) loop |
||
Position := |
Position := |
||
Find_Index |
|||
(Container => From, |
|||
Item => Members_Vectors.Element (Substract, I), |
|||
Index => Beginning); |
|||
if not (Position = No_Index) then |
if not (Position = No_Index) then |
||
Delete (From, Position); |
Delete (From, Position); |
||
Line 123: | Line 117: | ||
return; |
return; |
||
else |
else |
||
Put ("Language given: "); |
|||
Put_Line (Argument (1)); |
|||
Get_Vector (Argument (1), Language_Members); |
Get_Vector (Argument (1), Language_Members); |
||
end if; |
end if; |
||
Line 136: | Line 132: | ||
Integer'Image (Last_Index ((All_Tasks)))); |
Integer'Image (Last_Index ((All_Tasks)))); |
||
end Not_Coded;</syntaxhighlight> |
end Not_Coded;</syntaxhighlight> |
||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}} |
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}} |