repo

List, download and sync packs with remote repositories
Log | Files | Refs

commit dd25eabbe37570395ca70bfdf9f0c60d62a27691
parent be9bf8a9d75a32005bdd5cb7f9d50b04416f84a6
Author: z3bra <contactatz3bradotorg>
Date:   Thu Dec 15 18:42:10 +0100

Move sscanf() logic in local_load() functions

Diffstat:
repo.c | 30++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/repo.c b/repo.c @@ -30,7 +30,7 @@ struct repo { TAILQ_HEAD(repos, repo); void usage(char *); -struct pack *pack_load(char *); +struct pack *pack_load(struct packs *, char *, char *, char *); struct repo *add_repo(struct repos *, char *); int local_load(struct packs *, char *); int remote_sync(char *, FILE *); @@ -43,9 +43,8 @@ usage(char *name) } struct pack * -pack_load(char *repoline) +pack_load(struct packs *plist, char *name, char *version, char *url) { - int r = 0; struct pack *p = NULL; p = malloc(sizeof(struct pack)); @@ -54,12 +53,11 @@ pack_load(char *repoline) return NULL; } - r = sscanf(repoline, "%s\t%s\t%s", p->name, p->version, p->url); - if (r < 3) { - fprintf(stderr, "error parsing line: %s\n", repoline); - free(p); - p = NULL; - } + strncpy(p->url, url, sizeof(p->url)); + strncpy(p->name, name, sizeof(p->name)); + strncpy(p->version, version, sizeof(p->version)); + + TAILQ_INSERT_TAIL(plist, p, entries); return p; } @@ -89,9 +87,11 @@ add_repo(struct repos *rlist, char *url) int local_load(struct packs *plist, char *local) { + int r = 0; char fn[PATH_MAX] = ""; char buf[LINE_MAX] = ""; - struct pack *p = NULL; + + char n[LINE_MAX], v[LINE_MAX], u[PATH_MAX]; FILE *list; snprintf(fn, PATH_MAX, "%s/%s", local, LISTFILE); @@ -102,10 +102,12 @@ local_load(struct packs *plist, char *local) } while (fgets(buf, LINE_MAX, list)) { - p = pack_load(buf); - if (p) - TAILQ_INSERT_TAIL(plist, p, entries); - p = NULL; + r = sscanf(buf, "%s\t%s\t%s", n, v, u); + if (r < 3) { + perror(fn); + exit(1); + } + pack_load(plist, n, v, u); } fclose(list); return 0;