Skip to content

Commit cebc4a9

Browse files
committed
Refactor more stuff
1 parent 7974e8f commit cebc4a9

File tree

4 files changed

+19
-28
lines changed

4 files changed

+19
-28
lines changed

hd-tests.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,23 +286,17 @@ int
286286
test__create_horizontal_line__is_console_width(void)
287287
{
288288
/** Arrange */
289-
CONSOLE_SCREEN_BUFFER_INFO csbi = {
290-
80, 40, /** buffer columns, rows */
291-
0, 0, /** cursor column, row */
292-
14, /** color attributes */
293-
0, 0, 79, 39, /** coords left, top, right, bottom */
294-
0, 0 /** max window size */
295-
};
296-
size_t console_width = (size_t) csbi.srWindow.Right + 1;
289+
struct console_info console_info;
297290
char line[8192] = { 0 };
298-
size_t length = 0;
291+
int length = 0;
299292

300293
/** Act */
301-
create_horizontal_line(line, csbi);
302-
length = strlen(line);
294+
get_console_info(&console_info);
295+
create_horizontal_line(line, &console_info);
296+
length = (int) strlen(line);
303297

304298
/** Assert */
305-
if (length != console_width) {
299+
if (length != console_info.width) {
306300
printf("LINE %d: LENGTH OF LINE SHOULD MATCH CONSOLE WIDTH", __LINE__);
307301
return 1;
308302
}

hd.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ compact_size_with_suffix(double size_bytes, char * suffixed_size)
8585
if((size_bytes /= 1024) >= 1024) /** MB */
8686
if((size_bytes /= 1024) >= 1024) /** GB */
8787
if((size_bytes /= 1024) >= 1024) /** TB */
88-
sprintf(suffixed_size, "%lu TB", (unsigned long) (size_bytes/1024));
88+
sprintf(suffixed_size, "%lu TB", (unsigned long) (size_bytes/1024LU));
8989
else sprintf(suffixed_size, "%u GB", (unsigned) size_bytes);
9090
else sprintf(suffixed_size, "%u MB", (unsigned) size_bytes);
9191
else sprintf(suffixed_size, "%u KB", (unsigned) size_bytes);
@@ -110,20 +110,16 @@ create_footer(char * footer_string, int console_width, char * root_path, char se
110110

111111

112112
char *
113-
create_horizontal_line(char * result, CONSOLE_SCREEN_BUFFER_INFO csbi)
113+
create_horizontal_line(char result[], struct console_info * console_info)
114114
{
115-
SHORT i;
116-
SHORT console_width = csbi.srWindow.Right + 1;
117-
const char horizontal_line_character[] = { (char)196, '\0' };
115+
int i = 0;
116+
const char horizontal_line_character = (char) 196;
118117

119118
/** Draw line in result string */
120-
for(i = 0; i < console_width; ++i) {
121-
/* //if (i == console_width / 2) {
122-
// strcat(string, "%c", );
123-
//} else {
124-
*/ strncat(result, horizontal_line_character, 2);
125-
/* //}*/
119+
for(i = 0; i < console_info->width; ++i) {
120+
result[i] = horizontal_line_character;
126121
}
122+
result[i] = '\0';
127123

128124
return result;
129125
}
@@ -135,7 +131,7 @@ display_footer(struct console_info * console_info)
135131
char line[8192] = { 0 };
136132

137133
FG_AQUA();
138-
create_horizontal_line(line, g_screen_info_t);
134+
create_horizontal_line(line, console_info);
139135
printf("%s", line);
140136

141137
FG_LIGHT_AQUA();
@@ -182,7 +178,7 @@ display_header(struct console_info * console_info, struct search_info * search_i
182178
printf("Path: %s\n", search_info->path);
183179

184180
/** Draw horizontal line across screen */
185-
create_horizontal_line(line, g_screen_info_t);
181+
create_horizontal_line(line, console_info);
186182
printf("%s", line);
187183

188184
return 0;

hd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ struct console_info {
6565

6666
struct search_info {
6767
enum sort_by sort_by;
68-
char path[1024];
69-
char pattern[1024];
68+
char path[4096];
69+
char pattern[4096];
7070
enum should_clear_screen should_clear_screen;
7171
};
7272

@@ -75,7 +75,7 @@ int append_horizontal_line(char[], unsigned int);
7575
int build_initial_search_string(char * search_path, char * search_string);
7676
char * compact_size_with_suffix(double, char *);
7777
int create_footer(char *, int, char *, char);
78-
char * create_horizontal_line(char *, CONSOLE_SCREEN_BUFFER_INFO);
78+
char * create_horizontal_line(char *, struct console_info *);
7979
int display_footer(struct console_info *);
8080
int display_header(struct console_info *, struct search_info *);
8181
int display_help(struct console_info *);

main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ main(int argc, const char * argv[])
1919
display_help(&console_info);
2020
return 0;
2121
}
22+
display_header(&console_info, &search_info);
2223

2324
/* char search_path[MAX_PATH] = { 0 };*/
2425
/* char search_string[MAX_PATH] = { 0 };*/

0 commit comments

Comments
 (0)