Exemplo n.º 1
0
header
read_header (void)
{
  register header the_header = ((header) NULL);
  register line_list *next_line = ((line_list *) NULL);

  init_linebuffer (&lb);

  do
    {
      long length;
      register char *line;

      readline (&lb, stdin);
      line = lb.buffer;
      length = strlen (line);
      if (length == 0) break;

      if (has_keyword (line))
	{
	  register header old = the_header;
	  the_header = new_header ();
	  if (old == ((header) NULL))
	    {
	      the_header->next = the_header;
	      the_header->previous = the_header;
	    }
	  else
	    {
	      the_header->previous = old;
	      the_header->next = old->next;
	      old->next = the_header;
	    }
	  next_line = &(the_header->text);
	}

      if (next_line == ((line_list *) NULL))
	{
	  /* Not a valid header */
	  exit (EXIT_FAILURE);
	}
      *next_line = new_list ();
      (*next_line)->string = alloc_string (length);
      strcpy (((*next_line)->string), line);
      next_line = &((*next_line)->continuation);
      *next_line = NIL;

    } while (true);

  if (! the_header)
    fatal ("input message has no header");
  return the_header->next;
}
Exemplo n.º 2
0
pkgXmlNode *
pkgXmlDocument::FindPackageByName( const char *lookup, const char *subsystem )
{
  /* Create a local copy of the package "name" which we are required to
   * "lookup"; this allows us to make temporary adjustments to facilitate
   * stripping of any "component" identifying suffix, which might occlude
   * a match for a package "alias" name.
   */
  int len; char name[ 1 + (len = strlen( lookup )) ];
  strcpy( name, lookup );

  /* Working from the root of the package directory tree...
   */
  pkgXmlNode *dir = GetRoot()->GetChildren();
  /*
   * search all "package-collection" XML nodes, to locate a package
   * by "name"; return a pointer to the XML node which contains the
   * specification for the package, or NULL if no such package.
   */
  while( dir != NULL )
  {
    /* Select only "package-collection" elements, which have been
     * assigned the desired "subsystem" property...
     */
    if( dir->IsElementOfType( package_collection_key )
    &&  subsystem_strcmp( subsystem, dir->GetPropVal( subsystem_key, NULL )) )
    {
      /* ...inspect the content of each...
       */
      pkgXmlNode *pkg = dir->GetChildren();
      while( pkg != NULL )
      {
	/* ...and, for each "package" element we find...
	 */
	if( pkg->IsElementOfType( package_key ) )
	{
	  /* ...return immediately, if it has a "name" or an "alias"
	   * property which matches the required package name...
	   */
	  const char *pkg_name, *alias;
	  if( (strcmp( name, pkg_name = pkg->GetPropVal( name_key, "" )) == 0)
	  ||  (has_keyword( name, alias = pkg->GetPropVal( alias_key, NULL ) ) != 0)  )
	    return pkg;

	  /* We did find a "package" element, but neither its "name"
	   * nor its "alias" property provided a match; look within it,
	   * for a possible match on a "component" package element...
	   */
	  pkgXmlNode *cpt = pkg->GetChildren();
	  while( cpt != NULL )
	  {
	    /* For each element contained within the "package" definition,
	     * check if it represents a "component" package definition...
	     */
	    if( cpt->IsElementOfType( component_key ) )
	    {
	      /* ...and return immediately, when it does, AND it also has a
	       * "name" property which matches the required package name...
	       */
	      if( strcmp( name, cpt->GetPropVal( name_key, "" )) == 0 )
		return cpt;

	      else
	      { /* We did find a "component" package, but its "name"
		 * property didn't match; construct an alternative name,
		 * by combining the "class" property of the "component"
		 * with the "name" property of the containing "package",
		 * and evaluate that for a possible match...
		 */
		const char *cpt_class = cpt->GetPropVal( class_key, "" );
		char *cpt_name = name + len - strlen( cpt_class );
		if( (strcmp( cpt_name, cpt_class ) == 0)
		&&  (*--cpt_name == '-')  )
		{
		  /* Again, return the "component", if this identifies
		   * a successful match...
		   */
		  *cpt_name = '\0';
		  if( (strcmp( name, pkg_name ) == 0) || has_keyword( name, alias ) )
		    return cpt;

		  /* Otherwise, restore the original content of the
		   * working copy of the "lookup name", in preperation
		   * for any subsequent attempt to find a match.
		   */
		  *cpt_name = '-';
		}
	      }
	    }

	    /* ...otherwise, continue checking any other "components"
	     * which may be defined within the current "package.
	     */
	    cpt = cpt->GetNext();
	  }
	}

	/* ...otherwise, continue searching among any further
	 * entries in the current "package-collection"...
	 */
	pkg = pkg->GetNext();
      }
    }
    /* ...and ultimately, in any further "package-collection" elements
     * which may be present.
     */
    dir = dir->GetNext();
  }

  /* If we get to here, we didn't find the required "package";
   * return NULL, to indicate failure.
   */
  return NULL;
}