-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mehmetmertguduz
committed
May 31, 2024
1 parent
d91a0f6
commit 77e15c5
Showing
8 changed files
with
39 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
set(SOURCES | ||
conf_nsfw.c | ||
conf_plog.c | ||
conf_img_viewer_command.c | ||
) | ||
|
||
add_library(yiffy-conf STATIC ${SOURCES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @file conf_img_viewer_command.c | ||
* | ||
* @brief This file is used to configures the image viewer command system, the image viewer command is used to show images on terminal in search function. | ||
* | ||
* This file goes to the /home/user/.yiffy/yiffy-config.txt and sets the IMG_DISPLAY_COMMAND with an image viewer command. | ||
* | ||
* @author Mehmet Mert Gunduz ([email protected]) | ||
* | ||
* @date 31/05/2024 | ||
*/ | ||
|
||
#define MAX_FILE_PATH 256 | ||
#define MAX_BUFFER_SIZE 512 | ||
|
||
#include "yiffy_conf.h" | ||
|
||
/** | ||
* @brief Configures the image viewer command system, the image viewer command is used to show images on terminal in search function. | ||
* | ||
* @param argv This is the value that stores the command string. | ||
*/ | ||
void conf_img_viewer_command(char *argv) | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,23 @@ | ||
/** | ||
* @file conf_nsfw.c | ||
* | ||
* @brief This file is used to configure the nsfw system. Basically alters the request URL. | ||
* @brief This file is used to configure the NSFW option. | ||
* | ||
* This file goes to the /home/user/.yiffy/yiffy-config.txt and sets the nsfw function to on or off depending the option. | ||
* This file goes to the /home/user/.yiffy/yiffy-config.txt and sets the IS_NSFW to on/off. | ||
* | ||
* @author Mehmet Mert Gunduz ([email protected]) | ||
* | ||
* @date 05/09/2023 | ||
*/ | ||
|
||
#define MAX_FILE_PATH 256 | ||
#define MAX_BUFFER_SIZE 512 | ||
|
||
#include "yiffy_conf.h" | ||
|
||
/** | ||
* @brief Configures the nsfw system. Basically alters the request URL. | ||
* @brief Configures the nsfw NSFW option. | ||
* | ||
* @param argv This is the value that stores on/off. | ||
*/ | ||
void conf_nsfw(char *argv) | ||
{ | ||
char file_path[MAX_FILE_PATH]; | ||
char buffer[MAX_BUFFER_SIZE]; | ||
|
||
/* Operation boolean, used to check if it exists in the current configuration or not. */ | ||
bool is_nsfw; | ||
|
||
/* To write or delete the configuration setting. Keyword (nsfw) has got 4 characters. */ | ||
int option_size = 4; | ||
|
||
/* To set the index of the option. */ | ||
int nsfw_index; | ||
|
||
/* Get the home directory of the current user. */ | ||
char *home_directory = getenv("HOME"); | ||
|
||
if (home_directory == NULL) | ||
{ | ||
no_home_error_msg(); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
/* Create the configuration file path. */ | ||
sprintf(file_path, "%s/.yiffy/yiffy-config.txt", home_directory); | ||
|
||
/* create file pointer */ | ||
FILE *conf_read_write_file = fopen(file_path, "r+"); | ||
|
||
if (conf_read_write_file == NULL) | ||
{ | ||
file_open_error_msg(); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
fscanf(conf_read_write_file, "%s", buffer); | ||
|
||
/* Close the conf read file. */ | ||
fclose(conf_read_write_file); | ||
|
||
/* Get the buffer size. */ | ||
int buffer_size = strlen(buffer); | ||
|
||
/* Check if the nsfw string exists. */ | ||
char *string = strstr(buffer, "nsfw"); | ||
|
||
if (string != NULL) | ||
{ | ||
/* Get the index of the nsfw token. */ | ||
nsfw_index = string - buffer; | ||
|
||
/* Set the boolean to true to make operations. */ | ||
is_nsfw = true; | ||
} | ||
|
||
if (strcmp(argv, "on") == 0 && is_nsfw) | ||
{ | ||
already_conf_msg("nsfw", argv); | ||
} | ||
else if (strcmp(argv, "on") == 0 && !is_nsfw) | ||
{ | ||
FILE *conf_append_file = fopen(file_path, "a"); | ||
|
||
if (conf_append_file == NULL) | ||
{ | ||
file_open_error_msg(); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
fprintf(conf_append_file, ":nsfw"); | ||
|
||
fclose(conf_append_file); | ||
|
||
conf_successful_msg("nsfw", argv); | ||
} | ||
else if (strcmp(argv, "off") == 0 && !is_nsfw) | ||
{ | ||
already_conf_msg("nsfw", argv); | ||
} | ||
else if (strcmp(argv, "off") == 0 && is_nsfw) | ||
{ | ||
FILE *conf_write_file = fopen(file_path, "w"); | ||
|
||
if (conf_write_file == NULL) | ||
{ | ||
file_open_error_msg(); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
for (size_t i = 0; i < buffer_size; i++) | ||
{ | ||
if (nsfw_index == 0 && i == nsfw_index) | ||
{ | ||
i = i + option_size; | ||
continue; | ||
} | ||
else | ||
{ | ||
if (i == nsfw_index - 1) | ||
{ | ||
i = i + option_size; | ||
continue; | ||
} | ||
} | ||
|
||
fputc(buffer[i], conf_write_file); | ||
} | ||
|
||
fclose(conf_write_file); | ||
|
||
conf_successful_msg("nsfw", argv); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters