+static int format_output(char *outwalk, char *format, struct disc_time *dt) {
+ char *orig_outwalk = outwalk;
+ char *i;
+ char *tibs_end = 0;
+
+ for (i = format; *i != '\0'; i++) {
+ if (*i != '%') {
+ *(outwalk++) = *i;
+ continue;
+ }
+ switch (*(i + 1)) {
+ /* Weekday in long and abbreviation */
+ case 'A':
+ outwalk += sprintf(outwalk, "%s", day_long[dt->week_day]);
+ break;
+ case 'a':
+ outwalk += sprintf(outwalk, "%s", day_short[dt->week_day]);
+ break;
+ /* Season in long and abbreviation */
+ case 'B':
+ outwalk += sprintf(outwalk, "%s", season_long[dt->season]);
+ break;
+ case 'b':
+ outwalk += sprintf(outwalk, "%s", season_short[dt->season]);
+ break;
+ /* Day of the season (ordinal and cardinal) */
+ case 'd':
+ outwalk += sprintf(outwalk, "%d", dt->season_day + 1);
+ break;
+ case 'e':
+ outwalk += sprintf(outwalk, "%d", dt->season_day + 1);
+ if (dt->season_day > 9 && dt->season_day < 13) {
+ outwalk += sprintf(outwalk, "th");
+ break;
+ }
+
+ switch (dt->season_day % 10) {
+ case 0:
+ outwalk += sprintf(outwalk, "st");
+ break;
+ case 1:
+ outwalk += sprintf(outwalk, "nd");
+ break;
+ case 2:
+ outwalk += sprintf(outwalk, "rd");
+ break;
+ default:
+ outwalk += sprintf(outwalk, "th");
+ break;
+ }
+ break;
+ /* YOLD */
+ case 'Y':
+ outwalk += sprintf(outwalk, "%d", dt->year);
+ break;
+ /* Holidays */
+ case 'H':
+ if (dt->season_day == 4) {
+ outwalk += sprintf(outwalk, "%s", holidays[dt->season]);
+ }
+ if (dt->season_day == 49) {
+ outwalk += sprintf(outwalk, "%s", holidays[dt->season + 5]);