Skip to content

Commit 15694a7

Browse files
committed
Improve types and makefile
1 parent f149640 commit 15694a7

File tree

5 files changed

+51
-46
lines changed

5 files changed

+51
-46
lines changed

hd-tests.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int
114114
test__compact_size_with_suffix__is_not_gigabytes()
115115
{
116116
/** Arrange */
117-
long long size = 1073741823;
117+
unsigned long size = 1073741823;
118118
char result[16] = { 0 };
119119
const char * expected = "1023 MB";
120120

@@ -156,7 +156,7 @@ int
156156
test__compact_size_with_suffix__is_terabytes()
157157
{
158158
/** Arrange */
159-
long long size = 1099511627776;
159+
double size = 1099511627776;
160160
char result[16] = { 0 };
161161
const char * expected = "1 TB";
162162

@@ -177,7 +177,7 @@ int
177177
test__compact_size_with_suffix__works_with_ntfs_volume_limit()
178178
{
179179
/** Arrange */
180-
long long size = 281474976710656;
180+
double size = 281474976710656;
181181
char result[16] = { 0 };
182182
const char * expected = "256 TB";
183183

hd.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ HANDLE g_hConsole;
1919
SHORT g_console_width;
2020
WORD g_original_attributes;
2121
char g_search_drive = 'C'; /** Pre-load with C: drive */
22-
//char g_search_string[MAX_PATH];
23-
//char g_search_path[MAX_PATH];
22+
/*//char g_search_string[MAX_PATH];
23+
//char g_search_path[MAX_PATH];*/
2424

2525
/** Console variables: */
2626
CONSOLE_SCREEN_BUFFER_INFO
2727
g_screen_info_t;
2828
WIN32_FIND_DATA
2929
g_file_data_t;
3030
INT g_console_height = 24;
31-
//HANDLE g_search_handle;
31+
/*//HANDLE g_search_handle;*/
3232
SHORT g_line_count = 3; /** Preload w/ num lines in header */
3333
DWORD g_dwAttrib;
3434

@@ -58,17 +58,17 @@ append_horizontal_line(char string[], unsigned int console_width)
5858
{
5959
(void) string;
6060
(void) console_width;
61-
//unsigned int i = 0;
61+
/*//unsigned int i = 0;
6262
//SHORT console_width = csbi.srWindow.Right + 1;
63-
//const char horizontal_line_character[] = { (char)196, '\0' };
64-
//
63+
//const char horizontal_line_character[] = { (char)196, '\0' };*/
64+
/*//
6565
// sprintf(glyph, "%c", 196);
6666
//
6767
// for (i=0; i <= console_width; ++i) {
6868
// strcat(string, glyph);
6969
// }
7070
//
71-
// strcat(string, "\n");
71+
// strcat(string, "\n");*/
7272
return 0;
7373
}
7474

@@ -82,29 +82,29 @@ create_horizontal_line(char * result, CONSOLE_SCREEN_BUFFER_INFO csbi)
8282

8383
/** Draw line in result string */
8484
for(i = 0; i < console_width; ++i) {
85-
//if (i == console_width / 2) {
85+
/* //if (i == console_width / 2) {
8686
// strcat(string, "%c", );
8787
//} else {
88-
strncat(result, horizontal_line_character, 2);
89-
//}
88+
*/ strncat(result, horizontal_line_character, 2);
89+
/* //}*/
9090
}
9191

9292
return result;
9393
}
9494

9595

9696
char *
97-
compact_size_with_suffix(long long size_bytes, char * suffixed_size)
97+
compact_size_with_suffix(double size_bytes, char * suffixed_size)
9898
{
9999
if(size_bytes >= 1024LL) /** KB */
100100
if((size_bytes /= 1024LL) >= 1024LL) /** MB */
101101
if((size_bytes /= 1024LL) >= 1024LL) /** GB */
102102
if((size_bytes /= 1024LL) >= 1024LL) /** TB */
103-
sprintf(suffixed_size, "%lld TB", size_bytes/1024LL);
104-
else sprintf(suffixed_size, "%lld GB", size_bytes);
105-
else sprintf(suffixed_size, "%lld MB", size_bytes);
106-
else sprintf(suffixed_size, "%lld KB", size_bytes);
107-
else sprintf(suffixed_size, "%lld B", size_bytes);
103+
sprintf(suffixed_size, "%lu TB", (unsigned long) (size_bytes/1024LL));
104+
else sprintf(suffixed_size, "%u GB", (unsigned) size_bytes);
105+
else sprintf(suffixed_size, "%u MB", (unsigned) size_bytes);
106+
else sprintf(suffixed_size, "%u KB", (unsigned) size_bytes);
107+
else sprintf(suffixed_size, "%u B", (unsigned) size_bytes);
108108

109109
return suffixed_size;
110110
}
@@ -144,7 +144,7 @@ display_footer()
144144
FG_LIGHT_GREEN(); printf(" \t\t Volume label: ");
145145

146146
g_root_path[0] = g_search_drive;
147-
// GetVolumeInformation(g_root_path, g_volume_name, ARRAYSIZE(g_volume_name), &serial_number, &max_component_length, &filesystem_flags, filesystem_name, ARRAYSIZE(filesystem_name));
147+
/*// GetVolumeInformation(g_root_path, g_volume_name, ARRAYSIZE(g_volume_name), &serial_number, &max_component_length, &filesystem_flags, filesystem_name, ARRAYSIZE(filesystem_name));*/
148148
GetVolumeInformation(g_root_path, g_volume_name, ARRAYSIZE(g_volume_name), NULL, NULL, NULL, NULL, 0);
149149

150150
FG_LIGHT_RED(); printf("%s\n", g_volume_name);
@@ -368,12 +368,12 @@ int process_files(HANDLE search_handle, char * search_path)
368368
return -1;
369369

370370
}
371-
// else if (search_handle == ERROR_FILE_NOT_FOUND) {
371+
/*// else if (search_handle == ERROR_FILE_NOT_FOUND) {
372372
// puts("\nNo file or folder found.");
373373
//
374374
// restore_console();
375375
// return -1;
376-
// }
376+
// }*/
377377

378378
do {
379379
/** File is directory ? */
@@ -492,8 +492,8 @@ int process_files(HANDLE search_handle, char * search_path)
492492
|| strcmp(g_file_ext, ".deb") == 0 || strcmp(g_file_ext, ".rpm") == 0 || strcmp(g_file_ext, ".mdf") == 0
493493
|| strcmp(g_file_ext, ".cue") == 0 || strcmp(g_file_ext, ".bin") == 0 || strcmp(g_file_ext, ".apk") == 0)
494494
FG_YELLOW();
495-
else FG_GRAY(); // (everything else)
496-
} else FG_GRAY(); // (no extension)
495+
else FG_GRAY(); /** (everything else) */
496+
} else FG_GRAY(); /** (no extension) */
497497
} /** First if/else */
498498

499499
/** Pause if console screen is full */
@@ -535,7 +535,7 @@ int process_files(HANDLE search_handle, char * search_path)
535535
else printf("% 5.1f KB", g_file_size);
536536
else printf("% 5d B ", (int)g_file_size);
537537

538-
//g_total_consumed += (float)((*lpFileSizeHigh * (MAXDWORD+1)) + GetCompressedFileSize(g_file_data_t.cFileName, lpFileSizeHigh));
538+
/* //g_total_consumed += (float)((*lpFileSizeHigh * (MAXDWORD+1)) + GetCompressedFileSize(g_file_data_t.cFileName, lpFileSizeHigh));*/
539539
}
540540

541541
FG_AQUA(); printf("\263 \n"); // Print |

hd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ struct console_info {
4949

5050
int append_horizontal_line(char[], unsigned int);
5151
int build_initial_search_string(char * search_path, char * search_string);
52-
char * compact_size_with_suffix(unsigned long, char *);
52+
char * compact_size_with_suffix(double, char *);
5353
int create_footer(char *, int, char *, char);
5454
char * create_horizontal_line(char *, CONSOLE_SCREEN_BUFFER_INFO);
5555
int display_footer(void);
5656
int display_header(char * search_path);
5757
int display_help(void);
5858
int fixup_path(char * search_path);
59-
struct console_info * get_console_info(void);
59+
struct console_info * get_console_info(struct console_info *);
6060
int get_console_width(void);
6161
int process_cmdline_args(int argc, char * argv[], char search_drive, char * search_path, char * search_string);
6262
int process_files(HANDLE search_handle, char * search_path);
63-
int restore_console(void);
63+
int restore_console();
6464

6565
#endif /** HD_H */

main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ int main(int argc, char * argv[])
88
char search_string[MAX_PATH] = { 0 };
99
HANDLE search_handle = 0;
1010
struct console_info console;
11-
WORD original_colors;
11+
/* WORD original_colors;*/
1212

1313
get_console_info(&console);
14-
original_colors = (WORD)console.colors;
14+
/* original_colors = (WORD)console.colors;*/
1515

1616
build_initial_search_string(search_path, search_string);
1717
process_cmdline_args(argc,
@@ -24,6 +24,7 @@ int main(int argc, char * argv[])
2424
process_files(search_handle, search_path);
2525

2626
display_footer();
27-
restore_console(original_colors);
27+
/* restore_console(original_colors);*/
28+
restore_console();
2829
return 0;
2930
}

makefile

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
CL = cl.exe -nologo -J -WX -W4 -sdl -arch:IA32 -O2 -D_CRT_SECURE_NO_WARNINGS
2-
LINK = link.exe -nologo -subsystem:console,"5.01"
1+
CC = cl.exe -nologo -J -WX -W4 -sdl -arch:IA32 -O2 -D_CRT_SECURE_NO_WARNINGS
2+
LINK = link.exe -nologo -subsystem:console,"5.01" -OUT:
33

4-
GCC = gcc
5-
CFLAGS = -std=c99 -funsigned-char -O2 -fdiagnostics-color -Wall -Wextra -pedantic-errors -Wfatal-errors -Wshadow -Wconversion -Wsign-conversion -Wno-missing-braces
6-
LDFLAGS = -mconsole
4+
#CC = gcc -std=c99 -funsigned-char -O2 -fdiagnostics-color -Wall -Wextra -pedantic-errors -Wfatal-errors -Wshadow -Wconversion -Wsign-conversion -Wno-missing-braces
5+
#LINK = gcc -mconsole -o
76

87

98
all : tests hd.exe
@@ -14,24 +13,29 @@ test : tests
1413
tests : hd-tests.exe
1514

1615
hd-tests.exe : hd-tests.obj hd.obj
17-
@$(LINK) hd-tests.obj hd.obj 2>NUL \
18-
|| ($(GCC) $(LDFLAGS) -o hd-tests.exe hd-tests.obj hd.obj; rm NUL)
16+
# @$(LINK) hd-tests.obj hd.obj 2>NUL \
17+
# ($(GCC) $(LDFLAGS) -o hd-tests.exe hd-tests.obj hd.obj; rm NUL)
18+
@$(LINK)"hd-tests.exe" hd-tests.obj hd.obj 2>NUL
1919

2020
hd-tests.obj : hd-tests.c hd.h
21-
@$(CL) -c hd-tests.c 2>NUL \
22-
|| ($(GCC) $(CFLAGS) -c hd-tests.c -o hd-tests.obj; rm NUL)
21+
# @$(CL) -c hd-tests.c 2>NUL \
22+
# || ($(GCC) $(CFLAGS) -c hd-tests.c -o hd-tests.obj; rm NUL)
23+
@$(CC) -c hd-tests.c -o hd-tests.obj 2>NUL
2324

2425
hd.exe : hd.obj main.obj
25-
@$(LINK) hd.obj main.obj 2>NUL \
26-
|| ($(GCC) $(LDFLAGS) -o hd.exe hd.obj main.obj; rm NUL)
26+
# @$(LINK) hd.obj main.obj 2>NUL \
27+
# $(GCC) $(LDFLAGS) -o hd.exe hd.obj main.obj
28+
@$(LINK)"hd.exe" hd.obj main.obj 2>NUL
2729

2830
hd.obj : hd.c hd.h
29-
@$(CL) -c hd.c 2>NUL \
30-
|| ($(GCC) $(CFLAGS) -c hd.c -o hd.obj; rm NUL)
31+
# @$(CL) -c hd.c 2>NUL \
32+
# || ($(GCC) $(CFLAGS) -c hd.c -o hd.obj; rm NUL)
33+
@$(CC) -c hd.c -o hd.obj 2>NUL
3134

3235
main.obj : main.c hd.h
33-
@$(CL) -c main.c 2>NUL \
34-
|| ($(GCC) $(CFLAGS) -c main.c -o main.obj; rm NUL)
36+
# @$(CL) -c main.c 2>NUL \
37+
# || ($(GCC) $(CFLAGS) -c main.c -o main.obj; rm NUL)
38+
@$(CC) -c main.c -o main.obj 2>NUL
3539

3640
clean :
3741
@del hd-tests.obj hd-tests.exe hd.obj hd.exe main.obj 2>NUL \

0 commit comments

Comments
 (0)