]> git.mxchange.org Git - flightgear.git/blobdiff - utils/xmlgrep/xml.h
Another gitignore
[flightgear.git] / utils / xmlgrep / xml.h
index b02296554dfc1ed50aa0f6a5775b596d06c2b0f1..7431b4b5b03e47821c02176090a5addb5f5867b6 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (c) 2007, 2008 by Adalin B.V.
- * Copyright (c) 2007, 2008 by Erik Hofman
+/* Copyright (c) 2007-2009 by Adalin B.V.
+ * Copyright (c) 2007-2009 by Erik Hofman
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #ifndef __XML_CONFIG
 #define __XML_CONFIG 1
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#undef XML_NONVALIDATING
+
+#ifdef XML_USE_NODECACHE
+#include "xml_cache.h"
+#else
+void *cacheGet(void *);
+#endif
+
+enum
+{
+    XML_NO_ERROR = 0,
+    XML_OUT_OF_MEMORY,
+    XML_FILE_NOT_FOUND,
+    XML_INVALID_NODE_NAME,
+    XML_UNEXPECTED_EOF,
+    XML_TRUNCATE_RESULT,
+    XML_INVALID_COMMENT,
+    XML_INVALID_INFO_BLOCK,
+    XML_ELEMENT_NO_OPENING_TAG,
+    XML_ELEMENT_NO_CLOSING_TAG,
+    XML_ATTRIB_NO_OPENING_QUOTE,
+    XML_ATTRIB_NO_CLOSING_QUOTE,
+    XML_MAX_ERROR
+};
+
+#ifdef WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+
+typedef struct
+{
+    HANDLE m;
+    void *p;
+} SIMPLE_UNMMAP;
+#endif
+
+#ifndef XML_NONVALIDATING
+struct _xml_error
+{
+    char *pos;
+    int err_no;
+};
+#endif
+
+/*
+ * It is required for both the rood node and the normal xml nodes to both
+ * have 'char *name' defined as the first entry. The code tests whether
+ * name == 0 to detect the root node.
+ */
+struct _root_id
+{
+    char *name;
+    char *start;
+    size_t len;
+    int fd;
+#ifdef XML_USE_NODECACHE
+    void *node;
+#endif
+#ifndef XML_NONVALIDATING
+    struct _xml_error *info;
+#endif
+#ifdef WIN32
+    SIMPLE_UNMMAP un;
+#endif
+};
+
+struct _xml_id
+{
+    char *name;
+    char *start;
+    size_t len;
+    size_t name_len;
+#ifndef XML_NONVALIDATING
+    struct _root_id *root;
+#endif
+#ifdef XML_USE_NODECACHE
+    void *node;
+#endif
+};
+
+
+
 /**
  * Open an XML file for processing.
  *
  */
 void *xmlOpen(const char *);
 
+/**
+ * Process a section of XML code in a preallocated buffer.
+ * The buffer may not be free'd until xmlClose has been called.
+ *
+ * @param buffer pointer to the buffer
+ * @param size size of the buffer
+ * @return XML-id which is used for further processing
+ */
+void *xmlInitBuffer(const char *, size_t);
+
 /**
  * Close the XML file after which no further processing is possible.
  *
@@ -128,7 +224,7 @@ unsigned int xmlNodeGetNum(const void *, const char *);
  * @param num specify which occurence to return
  * @return XML-subsection-id for further processing or NULL if unsuccessful
  */
-void *xmlNodeGetPos(const void *, void *, const char *, int);
+void *xmlNodeGetPos(const void *, void *, const char *, size_t);
 
 
 /**
@@ -223,7 +319,8 @@ char *xmlAttributeGetString(const void *, const char *);
  * @param buffer the buffer to copy the string to
  * @param buflen length of the destination buffer
  * @return the length of the string
-size_t xmlAttributeCopyString(const void *, const char *, const char *, size_t);
+ */
+size_t xmlAttributeCopyString(const void *, const char *, char *, size_t);
 
 /**
  * Compare the value of an attribute to a reference string.
@@ -235,6 +332,7 @@ size_t xmlAttributeCopyString(const void *, const char *, const char *, size_t);
  * @return an integer less than, equal to, ro greater than zero if the value
  * of the node is found, respectively, to be less than, to match, or be greater
  * than str
+ */
 int xmlAttributeCompareString(const void *, const char *, const char *);
 
 
@@ -282,7 +380,6 @@ double xmlGetDouble(const void *);
  */
 double xmlNodeGetDouble(const void *, const char *);
 
-
 /**
  * Get the double value from the named attribute.
  *
@@ -292,5 +389,46 @@ double xmlNodeGetDouble(const void *, const char *);
  */
 double xmlAttributeGetDouble(const void *, const char *);
 
+
+/**
+ * Get the error number of the last error and clear it.
+ *
+ * @param xid XML-id
+ * @param clear clear the error state if non zero
+ * @return the numer of the last error, 0 means no error detected.
+ */
+int xmlErrorGetNo(const void *, int);
+
+/**
+ * Get the line number of the last detected syntax error in the xml file.
+ *
+ * @param xid XML-id
+ * @param clear clear the error state if non zero
+ * @return the line number of the detected syntax error.
+ */
+size_t xmlErrorGetLineNo(const void *, int);
+
+/**
+ * Get the column number of the last detected syntax error in the xml file.
+ *
+ * @param xid XML-id
+ * @param clear clear the error state if non zero
+ * @return the line number of the detected syntax error.
+ */
+size_t xmlErrorGetColumnNo(const void *, int);
+
+/**
+ * Get a string that explains the last error.
+ *
+ * @param xid XML-id
+ * @param clear clear the error state if non zero
+ * @return a string that explains the last error.
+ */
+const char *xmlErrorGetString(const void *, int);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* __XML_CONFIG */