refactor includes
This commit is contained in:
@@ -44,5 +44,5 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: gcc
|
- name: gcc
|
||||||
run: mkdir -p build && gcc $GCC_ARGS -o build/$TARGET
|
run: mkdir -p build && gcc $GCC_ARGS -o build/$TARGET
|
||||||
- name: $TARGET
|
- name: run program
|
||||||
run: ./build/$TARGET $TEST_ARGS
|
run: ./build/$TARGET $TEST_ARGS
|
||||||
|
|||||||
+21
-2
@@ -9,7 +9,7 @@ clean:
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
@mkdir -p build
|
@mkdir -p build
|
||||||
gcc -v -Wall -Wextra src/*.c src/*.h -o build/$(TARGET)
|
gcc -Wall -Wextra src/*.c src/*.h -o build/$(TARGET) -g
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: build
|
install: build
|
||||||
@@ -47,7 +47,26 @@ release: clean
|
|||||||
Makefile.in \
|
Makefile.in \
|
||||||
missing \
|
missing \
|
||||||
src/.* \
|
src/.* \
|
||||||
src/*.o \
|
src/*.o
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release-clean:
|
||||||
|
@rm -rf \
|
||||||
|
autom4te.cache \
|
||||||
|
aclocal.m4 \
|
||||||
|
compile \
|
||||||
|
config.* \
|
||||||
|
configure \
|
||||||
|
depcomp \
|
||||||
|
$(TARGET) \
|
||||||
|
$(TARGET)-*.tar.gz \
|
||||||
|
$(TARGET)-*.pkg.tar.zst \
|
||||||
|
install-sh \
|
||||||
|
Makefile \
|
||||||
|
Makefile.in \
|
||||||
|
missing \
|
||||||
|
src/.* \
|
||||||
|
src/*.o
|
||||||
|
|
||||||
.PHONY: release-arch
|
.PHONY: release-arch
|
||||||
release-arch: clean
|
release-arch: clean
|
||||||
|
|||||||
+7
-5
@@ -1,12 +1,14 @@
|
|||||||
#include "args.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "rand.h"
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "args.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "rand.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
void print_help(int status_code) {
|
void print_help(int status_code) {
|
||||||
puts(PACKAGE
|
puts(PACKAGE
|
||||||
" " VERSION "\n\n"
|
" " VERSION "\n\n"
|
||||||
@@ -118,8 +120,8 @@ void parse_color(char *arg, char *value, unsigned char color[3]) {
|
|||||||
color[2] = parse_char(arg, tmp);
|
color[2] = parse_char(arg, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters parse_args(int argc, char **argv) {
|
Parameters parse_args(int argc, char **argv) {
|
||||||
parameters params;
|
Parameters params;
|
||||||
|
|
||||||
params.quiet = false;
|
params.quiet = false;
|
||||||
params.seed = (unsigned long)time(NULL);
|
params.seed = (unsigned long)time(NULL);
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
#ifndef ARGS_H
|
#ifndef ARGS_H
|
||||||
#define ARGS_H
|
#define ARGS_H
|
||||||
|
|
||||||
parameters parse_args(int argc, char **argv);
|
Parameters parse_args(int argc, char **argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#include "bmp.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "bmp.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
#define HEADER_SIZE 54
|
#define HEADER_SIZE 54
|
||||||
|
|
||||||
void write_str(unsigned char *buffer, unsigned int offset, unsigned int size,
|
void write_str(unsigned char *buffer, unsigned int offset, unsigned int size,
|
||||||
|
|||||||
+10
-9
@@ -1,14 +1,15 @@
|
|||||||
#include "args.h"
|
|
||||||
#include "bmp.h"
|
|
||||||
#include "config.h"
|
|
||||||
#include "rand.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "args.h"
|
||||||
|
#include "bmp.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "rand.h"
|
||||||
|
|
||||||
#define BMP_COLOR_DEPTH 3
|
#define BMP_COLOR_DEPTH 3
|
||||||
|
|
||||||
parameters global_params;
|
Parameters global_params;
|
||||||
float slope;
|
float slope;
|
||||||
unsigned char color_depth;
|
unsigned char color_depth;
|
||||||
unsigned int line_width;
|
unsigned int line_width;
|
||||||
@@ -53,7 +54,7 @@ void generate_bmp_line(unsigned short y, unsigned char *data_buffer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_parameters(parameters params) {
|
void debug_parameters(Parameters params) {
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
printf(" output %s\n", params.file_path);
|
printf(" output %s\n", params.file_path);
|
||||||
printf(" seed %ld\n", params.seed);
|
printf(" seed %ld\n", params.seed);
|
||||||
@@ -74,7 +75,7 @@ void debug_parameters(parameters params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(parameters params) {
|
void init(Parameters params) {
|
||||||
global_params = params;
|
global_params = params;
|
||||||
slope = ((float)params.slope) / 255.0;
|
slope = ((float)params.slope) / 255.0;
|
||||||
color_depth = params.monochrome ? 1 : 3;
|
color_depth = params.monochrome ? 1 : 3;
|
||||||
@@ -94,14 +95,14 @@ void clean() {
|
|||||||
free(current_line);
|
free(current_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_time(parameters params, clock_t start) {
|
void print_time(Parameters params, clock_t start) {
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
clock_t now = clock();
|
clock_t now = clock();
|
||||||
printf("time: %.3fs\n", (float)(now - start) / CLOCKS_PER_SEC);
|
printf("time: %.3fs\n", (float)(now - start) / CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate(parameters params) {
|
void generate(Parameters params) {
|
||||||
if (!params.quiet) {
|
if (!params.quiet) {
|
||||||
puts(PACKAGE " " VERSION);
|
puts(PACKAGE " " VERSION);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,6 +3,6 @@
|
|||||||
#ifndef GENERATOR_H
|
#ifndef GENERATOR_H
|
||||||
#define GENERATOR_H
|
#define GENERATOR_H
|
||||||
|
|
||||||
void generate(parameters params);
|
void generate(Parameters params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
#include "args.h"
|
#include "args.h"
|
||||||
#include "generator.h"
|
#include "generator.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
parameters params;
|
Parameters params;
|
||||||
params = parse_args(argc, argv);
|
params = parse_args(argc, argv);
|
||||||
generate(params);
|
generate(params);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "rand.h"
|
||||||
|
|
||||||
static unsigned long long mcg_state = 0xcafef00dd15ea5e5u; // Must be odd
|
static unsigned long long mcg_state = 0xcafef00dd15ea5e5u; // Must be odd
|
||||||
static unsigned long long const multiplier = 6364136223846793005u;
|
static unsigned long long const multiplier = 6364136223846793005u;
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -3,7 +3,7 @@
|
|||||||
#ifndef TYPES_H
|
#ifndef TYPES_H
|
||||||
#define TYPES_H
|
#define TYPES_H
|
||||||
|
|
||||||
struct Parameters {
|
typedef struct Parameters {
|
||||||
bool quiet;
|
bool quiet;
|
||||||
bool monochrome;
|
bool monochrome;
|
||||||
unsigned long seed;
|
unsigned long seed;
|
||||||
@@ -15,9 +15,7 @@ struct Parameters {
|
|||||||
unsigned char start[3];
|
unsigned char start[3];
|
||||||
unsigned char var[3];
|
unsigned char var[3];
|
||||||
unsigned char rotation;
|
unsigned char rotation;
|
||||||
};
|
} Parameters;
|
||||||
|
|
||||||
typedef struct Parameters parameters;
|
|
||||||
|
|
||||||
typedef void line_fn(unsigned short y, unsigned char *data_buffer,
|
typedef void line_fn(unsigned short y, unsigned char *data_buffer,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
|
|||||||
Reference in New Issue
Block a user