diff options
-rw-r--r-- | include/spm.h | 5 | ||||
-rw-r--r-- | src/manifest.c | 53 | ||||
-rw-r--r-- | src/spm.c | 12 | ||||
-rw-r--r-- | src/version_spec.c | 24 |
4 files changed, 67 insertions, 27 deletions
diff --git a/include/spm.h b/include/spm.h index f40ea10..925de60 100644 --- a/include/spm.h +++ b/include/spm.h @@ -90,7 +90,10 @@ #define PACKAGE_MEMBER_SIZE 0xff #define PACKAGE_MEMBER_ORIGIN_SIZE PATH_MAX +#define PACKAGE_MEMBER_SEPARATOR '-' +#define PACKAGE_MEMBER_SEPARATOR_PLACEHOLD '*' +#define VERSION_OPERATORS " ~!=<>" #define VERSION_NOOP 1 << 0 #define VERSION_EQ 1 << 1 #define VERSION_NE 1 << 2 @@ -287,6 +290,8 @@ int dep_all(Dependencies **deps, const char *_package); void dep_show(Dependencies **deps); // manifest.c +void manifest_package_separator_swap(char **name); +void manifest_package_separator_restore(char **name); Manifest *manifest_from(const char *package_dir); Manifest *manifest_read(char *file_or_url); int manifest_write(Manifest *info, const char *dest); diff --git a/src/manifest.c b/src/manifest.c index 3aa054e..28cf2c4 100644 --- a/src/manifest.c +++ b/src/manifest.c @@ -6,6 +6,30 @@ #include "url.h" #define PACKAGE_MIN_DELIM 2 +void manifest_package_separator_swap(char **name) { + // Replace unwanted separators in the package name with placeholder to prevent splitting on the wrong one + int delim_count = num_chars((*name), PACKAGE_MEMBER_SEPARATOR); + if (delim_count > PACKAGE_MIN_DELIM) { + for (size_t t = strlen((*name)); t != 0; t--) { + if ((*name)[t] == PACKAGE_MEMBER_SEPARATOR) { + delim_count--; + if (delim_count == 0) { + (*name)[t] = PACKAGE_MEMBER_SEPARATOR_PLACEHOLD; + } + } + } + } +} + +void manifest_package_separator_restore(char **name) { + char separator[2]; + char placeholder[2]; + snprintf(separator, sizeof(separator), "%c", PACKAGE_MEMBER_SEPARATOR); + snprintf(placeholder, sizeof(placeholder), "%c", PACKAGE_MEMBER_SEPARATOR_PLACEHOLD); + + replace_text((*name), placeholder, separator); +} + /** * Generate a `Manifest` of package data * @param package_dir a directory containing SPM packages @@ -45,26 +69,17 @@ Manifest *manifest_from(const char *package_dir) { } dep_free(&deps); - // Replace unwanted hyphens in the package name with an invalid character to prevent splitting on the wrong - // hyphen below - int delims = num_chars(fsdata->files[i], '-'); - if (delims > PACKAGE_MIN_DELIM) { - for (size_t t = strlen(fsdata->files[i]); t != 0; t--) { - if (fsdata->files[i][t] == '-') { - delims--; - if (delims == 0) { - fsdata->files[i][t] = '*'; - } - } - } - } + // Swap extra package separators with a bogus character + manifest_package_separator_swap(&fsdata->files[i]); - // Split the package name into parts (invalid characters are ignored) - char **parts = split(fsdata->files[i], "-"); + // Split the package name into parts + char psep[2]; + snprintf(psep, sizeof(psep), "%c", PACKAGE_MEMBER_SEPARATOR); + char **parts = split(fsdata->files[i], psep); - // Replace invalid character with a hyphen - replace_text(parts[0], SPM_MANIFEST_NODATA, "-"); - replace_text(fsdata->files[i], SPM_MANIFEST_NODATA, "-"); + // Restore package separator + manifest_package_separator_restore(&parts[0]); + manifest_package_separator_restore(&fsdata->files[i]); // Populate `ManifestPackage` record info->packages[i]->size = (size_t) get_file_size(fsdata->files[i]); @@ -397,4 +412,4 @@ ManifestPackage *manifest_search(Manifest *info, const char *_package) { } } return NULL; -}
\ No newline at end of file +} @@ -245,24 +245,20 @@ int main(int argc, char *argv[], char *arge[]) { printf("Installing package:\n"); for (int i = 0; i < PACKAGE_MAX; i++) { - char *match = NULL; + //char *match = NULL; + ManifestPackage *match = NULL; char *package = NULL; if (!packages[i]) { break; } - if ((match = find_package(packages[i])) == NULL) { + if ((match = manifest_search(manifest, packages[i])) == NULL) { fprintf(SYSERROR); runtime_free(rt); exit(1); } - - if ((package = basename(match)) == NULL) { - fprintf(stderr, "Unable to derive package name from package path:\n\t-> %s\n", match); - runtime_free(rt); - exit(1); - } + package = match->archive; // If the package was installed as a requirement of another dependency, skip it if (dep_seen(&deps, package)) { diff --git a/src/version_spec.c b/src/version_spec.c index 0249375..d14e339 100644 --- a/src/version_spec.c +++ b/src/version_spec.c @@ -338,3 +338,27 @@ ManifestPackage **find_by_spec(Manifest *manifest, const char *name, const char return list; } + +ManifestPackage **find_by_strspec(const char *_strspec) { + const char *operators = VERSION_OPERATORS; // note: whitespace is synonymous with "==" if no other operators are present + char *pos = NULL; + char op[NAME_MAX]; + char name[NAME_MAX]; + char version[NAME_MAX]; + + memset(op, '\0', NAME_MAX); + memset(name, '\0', NAME_MAX); + memset(version, '\0', NAME_MAX); + + // Parse name + for (int i = 0; isalnum(_strspec[i]) || _strspec[i] == '_'; i++) { + name[i] = _strspec[i]; + } + + // Parse operators + pos = strpbrk(_strspec, operators); + for (int i = 0; !isalnum(*pos++); i++) { + + } + // hmmmmmm +} |