Skip to content

Commit

Permalink
remove gcov_report from goals, fixed codestyle, changed test.sh from …
Browse files Browse the repository at this point in the history
…cmake to make build system
  • Loading branch information
Georgyshul committed Oct 29, 2023
1 parent fa8cab5 commit 955d723
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 2,947 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Guide how to build, run, and use in your applications.
| make [all] | build library calc.a and run tests |
| make calc.a | build library calc.a |
| make test | run unit tests |
| make gcov_report | generate test coverage HTML report |
| make codestyle | apply google codestyle in project |
| make clean | clean build files |
| make run | build and run command line calculator |

### Include in other applications
Expand Down
2,579 changes: 0 additions & 2,579 deletions src/Doxyfile

This file was deleted.

89 changes: 7 additions & 82 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CXX=g++

SRC_BACK_DIR = back
TEST_DIR = gtest
GTEST_DIR = /home/googletest/googletest/googletest
GTEST_DIR = /home/georgy/googletest/googletest/googletest/googletest
GTEST_DIR_SRC = $(GTEST_DIR)/src

SRC_BACK := $(shell find ${SRC_BACK_DIR} -name "*.c" | sed -e 's/\.\///')
Expand All @@ -26,61 +26,7 @@ GTEST_HEADERS=$(GTEST_DIR)/include/gtest/*.h \

GTEST_SRCS_ = $(GTEST_DIR_SRC)/*.cc $(GTEST_DIR_SRC)/*.h $(GTEST_HEADERS)

# QT_PROJECT_NAME = front
# QT_PROJECT_FOLDER = ./$(QT_PROJECT_NAME)
# QT_PRO = $(QT_PROJECT_NAME).pro
# QT_MAKEFILE = $(QT_PROJECT_NAME)_Makefile
# QT_BUILD_FOLDER = build
# QT_APP_FOLDER = ../App
# DIST_FOLDER_NAME = SmartCalc-1.0

all: calc.a test run

# install: generate_make
# @echo "Building application..."
# @cd ./$(QT_BUILD_FOLDER) && make -sf $(QT_MAKEFILE)
# @echo "Application builded."
# @echo -n "Moving application to folder \"$(QT_APP_FOLDER)\"..."
# @mkdir ./$(QT_APP_FOLDER)
# ifeq ($(OS), Darwin)
# @mv ./$(QT_BUILD_FOLDER)/$(QT_PROJECT_NAME).app/Contents/MacOS/SmartCalc ./$(QT_APP_FOLDER)/Smart_Calc.app
# else
# @mv ./$(QT_BUILD_FOLDER)/$(QT_PROJECT_NAME) ./$(QT_APP_FOLDER)/Smart_Calc
# endif
# @echo " Done."
# @echo -n "Deleting build folder..."
# @rm -rf $(QT_BUILD_FOLDER)
# @echo " Done."
# @echo "Installation complete!"

# generate_make:
# @qmake $(QT_PROJECT_FOLDER)/$(QT_PRO) -o ./$(QT_BUILD_FOLDER)/$(QT_MAKEFILE)
# @rm -rf .qmake.stash

# uninstall:
# @echo -n "Uninstalling application..."
# @rm -rf $(QT_APP_FOLDER)
# @echo " Done"

# TAR_DIR = SmartCalc_v1.0_v1.0_Archive

# dist:
# rm -Rf $(TAR_DIR)
# mkdir $(TAR_DIR)
# mkdir $(TAR_DIR)/src
# cp $(SRC_BACK_DIR)/* $(SRC_FRONT_DIR)/* $(TAR_DIR)/src
# tar cvzf $(TAR_DIR).tgz $(TAR_DIR)
# mv $(TAR_DIR).tgz ..
# rm -Rf $(TAR_DIR)

# dvi:
# doxygen Doxyfile
# ifeq ($(shell uname), Linux)
# @firefox html/index.html
# else
# @open html/index.html
# endif

all: calc.a test

calc.a: $(OBJS_BACK)
@mkdir -p ${BUILD_DIR}
Expand Down Expand Up @@ -108,41 +54,20 @@ gtest_main.a : gtest-all.o gtest_main.o
$(BUILD_TEST_DIR)/%.o: $(TEST_DIR)/%.cpp $(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

test: $(OBJS_TEST) gtest_main.a calc.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@.out


#test: $(OBJS_TEST) calc.a
# $(CC) $(CFLAGS) $^ $(LDFLAGS) -o test.out
# ./test.out
#
#${BUILD_TEST_DIR}/%.o: %.c
# @mkdir -p $(dir $@)
# $(CC) $(LDFLAGS) -c $< -o $@
./test.out

run: entry.c calc.a
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o run.out
./run.out


gcov_report:
$(CC) $(CFLAGS) $(GCOVFLAGS) $(SRC_BACK) $(TEST_DIR)/*.cpp $(LDFLAGS) -o gcov_main
./gcov_main
lcov --capture --directory . --output-file coverage.info
genhtml coverage.info --output-directory gcov_report
rm -Rf *.gcda *.cov *.gcno *.info
ifeq ($(shell uname), Linux)
@firefox gcov_report/index.html
else
@open gcov_report/index.html
endif


codestyle:
clang-format -i --style=google $(SRC_BACK_DIR)/*.c $(TEST_DIR)/*.c
clang-format -i --style=google $(SRC_BACK_DIR)/*.h $(TEST_DIR)/*.h
clang-format -i --style=google $(SRC_FRONT_DIR)/*.h $(SRC_FRONT_DIR)/*.h

clang-format -i --style=google $(SRC_BACK_DIR)/*.c $(TEST_DIR)/*.cpp
clang-format -i --style=google $(SRC_BACK_DIR)/*.h
clang-format -i --style=google entry.c

clean:
rm -f *.gcda *.gcov *.o *.gcno
Expand Down
2 changes: 1 addition & 1 deletion src/back/calc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#include <math.h>

#include "to_polish.h"
#include "parser.h"
#include "stack.h"
#include "to_polish.h"

double calc(token *postfix, double var_value, int size);

Expand Down
3 changes: 2 additions & 1 deletion src/back/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ token parse_function_to_token(char **str, int *e_flag) {
return parsed_function;
}

void make_function_token(token *function, int type, int code, int priority, int associativity) {
void make_function_token(token *function, int type, int code, int priority,
int associativity) {
function->type = type;
function->code = code;
function->priority = priority;
Expand Down
3 changes: 2 additions & 1 deletion src/back/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ int is_digit(char c);
char *cut_number_from_str(char *start, char *end);
void check_number(char **number_str);
token parse_function_to_token(char **str, int *e_flag);
void make_function_token(token *function, int type, int code, int priority, int associativity);
void make_function_token(token *function, int type, int code, int priority,
int associativity);
void mark_unary(token *func, int array_idx, token *token_array);

void check_valid_expression(token *token_array, int *e_flag);
Expand Down
10 changes: 5 additions & 5 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function display_usage {
echo " all: Build the library (calc.a) and run tests"
echo " calc.a: Build the library (calc.a)"
echo " test: Run unit tests"
echo " gcov_report: Generate test coverage HTML report"
echo " codestyle: Apply Google code style to the project"
echo " clean: Clean build files"
echo " run: Build and run the command line calculator"
}

Expand All @@ -31,14 +31,14 @@ case "$1" in
# Run unit tests
make test
;;
"gcov_report")
# Generate test coverage HTML report
make gcov_report
;;
"codestyle")
# Apply Google code style to the project
make codestyle
;;
"clean")
# Clean build files
make clean
;;
"run")
# Build and run the command line calculator
make run
Expand Down
48 changes: 24 additions & 24 deletions src/entry.c
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#include "back/calc.h"
#include <stdio.h>
#include <string.h>

#include "back/calc.h"

int main() {
char expression[MAX_SIZE] = {0};
char expression[MAX_SIZE] = {0};

printf("\nEnter expression to calculate\n---> ");
fgets(expression, MAX_SIZE, stdin);

printf("\nEnter expression to calculate\n---> ");
fgets(expression, MAX_SIZE, stdin);
double var = 0;
int length = strlen(expression);

double var = 0;
int length = strlen(expression);
// Delete '\n' from expression
if (expression[length - 1] == '\n') {
expression[length - 1] = '\0';
}

// Delete '\n' from expression
if (expression[length - 1] == '\n') {
expression[length - 1] = '\0';
}
int size = 0;
token *infix = parse_str(expression, &size);
token *postfix = to_polish(infix, size);

int size = 0;
token *infix = parse_str(expression, &size);
token *postfix = to_polish(infix, size);
// If 'x' present in expression and expression is correct, read 'x' value
if (size && strchr(expression, 'x')) {
printf("\nEnter variable\n---> ");
scanf("%lf", &var);
}

// If 'x' present in expression and expression is correct, read 'x' value
if (size && strchr(expression, 'x')) {
printf("\nEnter variable\n---> ");
scanf("%lf", &var);
}
double res = calc(postfix, var, size);

double res = calc(postfix, var, size);
free(infix);
free(postfix);

free(infix);
free(postfix);
printf("Result = %f\n", res);

printf("Result = %f\n", res);

return 0;
return 0;
}
Loading

0 comments on commit 955d723

Please sign in to comment.