aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/archive.c3
-rw-r--r--src/checksum.c6
-rw-r--r--src/config.c2
-rw-r--r--src/config_global.c3
-rw-r--r--src/deps.c6
-rw-r--r--src/find.c3
-rw-r--r--src/fs.c5
-rw-r--r--src/install.c16
-rw-r--r--src/internal_cmd.c15
-rw-r--r--src/manifest.c30
-rw-r--r--src/mime.c27
-rw-r--r--src/relocation.c40
-rw-r--r--src/rpath.c3
-rw-r--r--src/shell.c3
-rw-r--r--src/spm.c6
-rw-r--r--src/spm_build.c9
-rw-r--r--src/strings.c18
-rw-r--r--src/version_spec.c47
18 files changed, 217 insertions, 25 deletions
diff --git a/src/archive.c b/src/archive.c
index 7ec9d04..9fbfae7 100644
--- a/src/archive.c
+++ b/src/archive.c
@@ -1,3 +1,6 @@
+/**
+ * @file archive.c
+ */
#include "spm.h"
/**
diff --git a/src/checksum.c b/src/checksum.c
index a26a415..d777edc 100644
--- a/src/checksum.c
+++ b/src/checksum.c
@@ -1,6 +1,6 @@
-//
-// Created by jhunk on 12/20/19.
-//
+/**
+ * @file checksum.c
+ */
#include "spm.h"
#include <openssl/md5.h>
#include <openssl/sha.h>
diff --git a/src/config.c b/src/config.c
index 93ff673..1eaed15 100644
--- a/src/config.c
+++ b/src/config.c
@@ -70,7 +70,7 @@ ConfigItem **config_read(const char *filename) {
while (lptr != sep_pos) {
*key++ = *lptr++;
}
- key = strip(key);
+ key = strip(key_orig);
// We're at the separator now, so skip over it
lptr++;
diff --git a/src/config_global.c b/src/config_global.c
index d4e7e69..4184eba 100644
--- a/src/config_global.c
+++ b/src/config_global.c
@@ -1,3 +1,6 @@
+/**
+ * @file config_global.c
+ */
#include "spm.h"
char *get_user_conf_dir(void) {
diff --git a/src/deps.c b/src/deps.c
index ded7fab..84b66e1 100644
--- a/src/deps.c
+++ b/src/deps.c
@@ -1,6 +1,6 @@
-//
-// Created by jhunk on 12/16/19.
-//
+/**
+ * @file deps.c
+ */
#include "spm.h"
int exists(const char *filename) {
diff --git a/src/find.c b/src/find.c
index 84ded16..d2fc5a2 100644
--- a/src/find.c
+++ b/src/find.c
@@ -1,3 +1,6 @@
+/**
+ * @file find.c
+ */
#include "spm.h"
/**
diff --git a/src/fs.c b/src/fs.c
index e20b6a7..5ea8f6b 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -1,3 +1,6 @@
+/**
+ * @file fs.c
+ */
#include "spm.h"
FSTree *fstree(const char *_path) {
@@ -354,7 +357,7 @@ int mkdirs(const char *_path, mode_t mode) {
* free(output);
* output = human_readable_size(1024) // "1.0K"
* free(output);
- * output = human_readable_size(1024000) // "1.0MB"
+ * output = human_readable_size(1024000) // "1.0M"
* free(output);
* // and so on
* ~~~
diff --git a/src/install.c b/src/install.c
index 7ecb401..8f56363 100644
--- a/src/install.c
+++ b/src/install.c
@@ -1,9 +1,13 @@
+/**
+ * @file install.c
+ */
#include "spm.h"
/**
- *
+ * SPM packages contain metadata files that are not useful post-install and would amount to a lot of clutter.
+ * This function removes these data files from a directory tree
* @param _path
- * @return
+ * @return success=0, error=-1
*/
int metadata_remove(const char *_path) {
char *metadata[] = {
@@ -35,6 +39,13 @@ int metadata_remove(const char *_path) {
return 0;
}
+/**
+ * Install a package and its dependencies into a destination root.
+ * The destination is created if it does not exist.
+ * @param destroot directory to install package
+ * @param _package name of archive to install (not a path)
+ * @return success=0, error=-1 (general), -2 (unable to create `destroot`)
+ */
int install(const char *destroot, const char *_package) {
char *package = find_package(_package);
if (!package) {
@@ -99,4 +110,5 @@ int install(const char *destroot, const char *_package) {
rmdirs(tmpdir);
free(package);
+ return 0;
}
diff --git a/src/internal_cmd.c b/src/internal_cmd.c
index 3f4d05d..c28bcbb 100644
--- a/src/internal_cmd.c
+++ b/src/internal_cmd.c
@@ -1,11 +1,20 @@
+/**
+ * @file internal_cmd.c
+ */
#include "spm.h"
+/**
+ * List of valid internal commands
+ */
static char *internal_commands[] = {
"mkprefixbin", "generate prefix manifest (binary)",
"mkprefixtext", "generate prefix manifest (text)",
NULL, NULL,
};
+/**
+ * Show a listing of valid internal commands
+ */
void internal_command_list(void) {
printf("possible commands:\n");
for (int i = 0; internal_commands[i] != NULL; i++) {
@@ -18,6 +27,12 @@ void mkprefix_usage(void) {
printf("usage: mkprefix[bin|text] {output_file} {dir} {prefix ...}\n");
}
+/**
+ * Execute an internal command
+ * @param argc
+ * @param argv
+ * @return success=0, failure=1, error=-1
+ */
int internal_cmd(int argc, char **argv) {
int command_valid = 0;
char *command = argv[1];
diff --git a/src/manifest.c b/src/manifest.c
index d917470..e527e69 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -1,10 +1,15 @@
-//
-// Created by jhunk on 12/20/19.
-//
+/**
+ * @file manifest.c
+ */
#include "spm.h"
#include <fnmatch.h>
#define PACKAGE_MIN_DELIM 2
+/**
+ *
+ * @param package_dir
+ * @return
+ */
Manifest *manifest_from(const char *package_dir) {
FSTree *fsdata = NULL;
fsdata = fstree(package_dir);
@@ -65,6 +70,10 @@ Manifest *manifest_from(const char *package_dir) {
return info;
}
+/**
+ *
+ * @param info
+ */
void manifest_free(Manifest *info) {
for (int i = 0; i < info->records; i++) {
if (info->packages[i]->requirements) {
@@ -79,6 +88,11 @@ void manifest_free(Manifest *info) {
free(info);
}
+/**
+ *
+ * @param info
+ * @return
+ */
int manifest_write(Manifest *info) {
const char *filename = "manifest.dat";
char path[PATH_MAX];
@@ -139,6 +153,10 @@ int manifest_write(Manifest *info) {
return 0;
}
+/**
+ *
+ * @return
+ */
Manifest *manifest_read(void) {
const char *filename = "manifest.dat";
char path[PATH_MAX];
@@ -190,6 +208,12 @@ Manifest *manifest_read(void) {
return info;
}
+/**
+ *
+ * @param info
+ * @param _package
+ * @return
+ */
ManifestPackage *manifest_search(Manifest *info, const char *_package) {
char package[PATH_MAX];
diff --git a/src/mime.c b/src/mime.c
index d90cc3f..9fcf97b 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -1,5 +1,13 @@
+/**
+ * @file mime.c
+ */
#include "spm.h"
+/**
+ * Execute OS `file` command
+ * @param _filename path to file
+ * @return Process structure
+ */
Process *file_command(const char *_filename) {
char *filename = strdup(_filename);
Process *proc_info = NULL;
@@ -26,6 +34,11 @@ Process *file_command(const char *_filename) {
return proc_info;
}
+/**
+ * Execute the `file` command, parse its output, and return the data in a `Mime` structure
+ * @param filename path to file
+ * @return Mime structure
+ */
Mime *file_mimetype(const char *filename) {
char **output = NULL;
char **parts = NULL;
@@ -63,6 +76,10 @@ Mime *file_mimetype(const char *filename) {
return type;
}
+/**
+ * Free a `Mime` structure
+ * @param m
+ */
void mime_free(Mime *m) {
if (m != NULL) {
free(m->origin);
@@ -72,6 +89,11 @@ void mime_free(Mime *m) {
}
}
+/**
+ * Determine if a file is a text file
+ * @param filename
+ * @return yes=1, no=0
+ */
int file_is_text(const char *filename) {
int result = 0;
char *path = normpath(filename);
@@ -84,6 +106,11 @@ int file_is_text(const char *filename) {
return result;
}
+/**
+ * Determine if a file is a binary data file
+ * @param filename
+ * @return yes=1, no=0
+ */
int file_is_binary(const char *filename) {
int result = 0;
char *path = normpath(filename);
diff --git a/src/relocation.c b/src/relocation.c
index 87b204e..681cded 100644
--- a/src/relocation.c
+++ b/src/relocation.c
@@ -1,5 +1,24 @@
+/**
+ * @file relocation.c
+ */
#include "spm.h"
+/**
+ * Replace all occurrences of `spattern` with `sreplacement` in `data`
+ *
+ * ~~~{.c}
+ * char *str = (char *)calloc(100, sizeof(char));
+ * strcpy(str, "This are a test.");
+ * replace_text(str, "are", "is");
+ * // str is: "This is a test."
+ * free(str);
+ * ~~~
+ *
+ * @param data string to modify
+ * @param spattern string value to replace
+ * @param sreplacement replacement string value
+ * @return success=0, error=-1
+ */
int replace_text(char *data, const char *spattern, const char *sreplacement) {
char *tmp = data;
size_t data_len = strlen(data);
@@ -23,9 +42,9 @@ int replace_text(char *data, const char *spattern, const char *sreplacement) {
/**
* Replace all occurrences of `oldstr` in file `path` with `newstr`
- * @param filename
- * @param oldstr
- * @param newstr
+ * @param filename file to modify
+ * @param oldstr string to replace
+ * @param newstr replacement string
* @return success=0, failure=-1, or value of `ferror()`
*/
int file_replace_text(char *filename, const char *spattern, const char *sreplacement) {
@@ -101,7 +120,7 @@ void prefixes_free(RelocationEntry **entry) {
* #...N
* ...N
* ~~~
- * @param filename
+ * @param filename path to prefix manifest
* @return success=array of RelocationEntry, failure=NULL
*/
RelocationEntry **prefixes_read(const char *filename) {
@@ -202,13 +221,22 @@ RelocationEntry **prefixes_read(const char *filename) {
}
/**
- * Generate a prefix manifest
+ * Scan `tree` for files containing `prefix`. Matches are recorded in `output_file` with the following format:
+ *
+ * ~~~
+ * #prefix
+ * path
+ * #prefix
+ * path
+ * #...N
+ * ...N
+ * ~~~
*
* Example:
* ~~~{.c}
* char **prefixes = {"/usr", "/var", NULL};
* prefixes_write("binary.manifest", PREFIX_WRITE_BIN, prefixes, "/usr/bin");
- * prefixes_write("text.manifest", PREFIX_WRITE_TEXT, prefixes, "/usr/share/man/7");
+ * prefixes_write("text.manifest", PREFIX_WRITE_TEXT, prefixes, "/etc");
* ~~~
*
* @param output_file file path to create
diff --git a/src/rpath.c b/src/rpath.c
index f499e98..b7d4937 100644
--- a/src/rpath.c
+++ b/src/rpath.c
@@ -1,3 +1,6 @@
+/**
+ * @file rpath.c
+ */
#include "spm.h"
/**
diff --git a/src/shell.c b/src/shell.c
index 8905c60..6ce3ad2 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1,3 +1,6 @@
+/**
+ * @file shell.c
+ */
#include "spm.h"
/**
diff --git a/src/spm.c b/src/spm.c
index bca6353..ef3e61d 100644
--- a/src/spm.c
+++ b/src/spm.c
@@ -288,11 +288,11 @@ int main(int argc, char *argv[]) {
}
- int banner_size = 77;
- printf("# ");
+ int banner_size = 79;
+ putchar('#');
print_banner("-", banner_size);
printf("# %-20s %-20s %-20s %-20s\n", "name", "version", "revision", "size");
- printf("# ");
+ putchar('#');
print_banner("-", banner_size);
if (RUNTIME_SEARCH) {
diff --git a/src/spm_build.c b/src/spm_build.c
index 4cc4c47..726b540 100644
--- a/src/spm_build.c
+++ b/src/spm_build.c
@@ -1,5 +1,14 @@
+/**
+ * @file spm_build.c
+ */
#include "spm.h"
+/**
+ *
+ * @param argc
+ * @param argv
+ * @return
+ */
int build(int argc, char **argv) {
printf("build:\n");
printf("argc: %d\n", argc);
diff --git a/src/strings.c b/src/strings.c
index 38cc4d3..d6da7b6 100644
--- a/src/strings.c
+++ b/src/strings.c
@@ -1,3 +1,6 @@
+/**
+ * @file strings.c
+ */
#include "spm.h"
/**
@@ -445,10 +448,19 @@ char *lstrip(char *sptr) {
* @return truncated string
*/
char *strip(char *sptr) {
- if (!strlen(sptr)) {
+ size_t len = strlen(sptr);
+ if (len < 1) {
+ *sptr = '\0';
return sptr;
}
- strchrdel(sptr, " \r\n");
+ for (size_t i = len - 1; i >= 0; i--) {
+ if (isspace(sptr[i]) || isblank(sptr[i])) {
+ sptr[i] = '\0';
+ }
+ else {
+ break;
+ }
+ }
return sptr;
}
@@ -505,7 +517,7 @@ int isrelational(char ch) {
}
/**
- * Repeatedly print string `s`, `len` times
+ * Print characters in `s`, `len` times
* @param s
* @param len
*/
diff --git a/src/version_spec.c b/src/version_spec.c
index af20fae..1bd31ae 100644
--- a/src/version_spec.c
+++ b/src/version_spec.c
@@ -1,5 +1,13 @@
+/**
+ * @file version_spec.c
+ */
#include "spm.h"
+/**
+ *
+ * @param str
+ * @return
+ */
char *version_suffix_get_alpha(char *str) {
size_t i;
size_t len = strlen(str);
@@ -12,6 +20,11 @@ char *version_suffix_get_alpha(char *str) {
return NULL;
}
+/**
+ *
+ * @param str
+ * @return
+ */
char *version_suffix_get_modifier(char *str) {
size_t i;
char *modifiers[] = {
@@ -31,6 +44,11 @@ char *version_suffix_get_modifier(char *str) {
return NULL;
}
+/**
+ *
+ * @param str
+ * @return
+ */
int64_t version_suffix_modifier_calc(char *str) {
int64_t result = 0;
char *tmp_s = str;
@@ -79,6 +97,11 @@ int64_t version_suffix_modifier_calc(char *str) {
return result;
}
+/**
+ *
+ * @param str
+ * @return
+ */
int version_suffix_alpha_calc(char *str) {
int x = 0;
char chs[255];
@@ -116,6 +139,11 @@ int version_suffix_alpha_calc(char *str) {
return x;
}
+/**
+ *
+ * @param version_str
+ * @return
+ */
int64_t version_from(const char *version_str) {
const char *delim = ".";
int64_t result = 0;
@@ -199,6 +227,11 @@ int64_t version_from(const char *version_str) {
return result;
}
+/**
+ *
+ * @param op
+ * @return
+ */
int version_spec_from(const char *op) {
int flags = VERSION_NOOP;
size_t len = strlen(op);
@@ -222,6 +255,12 @@ int version_spec_from(const char *op) {
return flags;
};
+/**
+ *
+ * @param a
+ * @param b
+ * @return
+ */
static int _find_by_spec_compare(const void *a, const void *b) {
const ManifestPackage *aa = *(const ManifestPackage**)a;
const ManifestPackage *bb = *(const ManifestPackage**)b;
@@ -230,6 +269,14 @@ static int _find_by_spec_compare(const void *a, const void *b) {
return version_a > version_b;
}
+/**
+ *
+ * @param manifest
+ * @param name
+ * @param op
+ * @param version_str
+ * @return
+ */
ManifestPackage **find_by_spec(Manifest *manifest, const char *name, const char *op, const char *version_str) {
int64_t version_a = 0;
int64_t version_b = 0;