Style changes and contribution guidelines

This commit is contained in:
Jarcode
2018-10-26 18:35:29 -07:00
parent 3da1fb34dd
commit 386d32076c
8 changed files with 477 additions and 451 deletions

44
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,44 @@
## Code Style
GLava uses a very relaxed version of the [linux kernel style](https://blog.github.com/2012-09-17-contributing-guidelines/), with a few changes:
* Opening braces are _always_ on the same line as the token it is associated with (`if`, `while`, labels, functions). The only time this is not honoured is when a set of braces has no associated token (ie. scope usage).
* Indentation is 4 spaces, and tabs are forbidden
* The content of a `switch` statement, including `case` labels, are indented.
* Preprocessor directives should inherit the same intentation level as the code it resides in.
* Align tokens in repetitious lines by padding spacing between tokens.
The following rules of the linux style are **ignored**:
* Function size and control flow recommendations
* Comment formatting rules
* Any other rules regarding preprocessor directives
Naming rules and the usage of `typedef` is strictly honoured from the Linux style. Anything not mentioned here is probably subjective and won't hurt your chances of getting a PR accepted.
If you use GNU Emacs, the above style can be configured via the following elisp:
```emacs
(setq-default c-basic-offset 4)
(setq c-default-style "linux")
(setq tab-stop-list (number-sequence 4 200 4))
(c-set-offset (quote cpp-macro) 0 nil)
(c-set-offset 'case-label '+)
```
## Shaders
If you author and maintain your own shader module for GLava, you are free to use your preferred code style. Otherwise, shaders follow the same style as GLava's C sources.
## Pull Requests
You are free to make pull requests for any change, even if you are not sure if the proposed changes are appropriate. @wacossusca34 and/or @coderobe will be able to suggest changes or commentary on the PR if there is a reason it is not acceptable.
## Conduct
Engagement in the issue tracker and pull requests simply requires participants remain rational and on-topic.

16
fifo.c
View File

@@ -10,9 +10,7 @@
#include "fifo.h"
//input: FIFO
void* input_fifo(void* data)
{
void* input_fifo(void* data) {
struct audio_data* audio = (struct audio_data *) data;
int fd;
int n = 0;
@@ -30,10 +28,9 @@ void* input_fifo(void* data)
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
while (1) {
bytes = read(fd, buf, sizeof(buf));
if (bytes == -1) { //if no bytes read sleep 10ms and zero shared buffer
if (bytes == -1) { /* if no bytes read, sleep 10ms and zero shared buffer */
nanosleep (&req, NULL);
t++;
if (t > 10) {
@@ -41,7 +38,7 @@ void* input_fifo(void* data)
for (i = 0; i < 2048; i++)audio->audio_out_r[i] = 0;
t = 0;
}
} else { //if bytes read go ahead
} else { /* if bytes read, go ahead */
t = 0;
for (q = 0; q < (size / 4); q++) {
@@ -59,12 +56,9 @@ void* input_fifo(void* data)
if (templ >= 0) templ = templ + lo;
else templ = templ - lo;
if (audio->channels == 1) audio->audio_out_l[n] = (tempr +
templ) /
2;
if (audio->channels == 1) audio->audio_out_l[n] = (tempr + templ) / 2;
//stereo storing channels in buffer
/* stereo storing channels in buffer */
if (audio->channels == 2) {
audio->audio_out_l[n] = templ;
audio->audio_out_r[n] = tempr;

View File

@@ -113,8 +113,7 @@ static void copy_cfg(const char* path, const char* dest, bool verbose) {
}
switch (type) {
case 1:
{
case 1: {
int source = -1, dest = -1;
uint8_t buf[pgsz];
ssize_t r, t, w, a;

View File

@@ -15,6 +15,13 @@
#include "glsl_ext.h"
#define LINE_START 0
#define GLSL 1
#define MACRO 2
#define REQUEST 3
#define INCLUDE 4
#define COLOR 5
struct sbuf {
char* buf;
size_t at; /* index of final null character */
@@ -121,9 +128,10 @@ static void inherit(struct glsl_ext* parent, struct glsl_ext* child) {
/* handle raw arguments for #include and #request directives */
static struct schar directive(struct glsl_ext* ext, char** args,
size_t args_sz, bool include,
size_t args_sz, int state,
size_t line, const char* f) {
if (include) {
switch (state) {
case INCLUDE: {
if (args_sz == 0) {
parse_error_s(line, f, "No arguments provided to #include directive!");
}
@@ -175,8 +183,8 @@ static struct schar directive(struct glsl_ext* ext, char** args,
};
return ret;
} else {
}
case REQUEST: {
if (args_sz > 0) {
char* request = args[0];
@@ -198,23 +206,20 @@ static struct schar directive(struct glsl_ext* ext, char** args,
}
char* raw = args[1 + i];
switch (c) {
case 'i':
{
case 'i': {
int v = (int) strtol(raw, NULL, 0);
processed_args[i] = malloc(sizeof(int));
*(int*) processed_args[i] = v;
break;
}
case 'f':
{
case 'f': {
float f = strtof(raw, NULL);
processed_args[i] = malloc(sizeof(float));
*(float*) processed_args[i] = f;
break;
}
case 's': { *(char**) &processed_args[i] = raw; break; }
case 'b':
{
case 'b': {
bool v;
if (!strcmp(raw, "true")) {
v = true;
@@ -262,6 +267,7 @@ static struct schar directive(struct glsl_ext* ext, char** args,
return ret;
}
}
}
/* state machine parser */
void ext_process(struct glsl_ext* ext, const char* f) {
@@ -269,13 +275,6 @@ void ext_process(struct glsl_ext* ext, const char* f) {
ext->destruct = malloc(1);
ext->destruct_sz = 0;
#define LINE_START 0
#define GLSL 1
#define MACRO 2
#define REQUEST 3
#define INCLUDE 4
#define COLOR 5
struct sbuf sbuf = {
.buf = malloc(256),
.at = 0,
@@ -301,13 +300,13 @@ void ext_process(struct glsl_ext* ext, const char* f) {
if (at == '\n')
++line;
switch (state) {
case LINE_START: /* processing start of line */
{
case LINE_START: { /* processing start of line */
switch (at) {
case '#': {
macro_start_idx = t;
state = MACRO;
continue; }
continue;
}
case '\n':
if (comment && comment_line) {
comment = false;
@@ -320,8 +319,7 @@ void ext_process(struct glsl_ext* ext, const char* f) {
/* let execution continue into next state */
}
}
case GLSL: /* copying GLSL source or unrelated preprocessor syntax */
{
case GLSL: { /* copying GLSL source or unrelated preprocessor syntax */
switch (at) {
case '"':
if (!comment && !prev_escape)
@@ -380,8 +378,7 @@ void ext_process(struct glsl_ext* ext, const char* f) {
goto copy;
}
}
case COLOR: /* parse hex color syntax (#ffffffff -> vec4(1.0, 1.0, 1.0, 1.0)) */
{
case COLOR: { /* parse hex color syntax (#ffffffff -> vec4(1.0, 1.0, 1.0, 1.0)) */
switch (at) {
case 'a' ... 'z':
case 'A' ... 'Z':
@@ -408,14 +405,12 @@ void ext_process(struct glsl_ext* ext, const char* f) {
else goto copy; /* copy character if it ended the sequence */
}
}
case MACRO: /* processing start of macro */
{
case MACRO: { /* processing start of macro */
switch (at) {
case '\n':
case ' ':
case '\t':
case '\0':
{
case '\0': {
/* end parsing directive */
if (!strncmp("#request", &ext->source[macro_start_idx], t - macro_start_idx)
|| !strncmp("#REQUEST", &ext->source[macro_start_idx], t - macro_start_idx)) {
@@ -458,8 +453,7 @@ void ext_process(struct glsl_ext* ext, const char* f) {
args[args_sz - 1][end - arg_start_idx] = '\0'; \
} } while (0)
case REQUEST:
case INCLUDE:
{
case INCLUDE: {
switch (at) {
case ' ':
case '\t':
@@ -475,7 +469,7 @@ void ext_process(struct glsl_ext* ext, const char* f) {
if (at == '\n') {
/* end directive */
size_t a;
struct schar r = directive(ext, args, args_sz, state == INCLUDE, line, f);
struct schar r = directive(ext, args, args_sz, state, line, f);
for (a = 0; a < args_sz; ++a) {
free(args[a]);
}

View File

@@ -35,16 +35,11 @@ static void cb(__attribute__((unused)) pa_context* pulseaudio_context,
static void pulseaudio_context_state_callback(pa_context* pulseaudio_context, void* userdata) {
/* Ensure loop is ready */
switch (pa_context_get_state(pulseaudio_context))
{
case PA_CONTEXT_UNCONNECTED:
break;
case PA_CONTEXT_CONNECTING:
break;
case PA_CONTEXT_AUTHORIZING:
break;
case PA_CONTEXT_SETTING_NAME:
break;
switch (pa_context_get_state(pulseaudio_context)) {
case PA_CONTEXT_UNCONNECTED: break;
case PA_CONTEXT_CONNECTING: break;
case PA_CONTEXT_AUTHORIZING: break;
case PA_CONTEXT_SETTING_NAME: break;
case PA_CONTEXT_READY: /* extract default sink name */
pa_operation_unref(pa_context_get_server_info(pulseaudio_context, cb, userdata));
break;