-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshuffle.h
71 lines (62 loc) · 1.35 KB
/
shuffle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <wchar.h>
#include <locale.h>
#include <errno.h>
#include <signal.h>
#include <stdbool.h>
// Program version
#define VERSION "1.3.1"
// Constants for program configuration
#define MAX_SPEED 500
#define MIN_SPEED 1
#define BASE_NANOSECONDS 10000
#define INITIAL_BUFFER_SIZE 1024
#define DISPLAY_PAUSE_SECONDS 2
// Color constants
#define MAX_COLOR_VALUE 255
#define DEFAULT_COLOR "white"
// Return codes
#define SUCCESS 0
#define ERROR_MEMORY -1
#define ERROR_FILE -2
#define ERROR_INPUT -3
// Function types
typedef void (*shuffle_func)(int *, size_t);
// Structure for program configuration
typedef struct
{
int width;
int height;
int speed;
char *color;
bool is_help;
const wchar_t *input_text;
} ShuffleConfig;
// Structure for color
typedef struct
{
int r;
int g;
int b;
bool is_random;
} Color;
// Function declarations
void shuffle_array(int *array, size_t n);
int load_ascii(const char *filename, wchar_t **output);
bool is_valid_color(const char *color);
int show_shuffled(const ShuffleConfig *config);
Color parse_color(const char *color_str);
void cleanup_resources(void);
// Inline functions
static inline void swap_ints(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}