Skip to content

Commit

Permalink
Mass reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jdarge authored Aug 9, 2023
1 parent 4ee9116 commit 0653c27
Show file tree
Hide file tree
Showing 19 changed files with 349 additions and 378 deletions.
21 changes: 8 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ cmake_minimum_required(VERSION 3.25)
# Setting a variable to use for both the project name and the resulting binary executable
set(REPO timer)
project(${REPO})
set(PROJECT_NAME ${REPO})

set(PROJECT_NAME ${REPO})


# Set the C standard to C99
Expand All @@ -14,7 +13,6 @@ set(CMAKE_C_STANDARD 99)
set(CPP_FLAGS "-Wall -Wextra -pedantic")



# Add the src directory to the include path
include_directories(${PROJECT_SOURCE_DIR}/include)

Expand All @@ -25,32 +23,29 @@ file(GLOB SOURCES ${PROJECT_SOURCE_DIR}/src/*.c)
add_executable(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/driver.c ${SOURCES})



# Set the output directory to the build/bin directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/bin)
set_target_properties(${PROJECT_NAME}
PROPERTIES
COMPILE_FLAGS ${CPP_FLAGS}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/bin
)
PROPERTIES
COMPILE_FLAGS ${CPP_FLAGS}
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/bin
)

# Set the object directory to the build/obj directory
set_property(
TARGET ${PROJECT_NAME}
PROPERTY
CMAKE_OBJECT_PATH_PREFIX ${PROJECT_SOURCE_DIR}/build/obj/
TARGET ${PROJECT_NAME}
PROPERTY
CMAKE_OBJECT_PATH_PREFIX ${PROJECT_SOURCE_DIR}/build/obj/
)



# Set the cmake binary directory to the build/cmake directory
set(CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/build/cmake)

# Add the build/cmake directory to the include path
include_directories(${PROJECT_SOURCE_DIR}/build/cmake)



# Add any other dependencies here, such as libraries or additional build options

target_link_libraries(${PROJECT_NAME} PRIVATE ao) # -lao
Expand Down
22 changes: 12 additions & 10 deletions driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

volatile bool allow_input = false;

void* input_thread();
void *input_thread(void *arg);

int main (int argc, char** argv) {
int main(int argc, char **argv) {

// used to capture user input prior to timer going off
pthread_t input_thread_id;
pthread_create(&input_thread_id, NULL, input_thread, NULL);

if (argc == 1 || argc > 3) {
FAULT:
FAULT:
display_help();
return 1;
}
Expand All @@ -28,12 +28,14 @@ int main (int argc, char** argv) {
goto FAULT;
}

char* alarm = "/usr/local/share/timer/sound/alarm.mp3";
AUDIO* a = audio_init(alarm);
if(!a) return 1;
char *alarm = "/usr/local/share/timer/sound/alarm.mp3"; // install
// char *alarm = "sound/alarm.mp3"; // debugging

AUDIO *a = audio_init(alarm);
if (!a) return 1;

int t = timer(argv);
if(t) return 1;
if (t) return 1;

play_alarm(a);
pthread_join(input_thread_id, NULL);
Expand All @@ -44,7 +46,9 @@ int main (int argc, char** argv) {
return 0;
}

void* input_thread() {
void *input_thread(void *arg) {
(void) arg; // to avoid unused variable warning lol

int c;
while (!allow_input) {
c = getchar();
Expand All @@ -56,10 +60,8 @@ void* input_thread() {
return NULL;
}


/*
TODO:
# dnf install mpg123-devel
# dnf install libao-devel
*/

28 changes: 17 additions & 11 deletions include/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
#include <ao/ao.h>

typedef struct AUDIO {
mpg123_handle* mh;
ao_device* dev;
ao_sample_format format;
int err;
mpg123_handle *mh;
ao_device *dev;
ao_sample_format format;
int err;
} AUDIO;

AUDIO* audio_init (char* file);
void init_handle (AUDIO* a);
void init_err (AUDIO* a, char* mp3);
void init_format (AUDIO* a);
void init_dev (AUDIO* a);
void play_alarm (AUDIO* a);
void audio_clean (AUDIO* a);
AUDIO *audio_init(char *file);

void init_handle(AUDIO *a);

void init_err(AUDIO *a, char *mp3);

void init_format(AUDIO *a);

void init_dev(AUDIO *a);

void play_alarm(AUDIO *a);

void audio_clean(AUDIO *a);

#endif
21 changes: 13 additions & 8 deletions include/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@

#define CYAN "\033[1m\033[36m"
#define CLEAR "\033[0m"

void display_help ();
int check_arguments (int argc, char** argv);
void clear_line();

void display_help(void);

int check_arguments(int argc, char **argv);

void clear_line(void);

#undef is_second

int is_second(char* s);
int is_minute(char* s);
int is_hour(char* s);
int is_format(char* s);
int is_second(char *s);

int is_minute(char *s);

int is_hour(char *s);

int is_format(char *s);

#endif
2 changes: 1 addition & 1 deletion include/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#define TIMER_KEYBOARD_INCLUDED

// Function to check if a key has been pressed
int kbhit();
int kbhit(void);

#endif
43 changes: 24 additions & 19 deletions include/leak_detector_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@
#ifndef LEAK_DETECTOR_C_H
#define LEAK_DETECTOR_C_H

#define FILE_NAME_LENGTH 256
#define OUTPUT_FILE "leak_info.txt"
#define malloc(size) xmalloc (size, __FILE__, __LINE__)
#define calloc(elements, size) xcalloc (elements, size, __FILE__, __LINE__)
#define free(mem_ref) xfree(mem_ref)

struct _MEM_INFO
{
void *address;
unsigned int size;
char file_name[FILE_NAME_LENGTH];
unsigned int line;
#define FILE_NAME_LENGTH 256
#define OUTPUT_FILE "leak_info.txt"
#define malloc(size) xmalloc (size, __FILE__, __LINE__)
#define calloc(elements, size) xcalloc (elements, size, __FILE__, __LINE__)
#define free(mem_ref) xfree(mem_ref)

struct _MEM_INFO {
void *address;
unsigned int size;
char file_name[FILE_NAME_LENGTH];
unsigned int line;
};
typedef struct _MEM_INFO MEM_INFO;

struct _MEM_LEAK {
MEM_INFO mem_info;
struct _MEM_LEAK * next;
MEM_INFO mem_info;
struct _MEM_LEAK *next;
};
typedef struct _MEM_LEAK MEM_LEAK;

void add(MEM_INFO alloc_info);

void erase(unsigned pos);

void clear(void);

void * xmalloc(unsigned int size, const char * file, unsigned int line);
void * xcalloc(unsigned int elements, unsigned int size, const char * file, unsigned int line);
void xfree(void * mem_ref);
void *xmalloc(unsigned int size, const char *file, unsigned int line);

void *xcalloc(unsigned int elements, unsigned int size, const char *file, unsigned int line);

void xfree(void *mem_ref);

void add_mem_info(void *mem_ref, unsigned int size, const char *file, unsigned int line);

void remove_mem_info(void *mem_ref);

void add_mem_info (void * mem_ref, unsigned int size, const char * file, unsigned int line);
void remove_mem_info (void * mem_ref);
void report_mem_leak(void);

#endif
Expand Down
4 changes: 2 additions & 2 deletions include/number.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef TIMER_NUMBER_INCLUDED
#define TIMER_NUMBER_INCLUDED

int is_num(char* str);
int is_num(char *str);

#endif
#endif
8 changes: 4 additions & 4 deletions include/strtonum.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

long long strtonum(const char *numstr, long long minval, long long maxval, const char **errstrp);

#define INVALID 1
#define TOOSMALL 2
#define TOOLARGE 3
#define INVALID 1
#define TOOSMALL 2
#define TOOLARGE 3

#endif
#endif
11 changes: 6 additions & 5 deletions include/timer.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef TIMER_TIMER_INCLUDED
#define TIMER_TIMER_INCLUDED

#define SECOND 1
#define SECOND 1
#define MINUTE 2
#define HOUR 3
#define HOUR 3
#define FORMAT 4

int timer (char** str);
int get_time_in_s(char* str, char* num);
int timer(char **str);

#endif
int get_time_in_s(char *str, char *num);

#endif
18 changes: 9 additions & 9 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/bin/bash

# Generate Binary Executable
chmod +x run.sh
./run.sh
chmod +x run.sh
./run.sh

# Detect the user's shell
SHELL_CONFIG_FILE=""
if [[ -n "$BASH_VERSION" ]]; then
SHELL_CONFIG_FILE=~/.bashrc
SHELL_CONFIG_FILE=~/.bashrc
elif [[ -n "$ZSH_VERSION" ]]; then
SHELL_CONFIG_FILE=~/.zshrc
SHELL_CONFIG_FILE=~/.zshrc
else
echo "Unsupported shell. Please add /usr/local/bin to your PATH manually."
exit 1
echo "Unsupported shell. Please add /usr/local/bin to your PATH manually."
exit 1
fi

# Check if /usr/local/bin is in PATH
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
echo "Adding /usr/local/bin to PATH"
echo 'export PATH=$PATH:/usr/local/bin' >> "$SHELL_CONFIG_FILE"
source "$SHELL_CONFIG_FILE"
echo "Adding /usr/local/bin to PATH"
echo 'export PATH=$PATH:/usr/local/bin' >>"$SHELL_CONFIG_FILE"
source "$SHELL_CONFIG_FILE"
fi

# Move timer executable
Expand Down
58 changes: 26 additions & 32 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@

project="timer"

if [ "$1" == "build" ] || [ "$1" == "make" ]
then
if [ "$1" == "build" ] || [ "$1" == "make" ]; then
cmake -B build/cmake/ -S .
make -C build/cmake/
elif [ "$1" == "rebuild" ]; then
rm -rf build/bin/* build/cmake/*
cmake -B build/cmake/ -S .
make -C build/cmake/
elif [ "$1" == "clean" ]; then
rm -rf build/
elif [ "$1" == "help" ]; then
echo -e "Build project:\t ./run build"
echo -e "Rebuild project: ./run rebuild"
echo -e "Clean project:\t ./run clean"
echo -e "Run project:\t ./run"
else
if [ -e build/bin/$project ]; then
exec build/bin/$project "$@"
else
echo "No binary executable named \"$project\" found in the directory \"build/bin/\"."
echo "Building..."

cmake -B build/cmake/ -S .
make -C build/cmake/
elif [ "$1" == "rebuild" ]
then
rm -rf build/bin/* build/cmake/*
cmake -B build/cmake/ -S .
make -C build/cmake/
elif [ "$1" == "clean" ]
then
rm -rf build/
elif [ "$1" == "help" ]
then
echo -e "Build project:\t ./run build"
echo -e "Rebuild project: ./run rebuild"
echo -e "Clean project:\t ./run clean"
echo -e "Run project:\t ./run"
else
if [ -e build/bin/$project ]
then
exec build/bin/$project "$@"
else
echo "No binary executable named \"$project\" found in the directory \"build/bin/\"."
echo "Building..."

cmake -B build/cmake/ -S .
make -C build/cmake/
if [ -e build/bin/$project ]
then
exec build/bin/$project "$@"
else
echo "Project built, but no binary executable found. Verify your project names match between the shell script and CMakeLists.txt"
fi
if [ -e build/bin/$project ]; then
exec build/bin/$project "$@"
else
echo "Project built, but no binary executable found. Verify your project names match between the shell script and CMakeLists.txt"
fi
fi
fi
Loading

0 comments on commit 0653c27

Please sign in to comment.