home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / bool-eval / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-31  |  3.7 KB  |  128 lines

  1. /* (c) copyright 1987 jim frost
  2.  * all rights reserved
  3.  *
  4.  * this program is copyrighted material.  the author gives permission
  5.  * to duplicate and redistribute this program provided the following
  6.  * conditions are met:
  7.  *   - this copyright notice is not removed.
  8.  *   - all duplicate copies or distributions contain full source
  9.  *     and documentation, including copyright notices.
  10.  *   - duplicate copies or distributions outside a single site are
  11.  *     original distributions without modifications.  (this is to keep
  12.  *     bastardized versions from showing up all over thie place.)
  13.  *
  14.  * this program source may be modified provided the following
  15.  * conditions are met:
  16.  *   - modified source is not distributed to other sites.
  17.  *   - modifications (including, but not limited to, bug fixes) are
  18.  *     sent to the author if the modifications are to be distributed.
  19.  *     no modified source is to be distributed unless done so by the
  20.  *     author.
  21.  *
  22.  * no warranty, either express or implied, is given for this program.
  23.  * the author makes no guarantees of fitness for any use of this
  24.  * program.  the author is not responsible for damages resulting from
  25.  * the use of this program for any purpose.
  26.  *
  27.  * 'site' refers to one or more computers under a single management.
  28.  * 'author' refers to the copyright holder, jim frost.
  29.  * 'source' refers to all files related to this program.
  30.  * 'documentation' refers to non-compilable files in the distribution.
  31.  *
  32.  * basically this notice is to keep me out of trouble should anything
  33.  * go wrong (i really *do* test these things though) and to make sure
  34.  * that the distribution of code is centralized.  makes bug fixes and
  35.  * enhancements much easier.
  36.  *
  37.  * thank you for your attention to this copyright notice.  if everyone
  38.  * follows this, you may find this a useful tool that is pretty well
  39.  * supported.
  40.  *
  41.  * author information:
  42.  *   jim frost                    permanent usnail address:
  43.  *   madd@bucsb.bu.edu            75 washington street
  44.  *   ..!harvard!bu-cs!bucsb!madd  laconia, nh  03246.
  45.  */
  46. /* misc.c:
  47.  *
  48.  * any miscellaneous functions that i didn't think belonged anywhere
  49.  * else.
  50.  */
  51.  
  52. #include "bool.h"
  53.  
  54. extern int print_err;
  55.  
  56. int blank(c)
  57. char c;
  58. {
  59.   return((c == ' ') || (c == '\011') || (c == '\n') || (c == '\r'));
  60. }
  61.  
  62. /*
  63.  * this function prints out the tree.  if the tree is incomplete, it
  64.  * just stops.
  65.  */
  66.  
  67. void print_tree(b)
  68. BOOL_EXP *b;
  69. { if (b == NULL) {
  70.     if (!print_err) {
  71.       printf("?");
  72.       print_err= 1;
  73.     }
  74.     return;
  75.   }
  76.   switch (b->opcode) {
  77.     case FALSE :
  78.       printf("0");
  79.       break;
  80.     case TRUE :
  81.       printf("1");
  82.       break;
  83.     case TOKEN :
  84.       print_token(b->value);
  85.       break;
  86.     case UNDEF :    /* all of these have a char stored in b-value */
  87.       if ((b->b1) && (!b->b2)) {
  88.         if (b->n1)
  89.           printf("!");
  90.         print_tree(b->b1);
  91.       }
  92.       else
  93.         print_err= 1;
  94.       break;
  95.     case OR :
  96.     case AND :
  97.     case XOR :
  98.       printf("(");
  99.       if (b->n1)                     /* left not */
  100.         printf("%c",b->n1);
  101.       print_tree(b->b1);             /* left tree */
  102.       printf(" %c ",(char)b->value); /* operator */
  103.       if (b->n2)                     /* right not */
  104.         printf("%c",b->n2);
  105.       print_tree(b->b2);             /* right tree */
  106.       if (b->b2)                     /* only print if not syntax err */
  107.         printf(")");
  108.       break;
  109.     default :
  110.       panic("print_tree");
  111.   }
  112. }
  113.  
  114.  
  115. /*
  116.  * we got a real serious error
  117.  */
  118.  
  119. void panic(s)
  120. char *s;
  121. {
  122.   printf("\n\nPANIC!!  Internal program error in %s\n",s);
  123.   printf("This error should not have happened.  Please contact you distributer\n");
  124.   printf("and keep a sample of the data that caused this crash.\n");
  125.   exit(1);
  126. }
  127.  
  128.