Skip to content

Commit

Permalink
Merge pull request #7 from rounnus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
constarg authored Apr 11, 2022
2 parents b449b94 + 3d98e2a commit 064710a
Show file tree
Hide file tree
Showing 18 changed files with 573 additions and 574 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ dkms.conf
/service/
/autostart/
.idea

*.swp
*.swo
19 changes: 11 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
cmake_minimum_required(VERSION 3.19)
project(File_Sorter_Core C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD 17)

add_executable(file-sorter main.c tools/logger.c tools/include/log/logger.h tools/config_parser.c tools/include/config/config_parser.h src/manager.c src/include/manager.h tools/include/mem.h)
set(SOURCE_FILES main.c ./src/config.c ./src/sorter.c ./src/logger.c)
set(HEADER_FILES ./include/config.h ./include/sorter.h ./include/logger.h)
set(TO_INCLUDE ./include/)

include_directories(
src/include
tools/include
)
add_executable(file-sorter ${SOURCE_FILES} ${HEADER_FILES})

include_directories(${TO_INCLUDE})

set(GCC_COVERAGE_COMPILE_FLAGS "-pthread")

Expand Down Expand Up @@ -47,11 +48,13 @@ file(WRITE config/config.conf
\n
[check]\n
\n
[done_check]\n
[done]\n
\n
[targets]\n
\n
[done_targets])
[done]\n
[exclude]\n
[done])

file(WRITE service/file-sorter.service
[Unit]\n
Expand Down
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ enable_default_path 1
[check]
[done_check]
[done]
[targets]
[done_targets]
[done]
[exclude]
[done]
```
The config is stored in the following location:<br>
`~/.local/share/file_sorter/config/config.conf`
Expand All @@ -71,6 +75,7 @@ Field | Description
`enable_default_path` | If this option is enabled, then any file that do not have a specific location to which they should be sent will be sent to the default.
`[check]` | This field includes all locations where the program will look for files. Each location that enters this field must be entered before `[done_check]`.
`[targets]` | This field contains all the file extensions and all the locations that these files should be sent to. Each line in this field consists of two elements that are separated by a space. The first element is the extension of the file and the second is the location where this file should be sent. Also each new line must be entered before `[done_targets]`.
`[exclude]` | This field contains all the file extensions and all the locations that these files should be ignored. Each line in this field consists of two elements that are separated by a space. The first element is the extension of the file and the second is the location where it must ignore a file. If a file has to be ignored in any location, then * must be placed instead of location. Also each new line must be entered before `[done]`.

An example of `[check]`:<br>

Expand All @@ -79,7 +84,7 @@ An example of `[check]`:<br>
/home/username/
/home/username/Desktop/
...
[done_check]
[done]
```

An example of `[targets]`:<br>
Expand All @@ -89,12 +94,23 @@ An example of `[targets]`:<br>
.py /home/username/Documents/py/
.cpp /home/username/Documents/cpp/
...
[done_targets]
[done]
```

In the example above the first part consists of the extensions `.py` and `.cpp` and the second part of the
locations `/home/username/ Documents/py/` and `/home/username/Documents/cpp/`.

```
[exclude]
.py /home/username/Documents/py/
.c *
...
[done]
```

In the example above the first part consists of the extensions `.py` and `.c` and the second part of the
locations `/home/username/Documents/py/` and `*`.

# Tool
Due to the nature of this program and this config i made a tool that helps the user to do the following:<br>
- Add locations to the config check field.<br>
Expand Down
6 changes: 4 additions & 2 deletions config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ enable_default_path 1

[check]

[done_check]
[done]

[targets]

[done_targets]
[done]
[exclude]
[done]
57 changes: 57 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* config.h */
#ifndef FILE_SORTER_CORE_CONFIG_H
#define FILE_SORTER_CORE_CONFIG_H

#include <memory.h>

#define FAILED_TO_PARSE -0x1


// config options.
struct options
{
unsigned int o_check_interval; // check interval option.
unsigned int o_parse_interval; // parse interval option.
unsigned int o_debug_log:1; // debug log option.
char *o_default_path; // default path option.
unsigned int o_enable_default:1; // enable default path option.
};

// config lists.
struct lists
{
char *(*l_check_list); // the check list of the config.
char *(*l_target_list); // the targests of the config.
char *(*l_exclude_list); // the excludes of the config.

};

// the config file.
struct config
{
struct options c_options; // the options of the config.
struct lists c_lists; // the lists of the config.
};


/**
Initialize the variable that contains the config
file.
**/
static void inline init_config(struct config *config)
{
memset(config, 0x0, sizeof(struct config));
}

/**
Parse the config file and save the informations
inside the dst variable.
@param dst The destination of where we put the config.
*/
extern void parse_config(struct config *dst);

extern void reparse_config(struct config *dst);

extern void destroy_config(struct config *src);

#endif
19 changes: 19 additions & 0 deletions include/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef SORTER_LOGGER_H
#define SORTER_LOGGER_H

// log tyoes.
#define ERROR 1
#define WAR 2
#define LOG 3

/**
Logs a message.
@param msg The message to log.
@param type The type of the log.
*/
extern void logger(const char *msg, int type);




#endif
8 changes: 8 additions & 0 deletions include/sorter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef SORTER_H
#define SORTER_H

#include <config.h>

extern void start_sorter(struct config *src);

#endif
35 changes: 30 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
#include <manager.h>
#ifdef __unix__

#include <malloc.h>

int main() {
run();
return 0;
}
#include <config.h>
#include <sorter.h>

#else
// TODO - include logger.
#endif




int main(int argc, char *argv[])
{
#ifdef __unix__
struct config config_p;
// initialzize the config.
init_config(&config_p);

// parse config.
parse_config(&config_p);

// start procces
start_sorter(&config_p);

destroy_config(&config_p);
#else
// TODO - call logger and write that the oparating system is not compatiple.
#endif
}
Loading

0 comments on commit 064710a

Please sign in to comment.