Script to fix comments into a file.
Just for the explanation:
- optional arguments are inside
() - the value of an argument is inside
<>
python3 main.py (-h) (-n) (-s) (-a) (-c <format_case>) (-e <excluded_words>) -t <comment_symbol> filename
-t,--type: comment symbol (like//for C/C++,#for Python etc...) surrouned by'- Example:
--type '#'
- Example:
filename: the file that needs comment formatting. MUST BE THE LAST ARGUMENT
Without value:
-h,--help: prints the info message-n,--no-space: formats without space after the command symbol- Example:
# this is a commentbecomes#this is a comment
- Example:
-s,--spaces: removes extra spaces after comment symbol- Example: becomes
# this is a comment# this is a comment
- Example:
-a,--all: applies uppercase / lowercase to all words after comment symbol- Example:
# THis Is A COMMentbecomes# this is a commentor# THIS IS A COMMENTrespecting excluded words
- Example:
With value:
-c,--case:u,upperorl,lower. Formatting type. Default:u- Example:
# this is a commentbecomes# This is a comment(without--all)
- Example:
-e,--exclude: string of words separated by,and surrounded by'- Example:
--exclude 'NULL,ERROR'.# VALUE is NULLwith-c lower -allbecomes# value is NULL
- Example:
test.c:
#include <stdio.h>
// main function
int main() {
//p poINTS to NULL
int *p = NULL;
//RETURNS 0
return 0;
}Comment formatting:
python3 main.py -s -a -t '//' -c lower -e 'NULL' test.c
Result (new_test.c):
#include <stdio.h>
// main function
int main() {
// p points to NULL
int *p = NULL;
// returns 0
return 0;
}