00001 #include <iostream>
00002 #include <Basics.H>
00003 #include <ParseImports.H>
00004
00005 using std::cout;
00006 using std::cerr;
00007 using std::endl;
00008
00009 Text program_name;
00010
00011 Text dump_import_id(ImportID id)
00012 {
00013 Text ret;
00014 ImportID::Iterator iter = id.begin();
00015 while(iter != id.end()) {
00016 if(ret.Empty())
00017 ret = *iter;
00018 else
00019 ret = ret + "/" + *iter;
00020 iter++;
00021 }
00022 return ret;
00023 }
00024
00025 void dump_imports(const ImportSeq &imports)
00026 {
00027 for(unsigned int i = 0; i < imports.size(); i++)
00028 {
00029 const Import *imp = imports.get(i);
00030 cout << " [" << i << "]:" << endl
00031 << " path = " << imp->path << endl
00032 << " orig = " << imp->orig << endl
00033 << " id = " << dump_import_id(imp->id) << endl
00034 << " start = " << imp->start << endl
00035 << " end = " << imp->end << endl
00036 << " local = " << (imp->local?"true":"false") << endl
00037 << " fromForm = " << (imp->fromForm?"true":"false") << endl
00038 << " noUpdate = " << (imp->noUpdate?"true":"false") << endl
00039 << endl;
00040 }
00041 }
00042
00043 int main(int argc, char **argv)
00044 {
00045 program_name = argv[0];
00046
00047
00048 char wd_buff[PATH_MAX+1];
00049 char *res = getcwd(wd_buff, PATH_MAX+1); assert(res != (char *)NULL);
00050 res = strcat(wd_buff, "/"); assert(res != (char *)NULL);
00051 Text wd(wd_buff);
00052
00053 try
00054 {
00055 for(unsigned int i = 1; i < argc; i++)
00056 {
00057 Text model = ParseImports::ResolvePath(argv[i], wd);
00058 try
00059 {
00060 ImportSeq imports( 10);
00061 ParseImports::P(model, imports);
00062 cout << model << ":" << endl;
00063 dump_imports(imports);
00064 }
00065 catch (FS::DoesNotExist)
00066 {
00067 cerr << endl << program_name << ": model file "
00068 << model << " does not exist" << endl;
00069 exit(1);
00070 }
00071 }
00072 }
00073 catch (const FS::Failure &f)
00074 {
00075 cerr << endl << program_name << ": " << f << endl;
00076 exit(1);
00077 }
00078 catch (const ParseImports::Error &err)
00079 {
00080 cerr << endl << program_name << ": " << err << endl;
00081 exit(1);
00082 }
00083 catch (const SRPC::failure &f)
00084 {
00085 cerr << program_name
00086 << ": SRPC failure; " << f.msg << " (" << f.r << ")" << endl;
00087 exit(1);
00088 }
00089
00090 return 0;
00091 }