G:/ScriptBasic/source/extensions/xml/interface.c

Go to the documentation of this file.
00001 /*
00002   FILE   : interface.c
00003   HEADER : interface.h
00004   BAS    : xml.bas
00005   AUTHOR : *TODO*
00006 
00007   DATE: 
00008 
00009   CONTENT:
00010   This is the interface.c file for the ScriptBasic module xml
00011 
00012 NTLIBS: /link /NODEFAULTLIB:"libcmt.lib" libxml2_a.lib iconv_a.lib ws2_32.lib
00013 UXLIBS: -lxml2
00014 */
00015 
00016 #include <stdio.h>
00017 #include "../../basext.h"
00018 
00019 #include <libxml/parser.h>
00020 
00021 /*
00022 *TODO*
00023 INSERT THE BASIC CODE THAT WILL GET INTO THE FILE xml.BAS
00024 AFTER THE LINE 'TO_BAS:' AND BEFORE THE LINE END OF THE COMMENT
00025 
00026 NOTE THAT SUB AND COMMAND DECLARATIONS ARE CREATED AUTOMATICALLY
00027 FROM THE FUNCTION DEFINTIONS WHEN THE MODULE IS CONFIGURED BEFORE
00028 COMPILATION
00029 
00030 TO_BAS:
00031 REM """
00032 The module xml.bas is based on the Gnome libxml2 library.
00033 """
00034 */
00035 
00036 typedef struct _ModuleObject {
00037   void *HandleArray;
00038   }ModuleObject,*pModuleObject;
00039 
00040 
00041 #define GET_ARGUMENT_POINTER(X,Y) \
00042   if( besARGNR < Y )return COMMAND_ERROR_ARGUMENT_RANGE;\
00043   Argument = besARGUMENT(Y);\
00044   besDEREFERENCE(Argument);\
00045   if( Argument == NULL )X=NULL; else { \
00046       if( Argument->vType != VTYPE_STRING ||\
00047           STRLEN(Argument) != sizeof(void *) ){\
00048     return COMMAND_ERROR_ARGUMENT_RANGE;\
00049     }\
00050   memcpy(&(X),STRINGVALUE(Argument),sizeof(void *));\
00051   }
00052 
00053 #define RETURN_POINTER(X) \
00054    besALLOC_RETURN_STRING( sizeof( void *) );\
00055    memcpy(STRINGVALUE(besRETURNVALUE),&(X),sizeof(void *));
00056 
00057 /*
00058 *TODO*
00059 ALTER THE VERSION NEGOTIATION CODE IF YOU NEED
00060 */
00061 besVERSION_NEGOTIATE
00062   return (int)INTERFACE_VERSION;
00063 besEND
00064 
00065 /*
00066 *TODO*
00067 ALTER THE ERROR MESSAGE FUNCTION
00068 */
00069 besSUB_ERRMSG
00070 
00071   switch( iError ){
00072     case 0x00080000: return "ERROR HAS HAPPENED";
00073     }
00074   return "Unknown xml module error.";
00075 besEND
00076 
00077 /*
00078 *TODO*
00079 ALTER THE MODULE INITIALIZATION CODE
00080 */
00081 besSUB_START
00082   pModuleObject p;
00083 
00084   besMODULEPOINTER = besALLOC(sizeof(ModuleObject));
00085   if( besMODULEPOINTER == NULL )return 0;
00086 
00087   p = (pModuleObject)besMODULEPOINTER;
00088   return 0;
00089 besEND
00090 
00091 /*
00092 *TODO*
00093 ALTER THE MODULE FINISH CODE IF NEEDED
00094 */
00095 besSUB_FINISH
00096   pModuleObject p;
00097 
00098   p = (pModuleObject)besMODULEPOINTER;
00099   if( p == NULL )return 0;
00100   return 0;
00101 besEND
00102 
00117 besFUNCTION(sbxmlParseFile)
00118   xmlDocPtr doc;
00119   char *pszFileName;
00120 
00121   besARGUMENTS("z")
00122     &pszFileName
00123   besARGEND
00124 
00125   doc = xmlParseFile(pszFileName);
00126   besFREE(pszFileName);
00127 
00128   besRETURN_POINTER(doc);
00129 besEND
00130 
00141 besFUNCTION(sbxmlNewDoc)
00142   xmlDocPtr doc;
00143   char *pszVersion;
00144 
00145   besARGUMENTS("z")
00146     &pszVersion
00147   besARGEND
00148 
00149   doc = xmlNewDoc(pszVersion);
00150 
00151   besFREE(pszVersion);
00152 
00153   besRETURN_POINTER(doc);
00154 besEND
00155 
00168 besFUNCTION(sbxmlFreeDoc)
00169   xmlDocPtr doc;
00170 
00171   besARGUMENTS("p")
00172     &doc
00173   besARGEND
00174 
00175   xmlFreeDoc(doc);
00176 besEND
00177 
00185 besFUNCTION(getchildren)
00186   xmlDocPtr doc;
00187 
00188   besARGUMENTS("p")
00189     &doc
00190   besARGEND
00191 
00192   besRETURN_POINTER(doc->children);
00193 besEND
00194 
00202 besFUNCTION(setchildren)
00203   xmlDocPtr doc;
00204   xmlNodePtr child;
00205 
00206   besARGUMENTS("pp")
00207     &doc , &child
00208   besARGEND
00209   doc->children = child;
00210 besEND
00211 
00219 besFUNCTION(getnext)
00220   xmlDocPtr doc;
00221 
00222   besARGUMENTS("p")
00223     &doc
00224   besARGEND
00225 
00226   besRETURN_POINTER(doc->next);
00227 besEND
00228 
00236 besFUNCTION(setnext)
00237   xmlDocPtr doc;
00238   xmlNodePtr nxt;
00239 
00240   besARGUMENTS("pp")
00241     &doc , &nxt
00242   besARGEND
00243   doc->next = nxt;
00244 besEND
00245 
00253 besFUNCTION(getprev)
00254   xmlDocPtr doc;
00255 
00256   besARGUMENTS("p")
00257     &doc
00258   besARGEND
00259 
00260   besRETURN_POINTER(doc->prev);
00261 besEND
00262 
00270 besFUNCTION(setprev)
00271   xmlDocPtr doc;
00272   xmlNodePtr prv;
00273 
00274   besARGUMENTS("pp")
00275     &doc , &prv
00276   besARGEND
00277   doc->prev = prv;
00278 besEND
00279 
00287 besFUNCTION(getparent)
00288   xmlDocPtr doc;
00289 
00290   besARGUMENTS("p")
00291     &doc
00292   besARGEND
00293 
00294   besRETURN_POINTER(doc->parent);
00295 besEND
00296 
00304 besFUNCTION(setparent)
00305   xmlDocPtr doc;
00306   xmlNodePtr par;
00307 
00308   besARGUMENTS("pp")
00309     &doc , &par
00310   besARGEND
00311   doc->parent = par;
00312 besEND
00313 
00318 besFUNCTION(sbxmlSetProp)
00319   xmlNodePtr node;
00320   char *pszName, *pszValue;
00321 
00322 
00323   besARGUMENTS("pzz")
00324     &node, &pszName , &pszValue
00325   besARGEND
00326 
00327   xmlSetProp(node,pszName,pszValue);
00328 
00329   besFREE(pszName);
00330   besFREE(pszValue);
00331 besEND
00332 
00338 besFUNCTION(sbxmlGetProp)
00339   xmlNodePtr node;
00340   char *pszName;
00341   char *pszValue;
00342 
00343   besARGUMENTS("pz")
00344     &node, &pszName
00345   besARGEND
00346 
00347   pszValue = xmlGetProp(node,pszName);
00348   besSET_RETURN_STRING( pszValue );
00349   if( pszValue )xmlMemFree(pszValue);
00350 besEND
00351 
00362 besFUNCTION(sbxmlNewNs)
00363   xmlNodePtr node;
00364   xmlChar *href;
00365   xmlChar *prefix;
00366   xmlNsPtr ns;
00367 
00368   besARGUMENTS("pzz")
00369     &node , &href , &prefix
00370   besARGEND
00371 
00372   ns = xmlNewNs(node,href,prefix);
00373 
00374   besFREE(href);
00375   besFREE(prefix);
00376   besRETURN_POINTER(ns);
00377 besEND
00378 
00391 besFUNCTION(sbxmlFreeNs)
00392   xmlNsPtr ns;
00393 
00394   besARGUMENTS("p")
00395     &ns
00396   besARGEND
00397 
00398   xmlFreeNs(ns);
00399 besEND
00400 
00421 besFUNCTION(sbxmlNewChild)
00422   xmlNodePtr node;
00423   xmlNsPtr ns;
00424   xmlChar *name;
00425   xmlChar *content;
00426 
00427   besARGUMENTS("p[p]z[z]")
00428     &node , &ns , &name , &content
00429   besARGEND
00430 
00431   node = xmlNewChild(node,ns,name,content);
00432 
00433   besFREE(name);
00434   besFREE(content);
00435 
00436   besRETURN_POINTER(node);
00437 besEND
00438 
00459 besFUNCTION(sbxmlNewTextChild)
00460   xmlNodePtr node;
00461   xmlNsPtr ns;
00462   xmlChar *name;
00463   xmlChar *content;
00464 
00465   besARGUMENTS("p[p]z[z]")
00466     &node , &ns , &name , &content
00467   besARGEND
00468 
00469   node = xmlNewTextChild(node,ns,name,content);
00470 
00471   besFREE(name);
00472   besFREE(content);
00473 
00474   besRETURN_POINTER(node);
00475 besEND
00476 
00497 besFUNCTION(sbxmlNewDocNode)
00498   xmlDocPtr doc;
00499   xmlNodePtr node;
00500   xmlNsPtr ns;
00501   xmlChar *name;
00502   xmlChar *content;
00503 
00504   besARGUMENTS("p[p]z[z]")
00505     &doc , &ns , &name , &content
00506   besARGEND
00507 
00508   node = xmlNewDocNode(doc,ns,name,content);
00509 
00510   besFREE(name);
00511   besFREE(content);
00512 
00513   besRETURN_POINTER(node);
00514 besEND
00519 besFUNCTION(sbxmlDocDumpMemory)
00520   VARIABLE Argument;
00521   xmlDocPtr p;
00522   xmlChar *mem;
00523   int size;
00524 
00525   GET_ARGUMENT_POINTER(p,1);
00526   xmlDocDumpMemory(p,&mem,&size);
00527   besALLOC_RETURN_STRING(size);
00528   memcpy(STRINGVALUE(besRETURNVALUE),mem,size);
00529 
00530 besEND
00531 
00532 /*
00533 *TODO*
00534 INSERT HERE THE NAME OF THE FUNCTION AND THE FUNCTION INTO THE
00535 TABLE. THIS TABLE IS USED TO FIND THE FUNCTIONS WHEN THE MODULE
00536 INTERFACE FILE IS COMPILED TO BE LINKED STATIC INTO A VARIATION
00537 OF THE INTERPRETER.
00538 */
00539 
00540 SLFST XML_SLFST[] ={
00541 
00542 { "versmodu" , versmodu },
00543 { "bootmodu" , bootmodu },
00544 { "finimodu" , finimodu },
00545 { "emsgmodu" , emsgmodu },
00546 { "sbxmlParseFile"     , sbxmlParseFile     },
00547 { "sbxmlNewDoc"        , sbxmlNewDoc        },
00548 { "sbxmlFreeDoc"       , sbxmlFreeDoc       },
00549 { "sbxmlNewNs"         , sbxmlNewNs         },
00550 { "sbxmlFreeNs"        , sbxmlFreeNs        },
00551 { "getchildren"        , getchildren        },
00552 { "setchildren"        , setchildren        },
00553 { "getnext"            , getnext            },
00554 { "setnext"            , setnext            },
00555 { "getprev"            , getprev            },
00556 { "setprev"            , setprev            },
00557 { "sbxmlSetProp"       , sbxmlSetProp       },
00558 { "sbxmlNewChild"      , sbxmlNewChild      },
00559 { "sbxmlNewTextChild"  , sbxmlNewTextChild  },
00560 { "sbxmlNewDocNode"    , sbxmlNewDocNode    },
00561 { "sbxmlDocDumpMemory" , sbxmlDocDumpMemory },
00562 { NULL , NULL }
00563   };

Generated on Sun Mar 12 23:56:29 2006 for ScriptBasic by  doxygen 1.4.6-NO