Skip to content

Commit

Permalink
Refactor getSection() to more generally useful
Browse files Browse the repository at this point in the history
Support looking up by name or part number, return a pointer to the
struct so callers get all the details they need.
  • Loading branch information
pmatilai committed Apr 23, 2024
1 parent 317dadb commit c97c482
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
6 changes: 3 additions & 3 deletions build/parsePreamble.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,9 @@ static int addBuildOption(rpmSpec spec, const char *sect, const char *opt)
if (*sect == '\0')
sect = "conf";

int sn = getSection(sect);
if (sn >= 0) {
argvAdd(&(spec->buildopts[sn]), opt);
const struct sectname_s *sc = getSection(sect, 0);
if (sc) {
argvAdd(&(spec->buildopts[sc->section]), opt);
rc = RPMRC_OK;
}
return rc;
Expand Down
37 changes: 15 additions & 22 deletions build/parseSpec.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,33 +922,26 @@ static int parseEmpty(rpmSpec spec, int prevParsePart)
return res;
}

struct sectname_s {
const char *name;
int section;
int required;
};

struct sectname_s sectList[] = {
{ "prep", SECT_PREP, 0 },
{ "conf", SECT_CONF, 1 },
{ "generate_buildrequires", SECT_BUILDREQUIRES, 0 },
{ "build", SECT_BUILD, 1 },
{ "install", SECT_INSTALL, 1 },
{ "check", SECT_CHECK, 0 },
{ "clean", SECT_CLEAN, 0 },
{ NULL, -1 }
{ "prep", SECT_PREP, PART_PREP, 0 },
{ "conf", SECT_CONF, PART_CONF, 1 },
{ "generate_buildrequires", SECT_BUILDREQUIRES, PART_BUILDREQUIRES, 0 },
{ "build", SECT_BUILD, PART_BUILD, 1 },
{ "install", SECT_INSTALL, PART_INSTALL, 1 },
{ "check", SECT_CHECK, PART_CHECK, 0 },
{ "clean", SECT_CLEAN, PART_CLEAN, 0 },
{ NULL, -1, -1, 0 }
};

int getSection(const char *name)
const struct sectname_s *getSection(const char *name, int part)
{
int sn = -1;
for (struct sectname_s *sc = sectList; sc->name; sc++) {
if (rstreq(name, sc->name)) {
sn = sc->section;
break;
}
for (const struct sectname_s *sc = sectList; sc->name; sc++) {
if (name && rstreq(name, sc->name))
return sc;
if (part && part == sc->part)
return sc;
}
return sn;
return NULL;
}

int checkBuildsystem(rpmSpec spec, const char *name)
Expand Down
10 changes: 9 additions & 1 deletion build/rpmbuild_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ enum sections_e {
};
#define NR_SECT 7

struct sectname_s {
const char *name;
int section;
int part;
int required;
};


struct TriggerFileEntry {
int index;
char * fileName;
Expand Down Expand Up @@ -654,7 +662,7 @@ void doPatchMacro(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t margs, size_t *parsed

/* Return section number, -1 on error */
RPM_GNUC_INTERNAL
int getSection(const char *name);
const struct sectname_s *getSection(const char *name, int part);

#ifdef __cplusplus
}
Expand Down

0 comments on commit c97c482

Please sign in to comment.