coding_style.md
The coding style used by XRdp is described below.
The XRdp project uses astyle (artistic style) to format the code. Astyle
requires a configuration file that describes how you want your code
formatted. This file is present in the XRdp root directory and is named
astyle_config.as.
Here is how we run the astyle command:
astyle --options=/path/to/file/astyle_config.as "*.c"
This coding style is a work in progress and is still evolving.
Try to make all code compile with both C and C++ compiler. C++ is more strict, which makes the code safer.
☞
if (fd < 0)
{
return -1;
}
☞
log_message("connection aborted: error %d",
ret);
☞
#define BUF_SIZE 1024
int fd;
int bytes_in_stream;
☞
int i;
int j;
☞
char *cptr;
int *iptr;
cptr = (char *) malloc(1024);
write(fd, &buf[12], 16);
☞
static int
value_ok(int val)
{
return (val >= 0);
}
☞
struct stream
{
int flags;
char *data;
};
void
process_data(struct stream *s)
{
if (stream == NULL)
{
return;
}
}
if statements☞
if (val <= 0xff)
{
out_uint8(s, val);
}
else if (val <= 0xffff)
{
out_uint16_le(s, val);
}
else
{
out_uint32_le(s, val);
}
for statements☞
for (i = 0; i < 10; i++)
{
printf("i = %d\n", i);
}
while and do while statementswhile after the closing brace is on the same line☞
while (cptr)
{
cptr—;
}
do
{
cptr--;
} while (cptr);
switch statementscase oncecase one more time☞
switch (cmd)
{
case READ:
read(fd, buf, 1024);
break;
default:
printf("bad cmd\n");
}
Use /* */ for comments Don't use //