Skip to content

Commit 845ab85

Browse files
committed
First cut at a Tsugi web site.
1 parent b86525e commit 845ab85

File tree

9 files changed

+277
-142
lines changed

9 files changed

+277
-142
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ a.out
44
.DS_Store
55
cc4e-private
66
jail
7+
tsugi
8+
mod/*
79

README.md

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
11

2-
C Programming for Everybody
3-
===========================
2+
This folder is used to checkout Tsugi tools from other repositories like:
43

5-
This is an emergent course with the learning objective of seeing how system software
6-
like Linux or Python is built. This course will cover either C or C++ and quickly work through
7-
the base features of the language and then using dynamic memory implement features similar to
8-
Python lists and dictionaries.
4+
https://github.com/tsugitools
95

10-
* Variables
11-
* Input / Output
12-
* Conditional operators
13-
* Functions
14-
* Files
15-
* Arrays
16-
* Strings
17-
* Objects/lstructures
18-
* Pointers
19-
* Linked lists
20-
* Hashing
21-
* Implementing lists and dictionaries
22-
23-
24-
Reference Materials
25-
------------------
26-
27-
Introduction to C++, LBS290. 1992.
28-
29-
Introduction to FORTRAN, LBS290. 1993.
30-
31-
Introduction to C++, EECS280. 2000.
6+
https://github.com/tsugicontrib/
327

book/index.php

+37
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function endsWith($haystack, $needle) {
2727
if ( ! $file || ! file_exists($file) ) $file = false;
2828
}
2929

30+
if ( $file == false ) $file = 'chap01.md';
31+
3032
if ( $file !== false ) {
3133
$contents = file_get_contents($file);
3234
$HTML_FILE = $file;
@@ -111,6 +113,7 @@ function myEdit(me) {
111113
</script>
112114
<div style="float:right">
113115
<select id="chapters" onchange="onSelect();">
116+
<option <?= x_sel("..") ?>>CC4E</option>
114117
<option <?= x_sel("about.md") ?>>About</option>
115118
<option <?= x_sel("chap00.md") ?>>Chapter 0</option>
116119
<option <?= x_sel("chap01.md") ?>>Chapter 1</option>
@@ -232,3 +235,37 @@ function myEdit(me) {
232235
</p>
233236
<?php
234237
}
238+
?>
239+
<hr/>
240+
<small>
241+
<blockquote>
242+
<p>
243+
This web site (www.cc4e.com) is based on the 1978
244+
<a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" target="_blank">"C Programming"</a>
245+
book written by Brian Kernighan and
246+
Dennis Ritchie. The book and the material this site used from the book
247+
is copyright all rights reserved by Prentice-Hall but is being used
248+
in this site under "fair use" because of the book's historical and scholarly significance
249+
and because it is not widely available in any form and in particular not
250+
available in any accessible form.
251+
</p>
252+
<p>
253+
The book is augmented in places to help understand its rightful place in a historical
254+
context amidst the major changes of the 1970's and 1980's as Computer Science evolved from a
255+
vendor-centered / hardware-focused aproach to a software-centered approach where
256+
portable operating systems and applications written in C could run on any hardware.
257+
</p>
258+
<p>
259+
This is not the ideal book to learn C programming. The 1978 edition does not reflect the modern
260+
C language - but that is the point of this effort - to take students back to 1978 and understand
261+
how the C language was evolving as it laid the ground work for a future with portable applications.
262+
</p>
263+
<p>
264+
If you want to learn modern C programming from a book that reflects the modern C language,
265+
I suggest you use the
266+
<a href="https://amzn.to/3hNp6QH" target="_blank">C Programming Language, 2nd Edition</a>,
267+
also written by Brian W. Kernighan and Dennis M. Ritchie, initialluy published in
268+
1988 and reflects the modern C language.
269+
</p>
270+
</blockquote>
271+
</small>

buildmenu.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
function buildMenu() {
4+
global $CFG;
5+
$R = $CFG->apphome . '/';
6+
$T = $CFG->wwwroot . '/';
7+
$adminmenu = isset($_COOKIE['adminmenu']) && $_COOKIE['adminmenu'] == "true";
8+
$set = new \Tsugi\UI\MenuSet();
9+
$set->setHome($CFG->servicename, $CFG->apphome);
10+
// $set->addLeft('Lessons', $R.'lessons');
11+
$set->addLeft('Write Code', $R.'play.php');
12+
$set->addLeft('Lectures', 'https://audio.cc4e.com');
13+
if ( isset($CFG->tdiscus) && $CFG->tdiscus ) $set->addLeft('Discussions', $R.'discussions');
14+
if ( isset($_SESSION['id']) ) {
15+
// $set->addLeft('Assignments', $R.'assignments');
16+
} else {
17+
// $set->addLeft('OER', $R.'materials');
18+
}
19+
20+
if ( isset($_SESSION['id']) ) {
21+
$submenu = new \Tsugi\UI\Menu();
22+
$submenu->addLink('Profile', $R.'profile');
23+
if ( isset($CFG->google_map_api_key) ) {
24+
$submenu->addLink('Map', $R.'map');
25+
}
26+
27+
$submenu->addLink('Badges', $R.'badges');
28+
$submenu->addLink('Materials', $R.'materials');
29+
if ( $CFG->providekeys ) {
30+
$submenu->addLink('LMS Integration', $T . 'settings');
31+
}
32+
if ( isset($CFG->google_classroom_secret) ) {
33+
$submenu->addLink('Google Classroom', $T.'gclass/login');
34+
}
35+
$submenu->addLink('Free App Store', 'https://www.tsugicloud.org');
36+
$submenu->addLink('Rate this course', 'https://www.class-central.com/mooc/7363/python-for-everybody');
37+
$submenu->addLink('Privacy', $R.'privacy');
38+
$submenu->addLink('Service Level', $R.'service');
39+
if ( isset($_COOKIE['adminmenu']) && $_COOKIE['adminmenu'] == "true" ) {
40+
$submenu->addLink('Administer', $T . 'admin/');
41+
}
42+
$submenu->addLink('Logout', $R.'logout');
43+
44+
if ( isset($_SESSION['avatar']) ) {
45+
$set->addRight('<img src="'.$_SESSION['avatar'].'" title="'.htmlentities(__('User Profile Menu - Includes logout')).'" style="height: 2em;"/>', $submenu);
46+
// htmlentities($_SESSION['displayname']), $submenu);
47+
} else {
48+
$set->addRight(htmlentities($_SESSION['displayname']), $submenu);
49+
}
50+
} else {
51+
$set->addRight('Login', $R.'login');
52+
}
53+
54+
$imenu = new \Tsugi\UI\Menu();
55+
56+
$imenu->addLink('Instructor', 'http://www.dr-chuck.com');
57+
$imenu->addLink('Office Hours', 'http://www.dr-chuck.com/office/');
58+
$set->addRight('Book', $R . 'book');
59+
$set->addRight('Instructor', $imenu);
60+
61+
return($set);
62+
}
63+

config.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
// Make this require relative to the parent of the current folder
4+
// http://stackoverflow.com/questions/24753758
5+
6+
require_once dirname(__DIR__)."/tsugi/config.php";

index.php

+37-114
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
if ( isset($_POST['secret']) && $_POST['secret'] == '42' ) {
33
setCookie('secret', '42', time() + 15 * 3600 * 24);
4+
header("Location: index.php");
45
} else if ( !isset($_COOKIE['secret']) || $_COOKIE['secret'] != '42' ) {
56
?>
67
<body style="font-family: Courier,monospace; width: 80%; max-width:500px;margin-left: auto; margin-right: auto;">
@@ -30,126 +31,48 @@
3031
return;
3132
}
3233

33-
$stdout = False;
34-
$stderr = False;
35-
$return_value = False;
34+
use \Tsugi\Core\LTIX;
35+
use \Tsugi\UI\Output;
3636

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>
9245
<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.
9449
</p>
9550
<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&amp;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.
12655
</p>
12756
<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.
13864
</p>
13965
<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>.
14470
</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();

nav.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require_once('buildmenu.php');
4+
5+
$OUTPUT->bodyStart();
6+
7+
$set = buildMenu();
8+
9+
// Set the topNav for the session
10+
$OUTPUT->topNavSession($set);
11+
12+
$OUTPUT->topNav();
13+
$OUTPUT->flashMessages();

0 commit comments

Comments
 (0)