up
authorMart Lubbers <mart@martlubbers.net>
Mon, 21 Nov 2016 18:26:17 +0000 (19:26 +0100)
committerMart Lubbers <mart@martlubbers.net>
Mon, 21 Nov 2016 18:26:17 +0000 (19:26 +0100)
int/int.c

index 2bf2cef..f3332f7 100644 (file)
--- a/int/int.c
+++ b/int/int.c
@@ -39,9 +39,8 @@ bool input_available(int fd){
        tv.tv_usec = 0;
        FD_ZERO(&fds);
        FD_SET(fd, &fds);
-       if(select(fd+1, &fds, NULL, NULL, &tv) == -1){
+       if (select(fd+1, &fds, NULL, NULL, &tv) == -1)
                pdie("select");
-       }
        return FD_ISSET(fd, &fds);
 }
 
@@ -86,58 +85,11 @@ void read_message(int fd_in, int fd_out)
 
 void run_task(char *program)
 {
-
-       (void) program;
-}
-
-int main(void)
-{
-       int fd_in, fd_out;
-       int ct;
-
-       fd_in = fileno(stdin);
-       fd_out = fileno(stdout);
-
-       //Register signal handler
-       if(signal(SIGINT, killHandler) == SIG_ERR){
-               die("Couldn't register signal handler...\n");
-       }
-       if(signal(SIGTERM, killHandler) == SIG_ERR){
-               die("Couldn't register signal handler...\n");
-       }
-
-       while(true){
-               //Check for new tasks
-               if(input_available(fd_in)){
-                       read_message(fd_in, fd_out);
-                       exit(1);
-               }
-               //Run tasks
-               for(ct = 0; ct<MAXTASKS; ct++){
-                       if(!tasks_used[ct]){
-                               debug("Task %d not implemented\n", ct);
-                               continue;
-                       }
-                       debug("Going to execute task %d\n", ct);
-                       run_task(tasks[ct]);
-               }
-               usleep(10);
-       }
-
-/*     //Read program
-       pc = 0;
-       while ((c = getchar()) != EOF && pc < PROGRAMSIZE)
-               program[pc++] = c;
-       if (pc >= PROGRAMSIZE)
-               die("Max program size: %d\n", PROGRAMSIZE);
-       pl = pc;
-       debug("Done reading, program length: %d\n", pl);
-
-       //Evaluate program
-       //Reset program counter and stack counter
-       pc = 0;
-       sp = 0;
-       while(pc != pl){
+       int pc = 0;
+       int sp = 0;
+       int plen = strlen(program);
+       char stack[1024] = {0};
+       while(pc != plen){
                switch(program[pc++]){
                case BCNOP:;
                        break;
@@ -230,6 +182,57 @@ int main(void)
                        die("Unrecognized command: %X\n", program[--pc]);
                }
        }
+}
+
+int main(void)
+{
+       int fd_in, fd_out;
+       int ct;
+
+       fd_in = fileno(stdin);
+       fd_out = fileno(stdout);
+
+       //Register signal handler
+       if(signal(SIGINT, killHandler) == SIG_ERR){
+               die("Couldn't register signal handler...\n");
+       }
+       if(signal(SIGTERM, killHandler) == SIG_ERR){
+               die("Couldn't register signal handler...\n");
+       }
+
+       while(true){
+               //Check for new tasks
+               if(input_available(fd_in)){
+                       read_message(fd_in, fd_out);
+                       exit(1);
+               }
+               //Run tasks
+               for(ct = 0; ct<MAXTASKS; ct++){
+                       if(!tasks_used[ct]){
+                               debug("Task %d not implemented\n", ct);
+                               continue;
+                       }
+                       debug("Going to execute task %d\n", ct);
+                       run_task(tasks[ct]);
+               }
+               usleep(10);
+       }
+
+/*     //Read program
+       pc = 0;
+       while ((c = getchar()) != EOF && pc < PROGRAMSIZE)
+               program[pc++] = c;
+       if (pc >= PROGRAMSIZE)
+               die("Max program size: %d\n", PROGRAMSIZE);
+       pl = pc;
+       debug("Done reading, program length: %d\n", pl);
+
+       //Evaluate program
+       //Reset program counter and stack counter
+       pc = 0;
+       sp = 0;
+       while(pc != pl){
+       }
 */
        return 0;
 }