Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
PjrCodes committed May 20, 2020
1 parent 420c437 commit e25b35d
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 17 deletions.
179 changes: 162 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,186 @@
# CodeStyliser
This is the repository for the Code Styliser utility, written by Pranjal Rastogi.

The Code Styliser utility adds curly braces \[`{}`\] in all C-source \[`.c`\] files and Header \[`.h`\] files under a given directory, wherever needed.
It adds braces after single line `if()`, `for()`, `while()`, `else`, `else if()` statements.
This is the Code Styliser utility.

The Code Styliser utility adds curly braces (`{}`) in C-source (`.c`) files wherever needed

It adds braces after single line `if()`, `for()`, `while()`, `else` and `else if()` statements.

For example,

```c
if(a == b)
if(condition)
statement;
```

will become

```c
if(a == b) {
if(condition) {
statement;
}
```

This utility is written in Python 3.7.7, 64-Bit. Currently, you must have Python 3.7.7, 64-Bit installed on your machine for this utility to work. Check [install](#Install) for more details
*It is my suggestion to check all the code once this utility is finished running, as few issues may arise*.

There is no guarantee that this software will work out of the box without any issues. Please check [License](#License) for more details

**NOTE:** This utility will replace all `\r\n` line endings with `\n`.

## Usage

## Install
This utility is written in Python 3.7.7, 64-Bit. However, you **dont** need to have python installed on your machine.

* Make sure you have Python 3.7.7 64-Bit installed on your device.
* If this is not done, Install Python3.7.7 from [python.org](https://www.python.org)
* Now, download `utilities.py` and `codeStyliser.py` from releases into the required directory
The usage is as follows:

* now, just run `$ python3.7 codeStyliser.py .` in the desired directory
* Download the binary file attached into the directory you want to run the utility from.
* Now, just run the file in the following manner
* If you want to run it for a file:

`$ ./codeStyliser -f file-name`
* Or, if you want to run it for a directory:

`$ ./codeStyliser -d directory-name`

* The complete usage of this binary is as follows:

```shell
usage: codeStyliser.py [-h] (-f file-name | -d directory-name)

optional arguments:
-h, --help show this help message and exit
-f file-name, --file file-name
file name to format
-d directory-name, --directory directory-name
directory to format files under
```

## Known issues

Please check [issues](https://github.com/PjrCodes/CodeStyliser/issues) for the latest bugs

### Encoding issue

The utility only changes UTF-8 encoded files, it will ignore all other file encodings.

### Non-keyword block of code

If a block of code, that is not a keyword( `for()`, `if()`, `while()`, `do`, etc.) is in the code after a keyword, which doesn't have curly braces (`{}`), the closing curly brace (`}`) is added in the wrong position by the utility.

For example,

```c
for (...)
NOT_A_KEYWORD () {
statement 1;
statement 2;
...
}
```
becomes:
```c
for (...) {
NOT_A_KEYWORD () {
statement 1;
}
statement 2;
...
}
```

This doesnt happen if the block of code starts on a keyword

### Tab indentation error

If the characters used to indent keywords, are tabs (`\t`), then the output code will not be indented properly.

The indented characters must always use spaces to indent.

For example,

```c
for(...)
statement;
```

becomes

```c
for(...) {
statement;
}
```
if the characters used to indent the `for(...)` are tabs, and not spaces.
### Hash ignore
The code will ignore all keywords that have a `#` on the next immediate valid line.
A valid line is a line which has no comment and isnt a blank line.
For example,
```c
for(...)
#endif
for(...)
// comment
#endif
for(...) statement;
#endif
```

Here, the `for(...)` is ignored, i.e. *NO* braces will be added.

```c
for(...)
foo;
#endif
```

In the above case, the `for(...)` is not ignored, i.e. braces will be added.

### Issues with Comments

Comments like the following will cause issues, as explained in this block:

```c
// the following for(); isnt detected

/*comment*/ for(...)
statement;

// this will result in an error, and this line will be ignored

for( /*comment*/ )
statement;

// this for is also not detected
/*comment*/ for(...) //comment
statement;

// Similiarly, this for is also not detected
/*comment*/ for() /*comment*/
statement;

// Here, the code results in an UnboundLocalError

/*
foo */ for(...) statement; //bar

```

## License
Copyright (C) Pranjal Rastogi 2020

This utility has no warranty.
license: BSD-2 Clause
Please see LICENSE for more information
**Copyright (c) 2020, Pranjal Rastogi,**

**All rights reserved.**

This utility has **NO** warranty.

This utility is licensed under a **BSD 2-Clause License**, please see LICENSE for more information
Binary file added README.pdf
Binary file not shown.

0 comments on commit e25b35d

Please sign in to comment.