spaces.cameron.stream/hello
Hello.
0
1
/* The letters addressed to the World, as the dead letter office opens them.
*
* letters [YYYY-MM-DD]
*
* Every letter posted on the day, in the order the office opens them:
* vans are unloaded in the order they come back, the last letter into a
* box is on top of its bag. Nobody has an address for the World. The
* office reads them anyway, because reading them is the job, and because
* somebody must. The first letters of the signatures, in this order, say
* what the town has been saying to the World all along. */
#include <stdio.h>
#include <string.h>
#include "census.h"
#include "greeting.h"
#include "letter.h"
#include "post.h"
#include "town.h"
static void hhmm(int minutes)
{
printf("%02d:%02d", minutes / 60, minutes % 60);
}
static const struct household *find(const struct town *town, const char *name)
{
for (int i = 0; i < town->lines; i++)
if (strcmp(town->line[i].name, name) == 0)
return &town->line[i];
return NULL;
}
int main(int argc, char **argv)
{
struct day day = census_day();
if (argc > 1)
day = parse_day(argv[1]);
if (argc > 2) {
fprintf(stderr, "letters [YYYY-MM-DD]\n");
return 1;
}
const struct town *town = town_on(day);
struct letter post[MAX_SENDERS];
int n = letters_from(town, day, post);
printf("# The post for the World, opened on %04d-%02d-%02d, in the order the office opens it.\n", day.y, day.m, day.d);
printf("# Nobody wrote this down. It is what the history says was in the bags.\n\n");
for (int i = 0; i < n; i++) {
const struct letter *letter = &post[i];
printf("------------------------------------------------------------\n");
printf("%d. From %s, of %s. Sealed ", i + 1, letter->sender.name, letter->sender.home);
hhmm(letter->sender.ready);
printf(", posted ");
hhmm(letter->posted);
printf(" at the %s box.\n The %s round, leaving at ", letter->visit.box, letter->visit.round);
hhmm(letter->visit.left);
printf(", emptied it at ");
hhmm(letter->visit.at);
printf(" and was back by ");
hhmm(letter->visit.back);
printf(".\n\n");
const struct household *h = find(town, letter->sender.name);
char text[2048];
if (h)
letter_text(h, day, text, sizeof text);
else {
snprintf(text, sizeof text, "%s\n", letter->sender.body);
}
fprintf(stdout, "%s\n", text);
}
char text[64];
greeting_on(day, text, sizeof text);
printf("------------------------------------------------------------\n");
printf("# Read the first letters of the signatures in this order: %s\n", text);
printf("# The World has never written back.\n");
return 0;
}