Skip to content

Commit 8a4857a

Browse files
committed
Add clang/c89 compatibility and remove old cruft from makefile
1 parent 15694a7 commit 8a4857a

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

hd-tests.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
int
8-
test__append_horizontal_line()
8+
test__append_horizontal_line(void)
99
{
1010
/** Arrange */
1111
char result[4096] = { 0 };
@@ -27,7 +27,7 @@ test__append_horizontal_line()
2727

2828

2929
int
30-
test__compact_size_with_suffix__is_bytes()
30+
test__compact_size_with_suffix__is_bytes(void)
3131
{
3232
/** Arrange */
3333
int size = 1023;
@@ -48,7 +48,7 @@ test__compact_size_with_suffix__is_bytes()
4848

4949

5050
int
51-
test__compact_size_with_suffix__is_gigabytes()
51+
test__compact_size_with_suffix__is_gigabytes(void)
5252
{
5353
/** Arrange */
5454
unsigned long size = 1073741824;
@@ -69,7 +69,7 @@ test__compact_size_with_suffix__is_gigabytes()
6969

7070

7171
int
72-
test__compact_size_with_suffix__is_kilobytes()
72+
test__compact_size_with_suffix__is_kilobytes(void)
7373
{
7474
/** Arrange */
7575
int size = 1048575;
@@ -90,7 +90,7 @@ test__compact_size_with_suffix__is_kilobytes()
9090

9191

9292
int
93-
test__compact_size_with_suffix__is_megabytes()
93+
test__compact_size_with_suffix__is_megabytes(void)
9494
{
9595
/** Arrange */
9696
int size = 1048576;
@@ -111,7 +111,7 @@ test__compact_size_with_suffix__is_megabytes()
111111

112112

113113
int
114-
test__compact_size_with_suffix__is_not_gigabytes()
114+
test__compact_size_with_suffix__is_not_gigabytes(void)
115115
{
116116
/** Arrange */
117117
unsigned long size = 1073741823;
@@ -132,7 +132,7 @@ test__compact_size_with_suffix__is_not_gigabytes()
132132

133133

134134
int
135-
test__compact_size_with_suffix__is_not_megabytes()
135+
test__compact_size_with_suffix__is_not_megabytes(void)
136136
{
137137
/** Arrange */
138138
int size = 1048575;
@@ -153,10 +153,10 @@ test__compact_size_with_suffix__is_not_megabytes()
153153

154154

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

@@ -174,10 +174,10 @@ test__compact_size_with_suffix__is_terabytes()
174174

175175

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

@@ -195,32 +195,32 @@ test__compact_size_with_suffix__works_with_ntfs_volume_limit()
195195

196196

197197
int
198-
test__create_footer()
198+
test__create_footer(void)
199199
{
200-
// /** Arrange */
201-
// char footer_string[1024] = { 0 };
200+
/** Arrange */
201+
/*// char footer_string[1024] = { 0 };
202202
// int console_width = 80;
203203
// char * root_path = "x:\\";
204204
// char search_drive = 'C';
205-
//
206-
// /** Act */
207-
// create_footer(footer_string, console_width, root_path, search_drive);
205+
//*/
206+
/** Act */
207+
/*// create_footer(footer_string, console_width, root_path, search_drive);*/
208208

209209
/** Assert */
210-
// if (strcmp(footer_string,
210+
/*// if (strcmp(footer_string,
211211
// " 0 files, totaling , consuming 0 bytes of disk space.\n"
212212
// " 0 bytes available on Drive C: Volume label: C_DRIVE\n"
213213
// ) != 0) {
214214
// puts("STRING SHOULD MATCH");
215215
// return 1;
216216
// }
217-
//
217+
//*/
218218
return 0;
219219
}
220220

221221

222222
int
223-
test__create_horizontal_line__is_console_width()
223+
test__create_horizontal_line__is_console_width(void)
224224
{
225225
/** Arrange */
226226
CONSOLE_SCREEN_BUFFER_INFO csbi = {
@@ -249,7 +249,7 @@ test__create_horizontal_line__is_console_width()
249249

250250

251251
int
252-
test__get_console_info__sets_attributes()
252+
test__get_console_info__sets_attributes(void)
253253
{
254254
/** Arrange */
255255
struct console_info console = { -1, -1, -1 };
@@ -272,7 +272,7 @@ test__get_console_info__sets_attributes()
272272

273273

274274
int
275-
test__get_console_width__greater_than_zero()
275+
test__get_console_width__greater_than_zero(void)
276276
{
277277
/** Arrange */
278278
int width = -1;
@@ -291,11 +291,11 @@ test__get_console_width__greater_than_zero()
291291

292292

293293
int
294-
main()
294+
main(void)
295295
{
296296
int failed_count = 0;
297297

298-
//failed_count += test__append_horizontal_line();
298+
/* //failed_count += test__append_horizontal_line();*/
299299
failed_count += test__compact_size_with_suffix__is_bytes();
300300
failed_count += test__compact_size_with_suffix__is_gigabytes();
301301
failed_count += test__compact_size_with_suffix__is_kilobytes();
@@ -304,7 +304,7 @@ main()
304304
failed_count += test__compact_size_with_suffix__is_not_megabytes();
305305
failed_count += test__compact_size_with_suffix__is_terabytes();
306306
failed_count += test__compact_size_with_suffix__works_with_ntfs_volume_limit();
307-
//failed_count += test__create_footer();
307+
/* //failed_count += test__create_footer();*/
308308
failed_count += test__create_horizontal_line__is_console_width();
309309
failed_count += test__get_console_info__sets_attributes();
310310
failed_count += test__get_console_width__greater_than_zero();

hd.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ create_horizontal_line(char * result, CONSOLE_SCREEN_BUFFER_INFO csbi)
9696
char *
9797
compact_size_with_suffix(double size_bytes, char * suffixed_size)
9898
{
99-
if(size_bytes >= 1024LL) /** KB */
100-
if((size_bytes /= 1024LL) >= 1024LL) /** MB */
101-
if((size_bytes /= 1024LL) >= 1024LL) /** GB */
102-
if((size_bytes /= 1024LL) >= 1024LL) /** TB */
103-
sprintf(suffixed_size, "%lu TB", (unsigned long) (size_bytes/1024LL));
99+
if(size_bytes >= 1024) /** KB */
100+
if((size_bytes /= 1024) >= 1024) /** MB */
101+
if((size_bytes /= 1024) >= 1024) /** GB */
102+
if((size_bytes /= 1024) >= 1024) /** TB */
103+
sprintf(suffixed_size, "%lu TB", (unsigned long) (size_bytes/1024));
104104
else sprintf(suffixed_size, "%u GB", (unsigned) size_bytes);
105105
else sprintf(suffixed_size, "%u MB", (unsigned) size_bytes);
106106
else sprintf(suffixed_size, "%u KB", (unsigned) size_bytes);
@@ -111,7 +111,7 @@ compact_size_with_suffix(double size_bytes, char * suffixed_size)
111111

112112

113113
int
114-
display_footer()
114+
display_footer(void)
115115
{
116116
char line[8192] = { 0 };
117117

@@ -183,7 +183,7 @@ int display_header(char * search_path)
183183
}
184184

185185

186-
int display_help()
186+
int display_help(void)
187187
{
188188
int i;
189189

@@ -253,7 +253,7 @@ get_console_info(struct console_info * p_console)
253253

254254

255255
int
256-
get_console_width()
256+
get_console_width(void)
257257
{
258258
HANDLE console_output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
259259
CONSOLE_SCREEN_BUFFER_INFO console_screen_buffer_info = { 0 };
@@ -502,7 +502,8 @@ int process_files(HANDLE search_handle, char * search_path)
502502
GetConsoleScreenBufferInfo(g_hConsole, &g_screen_info_t);
503503
g_dwAttrib = g_screen_info_t.wAttributes;
504504
FG_GRAY(); system("PAUSE");
505-
SetConsoleTextAttribute(g_hConsole, (WORD)g_dwAttrib); // Restore Color
505+
/** Restore Color */
506+
SetConsoleTextAttribute(g_hConsole, (WORD)g_dwAttrib);
506507
}
507508

508509
/** "DARK FG_RED" for hidden files */
@@ -512,7 +513,7 @@ int process_files(HANDLE search_handle, char * search_path)
512513

513514
/** Display file name */
514515
printf("%-*s", g_console_width / 2 - 8, g_file_data_t.cFileName);
515-
//printf("%s\n", g_file_ext);
516+
/* //printf("%s\n", g_file_ext);*/
516517

517518
/** Display <dir> for directories */
518519
if(g_file_data_t.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
@@ -538,7 +539,7 @@ int process_files(HANDLE search_handle, char * search_path)
538539
/* //g_total_consumed += (float)((*lpFileSizeHigh * (MAXDWORD+1)) + GetCompressedFileSize(g_file_data_t.cFileName, lpFileSizeHigh));*/
539540
}
540541

541-
FG_AQUA(); printf("\263 \n"); // Print |
542+
FG_AQUA(); printf("\263 \n"); /** Print | */
542543
} while( FindNextFile(search_handle, &g_file_data_t) != 0 );
543544
/** End do */
544545

@@ -547,7 +548,7 @@ int process_files(HANDLE search_handle, char * search_path)
547548
}
548549

549550

550-
int restore_console()
551+
int restore_console(void)
551552
{
552553
SetConsoleTextAttribute(g_hConsole, g_original_attributes);
553554
return 0;

hd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ 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();
63+
int restore_console(void);
6464

6565
#endif /** HD_H */

makefile

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
################################################################
2+
# NOTE: Subsystem "5.01" requires MSVC <= 19.27 (VS2019 16.7.28)
3+
################################################################
14
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:
5+
LL = link.exe -nologo -subsystem:console,"5.01" -OUT:
36

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
7+
#CFLAGS = -m32 -std=c89 -funsigned-char -O2 -fdiagnostics-color -Wall -Wextra -pedantic-errors -Wfatal-errors -Wshadow -Wconversion -Wsign-conversion -Wno-missing-braces -Wno-deprecated-declarations
8+
9+
#CC = gcc $(CFLAGS)
10+
#LL = gcc -mconsole -o
11+
12+
################################################################
13+
# NOTE: `nmake` is required to properly run `clang`, it seems...
14+
################################################################
15+
#CC = clang $(CFLAGS)
16+
#LL = lld-link --color-diagnostics=never -subsystem:console,"5.01" libcmt.lib -out:
617

718

819
all : tests hd.exe
@@ -13,29 +24,19 @@ test : tests
1324
tests : hd-tests.exe
1425

1526
hd-tests.exe : hd-tests.obj hd.obj
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
27+
@$(LL)"hd-tests.exe" hd-tests.obj hd.obj
1928

2029
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)
23-
@$(CC) -c hd-tests.c -o hd-tests.obj 2>NUL
30+
@$(CC) -c hd-tests.c -o hd-tests.obj
2431

2532
hd.exe : hd.obj main.obj
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
33+
@$(LL)"hd.exe" hd.obj main.obj
2934

3035
hd.obj : hd.c hd.h
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
36+
@$(CC) -c hd.c -o hd.obj
3437

3538
main.obj : main.c hd.h
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
39+
@$(CC) -c main.c -o main.obj
3940

4041
clean :
4142
@del hd-tests.obj hd-tests.exe hd.obj hd.exe main.obj 2>NUL \

0 commit comments

Comments
 (0)