Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB

  1. /*===========================================================================
  2. isrcmem.h
  3. Provides helper macros and typedefs for parsing memory buffers
  4. see parsifal.h for copyright info
  5. USAGE
  6. declare inputsource handler function (note param names
  7. must be exactly buf, cBytes etc.):
  8. int MemInputsrc(BYTE *buf, int cBytes, int *cBytesActual, void *inputData);
  9. int MemInputsrc(BYTE *buf, int cBytes, int *cBytesActual, void *inputData)
  10. {
  11. XMLMEMINPUTSRC_HANDLE
  12. }
  13. .....
  14. LPXMLPARSER parser;
  15. XMLMEMINPUTSRC meminput;
  16. char *xml = "<root><child1/><child2>text</child2></root>";
  17. XMLMEMINPUTSRC_INIT(&meminput, xml, strlen(xml));
  18. XMLParser_Create(&parser);
  19. XMLParser_Parse(parser, MemInputsrc, &meminput, NULL);
  20. .....
  21. ===========================================================================*/
  22. #ifndef ISRCMEM__H
  23. #define ISRCMEM__H
  24. typedef struct tagXMLMEMINPUTSRC
  25. {
  26. BYTE *pBuf;
  27. unsigned long cTotal;
  28. unsigned long cBytes;
  29. } XMLMEMINPUTSRC, *LPXMLMEMINPUTSRC;
  30. #define XMLMEMINPUTSRC_INIT(lpMemISrc,buf,size) \
  31. (((LPXMLMEMINPUTSRC)lpMemISrc)->cTotal=(size), \
  32. ((LPXMLMEMINPUTSRC)lpMemISrc)->cBytes=0, \
  33. ((LPXMLMEMINPUTSRC)lpMemISrc)->pBuf=(buf))
  34. #define XMLMEMINPUTSRC_HANDLE \
  35. if ((((LPXMLMEMINPUTSRC)inputData)->cBytes + cBytes) < ((LPXMLMEMINPUTSRC)inputData)->cTotal) { \
  36. memcpy(buf, ((LPXMLMEMINPUTSRC)inputData)->pBuf+((LPXMLMEMINPUTSRC)inputData)->cBytes, cBytes); \
  37. *cBytesActual = cBytes; \
  38. ((LPXMLMEMINPUTSRC)inputData)->cBytes += cBytes; \
  39. return 0; \
  40. } \
  41. else { \
  42. *cBytesActual = ((LPXMLMEMINPUTSRC)inputData)->cTotal - ((LPXMLMEMINPUTSRC)inputData)->cBytes; \
  43. if (*cBytesActual) { \
  44. memcpy(buf, ((LPXMLMEMINPUTSRC)inputData)->pBuf+((LPXMLMEMINPUTSRC)inputData)->cBytes, *cBytesActual); \
  45. ((LPXMLMEMINPUTSRC)inputData)->cBytes += *cBytesActual; } \
  46. return 1; \
  47. }
  48. #endif /* ISRCMEM__H */