aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-28 16:42:05 +0200
committerMattias Andrée <maandree@kth.se>2024-08-28 16:42:05 +0200
commita24071ae913b223487df78859c8d830f9e69f580 (patch)
treee2ec712cc29461c82cfdd477e8b1ba961b50018d /common.h
parentFirst commit (diff)
downloadanysum-a24071ae913b223487df78859c8d830f9e69f580.tar.gz
anysum-a24071ae913b223487df78859c8d830f9e69f580.tar.bz2
anysum-a24071ae913b223487df78859c8d830f9e69f580.tar.xz
Second commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'common.h')
-rw-r--r--common.h101
1 files changed, 91 insertions, 10 deletions
diff --git a/common.h b/common.h
index af153b9..a228fbd 100644
--- a/common.h
+++ b/common.h
@@ -1,11 +1,24 @@
/* See LICENSE file for copyright and license details. */
-#include <libsimple.h>
#ifndef SINGLE_THREADED
# include <pthread.h>
#else
# define pthread_barrier_t PhonyBarrier
#endif
#include <libhashsum.h>
+#include <libsimple.h>
+#include <libsimple-arg.h>
+LIBSIMPLE_NORETURN__ void usage(void);
+
+
+#if defined(__clang__)
+# pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
+# pragma clang diagnostic ignored "-Wcovered-switch-default"
+# pragma clang diagnostic ignored "-Wpadded"
+# pragma clang diagnostic ignored "-Wcomma"
+# pragma clang diagnostic ignored "-Wassign-enum"
+#elif defined(__GNUC__)
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+#endif
struct thread_data;
@@ -19,6 +32,14 @@ typedef struct {
#endif
+enum command {
+ SPECIALISED,
+ ANYSUM,
+ SHA3SUM,
+ BSUM
+};
+
+
enum format {
BINARY = 0,
LOWERCASE_HEX = 1,
@@ -31,9 +52,23 @@ enum format {
};
+struct config {
+ enum format format;
+ int verify;
+ int warn_improper_format;
+ int hexinput;
+ int recursive;
+ struct algorithm *algorithms;
+ size_t nalgorithms;
+ size_t threads;
+};
+
+
struct buffer {
char *buf;
- size_t length;
+ size_t ready;
+ size_t procoff;
+ size_t offset;
size_t size;
};
@@ -51,6 +86,7 @@ struct algorithm {
struct global_data {
void (*action)(struct algorithm *, struct global_data *);
enum format format;
+ int hexinput;
const char *file;
struct buffer *buffer;
struct algorithm *algorithms;
@@ -75,17 +111,62 @@ struct thread_data {
};
-int patheq(const char *have, const char *want, const char **end_out);
-int openfile(const char *path, int *is_new_fd_out, const char **fname_out);
-char *hex(char *out, const unsigned char *in, size_t n, const char *xdigits);
-void writeall(int fd, const void *data, size_t n, const char *fname);
+/* get.c */
+int calculate_and_print_each(char **files, struct algorithm *algorithms, size_t nalgorithms,
+ size_t nthreads, enum format format, int hexinput, int recursive);
+
+/* check.c */
+int verify_checksums(char **files, struct algorithm *algorithms, size_t nalgorithms, size_t nthreads,
+ enum format format, int warn_improper_format, int hexinput);
+
+/* barrier.c */
void barrierwait(pthread_barrier_t *barrier);
-void barriersend(struct barrier_group *group, struct global_data *global, void (*action)(struct algorithm *, struct global_data *));
-void format_result(struct algorithm *algorithm, const char *file, enum format format);
-int feedbuffer(int fd, struct buffer *buffer, const char *fname);
+void barriersend(struct barrier_group *group, struct global_data *global,
+ void (*action)(struct algorithm *, struct global_data *));
void createbarriergroup(struct barrier_group *group_out, size_t count, struct global_data *global);
void killbarriergroup(struct barrier_group *group, struct global_data *global);
+
+/* hash.c */
size_t inithashers(struct algorithm *algorithms, size_t nalgorithms);
void destroyhashers(struct algorithm *algorithms, size_t nalgorithms);
-void shiftbuffer(struct algorithm *algorithms, size_t nalgorithms, struct buffer *buffer);
int calculate(const char *file, struct barrier_group *group, struct global_data *global);
+
+/* write.c */
+void writeall(int fd, const void *data, size_t n, const char *fname);
+char *hex(char *out, const unsigned char *in, size_t n, const char *xdigits);
+void format_result(struct algorithm *algorithm, const char *file, enum format format, int hexinput);
+
+/* open.c */
+int patheq(const char *have, const char *want, const char **end_out);
+int openfile(const char *path, int *is_new_fd_out, const char **fname_out);
+
+/* read.c */
+int feedbuffer(int fd, struct buffer *buffer, const char *fname);
+void shiftbuffer(struct algorithm *algorithms, size_t nalgorithms, struct buffer *buffer);
+int unhex(struct buffer *buffer);
+
+/* proc.c */
+size_t getnproc(size_t default_count);
+size_t getautonthreads(void);
+
+/* command.c */
+enum command getcommand(const char **name_out, enum libhashsum_algorithm *algorithm_out);
+enum command getsupercommand(enum command cmd, enum libhashsum_algorithm algo);
+
+/* opts.c */
+int parseopt_vendor(void /* (struct config) */ *config, char *opt, char *val);
+char *parseopts(void *config, char *string, int (*parseopt)(void *, char *opt, char *val));
+
+/* cmdline_bsum.c */
+int cmdline_bsum(int argc, char **argv, enum command command, struct config *config,
+ const char **algostr, enum libhashsum_algorithm *algorithm, char **algostrbuf);
+
+/* cmdline_sha3sum.c */
+int cmdline_sha3sum(int argc, char **argv, enum command command, struct config *config,
+ const char **algostr, enum libhashsum_algorithm *algorithm, char **algostrbuf);
+
+/* cmdline_other.c */
+int cmdline_other(int argc, char **argv, enum command command, struct config *config);
+
+/* cmdline.c */
+void cmdline(int *argcp, char ***argvp, struct config *config);