! notes.h
! Release 1
! Copyright 2004 Anson Turner.
!
! To use, invoke the (note) print specifier with a string (or routine):
!
!    "This is an example.",(note) "This is the footnote.";
!
! Footnotes will be numbered automatically from 1 onwards. Players can view
! the footnotes with the NOTE (or FOOTNOTE) command:
!
!    This is an example. [1]
!
!    >NOTE 1
!    This is the footnote.
!
! Before including this file, set the constant MAX_FOOTNOTES to the number
! of footnotes that will appear in your implementation:
!
!    Constant MAX_FOOTNOTES = 42;
!
! If you don't set it high enough and the system runs out of room to store
! the referenced notes, it will simply start over, numbering the next note
! [1].
!
! And that's it. I made it any easier, you'd be insulted.


System_file;

Default MAX_FOOTNOTES = 20;
Array footnotes_mentioned --> (MAX_FOOTNOTES + 1);

[ note str     n;

    n = footnotenumber(str);
    if (n == 0) {
    
        if (++(footnotes_mentioned-->0) >= MAX_FOOTNOTES)
            footnotes_mentioned-->0 = 1;

        n = footnotes_mentioned-->0;
        footnotes_mentioned-->n = str;
    }
    print " [",n,"]";
];

[ footnotenumber str     c;

    for (c = 1 : c <= footnotes_mentioned-->0 : c++)
        if (footnotes_mentioned-->c == str)
            return c;
    return 0;
];

[ FootnoteSub     ;

    if (footnotes_mentioned-->0 == 0)
        "No footnotes have been mentioned.";
    
    if (noun < 1 || noun > footnotes_mentioned-->0)
        "No footnote ",noun," has been mentioned.";
    
    PrintOrRunVar(footnotes_mentioned-->noun);
];

Verb meta 'note' 'footnote' 
                * number               -> Footnote;