Flype - UserLibraries pour PureBasic 4.0

Vous avez développé un logiciel en PureBasic et vous souhaitez le faire connaitre ?
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

j'en prends note :wink:
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Update - PureXML2 Beta1.

Réécriture complète de PureXML pour PureBasic 4.02.

Il n'y a plus besoin de DLL mais en contre-partie la taille de l'exe
augmente d'une 100aine de Ko (ce qui reste très raisonnable).

Cette version est en Beta jusqu'à ce que ce soit prêt.

J'attends donc vos tests... et les questions.
Dernière modification par Flype le lun. 15/janv./2007 16:27, modifié 4 fois.
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Update - PureXML2 Beta2.

Quelques bugs corrigés + ajouts de fonctions.
Dernière modification par Flype le lun. 15/janv./2007 16:26, modifié 1 fois.
Image
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Merci Flype, je vais te beta tester dans une de mes libs en cours de réalisation, utilisant prou le XML !
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Update - PureXML2 Beta3.

UserLib_PB402_PureXML_V2_BETA.zip (207 Ko)

Beaucoup de changements :
Syntaxe des fonctions remaniées, Ajout de fonctions, Optimisation.

Attention, pas de support Multithread/Unicode pour le moment.
Ce sera la prochaine étape... ainsi que le CHM.

Code : Tout sélectionner

_______________________________________________________________________________________________________________

Title:    PureXML2 BETA 
Version:  2.0 Beta3 (15-Jan-2007 01:36)
License:  Free to use, greetings are welcome.

Author:   Written by Flype, flype44(at)gmail.com.

Target:   UserLibrary designed for PureBasic 4.02
OS:       Microsoft Windows (Only tested on Windows XP SP2).

Descript: PureXML is a event-based XML parser, based on Expat 2.0.0.
          No more DLL required - Small footprint (about 100Kb) !

Download: http://purebasic.myftp.org/?filename=files/44/PB4_UserLibs/UserLib_PB402_PureXML_V2_BETA.zip

_______________________________________________________________________________________________________________

List of functions :

PureXML_GetEngine()              ; Retrieves the version of the internal XML engine.
PureXML_GetVersion()             ; Retrieves the version of the PureXML UserLibrary.

PureXML_GetErrorString()         ; Returns the error that has occurred as string.
PureXML_GetErrorCode()           ; Returns the error that has occurred as errorcode.

PureXML_GetAttr(name.s)          ; Returns the attribute value (by name).
PureXML_GetAttrCount()           ; Returns the number of attributes.
PureXML_GetAttrName(index.l)     ; Returns the attribute name (by index).
PureXML_GetAttrValue(index.l)    ; Returns the attribute value (by index).

PureXML_GetBuffer()              ; Returns the internal buffer string of the current parsing.
PureXML_GetColumn()              ; Returns the column number of the current parsing position.
PureXML_GetDepth()               ; Returns the tag's depth of the current parsing position.
PureXML_GetLine()                ; Returns the line number of the current parsing position.
PureXML_GetPosition()            ; Returns the byte-offset of the current parsing position.

PureXML_GetBase()                ; Returns the base for resolving relative URLs.
PureXML_GetCDATA()               ; Returns the CDATA Section of the current element.
PureXML_GetCharData()            ; Returns the characters data of the current element.
PureXML_GetName()                ; Returns the name of the current element.
PureXML_GetPath()                ; Retrieves the path of the current element.
PureXML_GetStatus()              ; Returns the parsing status between 0, 1, 2, 3.

PureXML_SetBase(base.s)          ; Specify the base to be used for resolving relative URLs. 
PureXML_SetEncoding(encoding.s)  ; Specify the encoding type between US-ASCII, UTF-8, UTF-16, ISO-8859-1.

PureXML_ParseFile(fileName.s)    ; Parse a XML document.
PureXML_ParseString(xmlString.s) ; Parse a XML string.
PureXML_ParseUrl(url.s)          ; Parse a XML url.
PureXML_ParseResume()            ; Resumes the current parsing, if suspended with PureXML_Stop(#True). 
PureXML_ParseStop([resumable.l]) ; Stops the current parsing.

_______________________________________________________________________________________________________________

List of PureXML Handlers :

PureXML_SetAttributeHandler(*hProcedure)                   ; PureXML Handler: Attribute (name, value) of an element.
PureXML_SetCDataSectionHandler(*hProcedure1, *hProcedure2) ; PureXML Handler: Start and End of a CDATA Section.
PureXML_SetCharacterDataHandler(*hProcedure)               ; PureXML Handler: Characters data between two elements.
PureXML_SetCloseHandler(*hProcedure)                       ; PureXML Handler: End of an element.
PureXML_SetCommentHandler(*hProcedure)                     ; PureXML Handler: Comments.
PureXML_SetDefaultHandler(*hProcedure)                     ; PureXML Handler: Default.
PureXML_SetElementHandler(*hProcedure1, *hProcedure2)      ; PureXML Handler: Start and End of an element.
PureXML_SetEndCDataSectionHandler(*hProcedure)             ; PureXML Handler: End of a CDATA Section.
PureXML_SetOpenHandler(*hProcedure)                        ; PureXML Handler: Start of an element.
PureXML_SetStartCDataSectionHandler(*hProcedure)           ; PureXML Handler: Start of a CDATA Section.
PureXML_SetXmlHandler(*hProcedure)                         ; PureXML Handler: Xml Declaration.

_______________________________________________________________________________________________________________

PureXML Handlers syntax :

Procedure myAttribute(name.s, attrName.s, attrValue.s)
EndProcedure

Procedure myCharacterData(name.s, string.s, length.l)
EndProcedure

Procedure myComment(name.s, string.s, length.l)
EndProcedure

Procedure myDefault(name.s, string.s, length.l)
EndProcedure

Procedure myEndElement(name.s, depth.l)
EndProcedure

Procedure myEndCDataSection(name.s, string.s, length.l, position.l)
EndProcedure

Procedure myStartCDataSection(name.s, position.l)
EndProcedure

Procedure myStartElement(name.s, depth.l)
EndProcedure

Procedure myXml(xml_version.s, xml_encoding.s)
EndProcedure

_______________________________________________________________________________________________________________

Best Regards, flype 2007.
Dernière modification par Flype le lun. 15/janv./2007 16:27, modifié 4 fois.
Image
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Flype, pourquoi ne pas définir un ErrorHandler, ainsi l'user expérimenté pourrait définir ce qu'il doit faire en fonction de l'erreur (pause, stop, modif de la chaine, etc...)
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Je sais, je voudrais bien progi mais je ne peux pas.

J'aimerais aussi implémenter un ErrorHandler() mais je dépends complètement de lib xml utilisée pour compiler PureXML.

Et manque de chance la lib en question n'a pas de ErrorHandler,
tout simplement parce que le XML est un langage strict qui n'autorise aucune faute de syntaxe, c'est comme çà, la norme XML est ainsi faite !

J'essaye quand même de voir ce que je peux faire mais c'est pas gagné....
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Voici un petit exemple pour commencer avec PureXML2.

Cet exemple montre comment récupérer très facilement des informations partielles depuis un document XML distant (URL)
en utilisant les fonctions ParseUrl() et le handler (callback) CharacterData.

Code : Tout sélectionner

Global result$

Procedure.l Extract_From_IpPages(name.s, string.s, length.l)
  
  Select name ; tag name
    Case "ip":      result$ + "IP V4: " + #TAB$ + string + #CRLF$
    Case "ip_long": result$ + "IP: "    + #TAB$ + string + #CRLF$
    Case "ipv6":    result$ + "IP V6: " + #TAB$ + string + #CRLF$
    Case "host":    result$ + "HOST: "  + #TAB$ + string + #CRLF$
    Case "isp":     result$ + "ISP: "   + #TAB$ + string + #CRLF$
    Case "country": result$ + "CTRY: "  + #TAB$ + string + #CRLF$
  EndSelect
  
EndProcedure

If MessageRequester("Question", "Resolves your IP Address from `ippages.com` ?", #MB_OKCANCEL|#MB_ICONQUESTION) = #IDOK
  
  PureXML_SetCharacterDataHandler(@Extract_From_IpPages())
  
  If PureXML_ParseUrl("http://www.ippages.com/xml/")
    
    If MessageRequester("Copy the result to the clipboard ?", result$, #MB_OKCANCEL|#MB_ICONINFORMATION) = #IDOK
      
      SetClipboardText(result$)
      
    EndIf
    
  Else
    
    MessageRequester("Error", PureXML_GetErrorString(), #MB_ICONERROR)
    
  EndIf
  
EndIf
Image
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

Un autre exemple qui montre comment ajouter tous les produits du document XML dans une liste chainée - pour ensuite traiter les données de facon plus classique :

xml$ + "<?xml version='1.0'?>"
xml$ + "<products>"
xml$ + " <product id='PROD007'>"
xml$ + " <name>gizmo</name>"
xml$ + " <price>50</price>"
xml$ + " <desc>for geeks</desc>"
xml$ + " </product>"
xml$ + " <product id='PROD008'>"
xml$ + " <name>gadget</name>"
xml$ + " <price>10</price>"
xml$ + " <desc>for programmers</desc>"
xml$ + " </product>"
xml$ + " <product id='PROD009'>"
xml$ + " <name>utility</name>"
xml$ + " <price>99</price>"
xml$ + " <desc></desc>"
xml$ + " </product>"
xml$ + "</products>"

Code : Tout sélectionner

Structure PRODUCT
  id.s
  name.s
  price.s
  desc.s
EndStructure

Global NewList product.PRODUCT()

Procedure ProductInfo_StartElement(name.s, depth.l)
  
  If name = "product"
    If AddElement(product())
      product()\id = PureXML_GetAttr("id")
    EndIf
  EndIf
  
EndProcedure

Procedure ProductInfo_EndElement(name.s, depth.l)
  
  Select name
    Case "name":  product()\name  = PureXML_GetCharData()
    Case "price": product()\price = PureXML_GetCharData()
    Case "desc":  product()\desc  = PureXML_GetCharData()
  EndSelect
  
EndProcedure

PureXML_SetElementHandler(@ProductInfo_StartElement(), @ProductInfo_EndElement())

If PureXML_ParseString(xml$) 
  ForEach product()
    Debug "id = "    + product()\id
    Debug "name = "  + product()\name
    Debug "price = " + product()\price
    Debug "desc = "  + product()\desc
    Debug ""
  Next
EndIf
Image
linkerstorm
Messages : 20
Inscription : lun. 29/janv./2007 7:13

Message par linkerstorm »

Merci pour toutes ces bib FLype ! :)

Elles vont vraiment me servir... Surtout pour l'instant le parser XML V2 beta.

:wink:
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

sers-toi elles sont là pour çà :)

et bienvenu sur le forum.
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Bonjour Flype, je suis en train d'utiliser ton Inlcude file pour Firebird :

Include file for use with FireBird 2.0 (181 Ko)

Mais j'ai quelques questions à te poser :
- Quand je lance l'exemple, aucun fichier fdb n'est créé ! Normal ?
- Où as tu eu la doc sur les différentes procédures de la DLL ? Car moults recherches ne m'ont rien apporté.
Avatar de l’utilisateur
Flype
Messages : 2431
Inscription : jeu. 29/janv./2004 0:26
Localisation : Nantes

Message par Flype »

ca m'énerve, j'arrive pas à me souvenir comment j'ai fait.
probablement, depuis le fichier .h et les examples, fournis avec l'archive téléchargeable de firebird.

je te mets ici le dossier de travail qui me servait pour mes quelques tests (soit trois fois rien mais bon) ~750Ko :

File:1->FireBirdSrc.zip
Image
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Nickel ! Merci !

J'ai trouvé la doc pour toutes les fonctions de l'API Firebird :

http://www.ibphoenix.com/main.nfs?a=ibp ... umentation
et téléchargez : InterBase 6.0 API Guide (pdf) (zip) (1.69mb)
ou
le lien direct : http://www.ibphoenix.com/downloads/60ApiGuide.zip
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Message par Progi1984 »

Etant un fan de tes outils, je viens de m'initier à LinkedListEx, mais deux petites fonctions me manquent :

ListIndex (Ex)
InsertElement (Ex)
Répondre