Docs: C struct style

Tests: changed waiting->wait backend
This commit is contained in:
Olof hagsand 2022-10-24 13:54:02 +02:00
parent 62e652bbcf
commit 3a5d156690
33 changed files with 60 additions and 37 deletions

View file

@ -47,15 +47,14 @@ myfn(int par1,
ms = NULL;
```
Notes:
1. the return type of the function and all qualifers on first line (`static int`)
2. function name and first parameter on second line, thereafter each parameter on own line
1. The return type of the function and all qualifers on first line (`static int`)
2. Function name and first parameter on second line, thereafter each parameter on own line
3. Each parameter indented to match the "longest" (`my_structure`)
4. Pointer declarations written: `type *p`, not: `type* p`.
5. All local variables in a function declared at top of function, not inline with C-statements.
6. Local variables can be initialized with scalars or constants, not eg malloc or functions with return values that need to be checked for errors
7. There is a single empty line between local variable declarations and the first function statement.
Function signatures are declared in include files or in forward declaration using "one-line" syntax, unless very long:
```
static int myfn(int par1, my_structure *par2);
@ -123,6 +122,28 @@ files, there is only a single level of include file dependencies.
The drawback is that the same include file may need to be repeated in many .c files.
### Structs
Struct fields should have a prefix to distinguish them from other struct fields. The prefix should use an abbreviation of the struct name.
Example:
```
struct my_struct{
int ms_foo;
char *ms_string[42];
}
```
where `ms_` is the prefix and is an abbreviation of `my_struct`.
### Global variables
Try to avoid global variables.
If you absolutely need one, try to contain it as static within a
single C-file, ie do not declare it extern and use it elsewhere.
Also, always prepend a global variable with `_`, underscore.
## How to work in git
Clixon uses semantic versioning (https://semver.org).

View file

@ -228,7 +228,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -144,7 +144,8 @@ if [ $BE -ne 0 ]; then
new "start backend -s init -f $cfg -- -sS $fstate"
start_backend -s init -f $cfg -- -sS $fstate
fi
new "waiting"
new "wait backend"
wait_backend
#-----------------------------

View file

@ -109,7 +109,8 @@ if [ $BE -ne 0 ]; then
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
new "get-config empty"

View file

@ -138,7 +138,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -197,7 +197,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -114,7 +114,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
new "cli set t1-con t1-con t1-a 123"

View file

@ -123,7 +123,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -135,7 +135,7 @@ EOF
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
# First push in nacm rules via regular means

View file

@ -226,7 +226,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -100,7 +100,7 @@ if [ $BE -ne 0 ]; then
start_backend -s startup -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -231,7 +231,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -227,7 +227,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -191,7 +191,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -184,7 +184,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -145,7 +145,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -56,7 +56,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
new "Add two entries"

View file

@ -101,7 +101,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -n # create example notification stream
fi
new "waiting"
new "wait backend"
wait_backend
#

View file

@ -73,7 +73,7 @@ if [ $BE -ne 0 ]; then
start_backend -s startup -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
new "get startup"

View file

@ -83,7 +83,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
new "waiting"
new "wait backend"
wait_backend
new "generate config with $perfnr list entries"

View file

@ -85,7 +85,7 @@ function testrun(){
start_backend -s startup -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
pid=$(cat $pidfile)

View file

@ -87,7 +87,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
new "waiting"
new "wait backend"
wait_backend
# Check this later with committed data

View file

@ -106,7 +106,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -122,7 +122,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -s
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -96,7 +96,7 @@ function testrun(){
err 1 $c
fi
new "waiting"
new "wait backend"
wait_backend
if [ $expecterr -eq 1 ]; then

View file

@ -149,7 +149,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg -- -n # create example notification stream
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -196,7 +196,7 @@ if [ $BE -ne 0 ]; then
start_backend -s init -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
if [ $RC -ne 0 ]; then

View file

@ -124,7 +124,7 @@ function testrun(){
new "start backend -f $cfg -s $mode -c $dir/extra_db"
start_backend -s $mode -f $cfg -c $dir/extra_db
new "waiting"
new "wait backend"
wait_backend
else
new "Restart backend as eg follows: -Ff $cfg -s $mode -c $dir/extra_db # $BETIMEOUT s"

View file

@ -258,7 +258,7 @@ if [ $BE -ne 0 ]; then
start_backend -s $mode -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
new "Check running db content"

View file

@ -271,7 +271,7 @@ function testrun(){
start_backend -s startup -f $cfg -- -u
fi
new "waiting"
new "wait backend"
wait_backend
new "Check running db content"

View file

@ -268,7 +268,7 @@ function testrun(){
start_backend -s startup -f $cfg -- -u
fi
new "waiting"
new "wait backend"
wait_backend
new "Check running db content"

View file

@ -117,7 +117,7 @@ if [ $BE -ne 0 ]; then
start_backend -s $mode -f $cfg
fi
new "waiting"
new "wait backend"
wait_backend
new "Check running db content is failsafe"

View file

@ -111,11 +111,11 @@ EOF
if [ $BE -ne 0 ]; then
new "start backend -s running -f $cfg"
start_backend -s running -f $cfg
new "waiting"
wait_backend
fi
new "wait backend"
wait_backend
new "netconf get config"
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><hello xmlns=\"urn:example:simple\"><world/></hello></data></rpc-reply>"