Пример #1
0
FILE *scanctx_push_include(struct scan_context *ctx, void *buffer,
                           const char **error)
{
  FILE *fp = NULL;
  const char *file;

  *error = NULL;

  if(ctx->depth == MAX_INCLUDE_DEPTH)
  {
    *error = err_include_too_deep;
    return(NULL);
  }

  file = scanctx_take_string(ctx);
  fp = fopen(file, "rt");
  if(fp)
  {
    ctx->streams[ctx->depth] = fp;
    ctx->files[ctx->depth] = __scanctx_add_filename(ctx, file);
    ctx->buffers[ctx->depth] = buffer;
    ++(ctx->depth);
  }
  else
  {
    free((void *)file);
    *error = err_bad_include;
  }

  return(fp);
}
Пример #2
0
void scanctx_init(struct scan_context *ctx, const char *top_filename)
{
  memset(ctx, 0, sizeof(struct scan_context));
#ifndef __clang_analyzer__ // FIXME: Clang's static analyzer doesn't like this
  if(top_filename)
    ctx->top_filename = __scanctx_add_filename(ctx, strdup(top_filename));
#endif // __clang_analyzer__
}
Пример #3
0
FILE *scanctx_push_include(struct scan_context *ctx, void *buffer,
                           const char **error)
{
  FILE *fp = NULL;
  const char *file;
  char *full_file = NULL;

  *error = NULL;

  if(ctx->depth == MAX_INCLUDE_DEPTH)
  {
    *error = err_include_too_deep;
    return(NULL);
  }

  file = scanctx_take_string(ctx);
  if(ctx->config->include_dir)
  {
    full_file = (char *)malloc(strlen(ctx->config->include_dir) + strlen(file)
                               + 2);
    strcpy(full_file, ctx->config->include_dir);
    strcat(full_file, FILE_SEPARATOR);
    strcat(full_file, file);
  }

  fp = fopen(full_file ? full_file : file, "rt");
  free((void *)full_file);

  if(fp)
  {
    ctx->streams[ctx->depth] = fp;
#ifndef __clang_analyzer__ // FIXME: Clang's static analyzer doesn't like this
    ctx->files[ctx->depth] = __scanctx_add_filename(ctx, file);
#endif // __clang_analyzer__
    ctx->buffers[ctx->depth] = buffer;
    ++(ctx->depth);
  }
  else
  {
    free((void *)file);
    *error = err_bad_include;
  }

  return(fp);
}
Пример #4
0
void scanctx_init(struct scan_context *ctx, const char *top_filename)
{
  memset(ctx, 0, sizeof(struct scan_context));
  if(top_filename)
    ctx->top_filename = __scanctx_add_filename(ctx, strdup(top_filename));
}