xmlopen.c.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. xmlopen.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='xmlnode.c.html' title=' xmlnode.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='xmlread.c.html' title=' xmlread.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * NODE * xmlopen (char const * filename);
  24. *
  25. * node.h
  26. *
  27. * open an XML file and return the parse tree root;
  28. *
  29. * the entire file is read into a buffer associated with the text
  30. * member in the root node; the buffer is then split into strings
  31. * referenced by child nodes, forming a hierarchial string vector;
  32. *
  33. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  34. * Copyright (c) 2001-2006 by Charles Maier Associates;
  35. * Licensed under the Internet Software Consortium License;
  36. *
  37. *--------------------------------------------------------------------*/
  38. #ifndef XMLOPEN_SOURCE
  39. #define XMLOPEN_SOURCE
  40. #include &lt;unistd.h&gt;
  41. #include &lt;memory.h&gt;
  42. #include &lt;fcntl.h&gt;
  43. #include &lt;errno.h&gt;
  44. #include &quot;../nodes/node.h&quot;
  45. #include &quot;../tools/memory.h&quot;
  46. #include &quot;../tools/files.h&quot;
  47. #include &quot;../tools/error.h&quot;
  48. NODE * xmlopen (char const * filename)
  49. {
  50. ssize_t length;
  51. NODE * node = NEW (NODE);
  52. signed fd = open (filename, O_BINARY|O_RDONLY);
  53. if (fd == -1)
  54. {
  55. error (1, errno, FILE_CANTOPEN, filename);
  56. }
  57. length = lseek (fd, 0, SEEK_END);
  58. if (length == -1)
  59. {
  60. error (1, errno, FILE_CANTSEEK, filename);
  61. }
  62. if (lseek (fd, 0, SEEK_SET) == -1)
  63. {
  64. error (1, errno, FILE_CANTHOME, filename);
  65. }
  66. memset (node, 0, sizeof (NODE));
  67. node-&gt;text = STR (length);
  68. if (read (fd, node-&gt;text, length) &lt; length)
  69. {
  70. error (1, errno, FILE_CANTREAD, filename);
  71. }
  72. node-&gt;text [length] = (char)(0);
  73. close (fd);
  74. xmlscan (node);
  75. return (node);
  76. }
  77. #endif
  78. </pre>
  79. <div class='footerlink'>
  80. [<a href='xmlnode.c.html' title=' xmlnode.c '>PREV</a>]
  81. [<a href='toolkit.html' title=' Index '>HOME</a>]
  82. [<a href='xmlread.c.html' title=' xmlread.c '>NEXT</a>]
  83. </div>
  84. </body>
  85. </html>