OSDN Git Service

Support assignment of DEBUGLEVEL at configure time.
[mingw/mingw-get.git] / src / pkgname.cpp
1 /*
2  * pkgname.cpp
3  *
4  * $Id$
5  *
6  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
7  * Copyright (C) 2009, 2010, MinGW Project
8  *
9  *
10  * Implementation for the non-inherited components of the pkgXmlNode
11  * class, as declared in file "pkgdesc.h"; fundamentally, these are
12  * the accessors for package "tarname" properties, as specified in
13  * XML nodes identified as "release" elements.
14  *
15  *
16  * This is free software.  Permission is granted to copy, modify and
17  * redistribute this software, under the provisions of the GNU General
18  * Public License, Version 3, (or, at your option, any later version),
19  * as published by the Free Software Foundation; see the file COPYING
20  * for licensing details.
21  *
22  * Note, in particular, that this software is provided "as is", in the
23  * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
24  * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
25  * PARTICULAR PURPOSE.  Under no circumstances will the author, or the
26  * MinGW Project, accept liability for any damages, however caused,
27  * arising from the use of this software.
28  *
29  */
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "dmh.h"
34 #include "pkgbase.h"
35 #include "pkgkeys.h"
36
37 static
38 const char *pkgArchiveName( pkgXmlNode *rel, const char *tag, unsigned opt )
39 {
40   /* Local helper to establish actual release file names...
41    * applicable only to XML "release" elements.
42    */
43   if( ! rel->IsElementOfType( release_key ) )
44   {
45     /* The XML element type name is not "release"; identify it...
46      */
47     const char *reftype;
48     if( (reftype = rel->GetName()) == NULL )
49       /*
50        * ...or classify as "unknown", when given a NULL element.
51        */
52       reftype = value_unknown;
53
54     /* Complain that this XML element type is invalid, in this context...
55      */
56     dmh_control( DMH_BEGIN_DIGEST );
57     dmh_notify( DMH_ERROR, "internal package specification error\n" );
58     dmh_notify( DMH_ERROR, "can't get 'tarname' for non-release element %s\n", reftype );
59     dmh_notify( DMH_ERROR, "please report this to the package maintainer\n" );
60     dmh_control( DMH_END_DIGEST );
61
62     /* ...and bail out, telling the caller that no archive name is available...
63      */
64     return NULL;
65   }
66
67   /* Given a package release specification...
68    * First check that it relates to a real package, rather than to
69    * a virtual "meta-package"; such meta-packages exist solely as
70    * containers for requirements specifications, and have no
71    * associated archive.
72    */
73   pkgXmlNode *pkg = rel->GetParent();
74   while( (pkg != NULL) && ! pkg->IsElementOfType( package_key ) )
75     pkg = pkg->GetParent();
76
77   /* FIXME: we should probably provide some error handling here,
78    * to diagnose release elements without any package association;
79    * (these would be identified by pkg == NULL).
80    */
81   if( pkg != NULL )
82   {
83     /* We found the package association...
84      * Check its 'class' attribute, if any, and if classified as
85      * 'virtual', return the archive association as "none".
86      */
87     const char *package_class = pkg->GetPropVal( class_key, NULL );
88     if( (package_class != NULL) && (strcmp( package_class, value_virtual ) == 0) )
89       return value_none;
90   }
91
92   /* The given release specification relates to a real package...
93    * Determine the archive name for the tarball to be processed; this
94    * is retrieved from a child XML element with name specified by "tag";
95    * by default, if "opt" is non-zero, it is the canonical "tarname"
96    * assigned to the release element itself, unless an alternative
97    * specification is provided; if "opt" is zero, no default is
98    * assumed, and the return value is NULL if no alternative
99    * specification is provided.
100    */
101   unsigned matched = 0;
102   pkgXmlNode *dl = rel->GetChildren();
103   while( dl != NULL )
104   {
105     /* Visit all children of the release specification element,
106      * checking for the presence of an expected specification...
107      */
108     if( dl->IsElementOfType( tag ) )
109     {
110       /* Found one; ensure it is the only one...
111        */
112       if( matched++ )
113         /*
114          * ...else emit a warning, and ignore this one...
115          */
116         dmh_notify( DMH_WARNING, "%s: archive name reassignment ignored\n",
117             rel->GetPropVal( tarname_key, value_unknown )
118         );
119       else
120         /* ...ok; this is the first "tag" specification,
121          * accept it as the non-default source of the release's
122          * "tarname" property.
123          */
124         rel = dl;
125     }
126     /* Continue, until all children have been visited.
127      */
128     dl = dl->GetNext();
129   }
130   /* "rel" now points to the XML element having the appropriate
131    * "tarname" specification; return a pointer to it's value.
132    */
133   return (opt || matched) ? rel->GetPropVal( tarname_key, NULL ) : NULL;
134 }
135
136 const char *pkgXmlNode::SourceArchiveName()
137 {
138   /* Applicable only for XML nodes designated as "release".
139    *
140    * Retrieve the source tarball name, if specified, from the
141    * "tarname" property of the contained "source" element, within
142    * an XML node designated as a "release" element.
143    *
144    * Returns a pointer to the text of the "tarname" property of the
145    * contained "source" element, or NULL if the containing node does
146    * not represent a "release", or if it does not have a contained
147    * "source" element specifying a "tarname" property.
148    */
149   return pkgArchiveName( this, source_key, 0 );
150 }
151
152 const char *pkgXmlNode::ArchiveName()
153 {
154   /* Applicable only for XML nodes designated as "release".
155    *
156    * Retrieve the actual tarball name, if specified, from the
157    * "tarname" property of a contained "download" element, within
158    * an XML node designated as a "release" element.
159    *
160    * Returns a pointer to the text of the "tarname" property of the
161    * contained "download" element, or to the "tarname" property of
162    * the containing "release" element, if it does not contain an
163    * alternative specification within a "download" element; if
164    * unresolved to either of these, returns NULL.
165    */
166   return pkgArchiveName( this, download_key, 1 );
167 }
168
169 /* $RCSfile$: end of file */