Пример #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
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);
}