Skip to content

Commit

Permalink
style: update coding style
Browse files Browse the repository at this point in the history
Indent with 8-column tabs. 8 column tabs are the default, and will
render consistently in any editor, terminal, web browsers,
and other places where the code may appear.

Use braces where the language makes them optional.
Single-line if statements, loops, etc, must use braces. It's a small
loss for ergonomics with a tangible benefit for error prevention.

Place opening braces on the same line (excluding function definitions).

Start the name of the function in column one for function definitions.
This helps people to search for function, i.e., `git grep '^my_function'`,
and may also help certain tools recognize them.

Double-indent continuation lines for new scopes.

Single-indent continuation lines in the same scope.

Split long string literals into multiple lines. When long strings hit
80 columns, terminate the string and resume it on the following line.

Declare typedefs, structs and enums with the `{` on the first line.
  • Loading branch information
cezelot committed Aug 19, 2024
1 parent 6841073 commit b539360
Show file tree
Hide file tree
Showing 27 changed files with 639 additions and 779 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.{c,h}]
trim_trailing_whitespace = true
indent_style = tab
indent_size = 8
max_line_length = 80
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Added
## [0.5.0] - 2024-08-18

### Added

- Use `Ctrl-F` to search for strings.

### Fixed

- Fix `Complex Method` issue in input_3.c (#4).
- Fix `Bumpy Road` issue in file_io.c (#5).
- Fix `Complex Method` code health issue in input_3.c (#4).
- Fix `Bumpy Road` code health issue in file_io.c (#5).

## [0.4.0] - 2024-07-24

Expand Down Expand Up @@ -43,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix `Complex Method` issue in input.c (#1).
- Fix `Complex Method` code health issue in input.c (#1).

## [0.2.0] - 2024-07-12

Expand Down Expand Up @@ -73,7 +75,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Display a status bar and a status message.
- Take `--help` and `--version` command-line options.

[unreleased]: https://github.com/cezelot/eve/compare/v0.4.0...HEAD
[unreleased]: https://github.com/cezelot/eve/compare/v0.5.0...HEAD
[0.5.0]: https://github.com/cezelot/eve/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/cezelot/eve/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/cezelot/eve/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/cezelot/eve/compare/v0.1.0...v0.2.0
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ NAME := eve
CC := gcc
FLAGS := -Wall -Werror -Wextra -pedantic -std=c99

SRC_DIR := ./sources
SRC_DIR := src

SRC_FILES := main.c \
append_buffer.c \
editor_operations.c \
file_io.c \
save_file_operations.c \
find.c \
options.c \
file/file_io.c \
file/save_file_operations.c \
input/input.c \
input/input_2.c \
input/input_3.c \
input/input_4.c \
input/key_handlers.c \
input/additional_handlers.c \
output/output.c \
output/output_2.c \
row_operations/row_operations.c \
Expand All @@ -43,7 +42,7 @@ SRC_FILES := main.c \
terminal/terminal_2.c \
terminal/terminal_3.c

OBJ_DIR := ./objects
OBJ_DIR := objs

OBJS := $(addprefix $(OBJ_DIR)/, $(SRC_FILES:.c=.o))

Expand Down
9 changes: 1 addition & 8 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,7 @@ If you don't find one:

### Coding Style Guidelines

See the file [STANDARD.md](STANDARD.md) for details on the coding standard
used by this project.

Please follow this style to make eve easy to read, maintain and develop.

These coding rules are open for discussion, if you think another standard’s specifications
makes eve better overall in an objective sense or anything else, please feel free to implement it,
or you can [start a new discussion](https://github.com/cezelot/eve/discussions/new?category=standard).
*...*

### Commit Message Guidelines

Expand Down
4 changes: 2 additions & 2 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

| Version | Supported |
| ------- | ------------------ |
| 0.2.0 | :white_check_mark: |
| 0.1.0 | :x: |
| 0.4.0 | :white_check_mark: |
| 0.3.0 | :x: |

## Reporting a Vulnerability

Expand Down
222 changes: 2 additions & 220 deletions docs/STANDARD.md
Original file line number Diff line number Diff line change
@@ -1,224 +1,6 @@
# Coding Standard

Here are the set of rules/guidelines used when writing source codes of this
Set of rules/guidelines used when writing source codes of this
project.

**Table of Content:**
- [Denomination](#denomination)
- [Formatting](#formatting)
- [Functions](#functions)
- [Typedef, struct, enum and union](#typedef,-struct,-enum-and-union)
- [Headers](#headers)
- [The license notice](#the-license-notice)
- [Macros and Pre-processors](#macros-and-pre-processors)
- [Forbidden stuff](#forbidden-stuff)
- [Comments](#comments)

## Denomination

- A structure’s name must start by `s_`.
- A typedef’s name must start by `t_`.
- A union’s name must start by `u_`.
- An enum’s name must start by `e_`.
- A global’s name must start by `g_`.
- Variables and functions names can only contain lowercases, digits and '_' (snake_case).
- Files and directories names can only contain lowercases, digits and '_'
(excluding documentation files, e.g., README.md, CHANGELOG.md, ...).
- Characters that aren’t part of the standard ASCII table are forbidden.
- Variables, functions, and any other identifier must use snake case. No capital letters,
and each word separated by an underscore.
- All identifiers (functions, macros, types, variables, etc.) must be in English.
- Objects (variables, functions, macros, types, files or directories) must have the most
explicit or most mnemonic names as possible.
- Using global variables that are not marked `const` and `static` is forbidden.

## Formatting

- You must indent your code with 4-space tabulations. This is not the same as 4
average spaces, we’re talking about real tabulations here.
- Try to keep each function less than 26 lines, not counting the function’s own
curly brackets and the comments (if there are any).
- Each line must be at most 80 columns wide, comments included. Warning: a
tabulation doesn’t count as a column, but as the number of spaces it represents.
- Each function must be separated by a newline. Any comment or preprocessor
instruction can be right above the function. The newline is after the previous
function.
- One instruction per line.
- An empty line must be empty: no spaces or tabulations.
- A line can never end with spaces or tabulations.
- You can never have two consecutive spaces.
- You need to start a new line after each curly bracket or end of control structure.
- Unless it’s the end of a line, each comma or semi-colon must be followed by a space.
- Each operator or operand must be separated by one - and only one - space.
- Each C keyword must be followed by a space, except for keywords for types (such
as `int`, `char`, `float`, etc.), as well as `sizeof()`.
- Each variable declaration must be indented on the same column for its scope.
- The asterisks that go with pointers must be stuck to variable names.
- One single variable declaration per line.
- Declarations must be at the beginning of a function.
- In a function, you must place an empty line between variable declarations and the
remaining of the function.
- Multiple assignments are forbidden.
- Control structures (`if`, `while..`) must have braces, unless they contain a single line.
- Braces following functions, declarators or control structures must be preceded and
followed by a newline.

General example:

```c
int g_global;

typedef struct s_struct
{
char *str;
int i;
} t_struct;

struct s_other_struct;

int main(void)
{
int i;
char c;

return (i);
}
```
## Functions
- A function can take 4 named parameters maximum.
- A function that doesn’t take arguments must be explicitly prototyped with the
keyword `void` as the argument.
- Parameters in functions’ prototypes must be named.
- Each function must be separated from the next by an empty line.
- You can’t declare more than 5 variables per function.
- Return of a function has to be between parenthesis.
- Each function must have a single tabulation between its return type and its name.
```c
int func2(char, *message, int len, char c)
{
return (nb);
}
int func(void)
{
return ;
}
```

## Typedef, struct, enum and union

- Add a tabulation when declaring a struct, enum or union.
- When declaring a variable of type struct, enum or union, add a single space in the
type.
- When declaring a struct, union or enum with a typedef, all indentation rules apply.
- Typedef name must be preceded by a tab.
- You must indent all structures’ names on the same column for their scope.
- You cannot declare a structure in a .c file.

## Headers

- The things allowed in header files are: header inclusions (system or not), declara-
tions, defines, prototypes and macros.
- All includes must be at the beginning of the file.
- You cannot include a C file.
- Header files must be protected from double inclusions. If the file is foo.h, its
bystander macro is `FOO_H`.
- Unused header inclusions (.h) are forbidden.
- All header inclusions must be justified in a .c file as well as in a .h file.

```c
#ifndef FOO_H
# define FOO_H

# include <stdlib.h>
# include <stdio.h>
# define VERSION "0.1.0"

typedef struct s_config
{
char *color;
int tabstop;
} t_conf;

void init(t_conf *config);
void die(const char *format, ...);

#endif /* FOO_H */
```

## The license notice

- Every .c and .h file should start with the header below.
- If you modify a .c or .h file, you must update the date of the modification
and the name of its author. Please also add your name in the copyright notice, i.e.,
`Copyright (C) 2024 Jane Doe, Your Name`.

```c
/* ************************************************************************** */
/* */
/* <filename> - <optional description> */
/* */
/* Created: 2024/07/17 00:00:01 by <name> */
/* Updated: 2024/07/17 00:01:00 by <name> */
/* */
/* Copyright (C) 2024 <name> */
/* */
/* This file is part of eve. */
/* */
/* eve is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* eve is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with eve. If not, see <https://www.gnu.org/licenses/>. */
/* */
/* ************************************************************************** */
```

## Macros and Pre-processors

- Preprocessor constants (or `#define`) you create must be used only for literal and
constant values.
- Multiline macros are forbidden.
- Macro names must be all uppercase.
- You must indent characters following `#if`, `#ifdef` or `#ifndef`.
- Preprocessor instructions are forbidden outside of global scope.

## Forbidden stuff

- You’re not allowed to use:
- `do...while`
- `goto`
- VLAs - Variable Length Arrays.

## Comments

Comments are not mandatory but encouraged.

- Write the comments in English.
- Comments must be at the end of a line, or on their own line
- Put two spaces after the end of a sentence in your comments, so that the Emacs
sentence commands will work. Also, please write complete sentences and capitalize
the first word.
- Put a comment on top of each function saying what the function does, what sorts of
arguments it gets, and what the possible values of arguments mean and are used for.
Also explain the significance of the return value, if there is one.

```c
/* The comment on a function is much clearer if you use the argument names to speak
about the argument values. The variable name itself should be lower case, but write it in
upper case when you are speaking about the value rather than the variable itself, i.e.,
“the inode number NODENUM” rather than “an inode”. */
void func(int nodenum)
{
}
```
*To update*
33 changes: 0 additions & 33 deletions sources/input/additional_handlers.c

This file was deleted.

Loading

0 comments on commit b539360

Please sign in to comment.