From 5029f0e506c0c103124b964de45a263e7ecb875c Mon Sep 17 00:00:00 2001 From: mehmetmertguduz Date: Thu, 6 Jun 2024 12:52:47 +0300 Subject: [PATCH] search.c top window part updated --- .../create__controls__window_8c_source.html | 2 +- docs/html/dc/d3b/show__config_8c_source.html | 2 +- docs/html/dc/dc0/yiffy_8c_source.html | 2 +- docs/html/dc/dec/search_8c.html | 54 +--- docs/html/dc/dec/search_8c.js | 2 - docs/html/dc/dec/search_8c_source.html | 275 +++++++----------- docs/html/dd/d93/create__top__window_8c.html | 71 +++-- docs/html/dd/d93/create__top__window_8c.js | 4 +- .../dd/d93/create__top__window_8c_source.html | 92 ++++-- docs/html/de/d29/yiffy__search_8h.html | 26 +- docs/html/de/d29/yiffy__search_8h.js | 2 +- docs/html/de/d29/yiffy__search_8h_source.html | 8 +- docs/html/globals.html | 8 +- docs/html/globals_defs.html | 6 +- docs/html/globals_func.html | 2 +- docs/html/navtreeindex1.js | 20 +- docs/html/search/all_1.js | 2 +- docs/html/search/all_2.js | 2 +- docs/html/search/all_5.js | 4 +- docs/html/search/all_b.js | 4 +- docs/html/search/defines_1.js | 2 +- docs/html/search/defines_4.js | 2 +- docs/html/search/defines_7.js | 4 +- docs/html/search/functions_1.js | 2 +- src/menus/show_config.c | 2 +- src/search/create_top_window.c | 45 ++- src/search/search.c | 53 +--- src/search/yiffy_search.h | 2 +- 28 files changed, 331 insertions(+), 369 deletions(-) diff --git a/docs/html/d6/d24/create__controls__window_8c_source.html b/docs/html/d6/d24/create__controls__window_8c_source.html index 07f1291..e909ba7 100644 --- a/docs/html/d6/d24/create__controls__window_8c_source.html +++ b/docs/html/d6/d24/create__controls__window_8c_source.html @@ -138,7 +138,7 @@
40 wrefresh(window);
41}
void create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls)
Creates a new window to display the controls and adds it to the specified position.
-
control controls[]
Definition: search.c:19
+
control controls[]
Definition: search.c:17
void set_window_title(WINDOW *window, const char *title)
Writes a title to the top-left corner of the specified window.
Stores the control name and key for displaying in the controls panel.
Definition: yiffy_search.h:23
This header file is used to handle the fetching and searching system.
diff --git a/docs/html/dc/d3b/show__config_8c_source.html b/docs/html/dc/d3b/show__config_8c_source.html index dff6c1d..3dea883 100644 --- a/docs/html/dc/d3b/show__config_8c_source.html +++ b/docs/html/dc/d3b/show__config_8c_source.html @@ -166,7 +166,7 @@
65
67void write_credentials()
68{
-
69 /* Create the configuration file path. */
+
69 /* Create the credentials file path. */
70 sprintf(file_path, "%s/.yiffy/yiffy-credentials.txt", home_directory);
71
72 FILE *credentials_file = fopen(file_path, "r");
diff --git a/docs/html/dc/dc0/yiffy_8c_source.html b/docs/html/dc/dc0/yiffy_8c_source.html index 2ec9ab4..d284ed3 100644 --- a/docs/html/dc/dc0/yiffy_8c_source.html +++ b/docs/html/dc/dc0/yiffy_8c_source.html @@ -328,7 +328,7 @@
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:30
void no_arg_value_msg(char *argument)
Outputs the correct prompt format when there is no argument value.
void on_off_msg(char *argument)
Outputs the correct argument value (on/off) for specified options.
Definition: on_off_msg.c:18
-
void search(char *tags)
Creates a ncurses-based user interface to show, download, search and travel the e621/e926 by using cu...
Definition: search.c:44
+
void search(char *tags)
Creates a ncurses-based user interface to show, download, search and travel the e621/e926 by using cu...
Definition: search.c:39
void show_config()
Shows the yiffy configurations to user.
Definition: show_config.c:26
void show_github()
Shows the project github URL, current issues to user.
Definition: show_github.c:16
void show_help()
Shows the general help menu to user.
Definition: show_help.c:16
diff --git a/docs/html/dc/dec/search_8c.html b/docs/html/dc/dec/search_8c.html index 8d2c36f..86f1cd8 100644 --- a/docs/html/dc/dec/search_8c.html +++ b/docs/html/dc/dec/search_8c.html @@ -146,12 +146,6 @@ - - - - - - @@ -196,42 +190,6 @@

Definition at line 17 of file search.c.

- - - - -

◆ MAX_BUFFER_SIZE

- -
-
-

Macros

#define MAX_FILE_PATH   256
 This macro is used to set the default size for getting the home directory file. More...
 
#define MAX_BUFFER_SIZE   512
 This macro is used to set the default size for reading the config file. More...
 
#define CONTENT_SIZE   524288
 This macro is used to set the default size for reading the JSON file that comes as a response from the API. More...
 
- - - -
#define MAX_BUFFER_SIZE   512
-
- -

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

- -

Definition at line 16 of file search.c.

- -
- - -

◆ MAX_FILE_PATH

- -
-
- - - - -
#define MAX_FILE_PATH   256
-
- -

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

-

Definition at line 15 of file search.c.

@@ -261,7 +219,7 @@

Definition at line 44 of file search.c.

+

Definition at line 39 of file search.c.

@@ -286,7 +244,7 @@

{"QUIT", 'Q'}
}
-

Definition at line 19 of file search.c.

+

Definition at line 17 of file search.c.

@@ -302,7 +260,7 @@

-

Definition at line 31 of file search.c.

+

Definition at line 29 of file search.c.

@@ -318,7 +276,7 @@

-

Definition at line 30 of file search.c.

+

Definition at line 28 of file search.c.

@@ -334,7 +292,7 @@

-

Definition at line 29 of file search.c.

+

Definition at line 27 of file search.c.

@@ -350,7 +308,7 @@

-

Definition at line 28 of file search.c.

+

Definition at line 26 of file search.c.

diff --git a/docs/html/dc/dec/search_8c.js b/docs/html/dc/dec/search_8c.js index 53124c4..8e1a6bd 100644 --- a/docs/html/dc/dec/search_8c.js +++ b/docs/html/dc/dec/search_8c.js @@ -1,8 +1,6 @@ var search_8c = [ [ "CONTENT_SIZE", "dc/dec/search_8c.html#aff9b7f6d81297248bf0ad06d725c8cbb", null ], - [ "MAX_BUFFER_SIZE", "dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6", null ], - [ "MAX_FILE_PATH", "dc/dec/search_8c.html#a263efd24d550124313df51247f07457a", null ], [ "search", "dc/dec/search_8c.html#ab899bd069f8d6db7339eba31c3ad7a02", null ], [ "controls", "dc/dec/search_8c.html#af0d0e693c574c3bfb0fcdcca37cbd745", null ], [ "controls_window", "dc/dec/search_8c.html#ac105778d4687c921d3749c0e825d529d", null ], diff --git a/docs/html/dc/dec/search_8c_source.html b/docs/html/dc/dec/search_8c_source.html index 02dce75..2fb11a5 100644 --- a/docs/html/dc/dec/search_8c_source.html +++ b/docs/html/dc/dec/search_8c_source.html @@ -115,190 +115,135 @@
12
13#include "yiffy_search.h"
14
-
15#define MAX_FILE_PATH 256
-
16#define MAX_BUFFER_SIZE 512
-
17#define CONTENT_SIZE 524288
-
18
- -
20{
-
21 {"SHOW", 'S'},
-
22 {"DOWNLOAD", 'D'},
-
23 {"PREV", 'P'},
-
24 {"NEXT", 'N'},
-
25 {"QUIT", 'Q'}
-
26};
-
27
-
28WINDOW *top_window;
- - - -
32
-
34static bool is_nsfw;
-
35
-
37static int posts_panel_height;
-
38
-
40static char json_string[CONTENT_SIZE];
-
41
-
44void search(char *tags)
-
45{
-
46 /* Configuration file path and data buffer for configurations. */
-
47 char config_path[MAX_FILE_PATH];
- +
15#define CONTENT_SIZE 524288
+
16
+ +
18{
+
19 {"SHOW", 'S'},
+
20 {"DOWNLOAD", 'D'},
+
21 {"PREV", 'P'},
+
22 {"NEXT", 'N'},
+
23 {"QUIT", 'Q'}
+
24};
+
25
+
26WINDOW *top_window;
+ + + +
30
+
32static int posts_panel_height;
+
33
+
35static char json_string[CONTENT_SIZE];
+
36
+
39void search(char *tags)
+
40{
+
41 /* Initialize ncurses and configurations for the user interface. */
+ +
43
+
44 /* Create the ncurses-based user interfaces. */
+ +
46 create_posts_window(&posts_window, &posts_panel_height);
+
47 create_post_tags_window(post_tags_window, &posts_panel_height);
+
48 create_controls_window(controls_window, &posts_panel_height, controls, sizeof(controls) / sizeof(controls[0]));
49
-
50 /* The home path of the user. */
-
51 char *home_path = getenv("HOME");
+
50 /* Download the first page of posts with prompted tags. */
+
51 aria2_download(tags, 1, posts_panel_height);
52
-
53 /* Check if the NSFW option is enabled. */
-
54 is_nsfw = false;
+
53 /* Read the posts.json file. */
+
54 FILE *posts_json_file = fopen("posts.json", "r");
55
-
56 if (home_path == NULL)
+
56 if (posts_json_file == NULL)
57 {
- -
59 exit(EXIT_FAILURE);
+ +
59 goto END;
60 }
61
-
62 sprintf(config_path, "%s/.yiffy/yiffy-config.txt", home_path);
+
62 fgets(json_string, CONTENT_SIZE - 1, posts_json_file);
63
-
64 /* Read the configuration file (~/.yiffy/yiffy-config.txt) to execute the desired process. */
-
65 FILE *config = fopen(config_path, "r");
+
64 /* Close the file after reading and putting the data to json_string. */
+
65 fclose(posts_json_file);
66
-
67 if (config == NULL)
-
68 {
- -
70 exit(EXIT_FAILURE);
-
71 }
-
72
-
73 size_t config_bytes = fread(buffer, 1, MAX_BUFFER_SIZE - 1, config);
-
74 buffer[config_bytes] = '\0';
+
67 /* Parse the JSON. */
+
68 cJSON *json = cJSON_Parse(json_string);
+
69
+
70 if (json == NULL)
+
71 {
+ +
73 goto END;
+
74 }
75
-
76 fclose(config);
-
77
-
78 /* Parse the configuration to check for NSFW option. */
-
79 char *token = strtok(buffer, ":");
-
80
-
81 while (token != NULL)
-
82 {
-
83 if (strcmp(token, "nsfw") == 0)
-
84 {
-
85 is_nsfw = true;
-
86 break;
-
87 }
-
88
-
89 token = strtok(NULL, ":");
-
90 }
-
91
-
92 /* Initialize ncurses and configurations for the user interface. */
- -
94
-
95 /* Create the ncurses-based user interfaces. */
- -
97 create_posts_window(&posts_window, &posts_panel_height);
-
98 create_post_tags_window(post_tags_window, &posts_panel_height);
-
99 create_controls_window(controls_window, &posts_panel_height, controls, sizeof(controls) / sizeof(controls[0]));
-
100
-
101 /* Download the first page of posts with prompted tags. */
-
102 aria2_download(tags, 1, posts_panel_height);
-
103
-
104 /* Read the posts.json file. */
-
105 FILE *posts_json_file = fopen("posts.json", "r");
-
106
-
107 if (posts_json_file == NULL)
-
108 {
- -
110 goto END;
-
111 }
-
112
-
113 fgets(json_string, CONTENT_SIZE - 1, posts_json_file);
-
114
-
115 /* Close the file after reading and putting the data to json_string. */
-
116 fclose(posts_json_file);
+
76 /* Get the posts array. */
+
77 cJSON *posts = cJSON_GetObjectItem(json, "posts");
+
78
+
79 if (!cJSON_IsArray(posts))
+
80 {
+ +
82 goto END;
+
83 }
+
84
+
85 /* Counter for writing posts. */
+
86 size_t post_i = 0;
+
87
+
88 /* Write the posts and tags to windows. */
+
89 for (size_t i = 0; i < cJSON_GetArraySize(posts); i++)
+
90 {
+
91 /* Take the post with specified index. */
+
92 cJSON *post = cJSON_GetArrayItem(posts, i);
+
93
+
94 if (post == NULL)
+
95 {
+ +
97 goto END;
+
98 }
+
99
+
100 /* Take the file object of the specified post. */
+
101 cJSON *file_object = cJSON_GetObjectItem(post, "file");
+
102
+
103 if (file_object == NULL)
+
104 {
+
105 fprintf(stderr, "File object not found in post %d\n", i);
+
106 goto END;
+
107 }
+
108
+
109 /* Take the url of the of the specified post by parsing the data from file object. */
+
110 cJSON *url = cJSON_GetObjectItem(file_object, "url");
+
111
+
112 if (url != NULL && cJSON_IsString(url) && post_i != posts_panel_height - 2)
+
113 {
+
114 write_post(posts_window, post_i, url);
+
115
+
116 wrefresh(posts_window);
117
-
118 /* Parse the JSON. */
-
119 cJSON *json = cJSON_Parse(json_string);
-
120
-
121 if (json == NULL)
-
122 {
- -
124 goto END;
-
125 }
-
126
-
127 /* Get the posts array. */
-
128 cJSON *posts = cJSON_GetObjectItem(json, "posts");
-
129
-
130 if (!cJSON_IsArray(posts))
-
131 {
- -
133 goto END;
-
134 }
-
135
-
136 /* Counter for writing posts. */
-
137 size_t post_i = 0;
-
138
-
139 /* Write the posts and tags to windows. */
-
140 for (size_t i = 0; i < cJSON_GetArraySize(posts); i++)
-
141 {
-
142 /* Take the post with specified index. */
-
143 cJSON *post = cJSON_GetArrayItem(posts, i);
-
144
-
145 if (post == NULL)
-
146 {
- -
148 goto END;
-
149 }
-
150
-
151 /* Take the file object of the specified post. */
-
152 cJSON *file_object = cJSON_GetObjectItem(post, "file");
-
153
-
154 if (file_object == NULL)
-
155 {
-
156 fprintf(stderr, "File object not found in post %d\n", i);
-
157 goto END;
-
158 }
-
159
-
160 /* Take the url of the of the specified post by parsing the data from file object. */
-
161 cJSON *url = cJSON_GetObjectItem(file_object, "url");
-
162
-
163 if (url != NULL && cJSON_IsString(url) && post_i != posts_panel_height - 2)
-
164 {
-
165 write_post(posts_window, post_i, url);
-
166
-
167 wrefresh(posts_window);
-
168
-
169 /* Increase post_i. */
-
170 post_i++;
-
171 }
-
172 }
-
173
-
174 wrefresh(posts_window);
-
175 refresh();
-
176
-
177 END:
-
178 cJSON_Delete(json);
-
179 getch();
-
180 endwin();
-
181}
+
118 /* Increase post_i. */
+
119 post_i++;
+
120 }
+
121 }
+
122
+
123 wrefresh(posts_window);
+
124 refresh();
+
125
+
126 END:
+
127 cJSON_Delete(json);
+
128 getch();
+
129 endwin();
+
130}
void aria2_download(char *tags, int page, int lim)
downloads the API response by using aria2c, works with a system call
-
char * buffer
Definition: cjson.h:170
void create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls)
Creates a new window to display the controls and adds it to the specified position.
void create_post_tags_window(WINDOW *window, int *posts_panel_height)
Creates a new window to display post tags and adds it to the specified position.
void create_posts_window(WINDOW **window, int *posts_panel_height)
Creates a new window to display posts and adds it to the specified position.
-
void create_top_window(WINDOW *window, bool is_nsfw)
Creates a new top window to display the title and SFW/NSFW status.
-
void file_open_error_msg()
Shows some information about file permissions when yiffy is not able to read file.
+
void create_top_window(WINDOW *window)
Creates a new top window to display the title and SFW/NSFW status.
void init_ncurses()
Initializes the ncurses library and sets up the terminal UI.
Definition: init_ncurses.c:14
void json_parse_error_msg()
Outputs the error message when application can not parse the JSON content.
-
void no_home_error_msg()
Outputs the home not found error when application can not access the $HOME environment variable.
void no_json_error_msg()
Outputs the error when there is no JSON file.
void post_error_msg()
Outputs the error when the parsing is faced with an error in the post section.
void posts_not_array_error_msg()
Outputs the error when the parsing is faced with an error in the posts section.
-
WINDOW * post_tags_window
Definition: search.c:30
-
#define MAX_FILE_PATH
This macro is used to set the default size for getting the home directory file.
Definition: search.c:15
-
WINDOW * posts_window
Definition: search.c:29
-
WINDOW * top_window
Definition: search.c:28
-
void search(char *tags)
Creates a ncurses-based user interface to show, download, search and travel the e621/e926 by using cu...
Definition: search.c:44
-
WINDOW * controls_window
Definition: search.c:31
-
#define MAX_BUFFER_SIZE
This macro is used to set the default size for reading the config file.
Definition: search.c:16
-
control controls[]
Definition: search.c:19
-
#define CONTENT_SIZE
This macro is used to set the default size for reading the JSON file that comes as a response from th...
Definition: search.c:17
+
WINDOW * post_tags_window
Definition: search.c:28
+
WINDOW * posts_window
Definition: search.c:27
+
WINDOW * top_window
Definition: search.c:26
+
void search(char *tags)
Creates a ncurses-based user interface to show, download, search and travel the e621/e926 by using cu...
Definition: search.c:39
+
WINDOW * controls_window
Definition: search.c:29
+
control controls[]
Definition: search.c:17
+
#define CONTENT_SIZE
This macro is used to set the default size for reading the JSON file that comes as a response from th...
Definition: search.c:15
Definition: cjson.h:111
Stores the control name and key for displaying in the controls panel.
Definition: yiffy_search.h:23
void write_post(WINDOW *window, size_t post_i, cJSON *url)
Writes posts to the posts window.
Definition: write_post.c:17
diff --git a/docs/html/dd/d93/create__top__window_8c.html b/docs/html/dd/d93/create__top__window_8c.html index 3f18b50..c20d87f 100644 --- a/docs/html/dd/d93/create__top__window_8c.html +++ b/docs/html/dd/d93/create__top__window_8c.html @@ -108,6 +108,7 @@
create_top_window.c File Reference
@@ -141,11 +142,20 @@

Go to the source code of this file.

+ + + + + + + +

+Macros

#define FILE_PATH   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...
 
- - - + + +

Functions

void create_top_window (WINDOW *window, bool is_nsfw)
 Creates a new top window to display the title and SFW/NSFW status. More...
 
void create_top_window (WINDOW *window)
 Creates a new top window to display the title and SFW/NSFW status. More...
 

Detailed Description

This file is used to create a new top window to display the title and SFW/NSFW status.

@@ -153,29 +163,56 @@
Date
23/05/2024

Definition in file create_top_window.c.

-

Function Documentation

- -

◆ create_top_window()

+

Macro Definition Documentation

+ +

◆ BUFFER_SIZE

- - - - + +
void create_top_window (WINDOW * window, #define BUFFER_SIZE   512
+
+ +

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

+ +

Definition at line 14 of file create_top_window.c.

+ +
+
+ +

◆ FILE_PATH

+ +
+
+ - - - - + +
bool is_nsfw #define FILE_PATH   256
+
+ +

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

+ +

Definition at line 13 of file create_top_window.c.

+ +
+
+

Function Documentation

+ +

◆ create_top_window()

+ +
+
+ + + + + - -
void create_top_window (WINDOW * window) )
@@ -190,7 +227,7 @@

Definition at line 16 of file create_top_window.c.

+

Definition at line 24 of file create_top_window.c.

diff --git a/docs/html/dd/d93/create__top__window_8c.js b/docs/html/dd/d93/create__top__window_8c.js index 7b2eab7..74c3716 100644 --- a/docs/html/dd/d93/create__top__window_8c.js +++ b/docs/html/dd/d93/create__top__window_8c.js @@ -1,4 +1,6 @@ var create__top__window_8c = [ - [ "create_top_window", "dd/d93/create__top__window_8c.html#a090b2242d6c27461b6d72b4c69c3255f", null ] + [ "BUFFER_SIZE", "dd/d93/create__top__window_8c.html#a6b20d41d6252e9871430c242cb1a56e7", null ], + [ "FILE_PATH", "dd/d93/create__top__window_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3", null ], + [ "create_top_window", "dd/d93/create__top__window_8c.html#a5b2a6a6ce54a02a47d025adba6d325d7", null ] ]; \ No newline at end of file diff --git a/docs/html/dd/d93/create__top__window_8c_source.html b/docs/html/dd/d93/create__top__window_8c_source.html index d0e6983..005c3ff 100644 --- a/docs/html/dd/d93/create__top__window_8c_source.html +++ b/docs/html/dd/d93/create__top__window_8c_source.html @@ -113,29 +113,77 @@ Go to the documentation of this file.
1
11#include "yiffy_search.h"
12
-
16void create_top_window(WINDOW *window, bool is_nsfw)
-
17{
-
18 window = newwin(3, COLS, 0, 0);
-
19 box(window, 0, 0);
+
13#define FILE_PATH 256
+
14#define BUFFER_SIZE 512
+
15
+
16static char *home_directory;
+
17
+
18static char file_path[FILE_PATH];
+
19static char buffer[BUFFER_SIZE];
20
-
21 set_window_title(window, "YIFFY");
-
22
-
23 /* Write the SFW-NSFW option in A_STANDOUT (bright) mod. */
-
24 wattron(window, A_STANDOUT);
-
25 if (is_nsfw)
-
26 {
-
27 mvwprintw(window, 1, 1, " NSFW [E621.NET] - ASCII-IMAGE-CONVERTER ");
-
28 }
-
29 else
-
30 {
-
31 mvwprintw(window, 1, 1, " SFW [E926.NET] - ASCII-IMAGE-CONVERTER ");
-
32 }
-
33 wattroff(window, A_STANDOUT);
-
34
-
35 refresh();
-
36 wrefresh(window);
-
37}
-
void create_top_window(WINDOW *window, bool is_nsfw)
Creates a new top window to display the title and SFW/NSFW status.
+
24void create_top_window(WINDOW *window)
+
25{
+
26 /* NSFW option boolean value. */
+
27 bool is_nsfw = false;
+
28
+
29 /* Get the home directory of the current user. */
+
30 home_directory = getenv("HOME");
+
31
+
32 if (home_directory == NULL)
+
33 {
+ +
35 exit(1);
+
36 }
+
37
+
38 /* Create the credentials file path. */
+
39 sprintf(file_path, "%s/.yiffy/yiffy-config.txt", home_directory);
+
40
+
41 FILE *config_file = fopen(file_path, "r");
+
42
+
43 if (config_file == NULL)
+
44 {
+ +
46 exit(EXIT_FAILURE);
+
47 }
+
48
+
49 while (fgets(buffer, BUFFER_SIZE - 1, config_file))
+
50 {
+
51 if (strcmp(buffer, "IS_NSFW=YES\n") == 0)
+
52 {
+
53 is_nsfw = true;
+
54 break;
+
55 }
+
56 }
+
57
+
58 fclose(config_file);
+
59
+
60 /* Create the windows. */
+
61 window = newwin(3, COLS, 0, 0);
+
62 box(window, 0, 0);
+
63
+
64 set_window_title(window, "YIFFY");
+
65
+
66 /* Write the SFW-NSFW option in A_STANDOUT (bright) mod. */
+
67 wattron(window, A_STANDOUT);
+
68 if (is_nsfw)
+
69 {
+
70 mvwprintw(window, 1, 1, " NSFW [E621.NET] - ASCII-IMAGE-CONVERTER ");
+
71 }
+
72 else
+
73 {
+
74 mvwprintw(window, 1, 1, " SFW [E926.NET] - ASCII-IMAGE-CONVERTER ");
+
75 }
+
76 wattroff(window, A_STANDOUT);
+
77
+
78 refresh();
+
79 wrefresh(window);
+
80}
+
char * buffer
Definition: cjson.h:170
+
void create_top_window(WINDOW *window)
Creates a new top window to display the title and SFW/NSFW status.
+
#define BUFFER_SIZE
This macro is used to set the default size for reading the config file.
+
#define FILE_PATH
This macro is used to set the default size for getting the home directory 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.
void set_window_title(WINDOW *window, const char *title)
Writes a title to the top-left corner of the specified window.
This header file is used to handle the fetching and searching system.
diff --git a/docs/html/de/d29/yiffy__search_8h.html b/docs/html/de/d29/yiffy__search_8h.html index bb4846e..179609b 100644 --- a/docs/html/de/d29/yiffy__search_8h.html +++ b/docs/html/de/d29/yiffy__search_8h.html @@ -176,9 +176,9 @@ void init_ncurses ()  Initializes the ncurses library and sets up the terminal UI. More...
  -void create_top_window (WINDOW *window, bool is_nsfw) - Creates a new top window to display the title and SFW/NSFW status. More...
-  +void create_top_window (WINDOW *window) + Creates a new top window to display the title and SFW/NSFW status. More...
+  void create_posts_window (WINDOW **window, int *posts_panel_height)  Creates a new window to display posts and adds it to the specified position. More...
  @@ -339,8 +339,8 @@

-

◆ create_top_window()

+ +

◆ create_top_window()

@@ -424,7 +414,7 @@

Definition at line 44 of file search.c.

+

Definition at line 39 of file search.c.

diff --git a/docs/html/de/d29/yiffy__search_8h.js b/docs/html/de/d29/yiffy__search_8h.js index 75ffcd7..6d78765 100644 --- a/docs/html/de/d29/yiffy__search_8h.js +++ b/docs/html/de/d29/yiffy__search_8h.js @@ -4,7 +4,7 @@ var yiffy__search_8h = [ "create_controls_window", "de/d29/yiffy__search_8h.html#a0a856b187dbd59a65a8bc9ffe5a597b1", null ], [ "create_post_tags_window", "de/d29/yiffy__search_8h.html#a800291b89cb5eebec38a251c0ea0a24f", null ], [ "create_posts_window", "de/d29/yiffy__search_8h.html#ad1975f63b7ab6049822e7b85a4bd40ee", null ], - [ "create_top_window", "de/d29/yiffy__search_8h.html#a090b2242d6c27461b6d72b4c69c3255f", null ], + [ "create_top_window", "de/d29/yiffy__search_8h.html#a5b2a6a6ce54a02a47d025adba6d325d7", null ], [ "init_ncurses", "de/d29/yiffy__search_8h.html#a85769112d75b553ce8125bfda23f32bc", null ], [ "search", "de/d29/yiffy__search_8h.html#ab899bd069f8d6db7339eba31c3ad7a02", null ], [ "set_window_title", "de/d29/yiffy__search_8h.html#a99e678a5bf2aa342184677f946dc1439", null ], diff --git a/docs/html/de/d29/yiffy__search_8h_source.html b/docs/html/de/d29/yiffy__search_8h_source.html index afe4340..33d9864 100644 --- a/docs/html/de/d29/yiffy__search_8h_source.html +++ b/docs/html/de/d29/yiffy__search_8h_source.html @@ -134,7 +134,7 @@
32void init_ncurses();
33
34/* User Interface creation functions. */
-
35void create_top_window(WINDOW *window, bool is_nsfw);
+
35void create_top_window(WINDOW *window);
36void create_posts_window(WINDOW **window, int *posts_panel_height);
37void create_post_tags_window(WINDOW *window, int *posts_panel_height);
38void create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls);
@@ -146,17 +146,17 @@
44void write_post(WINDOW *window, size_t post_i, cJSON *url);
45
46#endif /* YIFFY_UI_H */
-
control controls[]
Definition: search.c:19
+
control controls[]
Definition: search.c:17
Definition: cjson.h:111
Stores the control name and key for displaying in the controls panel.
Definition: yiffy_search.h:23
char * control_full_name
Definition: yiffy_search.h:24
char control_character
Definition: yiffy_search.h:25
-
void create_top_window(WINDOW *window, bool is_nsfw)
Creates a new top window to display the title and SFW/NSFW status.
void create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls)
Creates a new window to display the controls and adds it to the specified position.
+
void create_top_window(WINDOW *window)
Creates a new top window to display the title and SFW/NSFW status.
void create_post_tags_window(WINDOW *window, int *posts_panel_height)
Creates a new window to display post tags and adds it to the specified position.
void init_ncurses()
Initializes the ncurses library and sets up the terminal UI.
Definition: init_ncurses.c:14
void set_window_title(WINDOW *window, const char *title)
Writes a title to the top-left corner of the specified window.
-
void search(char *tags)
Creates a ncurses-based user interface to show, download, search and travel the e621/e926 by using cu...
Definition: search.c:44
+
void search(char *tags)
Creates a ncurses-based user interface to show, download, search and travel the e621/e926 by using cu...
Definition: search.c:39
void create_posts_window(WINDOW **window, int *posts_panel_height)
Creates a new window to display posts and adds it to the specified position.
void write_post(WINDOW *window, size_t post_i, cJSON *url)
Writes posts to the posts window.
Definition: write_post.c:17
diff --git a/docs/html/globals.html b/docs/html/globals.html index 0b82555..f12080c 100644 --- a/docs/html/globals.html +++ b/docs/html/globals.html @@ -125,7 +125,7 @@

- b -

@@ -174,7 +174,7 @@

- c -

@@ -189,7 +189,7 @@

- f -

  • false : cjson.c
  • fetch() : fetch.c, yiffy_fetch.h
  • file_open_error_msg() : file_open_error_msg.c, yiffy_messages.h
  • -
  • FILE_PATH : aria2_download.c, show_config.c
  • +
  • FILE_PATH : aria2_download.c, show_config.c, create_top_window.c
  • FILE_PATH_SIZE : conf_img_viewer_command.c, conf_uname.c, conf_nsfw.c, conf_apikey.c
  • FILE_SIZE : conf_apikey.c, conf_img_viewer_command.c, conf_nsfw.c, conf_uname.c
  • fmt : cjson.h
  • @@ -228,8 +228,6 @@

    - l -

      - m -

      diff --git a/docs/html/globals_defs.html b/docs/html/globals_defs.html index 17a8584..5a67e61 100644 --- a/docs/html/globals_defs.html +++ b/docs/html/globals_defs.html @@ -117,7 +117,7 @@

      - a -

        - b -

        @@ -160,7 +160,7 @@

        - e -

          - f -

          @@ -181,8 +181,6 @@

          - i -

            - m -

            diff --git a/docs/html/globals_func.html b/docs/html/globals_func.html index 2b0a575..3504dbc 100644 --- a/docs/html/globals_func.html +++ b/docs/html/globals_func.html @@ -129,7 +129,7 @@

            - c -

            diff --git a/docs/html/navtreeindex1.js b/docs/html/navtreeindex1.js index 9af6440..07af9eb 100644 --- a/docs/html/navtreeindex1.js +++ b/docs/html/navtreeindex1.js @@ -35,18 +35,18 @@ var NAVTREEINDEX1 = "dc/dc0/yiffy_8c.html#ae19e91650edc7366559a74767d6e0075":[6,0,0,0,0,6], "dc/dc0/yiffy_8c_source.html":[6,0,0,0,0], "dc/dec/search_8c.html":[6,0,0,6,5], -"dc/dec/search_8c.html#a0ea8a08a91b67361f7ee216100e40a86":[6,0,0,6,5,6], -"dc/dec/search_8c.html#a263efd24d550124313df51247f07457a":[6,0,0,6,5,2], -"dc/dec/search_8c.html#a8e4fdaa342d2bb1acdd0ae66d38e5bc0":[6,0,0,6,5,7], -"dc/dec/search_8c.html#a8eb5644bdf68ad95ffafe4751a2bc094":[6,0,0,6,5,8], -"dc/dec/search_8c.html#ab899bd069f8d6db7339eba31c3ad7a02":[6,0,0,6,5,3], -"dc/dec/search_8c.html#ac105778d4687c921d3749c0e825d529d":[6,0,0,6,5,5], -"dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6":[6,0,0,6,5,1], -"dc/dec/search_8c.html#af0d0e693c574c3bfb0fcdcca37cbd745":[6,0,0,6,5,4], +"dc/dec/search_8c.html#a0ea8a08a91b67361f7ee216100e40a86":[6,0,0,6,5,4], +"dc/dec/search_8c.html#a8e4fdaa342d2bb1acdd0ae66d38e5bc0":[6,0,0,6,5,5], +"dc/dec/search_8c.html#a8eb5644bdf68ad95ffafe4751a2bc094":[6,0,0,6,5,6], +"dc/dec/search_8c.html#ab899bd069f8d6db7339eba31c3ad7a02":[6,0,0,6,5,1], +"dc/dec/search_8c.html#ac105778d4687c921d3749c0e825d529d":[6,0,0,6,5,3], +"dc/dec/search_8c.html#af0d0e693c574c3bfb0fcdcca37cbd745":[6,0,0,6,5,2], "dc/dec/search_8c.html#aff9b7f6d81297248bf0ad06d725c8cbb":[6,0,0,6,5,0], "dc/dec/search_8c_source.html":[6,0,0,6,5], "dd/d93/create__top__window_8c.html":[6,0,0,6,3], -"dd/d93/create__top__window_8c.html#a090b2242d6c27461b6d72b4c69c3255f":[6,0,0,6,3,0], +"dd/d93/create__top__window_8c.html#a5b2a6a6ce54a02a47d025adba6d325d7":[6,0,0,6,3,2], +"dd/d93/create__top__window_8c.html#a6b20d41d6252e9871430c242cb1a56e7":[6,0,0,6,3,0], +"dd/d93/create__top__window_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3":[6,0,0,6,3,1], "dd/d93/create__top__window_8c_source.html":[6,0,0,6,3], "dd/dee/structcontrol.html":[5,0,2], "dd/dee/structcontrol.html#a4e3589dccbb6b41838b153f38b21e3d2":[5,0,2,1], @@ -58,8 +58,8 @@ var NAVTREEINDEX1 = "de/d22/show__version_8c.html#af8f154bf210b7ff6d50433da876083e6":[6,0,0,4,3,0], "de/d22/show__version_8c_source.html":[6,0,0,4,3], "de/d29/yiffy__search_8h.html":[6,0,0,6,8], -"de/d29/yiffy__search_8h.html#a090b2242d6c27461b6d72b4c69c3255f":[6,0,0,6,8,4], "de/d29/yiffy__search_8h.html#a0a856b187dbd59a65a8bc9ffe5a597b1":[6,0,0,6,8,1], +"de/d29/yiffy__search_8h.html#a5b2a6a6ce54a02a47d025adba6d325d7":[6,0,0,6,8,4], "de/d29/yiffy__search_8h.html#a800291b89cb5eebec38a251c0ea0a24f":[6,0,0,6,8,2], "de/d29/yiffy__search_8h.html#a85769112d75b553ce8125bfda23f32bc":[6,0,0,6,8,5], "de/d29/yiffy__search_8h.html#a99e678a5bf2aa342184677f946dc1439":[6,0,0,6,8,7], diff --git a/docs/html/search/all_1.js b/docs/html/search/all_1.js index 918c48e..e9a84eb 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',['../d8/d99/conf__apikey_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_uname.c'],['../d6/d60/aria2__download_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): aria2_download.c'],['../dc/d3b/show__config_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): show_config.c']]] + ['buffer_5fsize_6',['BUFFER_SIZE',['../d8/d99/conf__apikey_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_uname.c'],['../d6/d60/aria2__download_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): aria2_download.c'],['../dc/d3b/show__config_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): show_config.c'],['../dd/d93/create__top__window_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): create_top_window.c']]] ]; diff --git a/docs/html/search/all_2.js b/docs/html/search/all_2.js index 1c4cdc3..6b04c35 100644 --- a/docs/html/search/all_2.js +++ b/docs/html/search/all_2.js @@ -61,7 +61,7 @@ var searchData= ['create_5fpost_5ftags_5fwindow_2ec_58',['create_post_tags_window.c',['../d9/d28/create__post__tags__window_8c.html',1,'']]], ['create_5fposts_5fwindow_59',['create_posts_window',['../d3/d45/create__posts__window_8c.html#ad1975f63b7ab6049822e7b85a4bd40ee',1,'create_posts_window(WINDOW **window, int *posts_panel_height): create_posts_window.c'],['../de/d29/yiffy__search_8h.html#ad1975f63b7ab6049822e7b85a4bd40ee',1,'create_posts_window(WINDOW **window, int *posts_panel_height): create_posts_window.c']]], ['create_5fposts_5fwindow_2ec_60',['create_posts_window.c',['../d3/d45/create__posts__window_8c.html',1,'']]], - ['create_5ftop_5fwindow_61',['create_top_window',['../dd/d93/create__top__window_8c.html#a090b2242d6c27461b6d72b4c69c3255f',1,'create_top_window(WINDOW *window, bool is_nsfw): create_top_window.c'],['../de/d29/yiffy__search_8h.html#a090b2242d6c27461b6d72b4c69c3255f',1,'create_top_window(WINDOW *window, bool is_nsfw): create_top_window.c']]], + ['create_5ftop_5fwindow_61',['create_top_window',['../dd/d93/create__top__window_8c.html#a5b2a6a6ce54a02a47d025adba6d325d7',1,'create_top_window(WINDOW *window): create_top_window.c'],['../de/d29/yiffy__search_8h.html#a5b2a6a6ce54a02a47d025adba6d325d7',1,'create_top_window(WINDOW *window): create_top_window.c']]], ['create_5ftop_5fwindow_2ec_62',['create_top_window.c',['../dd/d93/create__top__window_8c.html',1,'']]], ['credential_5fsize_63',['CREDENTIAL_SIZE',['../d6/d60/aria2__download_8c.html#a27ad396a87c1bba9a9fe061544824c0c',1,'aria2_download.c']]] ]; diff --git a/docs/html/search/all_5.js b/docs/html/search/all_5.js index 4402e9b..d25275c 100644 --- a/docs/html/search/all_5.js +++ b/docs/html/search/all_5.js @@ -4,9 +4,9 @@ var searchData= ['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_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',['../d0/de2/yiffy__messages_8h.html#a86dae457f49acffe2f59c6072cdec928',1,'file_open_error_msg(): file_open_error_msg.c'],['../db/df9/file__open__error__msg_8c.html#a86dae457f49acffe2f59c6072cdec928',1,'file_open_error_msg(): file_open_error_msg.c']]], + ['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_6',['FILE_PATH',['../d6/d60/aria2__download_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): aria2_download.c'],['../dc/d3b/show__config_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): show_config.c']]], + ['file_5fpath_6',['FILE_PATH',['../dc/d3b/show__config_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): show_config.c'],['../dd/d93/create__top__window_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): create_top_window.c'],['../d6/d60/aria2__download_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): aria2_download.c']]], ['file_5fpath_5fsize_7',['FILE_PATH_SIZE',['../d8/d99/conf__apikey_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_uname.c']]], ['file_5fsize_8',['FILE_SIZE',['../d8/d99/conf__apikey_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_uname.c']]], ['fmt_9',['fmt',['../d5/d56/cjson_8h.html#aa813b2b7bde1a5a1f528cd9d9aa9ee7d',1,'cjson.h']]], diff --git a/docs/html/search/all_b.js b/docs/html/search/all_b.js index af3f05c..841eade 100644 --- a/docs/html/search/all_b.js +++ b/docs/html/search/all_b.js @@ -4,7 +4,5 @@ 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',['../dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'search.c']]], - ['max_5ffile_5fpath_5',['MAX_FILE_PATH',['../dc/dec/search_8c.html#a263efd24d550124313df51247f07457a',1,'search.c']]], - ['missing_5fon_5foff_6',['MISSING_ON_OFF',['../dc/dc0/yiffy_8c.html#a9e8078dd597c541b6090e1e1ffd437e5',1,'yiffy.c']]] + ['missing_5fon_5foff_4',['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 6013b7a..ed2b3e0 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',['../d8/d99/conf__apikey_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_uname.c'],['../d6/d60/aria2__download_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): aria2_download.c'],['../dc/d3b/show__config_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): show_config.c']]] + ['buffer_5fsize_2',['BUFFER_SIZE',['../d8/d99/conf__apikey_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): conf_uname.c'],['../d6/d60/aria2__download_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): aria2_download.c'],['../dc/d3b/show__config_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): show_config.c'],['../dd/d93/create__top__window_8c.html#a6b20d41d6252e9871430c242cb1a56e7',1,'BUFFER_SIZE(): create_top_window.c']]] ]; diff --git a/docs/html/search/defines_4.js b/docs/html/search/defines_4.js index 944df93..ad1c4fc 100644 --- a/docs/html/search/defines_4.js +++ b/docs/html/search/defines_4.js @@ -1,7 +1,7 @@ var searchData= [ ['false_0',['false',['../d6/d49/cjson_8c.html#a65e9886d74aaee76545e83dd09011727',1,'cjson.c']]], - ['file_5fpath_1',['FILE_PATH',['../d6/d60/aria2__download_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): aria2_download.c'],['../dc/d3b/show__config_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): show_config.c']]], + ['file_5fpath_1',['FILE_PATH',['../d6/d60/aria2__download_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): aria2_download.c'],['../dc/d3b/show__config_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): show_config.c'],['../dd/d93/create__top__window_8c.html#af783caa0ab3eaa291b0af58fcb59d2b3',1,'FILE_PATH(): create_top_window.c']]], ['file_5fpath_5fsize_2',['FILE_PATH_SIZE',['../d8/d99/conf__apikey_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#a995dadc733fcb391aac2116c80dd9508',1,'FILE_PATH_SIZE(): conf_uname.c']]], ['file_5fsize_3',['FILE_SIZE',['../d8/d99/conf__apikey_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_apikey.c'],['../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'],['../d4/df4/conf__uname_8c.html#af3c3df6c9906ede8f09fa2af74cb28d5',1,'FILE_SIZE(): conf_uname.c']]] ]; diff --git a/docs/html/search/defines_7.js b/docs/html/search/defines_7.js index 47b31ad..20cabb6 100644 --- a/docs/html/search/defines_7.js +++ b/docs/html/search/defines_7.js @@ -1,6 +1,4 @@ var searchData= [ - ['max_5fbuffer_5fsize_0',['MAX_BUFFER_SIZE',['../dc/dec/search_8c.html#ad4d796b98c583d49e83adabd74a63bf6',1,'search.c']]], - ['max_5ffile_5fpath_1',['MAX_FILE_PATH',['../dc/dec/search_8c.html#a263efd24d550124313df51247f07457a',1,'search.c']]], - ['missing_5fon_5foff_2',['MISSING_ON_OFF',['../dc/dc0/yiffy_8c.html#a9e8078dd597c541b6090e1e1ffd437e5',1,'yiffy.c']]] + ['missing_5fon_5foff_0',['MISSING_ON_OFF',['../dc/dc0/yiffy_8c.html#a9e8078dd597c541b6090e1e1ffd437e5',1,'yiffy.c']]] ]; diff --git a/docs/html/search/functions_1.js b/docs/html/search/functions_1.js index f81ad13..17ed6c3 100644 --- a/docs/html/search/functions_1.js +++ b/docs/html/search/functions_1.js @@ -11,5 +11,5 @@ var searchData= ['create_5fcontrols_5fwindow_8',['create_controls_window',['../d6/d24/create__controls__window_8c.html#a0a856b187dbd59a65a8bc9ffe5a597b1',1,'create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls): create_controls_window.c'],['../de/d29/yiffy__search_8h.html#a0a856b187dbd59a65a8bc9ffe5a597b1',1,'create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls): create_controls_window.c']]], ['create_5fpost_5ftags_5fwindow_9',['create_post_tags_window',['../d9/d28/create__post__tags__window_8c.html#a800291b89cb5eebec38a251c0ea0a24f',1,'create_post_tags_window(WINDOW *window, int *posts_panel_height): create_post_tags_window.c'],['../de/d29/yiffy__search_8h.html#a800291b89cb5eebec38a251c0ea0a24f',1,'create_post_tags_window(WINDOW *window, int *posts_panel_height): create_post_tags_window.c']]], ['create_5fposts_5fwindow_10',['create_posts_window',['../d3/d45/create__posts__window_8c.html#ad1975f63b7ab6049822e7b85a4bd40ee',1,'create_posts_window(WINDOW **window, int *posts_panel_height): create_posts_window.c'],['../de/d29/yiffy__search_8h.html#ad1975f63b7ab6049822e7b85a4bd40ee',1,'create_posts_window(WINDOW **window, int *posts_panel_height): create_posts_window.c']]], - ['create_5ftop_5fwindow_11',['create_top_window',['../dd/d93/create__top__window_8c.html#a090b2242d6c27461b6d72b4c69c3255f',1,'create_top_window(WINDOW *window, bool is_nsfw): create_top_window.c'],['../de/d29/yiffy__search_8h.html#a090b2242d6c27461b6d72b4c69c3255f',1,'create_top_window(WINDOW *window, bool is_nsfw): create_top_window.c']]] + ['create_5ftop_5fwindow_11',['create_top_window',['../dd/d93/create__top__window_8c.html#a5b2a6a6ce54a02a47d025adba6d325d7',1,'create_top_window(WINDOW *window): create_top_window.c'],['../de/d29/yiffy__search_8h.html#a5b2a6a6ce54a02a47d025adba6d325d7',1,'create_top_window(WINDOW *window): create_top_window.c']]] ]; diff --git a/src/menus/show_config.c b/src/menus/show_config.c index 26ee4f5..fdda63b 100644 --- a/src/menus/show_config.c +++ b/src/menus/show_config.c @@ -66,7 +66,7 @@ void write_configuration() /// @brief Reads the credentials file and writes the credentials one by one. void write_credentials() { - /* Create the configuration file path. */ + /* Create the credentials file path. */ sprintf(file_path, "%s/.yiffy/yiffy-credentials.txt", home_directory); FILE *credentials_file = fopen(file_path, "r"); diff --git a/src/search/create_top_window.c b/src/search/create_top_window.c index 0f010cb..4149cee 100644 --- a/src/search/create_top_window.c +++ b/src/search/create_top_window.c @@ -10,11 +10,54 @@ #include "yiffy_search.h" +#define FILE_PATH 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. + +static char *home_directory; ///< Stores the home directory as string. + +static char file_path[FILE_PATH]; ///< 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. + /// @brief Creates a new top window to display the title and SFW/NSFW status. /// @param window A pointer to the WINDOW where the title and SFW/NSFW status will be displayed. /// @param is_nsfw A boolean indicating whether the content is NSFW (true) or SFW (false). -void create_top_window(WINDOW *window, bool is_nsfw) +void create_top_window(WINDOW *window) { + /* NSFW option boolean value. */ + bool is_nsfw = false; + + /* Get the home directory of the current user. */ + home_directory = getenv("HOME"); + + if (home_directory == NULL) + { + no_home_error_msg(); + exit(1); + } + + /* Create the credentials 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); + } + + while (fgets(buffer, BUFFER_SIZE - 1, config_file)) + { + if (strcmp(buffer, "IS_NSFW=YES\n") == 0) + { + is_nsfw = true; + break; + } + } + + fclose(config_file); + + /* Create the windows. */ window = newwin(3, COLS, 0, 0); box(window, 0, 0); diff --git a/src/search/search.c b/src/search/search.c index 56fa149..4949e9c 100644 --- a/src/search/search.c +++ b/src/search/search.c @@ -12,8 +12,6 @@ #include "yiffy_search.h" -#define MAX_FILE_PATH 256 ///< This macro is used to set the default size for getting the home directory file. -#define MAX_BUFFER_SIZE 512 ///< This macro is used to set the default size for reading the config file. #define CONTENT_SIZE 524288 ///< This macro is used to set the default size for reading the JSON file that comes as a response from the API. control controls[] = @@ -30,9 +28,6 @@ WINDOW *posts_window; WINDOW *post_tags_window; WINDOW *controls_window; -/// @brief Indicates whether the NSFW option is enabled. -static bool is_nsfw; - /// @brief Height of the posts panel in the user interface. static int posts_panel_height; @@ -43,57 +38,11 @@ static char json_string[CONTENT_SIZE]; /// @param tags These are the e621-e926 tags prompted by the user as an argument value. Example: yiffy --search "anthro+fur+male+smile". void search(char *tags) { - /* Configuration file path and data buffer for configurations. */ - char config_path[MAX_FILE_PATH]; - char buffer[MAX_BUFFER_SIZE]; - - /* The home path of the user. */ - char *home_path = getenv("HOME"); - - /* Check if the NSFW option is enabled. */ - is_nsfw = false; - - if (home_path == NULL) - { - no_home_error_msg(); - exit(EXIT_FAILURE); - } - - sprintf(config_path, "%s/.yiffy/yiffy-config.txt", home_path); - - /* Read the configuration file (~/.yiffy/yiffy-config.txt) to execute the desired process. */ - FILE *config = fopen(config_path, "r"); - - if (config == NULL) - { - file_open_error_msg(); - exit(EXIT_FAILURE); - } - - size_t config_bytes = fread(buffer, 1, MAX_BUFFER_SIZE - 1, config); - buffer[config_bytes] = '\0'; - - fclose(config); - - /* Parse the configuration to check for NSFW option. */ - char *token = strtok(buffer, ":"); - - while (token != NULL) - { - if (strcmp(token, "nsfw") == 0) - { - is_nsfw = true; - break; - } - - token = strtok(NULL, ":"); - } - /* Initialize ncurses and configurations for the user interface. */ init_ncurses(); /* Create the ncurses-based user interfaces. */ - create_top_window(top_window, is_nsfw); + create_top_window(top_window); create_posts_window(&posts_window, &posts_panel_height); create_post_tags_window(post_tags_window, &posts_panel_height); create_controls_window(controls_window, &posts_panel_height, controls, sizeof(controls) / sizeof(controls[0])); diff --git a/src/search/yiffy_search.h b/src/search/yiffy_search.h index 53d92ac..e73188d 100644 --- a/src/search/yiffy_search.h +++ b/src/search/yiffy_search.h @@ -32,7 +32,7 @@ void search(char *tags); void init_ncurses(); /* User Interface creation functions. */ -void create_top_window(WINDOW *window, bool is_nsfw); +void create_top_window(WINDOW *window); void create_posts_window(WINDOW **window, int *posts_panel_height); void create_post_tags_window(WINDOW *window, int *posts_panel_height); void create_controls_window(WINDOW *window, int *posts_panel_height, control *controls, int total_controls);