diff src/console.c @ 32:96af12a50fdb

fix cbc_read
author mir3636
date Tue, 22 Jan 2019 15:48:35 +0900
parents 96a5833d0d82
children 7a63dacab7f8
line wrap: on
line diff
--- a/src/console.c	Fri Jan 18 18:20:02 2019 +0900
+++ b/src/console.c	Tue Jan 22 15:48:35 2019 +0900
@@ -12,8 +12,8 @@
 #include "mmu.h"
 #include "proc.h"
 
-__code cbc_consoleread1 (__code(*)(int));
-__code cbc_consoleread2 (__code(*)(int));
+__code cbc_consoleread1 ();
+__code cbc_consoleread2 ();
 
 static void consputc (int);
 
@@ -233,19 +233,10 @@
     release(&input.lock);
 }
 
-__code cbc_consoleread2 (__code(*next)(int ret))
+__code cbc_consoleread2 ()
 {
-    int n = proc->cbc_arg.cbc_console_arg.n;
-    int target = proc->cbc_arg.cbc_console_arg.target;
-    char* dst = proc->cbc_arg.cbc_console_arg.dst;
     struct inode *ip = proc->cbc_arg.cbc_console_arg.ip;
-    struct file *f = proc->cbc_arg.cbc_console_arg.f;
-    proc->cbc_arg.cbc_console_arg.n = n;
-    proc->cbc_arg.cbc_console_arg.target = target;
-    proc->cbc_arg.cbc_console_arg.dst = dst;
-    proc->cbc_arg.cbc_console_arg.ip = ip;
-    proc->cbc_arg.cbc_console_arg.f = f;
-    proc->cbc_arg.cbc_console_arg.next = next;
+    __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
     if (input.r == input.w) {
         if (proc->killed) {
             release(&input.lock);
@@ -254,10 +245,10 @@
         }
        goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
     }
-    goto cbc_consoleread1(0);
+    goto cbc_consoleread1();
 }
 
-__code cbc_consoleread1 (__code(*next)(int ret))
+__code cbc_consoleread1 ()
 {
     int cont = 1;
     int n = proc->cbc_arg.cbc_console_arg.n;
@@ -265,6 +256,7 @@
     char* dst = proc->cbc_arg.cbc_console_arg.dst;
     struct inode *ip = proc->cbc_arg.cbc_console_arg.ip;
     struct file *f = proc->cbc_arg.cbc_console_arg.f;
+    __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next;
     
     int c = input.buf[input.r++ % INPUT_BUF];
 
@@ -284,14 +276,16 @@
         cont = 0;
     }
 
-    if (n > 0) {
-        proc->cbc_arg.cbc_console_arg.n = n;
-        proc->cbc_arg.cbc_console_arg.target = target;
-        proc->cbc_arg.cbc_console_arg.dst = dst;
-        proc->cbc_arg.cbc_console_arg.ip = ip;
-        proc->cbc_arg.cbc_console_arg.f = f;
-        proc->cbc_arg.cbc_console_arg.next = next;
-        goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
+    if (cont == 1) {
+        if (n > 0) {
+            proc->cbc_arg.cbc_console_arg.n = n;
+            proc->cbc_arg.cbc_console_arg.target = target;
+            proc->cbc_arg.cbc_console_arg.dst = dst;
+            proc->cbc_arg.cbc_console_arg.ip = ip;
+            proc->cbc_arg.cbc_console_arg.f = f;
+            proc->cbc_arg.cbc_console_arg.next = next;
+            goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2);
+        }
     }
     
     release(&input.lock);
@@ -305,7 +299,7 @@
 
     //goto next(target - n);
 
-    goto cbc_ret(r);
+    goto next(r);
 }
 
 __code cbc_consoleread (struct inode *ip, char *dst, int n, struct file *f, __code(*next)(int ret))