summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile10
-rw-r--r--loans.c48
-rw-r--r--loans.h19
3 files changed, 72 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index d3a30d0..14f15ab 100644
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,14 @@
UNAME := $$( uname -s )
.if ${UNAME} == "Linux"
-CC=clang --std=gnu99
+CC=clang --std=gnu11
.else
-CC=clang --std=c99
+CC=clang --std=c11
.endif
AR=ar ruvcs
-CFLAGS=-Wall -Wextra -Werror -Weverything -Wpadded -pedantic
-LIBS=-lncurses -lm
+CFLAGS=-Wall -Wextra -Werror -Weverything -pedantic
+LIBS=-lform -lncurses -lm
BLDFLAGS=-g
RELFLAGS=-O2
@@ -18,7 +18,7 @@ HEAD=
OBJ=${DEPS:.c=.o}
LIB=las.a
-LDEPS=bullet_loan.c straight_line_loan.c mortgage_loan.c
+LDEPS=bullet_loan.c straight_line_loan.c mortgage_loan.c loans.c
LHEAD=contract.h loans.h
LOBJ=${LDEPS:.c=.o}
diff --git a/loans.c b/loans.c
new file mode 100644
index 0000000..f812aaf
--- /dev/null
+++ b/loans.c
@@ -0,0 +1,48 @@
+#include "loans.h"
+#include "stdio.h"
+
+loan loan_init(loan_type type, int n, int d, float r, float P) {
+ loan ret;
+ ret.type = type;
+
+ switch (type) {
+ case BULLET:
+ ret.c = bullet_init(n, d, r, P);
+ break;
+ case STRAIGHTLINE:
+ ret.c = sl_init(n, d, r, P);
+ break;
+ case MORTGAGE:
+ ret.c = mort_init(n, d, r, P);
+ break;
+ }
+
+ return ret;
+}
+
+float loan_update(loan l) {
+ switch (l.type) {
+ case BULLET:
+ return bullet_update(l.c);
+ case STRAIGHTLINE:
+ return sl_update(l.c);
+ case MORTGAGE:
+ return mort_update(l.c);
+ }
+ perror("Unkown Loan type supplied!");
+ exit(EXIT_FAILURE);
+}
+
+void loan_free(loan l) {
+ switch (l.type) {
+ case BULLET:
+ bullet_free(l.c);
+ break;
+ case STRAIGHTLINE:
+ sl_free(l.c);
+ break;
+ case MORTGAGE:
+ mort_free(l.c);
+ break;
+ }
+}
diff --git a/loans.h b/loans.h
index fd276ae..88bbb41 100644
--- a/loans.h
+++ b/loans.h
@@ -3,6 +3,20 @@
#include <math.h>
#include "contract.h"
+typedef enum loan_type {
+ BULLET,
+ STRAIGHTLINE,
+ MORTGAGE,
+} loan_type;
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpadded"
+typedef struct loan {
+ loan_type type;
+ contract *c;
+} loan;
+#pragma clang diagnostic pop
+
/**** BULLET LOAN ****/
contract *bullet_init(int n, int d, float r, float P);
float bullet_update(contract *);
@@ -17,3 +31,8 @@ void sl_free(contract *);
contract *mort_init(int n, int d, float r, float P);
float mort_update(contract *);
void mort_free(contract *);
+
+/**** GENERAL LOAN STUFF ****/
+loan loan_init(loan_type type, int n, int d, float r, float P);
+float loan_update(loan);
+void loan_free(loan);