summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test-mvmt.c48
1 files changed, 16 insertions, 32 deletions
diff --git a/test-mvmt.c b/test-mvmt.c
index 952dd9d..27f0aa3 100644
--- a/test-mvmt.c
+++ b/test-mvmt.c
@@ -53,7 +53,6 @@ int startpipe(char *path, char *input , char *output, ssize_t *size) {
fprintf(stderr, "Error occured while duplicating stdout.\n");
close(fd1[1]);
}
- /*fprintf(stderr,"%s\n", path);*/
if (path == NULL)
fprintf(stderr, "oof, yet even more errors, this time with getcwd.\n");
if (execl(path, "clld", (char *)0) < 0) {
@@ -61,28 +60,30 @@ int startpipe(char *path, char *input , char *output, ssize_t *size) {
return -4;
}
return 0;
- /*printf("%s\n", path);*/
} else {
+ int status;
close(fd0[0]);
close(fd1[1]);
- /*if (write(fd0[1], input, strlen(input)) != strlen(input))
- fprintf(stderr, "Error occured while trying to write to clld.\n");
- close(fd0[1]);
- if ((*size = read(fd1[0], output, 129) < 0))
- fprintf(stderr, "Error occured while trying to read the output of clld.\n");
- close(fd1[0]);
- if (size == 0) {
- fprintf(stderr, "Child process has closed it's pipe.\n");
- return 0;
- }*/
write(fd0[1], input, strlen(input));
- usleep(2000);
+ while (pid = waitpid(pid, &status, WUNTRACED) > 0) {
+ if (pid == -1) {
+ perror("waitpid");
+ exit(EXIT_FAILURE);
+ }
+ if (WIFEXITED(status)) {
+ printf("\033[10;1H\033[2Kchild exited, status=%d", WEXITSTATUS(status));
+ } else if (WIFSIGNALED(status)) {
+ printf("\033[10;1H\033[2Kchild killed (signal %d)", WTERMSIG(status));
+ } else if (WIFSTOPPED(status)) {
+ printf("\033[10;1H\033[2Kchild stopped (signal %d)", WSTOPSIG(status));
+ } else {
+ printf("\033[10;1H\033[2KUnexpected status (0x%x)", status);
+ }
+ }
close(fd0[1]);
*size = read(fd1[0], output, 129);
close(fd1[0]);
return 0;
- /*printf("rv: %i\n", rv);*/
- /*printf("%s", output);*/
}
return 0;
}
@@ -92,7 +93,6 @@ void split(char *str, char **splitstr) {
int i=0;
p = strtok(str,"\n");
while(p!= NULL) {
- /*printf("%s\n", p);*/
splitstr[i] = malloc(strlen(p) + 1);
if (splitstr[i])
strcpy(splitstr[i], p);
@@ -137,26 +137,10 @@ int main (int argc, char **argv) {
startpipe(path, input, &ln, &size);
char *line[65] = {NULL};
split(ln, line);
- /*printf("%s\n%s\n%s\n%s\n", line[0], line[1], line[2], line[3]);*/
x1 = atof(strtok(line[2], ","));
y1 = atof(strtok(NULL, "\0"));
xvel = atof(strtok(line[3], ","));
yvel = atof(strtok(NULL, "\0"));
- /*for (int i = 0; i<sizeof(ln); i++) {
- if (ln[i] == '\n') {
- if(lines != 0) {
- chr2=chr;
- chr = i;
- strncpy(line[lines-1], &ln[chr2], )
- }
- chr = i;
- lines++;
- }
- if (ln[i] == '\0') {
- break;
- }
- }*/
- /*printf("x1: %i, y1: %i\nxvel: %07.06f, yvel: %07.06f\n", (int)a, (int)b, c, d);*/
u = match(keys, "KEY_W");
d = (match(keys, "KEY_S") && !match(keys, "KEY_(SHIFT|SLASH|SPACE|SEMICOLON)"));