-
Notifications
You must be signed in to change notification settings - Fork 0
Iz1 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paulnopaul
wants to merge
51
commits into
main
Choose a base branch
from
iz1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Iz1 #3
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
61d3e7d
Added .DS_Store to .gitignore
eace29b
updated gitignore
43ff072
Updated gitignore:
e195f9d
Initial project version
3808cc8
Updated project structure
16a4f8b
Tag name parsing addded
77b78bb
Updated ci
50993ff
Updated cmake version
f90e1d0
Added gtest initial
bf48262
Working attribute parser
77746ba
Updated ci script
9d5dd77
Updated cmakelists
d2128ad
update cmakelists
6e06807
updated build line
3d72a0b
update tests
fb52795
Added README.MD
83faa0a
Added correct tests for html_tag{:
96563d8
updated tests
5deef8a
tag parsing version added
9852dfe
Updated free function
52faee6
Updated tests
f71c01d
updated travis
b3d2cf2
updated travis
1154cdf
updated travis
5cc797f
updated travis
95809d1
reverted travis
49f8e62
Updated memcheck tests
e58bc21
Updated travis for memcheck
0a64c16
Updated travis
a055d85
updated travis
2438f8f
Added main app code
0f03d45
Added cppcheck
bee60d6
updated travis
efc3cf2
updated travis
3ad95c0
correct cppcheck for travis
a97c2e6
updated travis for cppcheck
908a5f8
updated travis
e63c6a2
Updated CmakeLIsts for gcov
9f0afab
added gcovr to tests
c5ed055
updated travis for gcovr
be08ddd
updated travis for gcovr
964d0b1
updated travis for gcov
f8c099b
updated travis for gcov
839dfbe
Solved pull request problems
141de92
removed commented code
1e80a5c
added nullptr check
c54493a
added parentheses
f053596
corrected funcion exit
0d4bc0d
check_attr_format refactor
6bcff01
solved pr problems
427f216
added nullptr checks
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,8 @@ | |
| *.exe | ||
| *.out | ||
| *.app | ||
|
|
||
| # Macos things | ||
| *.DS_Store | ||
| *.idea/ | ||
| *cmake-build-debug | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| language: cpp | ||
| os: linux | ||
| dist: xenial | ||
| compiler: gcc | ||
|
|
||
|
|
||
| before_script: | ||
| - cd iz1 | ||
| - mkdir build | ||
| - cd build | ||
|
|
||
| jobs: | ||
| # | ||
| # Valgrind | ||
| # | ||
| - os: linux | ||
| env: | ||
| - TEST="Valgrind" | ||
| addons: | ||
| apt: | ||
| packages: | ||
| - valgrind | ||
| script: | ||
| - cmake .. | ||
| - make | ||
| - ctest -T memcheck | ||
|
|
||
| # | ||
| # CppCheck | ||
| # | ||
| - os: linux | ||
| env: | ||
| - TEST="CppCheck" | ||
|
|
||
| script: | ||
| - cmake -DENABLE_CPPCHECK=ON .. | ||
| - make | ||
| - make check | ||
|
|
||
| # | ||
| # Coverage | ||
| # | ||
| # - os: linux | ||
| # env: | ||
| # - TEST="GCovr" | ||
| # addons: | ||
| # apt: | ||
| # packages: | ||
| # - gcov | ||
| # before_script: | ||
| # - pip3 install gcovr | ||
| # script: | ||
| # - cmake -DENABLE_GCOV | ||
| # - make | ||
| # - ctest | ||
| # - cd .. && gcovr | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| cmake_minimum_required(VERSION 3.1) | ||
|
|
||
| project(iz1 C CXX) | ||
|
|
||
| set(CMAKE_C_STANDARD 99) | ||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
|
||
| # | ||
| ### GCOV | ||
| # | ||
|
|
||
| if (ENABLE_GCOV) | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage -fprofile-arcs") | ||
| endif () | ||
|
|
||
|
|
||
| ## | ||
| ### Valgrind | ||
| ## | ||
|
|
||
| set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --leak-check=full") | ||
| set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --track-fds=yes") | ||
| set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --trace-children=yes") | ||
| set(MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --error-exitcode=1") | ||
|
|
||
|
|
||
| ## | ||
| ### Test definitions ### | ||
| ## | ||
|
|
||
| include(CTest) | ||
|
|
||
| configure_file(CMakeLists.txt.in | ||
| googletest-download/CMakeLists.txt) | ||
| execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . | ||
| WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) | ||
| execute_process(COMMAND ${CMAKE_COMMAND} --build . | ||
| WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) | ||
|
|
||
| add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src | ||
| ${CMAKE_BINARY_DIR}/googletest-build) | ||
|
|
||
| enable_testing() | ||
| add_subdirectory(test) | ||
|
|
||
|
|
||
| ## | ||
| ### Cppecheck | ||
| ## | ||
|
|
||
| if (ENABLE_CPPCHECK) | ||
|
|
||
| list(APPEND CPPCHECK_CMAKE_ARGS | ||
| "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}" | ||
| ) | ||
| include(ExternalProject) | ||
| ExternalProject_Add( | ||
| cppcheck | ||
| GIT_REPOSITORY https://github.com/danmar/cppcheck.git | ||
| GIT_TAG 1.79 | ||
| GIT_SHALLOW 1 | ||
| CMAKE_ARGS ${CPPCHECK_CMAKE_ARGS} | ||
| PREFIX ${CMAKE_BINARY_DIR}/external/cppcheck/prefix | ||
| TMP_DIR ${CMAKE_BINARY_DIR}/external/cppcheck/tmp | ||
| STAMP_DIR ${CMAKE_BINARY_DIR}/external/cppcheck/stamp | ||
| DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/cppcheck/download | ||
| SOURCE_DIR ${CMAKE_BINARY_DIR}/external/cppcheck/src | ||
| BINARY_DIR ${CMAKE_BINARY_DIR}/external/cppcheck/build | ||
| ) | ||
|
|
||
| list(APPEND CPPCHECK_ARGS | ||
| --enable=warning,style,performance,portability,unusedFunction | ||
| --std=c99 | ||
| --verbose | ||
| --error-exitcode=1 | ||
| --language=c | ||
| -DMAIN=main | ||
| -I ${CMAKE_SOURCE_DIR}/include | ||
| ${CMAKE_SOURCE_DIR}/include/*.h | ||
| ${CMAKE_SOURCE_DIR}/src/*.c | ||
| ) | ||
|
|
||
| add_custom_target( | ||
| check | ||
| COMMAND ${CMAKE_BINARY_DIR}/bin/cppcheck ${CPPCHECK_ARGS} | ||
| COMMENT "running cppcheck" | ||
| ) | ||
|
|
||
| endif () | ||
|
|
||
| ## | ||
| ### Source definitions ### | ||
| ## | ||
|
|
||
|
|
||
| include_directories("${PROJECT_SOURCE_DIR}/include") | ||
|
|
||
| file(GLOB sources | ||
| "${PROJECT_SOURCE_DIR}/include/html_tag/*.h" | ||
| "${PROJECT_SOURCE_DIR}/include/my_str/*.h" | ||
| "${PROJECT_SOURCE_DIR}/src/*.c") | ||
|
|
||
| add_executable(iz1 ${sources}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| cmake_minimum_required(VERSION 3.1) | ||
|
|
||
| project(extern-download NONE) | ||
|
|
||
|
|
||
| include(ExternalProject) | ||
| ExternalProject_Add( | ||
| googletest | ||
| GIT_REPOSITORY https://github.com/google/googletest.git | ||
| GIT_TAG release-1.8.1 | ||
| SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" | ||
| BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" | ||
| CONFIGURE_COMMAND "" | ||
| BUILD_COMMAND "" | ||
| INSTALL_COMMAND "" | ||
| TEST_COMMAND "" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Индивидуальное задание 1 | ||
|
|
||
| ИЗ1 посвящено приобретению навыков безопасной работы с памятью на языке C с использованием базовых структур данных и налаживания базовой инфраструктуры для автоматической проверки кода. В качестве результата ИЗ2 ожидается: | ||
| * грамотное разбиение проекта на файлы; | ||
| * использование безопасного стиля программирования - проверка возможных ошибок, корректное завершение программы в случае их возникновения и правильная работа с памятью; | ||
| * максимальное покрытие кода юнит-тестами; | ||
| * рабочий CI, включающего в себя автоматическую сборку проекта, статический анализ кода, прохождение линтеров, valgrind, запуск юнит-тестов и получение отчёта о покрытии кода тестами | ||
| * все автоматические проверки должны проходить на итоговой версии, которая проходит ревью | ||
| Вариант #23 | ||
| Создать структуру для хранения информации об HTML-теге: его имени, признаке «открывающий/закрывающий» и атрибутах тега. Составить с ее использованием программу, включающую в себя функцию, принимающую на вход текстовую строку с одним тегом. На выход функция должна возвращать указатель на инициализированную структуру. | ||
|
|
||
| Требования к оформлению: | ||
| Программа должна быть реализована на языке C и работать для произвольных наборов входных данных (в том числе и ошибочных), вводимых пользователем с клавиатуры. Должна быть выполнена грамотная декомпозиция на функции и файлы. | ||
| Помимо самой программы необходимо: | ||
| – разработать набор юнит-тестов, проверяющих корректную работу реализованных функций. Обеспечить максимальное покрытие исходного кода тестами; | ||
| – оформить задачу в виде Merge Request отдельной ветки в основную ветку проекта. | ||
| Внимание: в основной ветке проекта никакого кода быть не должно! | ||
| – развернуть CI, в рамках которого автоматизировать сборку проекта, прохождение юнит-тестов под valgrind, генерацию отчёта о покрытии кода тестами, линтера и статического анализатора исходного кода; | ||
| – после прохождения всех проверок необходимо отправить код на ревью своему преподавателю; | ||
| – ревью - процесс итерационный. До наступления дедлайна можно проходить несколько итераций, улучшая свою оценку. Решения после дедлайна не принимаются; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #ifndef IZ1_ATTR_H | ||
| #define IZ1_ATTR_H | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdbool.h> | ||
|
|
||
| typedef struct | ||
| { | ||
| char *name; | ||
| char *value; | ||
| } tag_attr_t; | ||
|
|
||
| // Функция проверки аттрибута тега (тег располагается в начале строкии и | ||
| // заканчивается либо символом '>', либо пробелом. Конец аттрибута записывается | ||
| // в переменную attr_end | ||
| bool check_attr_format(const char *str, size_t *attr_end); | ||
|
|
||
| tag_attr_t *parse_attr(const char *str, int *attr_end); | ||
|
|
||
| tag_attr_t **parse_attr_arr(const char *str, size_t count); | ||
|
|
||
| void free_attr(tag_attr_t **attr); | ||
|
|
||
| #endif //IZ1_ATTR_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Создать структуру для хранения информации об HTML-теге: его имени, признаке «открывающий/закрывающий» | ||
| * и атрибутах тега. Составить с ее использованием программу, включающую в себя функцию, принимающую на | ||
| * вход текстовую строку с одним тегом. На выход функция должна возвращать указатель на инициализированную структуру. | ||
| * | ||
| * Примеры тегов | ||
| * <a> | ||
| * <a href="abc"> | ||
| * </a> | ||
| * <tag_name attribute1=value attribute2=value> | ||
| * <tag_name attribute1="value1 value2" attribute2="value3 value4"> | ||
| * </tag_name> | ||
| */ | ||
|
|
||
| #ifndef IZ1_HTML_TAG_H | ||
| #define IZ1_HTML_TAG_H | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
|
|
||
| #include "attr.h" | ||
|
|
||
| typedef struct | ||
| { | ||
| char *name; | ||
| bool is_opening; | ||
| size_t attributes_count; | ||
| tag_attr_t **attributes; | ||
| } html_tag; | ||
|
|
||
| bool check_html_tag_format(const char *str); | ||
|
|
||
| html_tag *parse_tag(const char *str); | ||
|
|
||
| size_t parse_status(const char *str, html_tag *tag); | ||
|
|
||
| void free_tag(html_tag **tag); | ||
|
|
||
| #endif //IZ1_HTML_TAG_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef IZ1_ALG_H | ||
| #define IZ1_ALG_H | ||
|
|
||
| #define ASCII_NAME_ALLOWED "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789\"-" | ||
|
|
||
| int str_find(const char *str, char c); | ||
|
|
||
| int str_first_char_occurence(const char *str, const char *c); | ||
|
|
||
| int str_count(const char *str, char c); | ||
|
|
||
| #endif //IZ1_ALG_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef IZ1_MEM_H | ||
| #define IZ1_MEM_H | ||
|
|
||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
|
|
||
| size_t str_create_ncopy(char **to_allocate, const char *to_copy, size_t n); | ||
|
|
||
| size_t str_create_word(char **to_allocate, const char *src, const char *sep); | ||
|
|
||
| #endif //IZ1_MEM_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #include "my_str/alg.h" | ||
|
|
||
| int str_find(const char *str, char c) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. проверка на nullptr |
||
| { | ||
| if (!str) | ||
| return -1; | ||
|
|
||
| int i = 0; | ||
| while (str[i] != c && str[i] != '\0') | ||
| ++i; | ||
| return i; | ||
| } | ||
|
|
||
| int str_first_char_occurence(const char *str, const char *c) | ||
| { | ||
| if (!str) | ||
| return -1; | ||
|
|
||
| int i = 0; | ||
| while (c[str_find(c, str[i])] == '\0' && str[i] != '\0') | ||
| ++i; | ||
| return i; | ||
| } | ||
|
|
||
| int str_count(const char *str, char c) | ||
| { | ||
| if (!str) | ||
| return -1; | ||
|
|
||
| int count = 0; | ||
| while (*str != '\0') | ||
| count += (*(str++) == c); | ||
| return count; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
поясни сигнатуру. речь о проверке формата, но при этом есть второй аргумент.
кажется, что для проверки формата достаточно сигнатуры:
bool check_attr_format(const char* ftm);
либо проблема в дизайне, либо явно стоит указать комментарием назначение второго аргумента