home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OP2DEV.ZIP / ENGLISH.C < prev    next >
C/C++ Source or Header  |  1991-03-14  |  4KB  |  195 lines

  1.  
  2. /*    program ENGLISH.C                    *\
  3. \*    WARNING: "advent.c" allocates GLOBAL storage space by    *\
  4. \*        including "advdef.h".                *\
  5. \*        All other modules use "advdec.h".        */
  6.  
  7.  
  8. #include    "stdio.h"    /* drv = 1.1st file 2.def 3.A    */
  9. #include    "advent.h"
  10. #include    "advdec.h"
  11.  
  12. #define INCL_DOS
  13. #define INCL_SUB
  14. #include <os2.h>
  15.  
  16. #include "bbsexpan.h"
  17.  
  18.  
  19. /*
  20.     Analyze a two word sentence
  21. */
  22. english()
  23. {
  24.  
  25.     char    *msg;
  26.     int    type1, type2, val1, val2;
  27.  
  28.     verb = object = motion = 0;
  29.     type2 = val2 = -1;
  30.     type1 = val1 = -1;
  31.     msg = "Huh? I don't understand.";
  32.  
  33.     getwords();
  34.  
  35.     if (!(*word1))
  36.         return(0);        /* ignore whitespace    */
  37.     if (!analyze(word1, &type1, &val1))    /* check word1    */
  38.         return(0);        /* didn't know it    */
  39.  
  40.     if (type1 == 2 && val1 == SAY) {
  41.         verb = SAY;    /* repeat word & act upon if..    */
  42.         object = 1;
  43.         return(1);
  44.     }
  45.  
  46.     if (*word2)
  47.         if (!analyze(word2, &type2, &val2))
  48.             return(0);    /* didn't know it    */
  49.  
  50.     /* check his grammar */
  51.     if ((type1 == 3) && (type2 == 3) && \
  52.         (val1 == 51) && (val2 == 51)) {
  53.         outwords();
  54.         return(0);
  55.     }
  56.     else if (type1 == 3) {
  57.         rspeak(val1);
  58.         return(0);
  59.     }
  60.     else if (type2 == 3) {
  61.         rspeak(val2);
  62.         return(0);
  63.     }
  64.     else if (type1 == 0) {
  65.         if (type2 == 0) {
  66.             SerWritef(unhand,"%s\n\r", msg);
  67.             return(0);
  68.         }
  69.         else
  70.             motion = val1;
  71.     }
  72.     else if (type2 == 0)
  73.         motion = val2;
  74.     else if (type1 == 1) {
  75.         object = val1;
  76.         if (type2 == 2)
  77.             verb = val2;
  78.         if (type2 == 1) {
  79.             SerWritef(unhand,"%s\n\r", msg);
  80.             return(0);
  81.         }
  82.     }
  83.     else if (type1 == 2) {
  84.         verb = val1;
  85.         if (type2 == 1)
  86.             object = val2;
  87.         if (type2 == 2) {
  88.             SerWritef(unhand,"%s\n\r", msg);
  89.             return(0);
  90.         }
  91.     }
  92.     else
  93.         bug(36);
  94.     return(1);
  95. }
  96.  
  97.  
  98. /*
  99.         Routine to analyze a word.
  100. */
  101. analyze(word, type, value)
  102. char    *word;
  103. int    *type, *value;
  104. {
  105.     int    wordval, msg;
  106.  
  107.     /* make sure I understand */
  108.     if ((wordval = vocab(word, 0)) == -1) {
  109.         switch(rand() % 3) {
  110.         case 0:
  111.             msg = 60;
  112.             break;
  113.         case 1:
  114.             msg = 61;
  115.             break;
  116.         default:
  117.             msg = 13;
  118.         }
  119.         rspeak(msg);
  120.         return(0);
  121.     }
  122.     *type = wordval/1000;
  123.     *value = wordval%1000;
  124.     return(1);
  125. }
  126.  
  127. /*
  128.     retrieve input line (max 80 chars), convert to lower case
  129.      & rescan for first two words (max. WORDSIZE-1 chars).
  130. */
  131. getwords()
  132. {
  133.     char    words[100], *wptr;
  134.    char  t1[30];
  135.    short size;
  136.    short rc;
  137.  
  138.      while( (USENUM==0 || SerConnected(unhand)) && UseTm(unhand) && V_USRON) {
  139.         COLOR(BRMAGENTA);
  140.         SerWritef(unhand,">");
  141.         word1[0] = word2[0] = '\0';
  142.         COLOR(BRCYAN);
  143.         size = 0;
  144.         words[0] = '\0';
  145.         do {
  146.            rc = SerGetCmd(t1,20,unhand);
  147.            if( rc <= 0 )
  148.               break;
  149.            strcat(words,t1);
  150.            strcat(words," ");
  151.            size += strlen(t1);
  152.         } while( (unhand->cmdwait) && (size < sizeof(words) - 20));
  153.         if( rc >= 0 )
  154.            break;
  155.      }
  156.      if( !((USENUM==0 || SerConnected(unhand)) && UseTm(unhand) && V_USRON) ) {
  157.         exit(1);
  158.      }
  159.     
  160.     wptr = words;
  161.    strlwr(words);
  162.     sscanf(words,"%19s %19s", word1, word2);
  163.     if (dbugflg)
  164.         SerWritef(unhand,"WORD1 = '%s', WORD2 = '%s', words='%s'\n\r", word1, word2,words);
  165.     return(1);
  166. }
  167.  
  168. /*
  169.     output adventure word list (motion/0xxx & verb/2xxx) only
  170.     6 words/line pausing at 20th line until keyboard active
  171. */
  172. outwords()
  173. {
  174.     int    i, j, line;
  175.     char    words[80];
  176.  
  177.     j = line = 0;
  178.     for (i = 0; i < MAXWC; ++i) {
  179.         if ((wc[i].acode < 1000) || ((wc[i].acode < 3000) && \
  180.                                      (wc[i].acode > 1999))) {
  181.             SerWritef(unhand,"%-12s", wc[i].aword);
  182.             if ((++j == 6) || (i == MAXWC-1)) {
  183.                 j = 0;
  184.                     SerWritef(unhand,"\n\r");
  185.                 if (++line == 20) {
  186.                     line = 0;
  187.                     SerWritef(unhand,"\n\r\n\r\007Enter <RETURN>");
  188.                     SerWritef(unhand," to continue\n\r\n\r");
  189.                SerGetCmd(words,10,unhand);
  190.                 }
  191.             }
  192.         }
  193.     }
  194. }
  195.