Implement and document %V escape so version only needs to be set once.

This commit is contained in:
Eric S. Raymond 2017-06-30 14:35:18 -04:00
parent 40acab43af
commit e10637c419
3 changed files with 18 additions and 4 deletions

View file

@ -29,7 +29,7 @@ VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
.PHONY: debug indent release refresh dist linty html clean .PHONY: debug indent release refresh dist linty html clean
CC?=gcc CC?=gcc
CCFLAGS+=-std=c99 -D _DEFAULT_SOURCE -Wpedantic -O2 CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -Wpedantic -O2
LIBS= LIBS=
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)

View file

@ -124,6 +124,7 @@
# %9 = A 9-digit number # %9 = A 9-digit number
# %B = Variable number of blanks # %B = Variable number of blanks
# %! = The entire message should be suppressed # %! = The entire message should be suppressed
# %V = substitute program version string
motions: !!omap motions: !!omap
- MOT_0: - MOT_0:
@ -2778,7 +2779,7 @@ arbitrary_messages: !!omap
- TWIST_TURN: 'Sorry, but the path twisted and turned so much that I can''t figure\nout which way to go to get back.' - TWIST_TURN: 'Sorry, but the path twisted and turned so much that I can''t figure\nout which way to go to get back.'
- ADVENTURE_NEWS: 'Open Adventure is an author-approved open-source release of\nVersion 2.5 with, as yet, no gameplay changes.\nVersion 2.5 was essentially the same as Version II; the cave and the\nhazards therein are unchanged, and top score is still 430 points.\nThere are a few more hints, especially for some of the more obscure\npuzzles. There are a few minor bugfixes and cosmetic changes. You\ncan now save a game and resume it at once (formerly you had to wait a\nwhile first), but it now costs you a few points each time you save the\ngame. Saved games are now stored in much smaller files than before.' - ADVENTURE_NEWS: 'Open Adventure is an author-approved open-source release of\nVersion 2.5 with, as yet, no gameplay changes.\nVersion 2.5 was essentially the same as Version II; the cave and the\nhazards therein are unchanged, and top score is still 430 points.\nThere are a few more hints, especially for some of the more obscure\npuzzles. There are a few minor bugfixes and cosmetic changes. You\ncan now save a game and resume it at once (formerly you had to wait a\nwhile first), but it now costs you a few points each time you save the\ngame. Saved games are now stored in much smaller files than before.'
- GO_UNNEEDED: 'You don''t have to say "go" every time; just specify a direction or, if\nit''s nearby, name the place to which you wish to move.' - GO_UNNEEDED: 'You don''t have to say "go" every time; just specify a direction or, if\nit''s nearby, name the place to which you wish to move.'
- ADVENTURE_VERSION: 'There is a puff of orange smoke; within it, fiery runes spell out:\n\n\tOpen Adventure 1.1 - http://www.catb.org/esr/open-adventure/' - ADVENTURE_VERSION: 'There is a puff of orange smoke; within it, fiery runes spell out:\n\n\tOpen Adventure %V - http://www.catb.org/esr/open-adventure/'
classes: classes:
- threshold: 0 - threshold: 0

17
misc.c
View file

@ -176,7 +176,9 @@ void vspeak(const char* msg, va_list ap)
char* rendered = xmalloc(size); char* rendered = xmalloc(size);
char* renderp = rendered; char* renderp = rendered;
// Handle format specifiers (including the custom %C, %L, %S) by adjusting the parameter accordingly, and replacing the specifier with %s. // Handle format specifiers (including the custom %C, %L, %S) by
// adjusting the parameter accordingly, and replacing the
// specifier with %s.
long previous_arg = 0; long previous_arg = 0;
for (int i = 0; i < msglen; i++) { for (int i = 0; i < msglen; i++) {
if (msg[i] != '%') { if (msg[i] != '%') {
@ -187,7 +189,10 @@ void vspeak(const char* msg, va_list ap)
if (arg == -1) if (arg == -1)
arg = 0; arg = 0;
i++; i++;
// Integer specifier. In order to accommodate the fact that PARMS can have both legitimate integers *and* packed tokens, stringify everything. Future work may eliminate the need for this. // Integer specifier. In order to accommodate the fact
// that PARMS can have both legitimate integers *and*
// packed tokens, stringify everything. Future work may
// eliminate the need for this.
if (msg[i] == 'd') { if (msg[i] == 'd') {
int ret = snprintf(renderp, size, "%ld", arg); int ret = snprintf(renderp, size, "%ld", arg);
if (ret < size) { if (ret < size) {
@ -212,6 +217,14 @@ void vspeak(const char* msg, va_list ap)
} }
} }
/* Version specifier */
if (msg[i] == 'V') {
strcpy(renderp, VERSION);
size_t len = strlen(VERSION);
renderp += len;
size -= len;
}
// All-lowercase specifier. // All-lowercase specifier.
if (msg[i] == 'L' || msg[i] == 'C') { if (msg[i] == 'L' || msg[i] == 'C') {
packed_to_token(arg, renderp); /* unpack directly to destination */ packed_to_token(arg, renderp); /* unpack directly to destination */