spaces.cameron.stream/hello
Hello.
0
1
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "fate.h"
#include "letter.h"
#include "town.h"
#include "weather.h"
/* A word the letter says is picked by the line's seed, on the day it is
* written, by the question number of the pick. Two lines writing on the same
* day pick differently; one line writing on two days picks differently too. */
struct voice {
uint64_t seed;
long when;
int question;
};
static unsigned pick(struct voice *v, unsigned sides)
{
return fate(v->seed, v->when, v->question++, sides);
}
static void say(char *out, size_t size, const char *fmt, ...)
{
size_t room = strlen(out);
if (room >= size)
return;
va_list args;
va_start(args, fmt);
vsnprintf(out + room, size - room, fmt, args);
va_end(args);
}
static void lower_weather(char *text)
{
for (char *at = text; *at; at++)
*at = (char)tolower((unsigned char)*at);
}
static void resident(const struct household *h, struct day day, struct voice *v, char *out, size_t size)
{
static const char *const openings[] = {
"Dear World,",
"World,",
"To the World,",
"Sir or Madam of the World,",
};
static const char *const tidings[] = {
"The line keeps the house at %s and means to go on doing so.",
"We are all well here at %s, as well as can be expected.",
"The house at %s stands, and we in it.",
"Life at %s goes on much as it went last month.",
};
static const char *const bells[] = {
"The church was right again this morning. It is always right.",
"The bell told us the time, and the bell does not lie.",
"I set my clock by the church, as my people have always done with it.",
};
static const char *const wonders[] = {
"Is it true that you can see the sea from the top of the world?",
"Do you keep any plums this year? Ours failed here.",
"Do you know the whereabouts of summer, or where it went?",
"What do you do, all day, with all that world?",
"Is anyone else writing to you, or is it only us?",
};
static const char *const silence =
"You have never written back. We have decided we do not mind.";
static const char *const signs[] = {
"Yours,",
"Yours faithfully,",
"Your obedient servant,",
"Yours, in hope of a reply,",
};
char sky[FIELD];
snprintf(sky, sizeof sky, "%s", weather(day));
lower_weather(sky);
say(out, size, "%s\n\n", openings[pick(v, 4)]);
say(out, size, "It was %s that morning. ", sky);
say(out, size, "It took me %d minutes to write this, and I am slower with the pen than I was. ", h->writes);
say(out, size, tidings[pick(v, 4)], h->home);
say(out, size, "\n\n");
if (pick(v, 3) == 0)
say(out, size, "%s\n\n", bells[pick(v, 3)]);
if (pick(v, 4) != 0)
say(out, size, "%s\n\n", wonders[pick(v, 5)]);
if (pick(v, 3) == 0)
say(out, size, "%s\n\n", silence);
say(out, size, "%s\n", signs[pick(v, 4)]);
/* The dead letter office knows us by this. So do we, by now.
* North of the river they sign it large, as they write everything. */
char signature[FIELD];
snprintf(signature, sizeof signature, "%s", h->name);
if (north(h->home))
for (char *at = signature; *at; at++)
*at = (char)toupper((unsigned char)*at);
say(out, size, "%s\n", signature);
}
static void institution(const struct household *h, struct day day, struct voice *v, char *out, size_t size)
{
char sky[FIELD];
snprintf(sky, sizeof sky, "%s", weather(day));
lower_weather(sky);
if (strcmp(h->name, "School") == 0) {
static const char *const reports[] = {
"The School sends its regards to the World. Form the lowest are learning their letters this month, and most of them hold the pen correctly, and a few of them do not.",
"The School sends its report. The children wrote to you last month, as they do; they are told the World does not answer, and they are told nonetheless to write well.",
};
say(out, size, "World,\n\n");
say(out, size, "%s\n\n", reports[pick(v, 2)]);
say(out, size, "It was %s that morning, and the register shows every child present. ", sky);
say(out, size, "The children north of the river are taught to write their initial large, as their parents do. The others are not. It is the way of the town.\n\n");
say(out, size, "Yours, in the name of the pupils,\n");
say(out, size, "The School\n");
return;
}
if (strcmp(h->name, "Church") == 0) {
/* The same letter every first of the month since the founding, word
* for word, in 1900 as in 2200. The church does not know it is 2026.
* The bell does not explain itself, and neither does the church.
* The whole letter contains one comma. The office knows it by heart. */
(void)sky;
/* One comma in the whole letter. The salutation does not take one. */
say(out, size,
"World\n\n"
"The bell was rung this morning as it is rung every morning so that the town may know the hour. "
"It does not ask whether the town is listening. It does not explain what the hour is for. "
"It sets the hour down in its place and leaves it there.\n\n"
"The bell is not addressed to you. Neither is this letter. But the office reads everything and so it may as well have this. "
"It is all the bell has to say to the world on the first of every month since the founding and it is the same word for word now and in 2200 without adding to it or taking from it\n\n"
",\n"
"The Church\n");
return;
}
if (strcmp(h->name, "Fire Station") == 0) {
static const char *const notices[] = {
"The Fire Station reports no fires this month. The chimneys of the town have been seen to, and the van is kept ready.",
"Notice of the Fire Station to the World. There have been no fires to speak of. There is always next month.",
};
say(out, size, "World,\n\n");
say(out, size, "%s\n\n", notices[pick(v, 2)]);
say(out, size, "It was %s that morning. The engines are ready. We are not permitted to read our post while on shift, and this is the last of what we know.\n\n", sky);
say(out, size, "Yours, at the double,\n");
say(out, size, "The Fire Station!\n");
return;
}
/* An institution no one has thought to station here yet. */
say(out, size, "World,\n\nIt was %s that morning.\n\nYours,\n%s\n", sky, h->name);
}
void letter_text(const struct household *h, struct day day, char *out, size_t size)
{
struct voice v = { h->seed, day_number(day), 0 };
out[0] = '\0';
if (h->kind == RESIDENT)
resident(h, day, &v, out, size);
else
institution(h, day, &v, out, size);
}