scanctx.h 2.1 KB

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