summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2023-07-26 11:40:36 -0500
committerDanny Holman <dholman@gymli.org>2023-07-26 11:40:36 -0500
commitf3d50195e43fd33e7f36e4e55a84af790b7de5d1 (patch)
tree271f11ccb2297375245df5f9783ca31d84dd5c52 /client
parentee0f0f95d6972e66c56812e0e3abe9275d5f0fdc (diff)
common: create the common directory
Create a directory for files that are shared between the reference client and server. Refactor the build scripts to reflect this restructuring. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'client')
-rw-r--r--client/Makefile.am3
-rw-r--r--client/configure.ac2
-rw-r--r--client/include/util.h13
-rw-r--r--client/src/util.c76
4 files changed, 3 insertions, 91 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index 4f994ee..3812ae5 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -1,2 +1,3 @@
bin_PROGRAMS = mrat
-mrat_SOURCES = src/mini-rat.c src/util.c
+mrat_SOURCES = src/mini-rat.c ../common/src/util.c
+mrat_CFLAGS = -I../common/include
diff --git a/client/configure.ac b/client/configure.ac
index 325f582..c67c929 100644
--- a/client/configure.ac
+++ b/client/configure.ac
@@ -12,7 +12,7 @@ AC_CONFIG_FILES([Makefile])
AC_CHECK_HEADERS([stdio.h stdlib.h string.h arpa/inet.h sys/socket.h], [], AC_MSG_ERROR([missing required headers]))
AX_CHECK_COMPILE_FLAG([-Wall], [CFLAGS+=" -Wall"])
-AX_CHECK_COMPILE_FLAG([-Wextra], [CFLAGS+= "-Wextra"])
+AX_CHECK_COMPILE_FLAG([-Wextra], [CFLAGS+=" -Wextra"])
AC_PROG_CC
AC_OUTPUT
diff --git a/client/include/util.h b/client/include/util.h
deleted file mode 100644
index 39c130b..0000000
--- a/client/include/util.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef MRAT_UTIL_H
-#define MRAT_UTIL_H
-
-#include <stddef.h>
-
-#define container_of(ptr, type, member) ({ \
- const typeof(((type*)0)->member)*__mptr = (ptr); \
- (type*)((char*)__mptr - offsetof(type, member)); })
-
-char* str_strip(char *str);
-char** str_split(char *str, const char *delim);
-
-#endif
diff --git a/client/src/util.c b/client/src/util.c
deleted file mode 100644
index f9053f5..0000000
--- a/client/src/util.c
+++ /dev/null
@@ -1,76 +0,0 @@
-#include <util.h>
-#include <string.h>
-#include <stdlib.h>
-
-char* str_rstrip(char *str) {
- size_t len = strlen(str) - 1;
- int brakes = 1;
- while (brakes) {
- switch (str[len]) {
- case '\n':
- str[len] = '\0';
- len--;
- break;
- case '\t':
- str[len] = '\0';
- len--;
- break;
- case ' ':
- str[len] = '\0';
- len--;
- break;
- default:
- brakes = 0;
- break;
- }
- }
- return str;
-}
-
-char* str_lstrip(char *str) {
- int brakes = 1;
- while (brakes) {
- switch (str[0]) {
- case '\n':
- str[0] = '\0';
- str++;
- break;
- case '\t':
- str[0] = '\0';
- str++;
- break;
- case ' ':
- str[0] = '\0';
- str++;
- break;
- default:
- brakes = 0;
- break;
- }
- }
- return str;
-}
-
-char* str_strip(char *str) {
- str_rstrip(str);
- str_lstrip(str);
- return str;
-}
-
-char** str_split(char *str, const char *delim) {
- size_t count = 0;
- char **ret = NULL;
- char *token;
- char *saveptr;
- token = strtok_r(str, delim, &saveptr);
- while (token != NULL) {
- count++;
- ret = realloc(ret, sizeof(char*) * count);
- ret[count-1] = strdup(str_strip(token));
- token = strtok_r(NULL, delim, &saveptr);
- }
- count++;
- ret = realloc(ret, sizeof(char*) * count);
- ret[count-1] = NULL;
- return ret;
-}