Commit 91da81ef authored by Frits Daalmans's avatar Frits Daalmans

cleanup of part of the GETDEPS code. 2 small optimizations.

parent fe88e993
/* #define _GNU_SOURCE ** for vasprintf() */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -47,7 +48,7 @@ static char *xasprintf(const char *fmt, ...) {
return ret;
}
static void parse_exclude_field(char *str) {
static void parse_exclude_field(const char *str) {
char *workptr, *saveptr = NULL, *tok = NULL;
workptr = strdup(str);
int nf=0,f;
......@@ -86,7 +87,8 @@ static void free_exclude_array(void) {
exclude_array=NULL;
}
static int exclude_dep(char *dep, char *versionclause) {
/* versionclause is not used at the moment */
static int exclude_dep(const char *dep, const char *versionclause) {
int f;
if (exclude_array==NULL) return(0);
......@@ -133,17 +135,19 @@ typedef struct deps_proto {
char ** deps;
} deps_t, *deps_p;
deps_p deps_new(void) {
static deps_p deps_new(void) {
deps_p n = (deps_p) malloc(sizeof(deps_t));
if (n==NULL) oom_die();
memset(n, 0x00, sizeof(deps_t));
n->cur_pkg = NULL;
n->nd = 0;
n->deps = NULL;
return(n);
}
void deps_free(deps_p d) {
static void deps_free(deps_p d) {
int i;
if (d==NULL) return;
for(i=0;i<d->nd;i++){
......@@ -164,12 +168,12 @@ void deps_free(deps_p d) {
free(d);
}
void deps_setpkgname(deps_p d, char *cur_pkg) {
static void deps_setpkgname(deps_p d, const char *cur_pkg) {
if (d->cur_pkg) free(d->cur_pkg);
d->cur_pkg = strdup(cur_pkg);
}
void deps_add_4(deps_p d, char *dep) {
static void deps_add_4(deps_p d, const char *dep) {
int di;
/* Typically, a package depends on 0-10 other ones. I can't be
......@@ -191,7 +195,7 @@ void deps_add_4(deps_p d, char *dep) {
d->nd++;
}
int deps_add_3(deps_p d, char *versioneddep) {
static int deps_add_3(deps_p d, const char *versioneddep) {
char *workptr, *tok3, *saveptr3, *versionclause;
int used;
workptr = strdup(versioneddep);
......@@ -217,9 +221,17 @@ int deps_add_3(deps_p d, char *versioneddep) {
return(used);
}
void deps_add_2(deps_p d, char *depsaltlist) {
static void deps_add_2(deps_p d, const char *depsaltlist) {
char *workptr, *tok2, *saveptr2;
int used, chose_alternative;
/* shortcut: most dependencies don't have the alternatives syntax */
if (strchr(depsaltlist, '|')==NULL) {
(void) deps_add_3(d, depsaltlist);
return;
}
/* parse this dependency-alternatives-list A | B | C */
workptr = strdup(depsaltlist);
tok2 = strtok_r(workptr, " |", &saveptr2);
chose_alternative = 0;
......@@ -245,8 +257,8 @@ void deps_add_2(deps_p d, char *depsaltlist) {
free(workptr);
}
void deps_add(deps_p d, char *depslist) {
char *workptr, *tok, *saveptr;
static void deps_add(deps_p d, const char *depslist) {
char *workptr, *tok, *saveptr = NULL;
/* skip initial space */
while ((depslist[0])&&(isspace(depslist[0]))) depslist++;
......@@ -259,7 +271,7 @@ void deps_add(deps_p d, char *depslist) {
free(workptr);
}
void deps_output(FILE *f, deps_p d) {
static void deps_output(FILE *f, const deps_p d) {
int i;
if ((f==NULL)||(d==NULL)||(d->nd==0)) return;
......@@ -289,7 +301,7 @@ static void dogetdeps(char *pkgsfile, char **in_pkgs, int pkgc) {
char cur_predeps[MAX_LINE];
char prev_pkg[MAX_LINE];
char *pkgs[MAX_PKGS];
int i;
int i,l;
int skip;
FILE *f;
int output_pkg = -1;
......@@ -309,7 +321,8 @@ static void dogetdeps(char *pkgsfile, char **in_pkgs, int pkgc) {
skip = 1;
while (fgets(buf, sizeof(buf), f)) {
if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
l = strlen(buf);
if (*buf && buf[l-1] == '\n') buf[l-1] = '\0';
if (strncasecmp(buf, "Package:", 8) == 0) {
int any = 0;
skip = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment