|
1 | 1 | <?php
|
2 | 2 | if ( isset($_POST['secret']) && $_POST['secret'] == '42' ) {
|
3 | 3 | setCookie('secret', '42', time() + 15 * 3600 * 24);
|
| 4 | + header("Location: index.php"); |
4 | 5 | } else if ( !isset($_COOKIE['secret']) || $_COOKIE['secret'] != '42' ) {
|
5 | 6 | ?>
|
6 | 7 | <body style="font-family: Courier,monospace; width: 80%; max-width:500px;margin-left: auto; margin-right: auto;">
|
|
30 | 31 | return;
|
31 | 32 | }
|
32 | 33 |
|
33 |
| -$stdout = False; |
34 |
| -$stderr = False; |
35 |
| -$return_value = False; |
| 34 | +use \Tsugi\Core\LTIX; |
| 35 | +use \Tsugi\UI\Output; |
36 | 36 |
|
37 |
| -if ( isset($_POST['code']) ) { |
38 |
| -$descriptorspec = array( |
39 |
| - 0 => array("pipe", "r"), // stdin is a pipe that the child will read from |
40 |
| - 1 => array("pipe", "w"), // stdout is a pipe that the child will write to |
41 |
| - 2 => array("pipe", "w") // stderr is a file to write to |
42 |
| -); |
43 |
| - |
44 |
| -$cwd = '/tmp'; |
45 |
| -$env = array( |
46 |
| - 'some_option' => 'aeiou', |
47 |
| - 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', |
48 |
| -); |
49 |
| - |
50 |
| -$process = proc_open('gcc -ansi -x c -c -', $descriptorspec, $pipes, $cwd, $env); |
51 |
| - |
52 |
| -if (is_resource($process)) { |
53 |
| - // $pipes now looks like this: |
54 |
| - // 0 => writeable handle connected to child stdin |
55 |
| - // 1 => readable handle connected to child stdout |
56 |
| - // Any error output will be appended to /tmp/error-output.txt |
57 |
| - |
58 |
| - fwrite($pipes[0], $_POST['code']); |
59 |
| - fclose($pipes[0]); |
60 |
| - |
61 |
| - $stdout = stream_get_contents($pipes[1]); |
62 |
| - fclose($pipes[1]); |
63 |
| - $stderr = stream_get_contents($pipes[2]); |
64 |
| - fclose($pipes[2]); |
65 |
| - |
66 |
| - // It is important that you close any pipes before calling |
67 |
| - // proc_close in order to avoid a deadlock |
68 |
| - $return_value = proc_close($process); |
69 |
| - |
70 |
| -} |
71 |
| -} |
72 |
| - |
73 |
| -?><html> |
74 |
| -<head> |
75 |
| -<link href="static/codemirror-5.62.0/lib/codemirror.css" rel="stylesheet"/> |
76 |
| -<style> |
77 |
| -body { |
78 |
| - font-family: Courier, monospace; |
79 |
| -} |
80 |
| -</style> |
81 |
| -</head> |
82 |
| -<body> |
83 |
| -<h1>C Programming for Everybody (CC4E)</h1> |
84 |
| -<p> |
85 |
| -This web site will teach C programming and Computer Architecture using the 1978 |
86 |
| -<a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" target="_blank"> |
87 |
| -C Programming</a> book by |
88 |
| -<a href="https://en.wikipedia.org/wiki/Brian_Kernighan" title="Brian Kernighan">Brian Kernighan</a> |
89 |
| -and |
90 |
| -<a href="https://en.wikipedia.org/wiki/Dennis_Ritchie" title="Dennis Ritchie">Dennis Ritchie</a>. |
91 |
| -</p> |
| 37 | +require_once "top.php"; |
| 38 | +require_once "nav.php"; |
| 39 | +?> |
| 40 | +<div id="container"> |
| 41 | +<div style="margin-left: 10px; float:right"> |
| 42 | +<iframe width="400" height="225" src="https://www.youtube.com/embed/sQwkC5PBTfk?rel=0" frameborder="0" allowfullscreen></iframe> |
| 43 | +</div> |
| 44 | +<h1>C Programming for Everybody</h1> |
92 | 45 | <p>
|
93 |
| -You can write and compile some C code below. |
| 46 | +This web site is dedicated to understanding computer architecture and low-level programming |
| 47 | +by studying the "classic" version of |
| 48 | +the C Programming language from the 1978 book written by Brian Kernighan and Dennis Ritchie. |
94 | 49 | </p>
|
95 | 50 | <p>
|
96 |
| -<?php |
97 |
| -if ( $return_value !== False ) { |
98 |
| - if ( $return_value === 0 ) { |
99 |
| - echo('<p style="color:green;">Your code compiled successfully. </p>'."\n"); |
100 |
| - } else { |
101 |
| - echo('<pre style="color:white; background-color:black;">'."\n"); |
102 |
| - echo("$ gcc -ansi hello.c\n"); |
103 |
| - if ( strlen($stdout) > 0 ) echo(htmlentities($stdout)); |
104 |
| - if ( strlen($stderr) > 0 ) echo(htmlentities($stderr)); |
105 |
| - echo("\n</pre>\n"); |
106 |
| - } |
107 |
| -} |
108 |
| -?> |
109 |
| -<form method="post"> |
110 |
| -<textarea id="mycode" name="code" style="border: 1px black solid;"> |
111 |
| -<?php |
112 |
| -if ( isset($_POST['code']) ) { |
113 |
| - echo(htmlentities($_POST['code'])); |
114 |
| -} else { |
115 |
| -?> |
116 |
| -#include <stdio.h> |
117 |
| - |
118 |
| -main() { |
119 |
| - printf("Hello World\n"); |
120 |
| -} |
121 |
| -<?php } ?> |
122 |
| -</textarea> |
123 |
| -<input type="submit" value="Compile"> |
124 |
| -</form> |
125 |
| -Executing code needs more security and is coming soon. |
| 51 | +The K&R book places the reader in the middle of the 1970's transition from |
| 52 | +a hardware-centered computer science to a focus on writing portable and efficient |
| 53 | +software. C was used to develop operating systems like Unix, Minix, and Linux and |
| 54 | +progamming languages like Java, JavaScript, and Python. |
126 | 55 | </p>
|
127 | 56 | <p>
|
128 |
| -This book is the foundation of all modern computing and advanced the notion that one programming language |
129 |
| -could be used to develop high performance systems-level code that was portable across multiple |
130 |
| -computer architectures. In a sense it is like a |
131 |
| -<a href="https://en.wikipedia.org/wiki/Rosetta_Stone" target="_blank">Rosetta Stone</a> |
132 |
| -that connects the early hardware-centered phase of computing |
133 |
| -with today's software-centered phase of computing. |
134 |
| -Since the book for this course is out of print, otherwise unavailable, not available in an accessable format, |
135 |
| -and being presented in a historical context, we are providing a copy to |
136 |
| -be used in conjunction with this course under |
137 |
| -<a href="https://en.wikipedia.org/wiki/Fair_use" target="_blank">Fair Use</a>. |
| 57 | +This site uses <a href="http://www.tsugi.org" target="_blank">Tsugi</a> |
| 58 | +framework to embed a learning management system into this site and |
| 59 | +provide the autograders. |
| 60 | +If you are interested in collaborating |
| 61 | +to build these kinds of sites for yourself, please see the |
| 62 | +<a href="http://www.tsugi.org" target="_blank">tsugi.org</a> website and/or |
| 63 | +contact me. |
138 | 64 | </p>
|
139 | 65 | <p>
|
140 |
| -Here is our copy of the |
141 |
| -<a href="book/chap01.md">book in progress</a> for your use in this course. |
142 |
| -You can help us recover and present this historically important book in |
143 |
| -<a href="https://github.com/csev/cc4e/" target="_blank">Github</a>. |
| 66 | +And yes, Dr. Chuck actually has a race car - it is called the |
| 67 | +<a href="https://www.sakaiger.com/sakaicar/" target=_blank">SakaiCar</a>. |
| 68 | +He races in a series called |
| 69 | +<a href="https://www.24hoursoflemons.com" target="_blank">24 Hours of Lemons</a>. |
144 | 70 | </p>
|
145 |
| -<script type="text/javascript" src="static/codemirror-5.62.0/lib/codemirror.js"></script> |
146 |
| -<script type="text/javascript" src="static/codemirror-5.62.0/mode/clike/clike.js"></script> |
147 |
| -<script> |
148 |
| - var myTextarea = document.getElementById("mycode"); |
149 |
| - var editor = CodeMirror.fromTextArea(myTextarea, { |
150 |
| - lineNumbers: true, |
151 |
| - matchBrackets: true, |
152 |
| - mode: "text/x-csrc" |
153 |
| - }); |
154 |
| -</script> |
155 |
| -</body> |
| 71 | +<!-- |
| 72 | +<?php |
| 73 | +echo(Output::safe_var_dump($_SESSION)); |
| 74 | +var_dump($USER); |
| 75 | +?> |
| 76 | +--> |
| 77 | +</div> |
| 78 | +<?php $OUTPUT->footer(); |
0 commit comments