testminixml.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* $Id: testminixml.c,v 1.6 2006/11/19 22:32:35 nanard Exp $
  2. * testminixml.c
  3. * test program for the "minixml" functions.
  4. * Author : Thomas Bernard.
  5. */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include "minixml.h"
  10. #include "igd_desc_parse.h"
  11. #ifdef WIN32
  12. #define NO_BZERO
  13. #endif
  14. #ifdef NO_BZERO
  15. #define bzero(p, n) memset(p, 0, n)
  16. #endif
  17. /* ---------------------------------------------------------------------- */
  18. void printeltname1(void * d, const char * name, int l)
  19. {
  20. int i;
  21. printf("element ");
  22. for(i=0;i<l;i++)
  23. putchar(name[i]);
  24. }
  25. void printeltname2(void * d, const char * name, int l)
  26. {
  27. int i;
  28. putchar('/');
  29. for(i=0;i<l;i++)
  30. putchar(name[i]);
  31. putchar('\n');
  32. }
  33. void printdata(void *d, const char * data, int l)
  34. {
  35. int i;
  36. printf("data : ");
  37. for(i=0;i<l;i++)
  38. putchar(data[i]);
  39. putchar('\n');
  40. }
  41. void burptest(const char * buffer, int bufsize)
  42. {
  43. struct IGDdatas data;
  44. struct xmlparser parser;
  45. /*objet IGDdatas */
  46. bzero(&data, sizeof(struct IGDdatas));
  47. /* objet xmlparser */
  48. parser.xmlstart = buffer;
  49. parser.xmlsize = bufsize;
  50. parser.data = &data;
  51. /*parser.starteltfunc = printeltname1;
  52. parser.endeltfunc = printeltname2;
  53. parser.datafunc = printdata; */
  54. parser.starteltfunc = IGDstartelt;
  55. parser.endeltfunc = IGDendelt;
  56. parser.datafunc = IGDdata;
  57. parsexml(&parser);
  58. printIGD(&data);
  59. }
  60. /* ----- main ---- */
  61. #define XML_MAX_SIZE (8192)
  62. int main(int argc, char * * argv)
  63. {
  64. FILE * f;
  65. char buffer[XML_MAX_SIZE];
  66. int bufsize;
  67. if(argc<2)
  68. {
  69. printf("usage:\t%s file.xml\n", argv[0]);
  70. return 1;
  71. }
  72. f = fopen(argv[1], "r");
  73. if(!f)
  74. {
  75. printf("cannot open file %s\n", argv[1]);
  76. return 1;
  77. }
  78. bufsize = (int)fread(buffer, 1, XML_MAX_SIZE, f);
  79. fclose(f);
  80. burptest(buffer, bufsize);
  81. return 0;
  82. }