home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume6 / lookup.c++ / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-04  |  882 b   |  45 lines

  1. #include <stream.h>
  2. #include <string.h>
  3. #include "lookup.h"
  4.  
  5. extern RET_TYPE
  6.     a(ARG_TYPE),
  7.     b(ARG_TYPE),
  8.     c(ARG_TYPE),
  9.     help(ARG_TYPE),
  10.     oops(ARG_TYPE);
  11.  
  12. entry list[] = {
  13.   (char *)4, &oops,
  14.   "acmd", &a,
  15.   "bcmd", &b,
  16.   "c", &c,
  17.   "help", &help,
  18.   };
  19.  
  20. int main(int argc, char *argv[])
  21.   {
  22.   char *progname = argv[0];
  23.   lookup command(list);
  24.   char word[200]; // of type ARG_TYPE
  25.   int i;
  26.  
  27.   argc--; // to shut up CC
  28.  
  29.   while(cout << "% ", cin >> word && strcmp(word, "quit"))
  30.     {
  31.  
  32.     // Note that in the next statement, we are in
  33.     // fact saying command[const char *](ARG_TYPE)
  34.     // In this case, ARG_TYPE *is* const char *, so we 
  35.     // are just passing the same thing to both [] and ().
  36.  
  37.     if(i = command[word](word))
  38.       {
  39.       // the function returned a non-zero result
  40.       cerr << form("%s: %s returned %d\n", progname, word, i);
  41.       }
  42.     }
  43.   return 0;
  44.   }
  45.