Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ Release notes:

1c/04, Lib 1.2.4:

Compiler: multiple definitions for the same style class or
metadata predicate now produce a warning.

Compiler: improved dictionary word matching accuracy.

Compiler: Improved ordering of strings in WRIT chunk, which
Compiler: improved ordering of strings in WRIT chunk, which
improves performance on slow platforms like 6502.

1c/03, Lib 1.2.4:
1c/03, Lib 1.2.3:

Language: CSS text-decoration: reverse has been replaced with
-iftf-reverse-video: reverse for compatibility reasons.
Expand Down
20 changes: 13 additions & 7 deletions src/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ int main(int argc, char **argv) {

need_meta = prg->totallines > 100;

prg->meta_ifid = decode_metadata_str(BI_STORY_IFID, 0, prg, &prg->arena);
prg->meta_ifid = decode_metadata_str(BI_STORY_IFID, 0, prg, &prg->arena, "story ifid", -1);
if(!prg->meta_ifid) {
if(!strcmp(format, "zblorb")) { // Mandatory for zblorb, make it an error
report(LVL_ERR, 0, "An IFID is mandatory for the blorb output format.");
Expand All @@ -315,25 +315,25 @@ int main(int argc, char **argv) {
prg->meta_ifid = 0;
}

prg->meta_author = decode_metadata_str(BI_STORY_AUTHOR, 0, prg, &prg->arena);
prg->meta_author = decode_metadata_str(BI_STORY_AUTHOR, 0, prg, &prg->arena, "story author", -1);
if(!prg->meta_author) {
if(need_meta) {
report(LVL_WARN, 0, "No author declared.");
}
prg->meta_author = "Anonymous";
}
prg->meta_title = decode_metadata_str(BI_STORY_TITLE, 0, prg, &prg->arena);
prg->meta_title = decode_metadata_str(BI_STORY_TITLE, 0, prg, &prg->arena, "story title", -1);
if(!prg->meta_title) {
if(need_meta) {
report(LVL_WARN, 0, "No title declared.");
}
prg->meta_title = "An Interactive Fiction";
}
prg->meta_noun = decode_metadata_str(BI_STORY_NOUN, 0, prg, &prg->arena);
prg->meta_noun = decode_metadata_str(BI_STORY_NOUN, 0, prg, &prg->arena, "story noun", -1);
if(!prg->meta_noun) {
prg->meta_noun = "An Interactive Fiction";
}
prg->meta_blurb = decode_metadata_str(BI_STORY_BLURB, 0, prg, &prg->arena);
prg->meta_blurb = decode_metadata_str(BI_STORY_BLURB, 0, prg, &prg->arena, "story blurb", -1);

predname = find_builtin(prg, BI_STORY_RELEASE);
if(predname && (pred = predname->pred)->nclause) {
Expand All @@ -342,8 +342,14 @@ int main(int argc, char **argv) {
exit(1);
}
prg->meta_release = pred->clauses[0]->params[0]->value;
} else if(need_meta) {
report(LVL_WARN, 0, "No release number declared.");
if(pred->nclause > 1) {
report(LVL_WARN, pred->clauses[0]->line, "%d separate definitions found for (story release $). Only the first (at this line) will be used.", pred->nclause);
}
} else {
if(need_meta) {
report(LVL_WARN, 0, "No release number declared.");
}
prg->meta_release = 1;
}

if(serial_overridden) {
Expand Down
33 changes: 25 additions & 8 deletions src/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2399,26 +2399,43 @@ static void assign_select_statements(struct program *prg) {
selectforms = 0;
}

char *decode_metadata_str(int builtin, struct word *param, struct program *prg, struct arena *arena) {
char *decode_metadata_str(int builtin, struct word *param, struct program *prg, struct arena *arena, const char *report_as, int lib_file) {
struct predname *predname;
struct predicate *pred;
char *buf;
char *buf = 0;
int i;
int nfound = 0;
int nlib = 0;
line_t whichline = 0;

predname = find_builtin(prg, builtin);
pred = predname->pred;
for(i = 0; i < pred->nclause; i++) {
if(!param
|| (pred->clauses[i]->params[0]->kind == AN_DICTWORD && pred->clauses[i]->params[0]->word == param)) {
if(decode_output(&buf, pred->clauses[i]->body, 0, 0, arena, "Story metadata")) {
return buf;
} else {
return 0;
if(!nfound) { // First one found
if(!decode_output(&buf, pred->clauses[i]->body, 0, 0, arena, "Story metadata")) {
buf = 0; // Failed to decode into buf
}
whichline = pred->clauses[i]->line;
}
nfound ++;
if(FILENUMPART(pred->clauses[i]->line) == lib_file) { // This one was in a library file
nlib ++;
}
}
}

return 0;
if(nfound - nlib > 1) {
if(param) {
report(LVL_WARN, whichline, "%d separate definitions found for (%s @%s) outside of the library. Only the first (at this line) will be used.", nfound, report_as, param->name);
} else {
// Disabling the warnings for meta predicates, which can usefully have defaults given in the library. Now they will only exist for style classes.
// report(LVL_WARN, whichline, "%d separate definitions found for (%s). Only the first (at this line) will be used.", nfound, report_as);
}
}

return buf;
}

int frontend(struct program *prg, int nfile, char **fname, dictmap_callback_t dictmap_callback) {
Expand Down Expand Up @@ -2896,7 +2913,7 @@ int frontend(struct program *prg, int nfile, char **fname, dictmap_callback_t di

for(i = 0; i < prg->nboxclass; i++) {
struct boxclass *bc = &prg->boxclasses[i];
char *css = decode_metadata_str(BI_STYLEDEF, bc->class, prg, &lexer.temp_arena);
char *css = decode_metadata_str(BI_STYLEDEF, bc->class, prg, &lexer.temp_arena, "style class", lexer.lib_file);
char *param, *str;
struct boxclassline *bcl, **bclptr;

Expand Down
2 changes: 1 addition & 1 deletion src/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int body_succeeds(struct astnode *an);
int body_might_stop(struct astnode *an);
int body_succeeds_at_most_once(struct astnode *an);
void frontend_add_builtins(struct program *prg);
char *decode_metadata_str(int builtin, struct word *param, struct program *prg, struct arena *arena);
char *decode_metadata_str(int builtin, struct word *param, struct program *prg, struct arena *arena, const char *report_as, int lib_file);
int frontend(struct program *prg, int nfile, char **fname, dictmap_callback_t dictmap_callback);
int frontend_inject_query(struct program *prg, struct predname *predname, struct predname *tailpred, struct word *prompt, const uint8_t *str);

Expand Down
16 changes: 9 additions & 7 deletions stdlib.dg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

(library version) Library version 1.2.3.
(library version) Library version 1.2.4.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Global variables
Expand Down Expand Up @@ -5148,19 +5148,21 @@
(story author or default) (story author)
(story author or default) Anonymous

%% Don't warn about querying these; however, this does not disable the warning
%% about them not being defined (for a sufficiently large story):

(story title) (fail)
(story author) (fail)

%% We can safely supply defaults for the following:

(story release 1)

(story noun)
An interactive fiction

%% Don't warn about querying these; however, this does not disable the warning
%% about them not being defined (for a sufficiently large story):

(story title) (fail)
(story author) (fail)
(story noun) (fail)
(story release $) (fail)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Game over

Expand Down
Loading