home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_03 / 1n03022a < prev    next >
Text File  |  1990-06-17  |  8KB  |  370 lines

  1. /*** Instrumented for SRA TCAT-C instrumentor
  2.     C instr: Release 6.1
  3.     Fri Jun 15 08:01:41 1990
  4.     C1 (segment) instrumentation
  5.     UNIX Version, Release 6.1, 4/7/89
  6. ***/
  7. /* Copyright (c) 1988 by Software Research, Inc.
  8.  All Rights Reserved.*/
  9. /* 
  10.  This program was instrumented by SR proprietary software,
  11.  for use with the SR proprietary runtime package.
  12.  Use of this program is limited by associated software license agreements.
  13. */
  14.  
  15.  
  16. /* SRA's Runtime Functions. */
  17.  
  18.  
  19. extern    Strace();
  20. extern    Ftrace();
  21. extern    EntrMod();
  22. extern    ExtMod();
  23. extern    SegHit();
  24.  
  25.  
  26. /* TCATREST.C
  27. ** May 5, 1987
  28. ** Eduard Qualls
  29. ** 
  30. ** --example file for use with TCAT, STCAT, CapBak.
  31. */
  32.  
  33.  
  34. /*
  35.  *    @(#) stdio.h 1.4 87/06/22 
  36.  *
  37.  *    Copyright (C) The Santa Cruz Operation, 1985
  38.  *    This Module contains Proprietary Information of
  39.  *    The Santa Cruz Operation, Microsoft Corporation
  40.  *    and AT&T, and should be treated as Confidential.
  41.  *
  42.  */
  43.  
  44. /*
  45.  **    stdio.h
  46.  */
  47.  
  48.  
  49.  
  50.  
  51. extern    struct _iobuf {
  52.  
  53.     int    _cnt;
  54.     unsigned char    *_ptr;
  55.  
  56.     unsigned char    *_base;
  57.     char    _flag;
  58.     char    _file;
  59. } _iob[60];
  60.  
  61.  
  62. /* Buffer size for multi-character output to unbuffered files */
  63.  
  64.  
  65. /*
  66.  * _IOLBF means that a file's output will be buffered line by line
  67.  * In addition to being flags, _IONBF, _IOLBF and _IOFBF are possible
  68.  * values for "type" in setvbuf.
  69.  */
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. /***    getc -- get character from a stream.
  92.  *
  93.  *    return character on success.  return EOF on end of file or
  94.  *    error.
  95.  *
  96.  *    int getc(stream)
  97.  *    FILE  *stream;
  98.  */
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /***    putc -- put character on a stream.
  105.  *
  106.  *    return character on success.  return EOF on error.
  107.  *
  108.  *    int putc(ch, stream)
  109.  *    char  ch;
  110.  *    FILE  *stream;
  111.  */
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. extern    struct _iobuf    *fopen(), *fdopen(), *freopen(), *popen(), *
  123. tmpfile();
  124. extern    char    *fgets(), *gets(), *ctermid(), *cuserid();
  125. extern    char    *tempnam(), *tmpnam();
  126. extern    void    rewind(), setbuf();
  127. extern    long    ftell();
  128. extern    unsigned char    *_bufendtab[];
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. /*
  138.  *    @(#) ctype.h 1.1 87/06/22 
  139.  *
  140.  *    Copyright (C) The Santa Cruz Operation, 1985
  141.  *    This Module contains Proprietary Information of
  142.  *    The Santa Cruz Operation, Microsoft Corporation
  143.  *    and AT&T, and should be treated as Confidential.
  144.  *
  145.  */
  146.  
  147. /*
  148.  **    ctype.h
  149.  *
  150.  *    In order to get non-macro versions of toupper() and tolower(),
  151.  *    do a #undef.  Non-macro versions are supplied in libc.
  152.  *
  153.  */
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. extern    char    _ctype[];
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199. char menu[13][79] = {
  200.    "SOFTWARE RESEARCH'S RESTAURANT GUIDE \n",
  201.    "\n",
  202.    "      What type of food would you like?\n",
  203.    "\n",
  204.    "      1        American 50s   \n",
  205.    "      2        Chinese    - Hunan Style \n",
  206.    "      3        Chinese    - Seafood Oriented \n",
  207.    "      4        Chinese    - Conventional Style \n",
  208.    "      5        Danish          \n",
  209.    "      6        French          \n",
  210.    "      7        Italian         \n",
  211.    "      8        Japanese        \n",
  212.    "\n\n"
  213. };
  214.  
  215. int char_index;
  216.  
  217. main(argc,argv)      /* simple program to pick a restaurant, to demo TCAT */
  218. int    argc;
  219. char    *argv[];
  220. {
  221.    int  i, choice, c,answer;
  222.    char str[79];
  223.    int ask, repeat;
  224.  
  225.  
  226.  
  227.  
  228.    int proc_input();
  229. Strace("IC",0x7504,&argc,&argv); EntrMod(27,"main",-1); SegHit(1);
  230.  
  231.  
  232.    c = 3;
  233.    repeat = 1;
  234.  
  235.    while(repeat){ SegHit(2); {
  236.       printf("\n\n\n");
  237.       for(i = 0; i < 13; i++){ SegHit(3);
  238.          printf("%s", menu[i]);}; SegHit(4);
  239.  
  240.       gets(str);
  241.       printf("\n");
  242.       while(choice = proc_input(str)){ SegHit(5); {
  243.          switch(choice) {
  244.             case 1: SegHit(6);
  245.                printf(
  246. "\tFog City Diner           1300 Battery   982-2000 \n");
  247.                break;
  248.              case 2: SegHit(7);
  249.                printf(
  250. "\tHunan Village Restaurant  839 Kearney   956-7868 \n");
  251.                break;
  252.              case 3: SegHit(8); 
  253.                printf(
  254. "\tOcean Restaurant          726 Clement   221-3351 \n");
  255.                break;
  256.              case 4: SegHit(9);
  257.                printf(
  258. "\tYet Wah                  1829 Clement   387-8056 \n");
  259.                break;
  260.              case 5: SegHit(10);
  261.                printf(
  262. "\tEiners Danish Restaurant 1901 Clement   386-9860 \n");
  263.                break;
  264.              case 6: SegHit(11); 
  265.                printf(
  266. "\tChateau Suzanne          1449 Lombard   771-9326 \n");
  267.                break;
  268.              case 7: SegHit(12);
  269.                printf(
  270. "\tGrifone Ristorante       1609 Powell    397-8458 \n");
  271.                break;
  272.              case 8: SegHit(13);
  273.                printf(
  274. "\tFlints Barbeque          4450 Shattuck, Oakland \n");
  275.                break;
  276.              default: SegHit(14);
  277.                if(choice != -1){ SegHit(15);
  278.                   printf("\t>>> %d: not a valid choice.\n", choice);} else  SegHit(16);
  279.                break;
  280.          }
  281.       }}; SegHit(17);
  282.       for(ask = 1; ask; ){ SegHit(18); {
  283.          printf("\n\tDo you want to run it again? ");
  284.          while((answer = ( --((&_iob[0]))->_cnt >= 0 ? (0xff & (int) (*((&
  285. _iob[0]))->
  286. _ptr++)) : 
  287. _filbuf((&
  288. _iob[0])) )) != '\n'){ SegHit(19); {
  289.             switch(answer) {
  290.                case 'Y': SegHit(20);
  291.                case 'y': SegHit(21);
  292.                   ask = 0;
  293.                   char_index = 0;
  294.                   break;
  295.                case 'N': SegHit(22);
  296.                case 'n': SegHit(23);
  297.                   ask = 0;
  298.                   repeat = 0;
  299.                   break;
  300.                default: SegHit(24);
  301.                   break;
  302.             }
  303.          }}; SegHit(25); 
  304.       }}; SegHit(26);
  305.    }}; SegHit(27); ExtMod("main");
  306. Ftrace(0);
  307. }
  308.  
  309.  
  310. int proc_input(in_str)
  311. char *in_str;
  312. {
  313.    int tempresult = 0;
  314.    char bad_str[80], *bad_input;
  315.    int got_first = 0; EntrMod(24,"proc_input",-1); SegHit(1);
  316.    bad_input = bad_str;
  317.  
  318.    while(((_ctype+1)[in_str[char_index]]&010)){ SegHit(2);
  319.       char_index++;}; SegHit(3);
  320.    for( ; char_index <= strlen(in_str); char_index++){ SegHit(4); {
  321.       switch(in_str[char_index]) {
  322.          case '0': SegHit(5);
  323.          case '1': SegHit(6);
  324.          case '2': SegHit(7);
  325.          case '3': SegHit(8);
  326.          case '4': SegHit(9);
  327.          case '5': SegHit(10);
  328.          case '6': SegHit(11);
  329.          case '7': SegHit(12);
  330.          case '8': SegHit(13);
  331.          case '9': SegHit(14);
  332.             /* process choice */
  333.             tempresult = tempresult * 10 + (in_str[char_index] - '0');
  334.             got_first = 1;
  335.             break;
  336.  
  337.          default: SegHit(15);
  338.             if(chk_char(in_str[char_index])){ SegHit(16); { ExtMod("proc_input");
  339.                return(tempresult);
  340.             }}
  341.             else{ SegHit(17); {
  342.                if(char_index > 0 && got_first){ SegHit(18);
  343.                   char_index--;} else  SegHit(19);
  344.                while(char_index <= strlen(in_str)){ SegHit(20); {
  345.                   if(chk_char(in_str[char_index])){ SegHit(21);
  346.                      break;}
  347.                   else{ SegHit(22);
  348.                      *bad_input++ = in_str[char_index];}
  349.                   char_index++;
  350.                }}; SegHit(23);
  351.                *bad_input = '\0';
  352.                printf("\t>>> bad input: %s\n", bad_str);
  353.                char_index++; ExtMod("proc_input");
  354.                return(-1);
  355.             }}
  356.       }
  357.    }}; SegHit(24); ExtMod("proc_input");
  358.    return(0);
  359. }
  360.  
  361. int chk_char(ch)
  362. char ch;
  363. { EntrMod(3,"chk_char",-1); SegHit(1);
  364.    if(((_ctype+1)[ch]&010) || ch == '\0'){ SegHit(2); ExtMod("chk_char");
  365.       return(1);}
  366.    else{ SegHit(3); ExtMod("chk_char");
  367.       return(0);}
  368. }
  369.  
  370.