add 2012 generalstatics.com site

This commit is contained in:
Neale Pickett 2012-06-27 13:46:32 -06:00
parent d18ad8238f
commit febb10e92f
9 changed files with 665 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

View File

@ -0,0 +1,241 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include "cgi.h"
#ifdef NODUMP
# define DUMPf(fmt, args...)
#else
# define DUMPf(fmt, args...) fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, ##args)
#endif
#define DUMP() DUMPf("")
#define DUMP_d(v) DUMPf("%s = %d", #v, v)
#define DUMP_x(v) DUMPf("%s = 0x%x", #v, v)
#define DUMP_s(v) DUMPf("%s = %s", #v, v)
#define DUMP_c(v) DUMPf("%s = '%c' (0x%02x)", #v, v, v)
#define DUMP_p(v) DUMPf("%s = %p", #v, v)
#define POST_MAX 1024
/*
* CGI
*/
static int is_cgi = 0;
static char **argv = NULL;
static int
read_char_argv()
{
static int arg = 0;
static char *p;
if (NULL == argv) {
return EOF;
}
if (0 == arg) {
arg = 1;
p = argv[1];
}
if (! p) {
return EOF;
} else if (! *p) {
arg += 1;
p = argv[arg];
return '&';
}
return *(p++);
}
static int
read_char_stdin()
{
static int inlen = -1;
if (-1 == inlen) {
char *p = getenv("CONTENT_LENGTH");
if (p) {
inlen = atoi(p);
if (inlen > POST_MAX) {
inlen = POST_MAX;
}
if (inlen < 0) {
inlen = 0;
}
} else {
inlen = 0;
}
}
if (inlen) {
inlen -= 1;
return getchar();
}
return EOF;
}
static int
read_char_query_string()
{
static char *p = (char *)-1;
if ((char *)-1 == p) {
p = getenv("QUERY_STRING");
}
if (! p) {
return EOF;
} else if (! *p) {
return EOF;
} else {
return *(p++);
}
}
static int (* read_char)() = read_char_argv;
int
cgi_init(char *global_argv[])
{
char *rm = getenv("REQUEST_METHOD");
if (! rm) {
read_char = read_char_argv;
argv = global_argv;
} else if (0 == strcmp(rm, "POST")) {
read_char = read_char_stdin;
is_cgi = 1;
} else if (0 == strcmp(rm, "GET")) {
read_char = read_char_query_string;
is_cgi = 1;
} else {
printf(("405 Method not allowed\r\n"
"Allow: GET, POST\r\n"
"Content-type: text/plain\r\n"
"\r\n"
"%s is not allowed.\n"),
rm);
return -1;
}
return 0;
}
static char
tonum(int c)
{
if ((c >= '0') && (c <= '9')) {
return c - '0';
}
if ((c >= 'a') && (c <= 'f')) {
return 10 + c - 'a';
}
if ((c >= 'A') && (c <= 'F')) {
return 10 + c - 'A';
}
return 0;
}
static char
read_hex()
{
int a = read_char();
int b = read_char();
return tonum(a)*16 + tonum(b);
}
/* Read a key or a value. Since & and = aren't supposed to appear
outside of boundaries, we can use the same function for both.
*/
size_t
cgi_item(char *str, size_t maxlen)
{
int c;
size_t pos = 0;
while (1) {
c = read_char();
switch (c) {
case EOF:
case '=':
case '&':
str[pos] = '\0';
return pos;
case '%':
c = read_hex();
break;
case '+':
c = ' ';
break;
}
if (pos < maxlen - 1) {
str[pos] = c;
pos += 1;
}
}
}
void
cgi_head(char *title)
{
if (is_cgi) {
printf("Content-type: text/html\r\n\r\n");
}
printf(("<!DOCTYPE html>\n"
"<html>\n"
" <head>\n"
" <title>%s</title>\n"
" </head>\n"
" <body>\n"
" <h1>%s</h1>\n"),
title, title);
}
void
cgi_foot()
{
printf("\n"
" </body>\n"
"</html>\n");
}
void
cgi_result(int code, char *desc, char *fmt, ...)
{
va_list ap;
if (is_cgi) {
printf("%d %s\r\n", code, desc);
}
cgi_head(desc);
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
cgi_foot();
exit(0);
}
void
cgi_page(char *title, char *fmt, ...)
{
va_list ap;
cgi_head(title);
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
cgi_foot();
exit(0);
}
void
cgi_error(char *text)
{
cgi_result(500, "Internal error", "<p>%s</p>", text);
}

View File

@ -0,0 +1,14 @@
#ifndef __CGI_H_
#define __CGI_H_
#include <stddef.h>
int cgi_init(char *global_argv[]);
size_t cgi_item(char *str, size_t maxlen);
void cgi_head(char *title);
void cgi_foot();
void cgi_result(int code, char *desc, char *fmt, ...);
void cgi_page(char *title, char *fmt, ...);
void cgi_error(char *text);
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -0,0 +1,212 @@
<!DOCTYPE html>
<html>
<head>
<title>General Statics</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<style type="text/css">
html {
background: url("bg.jpg");
}
body {
background: black url("p2.png") no-repeat top center;
background-size: contain;
color: magenta;
max-width: 44em;
margin: auto;
padding: 2em;
}
h1 {
background: silver url("data.png") no-repeat top center;
background-size: 100% 100%;
color: green;
}
.hidden {
font-size: small;
opacity: 0.1;
herring: #f00;
}
table#game {
float: right;
border-collapse: collapse;
text-align: center;
background: #400;
color: white;
margin: 2em;
}
table#game td {
border: solid 5px white;
width: 3em;
height: 3em;
}
table#game tr:first-child td {
border-top: 0;
}
table#game tr:last-child td {
border-bottom: 0;
}
table#game tr td:first-child {
border-left: 0;
}
table#game tr td:last-child {
border-right: 0;
}
#login {
position: absolute;
bottom: 10px;
}
</style>
<script type="text/javascript">
var pending = false;
var aleph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@";
var board = [[0,0,0],[0,0,0],[0,0,0]];
function clicky(y, x) {
var td = document.getElementById("t" + y + x);
if (pending) {
return;
}
if (board[y][x] > 0) {
return;
}
board[y][x] = 1;
// Build up state
var b = "";
for (var y = 0; y < 3; y += 1) {
var acc = 0;
for (var x = 0; x < 3; x += 1) {
acc <<= 2;
acc += board[y][x];
}
b += aleph.charAt(acc);
}
var request = new XMLHttpRequest();
request.open("POST", "/ttt.cgi", false);
request.send("b=" + b);
if (request.status == 200) {
var rt = request.responseText;
if (rt.length == 3) {
for (var y = 0; y < 3; y += 1) {
var acc = aleph.indexOf(rt[y]);
for (var x = 2; x >= 0; x -= 1) {
board[y][x] = acc & 3;
acc >>= 2;
}
}
} else {
alert(rt);
}
}
update();
}
function update() {
var be = document.getElementById("board");
for (var y = 0; y < 3; y += 1) {
for (var x = 0; x < 3; x += 1) {
var e = document.getElementById("t" + y + x);
if (board[y][x] == 1) {
e.innerHTML = "X";
} else if (board[y][x] == 2) {
e.innerHTML = "O";
} else {
e.innerHTML = "";
}
}
}
}
var c = unescape("vlkkrolv.zhk%7D%7F%60msou%3Aao%7F%7Cq%7B%7Bu%3Amk%7Fj%7Ctzp%7Bb9ux%7Chfxob9y%7C%7C%7Ekwngxv");
function u() {
var o = document.getElementById("output");
var i = document.getElementById("input").value.split("-");
var k = i[0];
var r = parseInt(i[1] || 0);
var s = [];
for (i = 0; i < c.length; i += 1) {
s.push(c.charCodeAt(i) ^ k.charCodeAt(i%3) ^ r);
}
console.log(escape(String.fromCharCode.apply(0, s)));
o.innerHTML = String.fromCharCode.apply(0, s);
//o.innerHTML = s.join(" ");
}
window.onload = update;
</script>
</head>
<body>
<h1>General Statics</h1>
<p>
General Statics is pleased to announce our shift into the casual gaming
market. Please try our new flagship product: Tic-Tac-Toe Extreme!
</p>
<table id="game">
<tr><td id="t00" onclick="clicky(0, 0)"></td><td id="t01" onclick="clicky(0, 1)"></td><td id="t02" onclick="clicky(0, 2)"></td></tr>
<tr><td id="t10" onclick="clicky(1, 0)"></td><td id="t11" onclick="clicky(1, 1)"></td><td id="t12" onclick="clicky(1, 2)"></td></tr>
<tr><td id="t20" onclick="clicky(2, 0)"></td><td id="t21" onclick="clicky(2, 1)"></td><td id="t22" onclick="clicky(2, 2)"></td></tr>
<caption>You play X. Reload this page to start over.</caption>
</table>
<p id="output">
This strategic shift will bring our company back to the forefront
of revenue-generating companies.
</p>
<h2>About Us</h2>
<p>
Most strategic planning involves thinking and talking
about the future. Crafting and executing strategy requires
actually making decisions and acting on the future. And doing
so in an “expeditionary” manner that enables continuous
change, flexibility, and adaptability.
</p>
<p>
General Statics continuously delivers value through leveraging technology to
change behaviors, processes and practices. In the Knowledge Economy, many
of the most decisive sources of value are intangible. We
help our clients to optimize both tangible and intangible
<!-- 8↙4↙3↓9↘3↙4↙6↓3↘3↓7↓7↙13↙4↙5↙3↓8↘7↙ -->
value. We deploy and leverage new technologies to change the
dynamics of organizational processes, relationships, and
interactions with customers, clients, partners, members, and
other stakeholders. This drives enhanced performance, reduces
costs, and enables enterprises to improve their competitive
advantage.
</p>
<p>
Knowledge Age enterprises must realign their strategies,
processes and practices to the post-recession Economy.
New generations of measurement and analytics tools are
making it possible for enterprises to pursue new
strategies that lead them to higher planes of nimble
performance.
</p>
<p id="login">
Employee access:
<input id="input" onchange="u();">
<audio autoplay="go" loop="yeah" src="msg.ogg">
</p>
</body>
</html>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@ -0,0 +1,198 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cgi.h"
const char *b64_aleph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@";
typedef int board_t[3][3];
void
b64_of_board(char *out, board_t board)
{
int y, x;
for (y = 0; y < 3; y += 1) {
int acc = 0;
for (x = 0; x < 3; x += 1) {
acc <<= 2;
acc += board[y][x];
}
out[y] = b64_aleph[acc];
}
}
void
board_of_b64(board_t out, char *b64)
{
int y, x;
for (y = 0; y < 3; y += 1) {
char *p = strchr(b64_aleph, b64[y]);
int acc = 0;
if (p) {
acc = p - b64_aleph;
}
for (x = 2; x >= 0; x -= 1) {
out[y][x] = acc & 3;
acc >>= 2;
}
}
}
void
print_board(board_t board)
{
int y, x;
for (y = 0; y < 3; y += 1) {
for (x = 0; x < 3; x += 1) {
printf("%d", board[y][x]);
}
printf("\n");
}
}
int
winner(board_t board)
{
int i, j, k;
for (i = 0; i < 3; i += 1) {
for (k = 0; k < 3; k += 1) {
int winner = -1;
for (j = 0; j < 3; j += 1) {
int b;
switch (k) {
case 0:
b = board[i][j];
break;
case 1:
b = board[j][i];
break;
case 2:
/* This will happen 3× as often as it needs to. Who cares. */
b = board[j][j];
break;
}
if (winner == -1) {
winner = b;
} else if (winner != b) {
winner = -1;
break;
}
}
if (winner > 0) {
return winner;
}
}
}
return 0;
}
void
claim(board_t board, int x, int y, int whom)
{
int prev = board[x][y];
int i;
if (prev == whom) {
return;
}
for (i = 0; i < 9; i += 1) {
if (! board[i/3][i%3]) {
board[i/3][i%3] = prev;
break;
}
}
board[x][y] = whom;
}
void
make_move(board_t board)
{
switch (winner(board)) {
case 1:
printf("A WINNER IS YOU\n");
exit(0);
case 2:
/* I win; we can keep playing though, because I (neale)
don't want to write any more code to handle this. */
break;
case 3:
printf("A WINNER IS WHO?\n");
exit(1);
}
/* Reserve our final space */
claim(board, 2, 2, 0);
/* First move */
if (board[1][1] != 2) {
claim(board, 1, 1, 2);
return;
}
/* Second move */
if (board[0][0] != 2) {
/* Prevent them from winning legally */
if (board[0][2]) {
claim(board, 1, 2, 0);
}
if (board[2][0]) {
claim(board, 2, 1, 0);
}
claim(board, 0, 0, 2);
return;
}
/* Third move */
claim(board, 2, 2, 2);
}
int
main(int argc, char *argv[])
{
char b64[4] = {0};
board_t board = {0};
if (-1 == cgi_init(argv)) {
return 0;
}
while (1) {
size_t len;
char key[20];
len = cgi_item(key, sizeof key);
if (0 == len) break;
switch (key[0]) {
case 'b':
cgi_item(b64, sizeof b64);
break;
default:
cgi_item(key, 0);
break;
}
}
printf("Content-type: text/plain\r\n\r\n");
board_of_b64(board, b64);
make_move(board);
b64_of_board(b64, board);
fwrite(b64, 1, 3, stdout);
return 0;
}