! --------------------------------------------------------------
! Dunno - A Libary Extension by Neil Cerutti (neilc@norwich.edu)
! Version 1 - 25 Jun 1999
! (modified by Andrew Plotkin for Glulx compatibility, 2 Apr 2001)
!
! If, for some reason, you always wanted the Infocom-style error
! messages that say:
!
!  I don't know the word "kludge".
!
! here's one way to do it.
!
! To use this file, put the command
!
!   Include "dunno.h";
!
! somewhere in your program's source code.
!
! The DontKnowError() routine must be called from within your
! program in one of the following two ways:
!
! 1. by the ParserError entry point (Inform Designer's Manual
! chapter 29). For exampe:
!
!   [ ParserError pe; 
!     if (pe == CANTSEE_PE) return DontKnowError(); 
!     rfalse; 
!   ];
!
! or
!
! 2. by the LibraryMessages object (IDM chapter 21). For example:
!
!   Object LibraryMessages with before [; 
!     Miscellany: if (lm_n == 30) return DontKnowError(); 
!   ];
!
! If you need help getting this to work, or just have comments or
! suggestions, write me at neilc@norwich.edu.
! ---------------------------------------------------------------

! Receives no parameters. It checks for an unknown word in the
! command the player typed, starting at word 2. If it finds one,
! it prints "I don't know the word ~xxx~." and returns true.
! Otherwise, it returns false.
[ DontKnowError wordnum;
  wordnum=FindUnknownWordToken(2);
  if (wordnum ~= 0)
  { print "[ Sorry, I don't know the word ~";
    PrintToken(wordnum);
    ".~ ]";
  } 
  else rfalse; 
];

! Receives the word number to start looking from. Returns the
! word number that contains an unknown word, or false if no
! unknown words are found. (An unknown word is defined, "not in
! the dictionary, and not something that Inform understand to be
! a number"). For convenience, this routine does not alter 'wn'.
! This routine is protected against invalid values of wordnum. 
[ FindUnknownWordToken wordnum w twn numwds;
#ifdef TARGET_GLULX;
  numwds = parse-->0;
#ifnot;
  numwds = parse->1;
#endif; ! TARGET_GLULX;
  if (wordnum <= 0 || wordnum > numwds) rfalse;
  twn=wn;
  wn=wordnum;
  while (1)
  { w=NextWordStopped();
    if (w == -1) { wn=twn; rfalse; }
    if (w == 0 && TryNumber(wn-1) == -1000) 
    { wordnum=wn-1;
      wn=twn;
      return wordnum; 
    }
  }
];

! Receives a word number and Prints the exact text typed in by
! the player at that word number. This routine is protected
! against invalid values of wordnum.
[ PrintToken wordnum k l m numwds;
#ifdef TARGET_GLULX;
  numwds = parse-->0;
#ifnot;
  numwds = parse->1;
#endif; ! TARGET_GLULX;
  if (wordnum <= 0 || wordnum > numwds) return;
  wordnum--;
  k=WordAddress(wordnum+1); 
  l=WordLength(wordnum+1); 
  for (m=0: m < l: m++) print (char) k->m; 
];

! ---------------------------------------------------------------

