Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1584 connectés 

  FORUM HardWare.fr
  Programmation
  Ada

  [Res]Problème d'encodage sous fvwm des pages de manuels Gnu/Linux.

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Res]Problème d'encodage sous fvwm des pages de manuels Gnu/Linux.

n°2250264
par l'anne​au de l'ia
word master
Posté le 06-02-2015 à 15:34:24  profilanswer
 

Bonjour,
 
J'ai un problème d'encodage donc, avec un programme qui fait un Spawn au dessus de Fvwm.
Sous Gnome pas de problème, enfin... Espérons que ça dure.
 
Bref, sur Fvwm je me trouve avec des caractère carré avec des nombre dedans intercalé entre les caractères lisibles.
 
Donc je suis sur Gnu/Linux, j'essais de lire une page de manuel dans GtkAda grâce à cette ligne que je donne à un Spawn Ada :
 

Code :
  1. "man -t -l -Tutf8 -Eutf8 " & [chemin de la page]


 
J'ai essayé toute les combinaisons, j'espère de -Tutf8 et -Eutf8 ou latin1 avec dans mon makefile l'option -gnatW8 ou pas.
 
J'ai réussi un coup à avoir le bon format, mais j'ai nettoyer mon répertoire de travaille et recompilé et ça marchais plu, donc je sèche carrément.
 
Voilà. j'espère avoir donné toutes les info nécessaire à la compréhension de mon problème.
 
Evidemment cette ligne correct dans un shell comme bash ; mais avec GtkAda au dessus de fvwm c'est illisible.
 
Je suis parti d'une ligne à base de -Tascii, c'était le même résultat, donc j'ai laisser les combinaison à base d'ascii.
 
 
Si vous avez l'astuce. Le projet s'appelle GnuArchman sur Sourceforge. Vous trouverez la ligne en question dans Archman/Arch-Manuals/src/lib/
 
Merci pour vos réponses.
 
Peut-être ai- je oublié un détail presque important, ma variable LANG est settée à fr_FR.UTF-8.


Message édité par par l'anneau de l'ia le 07-02-2015 à 12:40:21

---------------
Toute expression prend un sens spirituel qui nous influence dans notre quête de l'Homme.
mood
Publicité
Posté le 06-02-2015 à 15:34:24  profilanswer
 

n°2250276
par l'anne​au de l'ia
word master
Posté le 06-02-2015 à 19:39:42  profilanswer
 

Alors là, je ne comprends pas.
 
Au lieu de demander à man de me convertir le fichier, je converti les ligne avec Glib.Convert.Locale_To_Utf8(Latin1);
 
Les commandes man sont les mêmes, mais voilà, quoi. Plus ou moins, j'ai testé le plus simple :  ("man -t -Tascii -Elatin1" & ' ' & Manual)
 
Avec en plus une conversion interne.
 
J'ai testé avec et sans l'option -gnatW8.
 
Mais j'ai réussi après avoir utiliser l'option -R, mais ça ne me conviens pas à priori puisque que le formatation mandoc ou docman par groff n'est plus effectuée.
 
Bon, je j'y retourne quand même.


---------------
Toute expression prend un sens spirituel qui nous influence dans notre quête de l'Homme.
n°2250282
par l'anne​au de l'ia
word master
Posté le 06-02-2015 à 22:31:44  profilanswer
 

Bonsoir, j'ai compilé un bout de code pour vous permettre de tester mais il faut un Ctrl+C pour terminer.
 
Ce code appelle "man" pour la page ls qui doit se trouver sur "/usr/share/man/man1/"
Les option à trouver sont ligne 88 normalement, et vous pouver tester l'option -gnatW8 pour lire les caractère UTF-8 avec Ada qui normalement lit du Latin1 mais vous pouvez aussi convertir le texte de la ligne par ligne à l'écriture dans le buffer du Gtk_text_view avec Glib.Convert.Local_To_Utf8();
A compiler avec gnatmake nom de fichier `gtkada-config`
 

Code :
  1. -------------------------------------
  2. -- To Call "man" command by spawn. --
  3. -------------------------------------
  4. with Ada.Text_Io;
  5. use Ada;
  6. with Gnat.Os_Lib;
  7. use Gnat;
  8. with Gnat.Command_Line;
  9. use Gnat.Command_Line;
  10. with Ada.Strings.Unbounded;
  11. with Ada.Strings.Fixed;
  12. use Ada.Strings;
  13.  
  14.  
  15.  
  16. --------------------------------------------
  17. -- To create dialog window with Textview. --
  18. --------------------------------------------
  19. with Gtk.Frame;                         use Gtk.Frame;
  20. with Gtk.Box;                           use Gtk.Box;
  21. with Gtk.Text_Tag_Table;               use Gtk.Text_Tag_Table;
  22. with Gtk.Text_Tag;                     use Gtk.Text_Tag;
  23. with Gtk.Text_Iter;                    use Gtk.Text_Iter;
  24. with Gtk.Text_Buffer;                  use Gtk.Text_Buffer;
  25. with Gtk.Text_View;                    use Gtk.Text_View;
  26. with Gtk.Dialog;                        use Gtk.Dialog;
  27. with Gtk.Scrolled_Window;              use Gtk.Scrolled_Window;
  28. with Gtk.Widget;                       use Gtk.Widget;
  29. with Gtk.Window;                       use Gtk.Window;
  30. with Gtk.Enums;                        use Gtk.Enums;
  31. with Gtk.Main;
  32. with Glib.Error;                       use Glib.Error;
  33. with Glib.Convert;
  34.  
  35. use Glib;
  36.  
  37. ----------------------------------------------------------------------
  38. -- To Convert absolut path to accepted Parse function command line. --
  39. ----------------------------------------------------------------------
  40.  
  41. with Gnat.Directory_Operations;
  42. with Gnat.Directory_Operations.Iteration;
  43. use Gnat.Directory_Operations;
  44.  
  45.  
  46. --------------------------------
  47. -- To print some information. --
  48. --------------------------------
  49. with Ada.Text_Io;
  50.  
  51. ----------------
  52. -- Main unit. --
  53. ----------------
  54. procedure Manpages_To_Gtkada is
  55.  
  56.  
  57.   ----------------------------------------------------------------------------
  58.   -- Search the absolut path of man page from section number and page name. --
  59.   ----------------------------------------------------------------------------
  60.   -- for "man 1 ls" return "man [option] /usr/share/man/man1/ls.1.gz".      --  
  61.   ----------------------------------------------------------------------------
  62.   function Parse_Man_Command (Man : in String) return String is
  63.      
  64.      Man_Line : access String;
  65.   begin
  66.      if Fixed.Index(Man(Fixed.Index_Non_Blank(Man)..Man'Last), " " ) /= 0 and then
  67.        Fixed.Index_Non_Blank(Man, Backward) /=
  68.        Fixed.Index(Man(Fixed.Index_Non_Blank(Man)..Man'Last), " " ) then
  69.         begin
  70.            declare
  71.               Line : constant String := Man(Fixed.Index
  72.                                               (Man(Fixed.Index_Non_Blank
  73.                                                      (Man)..Man'Last),
  74.                                                " " )+1..Fixed.Index_Non_Blank(Man, Backward));              
  75.            begin
  76.               if Fixed.Index(Line(Fixed.Index_Non_Blank(Line)..Line'Last), " " ) /= 0 and then
  77.                 Fixed.Index_Non_Blank(Line, Backward) /=
  78.                 Fixed.Index(Line(Fixed.Index_Non_Blank(Line)..Line'Last), " " ) then
  79.                  begin
  80.                     declare                        
  81.                        Section : constant String := Line(Line'First..Line'First);
  82.                        
  83.                        Manual : constant String := "/usr/share/man/man" &
  84.                           Section & '/' & line(Fixed.Index
  85.                                                  (Line, " ", Backward)+1..Fixed.Index_Non_Blank(line, Backward)) & '.' & Section & ".gz";
  86.                     begin
  87.                        Man_Line := New String ' ("man -l -t -Tlatin1 -Eutf8 " & Manual);
  88.                     end;
  89.                  end;
  90.               else
  91.                  return "";
  92.               end if;
  93.            end;
  94.         end;              
  95.      else
  96.         return "";
  97.      end if;
  98.      return Man_Line.all;
  99.   end Parse_Man_Command;
  100.  
  101.  
  102.  
  103.   -------------------------------------------------------------------------
  104.   -- To Call "man" command by spawn.                                     --
  105.   -------------------------------------------------------------------------
  106.   subtype U_String is Ada.Strings.Unbounded.Unbounded_String;
  107.   use type U_String;
  108.  
  109.   function "+"(S: String) return U_String
  110.     renames Ada.Strings.Unbounded.To_Unbounded_String;
  111.  
  112.   function "-"(U: U_String) return String
  113.     renames Ada.Strings.Unbounded.To_String;
  114.  
  115.   type Variadic_Array is array(Positive range <> ) of U_String;
  116.  
  117.   type Variadic_Access is access Variadic_Array;
  118.  
  119.   type Spawn_Result_Type is
  120.      record
  121.      Process_Id     : Gnat.Os_Lib.Process_Id;
  122.      Program_Name   : U_String;
  123.      Args           : Os_Lib.Argument_List_Access;    
  124.      Output_File    : U_String;
  125.      Success        : Boolean := False;
  126.      Return_Code    : Integer := 0;
  127.      Err_To_Out     : Boolean := False;
  128.      File_Content   : Variadic_Access;
  129.      end record;
  130.  
  131.  
  132.  
  133.   use Os_Lib;
  134.   use type U_String;
  135.  
  136.   function Spawn(Line : in String) return Spawn_Result_Type is
  137.      
  138.      Command : Gnat.Command_Line.Command_Line;
  139.            
  140.      Spawn_Result : Spawn_Result_Type;
  141.             
  142.      Buffer_args, Arguments_List : Os_Lib.Argument_List_Access;                  
  143.      
  144.      File : Text_Io.File_Type;      
  145.      Deleted : Boolean := False;
  146.      
  147.      Exec_Path : Os_Lib.String_Access;
  148.      
  149.   begin
  150.      
  151.      Set_Command_Line(Command, Line);
  152.      
  153.      Gnat.Command_Line.Build(Command, Arguments_List, True);
  154.      
  155.      if Arguments_List(1) /= null and then Arguments_List(1).all /= "" then
  156.        
  157.        
  158.         if Arguments_List'length > 1 then
  159.            
  160.            Buffer_Args := new Argument_List(1..Arguments_List'Last - 1);
  161.            
  162.            for I in 1..Arguments_List'Last - 1 loop
  163.               Buffer_Args(I) := new String ' (Arguments_List(I+1).all);
  164.            end loop;            
  165.            
  166.            Spawn_Result := (
  167.                             Process_Id   => Invalid_Pid,              
  168.                             Program_Name => +Arguments_List(1).all,
  169.                             Args          => Buffer_Args,
  170.                             Output_File  => +"out_file.txt",
  171.                             Success      => False,
  172.                             Return_Code  => 0,
  173.                             Err_To_Out   => True,
  174.                             File_content => null                
  175.                            );
  176.            
  177.            
  178.            
  179.            
  180.         else
  181.            
  182.            
  183.            Spawn_Result := (
  184.                             Process_Id   => Invalid_Pid,                            
  185.                             Program_Name => +Arguments_List(1).all,
  186.                             Args          => new Argument_List  ' (1..0 => new String ' ("" & Character'Val(0))),
  187.                             Output_File  => +"out_file.txt",
  188.                             Success      => False,
  189.                             Return_Code  => 0,
  190.                             Err_To_Out   => True,
  191.                             File_content => null
  192.                              
  193.                            );
  194.         end if;
  195.        
  196.        
  197.        
  198.         if Locate_Exec_On_Path(Arguments_List(1).all) /= null then
  199.            Exec_Path := new String ' (Locate_Exec_On_Path(Arguments_List(1).all).all);        
  200.                              
  201.            
  202.            if Is_Executable_File(Exec_Path.all) then
  203.              
  204.              
  205.               Os_Lib.Normalize_Arguments(Arguments_List.all);
  206.              
  207.              
  208.               Spawn_Result.Process_Id :=
  209.                 Non_Blocking_Spawn(Program_Name => Exec_Path.all,
  210.                                    Args         => Spawn_Result.Args.all,                          
  211.                                    Output_File  => (-Spawn_Result.Output_File),
  212.                                    Err_To_Out   => Spawn_Result.Err_To_out
  213.                                   );
  214.              
  215.               if Spawn_Result.Process_Id /= Gnat.Os_Lib.Invalid_Pid then
  216.                  
  217.                  Gnat.Os_Lib.Wait_Process(Spawn_Result.Process_Id, Spawn_Result.Success);
  218.                  
  219.               end if;
  220.              
  221.              
  222.               Spawn_Result.File_Content := new Variadic_Array(1..1);
  223.              
  224.               Text_Io.Open(File, Text_Io.In_File, (-Spawn_Result.Output_File));
  225.  
  226.               while not Text_Io.End_Of_File(File) loop
  227.  
  228.                  declare
  229.                    
  230.                     Line : constant String := Text_Io.Get_Line(File);
  231.                     Buffer : Variadic_Array(1..Spawn_Result.File_Content'Length+1);
  232.                  begin
  233.  
  234.                     if Spawn_Result.File_Content /= null then
  235.                        
  236.                        Buffer(Buffer'First..Buffer'Last-1) := Spawn_Result.File_Content.all;
  237.  
  238.                     end if;
  239.                    
  240.                     Buffer(Buffer'Last) := (+Line);
  241.  
  242.                     Spawn_Result.File_Content := new Variadic_Array ' (Buffer);
  243.                  end;
  244.                  
  245.               end loop;
  246.              
  247.               Text_Io.Close(File);    
  248.               Delete_File (Name => (-Spawn_Result.Output_File), Success => deleted);
  249.              
  250.               if not Spawn_Result.Success then      
  251.                  Spawn_Result.Return_Code := Gnat.Os_Lib.Errno;
  252.               end if;
  253.            else
  254.               Spawn_Result.File_Content := new Variadic_Array ' (1 => (+(Arguments_List(1).all & " : command not found." )));              
  255.               Spawn_Result.Return_Code := 127;
  256.            end if;
  257.         else            
  258.            Spawn_Result.File_Content := new Variadic_Array ' (1 => (+(Arguments_List(1).all & " : command not found." )));              
  259.            Spawn_Result.Return_Code := 127;
  260.         end if;        
  261.      else        
  262.         Spawn_Result.File_Content := new Variadic_Array ' (1 => (+(Arguments_List(1).all & " : command not found." )));                        
  263.         Spawn_Result.Return_Code := 127;
  264.      end if;
  265.      
  266.      return Spawn_Result;
  267.   end Spawn;    
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.   -------------------------------------------------------------------------
  275.   -- Window [just dialog]                                                --
  276.   -------------------------------------------------------------------------
  277.      procedure Insert_With_Tag
  278.     (Buffer : access Gtk_Text_Buffer_Record'Class;
  279.      Tag    : String;
  280.      Text   : String)
  281.   is
  282.      T : Gtk_Text_Tag;
  283.      Iter, Start_Iter : Gtk_Text_Iter;
  284.      Table : Gtk_Text_Tag_Table;
  285.      Result : Boolean;
  286.      pragma Warnings (Off, Result);
  287.   begin
  288.      Get_End_Iter (Buffer, Iter);
  289.  
  290.      if Tag = "" then
  291.         Insert (Buffer, Iter, Text & ASCII.LF);
  292.  
  293.      else
  294.         Table := Get_Tag_Table (Buffer);
  295.         T := Lookup (Table, Tag);
  296.        
  297.         Insert (Buffer, Iter, Text & ASCII.LF);
  298.         Copy (Source => Iter, Dest => Start_Iter);
  299.         Backward_Chars (Start_Iter, Text'Length + 1, Result);
  300.         Apply_Tag (Buffer, T, Start_Iter, Iter);
  301.      end if;
  302.   end Insert_With_Tag;
  303.  
  304.      
  305.  
  306.    
  307.   Page_Frame : Gtk_Frame;    
  308.   Buffer   : Gtk_Text_Buffer;
  309.   Tags     : Gtk_Text_Tag_Table;
  310.   Tag      : Gtk_Text_Tag;
  311.   View     : Gtk_Text_View;
  312.   Scrolled : Gtk_Scrolled_Window;          
  313.  
  314.   Man_Dialog : Gtk.Dialog.Gtk_Dialog;
  315.  
  316.  
  317.  
  318.   Link      : constant String := "/usr/share/man/man1/ls.1.gz";
  319.   Extension : constant String := File_Extension(Base_Name(Link, ".gz" ));
  320.   Section   : constant String := Extension(Extension'Last..Extension'Last);
  321.  
  322.   Spawn_Result : Spawn_Result_Type := Spawn(Parse_Man_Command("man " & section & ' ' & Base_Name(Link, '.' & Section & ".gz" )));
  323.   Response : Gtk_Response_Type;
  324.   Vbox     : Gtk_Vbox;
  325.   Widget   : Gtk_Widget;
  326. begin      
  327.   Gtk.Main.Init;
  328.   Text_Io.Put_Line ("Link_Button clicked: " & Link);
  329.  
  330.   Gtk_New (Tags);
  331.   Gtk_New (Buffer, Tags);
  332.   Gtk_New (View, Buffer);
  333.  
  334.  
  335.   Gtk_New(Page_Frame);
  336.   Set_Label (Page_Frame, Link);
  337.      
  338.  
  339.   Gtk.Dialog.Gtk_New(Man_Dialog, Link, null, No_separator);            
  340.   Gtk.Window.Set_Default_Size(Gtk_Window(Man_Dialog), 640, 400);
  341.  
  342.   if Spawn_Result.File_Content /= null then
  343.  Print_Loop:
  344.      for I in 1..Spawn_Result.File_Content'Length loop
  345.         declare
  346.            Line : constant String := (-Spawn_Result.File_Content(I));
  347.            
  348.         begin
  349.            if Line'Length > 0 then
  350.               Insert_With_Tag
  351.                 (Buffer, "", Line);
  352.            else
  353.               Insert_With_Tag
  354.                 (Buffer, "", "" );
  355.            end if;                          
  356.         end;
  357.      end loop Print_Loop;
  358.   else
  359.      Insert_With_Tag
  360.        (Buffer, "", "Spawn failure or Empry file." );
  361.   end if;
  362.  
  363.   Gtk_New (Scrolled);      
  364.   Set_Policy (Scrolled, Policy_Always, Policy_Always);      
  365.   Add (Scrolled, View);
  366.   Show_All (Scrolled);
  367.   Add (Page_Frame, Scrolled);      
  368.   Vbox := Get_Vbox(Man_Dialog);            
  369.   Pack_Start(vbox, Page_Frame, True, True);      
  370.   Show_All(Vbox);
  371.   Widget := Add_Button(Man_Dialog, "Close", Gtk_Response_Close);
  372.   Response := Run(Man_Dialog);  
  373.   Destroy(Man_Dialog);        
  374.   Gtk.Main.Main;
  375. end Manpages_To_Gtkada;


Ding  :pt1cable:  
 
J'ai fait toutes les combinaisons que j'avais potentiellement fait et j'ai pas retrouvé.
 
J'ai fait ou refait méticuleusement toutes les combinaisons, toujours les caractères carrés intercalés.
 
Là ?  :heink:  
 
edit :


Message édité par par l'anneau de l'ia le 07-02-2015 à 06:29:13
n°2250301
par l'anne​au de l'ia
word master
Posté le 07-02-2015 à 10:30:38  profilanswer
 

L'option -P avec cat en paramètre suffis.  :bounce:


---------------
Toute expression prend un sens spirituel qui nous influence dans notre quête de l'Homme.

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Ada

  [Res]Problème d'encodage sous fvwm des pages de manuels Gnu/Linux.

 

Sujets relatifs
Probleme preg_replace_callbackHTML/CSS Probleme de format Besoin d'aide !!!
[Curl] problème d'interprétation des quotes[Résolu] Problème Index.html quand hébergé
Probleme connexion yahoo CSS[PHP] [Curl] Problème avec les espaces
Problème police d'écriture PC/téléphoneExtraction VBA de données depuis pages HTML
Jeu de plateforme AS3 (problème de passage de niveau)Problème du voisin le plus proche sur R
Plus de sujets relatifs à : [Res]Problème d'encodage sous fvwm des pages de manuels Gnu/Linux.


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR