scanctx.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* ----------------------------------------------------------------------------
  2. libconfig - A library for processing structured configuration files
  3. Copyright (C) 2005-2010 Mark A Lindner
  4. This file is part of libconfig.
  5. This library is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this library. If not, see <http://www.gnu.org/licenses/>.
  15. ----------------------------------------------------------------------------
  16. */
  17. #ifndef __libconfig_scanctx_h
  18. #define __libconfig_scanctx_h
  19. #include "libconfig.h"
  20. #include "strbuf.h"
  21. #include <stdio.h>
  22. #include <sys/types.h>
  23. #define MAX_INCLUDE_DEPTH 10
  24. struct scan_context
  25. {
  26. config_t *config;
  27. const char *top_filename;
  28. const char *files[MAX_INCLUDE_DEPTH];
  29. void *buffers[MAX_INCLUDE_DEPTH];
  30. FILE *streams[MAX_INCLUDE_DEPTH];
  31. int depth;
  32. strbuf_t string;
  33. const char **filenames;
  34. unsigned int num_filenames;
  35. };
  36. extern void scanctx_init(struct scan_context *ctx, const char *top_filename);
  37. extern const char **scanctx_cleanup(struct scan_context *ctx,
  38. unsigned int *num_filenames);
  39. extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
  40. const char **error);
  41. extern void *scanctx_pop_include(struct scan_context *ctx);
  42. #define scanctx_append_string(C, S) \
  43. strbuf_append(&((C)->string), (S))
  44. extern char *scanctx_take_string(struct scan_context *ctx);
  45. extern const char *scanctx_current_filename(struct scan_context *ctx);
  46. #endif /* __libconfig_scanctx_h */