diff --git a/Makefile b/Makefile index f3edacc1046207fa4a25968f2da426e38f9625e7..4df20b7cc5f966dd24b1f90889fb60259e97c1fd 100755 --- a/Makefile +++ b/Makefile @@ -20,18 +20,18 @@ DOBJDIR := $(OUTDIR)/debug/tmp/bin ROBJS := $(SRCS:$(SRCDIR)/%.c=$(ROBJDIR)/%.o) DOBJS := $(SRCS:$(SRCDIR)/%.c=$(DOBJDIR)/%.o) CPPFLAGS = -I./$(SRCDIR)/ -# CC=clang -# CFLAGS = -Weverything +#CC=clang-6.0 +#CFLAGS = -Weverything -O2 ############## #Target Specific settings ############## debug : OBJDIR = $(DOBJDIR) debug : OBJS = $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o) -debug : CFLAGS = -std='c11' -g3 -Wall -Wextra +debug : CFLAGS += -std='c11' -g3 -Wall -Wextra debug : BIN = $(DBINDIR)/$(PROJ) release : OBJDIR = $(ROBJDIR) release : OBJS = $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o) -release : CFLAGS = -std='c11' -O2 -Wall -Wextra +release : CFLAGS += -std='c11' -O2 -Wall -Wextra release : BIN = $(RBINDIR)/$(PROJ) TIDY=/usr/bin/clang-tidy diff --git a/src/app_transport.c b/src/app_transport.c index 7520493d58dd6506bcde238e40d863b683d4ebed..82ff45be67b8af8c38b7ef433945a1fb881509c4 100644 --- a/src/app_transport.c +++ b/src/app_transport.c @@ -105,7 +105,7 @@ void Buy_A_Pass(void) { int dom = 0; /* get user type */ - char entry = Menu_Prompt_Char( + int entry = Menu_Prompt_Char( "What type of user?", "(1) Standard, (2) Student, (3) Elderly, (0) Worker", '0', '3'); switch (entry) { @@ -222,7 +222,7 @@ void Buy_A_Pass(void) { void Use_A_Pass(void) { /* determine the trans (portation) type to be used */ TransType trans = {0}; - char entry = Menu_Prompt_Char( + int entry = Menu_Prompt_Char( "What type of trans?", "(1) Bus, (2) Subway, (3) Rail, (4) Elderly Bus", '1', '4'); switch (entry) { diff --git a/src/menu.c b/src/menu.c index 581f09523949a366b15682d6e1cc924c87617e5b..356c8334b2d9859c2b38b95fa0e882c0edf5b842 100644 --- a/src/menu.c +++ b/src/menu.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <limits.h> /* Displays a title and waits for the user to enter a number. * Then clears stdin of all remaining characters including the @@ -16,8 +17,9 @@ * Returns the numeric value */ -int Menu_Prompt_Int(const char *title) { +int Menu_Prompt_Int(char const *title) { int entry = -1; + long ltmp = 0L; int retval = 0; int c = '\0'; char line[2] = ""; @@ -25,8 +27,11 @@ int Menu_Prompt_Int(const char *title) { while (entry < 0) { puts(title); fgets(line, sizeof line, stdin); - retval = strtol(line, NULL, 10); - + ltmp = strtol(line, NULL, 10); + if (ltmp < INT_MAX) { + retval = (int)ltmp; + } + if (retval == EOF) { entry = -1; } else { @@ -44,8 +49,8 @@ int Menu_Prompt_Int(const char *title) { * * This also clears the stdin including the \n. */ -char Menu_Prompt_Char(const char *title, const char *choices, const char begin, - const char end) { +int Menu_Prompt_Char(char const *title, char const *choices, char const begin, + char const end) { int entry = begin - 1; int c = '\0'; diff --git a/src/menu.h b/src/menu.h index 97a5d641f8dc22f80af436289c80d5ea04bbc175..4725d4869d04cdd1194a79b9d447c51df288c3e8 100644 --- a/src/menu.h +++ b/src/menu.h @@ -8,8 +8,8 @@ #ifndef MENU_H #define MENU_H 1 -int Menu_Prompt_Int(const char *title); -char Menu_Prompt_Char(const char *title, const char *choices, char begin, +int Menu_Prompt_Int(char const *title); +int Menu_Prompt_Char(char const *title, char const *choices, char begin, char end); #endif diff --git a/src/pass.c b/src/pass.c index 1fef92bf46faca3770be816c48fca622604cba99..c5c973cc90d95c48f70374d815859c1af0fb342d 100644 --- a/src/pass.c +++ b/src/pass.c @@ -11,8 +11,8 @@ * * returns the id of the newly created Pass */ -int Pass_Buy(Pass *pass, const UserType user, const TermType term, - const TransType trans, const int amount, const time_t expires) { +int Pass_Buy(Pass *pass, UserType const user, TermType const term, + TransType const trans, int const amount, time_t const expires) { pass->balance = amount; pass->trans = trans; pass->term = term; @@ -31,7 +31,7 @@ int Pass_Buy(Pass *pass, const UserType user, const TermType term, * but the version below shows that when written that way, this is more * readable, and maintainable. */ -bool Pass_Use(Pass *pass, const TransType trans) { +bool Pass_Use(Pass *pass, TransType const trans) { /***** SPECIAL CASE FOR WORKERS ****/ if (pass->user == USERTYPE_WORKER) { /* short circuit for workers */ @@ -71,7 +71,7 @@ bool Pass_Use(Pass *pass, const TransType trans) { * Simply returns the balance. This may be a bit lacking in functionality * but it is as specified. */ -int Pass_Check(const Pass *pass) { return pass->balance; } +int Pass_Check(Pass const *pass) { return pass->balance; } /* Gets an ordinal id for the Pass id's. It is utilitarian and would more likely * be a call to a database or algorithmic method of establishing card id's. diff --git a/src/pass.h b/src/pass.h index cc93c6c6c7e07db6d2ee7aacd3bde4dedb2fcdd8..e6b7d5e55131446c65b38c2821ee792238331ba2 100644 --- a/src/pass.h +++ b/src/pass.h @@ -27,7 +27,7 @@ typedef struct Transport_Pass { int Pass_Buy(Pass *pass, UserType user, TermType term, TransType trans, int amount, time_t expires); bool Pass_Use(Pass *pass, TransType trans); -int Pass_Check(const Pass *pass); +int Pass_Check(Pass const *pass); int get_next_id(void); #endif diff --git a/src/trans.c b/src/trans.c index d68f1583f069457a367d94ac95ca121162ddb74d..8029ed8a644f8cd9a4ab375e88aa76707f5d6504 100644 --- a/src/trans.c +++ b/src/trans.c @@ -41,7 +41,7 @@ static float DOW_Discounts[7] = {0.75, 1.0, 1.0, 1.0, 1.0, 1.0, 0.75}; * -1 indicates a currently unused value * it would be useful for future expansion * */ -int Trans_Ride_Rate(const TransType trans, const UserType user) { +int Trans_Ride_Rate(TransType const trans, UserType const user) { int base = Trans_Bases[trans]; float usr_disc = User_Discounts[user]; @@ -63,8 +63,8 @@ int Trans_Ride_Rate(const TransType trans, const UserType user) { * -1 indicates a currently unused value * it would be useful for future expansion * */ -int Trans_Month_Rate(const TransType trans, const UserType user, - const int dom) { +int Trans_Month_Rate(TransType const trans, UserType const user, + int const dom) { int base = Trans_Monthly[trans]; float usr_disc = User_Discounts[user]; float dom_disc = DOM_Discount[dom];