ucmain.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2000 The Exult Team
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifdef HAVE_CONFIG_H
00026 #  include <config.h>
00027 #endif
00028 
00029 #include <fstream>
00030 #include <unistd.h>
00031 #include <stdio.h>
00032 #include <string>
00033 #include <vector>
00034 #include "ucloc.h"
00035 #include "ucfun.h"
00036 
00037 #ifndef ALPHA_LINUX_CXX
00038 #  include <iosfwd>
00039 #endif
00040 
00041 using std::strcpy;
00042 using std::strrchr;
00043 using std::strlen;
00044 using std::ios;
00045 
00046           // THIS is what the parser produces.
00047 extern std::vector<Uc_function *> functions;  
00048 
00049 std::vector<char *> include_dirs; // -I directories.
00050 
00051 /*
00052  *  MAIN.
00053  */
00054 
00055 int main
00056   (
00057   int argc,
00058   char **argv
00059   )
00060   {
00061   extern int yyparse();
00062   extern FILE *yyin;
00063   char *src;
00064   char outbuf[256];
00065   char *outname = 0;
00066   static char *optstring = "o:I:s";
00067   extern int optind, opterr, optopt;
00068   extern char *optarg;
00069   Uc_function::Intrinsic_type ty = Uc_function::bg;
00070   opterr = 0;     // Don't let getopt() print errs.
00071   int optchr;
00072   while ((optchr = getopt(argc, argv, optstring)) != -1)
00073     switch (optchr)
00074       {
00075     case 'o':   // Output to write.
00076       outname = optarg;
00077       break;
00078     case 'I':   // Include dir.
00079       include_dirs.push_back(optarg);
00080       break;
00081     case 's':
00082       ty = Uc_function::si;
00083       break;
00084       }
00085   if (optind < argc)    // Filename?
00086     {
00087     src = argv[optind];
00088     yyin = fopen(argv[optind], "r");
00089     if (!outname)   // No -o option?
00090       {   // Set up output name.
00091       outname = strncpy(outbuf, src, sizeof(outbuf) - 5);
00092       outbuf[sizeof(outbuf) - 5] = 0;
00093       char *dot = strrchr(outname, '.');
00094       if (!dot)
00095         dot = outname + strlen(outname);
00096       strcpy(dot, ".uco");
00097       }
00098     }
00099   else
00100     {
00101     src = "<stdin>";
00102     yyin = stdin;
00103     if (!outname)
00104       outname = strcpy(outbuf, "a.ucout");
00105     }
00106   Uc_location::set_cur(src, 0);
00107           // For now, use black gate.
00108   Uc_function::set_intrinsics(ty);
00109 #if 0
00110 //++++TESTING
00111   int tok;
00112   extern int yylex();
00113   while ((tok = yylex()) != EOF)
00114     printf("%d\n", tok);
00115 #endif
00116   yyparse();
00117   int errs = Uc_location::get_num_errors();
00118   if (errs > 0)     // Check for errors.
00119     return errs;
00120           // Open output.
00121   std::ofstream out(outname, ios::binary|ios::out);
00122   for (std::vector<Uc_function *>::iterator it = functions.begin();
00123           it != functions.end(); it++)
00124     {
00125     Uc_function *fun = *it;
00126     fun->gen(out);    // Generate function.
00127     }
00128   return Uc_location::get_num_errors();
00129   }
00130 
00131 /*
00132  *  Report error.
00133  */
00134 void yyerror
00135   (
00136   char *s
00137   )
00138   {
00139   Uc_location::yyerror(s);
00140   }

Generated on Mon Jul 9 14:42:51 2007 for ExultEngine by  doxygen 1.5.1