-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindowsTest.h
134 lines (101 loc) · 3.37 KB
/
windowsTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <Windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define CLEANUP() clean_up()
#define COMPILE(compiler, files, cflags, executable_name, packages) \
compile_files(compiler, files, cflags, executable_name, packages)
#define READ_FILES() get_files_windows()
#define INFO(msg) printf("[INFO] %s\n", msg)
#define CMD(cmd) printf("[CMD] %s\n", cmd)
#define DONE(msg, file) printf("[DONE] %s : %s\n", msg, file)
int str_ends_with(const char* string, const char* suffix);
int str_starts_with(const char* string, const char* prefix);
void get_files_windows();
void compile_files(char* compiler, const char* files, const char* cflags, char* executable_name, char* packages);
const size_t number_of_files_to_build = 40;
const size_t filename_size_limit = 256;
char* file_list;
int main() {
READ_FILES();
printf("Hello World \n");
return 1;
}
void get_files_windows() {
LPWIN32_FIND_DATAA find_file_data;
HANDLE hFind;
file_list = (char*)malloc(sizeof(char) * filename_size_limit * number_of_files_to_build);
TCHAR buffer[MAX_PATH];
DWORD dwRet;
// This returns the wrong path right now!?
// it returns gibberish, probably because of how i'm
// running it but I don't actually know
dwRet = GetCurrentDirectory((TCHAR)MAX_PATH, buffer);
if (dwRet == 0) {
DWORD error = GetLastError();
printf("Error getting current directory: %lu \n", error);
return 1;
}
printf("%s", buffer);
LPCSTR sPath[2048];
sprintf(sPath, "%s\\*.*", buffer);
hFind = FindFirstFile(sPath, find_file_data);
if (hFind == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
printf("Error finding files %lu \n", error);
return 1;
}
strcpy(file_list, "");
do {
if (!(find_file_data->dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY)) {
if (str_ends_with(find_file_data->cFileName, ".c") && !str_starts_with(find_file_data->cFileName, "richBuild")) {
strcat(file_list, find_file_data->cFileName);
strcat(file_list, " ");
printf("File: %s\n", find_file_data->cFileName);
}
}
} while (FindNextFile(hFind, find_file_data) != 0);
FindClose(hFind);
return file_list;
}
int str_ends_with(const char* string, const char* suffix) {
if (!string || !suffix) {
return 0;
}
size_t string_len = strlen(string);
size_t suffix_len = strlen(suffix);
if (suffix_len > string_len) {
return 0;
}
return strncmp(string + string_len - suffix_len, suffix, suffix_len) == 0;
}
int str_starts_with(const char* string, const char* prefix) {
if (!prefix || !string) {
return 0;
}
size_t prefix_length = strlen(prefix);
if (prefix_length > strlen(string)) {
return 0;
}
return strncmp(string, prefix, prefix_length) == 0;
}
void compile_files(char* compiler, const char* files, const char* cflags, char* executable_name, char* packages) {
char compile_command[256];
if (packages == NULL) {
snprintf(compile_command, sizeof(compile_command),
"%s %s -o %s %s",
compiler, cflags, executable_name, files);
} else {
snprintf(compile_command, sizeof(compile_command),
"%s %s -o %s %s %s",
compiler, cflags, executable_name, files, packages);
}
INFO("Compiling Command:");
CMD(compile_command);
system(compile_command);
DONE("Finshed Compiling", executable_name);
}
void clean_up() {
free(file_list);
}