-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
123 lines (99 loc) · 2.44 KB
/
main.c
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
// Copyright (c) 2015, Sam Silberstein. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License").
// Author: [email protected]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include "sim.h"
int main(int ac, char **av)
{
int pfd1[2], pfd2[2], status;
char *av0 = *(av++); ac--;
struct ami_machine *m = create_ami_machine();
m->opt_graphical = 1;
m->reg_count = 1;
m->opt_printstack = -1;
if (ac <= 0) {
printf("Usage: ./sim {FLAGS} FILENAME\n");
exit(1);
} else {
if (ac > 1) {
char *flag;
for (ac; ac > 1; ac--) {
flag = *(av++);
if (flag[0] == '-')
flag++;
if (!strcmp(flag, "t")) {
m->opt_graphical = 0;
}
}
}
}
m->filename = strdup(*av);
printf("Filename: %s\n", m->filename);
allocate_stack(m);
if (m->opt_graphical == 1) {
/*if(pipe(pfd1) == -1 || pipe(pfd2) == -1) {
printf("Could not open pipe\n");
exit(1);
}
#define CHILDREAD pfd2[0]
#define CHILDWRITE pfd1[1]
#define PARENTREAD pfd1[0]
#define PARENTWRITE pfd2[1]
m->childread = CHILDREAD;
m->childwrite = CHILDWRITE;
m->parentread = PARENTREAD;
m->parentwrite = PARENTWRITE;*/
//mkfifo("ptc", 0755);
//mkfifo("ctp", 0755);
int shmid;
key_t key = 1234;
char *shm;
if ((shmid = shmget(key, 256, IPC_CREAT | 0666)) < 0) {
perror("Could not initialize GUI\n");
exit(1);
}
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
perror("Could not initialize GUI\n");
exit(1);
}
*shm = '\0';
status = fork();
if (status == 0) {
/* dup2(CHILDREAD, 0);
dup2(CHILDWRITE, 1);
close(PARENTREAD);
close(PARENTWRITE);*/
system("perl gui.pl 1234");
} else {
/* // dup2(PARENTREAD, 0);
//dup2(PARENTWRITE, 1);
close(CHILDREAD);
close(CHILDWRITE);
*/
/*
it is extremely important that the order of these two opens
stay the same or the program will hang forever while
each side waits for the other
*/
/* FILE *in = fopen("ptc", "r");
m->ptc = in;
FILE *out = fopen("ctp", "w");
m->ctp = out;*/
m->shm = shm;
interactive_debug(m);
shmdt(shm);
//fclose(in);
//fclose(out);
//unlink("ptc");
//unlink("ctp");
}
} else {
interactive_debug(m);
}
return 0;
}