home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / bool-eval / bool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-31  |  3.6 KB  |  109 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. /* bool.c:
  47.  *
  48.  * this program evaluates boolean equations and builds truth tables from
  49.  * the equations.
  50.  *
  51.  * history:
  52.  *   9.29.87    original version.
  53.  *   10.19.87   single expression (no operator) bugs fixed.  it couldn't
  54.  *              handle a single expression.  FALSE constant bug fixed.
  55.  *              returned TRUE by mistake.  typo.  changes made to output
  56.  *              to make it more readable.  bug in centering function of
  57.  *              the evaluation print routine fixed.  forgot to follow the
  58.  *              evaluated number by a space.
  59.  *   10.20.87   duplicate function declaration error fixed.  wouldn't
  60.  *              find duplicate function name if the duplicate was the
  61.  *              first in the function list.
  62.  */
  63.  
  64. #include "bool.h"
  65.  
  66. int debug_mode,
  67.     no_print;
  68.  
  69. main(argc,argv)
  70. int argc;
  71. char *argv[];
  72. { FILE *f;
  73.   int a;
  74.  
  75.   debug_mode= 0; /* no debugging mode unless -D */
  76.   no_print= 0;   /* print unless -n */
  77.  
  78.   if (argc == 1) {
  79.     printf("Usage: %s [-DEBUG -noprint] filename [filename ...]\n",PROG);
  80.     exit(1);
  81.   }
  82.  
  83. /*
  84.  * evaluate switches
  85.  */
  86.  
  87.   for (a= 1; *argv[a] == '-'; a++) {
  88.     if ((!strcmp(argv[a]+1,"DEBUG")) || (!strcmp(argv[a]+1,"D")))
  89.       debug_mode= 1;
  90.     else if ((!strcmp(argv[a]+1,"noprint")) || (!strcmp(argv[a]+1,"n")))
  91.       no_print= 1;
  92.   }
  93.  
  94. /*
  95.  * evaluate for every file on command line
  96.  */
  97.  
  98.   for (; a < argc; a++) {
  99.     if (strcmp(argv[a]+strlen(argv[a])-2,".b"))
  100.       printf("%s: not %s source file\n",argv[a],PROG);
  101.     else if ((f= fopen(argv[a],"r")) != NULL) {
  102.       eval_file(f);
  103.       fclose(f);
  104.     }
  105.     else
  106.       perror(argv[a]);
  107.   }
  108. }
  109.