From 66cbe9b2ca111c730ccbeecfd0d1fe8c2ef78b90 Mon Sep 17 00:00:00 2001 From: Xaver K Date: Thu, 25 Feb 2021 12:50:14 +0100 Subject: [PATCH] Set bufferedOutput=True since that is the usual command line behaviour. Updated README. --- README.md | 29 +++++++++++++++++++++-------- jupyter_c_kernel/kernel.py | 7 +++++-- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 47912c6..e7a3d06 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,25 @@ -# Minimal C kernel for Jupyter +# C kernel for Jupyter + +This project was forked from [https://github.com/brendan-rius/jupyter-c-kernel](brendan-rius/jupyter-c-kernel) as that project seems to have been abandoned. (PR is pending) + +This project includes fixes to many issues reported in [https://github.com/brendan-rius/jupyter-c-kernel](brendan-rius/jupyter-c-kernel), as well as the following additional features: + +* Option for buffered output to mimic command line behaviour (useful for teaching, default is on) +* Command line input via `scanf` and `getchar` +* Support for `C89`/`ANSI C` (all newer versions were already supported and still are) + +Following limitations compared to command line execution exist: + +* Input is always buffered due to limitations of the jupyter interface +* When using `-ansi` or `-std=C89`, glibc still has to support at least `C99` for the interfacing with jupyter (this should not be an issue on an OS made after 2000) ## Use with Docker (recommended) - * `docker pull xaverklemenschits/jupyter-c-kernel` - * `docker run -p 8888:8888 xaverklemenschits/jupyter-c-kernel` - * Copy the given URL containing the token, and browse to it. For instance: +* `docker pull xaverklemenschits/jupyter-c-kernel` +* `docker run -p 8888:8888 xaverklemenschits/jupyter-c-kernel` +* Copy the given URL containing the token, and browse to it. For instance: - ``` + ```bash Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://localhost:8888/?token=66750c80bd0788f6ba15760aadz53beb9a9fb4cf8ac15ce8 @@ -16,14 +29,14 @@ Works only on Linux and OS X. Windows is not supported yet. If you want to use this project on Windows, please use Docker. - - * Make sure you have the following requirements installed: +* Make sure you have the following requirements installed: * gcc * jupyter * python 3 * pip -### Step-by-step: +### Step-by-step + ```bash git clone https://github.com/XaverKlemenschits/jupyter-c-kernel.git cd jupyter-c-kernel diff --git a/jupyter_c_kernel/kernel.py b/jupyter_c_kernel/kernel.py index 44d3095..59162d7 100644 --- a/jupyter_c_kernel/kernel.py +++ b/jupyter_c_kernel/kernel.py @@ -106,7 +106,7 @@ class CKernel(Kernel): super(CKernel, self).__init__(*args, **kwargs) self._allow_stdin = True self.readOnlyFileSystem = False - self.bufferedOutput = False + self.bufferedOutput = True self.linkMaths = True # always link math library self.wAll = True # show all warnings by default self.wError = False # but keep comipiling for warnings @@ -191,7 +191,10 @@ class CKernel(Kernel): for argument in re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', value): magics['args'] += [argument.strip('"')] - # only keep lines which did not contain magics + # always add empty line, so line numbers don't change + actualCode += '\n' + + # keep lines which did not contain magics else: actualCode += line + '\n'