Skip to content

Commit

Permalink
系统的格式化所有代码
Browse files Browse the repository at this point in the history
- 添加 clang-format 配置
- 并用其格式化了主要代码
  • Loading branch information
SourLemonJuice committed Jun 15, 2024
1 parent d253ef8 commit e327a90
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
BasedOnStyle: Microsoft
IndentWidth: 4
UseTab: Never
MaxEmptyLinesToKeep: 2 # for me, 2 empty lines were so common.
BreakBeforeBraces: Linux # it's my first guide of style, so I'll keep it.
AllowShortIfStatementsOnASingleLine: Never
IndentCaseLabels: false
IncludeBlocks: Preserve # because google c++ guide specifies the order of #include blocks.
SortIncludes: CaseInsensitive
ColumnLimit: 120 # same as Microsoft, don't ask me, I just think it's great.
BinPackParameters: true # MS also seted this, but I saw this config.
AlignAfterOpenBracket: Align # TBD, now same as Microsoft.
AlignTrailingComments: # TBD, so don't change my code now.
Kind: Leave
OverEmptyLines: 0
...
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ NOTE: All flags are unstabled.
### Precautions

stdin/file mode only can process words with a maximum length of (1024 * 1) chars. This limit defined in *source/main.h*\
Although there is no **word**(separated with space and `\n`) as long as this.
Although there is no **word**(separated with `space` and `\n`) as long as this.

Only use for ASCII(single char type) characters, don't do this:

```shell
./i18nglish.out -- — 或者这种字符串
```

If it's happend, I won't care of them.\
Maybe, error looked like: `�16�`\
This program just an English joke, so it's should be fine.

## Move main functions to other project

Expand Down Expand Up @@ -90,15 +100,17 @@ Maybe I'll put them to *main.c* at later.
> Todo list is for myself, not for showing off. The history todo only needs store in git history.
- Improve the way to handle CLI flags
- Add clang-format config

## Code style

[Google Style Guide C++](https://google.github.io/styleguide/cppguide.html)(or just want to be)
Variable names reference [Google Style Guide C++](https://google.github.io/styleguide/cppguide.html)(or just want to be).\
Most block styles are from Linux kernal.

The clang-format config has already been added to the repo, but maybe still incomplete.

## GitHub CI
## Just put something at last

![Build CI Badge](https://github.com/SourLemonJuice/i18nglish.c/actions/workflows/GitHub_CI_Build.yml/badge.svg)
![Build CI Badge](https://github.com/SourLemonJuice/i18nglish.c/actions/workflows/Build.yml/badge.svg)

## License

Expand Down
9 changes: 5 additions & 4 deletions source/i7h_processor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "i7h_processor.h"

#include <stdbool.h>
#include <iso646.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -35,7 +35,8 @@ int i7hProcessor(struct I7hDataStruct i7h_D[restrict], const char src_string[])
return 0;
} else {
// normal one
if(snprintf(i7h_D->buffer, i7h_D->now_buffer_size, "%c%d%c", src_string[0], i7h_D->src_string_length - 2, src_string[i7h_D->src_string_length - 1]) >= 0) {
if (snprintf(i7h_D->buffer, i7h_D->now_buffer_size, "%c%d%c", src_string[0], i7h_D->src_string_length - 2,
src_string[i7h_D->src_string_length - 1]) >= 0) {
return 0;
} else {
return 1;
Expand All @@ -57,7 +58,7 @@ int i7hInitStructure(struct I7hDataStruct i7h_D[restrict])

int i7hFreeStructure(struct I7hDataStruct i7h_D[restrict])
{
if(i7h_D->buffer != NULL) {
if (i7h_D->buffer != NULL) {
free(i7h_D->buffer);
} else {
return I7hErrorFreeMemory;
Expand All @@ -69,7 +70,7 @@ int i7hFreeStructure(struct I7hDataStruct i7h_D[restrict])
int getIntLength(int src_int)
{
int length = 1;
for(; src_int > 10; length++)
for (; src_int > 10; length++)
src_int /= 10;
return length;
}
6 changes: 3 additions & 3 deletions source/main.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "main.h"

#include <stdbool.h>
#include <ctype.h>
#include <iso646.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>

#include "i7h_processor.h"

Expand Down

0 comments on commit e327a90

Please sign in to comment.