diff --git a/docs/html/d1/d33/yiffy__conf_8h.html b/docs/html/d1/d33/yiffy__conf_8h.html index 4ae9755..57f1f81 100644 --- a/docs/html/d1/d33/yiffy__conf_8h.html +++ b/docs/html/d1/d33/yiffy__conf_8h.html @@ -186,7 +186,7 @@

Definition at line 23 of file conf_img_viewer_command.c.

+

Definition at line 31 of file conf_img_viewer_command.c.

diff --git a/docs/html/d1/d33/yiffy__conf_8h_source.html b/docs/html/d1/d33/yiffy__conf_8h_source.html index 5038be0..2ac5490 100644 --- a/docs/html/d1/d33/yiffy__conf_8h_source.html +++ b/docs/html/d1/d33/yiffy__conf_8h_source.html @@ -124,7 +124,7 @@
21
22#endif /* YIFFY_CONF_H */
void conf_nsfw(char *argv)
Configures the nsfw NSFW option.
Definition: conf_nsfw.c:29
-
void conf_img_viewer_command(char *argv)
Configures the image viewer command system, the image viewer command is used to show images on termin...
+
void conf_img_viewer_command(char *argv)
Configures the image viewer command system, the image viewer command is used to show images on termin...
diff --git a/docs/html/da/d93/conf__img__viewer__command_8c.html b/docs/html/da/d93/conf__img__viewer__command_8c.html index f58dbdc..98d1b39 100644 --- a/docs/html/da/d93/conf__img__viewer__command_8c.html +++ b/docs/html/da/d93/conf__img__viewer__command_8c.html @@ -136,10 +136,15 @@ - - - - + + + + + + + + +

Macros

#define MAX_FILE_PATH   256
 
#define MAX_BUFFER_SIZE   512
 
#define FILE_PATH_SIZE   256
 This macro is used to set the default size for getting the home directory file. More...
 
#define BUFFER_SIZE   512
 This macro is used to set the default size for reading the config file. More...
 
#define FILE_SIZE   2048
 This macro is used to set the default size for the file. More...
 
@@ -155,36 +160,58 @@

Definition in file conf_img_viewer_command.c.

Macro Definition Documentation

- -

◆ MAX_BUFFER_SIZE

+ +

◆ BUFFER_SIZE

Functions

- +
#define MAX_BUFFER_SIZE   512#define BUFFER_SIZE   512
+

This macro is used to set the default size for reading the config file.

+

Definition at line 14 of file conf_img_viewer_command.c.

- -

◆ MAX_FILE_PATH

+ +

◆ FILE_PATH_SIZE

- +
#define MAX_FILE_PATH   256#define FILE_PATH_SIZE   256
+

This macro is used to set the default size for getting the home directory file.

+

Definition at line 13 of file conf_img_viewer_command.c.

+
+
+ +

◆ FILE_SIZE

+ +
+
+ + + + +
#define FILE_SIZE   2048
+
+ +

This macro is used to set the default size for the file.

+ +

Definition at line 15 of file conf_img_viewer_command.c.

+

Function Documentation

@@ -212,7 +239,7 @@

Definition at line 23 of file conf_img_viewer_command.c.

+

Definition at line 31 of file conf_img_viewer_command.c.

diff --git a/docs/html/da/d93/conf__img__viewer__command_8c.js b/docs/html/da/d93/conf__img__viewer__command_8c.js index a4a5c8a..9afb577 100644 --- a/docs/html/da/d93/conf__img__viewer__command_8c.js +++ b/docs/html/da/d93/conf__img__viewer__command_8c.js @@ -1,6 +1,7 @@ var conf__img__viewer__command_8c = [ - [ "MAX_BUFFER_SIZE", "da/d93/conf__img__viewer__command_8c.html#ad4d796b98c583d49e83adabd74a63bf6", null ], - [ "MAX_FILE_PATH", "da/d93/conf__img__viewer__command_8c.html#a263efd24d550124313df51247f07457a", null ], + [ "BUFFER_SIZE", "da/d93/conf__img__viewer__command_8c.html#a6b20d41d6252e9871430c242cb1a56e7", null ], + [ "FILE_PATH_SIZE", "da/d93/conf__img__viewer__command_8c.html#a995dadc733fcb391aac2116c80dd9508", null ], + [ "FILE_SIZE", "da/d93/conf__img__viewer__command_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5", null ], [ "conf_img_viewer_command", "da/d93/conf__img__viewer__command_8c.html#a3ebba735c22a2c7fed2d6deeca8f1529", null ] ]; \ No newline at end of file diff --git a/docs/html/da/d93/conf__img__viewer__command_8c_source.html b/docs/html/da/d93/conf__img__viewer__command_8c_source.html index 36e8b2f..c15c2d7 100644 --- a/docs/html/da/d93/conf__img__viewer__command_8c_source.html +++ b/docs/html/da/d93/conf__img__viewer__command_8c_source.html @@ -111,16 +111,88 @@
Go to the documentation of this file.
1
-
13#define MAX_FILE_PATH 256
-
14#define MAX_BUFFER_SIZE 512
-
15
-
16#include "yiffy_conf.h"
-
17
- -
24{
+
13#define FILE_PATH_SIZE 256
+
14#define BUFFER_SIZE 512
+
15#define FILE_SIZE 2048
+
16
+
17static char *home_directory;
+
18
+
19static char file_path[FILE_PATH_SIZE];
+
20static char buffer[BUFFER_SIZE];
+
21
+
22static char ivcommand[256];
+
23
+
24#include "yiffy_conf.h"
25
-
26}
-
void conf_img_viewer_command(char *argv)
Configures the image viewer command system, the image viewer command is used to show images on termin...
+ +
32{
+
33 printf("%s\n", argv);
+
34
+
35 /* Create the image viewer command option string. */
+
36 sprintf(ivcommand, "IMG_DISPLAY_COMMAND=%s\n", argv);
+
37
+
38 /* Get the home directory of the current user. */
+
39 home_directory = getenv("HOME");
+
40
+
41 if (home_directory == NULL)
+
42 {
+ +
44 exit(1);
+
45 }
+
46
+
47 /* Create the configuration file path. */
+
48 sprintf(file_path, "%s/.yiffy/yiffy-config.txt", home_directory);
+
49
+
50 FILE *config_file = fopen(file_path, "r");
+
51
+
52 if (config_file == NULL)
+
53 {
+ +
55 exit(EXIT_FAILURE);
+
56 }
+
57
+
58 /* Read the entire file into memory */
+
59 char file_content[FILE_SIZE];
+
60 char *content_ptr = file_content;
+
61 size_t content_length = 0;
+
62
+
63 while (fgets(buffer, BUFFER_SIZE - 1, config_file))
+
64 {
+
65 if (strstr(buffer, "IMG_DISPLAY_COMMAND=") != NULL)
+
66 {
+
67 strcpy(buffer, ivcommand);
+
68 }
+
69
+
70 strcpy(content_ptr, buffer);
+
71
+
72 content_ptr += strlen(buffer);
+
73 content_length += strlen(buffer);
+
74 }
+
75
+
76 /* Close the config file for reading. */
+
77 fclose(config_file);
+
78
+
79 /* Write the modified content back to the file. */
+
80 config_file = fopen(file_path, "w");
+
81
+
82 if (config_file == NULL)
+
83 {
+ +
85 exit(EXIT_FAILURE);
+
86 }
+
87
+
88 fwrite(file_content, sizeof(char), content_length, config_file);
+
89
+
90 /* Close the config file for writing. */
+
91 fclose(config_file);
+
92}
+
char * buffer
Definition: cjson.h:170
+
void conf_img_viewer_command(char *argv)
Configures the image viewer command system, the image viewer command is used to show images on termin...
+
#define BUFFER_SIZE
This macro is used to set the default size for reading the config file.
+
#define FILE_PATH_SIZE
This macro is used to set the default size for getting the home directory file.
+
#define FILE_SIZE
This macro is used to set the default size for the file.
+
void file_open_error_msg()
Shows some information about file permissions when yiffy is not able to read file.
+
void no_home_error_msg()
Outputs the home not found error when application can not access the $HOME environment variable.
This header file is used to do configuration for yiffy.
diff --git a/docs/html/dc/dc0/yiffy_8c_source.html b/docs/html/dc/dc0/yiffy_8c_source.html index c640d08..7f9730a 100644 --- a/docs/html/dc/dc0/yiffy_8c_source.html +++ b/docs/html/dc/dc0/yiffy_8c_source.html @@ -188,7 +188,7 @@
94 {
95 void (*menu_func)(char *argv) = general_options[i].function;
96
-
97 if (strcmp(general_options[i].option, "--search") == 0 || strcmp(general_options[i].option, "--nsfw") == 0 || strcmp(general_options[i].option, "--plog") == 0) /* THIRD ARGUMENT: tags [yiffy --search "blush+fox+male"]*/
+
97 if (strcmp(general_options[i].option, "--search") == 0 || strcmp(general_options[i].option, "--nsfw") == 0 || strcmp(general_options[i].option, "--ivcommand") == 0) /* THIRD ARGUMENT: tags [yiffy --search "blush+fox+male"]*/
98 {
99 menu_func(argv[2]);
100 }
@@ -318,7 +318,7 @@
282}
void access_error_msg()
Checks the accessibility to the e621/e926 api.
void argc_error_msg(int argc)
Evaluates the argument count and gives information if not in the requested format.
-
void conf_img_viewer_command(char *argv)
Configures the image viewer command system, the image viewer command is used to show images on termin...
+
void conf_img_viewer_command(char *argv)
Configures the image viewer command system, the image viewer command is used to show images on termin...
void conf_nsfw(char *argv)
Configures the nsfw NSFW option.
Definition: conf_nsfw.c:29
void extra_arg_error_msg(char *argument)
Outputs the correct format for the prompted option when there is additional invalid argument.
void fetch(char *tags, int page, char *command)
Reads the configuration file, sets the options and sends a request to e621-e926. After taking the res...
Definition: fetch.c:32
diff --git a/docs/html/de/dfc/conf__nsfw_8c_source.html b/docs/html/de/dfc/conf__nsfw_8c_source.html index cfc53cf..2d3aa19 100644 --- a/docs/html/de/dfc/conf__nsfw_8c_source.html +++ b/docs/html/de/dfc/conf__nsfw_8c_source.html @@ -182,25 +182,23 @@
86 content_length += strlen(buffer);
87 }
88
-
89 printf("%d\n", content_length);
-
90
-
91 /* Close the config file for reading. */
-
92 fclose(config_file);
-
93
-
94 /* Write the modified content back to the file. */
-
95 config_file = fopen(file_path, "w");
-
96
-
97 if (config_file == NULL)
-
98 {
- -
100 exit(EXIT_FAILURE);
-
101 }
+
89 /* Close the config file for reading. */
+
90 fclose(config_file);
+
91
+
92 /* Write the modified content back to the file. */
+
93 config_file = fopen(file_path, "w");
+
94
+
95 if (config_file == NULL)
+
96 {
+ +
98 exit(EXIT_FAILURE);
+
99 }
+
100
+
101 fwrite(file_content, sizeof(char), content_length, config_file);
102
-
103 fwrite(file_content, sizeof(char), content_length, config_file);
-
104
-
105 /* Close the config file for writing. */
-
106 fclose(config_file);
-
107}
+
103 /* Close the config file for writing. */
+
104 fclose(config_file);
+
105}
void already_conf_msg(char *option, char *argv)
Shows some information when cjson root gives error.
char * buffer
Definition: cjson.h:170
void conf_nsfw(char *argv)
Configures the nsfw NSFW option.
Definition: conf_nsfw.c:29
diff --git a/docs/html/globals.html b/docs/html/globals.html index c356297..339ac9f 100644 --- a/docs/html/globals.html +++ b/docs/html/globals.html @@ -125,7 +125,7 @@

- b -

@@ -186,8 +186,8 @@

- f -

@@ -219,8 +219,8 @@

- l -

    - m -

    diff --git a/docs/html/globals_defs.html b/docs/html/globals_defs.html index 0b5e0e9..867c6d3 100644 --- a/docs/html/globals_defs.html +++ b/docs/html/globals_defs.html @@ -117,7 +117,7 @@

    - a -

      - b -

      @@ -159,8 +159,8 @@

      - e -

        - f -

        @@ -174,8 +174,8 @@

        - i -

          - m -

          diff --git a/docs/html/navtreedata.js b/docs/html/navtreedata.js index 4bfd8b8..1ad806f 100644 --- a/docs/html/navtreedata.js +++ b/docs/html/navtreedata.js @@ -64,7 +64,7 @@ var NAVTREE = var NAVTREEINDEX = [ "annotated.html", -"dc/d8f/system__func__error__msg_8c_source.html" +"dc/d8f/system__func__error__msg_8c.html#acc21d14c9f9a59987f07615415759325" ]; var SYNCONMSG = 'click to disable panel synchronisation'; diff --git a/docs/html/navtreeindex0.js b/docs/html/navtreeindex0.js index 3148847..ddb9bf0 100644 --- a/docs/html/navtreeindex0.js +++ b/docs/html/navtreeindex0.js @@ -206,9 +206,10 @@ var NAVTREEINDEX0 = "da/d03/already__conf__msg_8c.html#a2b3c403bb7977f8a7672f39dec8d5659":[6,0,0,5,1,0], "da/d03/already__conf__msg_8c_source.html":[6,0,0,5,1], "da/d93/conf__img__viewer__command_8c.html":[6,0,0,2,0], -"da/d93/conf__img__viewer__command_8c.html#a263efd24d550124313df51247f07457a":[6,0,0,2,0,1], -"da/d93/conf__img__viewer__command_8c.html#a3ebba735c22a2c7fed2d6deeca8f1529":[6,0,0,2,0,2], -"da/d93/conf__img__viewer__command_8c.html#ad4d796b98c583d49e83adabd74a63bf6":[6,0,0,2,0,0], +"da/d93/conf__img__viewer__command_8c.html#a3ebba735c22a2c7fed2d6deeca8f1529":[6,0,0,2,0,3], +"da/d93/conf__img__viewer__command_8c.html#a6b20d41d6252e9871430c242cb1a56e7":[6,0,0,2,0,0], +"da/d93/conf__img__viewer__command_8c.html#a995dadc733fcb391aac2116c80dd9508":[6,0,0,2,0,1], +"da/d93/conf__img__viewer__command_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5":[6,0,0,2,0,2], "da/d93/conf__img__viewer__command_8c_source.html":[6,0,0,2,0], "db/d68/structcJSON.html":[5,0,0], "db/d68/structcJSON.html#a369cea49494eb5d4409d532a731a0fbf":[5,0,0,6], @@ -248,6 +249,5 @@ var NAVTREEINDEX0 = "dc/d55/structcJSON__Hooks.html":[5,0,1], "dc/d55/structcJSON__Hooks.html#a42c96b388103ffb466e7335b9fc710c3":[5,0,1,1], "dc/d55/structcJSON__Hooks.html#ae8fc738005f553ff03bc725c58d3188f":[5,0,1,0], -"dc/d8f/system__func__error__msg_8c.html":[6,0,0,5,17], -"dc/d8f/system__func__error__msg_8c.html#acc21d14c9f9a59987f07615415759325":[6,0,0,5,17,0] +"dc/d8f/system__func__error__msg_8c.html":[6,0,0,5,17] }; diff --git a/docs/html/navtreeindex1.js b/docs/html/navtreeindex1.js index 6518c1e..2c4724b 100644 --- a/docs/html/navtreeindex1.js +++ b/docs/html/navtreeindex1.js @@ -1,5 +1,6 @@ var NAVTREEINDEX1 = { +"dc/d8f/system__func__error__msg_8c.html#acc21d14c9f9a59987f07615415759325":[6,0,0,5,17,0], "dc/d8f/system__func__error__msg_8c_source.html":[6,0,0,5,17], "dc/db4/structgeneral__option.html":[5,0,5], "dc/db4/structgeneral__option.html#a62084e958e49adf5c63fc40bcd982748":[5,0,5,1], diff --git a/docs/html/search/all_1.js b/docs/html/search/all_1.js index 3432a59..8f9bcff 100644 --- a/docs/html/search/all_1.js +++ b/docs/html/search/all_1.js @@ -6,5 +6,5 @@ var searchData= ['buffer_3',['buffer',['../d1/dc7/structprintbuffer.html#a754f63618e91db99f7ab6cfc4e629013',1,'printbuffer::buffer()'],['../d5/d56/cjson_8h.html#aff2566f4c366b48d73479bef43ee4d2e',1,'buffer(): cjson.h']]], ['buffer_5fat_5foffset_4',['buffer_at_offset',['../d6/d49/cjson_8c.html#ac538057ef78677344d222b763251af5e',1,'cjson.c']]], ['buffer_5flength_5',['buffer_length',['../d5/d56/cjson_8h.html#a7beaf9b4ef5e4c7254cc3298a3424354',1,'cjson.h']]], - ['buffer_5fsize_6',['BUFFER_SIZE',['../de/dfc/conf__nsfw_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'conf_nsfw.c']]] + ['buffer_5fsize_6',['BUFFER_SIZE',['../da/d93/conf__img__viewer__command_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_img_viewer_command.c'],['../de/dfc/conf__nsfw_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_nsfw.c']]] ]; diff --git a/docs/html/search/all_5.js b/docs/html/search/all_5.js index 161cca8..6770f14 100644 --- a/docs/html/search/all_5.js +++ b/docs/html/search/all_5.js @@ -1,13 +1,13 @@ var searchData= [ ['false_0',['false',['../d6/d49/cjson_8c.html#a65e9886d74aaee76545e83dd09011727',1,'cjson.c']]], - ['fetch_1',['fetch',['../d1/d14/fetch_8c.html#a41f382b6bd05c9776641fb4bc5024afa',1,'fetch(char *tags, int page, char *command): fetch.c'],['../d5/d05/yiffy__fetch_8h.html#a41f382b6bd05c9776641fb4bc5024afa',1,'fetch(char *tags, int page, char *command): fetch.c']]], + ['fetch_1',['fetch',['../d5/d05/yiffy__fetch_8h.html#a41f382b6bd05c9776641fb4bc5024afa',1,'fetch(char *tags, int page, char *command): fetch.c'],['../d1/d14/fetch_8c.html#a41f382b6bd05c9776641fb4bc5024afa',1,'fetch(char *tags, int page, char *command): fetch.c']]], ['fetch_2ec_2',['fetch.c',['../d1/d14/fetch_8c.html',1,'']]], ['fetch_5foption_3',['fetch_option',['../df/d6b/structfetch__option.html',1,'']]], ['file_5fopen_5ferror_5fmsg_4',['file_open_error_msg',['../db/df9/file__open__error__msg_8c.html#a86dae457f49acffe2f59c6072cdec928',1,'file_open_error_msg(): file_open_error_msg.c'],['../d0/de2/yiffy__messages_8h.html#a86dae457f49acffe2f59c6072cdec928',1,'file_open_error_msg(): file_open_error_msg.c']]], ['file_5fopen_5ferror_5fmsg_2ec_5',['file_open_error_msg.c',['../db/df9/file__open__error__msg_8c.html',1,'']]], - ['file_5fpath_5fsize_6',['FILE_PATH_SIZE',['../de/dfc/conf__nsfw_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'conf_nsfw.c']]], - ['file_5fsize_7',['FILE_SIZE',['../de/dfc/conf__nsfw_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'conf_nsfw.c']]], + ['file_5fpath_5fsize_6',['FILE_PATH_SIZE',['../da/d93/conf__img__viewer__command_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_img_viewer_command.c'],['../de/dfc/conf__nsfw_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_nsfw.c']]], + ['file_5fsize_7',['FILE_SIZE',['../da/d93/conf__img__viewer__command_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_img_viewer_command.c'],['../de/dfc/conf__nsfw_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_nsfw.c']]], ['fmt_8',['fmt',['../d5/d56/cjson_8h.html#aa813b2b7bde1a5a1f528cd9d9aa9ee7d',1,'cjson.h']]], ['format_9',['format',['../d1/dc7/structprintbuffer.html#a75d3f480f5308e7f4afecf30e11277ef',1,'printbuffer::format()'],['../d5/d56/cjson_8h.html#adb411a44855a4c49231d72a0fc9a3b3b',1,'format(): cjson.h']]], ['function_10',['function',['../dc/db4/structgeneral__option.html#abf4aa62f04dc6060c4e6102c7bec49f4',1,'general_option::function()'],['../df/d6b/structfetch__option.html#a03db2a934e5a0d186f9f41270a5be04e',1,'fetch_option::function()']]] diff --git a/docs/html/search/all_b.js b/docs/html/search/all_b.js index 44b9ef9..db3379e 100644 --- a/docs/html/search/all_b.js +++ b/docs/html/search/all_b.js @@ -4,7 +4,7 @@ var searchData= ['malloc_5ferror_5fmsg_1',['malloc_error_msg',['../d4/ddf/malloc__error__msg_8c.html#a8f2c3050fed77b86a432d485cde3ade1',1,'malloc_error_msg(): malloc_error_msg.c'],['../d0/de2/yiffy__messages_8h.html#a8f2c3050fed77b86a432d485cde3ade1',1,'malloc_error_msg(): malloc_error_msg.c']]], ['malloc_5ferror_5fmsg_2ec_2',['malloc_error_msg.c',['../d4/ddf/malloc__error__msg_8c.html',1,'']]], ['malloc_5ffn_3',['malloc_fn',['../dc/d55/structcJSON__Hooks.html#ae8fc738005f553ff03bc725c58d3188f',1,'cJSON_Hooks']]], - ['max_5fbuffer_5fsize_4',['MAX_BUFFER_SIZE',['../da/d93/conf__img__viewer__command_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): conf_img_viewer_command.c'],['../d1/d14/fetch_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): fetch.c'],['../dc/d3b/show__config_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): show_config.c'],['../dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): search.c']]], - ['max_5ffile_5fpath_5',['MAX_FILE_PATH',['../da/d93/conf__img__viewer__command_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): conf_img_viewer_command.c'],['../d1/d14/fetch_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): fetch.c'],['../dc/d3b/show__config_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): show_config.c'],['../dc/dec/search_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): search.c']]], + ['max_5fbuffer_5fsize_4',['MAX_BUFFER_SIZE',['../d1/d14/fetch_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): fetch.c'],['../dc/d3b/show__config_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): show_config.c'],['../dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): search.c']]], + ['max_5ffile_5fpath_5',['MAX_FILE_PATH',['../d1/d14/fetch_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): fetch.c'],['../dc/d3b/show__config_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): show_config.c'],['../dc/dec/search_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): search.c']]], ['missing_5fon_5foff_6',['MISSING_ON_OFF',['../dc/dc0/yiffy_8c.html#a9e8078dd597c541b6090e1e1ffd437e5',1,'yiffy.c']]] ]; diff --git a/docs/html/search/defines_1.js b/docs/html/search/defines_1.js index b894698..ba1a768 100644 --- a/docs/html/search/defines_1.js +++ b/docs/html/search/defines_1.js @@ -2,5 +2,5 @@ var searchData= [ ['bad_5fsystem_5ffunc_5fcall_0',['BAD_SYSTEM_FUNC_CALL',['../d5/d05/yiffy__fetch_8h.html#acbd50aa1f19ce68034a26b45b0aaed69',1,'yiffy_fetch.h']]], ['buffer_5fat_5foffset_1',['buffer_at_offset',['../d6/d49/cjson_8c.html#ac538057ef78677344d222b763251af5e',1,'cjson.c']]], - ['buffer_5fsize_2',['BUFFER_SIZE',['../de/dfc/conf__nsfw_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'conf_nsfw.c']]] + ['buffer_5fsize_2',['BUFFER_SIZE',['../da/d93/conf__img__viewer__command_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_img_viewer_command.c'],['../de/dfc/conf__nsfw_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_nsfw.c']]] ]; diff --git a/docs/html/search/defines_4.js b/docs/html/search/defines_4.js index bbc1596..879527f 100644 --- a/docs/html/search/defines_4.js +++ b/docs/html/search/defines_4.js @@ -1,6 +1,6 @@ var searchData= [ ['false_0',['false',['../d6/d49/cjson_8c.html#a65e9886d74aaee76545e83dd09011727',1,'cjson.c']]], - ['file_5fpath_5fsize_1',['FILE_PATH_SIZE',['../de/dfc/conf__nsfw_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'conf_nsfw.c']]], - ['file_5fsize_2',['FILE_SIZE',['../de/dfc/conf__nsfw_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'conf_nsfw.c']]] + ['file_5fpath_5fsize_1',['FILE_PATH_SIZE',['../da/d93/conf__img__viewer__command_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_img_viewer_command.c'],['../de/dfc/conf__nsfw_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_nsfw.c']]], + ['file_5fsize_2',['FILE_SIZE',['../da/d93/conf__img__viewer__command_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_img_viewer_command.c'],['../de/dfc/conf__nsfw_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_nsfw.c']]] ]; diff --git a/docs/html/search/defines_6.js b/docs/html/search/defines_6.js index e1bd957..6c7e700 100644 --- a/docs/html/search/defines_6.js +++ b/docs/html/search/defines_6.js @@ -1,6 +1,6 @@ var searchData= [ - ['max_5fbuffer_5fsize_0',['MAX_BUFFER_SIZE',['../da/d93/conf__img__viewer__command_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): conf_img_viewer_command.c'],['../d1/d14/fetch_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): fetch.c'],['../dc/d3b/show__config_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): show_config.c'],['../dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): search.c']]], - ['max_5ffile_5fpath_1',['MAX_FILE_PATH',['../da/d93/conf__img__viewer__command_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): conf_img_viewer_command.c'],['../d1/d14/fetch_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): fetch.c'],['../dc/d3b/show__config_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): show_config.c'],['../dc/dec/search_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): search.c']]], + ['max_5fbuffer_5fsize_0',['MAX_BUFFER_SIZE',['../d1/d14/fetch_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): fetch.c'],['../dc/d3b/show__config_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): show_config.c'],['../dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'MAX_BUFFER_SIZE(): search.c']]], + ['max_5ffile_5fpath_1',['MAX_FILE_PATH',['../d1/d14/fetch_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): fetch.c'],['../dc/d3b/show__config_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): show_config.c'],['../dc/dec/search_8c.html#a263efd24d550124313df51247f07457a',1,'MAX_FILE_PATH(): search.c']]], ['missing_5fon_5foff_2',['MISSING_ON_OFF',['../dc/dc0/yiffy_8c.html#a9e8078dd597c541b6090e1e1ffd437e5',1,'yiffy.c']]] ]; diff --git a/src/app/yiffy.c b/src/app/yiffy.c index 63b1cf1..f1f6e4d 100644 --- a/src/app/yiffy.c +++ b/src/app/yiffy.c @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) { void (*menu_func)(char *argv) = general_options[i].function; - if (strcmp(general_options[i].option, "--search") == 0 || strcmp(general_options[i].option, "--nsfw") == 0 || strcmp(general_options[i].option, "--plog") == 0) /* THIRD ARGUMENT: tags [yiffy --search "blush+fox+male"]*/ + if (strcmp(general_options[i].option, "--search") == 0 || strcmp(general_options[i].option, "--nsfw") == 0 || strcmp(general_options[i].option, "--ivcommand") == 0) /* THIRD ARGUMENT: tags [yiffy --search "blush+fox+male"]*/ { menu_func(argv[2]); } diff --git a/src/conf/conf_img_viewer_command.c b/src/conf/conf_img_viewer_command.c index 7bc52ec..94e88d8 100644 --- a/src/conf/conf_img_viewer_command.c +++ b/src/conf/conf_img_viewer_command.c @@ -10,8 +10,16 @@ * @date 31/05/2024 */ -#define MAX_FILE_PATH 256 -#define MAX_BUFFER_SIZE 512 +#define FILE_PATH_SIZE 256 ///< This macro is used to set the default size for getting the home directory file. +#define BUFFER_SIZE 512 ///< This macro is used to set the default size for reading the config file. +#define FILE_SIZE 2048 ///< This macro is used to set the default size for the file. + +static char *home_directory; ///< Stores the home directory as string. + +static char file_path[FILE_PATH_SIZE]; ///< Stores the file path for config and credentials files. +static char buffer[BUFFER_SIZE]; ///< Stores the configs and credentials one by one, used for parsing them by using fgets. + +static char ivcommand[256]; ///< Stores the image viewer command option string. #include "yiffy_conf.h" @@ -22,5 +30,63 @@ */ void conf_img_viewer_command(char *argv) { + printf("%s\n", argv); + + /* Create the image viewer command option string. */ + sprintf(ivcommand, "IMG_DISPLAY_COMMAND=%s\n", argv); + + /* Get the home directory of the current user. */ + home_directory = getenv("HOME"); + + if (home_directory == NULL) + { + no_home_error_msg(); + exit(1); + } + + /* Create the configuration file path. */ + sprintf(file_path, "%s/.yiffy/yiffy-config.txt", home_directory); + + FILE *config_file = fopen(file_path, "r"); + + if (config_file == NULL) + { + file_open_error_msg(); + exit(EXIT_FAILURE); + } + + /* Read the entire file into memory */ + char file_content[FILE_SIZE]; + char *content_ptr = file_content; + size_t content_length = 0; + + while (fgets(buffer, BUFFER_SIZE - 1, config_file)) + { + if (strstr(buffer, "IMG_DISPLAY_COMMAND=") != NULL) + { + strcpy(buffer, ivcommand); + } + + strcpy(content_ptr, buffer); + + content_ptr += strlen(buffer); + content_length += strlen(buffer); + } + + /* Close the config file for reading. */ + fclose(config_file); + + /* Write the modified content back to the file. */ + config_file = fopen(file_path, "w"); + + if (config_file == NULL) + { + file_open_error_msg(); + exit(EXIT_FAILURE); + } + + fwrite(file_content, sizeof(char), content_length, config_file); + /* Close the config file for writing. */ + fclose(config_file); } \ No newline at end of file diff --git a/src/conf/conf_nsfw.c b/src/conf/conf_nsfw.c index 455a4d0..259fdf0 100644 --- a/src/conf/conf_nsfw.c +++ b/src/conf/conf_nsfw.c @@ -86,8 +86,6 @@ void conf_nsfw(char *argv) content_length += strlen(buffer); } - printf("%d\n", content_length); - /* Close the config file for reading. */ fclose(config_file);