Ejemplo n.º 1
0
/* add a section with the current token as name */
static PVOID add_section_from_token( struct parser *parser )
{
  PINFCACHESECTION Section;

  if (parser->token_len > MAX_SECTION_NAME_LEN)
    {
      parser->error = INF_STATUS_SECTION_NAME_TOO_LONG;
      return NULL;
    }

  Section = InfpFindSection(parser->file,
                            parser->token);
  if (Section == NULL)
    {
      /* need to create a new one */
      Section= InfpAddSection(parser->file,
                              parser->token);
      if (Section == NULL)
        {
          parser->error = INF_STATUS_NOT_ENOUGH_MEMORY;
          return NULL;
        }
    }

  parser->token_len = 0;
  parser->cur_section = Section;

  return (PVOID)Section;
}
Ejemplo n.º 2
0
INFSTATUS
InfpFindOrAddSection(PINFCACHE Cache,
                     PCWSTR Section,
                     PINFCONTEXT *Context)
{
  DPRINT("InfpFindOrAddSection section %S\n", Section);

  *Context = MALLOC(sizeof(INFCONTEXT));
  if (NULL == *Context)
    {
      DPRINT1("MALLOC() failed\n");
      return INF_STATUS_NO_MEMORY;
    }

  (*Context)->Inf = Cache;
  (*Context)->Section = InfpFindSection(Cache, Section);
  (*Context)->Line = NULL;
  if (NULL == (*Context)->Section)
    {
      DPRINT("Section not found, creating it\n");
      (*Context)->Section = InfpAddSection(Cache, Section);
      if (NULL == (*Context)->Section)
        {
          DPRINT("Failed to create section\n");
          FREE(*Context);
          return INF_STATUS_NO_MEMORY;
        }
    }

  return INF_STATUS_SUCCESS;
}
Ejemplo n.º 3
0
INFSTATUS
InfpFindFirstLine(PINFCACHE Cache,
                  PCWSTR Section,
                  PCWSTR Key,
                  PINFCONTEXT *Context)
{
  PINFCACHESECTION CacheSection;
  PINFCACHELINE CacheLine;

  if (Cache == NULL || Section == NULL || Context == NULL)
    {
      DPRINT1("Invalid parameter\n");
      return INF_STATUS_INVALID_PARAMETER;
    }

  CacheSection = InfpFindSection(Cache, Section);
  if (NULL == CacheSection)
    {
      DPRINT("Section not found\n");
      return INF_STATUS_NOT_FOUND;
    }

  if (Key != NULL)
    {
      CacheLine = InfpFindKeyLine(CacheSection, Key);
    }
  else
    {
      CacheLine = CacheSection->FirstLine;
    }

  if (NULL == CacheLine)
    {
      DPRINT("Key not found\n");
      return INF_STATUS_NOT_FOUND;
    }

  *Context = MALLOC(sizeof(INFCONTEXT));
  if (NULL == *Context)
    {
      DPRINT1("MALLOC() failed\n");
      return INF_STATUS_NO_MEMORY;
    }
  (*Context)->Inf = (PVOID)Cache;
  (*Context)->Section = (PVOID)CacheSection;
  (*Context)->Line = (PVOID)CacheLine;

  return INF_STATUS_SUCCESS;
}
Ejemplo n.º 4
0
/* parse a complete buffer */
INFSTATUS
InfpParseBuffer (PINFCACHE file,
                 const WCHAR *buffer,
                 const WCHAR *end,
                 PULONG error_line)
{
  struct parser parser;
  const WCHAR *pos = buffer;

  parser.start       = buffer;
  parser.end         = end;
  parser.file        = file;
  parser.line        = NULL;
  parser.state       = LINE_START;
  parser.stack_pos   = 0;
  parser.cur_section = NULL;
  parser.line_pos    = 1;
  parser.error       = 0;
  parser.token_len   = 0;

  /* parser main loop */
  while (pos)
    pos = (parser_funcs[parser.state])(&parser, pos);

  if (parser.error)
    {
      if (error_line)
        *error_line = parser.line_pos;
      return parser.error;
    }

  /* find the [strings] section */
  file->StringsSection = InfpFindSection(file,
                                         L"Strings");

  return INF_STATUS_SUCCESS;
}