Skip to content

Commit 6c7b940

Browse files
authored
Merge pull request #409 from pkratoch/comps-parsing
Parsing comps - add default, langonly and parse boolean values
2 parents 0077ef2 + 3f6bee6 commit 6c7b940

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

ext/repo_comps.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdlib.h>
1717
#include <string.h>
1818
#include <assert.h>
19+
#include <stdbool.h>
1920

2021
#include "pool.h"
2122
#include "repo.h"
@@ -29,7 +30,6 @@
2930
* TODO:
3031
*
3132
* what's the difference between group/category?
32-
* handle "default" and "langonly".
3333
*
3434
* maybe handle REL_COND in solver recommends handling?
3535
*/
@@ -101,6 +101,21 @@ struct parsedata {
101101
};
102102

103103

104+
const bool COMPS_DEFAULT_USERVISIBLE = true;
105+
const bool COMPS_DEFAULT_DEFAULT = false;
106+
107+
108+
/* Return true if "true", false if "false", default_value otherwise */
109+
bool
110+
parse_boolean(char *content, bool default_value)
111+
{
112+
if (!strcmp(content, "true"))
113+
return true;
114+
if (!strcmp(content, "false"))
115+
return false;
116+
return default_value;
117+
}
118+
104119

105120
static void
106121
startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts)
@@ -116,6 +131,10 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
116131
s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo));
117132
pd->handle = s - pool->solvables;
118133
pd->kind = state == STATE_GROUP ? "group" : "category";
134+
if (COMPS_DEFAULT_USERVISIBLE)
135+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
136+
if (COMPS_DEFAULT_DEFAULT)
137+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
119138
break;
120139

121140
case STATE_NAME:
@@ -194,7 +213,25 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content)
194213
break;
195214

196215
case STATE_USERVISIBLE:
197-
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
216+
if (parse_boolean(content, COMPS_DEFAULT_USERVISIBLE))
217+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
218+
else
219+
repodata_unset(pd->data, pd->handle, SOLVABLE_ISVISIBLE);
220+
break;
221+
222+
case STATE_DEFAULT:
223+
if (parse_boolean(content, COMPS_DEFAULT_DEFAULT))
224+
repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
225+
else
226+
repodata_unset(pd->data, pd->handle, SOLVABLE_ISDEFAULT);
227+
break;
228+
229+
case STATE_LANG_ONLY:
230+
repodata_set_str(pd->data, pd->handle, SOLVABLE_LANGONLY, content);
231+
break;
232+
233+
case STATE_LANGONLY:
234+
repodata_set_str(pd->data, pd->handle, SOLVABLE_LANGONLY, content);
198235
break;
199236

200237
case STATE_DISPLAY_ORDER:

src/knownid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ KNOWNID(LIBSOLV_SELF_DESTRUCT_PKG, "libsolv-self-destruct-pkg()"), /* this
267267

268268
KNOWNID(SOLVABLE_CONSTRAINS, "solvable:constrains"), /* conda */
269269
KNOWNID(SOLVABLE_TRACK_FEATURES, "solvable:track_features"), /* conda */
270+
KNOWNID(SOLVABLE_ISDEFAULT, "solvable:isdefault"),
271+
KNOWNID(SOLVABLE_LANGONLY, "solvable:langonly"),
270272

271273
KNOWNID(UPDATE_COLLECTIONLIST, "update:collectionlist"), /* list of UPDATE_COLLECTION (actually packages) and UPDATE_MODULE */
272274

0 commit comments

Comments
 (0)