mirror of
https://github.com/theoludwig/libcproject.git
synced 2024-11-08 22:31:31 +01:00
feat: first release
This commit is contained in:
parent
0fa82c5772
commit
cf6b7db16d
13
.editorconfig
Normal file
13
.editorconfig
Normal file
@ -0,0 +1,13 @@
|
||||
# For more information see: <https://editorconfig.org/>
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* text=auto eol=lf
|
20
.github/ISSUE_TEMPLATE/BUG.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/BUG.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: '🐛 Bug Report'
|
||||
about: 'Report an unexpected problem or unintended behavior.'
|
||||
title: '[Bug]'
|
||||
labels: 'bug'
|
||||
---
|
||||
|
||||
<!--
|
||||
Please provide a clear and concise description of what the bug is. Include
|
||||
screenshots if needed. Please make sure your issue has not already been fixed.
|
||||
-->
|
||||
|
||||
## Steps To Reproduce
|
||||
|
||||
1. Step 1
|
||||
2. Step 2
|
||||
|
||||
## The current behavior
|
||||
|
||||
## The expected behavior
|
18
.github/ISSUE_TEMPLATE/DOCUMENTATION.md
vendored
Normal file
18
.github/ISSUE_TEMPLATE/DOCUMENTATION.md
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
name: '📜 Documentation'
|
||||
about: 'Correct spelling errors, improvements or additions to documentation files (README, CONTRIBUTING...).'
|
||||
title: '[Documentation]'
|
||||
labels: 'documentation'
|
||||
---
|
||||
|
||||
<!-- Please make sure your issue has not already been fixed. -->
|
||||
|
||||
## Documentation
|
||||
|
||||
<!-- Please uncomment the type of documentation problem this issue address -->
|
||||
|
||||
<!-- Documentation is Missing -->
|
||||
<!-- Documentation is Confusing -->
|
||||
<!-- Documentation has Typo errors -->
|
||||
|
||||
## Proposal
|
20
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: '✨ Feature Request'
|
||||
about: 'Suggest a new feature idea.'
|
||||
title: '[Feature]'
|
||||
labels: 'feature request'
|
||||
---
|
||||
|
||||
<!-- Please make sure your issue has not already been fixed. -->
|
||||
|
||||
## Description
|
||||
|
||||
<!-- A clear and concise description of the problem or missing capability... -->
|
||||
|
||||
## Describe the solution you'd like
|
||||
|
||||
<!-- If you have a solution in mind, please describe it. -->
|
||||
|
||||
## Describe alternatives you've considered
|
||||
|
||||
<!-- Have you considered any alternative solutions or workarounds? -->
|
20
.github/ISSUE_TEMPLATE/IMPROVEMENT.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/IMPROVEMENT.md
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
name: '🔧 Improvement'
|
||||
about: 'Improve structure/format/performance/refactor/tests of the code.'
|
||||
title: '[Improvement]'
|
||||
labels: 'improvement'
|
||||
---
|
||||
|
||||
<!-- Please make sure your issue has not already been fixed. -->
|
||||
|
||||
## Type of Improvement
|
||||
|
||||
<!-- Please uncomment the type of improvements this issue address -->
|
||||
|
||||
<!-- Files and Folders Structure -->
|
||||
<!-- Performance -->
|
||||
<!-- Refactoring code -->
|
||||
<!-- Tests -->
|
||||
<!-- Not Sure? -->
|
||||
|
||||
## Proposal
|
8
.github/ISSUE_TEMPLATE/QUESTION.md
vendored
Normal file
8
.github/ISSUE_TEMPLATE/QUESTION.md
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
name: '🙋 Question'
|
||||
about: 'Further information is requested.'
|
||||
title: '[Question]'
|
||||
labels: 'question'
|
||||
---
|
||||
|
||||
### Question
|
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
7
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<!-- Please first discuss the change you wish to make via issue before making a change. It might avoid a waste of your time. -->
|
||||
|
||||
## What changes this PR introduce?
|
||||
|
||||
## List any relevant issue numbers
|
||||
|
||||
## Is there anything you'd like reviewers to focus on?
|
22
.github/workflows/ci.yml
vendored
Normal file
22
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
name: 'CI'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [develop]
|
||||
pull_request:
|
||||
branches: [master, develop]
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.0.0'
|
||||
|
||||
- name: 'Install Build Tools'
|
||||
run: 'sudo apt-get install --yes build-essential gcc make clang-format'
|
||||
|
||||
- run: 'make'
|
||||
- run: 'make run'
|
||||
- run: 'make test'
|
||||
- run: 'make lint'
|
||||
- run: 'make clean'
|
41
.github/workflows/release.yml
vendored
Normal file
41
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: 'Release'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: 'actions/checkout@v3.1.0'
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: 'Import GPG key'
|
||||
uses: 'crazy-max/ghaction-import-gpg@v4'
|
||||
with:
|
||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
git_user_signingkey: true
|
||||
git_commit_gpgsign: true
|
||||
|
||||
- name: 'Install Build Tools'
|
||||
run: 'apt-get install --yes build-essential gcc make clang-format'
|
||||
|
||||
- run: 'make set_version'
|
||||
|
||||
- name: 'Use Node.js'
|
||||
uses: 'actions/setup-node@v3.1.0'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
|
||||
- name: 'Install Release Tools'
|
||||
run: 'npm install --global semantic-release @semantic-release/git @semantic-release/exec @saithodev/semantic-release-backmerge'
|
||||
|
||||
- name: 'Release'
|
||||
run: 'semantic-release'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
GIT_COMMITTER_NAME: ${{ secrets.GIT_NAME }}
|
||||
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_EMAIL }}
|
39
.releaserc.json
Normal file
39
.releaserc.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"branches": ["master"],
|
||||
"plugins": [
|
||||
[
|
||||
"@semantic-release/commit-analyzer",
|
||||
{
|
||||
"preset": "conventionalcommits"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@semantic-release/release-notes-generator",
|
||||
{
|
||||
"preset": "conventionalcommits"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@semantic-release/exec",
|
||||
{
|
||||
"prepareCmd": "make set_version",
|
||||
"publishCmd": "./bin/set_version.exe ${nextRelease.version}"
|
||||
}
|
||||
],
|
||||
[
|
||||
"@semantic-release/git",
|
||||
{
|
||||
"assets": ["version.h"],
|
||||
"message": "chore(release): ${nextRelease.version} [skip ci]"
|
||||
}
|
||||
],
|
||||
"@semantic-release/github",
|
||||
[
|
||||
"@saithodev/semantic-release-backmerge",
|
||||
{
|
||||
"branches": [{ "from": "master", "to": "develop" }],
|
||||
"backmergeStrategy": "merge"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
132
CODE_OF_CONDUCT.md
Normal file
132
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,132 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
contact@divlo.fr.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][mozilla coc].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][faq]. Translations are available
|
||||
at [https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
||||
[mozilla coc]: https://github.com/mozilla/diversity
|
||||
[faq]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
46
CONTRIBUTING.md
Normal file
46
CONTRIBUTING.md
Normal file
@ -0,0 +1,46 @@
|
||||
# 💡 Contributing
|
||||
|
||||
Thanks a lot for your interest in contributing to **libcproject**! 🎉
|
||||
|
||||
## Types of contributions
|
||||
|
||||
- Reporting a bug.
|
||||
- Suggest a new feature idea.
|
||||
- Correct spelling errors, improvements or additions to documentation files (README, CONTRIBUTING...).
|
||||
- Improve structure/format/performance/refactor/tests of the code.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
- **Please first discuss** the change you wish to make via [issue](https://github.com/Divlo/libcproject/issues) before making a change. It might avoid a waste of your time.
|
||||
|
||||
- Ensure your code respect linting.
|
||||
|
||||
- Make sure your **code passes the tests**.
|
||||
|
||||
If you're adding new features to **libcproject**, please include tests.
|
||||
|
||||
## Commits
|
||||
|
||||
The commit message guidelines respect [@commitlint/config-conventional](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional) and [Semantic Versioning](https://semver.org/) for releases.
|
||||
|
||||
### Types
|
||||
|
||||
Types define which kind of changes you made to the project.
|
||||
|
||||
| Types | Description |
|
||||
| -------- | ------------------------------------------------------------------------------------------------------------ |
|
||||
| feat | A new feature. |
|
||||
| fix | A bug fix. |
|
||||
| docs | Documentation only changes. |
|
||||
| style | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc). |
|
||||
| refactor | A code change that neither fixes a bug nor adds a feature. |
|
||||
| perf | A code change that improves performance. |
|
||||
| test | Adding missing tests or correcting existing tests. |
|
||||
| build | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm). |
|
||||
| ci | Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs). |
|
||||
| chore | Other changes that don't modify src or test files. |
|
||||
| revert | Reverts a previous commit. |
|
||||
|
||||
### Scopes
|
||||
|
||||
Scopes define what part of the code changed.
|
13
Makefile
13
Makefile
@ -1,19 +1,21 @@
|
||||
LIBRARY_NAME = libcproject
|
||||
CC = gcc
|
||||
CC_FLAGS = -Wall -Wextra -Wfloat-equal -Wundef -Werror -std=c17 -pedantic -pedantic-errors -I./
|
||||
LIB_CC_FLAGS = -L. -l:./build/${LIBRARY_NAME}.a
|
||||
LIB = ./build/${LIBRARY_NAME}.a
|
||||
LIB_CC_FLAGS = -L. -l:${LIB}
|
||||
LIB_SOURCES = $(wildcard lib/*.c)
|
||||
TEST_SOURCES = $(wildcard test/*.c)
|
||||
HEADER_FILES = $(wildcard lib/*.h) $(wildcard test/*.h) ./${LIBRARY_NAME}.h
|
||||
MAIN_EXECUTABLE = bin/main.exe
|
||||
SET_VERSION_EXECUTABLE = bin/set_version.exe
|
||||
TEST_EXECUTABLE = bin/test.exe
|
||||
|
||||
.PHONY: all
|
||||
all: ${LIB_SOURCES}
|
||||
mkdir --parents ./build
|
||||
${CC} ${CC_FLAGS} -c ${LIB_SOURCES}
|
||||
rm --force ./build/${LIBRARY_NAME}.a
|
||||
ar -rcs ./build/${LIBRARY_NAME}.a *.o
|
||||
rm --force ${LIB}
|
||||
ar -rcs ${LIB} *.o
|
||||
rm --recursive --force *.o
|
||||
|
||||
.PHONY: run
|
||||
@ -22,6 +24,11 @@ run: all ./main.c
|
||||
${CC} ${CC_FLAGS} -o ${MAIN_EXECUTABLE} ./main.c ${LIB_CC_FLAGS}
|
||||
./${MAIN_EXECUTABLE} ${ARGS}
|
||||
|
||||
.PHONY: set_version
|
||||
set_version: all ./set_version.c
|
||||
mkdir --parents ./bin
|
||||
${CC} ${CC_FLAGS} -o ${SET_VERSION_EXECUTABLE} ./set_version.c ${LIB_CC_FLAGS}
|
||||
|
||||
.PHONY: test
|
||||
test: all ${TEST_SOURCES}
|
||||
mkdir --parents ./bin
|
||||
|
48
README.md
48
README.md
@ -1,8 +1,26 @@
|
||||
# libcproject
|
||||
<h1 align="center">libcproject</h1>
|
||||
|
||||
<p align="center">
|
||||
<strong>C static library easier to use than `libc` (C standard library).</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="./CONTRIBUTING.md"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" /></a>
|
||||
<a href="./LICENSE"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="Licence MIT"/></a>
|
||||
<a href="./CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg" alt="Contributor Covenant" /></a>
|
||||
<br />
|
||||
<a href="https://github.com/Divlo/libcproject/actions/workflows/ci.yml"><img src="https://github.com/Divlo/libcproject/actions/workflows/ci.yml/badge.svg?branch=develop" /></a>
|
||||
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits" /></a>
|
||||
<a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release" /></a>
|
||||
</p>
|
||||
|
||||
## About
|
||||
|
||||
`libcproject` is a C static library for learning purposes. It tries to implement useful functions/data structures while being easier to use than `libc` (C standard library) as much as possible.
|
||||
**libcproject** is a C static library for learning purposes. It tries to implement useful functions/data structures while being easier to use than `libc` (C standard library) as much as possible.
|
||||
|
||||
C is a low-level programming language and we often end up reinventing the wheel as the C standard library (`libc`) is quite small and in my humble opinion, not well designed.
|
||||
|
||||
**libcproject** solve this by providing common functions or data structures (`dictionary`, `linked_list`, `queue`, `stack`, etc.) we might need in our C projects.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@ -20,6 +38,16 @@ sudo apt-get install build-essential gcc make clang-format
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
make # to compile
|
||||
make run # to run main
|
||||
make test # to run unit tests
|
||||
make lint # to lint the code
|
||||
make clean # to clean up
|
||||
|
||||
nm ./build/libcproject.a # to see the symbols
|
||||
```
|
||||
|
||||
Steps to create a new C project that uses `libcproject`:
|
||||
|
||||
### Step 1: Compile `libcproject`
|
||||
@ -70,14 +98,12 @@ int main() {
|
||||
gcc -o ./main.exe ./main.c -L. -l:./libcproject/build/libcproject.a
|
||||
```
|
||||
|
||||
## Contributing
|
||||
## 💡 Contributing
|
||||
|
||||
```sh
|
||||
make # to compile
|
||||
make run # to run main
|
||||
make test # to run unit tests
|
||||
make lint # to lint the code
|
||||
make clean # to clean up
|
||||
Anyone can help to improve the project, submit a Feature Request, a bug report or even correct a simple spelling mistake.
|
||||
|
||||
nm ./build/libcproject.a # to see the symbols
|
||||
```
|
||||
The steps to contribute can be found in the [CONTRIBUTING.md](./CONTRIBUTING.md) file.
|
||||
|
||||
## 📄 License
|
||||
|
||||
[MIT](./LICENSE)
|
||||
|
@ -26,7 +26,7 @@ void dictionary_add(struct dictionary *dictionary, char *key, void *data) {
|
||||
}
|
||||
struct dictionary_item *item = NULL;
|
||||
for (size_t index = 0; index < dictionary->length && item == NULL; index++) {
|
||||
if (string_get_is_equal(key, dictionary->items[index]->key)) {
|
||||
if (string_equals(key, dictionary->items[index]->key)) {
|
||||
item = dictionary->items[index];
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ void dictionary_add(struct dictionary *dictionary, char *key, void *data) {
|
||||
void dictionary_remove(struct dictionary *dictionary, char *key) {
|
||||
bool found = false;
|
||||
for (size_t index = 0; index < dictionary->length && !found; index++) {
|
||||
if (string_get_is_equal(key, dictionary->items[index]->key)) {
|
||||
if (string_equals(key, dictionary->items[index]->key)) {
|
||||
free(dictionary->items[index]);
|
||||
dictionary->items[index] = dictionary->items[dictionary->length - 1];
|
||||
dictionary->length--;
|
||||
@ -56,7 +56,7 @@ void dictionary_remove(struct dictionary *dictionary, char *key) {
|
||||
struct dictionary_item *dictionary_get(struct dictionary *dictionary, char *key) {
|
||||
for (size_t index = 0; index < dictionary->length; index++) {
|
||||
struct dictionary_item *item = dictionary->items[index];
|
||||
if (string_get_is_equal(key, item->key)) {
|
||||
if (string_equals(key, item->key)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool mathematics_get_is_equal(const float number1, const float number2) {
|
||||
bool mathematics_equals(const float number1, const float number2) {
|
||||
return (number1 - number2) < MATHEMATICS_FLOAT_PRECISION;
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ unsigned long long mathematics_pow(unsigned long long base, unsigned long long e
|
||||
float mathematics_root(float number, unsigned int nth_root) {
|
||||
float result = number;
|
||||
float previous_result = 0;
|
||||
while (!mathematics_get_is_equal(result, previous_result)) {
|
||||
while (!mathematics_equals(result, previous_result)) {
|
||||
result = (((nth_root - 1) * previous_result) + (number / mathematics_pow(result, nth_root - 1))) / nth_root;
|
||||
previous_result = result;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool mathematics_get_is_equal(const float number1, const float number2);
|
||||
bool mathematics_equals(const float number1, const float number2);
|
||||
|
||||
unsigned long long mathematics_absolute_value(const long long number);
|
||||
|
||||
|
@ -142,7 +142,7 @@ char* string_reverse(const char* string) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool string_get_is_equal(const char* string1, const char* string2) {
|
||||
bool string_equals(const char* string1, const char* string2) {
|
||||
size_t string1_length = string_get_length(string1);
|
||||
size_t string2_length = string_get_length(string2);
|
||||
bool is_equal = string1_length == string2_length;
|
||||
|
@ -102,7 +102,7 @@ char* string_reverse(const char* string);
|
||||
* @param string2
|
||||
* @return true if the strings are equals, false otherwise
|
||||
*/
|
||||
bool string_get_is_equal(const char* string1, const char* string2);
|
||||
bool string_equals(const char* string1, const char* string2);
|
||||
|
||||
/**
|
||||
* @brief Check if the string is a integer.
|
||||
|
23
set_version.c
Normal file
23
set_version.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libcproject.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <version>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
char* content = "#ifndef __LIBCPROJECT_VERSION__\n";
|
||||
content = string_concatenate(content, "#define __LIBCPROJECT_VERSION__ \"");
|
||||
content = string_concatenate(content, argv[1]);
|
||||
content = string_concatenate(content, "\"\n\n");
|
||||
content = string_concatenate(content, "#endif\n");
|
||||
int result = filesystem_write("./version.h", content, string_get_length(content));
|
||||
if (result == -1) {
|
||||
fprintf(stderr, "Error: Could not write to file.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Success: Version set to %s.\n", argv[1]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -31,20 +31,20 @@ void mathematics_pow_test() {
|
||||
}
|
||||
|
||||
void mathematics_root_test() {
|
||||
assert(mathematics_get_is_equal(mathematics_root(0, 0), 0));
|
||||
assert(mathematics_get_is_equal(mathematics_root(0, 1), 0));
|
||||
assert(mathematics_get_is_equal(mathematics_root(2, 2), 1));
|
||||
assert(mathematics_get_is_equal(mathematics_root(27, 3), 3));
|
||||
assert(mathematics_get_is_equal(mathematics_root(16807, 5), 7));
|
||||
assert(mathematics_equals(mathematics_root(0, 0), 0));
|
||||
assert(mathematics_equals(mathematics_root(0, 1), 0));
|
||||
assert(mathematics_equals(mathematics_root(2, 2), 1));
|
||||
assert(mathematics_equals(mathematics_root(27, 3), 3));
|
||||
assert(mathematics_equals(mathematics_root(16807, 5), 7));
|
||||
}
|
||||
|
||||
void mathematics_square_root_test() {
|
||||
assert(mathematics_get_is_equal(mathematics_square_root(0), 0));
|
||||
assert(mathematics_get_is_equal(mathematics_square_root(1), 1));
|
||||
assert(mathematics_get_is_equal(mathematics_square_root(4), 2));
|
||||
assert(mathematics_get_is_equal(mathematics_square_root(9), 3));
|
||||
assert(mathematics_get_is_equal(mathematics_square_root(25), 5));
|
||||
assert(mathematics_get_is_equal(mathematics_square_root(100), 10));
|
||||
assert(mathematics_equals(mathematics_square_root(0), 0));
|
||||
assert(mathematics_equals(mathematics_square_root(1), 1));
|
||||
assert(mathematics_equals(mathematics_square_root(4), 2));
|
||||
assert(mathematics_equals(mathematics_square_root(9), 3));
|
||||
assert(mathematics_equals(mathematics_square_root(25), 5));
|
||||
assert(mathematics_equals(mathematics_square_root(100), 10));
|
||||
}
|
||||
|
||||
void mathematics_factorial_test() {
|
||||
|
@ -19,7 +19,7 @@ void string_test() {
|
||||
string_capitalize_test();
|
||||
string_total_occurrences_of_character_test();
|
||||
string_reverse_test();
|
||||
string_get_is_equal_test();
|
||||
string_equals_test();
|
||||
string_get_is_integer_test();
|
||||
string_split_test();
|
||||
string_join_test();
|
||||
@ -102,13 +102,13 @@ void string_reverse_test() {
|
||||
assert(assert_string_equal(string, "dlrow olleh"));
|
||||
}
|
||||
|
||||
void string_get_is_equal_test() {
|
||||
void string_equals_test() {
|
||||
char *string1 = "hello world";
|
||||
char *string2 = "dlrow olleh";
|
||||
char *string3 = "dlrow olleh";
|
||||
assert(!string_get_is_equal(string1, string2));
|
||||
assert(string_get_is_equal(string1, string1));
|
||||
assert(string_get_is_equal(string2, string3));
|
||||
assert(!string_equals(string1, string2));
|
||||
assert(string_equals(string1, string1));
|
||||
assert(string_equals(string2, string3));
|
||||
}
|
||||
|
||||
void string_get_is_integer_test() {
|
||||
|
@ -25,7 +25,7 @@ void string_total_occurrences_of_character_test();
|
||||
|
||||
void string_reverse_test();
|
||||
|
||||
void string_get_is_equal_test();
|
||||
void string_equals_test();
|
||||
|
||||
void string_get_is_integer_test();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user