Split config.c into a separate object file

master
Quantum 6 years ago
parent 45b538ad10
commit 19fdf69664
  1. 6
      Makefile.am
  2. 7
      cava.c
  3. 42
      config.c
  4. 26
      config.h

@ -9,9 +9,9 @@ ACLOCAL_AMFLAGS = -I m4
M_CPPFLAGS = -DSYSTEM_LIBINIPARSER=@SYSTEM_LIBINIPARSER@
bin_PROGRAMS = cava
cava_SOURCES = cava.c input/common.c input/alsa.c input/fifo.c input/portaudio.c input/pulse.c \
input/sndio.c input/shmem.c output/terminal_bcircle.c output/terminal_ncurses.c \
output/terminal_noncurses.c output/raw.c
cava_SOURCES = cava.c config.c input/common.c input/alsa.c input/fifo.c input/portaudio.c \
input/pulse.c input/sndio.c input/shmem.c output/terminal_bcircle.c \
output/terminal_ncurses.c output/terminal_noncurses.c output/raw.c
cava_LDFLAGS = -L/usr/local/lib -Wl,-rpath /usr/local/lib
cava_CPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" \
-D_POSIX_SOURCE -D _POSIX_C_SOURCE=200809L

@ -12,6 +12,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <ctype.h>
@ -47,13 +48,7 @@
#include "input/shmem.h"
#include "input/sndio.h"
#include <iniparser.h>
// We need to make sure that clang-format does not order the .h files before the .c files.
// clang-format off
#include "config.h"
#include "config.c"
// clang-format on
#ifdef __GNUC__
// curses.h or other sources may already define

@ -1,27 +1,16 @@
#define MAX_ERROR_LEN 1024
#include "config.h"
#include <ctype.h>
#include <iniparser.h>
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <sys/stat.h>
double smoothDef[5] = {1, 1, 1, 1, 1};
char *inputMethod, *outputMethod, *channels;
struct config_params {
char *color, *bcolor, *raw_target, *audio_source,
/**gradient_color_1, *gradient_color_2,*/ **gradient_colors, *data_format, *mono_option;
char bar_delim, frame_delim;
double monstercat, integral, gravity, ignore, sens;
unsigned int lowcf, highcf;
double *smooth;
int smcount, customEQ, im, om, col, bgcol, autobars, stereo, is_bin, ascii_range, bit_format,
gradient, gradient_count, fixedbars, framerate, bw, bs, autosens, overshoot, waves,
FFTbufferSize, fifoSample;
};
struct error_s {
char message[MAX_ERROR_LEN];
int length;
};
void write_errorf(void *err, const char *fmt, ...) {
struct error_s *error = (struct error_s *)err;
va_list args;
@ -138,11 +127,7 @@ bool validate_colors(void *params, void *err) {
return true;
}
bool validate_config(char supportedInput[255], void *params, void *err) {
struct config_params *p = (struct config_params *)params;
struct error_s *error = (struct error_s *)err;
bool validate_config(char supportedInput[255], struct config_params *p, struct error_s *error) {
// validate: input method
p->im = 0;
if (strcmp(inputMethod, "alsa") == 0) {
@ -385,11 +370,8 @@ bool load_colors(struct config_params *p, dictionary *ini, void *err) {
return true;
}
bool load_config(char configPath[255], char supportedInput[255], void *params, bool colorsOnly,
void *err) {
struct config_params *p = (struct config_params *)params;
struct error_s *error = (struct error_s *)err;
bool load_config(char configPath[255], char supportedInput[255], struct config_params *p,
bool colorsOnly, struct error_s *error) {
FILE *fp;
// config: creating path to default config file
@ -565,7 +547,7 @@ bool load_config(char configPath[255], char supportedInput[255], void *params, b
}
#endif
bool result = validate_config(supportedInput, params, error);
bool result = validate_config(supportedInput, p, error);
iniparser_freedict(ini);
return result;
}

@ -1,6 +1,26 @@
#include <stdarg.h>
#pragma once
#include <stdbool.h>
#include <stdio.h>
bool load_config(char configPath[255], char supportedInput[255], void *p, bool colorsOnly,
void *error);
#define MAX_ERROR_LEN 1024
struct config_params {
char *color, *bcolor, *raw_target, *audio_source,
/**gradient_color_1, *gradient_color_2,*/ **gradient_colors, *data_format, *mono_option;
char bar_delim, frame_delim;
double monstercat, integral, gravity, ignore, sens;
unsigned int lowcf, highcf;
double *smooth;
int smcount, customEQ, im, om, col, bgcol, autobars, stereo, is_bin, ascii_range, bit_format,
gradient, gradient_count, fixedbars, framerate, bw, bs, autosens, overshoot, waves,
FFTbufferSize, fifoSample;
};
struct error_s {
char message[MAX_ERROR_LEN];
int length;
};
bool load_config(char configPath[255], char supportedInput[255], struct config_params *p,
bool colorsOnly, struct error_s *error);

Loading…
Cancel
Save