progress: make gmsh great again

This commit is contained in:
2026-01-07 20:02:39 +09:00
parent db1e2c2364
commit 7f6de0567a
7 changed files with 442 additions and 231 deletions
+1 -56
View File
@@ -114,59 +114,4 @@ void cmd_resize(char* row, char* col) {
}
}
void cmd_help() { printf("Built-ins: ls, cd, pwd, cat, sz, poweroff, reboot\n"); }
void handle_redirection(const char *argv[]) {
int i = 0;
while (argv[i] != NULL) {
int fd = -1;
int is_redirect = 0;
// 1. Output Redirection (Overwrite): >
if (strcmp(argv[i], ">") == 0) {
if (argv[i+1] == NULL) {
fprintf(stderr, "gmsh: syntax error near unexpected token 'newline'\n");
exit(1);
}
fd = open(argv[i+1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) { perror("open"); exit(1); }
dup2(fd, STDOUT_FILENO); // stdout(1) -> fd
close(fd);
is_redirect = 1;
}
// 2. Output Redirection (Append): >>
else if (strcmp(argv[i], ">>") == 0) {
if (argv[i+1] == NULL) {
fprintf(stderr, "gmsh: syntax error\n");
exit(1);
}
// O_APPEND: 뒤에 추가
fd = open(argv[i+1], O_WRONLY | O_CREAT | O_APPEND, 0644);
if (fd < 0) { perror("open"); exit(1); }
dup2(fd, STDOUT_FILENO);
close(fd);
is_redirect = 1;
}
// 3. Input Redirection: <
else if (strcmp(argv[i], "<") == 0) {
if (argv[i+1] == NULL) {
fprintf(stderr, "gmsh: syntax error\n");
exit(1);
}
fd = open(argv[i+1], O_RDONLY);
if (fd < 0) { perror("open"); exit(1); }
dup2(fd, STDIN_FILENO); // stdin(0) -> fd
close(fd);
is_redirect = 1;
}
if (is_redirect) {
argv[i] = NULL;
break;
}
i++;
}
}
void cmd_help() { printf("Built-ins: ls, cd, pwd, cat, sz, poweroff, reboot\n"); }