repo

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 88561a75de8adb2f555403958572a5167d9ea575
parent 255d98c6c20cb6db83a1a61e7c9bf8d7630baed5
Author: z3bra <willyatmailoodotorg>
Date:   Sat Dec 10 09:55:34 +0100

Load packs from repo file

Diffstat:
repo.c | 65++++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 50 insertions(+), 15 deletions(-)
diff --git a/repo.c b/repo.c @@ -3,8 +3,9 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> +#include <sys/queue.h> #include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> #include <curl/curl.h> @@ -16,13 +17,17 @@ #define REMOTEREPO "http://localhost" struct pack { - char *name; - char *version; - char *filename; + char name[LINE_MAX]; + char version[LINE_MAX]; + char filename[PATH_MAX]; + SLIST_ENTRY(pack) entries; }; +SLIST_HEAD(packs, pack); void usage(char *); int mkdir_parents(char *, mode_t); +struct pack *pack_load(char *); +int local_load(struct packs *, char *); int local_list(char *); int remote_sync(char *, char *); @@ -57,13 +62,35 @@ mkdir_parents(char *path, mode_t mode) return mkdir(tmp, mode); } +struct pack * +pack_load(char *repoline) +{ + int r = 0; + struct pack *p = NULL; + + p = malloc(sizeof(struct pack)); + if (!p) { + perror("malloc"); + return NULL; + } + + r = sscanf(repoline, "%s\t%s\t%s", p->name, p->version, p->filename); + if (r < 3) { + fprintf(stderr, "error parsing line: %s\n", repoline); + free(p); + p = NULL; + } + + return p; +} + int -local_list(char *local) +local_load(struct packs *plist, char *local) { - int ret = 0; ssize_t len = 0; char *fn; char buf[LINE_MAX] = ""; + struct pack *p = NULL; FILE *list; len = strlen(local) + strlen(LISTFILE); @@ -81,17 +108,25 @@ local_list(char *local) return -1; } - while ((len = fread(buf, 1, LINE_MAX, list))) { - if (len < 0) { - perror("fread"); - return ret = -1; - } - fwrite(buf, 1, len, stdout); + while (fgets(buf, LINE_MAX, list)) { + p = pack_load(buf); + if (p) + SLIST_INSERT_HEAD(plist, p, entries); + p = NULL; } + return 0; +} - fclose(list); - free(fn); - return ret; +int +local_list(char *local) +{ + struct packs plist; + struct pack *p = NULL; + local_load(&plist, local); + SLIST_FOREACH(p, &plist, entries) { + printf("%s\t%s\n", p->name, p->version); + } + return 0; } int