C:/Users/Dennis/src/lang/bertrand/BERTRAND/bertrand/main.c

Go to the documentation of this file.
00001 #include "def.h"
00002 
00003 int verbose;
00004 char *libdir;   /* where #included files are found */
00005 
00006 static char* copyright = "copyright (c) 1988 Wm Leler";
00007 
00008 /*********************************************************************
00009  *
00010  * Execution shell for Bertrand interpreter.
00011  * 
00012  * command line arguments:      names of bertrand programs to be executed 
00013  *
00014  *********************************************************************/
00015 void
00016 main(argc, argv)
00017 int argc;
00018 char *argv[];
00019 {
00020 void parse();                   /* from parse.c */
00021 extern FILE *infile;            /* from scanner.c */
00022 extern char *infilename;        /* from scanner.c */
00023 extern int lineno;              /* from scanner.c */
00024 NODE *init();                   /* from util.c */
00025 extern int learn;               /* from match.c */
00026 NODE *walk();                   /* from match.c */
00027 void expr_print();              /* from expr.c */
00028 void name_space_print();        /* from names.c */
00029 extern NAME_NODE *global_names; /* from names.c */
00030 void graphics_close();          /* from graphics.c */
00031 extern int graphics;            /* from graphics.c */
00032 void st_mem_free();             /* from util.c */
00033 char *getenv();                 /* UNIX system routine */
00034 
00035 int argno = 1;                  /* command line argument */
00036 NODE *subject;                  /* subject expression */
00037 
00038 /* check for BERTRAND environment variable */
00039 if (!(libdir = getenv("BERTRAND"))) libdir = LIBDIR;
00040 
00041 do {
00042     subject = init();           /* init constant operators */
00043     if (argc==1) {
00044         infilename = "stdin";
00045         infile = stdin;
00046         parse();
00047         }
00048     else {
00049         infilename = argv[argno];
00050         infile = fopen(infilename, "r");
00051         if (NULL==infile) {
00052             fprintf(stderr, "can't open program file %s\n", infilename);
00053             exit(1);
00054             }
00055         parse();        /* call parser */
00056         fclose(infile);
00057         }
00058 
00059     lineno = 0; /* to supress error message line numbers */
00060     if (verbose) fprintf(stderr, "\n");
00061 
00062     do {        /* apply rules to subject expression */
00063         subject = walk(subject);
00064         } while (learn);
00065 
00066     if (verbose && global_names->child) {
00067         fprintf(stderr, "\nglobal name space is: ");
00068         name_space_print(global_names);
00069         }
00070     if (verbose) fprintf(stderr, "\nfinal expression is: ");
00071     expr_print(subject);
00072     fprintf(stderr, "\n");
00073 
00074     st_mem_free();      /* free stack memory */
00075 
00076     if (graphics) {
00077         fprintf(stderr, "Zap output window to continue...\n");
00078         graphics_close();
00079         }
00080 
00081     } while(++argno<argc);
00082 }

Generated on Fri Jan 25 09:58:43 2008 for Bertrand by  doxygen 1.5.4