1
0
mirror of https://github.com/Wessel/boilerplate-c.git synced 2026-06-06 02:35:46 +02:00

feat: initial commit and populate repo

This commit is contained in:
2023-02-06 15:13:16 +01:00
parent 5f7d41f1a6
commit 1c3bb4e360
17 changed files with 159 additions and 237 deletions

View File

@@ -1,6 +1,62 @@
root = true
[*]
cpp_indent_braces=false
cpp_indent_multi_line_relative_to=innermost_parenthesis
cpp_indent_within_parentheses=indent
cpp_indent_preserve_within_parentheses=false
cpp_indent_case_labels=false
cpp_indent_case_contents=true
cpp_indent_case_contents_when_block=false
cpp_indent_lambda_braces_when_parameter=true
cpp_indent_goto_labels=one_left
cpp_indent_preprocessor=leftmost_column
cpp_indent_access_specifiers=false
cpp_indent_namespace_contents=true
cpp_indent_preserve_comments=false
cpp_new_line_before_open_brace_namespace=ignore
cpp_new_line_before_open_brace_type=ignore
cpp_new_line_before_open_brace_function=ignore
cpp_new_line_before_open_brace_block=ignore
cpp_new_line_before_open_brace_lambda=ignore
cpp_new_line_scope_braces_on_separate_lines=false
cpp_new_line_close_brace_same_line_empty_type=false
cpp_new_line_close_brace_same_line_empty_function=false
cpp_new_line_before_catch=true
cpp_new_line_before_else=true
cpp_new_line_before_while_in_do_while=false
cpp_space_before_function_open_parenthesis=remove
cpp_space_within_parameter_list_parentheses=false
cpp_space_between_empty_parameter_list_parentheses=false
cpp_space_after_keywords_in_control_flow_statements=true
cpp_space_within_control_flow_statement_parentheses=false
cpp_space_before_lambda_open_parenthesis=false
cpp_space_within_cast_parentheses=false
cpp_space_after_cast_close_parenthesis=false
cpp_space_within_expression_parentheses=false
cpp_space_before_block_open_brace=true
cpp_space_between_empty_braces=false
cpp_space_before_initializer_list_open_brace=false
cpp_space_within_initializer_list_braces=true
cpp_space_preserve_in_initializer_list=true
cpp_space_before_open_square_bracket=false
cpp_space_within_square_brackets=false
cpp_space_before_empty_square_brackets=false
cpp_space_between_empty_square_brackets=false
cpp_space_group_square_brackets=true
cpp_space_within_lambda_brackets=false
cpp_space_between_empty_lambda_brackets=false
cpp_space_before_comma=false
cpp_space_after_comma=true
cpp_space_remove_around_member_operators=true
cpp_space_before_inheritance_colon=true
cpp_space_before_constructor_colon=true
cpp_space_remove_before_semicolon=true
cpp_space_after_semicolon=false
cpp_space_remove_around_unary_operator=true
cpp_space_around_binary_operator=insert
cpp_space_around_assignment_operator=insert
cpp_space_pointer_reference_alignment=left
cpp_space_around_ternary_operator=insert
cpp_wrap_preserve_blocks=one_liners
indent_style = space
indent_size = 2
charset = utf-8

View File

@@ -1,2 +0,0 @@
node_modules/
dist/

View File

@@ -1,65 +0,0 @@
{
"env": {
"es6": true,
"amd": true,
"node": true,
"mongo": true,
"jquery": true,
"browser": true,
"commonjs": true
},
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"forOf": true,
"spread": true,
"modules": true,
"classes": true,
"generators": true,
"restParams": true,
"regexUFlag": true,
"regexYFlag": true,
"globalReturn": true,
"destructuring": true,
"impliedStrict": true,
"blockBindings": true,
"defaultParams": true,
"octalLiterals": true,
"arrowFunctions": true,
"binaryLiterals": true,
"templateStrings": true,
"superInFunctions": true,
"unicodeCodePointEscapes": true,
"experimentalObjectRestSpread": true,
"objectLiteralShorthandMethods": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandProperties": true
}
},
"plugins": [],
"rules": {
"semi": "warn",
"indent": [ "off", "error" ],
"strict": "off",
"eqeqeq": "error",
"no-var": "warn",
"no-undef": "warn",
"valid-jsdoc": "warn",
"comma-dangle": "warn",
"no-dupe-args": "warn",
"no-dupe-keys": "warn",
"require-await": "warn",
"spaced-comment": "error",
"space-in-parens": "error",
"no-global-assign": "warn",
"no-duplicate-imports": "error",
"no-dupe-class-members": "error"
},
"globals": {
"_config": false,
"console": false
}
}

View File

@@ -1,12 +1,11 @@
# Contributing
If you wish to contribute to $(PROJECT_NAME), feel free to fork the repository and submit a pull request.
[ESLint](https://eslint.org/) is enforced to correct most typo's you make and keep the code style the same throughout the whole project, so it would be appreciated if you installed [ESLint](https://eslint.org/) to your editor of choice
If you wish to contribute to c-boilerplate, feel free to fork the repository and submit a pull request.
[EditorConfig](https://editorconfig.org) is enforced to correct most typo's you make and keep the code style the same throughout the whole project, so it would be appreciated if you installed [EditorConfig](https://editorconfig.org) to your editor of choice
## Setup
To get ready to work on the codebase, please do the following:
1. Fork & clone the repository, and make sure you're on the **master** branch
2. Run `yarn --dev` or `npm install --dev`
4. Code your heart out and test using `yarn test` or `npm run test`
6. [Submit a pull request](https://github.com/Wessel/$(PROJECT_NAME)/compare)
4. Code your heart out and test using `make dev`
6. [Submit a pull request](https://github.com/Wessel/c-boilerplate/compare)

2
.github/FUNDING.yml vendored
View File

@@ -1,2 +1,2 @@
patreon: wessel
github: wessel
ko_fi: wessel

View File

@@ -1,6 +1,6 @@
---
name: Bug Report
about: Report an issue with $(PROJECT_NAME)
about: Report an issue with c-boilerplate
title: "[BUG] Bug summed up in 1 sentence"
labels: bug
assignees: Wessel
@@ -11,13 +11,13 @@ assignees: Wessel
**Include a reproducible code sample here, if possible:**
```js
```c
// Place your code here
```
**Further details:**
- $(PROJECT_NAME) version:
- Node.js version:
- c-boilerplate version:
- gcc version:
- Operating system:
<!--

View File

@@ -1,6 +1,6 @@
---
name: Feature request
about: Request a feature for $(PROJECT_NAME)
about: Request a feature for c-boilerplate
title: "[ENHANCEMENT] Your idea"
labels: enhancement
assignees: Wessel

View File

@@ -1,6 +1,6 @@
---
name: Pull Request
about: Propose changes to $(PROJECT_NAME)
about: Propose changes to c-boilerplate
title: "[PR] Your changes"
labels: pullrequest
assignees: Wessel
@@ -14,6 +14,6 @@ assignees: Wessel
- [ ] Code changes have been tested and there aren't any typos in it
**Semantic versioning classification:**
- [ ] This PR changes $(PROJECT_NAME) core codebase (methods or parameters added)
- [ ] This PR changes c-boilerplate core codebase (methods or parameters added)
- [ ] This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
- [ ] This PR **only** includes non-code changes, like changes to documentation, README, etc.

7
.gitignore vendored
View File

@@ -1,3 +1,4 @@
tmp/
src/tmp
node_modules/
tmp/**/*
obj/**/*
out/**/*
!.gitkeep

144
.vscode/settings.json vendored
View File

@@ -1,144 +0,0 @@
/*
? Extensions: rainglow, eslint, material icon theme, gitlens, fish-vscode, Docker, EditorConfig for VS Code
? Popping and Locking theme, Sass, stylelint, SVG viewer, Trailing spaces, Auto renaming tags, Better Comments,
? Regex previewer
* Color themes: Banner (rainglow), Hyrule (rainglow), Azure (rainglow), Github (rainglow),
* Heroku (rainglow), Popping and Locking
* Comment legend:
/ Info
* Note
? Question
! Somenthing's wrong
> Changed
+ Added
- Removed
todo TODO
*/
{
"window.zoomLevel": 0,
"editor.fontSize": 13,
"editor.fontWeight": "200",
"editor.fontFamily": "'SFMono-Regular','Consolas','Liberation Mono','Menlo','Courier','monospace','Operator Mono SSm Lig','OperatorMonoSSmLig-Book'",
"editor.lineHeight": 20,
"editor.cursorStyle": "line",
"editor.lineNumbers": "relative",
"editor.cursorWidth": 0,
"editor.fontLigatures": true,
"editor.cursorBlinking": "blink",
"editor.minimap.enabled": true,
"editor.smoothScrolling": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.minimap.renderCharacters": true,
"editor.tabSize": 2,
"editor.autoIndent": "advanced",
"editor.insertSpaces": true,
"editor.tabCompletion": "on",
"editor.formatOnPaste": true,
"editor.detectIndentation": false,
"editor.wordWrap": "off",
"editor.matchBrackets": "always",
"editor.renderWhitespace": "none",
"editor.autoClosingBrackets": "always",
"editor.tokenColorCustomizations": {
"types": "#C59F61",
"strings": "#F6EB90",
"numbers": "#C54121",
"keywords": "#C59F49",
"comments": "#6a737d",
"variables": "#C55F45",
"functions": "#C59F55"
},
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Darkside (rainglow)",
"workbench.editor.showTabs": true,
"workbench.statusBar.visible": true,
"workbench.editor.tabSizing": "fit",
"workbench.sideBar.location": "left",
"debug.toolBarLocation": "floating",
"debug.allowBreakpointsEverywhere": true,
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe", // C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
"files.autoSave": "off",
"files.exclude": {
"**/.git": false,
"**/.svn": false,
"**/.hg": false,
"**/CVS": false,
"**/.DS_Store": false
},
"breadcrumbs.enabled": true,
"breadcrumbs.filePath": "last",
"breadcrumbs.symbolPath": "on",
"breadcrumbs.symbolSortOrder": "name",
"git.enableSmartCommit": true,
"git.ignoreLimitWarning": true,
"eslint.enable": true,
"eslint.packageManager": "yarn",
"[yaml]": {
"editor.tabSize": 2,
"editor.autoIndent": "advanced",
"editor.insertSpaces": true
},
"[markdown]": {
"editor.wordWrap": "on",
"editor.quickSuggestions": false
},
"liveshare.featureSet": "insiders",
"better-comments.tags": [
{
"tag": "/",
"color": "#008080",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "+",
"color": "#00ff00",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": ">",
"color": "#FF00FF",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "-",
"color": "#ff0000",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "!",
"color": "#FF2D00",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "?",
"color": "#3498DB",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "//",
"color": "#474747",
"strikethrough": true,
"backgroundColor": "transparent"
},
{
"tag": "todo",
"color": "#FF8C00",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "*",
"color": "#98C379",
"strikethrough": false,
"backgroundColor": "transparent"
}
]
}

View File

@@ -1,14 +1,10 @@
<img src="$(LOGO_SQUARE).svg" align="left" width="192px" height="192px"/>
<img src="https://avatars.githubusercontent.com/u/29184334?v=4" align="left" width="192px" height="192px"/>
<img align="left" width="0" height="192px" hspace="10"/>
> $(PROJECT_NAME)
> c-boilerplate
[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)](/LICENSE) $(BADGES)
[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)](/LICENSE)
$(SMALL_DESC)
A simple boilerplate for C applications
<br>
## Table of contents
* $(HEADER)
* $(SUB_HEADER)

6
include/utils.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef UTILS_H
#define UTILS_H
const unsigned long hash(const char *str);
#endif

20
lib/utils.c Normal file
View File

@@ -0,0 +1,20 @@
/* utils.c */
/** @brief Hash `str` to `hash` for use in a switch case
*
* A string needs to be hashed for it to be used
* inside of a switch statement. We want to use a switch
* statement instead of an if-else chain for it's
* simplicity and lower amount of low-level operations.
*
* @param str The string to hash
*
* @returns hash The hashed version of `str`
*/
unsigned long hash(const char *str) {
unsigned long hash = 5381;
unsigned long int c;
while ((c = *str++))
hash = ((hash << 5) + hash) + c;
return hash;
}

42
makefile Normal file
View File

@@ -0,0 +1,42 @@
# C compiler to use
CC := gcc
# Directory mappings
SRC_DIR := src
LIB_DIR := lib
OBJ_DIR := obj
OUT_DIR := out
INC_DIR := include
# Map all object and source files
SRC_FILES := $(wildcard $(SRC_DIR)/*.c) $(wildcard $(LIB_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC_FILES))
# All optional libs and Cflags to append to the final command
LIBS := -lm
CFLAGS := -I$(INC_DIR)
BUILDFLAGS := -Wall -Wextra -Wconversion
# Special and default commands
.PHONY: clean help
.DEFAULT_GOAL := help
# Macro for creating object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) -c -o $@ $<
## All make commands ##
help: ## Lists all commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
clean: ## Clean up all object files and executables
rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/*
dev: $(OBJ_FILES) ## Build, run and debug the project
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && strace ./out/dev
run: $(OBJ_FILES) ## Build and run the project
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(LIBS) && ./out/run
prod: $(OBJ_FILES) ## Build the project
$(CC) -o $(OUT_DIR)/$@ $^ $(CFLAGS) $(BUILDFLAGS) $(LIBS)

0
obj/.gitkeep Normal file
View File

0
out/.gitkeep Normal file
View File

13
src/main.c Normal file
View File

@@ -0,0 +1,13 @@
/* main.c */
/*
Project description
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "../include/utils.h"
int main(int argc, char *argv[], char *env[]) {
return 0;
}