xlparse.c

00001 /* File:      parse.c -- Prolog interface to front-end parser
00002 ** Author(s): Yifei Dong
00003 ** Contact:   lmc@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) SUNY at Stony Brook, 1998-2000
00006 ** 
00007 ** XMC is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XMC is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XMC; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: xlparse.c,v 1.1 2001/05/25 19:11:43 lfcastro Exp $
00022 ** 
00023 */
00024 
00025 
00026 #include <stdio.h>
00027 #include <string.h>
00028 
00029 /*
00030 #include <cinterf.h>
00031 */
00032 #define TRUE  1
00033 #define FALSE 0
00034 extern char* ptoc_string(int);
00035 
00036 extern FILE* yyin;
00037 extern FILE* yyout;
00038 
00039 extern int yyparse();
00040 extern int line_no, char_no;
00041 extern int num_errs;
00042 
00043 char* fn_source;
00044 char* fn_target;
00045 char* fn_error;
00046 
00047 FILE* error_file;
00048 
00049 int parse()
00050 {
00051     fn_source = (char*)ptoc_string(1);
00052     fn_target = (char*)ptoc_string(2);
00053     fn_error  = (char*)ptoc_string(3);
00054 
00055     if (strcmp(fn_error, "stderr") == 0)
00056         error_file = stderr;
00057     else
00058         error_file = fopen(fn_error, "w");
00059 
00060     if ((yyin = fopen(fn_source, "r")) == NULL) {
00061         fprintf(error_file,
00062                 "Can not open source file %s.\n",
00063                 fn_source);
00064         return FALSE;
00065     }
00066 
00067     if ((yyout = fopen(fn_target, "w")) == NULL) {
00068         fprintf(error_file, 
00069                 "Can not open target file %s.\n",
00070                 fn_target);
00071         return FALSE;
00072     }
00073 
00074     line_no = 1; char_no = 1;
00075     num_errs = 0;
00076 
00077     yyparse();
00078 
00079     fclose(yyin);
00080     fclose(yyout);
00081 
00082     if (num_errs > 0) {
00083         fprintf(error_file,
00084                 "%s contains syntax %d errors.\n", 
00085                 fn_source, num_errs);
00086     }
00087 
00088     if (error_file != stderr)
00089         fclose(error_file);
00090     return (num_errs == 0) ? TRUE : FALSE ;
00091 }

Generated on Wed Jul 26 13:30:46 2006 for XSB by  doxygen 1.4.5