Skip to content

Commit f442ab9

Browse files
committed
feat: It finally compiles, but it doesn't run.
1 parent b209998 commit f442ab9

12 files changed

+72
-14
lines changed

.clangd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CompileFlags:
2-
Add: [-Wall, -Wextra, -I./]
2+
Add: [-Wall, -Wextra, -I./include/]

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug",
11+
"program": "${workspaceFolder}\\build\\bin\\hsh.exe",
12+
"args": [],
13+
"cwd": "${workspaceFolder}"
14+
}
15+
]
16+
}

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ _et voilà!_ Now it should be located in ./bin/ aswell.
6464

6565
## Contributing
6666

67-
Contribution is simple, make sure you're running an editor that works with C.
67+
Contribution is simple, make sure you're running an editor that works with C and is using clang for compilation.
6868

6969
Such as:
7070

@@ -84,6 +84,13 @@ which is ick, but I'll gladly accept a pr for it.
8484

8585
Also, one final thing, make sure you have pre-commit hooks.
8686

87+
> \[!NOTE\]
88+
> Windows people!
89+
90+
Just copy and paste the win_compile_commands.json in build and change it so it fits your path.
91+
92+
Don't forget to rename it to compile_commands.json!
93+
8794
_direnv users who don't use nix, i'm sorry :(_
8895

8996
Made with :heart: by tatsoku-org!

build/build.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if [[ ${OSTYPE} != "msys" ]]; then
8080
LINKER_FLAGS+=" -fuse-ld=mold"
8181
else
8282
CFLAGS+=" -I/usr/include"
83-
LINKER_FLAGS="-lbsd ${LINKER_FLAGS}"
83+
LINKER_FLAGS+=" -lbsd -L/usr/lib"
8484
fi
8585

8686
if [[ ${2} == "--debug" ]]; then
@@ -435,7 +435,7 @@ clear_vgcores() {
435435
fix_clangd() {
436436
cmake -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=ON >/dev/null
437437
mv build/compile_commands.json .
438-
find build -mindepth 1 ! -path "build/bin" ! -path "build/out" ! -path "build/tests" ! -name "build.sh" -exec rm -rf {} +
438+
find build -mindepth 1 ! -path "build/bin" ! -path "build/win_compile_commands.json" ! -path "build/out" ! -path "build/tests" ! -name "build.sh" -exec rm -rf {} +
439439
}
440440

441441
case $1 in

build/win_compile_commands.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"directory": "C:\\msys64\\home\\h4rl\\projects\\hamon-1\\build",
4+
"command": "C:\\msys64\\clang64\\bin\\cc.exe -IC:\\msys64\\home\\h4rl\\projects\\hamon-1\\include -IC:\\msys64\\usr\\include -o CMakeFiles\\main.dir\\src\\main.c.o -c C:\\msys64\\home\\h4rl\\projects\\hamon-1\\src\\main.c",
5+
"file": "C:\\msys64\\home\\h4rl\\projects\\hamon-1\\src\\main.c",
6+
"output": "CMakeFiles\\main.dir\\src\\main.c.o"
7+
}
8+
]

justfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ default:
2828
just link {{name}}
2929
./build/bin/{{name}} {{args}}
3030

31-
@debug args="" name="hsh": fix_perms
31+
@debug-linux args="" name="hsh": fix_perms
3232
just compile --debug
3333
just link {{name}}
3434
valgrind ./build/bin/{{name}} {{args}}
3535

36+
@debug-windows args="" name="hsh": fix_perms
37+
just compile --debug
38+
just link {{name}}
39+
lldb ./build/bin/{{name}}.exe {{args}}
40+
3641
@clear_cores: fix_perms
3742
build/build.sh -vg
3843

src/hamon/builtins.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int builtin_cd(int argc, char *argv[], char *const *envp) {
169169
#elif _WIN32
170170
char cwd_buf[MAX_PATH] = {0};
171171

172-
GetCurrentDirectory(MAX_PATH, (LPWSTR)cwd_buf);
172+
GetCurrentDirectory(MAX_PATH, (LPSTR)cwd_buf);
173173
strlcpy(last_dir, cwd_buf, MAX_PATH);
174174

175175
if (strncmp(path, "~", 1) == 0) {
@@ -178,7 +178,7 @@ int builtin_cd(int argc, char *argv[], char *const *envp) {
178178
strlcpy(path, last_dir, MAX_PATH);
179179
}
180180

181-
if (!SetCurrentDirectory((LPWSTR)path)) {
181+
if (!SetCurrentDirectory((LPSTR)path)) {
182182
win_perror("Couldn't change directory.");
183183
return 1;
184184
}

src/hamon/config.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int gen_default_config(void) {
164164
}
165165

166166
size_t length = strlcpy(config_buffer, default_config, config_buffer_size);
167-
if (length > sizeof(config_buffer_size)) {
167+
if (length > config_buffer_size) {
168168
free(config_buffer);
169169
return -1;
170170
}

src/hamon/error.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void win_perror(const char *msg) {
1212
0, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1313
(LPTSTR)&lpMsgBuf, 0, 0);
1414

15-
printf("%s: %s\n", msg, lpMsgBuf);
15+
printf("%s: %s\n", msg, (LPTSTR)lpMsgBuf);
1616
LocalFree(lpMsgBuf);
1717
}
1818
#endif

src/hamon/exec.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BOOL find_executable_in_path(LPCSTR executable, LPCSTR *path_found) {
5252
return FALSE;
5353
}
5454
#endif
55-
55+
#ifdef __linux__
5656
char *get_exec_path(const char *name, char *const *envp) {
5757
char path[4096] = {0};
5858

@@ -78,6 +78,7 @@ char *get_exec_path(const char *name, char *const *envp) {
7878
}
7979
return 0;
8080
}
81+
#endif
8182

8283
int execute(char *executable, char *argv[], char *const *envp) {
8384
#ifdef __linux__
@@ -103,15 +104,16 @@ int execute(char *executable, char *argv[], char *const *envp) {
103104
} else if (pid == 0) {
104105
if (execve(path, argv, envp) != 0) {
105106
perror("Failed to exec to childprocess (execve)");
107+
free(path);
106108
exit(-1);
107109
} else {
108110
free(path);
109111
exit(0);
110112
}
111113
} else {
112114
wait(&status);
115+
free(path);
113116
}
114-
115117
#elif _WIN32
116118

117119
LPCSTR win_executable = (LPCSTR)executable;
@@ -147,6 +149,5 @@ int execute(char *executable, char *argv[], char *const *envp) {
147149
}
148150

149151
#endif
150-
free(path);
151152
return 0;
152153
}

src/hamon/prompt.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ char *get_username(void) {
7777

7878
// char *assemble_prompt() { return ">"; }
7979

80+
#ifdef _WIN32
81+
char **get_environment_variables() {
82+
LPCH env_strings = GetEnvironmentStrings();
83+
LPCH ptr = env_strings;
84+
char **env_array = calloc(4096, sizeof(char *));
85+
int count = 0;
86+
87+
while (*ptr != '\0' && count < 4096 - 1) {
88+
size_t len = strlen(ptr);
89+
env_array[count] = malloc(len + 1);
90+
strcpy(env_array[count], ptr);
91+
ptr += len + 1;
92+
count++;
93+
}
94+
95+
env_array[count] = NULL;
96+
FreeEnvironmentStrings(env_strings);
97+
return env_array;
98+
}
99+
#endif
100+
80101
bool is_env_format(const char *str) {
81102
const char *equals = strchr(str, '=');
82103
return equals != 0 && equals != str && *(equals + 1) != '\0';
@@ -104,7 +125,7 @@ int init_prompt(void) {
104125
#ifdef __linux__
105126
char **envp = __environ;
106127
#elif _WIN32
107-
char **envp = _dupenv_s(NULL, NULL, 0);
128+
char **envp = get_environment_variables();
108129
#endif
109130
int argc = 0;
110131
int env_count = 0;

src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ int main(int argc, char *argv[]) {
4545
gen_default_config();
4646

4747
// init_shell();
48-
return init_prompt();
48+
// return init_prompt();
4949
}

0 commit comments

Comments
 (0)