Annotation of mstools/samples/rpc/doctor/doctorp.c, revision 1.1.1.2

1.1       root        1: /****************************************************************************
1.1.1.2 ! root        2:                    Microsoft RPC Version 1.0
        !             3:                  Copyright Microsoft Corp. 1992
        !             4:                         Doctor Example
        !             5: 
        !             6:     FILE:       Doctorp.c
        !             7: 
        !             8:     PURPOSE:    Procedures that can be linked with the client side
        !             9:                 to form a standalone application, or linked with
        !            10:                 the server side to form a distributed RPC application
        !            11: 
        !            12:     DATA:       Pattern   - array of strings; input patterns and responses
        !            13:                 Substring - substrings within user input
        !            14: 
        !            15:     FUNCTIONS:  Analyze(*pszInOut) - top level function
        !            16:                 Match(*string, *pattern) - compare input to patterns
        !            17:                 Respond(*string, *response) - replace substrings in response
        !            18:                 Synonyms(*ps1, *ps2) - replace synonyms in user input
        !            19: 
1.1       root       20: ****************************************************************************/
                     21: 
                     22: #include <stdlib.h>
                     23: #include <stdio.h>
                     24: #include <string.h>
                     25: #include <ctype.h>
1.1.1.2 ! root       26: #include "doctor.h"     // header file generated by MIDL compiler
1.1       root       27: 
                     28: #define TRUE  1
                     29: #define FALSE 0
                     30: 
                     31: 
                     32: char *Pattern[] =
                     33:     {
                     34:     "0COMPUTER 1",
                     35:     "0COMPUTERS 1",
1.1.1.2 ! root       36:     "=DO 11S WORRY YOU?",    // string 11 = "computer" or "machine" 
1.1       root       37:     "=WHY DO YOU MENTION 11S?",
                     38:     "=WHAT DO YOU THINK 11S HAVE TO DO WITH YOUR PROBLEM?",
                     39:     "=WHAT DO YOU THINK ABOUT 11S?",
                     40: 
                     41:     "0RPC0",
                     42:     "=WHY DO YOU MENTION RPC?",
                     43:     "=DO YOU MENTION RPC BECAUSE YOU ARE FEELING REMOTE RIGHT NOW?",
                     44:     "=WHAT FEELINGS DO YOU HAVE ABOUT RPC?",
                     45: 
                     46:     "0SORRY0",
                     47:     "=PLEASE DON'T APOLOGIZE.",
                     48:     "=APOLOGIES ARE NOT NECESSARY.",
                     49:     "=WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?",
                     50:     "=I'VE TOLD YOU THAT APOLOGIES ARE NOT REQUIRED.",
                     51:     "=APOLOGIES ARE NOT NECESSARY, PLEASE GO ON",
                     52: 
                     53:     "0I AM SAD1",
1.1.1.2 ! root       54:     "=I AM SORRY TO HEAR YOU ARE 14.",    // string 14 = "sad", "sick", etc.
1.1       root       55:     "=DO YOU THINK COMING HERE WILL HELP YOU NOT TO BE 14?",
                     56:     "=I'M SURE IT'S NOT PLEASANT TO BE 14.",
                     57:     "=CAN YOU EXPLAIN WHAT MADE YOU 14?",
                     58: 
                     59:     "0I AM HAPPY1",
1.1.1.2 ! root       60:     "=HOW HAVE I HELPED YOU TO BE 15?",    // string 15 = "happy", etc.
1.1       root       61:     "=HAS YOUR TREATMENT MADE YOU 15?",
                     62:     "=WHAT MAKES YOU 15 JUST NOW?",
                     63:     "=CAN YOU EXPLAIN WHY YOU ARE SUDDENLY 15?",
                     64: 
                     65:     "0NAME0",
                     66:     "=I AM NOT INTERESTED IN NAMES.",
                     67:     "=I'VE TOLD YOU BEFORE I DON'T CARE ABOUT NAMES.  PLEASE CONTINUE.",
                     68: 
                     69:     "0 FAMILY1",
1.1.1.2 ! root       70:     "=TELL ME MORE ABOUT YOUR 12.",    // string 12 = "mother", "brother", etc.
1.1       root       71:     "=WHO ELSE IN YOUR FAMILY?",
                     72:     "=YOUR 12?",
                     73:     "=WHAT ELSE COMES TO MIND WHEN YOU THINK OF YOUR 12?",
                     74: 
                     75:     "0I REMEMBER 1",
                     76:     "=DO YOU OFTEN THINK OF 1?",
                     77:     "=WHAT IN THE PRESENT SITUATION REMINDS YOU OF 1?",
                     78: 
                     79:     "0SAME0",
                     80:     "0ALIKE0",
                     81:     "0IS 0LIKE0",
                     82:     "=IN WHAT WAY?",
                     83:     "=WHAT RESEMBLANCE DO YOU SEE?",
                     84:     "=WHAT DOES THAT SIMILARITY SUGGEST TO YOU?",
                     85:     "=WHAT OTHER CONNECTIONS DO YOU SEE?",
                     86:     "=WHAT DO YOU SUPPOSE THAT RESEMBLANCE MEANS?",
                     87:     "=WHAT IS THE CONNECTION, DO YOU SUPPOSE?",
                     88:     "=COULD THERE REALLY BE SOME CONNECTION?",
                     89:     "=HOW?",
                     90: 
                     91:     "0I REMEMBER 1",
                     92:     "=DO YOU OFTEN THINK OF 1?",
                     93:     "=DOES THINKING OF 1 BRING ANYTHING ELSE TO MIND?",
                     94:     "=WHAT ELSE DO YOU REMEMBER?",
                     95:     "=WHY DO YOU REMEMBER 1 JUST NOW?",
                     96:     "=WHAT IN THE PRESENT SITUATION REMINDS YOU OF 1?",
                     97:     "=WHAT IS THE CONNECTION BETWEEN ME AND 1?",
                     98: 
                     99:     "0DO YOU REMEMBER 1",
                    100:     "=DID YOU THINK I WOULD FORGET 1?",
                    101:     "=WHY DO YOU THINK I SHOULD RECALL 1 NOW?",
                    102:     "=WHAT ABOUT 1?",
                    103:     "=YOU MENTIONED 1?",
                    104: 
                    105:     "1 IS MY PROBLEM0",
1.1.1.2 ! root      106:     "=1 13 YOUR PROBLEM?",    // string 13 = "is" or "are" 
1.1       root      107:     "=ARE YOU SURE 13 1 YOUR PROBLEM?",
                    108:     "=PERHAPS 13 1 NOT YOUR REAL PROBLEM.",
                    109:     "=YOU THINK YOU HAVE PROBLEMS?",
                    110:     "=DO YOU OFTEN THINK ABOUT 1?",
                    111: 
                    112:     "0PROBLEM0",
                    113:     "=PLEASE CONTINUE, THIS MAY BE INTERESTING.",
                    114:     "=HAVE YOU ANY OTHER PROBLEMS YOU WISH TO DISCUSS?",
                    115:     "=PERHAPS YOU'D RATHER CHANGE THE SUBJECT.",
                    116:     "=YOU SEEM A BIT UNEASY.",
                    117: 
                    118:     "0I DREAMT 1",
                    119:     "0I DREAMED 1",
                    120:     "=REALLY 1?",
                    121:     "=HAVE YOU EVER FANTASIZED 1 WHILE YOU WERE AWAKE?",
                    122:     "=HAVE YOU DREAMT 1 BEFORE?",
                    123:     "=WHAT DOES THAT DREAM SUGGEST TO YOU?",
                    124:     "=DO YOU DREAM OFTEN?",
                    125:     "=WHAT PERSONS APPEAR IN YOUR DREAMS?",
                    126:     "=DON'T YOU BELIEVE THAT DREAM HAS SOMETHING TO DO WITH YOUR PROBLEM?",
                    127:     "=DO YOU EVER WISH YOU COULD FLEE FROM REALITY?",
                    128: 
                    129:     "0DREAM0",
                    130:     "=WHAT DOES THAT DREAM SUGGEST TO YOU?",
                    131:     "=DO YOU DREAM OFTEN?",
                    132:     "=WHAT PERSONS APPEAR IN YOUR DREAMS?",
                    133:     "=DON'T YOU BELIEVE THAT DREAM HAS SOMETHING TO DO WITH YOUR PROBLEM?",
                    134:     "=DO YOU EVER WISH YOU COULD FLEE FROM REALITY?",
                    135: 
                    136:     "0IF 1 HAD 2",
                    137:     "=DO YOU THINK IT'S LIKELY THAT 1 MIGHT HAVE 2?",
                    138:     "=DO YOU WISH THAT 1 HAD 2?",
                    139:     "=REALLY, IF 1 HAD 2?",
                    140: 
                    141:     "0IF 1",
                    142:     "=DO YOU THINK IT'S LIKELY THAT 1?",
                    143:     "=DO YOU WISH THAT 1?",
                    144:     "=WHAT DO YOU THINK ABOUT 1?",
                    145:     "=REALLY, IF 1?",
                    146: 
                    147:     "WAS I 1",
                    148:     "=WHAT IF YOU WERE 1?",
                    149:     "=DO YOU THINK YOU WERE 1?",
                    150:     "=WERE YOU 1?",
                    151:     "=WHAT WOULD IT MEAN IF YOU WERE 1?",
                    152:     "=WHAT DOES \"1\" SUGGEST TO YOU?",
                    153:     "=WHY DO YOU ASK?",
                    154:     "=DOES THAT QUESTION INTERST YOU?",
                    155:     "=WHAT IS IT YOU REALLY WANT TO KNOW?",
                    156:     "=ARE SUCH QUESTIONS MUCH ON YOUR MIND?",
                    157:     "=WHAT ANSWER WOULD PLEASE YOU MOST?",
                    158:     "=WHAT DO YOU THINK?",
                    159:     "=WHAT COMES TO YOUR MIND WHEN YOU ASK THAT?",
                    160:     "=HAVE YOU ASKED SUCH QUESTIONS BEFORE?",
                    161:     "=HAVE YOU ASKED ANYONE ELSE?",
                    162: 
                    163:     "0I WAS 1",
                    164:     "=WERE YOU REALLY?",
                    165:     "=WHY DO YOU TELL ME YOU WERE 1 NOW?",
                    166:     "=PERHAPS I ALREADY KNEW YOU WERE 1.",
                    167: 
                    168:     "WERE YOU 1",
                    169:     "=WOULD YOU LIKE TO BELIEVE THAT I WAS 1?",
                    170:     "=WHAT SUGGESTS THAT I WAS 1?",
                    171:     "=WHAT DO YOU THINK?",
                    172:     "=PERHAPS I WAS 1.",
                    173:     "=WHAT IF I HAD BEEN 1.",
                    174: 
                    175:     "0 MY 1",
                    176:     "MY 1",
                    177:     "=YOUR 1?",
                    178:     "=WHY DO YOU SAY YOUR 1?",
                    179:     "=DOES THAT SUGGEST ANYTHING ELSE WHICH BELONGS TO YOU?",
                    180:     "=IS IT IMPORTANT TO YOU THAT 1?",
                    181: 
                    182:     "0EVERYONE0",
                    183:     "0EVERYBODY0",
                    184:     "=REALLY, EVERYONE?",
                    185:     "=SURELY NOT EVERYONE.",
                    186:     "=CAN YOU THINK OF ANYONE IN PARTICULAR?",
                    187:     "=WHO, FOR EXAMPLE?",
                    188:     "=YOU ARE THINKING OF A VERY SPECIAL PERSON.",
                    189:     "=WHO, MAY I ASK?",
                    190:     "=SOMEONE SPECIAL, PERHAPS.",
                    191:     "=YOU HAVE A PARTICULAR PERSON IN MIND, DON'T YOU?",
                    192:     "=WHO DO YOU THINK YOU'RE TALKING ABOUT?",
                    193:     "=I SUSPECT YOU'RE EXAGGERATING A LITTLE.",
                    194: 
                    195:     "NO ONE0",
                    196:     "0 NO ONE0",
                    197:     "0NOBODY0",
                    198:     "=REALLY, NO ONE?",
                    199:     "=SURELY SOMEONE.",
                    200:     "=CAN YOU THINK OF ANYONE IN PARTICULAR?",
                    201:     "=WHO, FOR EXAMPLE?",
                    202:     "=YOU ARE THINKING OF A VERY SPECIAL PERSON.",
                    203:     "=WHO, MAY I ASK?",
                    204:     "=SOMEONE SPECIAL, PERHAPS.",
                    205:     "=YOU HAVE A PARTICULAR PERSON IN MIND, DON'T YOU?",
                    206:     "=WHO DO YOU THINK YOU'RE TALKING ABOUT?",
                    207:     "=I SUSPECT YOU'RE EXAGGERATING A LITTLE.",
                    208: 
                    209:     "0ALWAYS0",
                    210:     "=CAN YOU THINK OF A SPECIFIC EXAMPLE?",
                    211:     "=WHEN?",
                    212:     "=WHAT INCIDENT ARE YOU THINKING OF?",
                    213:     "=REALLY, ALWAYS?",
                    214:     "=WHAT IF THIS NEVER HAPPENED?",
                    215: 
                    216:     "0HOW 0",
                    217:     "0WHERE 0",
                    218:     "=WHY DO YOU ASK?",
                    219:     "=DOES THAT QUESTION INTERST YOU?",
                    220:     "=WHAT IS IT YOU REALLY WANT TO KNOW?",
                    221:     "=ARE SUCH QUESTIONS MUCH ON YOUR MIND?",
                    222:     "=WHAT ANWSER WOULD PLEASE YOU MOST?",
                    223:     "=WHAT DO YOU THINK?",
                    224:     "=WHAT COMES TO YOUR MIND WHEN YOU ASK THAT?",
                    225:     "=HAVE YOU ASKED SUCH QUESTIONS BEFORE?",
                    226:     "=HAVE YOU ASKED ANYONE ELSE?",
                    227: 
1.1.1.2 ! root      228:     /* "there is no" strings must precede "there is" strings */
1.1       root      229:     "0THERE IS NO 1",
                    230:     "0THERE IS NOT 1",
                    231:     "=WHAT IF THERE WERE 1",
                    232:     "=DID YOU THINK THERE MIGHT BE 1",
                    233:     "=HOW 13 1 RELATED TO YOU?",
1.1.1.2 ! root      234:     /* these must follow "there is no" strings */
1.1       root      235:     "0THERE IS 1",
1.1.1.2 ! root      236:     "=13 THERE REALLY 1?", 
1.1       root      237:     "=HOW 13 1 RELATED TO YOU?",
                    238: 
                    239:     "0SEX 1",
                    240:     "=DO YOU REALLY WANT TO DISCUSS SEX?",
                    241:     "=DO YOU EVER DREAM ABOUT SEX?",
                    242:     "=WHY DO YOU MENTION SEX?",
                    243:     "=COULD SEX BE PART OF YOUR PROBLEM?",
                    244: 
1.1.1.2 ! root      245:     "0HECK1",    // checks for strong language
1.1       root      246:     "0DARN1",
                    247:     "=ARE SUCH OBSCENITIES FREQUENTLY ON YOUR MIND?",
                    248:     "=YOU ARE BEING A BIT CHILDISH.",
                    249:     "=REALLY NOW",
                    250:     "=DEAR ME",
                    251:     "=I REALLY SHOULDN'T TOLERATE SUCH LANGUAGE.",
                    252: 
                    253:     "0MY FRIEND 1",
                    254:     "=WHAT ELSE CAN YOU TELL ME ABOUT YOUR FRIEND?",
                    255:     "=WHAT MIGHT YOUR FRIEND HAVE TO DO WITH THE PROBLEM?",
                    256: 
1.1.1.2 ! root      257:     "0",    // last resort: match anything
1.1       root      258:     "=PLEASE GO ON.",
                    259:     "=I AM NOT SURE I UNDERSTAND YOU FULLY.",
                    260:     "=WHAT DOES THAT SUGGEST TO YOU?",
                    261:     "=DO YOU FEEL STRONGLY ABOUT DISCUSSING SUCH THINGS?",
1.1.1.2 ! root      262:     NULL    // special end of list character
1.1       root      263: };
                    264: 
1.1.1.2 ! root      265: 
        !           266: int iLastIndex = 0;     // don't send same response twice in a row
        !           267:                         // note: this requires 2 responses for each pattern
1.1       root      268: 
                    269: char Substring[20][STRSIZE] = {
                    270:   "", "", "", "", "", "", "", "", "", "",
                    271:   "REMEMBER",  /* 10 */
                    272:   "COMPUTER",  /* 11 */
                    273:   "FAMILY",    /* 12 */
                    274:   "IS",        /* 13 */
1.1.1.2 ! root      275:   "", "", "", "", "", ""        };
1.1       root      276: 
                    277: 
1.1.1.2 ! root      278: /* Compare user input to patterns */
        !           279: 
1.1       root      280: int Match (char *str, char *pat)
                    281: {
1.1.1.2 ! root      282:     char * pStr;             // backup ptr to the user input string
        !           283:     char * pPat;             // backup ptr to the pattern
        !           284:     char *pSubstr = NULL;    // possible substrings within pattern
        !           285:     int index = 0;           // index to substring
        !           286: 
        !           287:     while (TRUE) {  // exit routine from within this loop
        !           288: 
        !           289:         if (isdigit(*pat)) {  // replaceable pattern number
        !           290:             index = atoi(pat);       // extract pattern number
        !           291:             while (isdigit(*pat))    // skip number in pattern
        !           292:                 pat++;
        !           293: 
        !           294:             pSubstr = Substring[index]; // pointer to current substring
        !           295: 
        !           296:             if (*pat == '\0') {  // if end of pattern, everything will match
        !           297:                 strcpy(pSubstr, str);   // copy rest of input into substring
        !           298:                 return(TRUE);
        !           299:             }
        !           300: 
        !           301:             else 
        !           302:                 while (*pat != *str) {  // match all to specific char in pattern
        !           303:                     *pSubstr++ = *str++; // fill substring
        !           304:                     if (*str == '\0')    // stuff left to match, but no input
        !           305:                         return(FALSE);
        !           306:                     *pSubstr = '\0';     // can overwrite if there's more...
        !           307:                 }
        !           308: 
        !           309:             pStr = str;  // keep track; it may still be *
        !           310:             pPat = pat;  // keep track; it may still be *
        !           311:         }  
        !           312: 
        !           313:         if (*str == *pat) {  // matches the specific pattern
        !           314:             str++;  // skip to next character of input string
        !           315:             pat++;  // skip to next character of pattern
        !           316:             if ((*str == '\0') && (*pat == '\0'))  // both at end?
        !           317:                 return(TRUE);
        !           318:         }  
        !           319: 
        !           320:         else if (pSubstr != NULL) {  // didn't match specific, so still * substring
        !           321:             pat = pPat;              // restore ptr to input pattern
        !           322:             while (pStr < str)       // catch up to current input character
        !           323:                 *pSubstr++ = *pStr++;
        !           324:             while (*pat != *str) {   // match to next possible match in pattern
        !           325:                 *pSubstr++ = *str++; // fill substring with more characters
        !           326:                 if (*str == '\0')    // stuff left to match, but no input
        !           327:                     return(FALSE);
        !           328:             }
        !           329:             *pSubstr = '\0';         // can overwrite if there's more...
        !           330:             pStr = str;              // keep track; it may still be *
        !           331:             pPat = pat;              // keep track; it may still be *
        !           332:         }  
        !           333: 
        !           334:         else
        !           335:             return(FALSE);           // no match
        !           336: 
        !           337:     }  // end while (TRUE) loop
        !           338: 
        !           339: }  // end function Match
1.1       root      340: 
                    341: 
1.1.1.2 ! root      342: /* Add possible substrings to the response string */
1.1       root      343: 
                    344: void Respond(char *str, char *finalstr)
                    345: {
1.1.1.2 ! root      346:     char copy[STRSIZE];  // copy of the substring to process token at a time
        !           347:     char *token;
        !           348:     char *word;
        !           349:     int index;           // index to substring (string converted to number)
        !           350:     int len = 0;         // index to output string for sprintf
1.1       root      351: 
                    352:     while (*str) {
1.1.1.2 ! root      353: 
        !           354:         if (! isdigit(*str)) 
        !           355:             len += sprintf(finalstr + len, "%c", *str++);
        !           356: 
        !           357:         else {  // check for pattern number
        !           358: 
        !           359:             index = atoi(str);     // extract pattern number
        !           360:             while (isdigit(*str))  // skip number in pattern
        !           361:                 str++;
        !           362: 
        !           363:             strcpy(copy, Substring[index]);  // process substring
        !           364:             token = strtok(copy, " ");       // skip blanks
        !           365: 
        !           366:             while (token) {
        !           367:                 word = token;
        !           368: 
        !           369:                 if (! strcmp(token,"I") || ! strcmp(token,"ME")) 
        !           370:                     word = "YOU";
        !           371:                 else if (! strcmp(token,"YOU")) 
        !           372:                     word = "I";
        !           373:                 else if (! strcmp(token,"MY")) 
        !           374:                     word = "YOUR";
        !           375:                 else if (! strcmp(token,"YOUR")) 
        !           376:                     word = "MY";
        !           377:                 else if (! strcmp(token,"MINE")) 
        !           378:                     word = "YOURS";
        !           379:                 else if (! strcmp(token,"YOURS")) 
        !           380:                     word = "MINE";
        !           381:                 else if (! strcmp(token,"MYSELF")) 
        !           382:                     word = "YOURSELF";
        !           383:                 else if (! strcmp(token,"YOURSELF")) 
        !           384:                     word = "MYSELF";
        !           385:                 else if (! strcmp(token,"I'M")) 
        !           386:                     word = "YOU'RE";
        !           387:                 else if (! strcmp(token,"YOU'RE")) 
        !           388:                     word = "I'M";
        !           389:                 else if (! strcmp(token,"AM")) 
        !           390:                     word = "ARE";
        !           391:                 else if (! strcmp(token,"WAS")) 
        !           392:                     word = "WERE";
        !           393: 
        !           394:                 len += sprintf(finalstr + len, "%s", word);
        !           395: 
        !           396:                 // get next token from Substring
        !           397:                 if ((token = strtok(NULL, " ")) != NULL) 
        !           398:                     len += sprintf(finalstr + len, " ");
        !           399: 
        !           400:             }  // end while token
        !           401: 
        !           402:         }  // end else (if isdigit)
        !           403: 
        !           404:     }  // end while str
        !           405: 
1.1       root      406:     len += sprintf(finalstr + len, "\n");
                    407: 
1.1.1.2 ! root      408: }  // end function Respond
1.1       root      409: 
                    410: 
1.1.1.2 ! root      411: /* Replace synonyms in user input */
        !           412: 
1.1       root      413: void Synonyms(char *input, char *output)
                    414: {
1.1.1.2 ! root      415:     char *ps1 = input;
        !           416:     char *ps2 = output;
        !           417:     char *token;
        !           418:     char *word;
        !           419: 
        !           420:     static char *synonym10[] = {"RECALL", "RECOLLECT", ""};
        !           421:     static char *synonym11[] = {"MACHINE", ""};
        !           422:     static char *synonym12[] = {"MOTHER", "MOMMY", "FATHER", "DADDY", 
        !           423:                                 "SISTER", "BROTHER", "AUNT", "UNCLE", ""}; 
        !           424:     static char *synonym13[] = {"ARE", "AM", ""};
        !           425:     static char *synonym14[] = {"SAD", "UNHAPPY", "DEPRESSED", "SICK", ""};
        !           426:     static char *synonym15[] = {"HAPPY", "ELATED", "GLAD", "BETTER", ""};
        !           427: 
        !           428:     short StrMember();
        !           429: 
        !           430:     // preprocessing...convert to uppercase and check for special chars
        !           431: 
        !           432:     while (*ps1) {
        !           433:         *ps1 = toupper(*ps1);
        !           434:         if (*ps1 == '.' || *ps1 == ',' || *ps1 == '!' ||
        !           435:             *ps1 == '?' || *ps1 == ';' || *ps1 == ':' ||
        !           436:             ! isprint(*ps1)) {
        !           437:             *ps1 = '\0';
        !           438:             break;
        !           439:         }
        !           440:         ps1++;
        !           441:     } 
        !           442: 
        !           443:     // ok, it's preprocessed now...let's check for pattern matches
        !           444: 
        !           445:     ps1 = input;               // back to the beginning...
        !           446:     strcpy(ps2, "");
        !           447:     token = strtok(ps1, " ");  // search for tokens deliminated by space
        !           448: 
        !           449:     while (token) {
        !           450: 
        !           451:         word = token;
        !           452: 
        !           453:         if (StrMember(token, synonym10)) {
        !           454:             word = "REMEMBER";  // use this synonym for pattern-matching
        !           455:         }
        !           456:         else if (StrMember(token, synonym11)) {
        !           457:             strcpy(Substring[11], token);  // 11 is hardcoded into response
        !           458:             word = "COMPUTER";  
        !           459:         }
        !           460:         else if (StrMember(token, synonym12)) {
        !           461:             strcpy(Substring[12], token);  // 12
        !           462:             word = "FAMILY";
        !           463:         }
        !           464:         else if (StrMember(token, synonym13)) {
        !           465:             strcpy(Substring[13], token);  // 13
        !           466:             word = "IS";
        !           467:         }
        !           468:         else if (StrMember(token, synonym14)) {
        !           469:             strcpy(Substring[14], token);  // 14
        !           470:             word = "SAD";
        !           471:         }
        !           472:         else if (StrMember(token, synonym15)) {
        !           473:             strcpy(Substring[15], token);  // 15
        !           474:             word = "HAPPY";
        !           475:         }
        !           476: 
        !           477:         strcat(ps2, word);          // append the token to the output string
        !           478:         strcat(ps2, " ");           // restore space
        !           479:         token = strtok(NULL, " ");  // search for the next token
        !           480: 
        !           481:     }  // end while token
        !           482: 
        !           483: }  // end function Synonyms
        !           484: 
        !           485: 
        !           486: short StrMember(char *str, char **list)
        !           487: {
        !           488:     while (strcmp(*list, "")) {    // not end of the list
        !           489:         if (!strcmp(str, *list))
        !           490:             return 1;
        !           491:         else
        !           492:             list++;
        !           493:     }
1.1       root      494: 
1.1.1.2 ! root      495:     return 0;
        !           496: } 
1.1       root      497: 
                    498: 
1.1.1.2 ! root      499: /* Top-level routine */
1.1       root      500: 
                    501: void Analyze(unsigned char *str)
                    502: {
1.1.1.2 ! root      503:     int i = 0;      // index to entry within Pattern
        !           504:     int j;          // index to first possible response string
        !           505:     int index;      // index of the actual response string used
        !           506:     int count = 0;  // count of all possible response strings (must be > 2)
        !           507:     char *response;
        !           508:     char synstr[STRSIZE];
1.1       root      509: 
                    510:     Synonyms(str, synstr);
                    511: 
1.1.1.2 ! root      512:     while (Pattern[i] != NULL) {  // check against all patterns
        !           513: 
        !           514:         if (Pattern[i][0] != '=') {  // if a patient pattern
        !           515: 
        !           516:             if (Match(synstr, Pattern[i]) == TRUE) {
        !           517: 
        !           518:                 // skip past patient input to doctor responses
        !           519:                 while (Pattern[i] && Pattern[i][0] != '=')
        !           520:                     i++;      
        !           521: 
        !           522:                 // count the number of possible responses, and
        !           523:                 // point index to beginning of doctor responses
        !           524:                 if (Pattern[i] && Pattern[i][0] == '=') {
        !           525:                     count = 1; 
        !           526:                     j = i++;  
        !           527:                 }
        !           528: 
        !           529:                 // count all possible doctor responses
        !           530:                 while (Pattern[i] && Pattern[i][0] == '=') {
        !           531:                     count++;  
        !           532:                     i++;
        !           533:                 }
        !           534: 
        !           535:                 // pick a different doctor response from last time
        !           536:                 do { 
        !           537:                     index = j + (rand() % count);
        !           538:                 } while (index == iLastIndex);
        !           539: 
        !           540:                 // process the doctor respose, and
        !           541:                 // keep track of the response used last
        !           542:                 response = &Pattern[index][1];
        !           543:                 iLastIndex = index;     
        !           544:                 Respond(response, str); 
        !           545:                 return;
        !           546: 
        !           547:             }  // end if match
        !           548: 
        !           549:         }  // end if patient pattern
        !           550: 
        !           551:         i++;  // next pattern
        !           552: 
        !           553:     }  // end while pattern
        !           554: 
1.1       root      555: }  // end function Analyze
                    556: 
                    557: 
1.1.1.2 ! root      558: /* Shutdown the server by calling RPC API functions */
1.1       root      559: 
                    560: void Shutdown(void)
                    561: {
                    562:     RPC_STATUS status;
                    563: 
                    564:     printf("Calling RpcMgmtStopServerListening\n");
                    565:     status = RpcMgmtStopServerListening(NULL);
                    566:     printf("RpcMgmtStopServerListening returned: 0x%x\n", status);
                    567:     if (status) {
1.1.1.2 ! root      568:         exit(status);
1.1       root      569:     }
                    570: 
                    571:     printf("Calling RpcServerUnregisterIf\n");
                    572:     status = RpcServerUnregisterIf(NULL, NULL, FALSE);
                    573:     printf("RpcServerUnregisterIf returned 0x%x\n", status);
                    574:     if (status) {
1.1.1.2 ! root      575:         exit(status);
1.1       root      576:     }
                    577: }
                    578: 
1.1.1.2 ! root      579: /* end file doctorp.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.