Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

vfindmaster.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 //
00020 // vfindmaster.C
00021 // Last modified on Sun Jun  5 21:52:25 EDT 2005 by ken@xorian.net         
00022 //      modified on Fri Nov 12 12:09:53 EST 2004 by irina.furman@intel.com 
00023 //      modified on Wed Jul 11 22:24:38 PDT 2001 by mann  
00024 //      modified on Tue May  4 11:34:41 PDT 1999 by heydon
00025 //
00026 
00027 // Attempt to locate the repository with the master copy of a
00028 // particular object.
00029 
00030 #include <Basics.H>
00031 #include <Text.H>
00032 #include <VestaConfig.H>
00033 #include <VestaSource.H>
00034 #include "ReposUI.H"
00035 
00036 #if !defined(__sun__)
00037 extern "C" {
00038 #include <getopt.h>
00039 }
00040 #endif
00041 
00042 using std::cout;
00043 using std::cerr;
00044 using std::endl;
00045 
00046 Text program_name;
00047 
00048 void usage()
00049 {
00050   cerr << "Usage: " << program_name << endl
00051        << "        [-h hints]" << endl
00052        << "        [path]" << endl << endl;
00053   exit(1);
00054 }
00055 
00056 int
00057 main(int argc, char* argv[])
00058 {
00059   program_name = argv[0];
00060 
00061   try {
00062     //
00063     // Read config file
00064     //
00065     Text defpkgpar = VestaConfig::get_Text("UserInterface",
00066                                            "DefaultPackageParent");
00067     Text defhints;
00068     (void) VestaConfig::get("UserInterface", "DefaultHints", defhints);
00069 
00070     Text path, hints;
00071 
00072     opterr = 0;
00073     for (;;) {
00074       int c = getopt(argc, argv, "h:");
00075       if (c == EOF) break;
00076       switch (c) {
00077       case 'h':
00078         hints = optarg;
00079         break;
00080       case '?':
00081       default:
00082         usage();
00083       }
00084     }
00085 
00086     hints = hints + " " + defhints;
00087 
00088     switch (argc - optind) {
00089     case 1:
00090       path = argv[optind];
00091       break;
00092     case 0:
00093       path = ".";
00094       break;
00095     default:
00096       usage();
00097       /* not reached */
00098     }
00099 
00100     // Canonicalize path
00101     Text cpath;
00102     cpath = ReposUI::canonicalize(path, defpkgpar);
00103 
00104     // Find the master copy of this object
00105     VestaSource *vs = ReposUI::filenameToMasterVS(cpath, hints);
00106 
00107     // Display what repository the master copy is found in
00108     cout << vs->host() << ":" << vs->port() << endl;
00109 
00110   } catch (VestaConfig::failure f) {
00111     cerr << program_name << ": " << f.msg << endl;
00112     exit(2);
00113   } catch (SRPC::failure f) {
00114     cerr << program_name
00115          << ": SRPC failure; " << f.msg << " (" << f.r << ")" << endl;
00116     exit(2);
00117   } catch (ReposUI::failure f) {
00118     cerr << program_name << ": " << f.msg << endl;
00119     exit(2);
00120   }
00121 
00122   return 0;
00123 }

Generated on Mon May 8 00:48:55 2006 for Vesta by  doxygen 1.4.2