Skip to content

Commit

Permalink
ivcommand added
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetmertguduz committed May 31, 2024
1 parent d91a0f6 commit 77e15c5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 260 deletions.
2 changes: 1 addition & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install(TARGETS yiffy DESTINATION /usr/local/bin)
install(CODE "
file(MAKE_DIRECTORY \"${dest_path}\")
file(WRITE \"${dest_path}/yiffy-config.txt\" \"IS_NSFW=NO\nIMG_DISPLAY_COMMAND=ascii-image-converter\n\")
file(WRITE \"${dest_path}/yiffy-credentials.txt\" \"API_KEY=\nUSERNAME=\n\")
file(WRITE \"${dest_path}/yiffy-credentials.txt\" \"USERNAME=\nAPI-KEY=\n\")
execute_process(COMMAND chmod 755 \"${dest_path}\")
execute_process(COMMAND chmod 755 \"${dest_path}/yiffy-config.txt\")
execute_process(COMMAND chmod 755 \"${dest_path}/yiffy-credentials.txt\")
Expand Down
12 changes: 6 additions & 6 deletions src/app/yiffy.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static struct general_option general_options[] =
{"--config", show_config},
{"--export", export_local_data},
{"--import", import_local_data},
{"--plog", conf_plog},
{"--ivcommand", conf_img_viewer_command},
{"--nsfw", conf_nsfw},
{"--search", search_urls}
};
Expand Down Expand Up @@ -127,7 +127,7 @@ int main(int argc, char *argv[])
static bool argument_verify(int argument_count, char *arguments[])
{
char *one_arguments[] = {"--help", "--version", "--github", "--website", "--config", "--export", "--import"};
char *two_arguments[] = {"--plog", "--nsfw", "--dfetch", "--fetch", "--search"};
char *two_arguments[] = {"--ivcommand", "--nsfw", "--dfetch", "--fetch", "--search"};


if (argument_count == 3)
Expand All @@ -136,18 +136,18 @@ static bool argument_verify(int argument_count, char *arguments[])
* @section Two Arguments Handling
*
* It checks if the passed argument exists in the two_arguments array.
* If the passed option is --dfetch, --fetch or --search it returns true.
* If the passed option is --dfetch, --fetch, --search or --ivcommand it returns true.
* Also, if the passed option is one of the twoArgument options and includes on/off as the second option returns true.
* If not, returns false and shows the user that the second option can only be on/off.
*
* two_arguments they don't take on off: --dfetch, --fetch, --search.
* two_arguments they take on/off: --plog, --nsfw.
* two_arguments they don't take on/off: --dfetch, --fetch, --search, --ivcommand.
* two_arguments they take on/off: --nsfw.
*/
for (size_t i = 0; i < sizeof(two_arguments) / sizeof(two_arguments[0]); i++)
{
if (strcmp(arguments[1], two_arguments[i]) == 0)
{
if (strcmp(arguments[2], "on") == 0 || strcmp(arguments[2], "off") == 0 || strcmp(arguments[1], "--dfetch") == 0 || strcmp(arguments[1], "--fetch") == 0 || strcmp(arguments[1], "--search") == 0)
if (strcmp(arguments[2], "on") == 0 || strcmp(arguments[2], "off") == 0 || strcmp(arguments[1], "--dfetch") == 0 || strcmp(arguments[1], "--fetch") == 0 || strcmp(arguments[1], "--search") == 0 || strcmp(arguments[1], "--ivcommand") == 0)
{
return RECOGNIZED_ARGUMENT; /* Return true. */
}
Expand Down
2 changes: 1 addition & 1 deletion src/conf/CMakeLists.txt
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})
26 changes: 26 additions & 0 deletions src/conf/conf_img_viewer_command.c
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)
{

}
118 changes: 3 additions & 115 deletions src/conf/conf_nsfw.c
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);
}
}
135 changes: 0 additions & 135 deletions src/conf/conf_plog.c

This file was deleted.

2 changes: 1 addition & 1 deletion src/conf/yiffy_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <stdbool.h>
#include "../msg/yiffy_messages.h"

void conf_plog(char *argv);
void conf_nsfw(char *argv);
void conf_img_viewer_command(char *argv);

#endif /* YIFFY_CONF_H */
2 changes: 1 addition & 1 deletion src/msg/no_arg_value_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void no_arg_value_msg(char *argument)
fprintf(stderr, "yiffy: please enter the argument value for \"%s\".\n", argument);
fprintf(stderr, "yiffy: valid values for \"%s\" are on/off.\n", argument);
}
else if (strcmp(argument, "--search") == 0 || strcmp(argument, "--dfetch") == 0 || strcmp(argument, "--fetch") == 0)
else if (strcmp(argument, "--search") == 0 || strcmp(argument, "--dfetch") == 0 || strcmp(argument, "--fetch") == 0 || strcmp(argument, "--ivcommand") == 0)
{
fprintf(stderr, "yiffy: please enter the search tags.\n");
fprintf(stderr, "yiffy: prompt \"man yiffy\" to read the user manual.\n");
Expand Down

0 comments on commit 77e15c5

Please sign in to comment.