1 | //
|
---|
2 | // scls.cc
|
---|
3 | //
|
---|
4 | // Copyright (C) 1997 Limit Point Systems, Inc.
|
---|
5 | //
|
---|
6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
7 | // Maintainer: LPS
|
---|
8 | //
|
---|
9 | // This file is part of the SC Toolkit utilities.
|
---|
10 | //
|
---|
11 | // The SC Toolkit utilities are free software; you can redistribute them
|
---|
12 | // and/or modify them under the terms of the GNU General Public License as
|
---|
13 | // published by the Free Software Foundation; either version 2, or (at your
|
---|
14 | // option) any later version.
|
---|
15 | //
|
---|
16 | // The SC Toolkit utilities are distributed in the hope that they will be
|
---|
17 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | // General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License along
|
---|
22 | // with the SC Toolkit utilities; see the file COPYING. If not, write to
|
---|
23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | //
|
---|
25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
26 | //
|
---|
27 |
|
---|
28 | #ifdef HAVE_CONFIG_H
|
---|
29 | #include <scconfig.h>
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <new>
|
---|
33 | #include <unistd.h>
|
---|
34 |
|
---|
35 | #include <util/class/scexception.h>
|
---|
36 | #include <util/misc/exenv.h>
|
---|
37 | #include <util/misc/formio.h>
|
---|
38 | #include <util/group/mstate.h>
|
---|
39 | #include <util/group/message.h>
|
---|
40 | #include <util/group/thread.h>
|
---|
41 | #include <util/group/memory.h>
|
---|
42 |
|
---|
43 | // Force linkages:
|
---|
44 | #include <util/state/linkage.h>
|
---|
45 |
|
---|
46 | #ifdef HAVE_MPI
|
---|
47 | #define MPICH_SKIP_MPICXX
|
---|
48 | #include <mpi.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 | using namespace sc;
|
---|
53 |
|
---|
54 | //////////////////////////////////////////////////////////////////////////
|
---|
55 |
|
---|
56 | // This forces the exception classes to be linked in. Otherwise they won't
|
---|
57 | // for single pass linkage of static libraries. This is because of library
|
---|
58 | // ordering and interdependency issues.
|
---|
59 | static SCException ex;
|
---|
60 |
|
---|
61 | static void
|
---|
62 | clean_up(void)
|
---|
63 | {
|
---|
64 | MessageGrp::set_default_messagegrp(0);
|
---|
65 | }
|
---|
66 |
|
---|
67 | static void
|
---|
68 | out_of_memory()
|
---|
69 | {
|
---|
70 | cerr << "ERROR: out of memory" << endl;
|
---|
71 | abort();
|
---|
72 | }
|
---|
73 |
|
---|
74 | int
|
---|
75 | main(int argc, char *argv[])
|
---|
76 | {
|
---|
77 | atexit(clean_up);
|
---|
78 | std::set_new_handler(out_of_memory);
|
---|
79 |
|
---|
80 | ExEnv::init(argc, argv);
|
---|
81 | ExEnv::set_out(&cout);
|
---|
82 |
|
---|
83 | #ifdef HAVE_MPI
|
---|
84 | // MPI is allowed wait until MPI_Init to fill in argc and argv,
|
---|
85 | // so we may have to call MPI_Init before we even know that we
|
---|
86 | // want an MPIMessageGrp. The command name is used to let scls
|
---|
87 | // know that an early init is needed.
|
---|
88 | if (!strcmp(ExEnv::program_name(), "scls-mpi")) {
|
---|
89 | MPI_Init(&argc, &argv);
|
---|
90 | }
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | int i;
|
---|
94 | int debug = 0;
|
---|
95 | int version = 0;
|
---|
96 | int warranty = 0;
|
---|
97 | int license = 0;
|
---|
98 | int help = 0;
|
---|
99 | const char *working_dir = 0;
|
---|
100 | char **files = 0;
|
---|
101 | int nfile = 0;
|
---|
102 | for (i=1; i<argc; i++) {
|
---|
103 | char *arg = argv[i];
|
---|
104 | if (!strcmp(arg,"-messagegrp")) i++;
|
---|
105 | else if (!strcmp(arg,"-memorygrp")) i++;
|
---|
106 | else if (!strcmp(arg,"-threadgrp")) i++;
|
---|
107 | else if (!strcmp(arg,"-W")) working_dir = argv[++i];
|
---|
108 | else if (!strcmp(arg,"-d")) debug = 1;
|
---|
109 | else if (!strcmp(arg,"-h")) help = 1;
|
---|
110 | else if (!strcmp(arg,"-v")) version = 1;
|
---|
111 | else if (!strcmp(arg,"-l")) SCFormIO::setverbose(cout,1);
|
---|
112 | else if (!strcmp(arg,"-w")) warranty = 1;
|
---|
113 | else if (!strcmp(arg,"-L")) license = 1;
|
---|
114 | else {
|
---|
115 | char **newfiles = new char *[nfile+1];
|
---|
116 | memcpy(newfiles, files, sizeof(char*)*nfile);
|
---|
117 | delete[] files;
|
---|
118 | files = newfiles;
|
---|
119 | files[nfile++] = arg;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | if (help) {
|
---|
124 | ExEnv::out0()
|
---|
125 | << indent << "scls version " << SC_VERSION << endl
|
---|
126 | << SCFormIO::copyright << endl
|
---|
127 | << indent << "-memorygrp <$val> (which memory group to use)" << endl
|
---|
128 | << indent << "-threadgrp <$val> (which thread group to use)" << endl
|
---|
129 | << indent << "-messagegrp <$val> (which message group to use)"<<endl
|
---|
130 | << indent << "-W <$val> (set the working directory)" << endl
|
---|
131 | << indent << "-d (turn on debugging)" << endl
|
---|
132 | << indent << "-v (print the version)" << endl
|
---|
133 | << indent << "-w (print the warranty)" << endl
|
---|
134 | << indent << "-l (detailed list of objects)" << endl
|
---|
135 | << indent << "-L (print the license)" << endl
|
---|
136 | << indent << "-h (print this help)" << endl;
|
---|
137 | exit(0);
|
---|
138 | }
|
---|
139 |
|
---|
140 | if (version) {
|
---|
141 | ExEnv::out0()
|
---|
142 | << indent << "scls version " << SC_VERSION << endl
|
---|
143 | << SCFormIO::copyright;
|
---|
144 | exit(0);
|
---|
145 | }
|
---|
146 |
|
---|
147 | if (warranty) {
|
---|
148 | ExEnv::out0()
|
---|
149 | << indent << "scls version " << SC_VERSION << endl
|
---|
150 | << SCFormIO::copyright << endl
|
---|
151 | << SCFormIO::warranty;
|
---|
152 | exit(0);
|
---|
153 | }
|
---|
154 |
|
---|
155 | if (license) {
|
---|
156 | ExEnv::out0()
|
---|
157 | << indent << "scls version " << SC_VERSION << endl
|
---|
158 | << SCFormIO::copyright << endl
|
---|
159 | << SCFormIO::license;
|
---|
160 | exit(0);
|
---|
161 | }
|
---|
162 |
|
---|
163 | // set the working dir
|
---|
164 | if (working_dir && strcmp(working_dir,"."))
|
---|
165 | chdir(working_dir);
|
---|
166 |
|
---|
167 | // get the message group. first try the commandline and environment
|
---|
168 | Ref<MessageGrp> grp = MessageGrp::initial_messagegrp(argc, argv);
|
---|
169 | if (grp.nonnull())
|
---|
170 | MessageGrp::set_default_messagegrp(grp);
|
---|
171 | else
|
---|
172 | grp = MessageGrp::get_default_messagegrp();
|
---|
173 |
|
---|
174 | // get the thread group. first try the commandline and environment
|
---|
175 | Ref<ThreadGrp> thread = ThreadGrp::initial_threadgrp(argc, argv);
|
---|
176 | if (thread.nonnull())
|
---|
177 | ThreadGrp::set_default_threadgrp(thread);
|
---|
178 | else
|
---|
179 | thread = ThreadGrp::get_default_threadgrp();
|
---|
180 |
|
---|
181 | // set up output classes
|
---|
182 | SCFormIO::setindent(ExEnv::outn(), 0);
|
---|
183 | SCFormIO::setindent(ExEnv::errn(), 0);
|
---|
184 | SCFormIO::setindent(cout, 0);
|
---|
185 | SCFormIO::setindent(cerr, 0);
|
---|
186 |
|
---|
187 | SCFormIO::set_printnode(0);
|
---|
188 | if (grp->n() > 1)
|
---|
189 | SCFormIO::init_mp(grp->me());
|
---|
190 |
|
---|
191 | if (debug)
|
---|
192 | SCFormIO::set_debug(1);
|
---|
193 |
|
---|
194 |
|
---|
195 | for (i=0; i<nfile; i++) {
|
---|
196 | ExEnv::out0() << indent << files[i] << ":" << endl;
|
---|
197 | BcastStateInBin s(grp,files[i]);
|
---|
198 | ExEnv::out0() << incindent;
|
---|
199 | s.list_objects(ExEnv::out0());
|
---|
200 | if (s.has_directory() && !s.seekable()) {
|
---|
201 | ExEnv::out0() << "(objects cannot be listed since cannot seek file)" << endl;
|
---|
202 | }
|
---|
203 | ExEnv::out0() << decindent;
|
---|
204 | }
|
---|
205 |
|
---|
206 | delete[] files;
|
---|
207 |
|
---|
208 | return 0;
|
---|
209 | }
|
---|
210 |
|
---|
211 | /////////////////////////////////////////////////////////////////////////////
|
---|
212 |
|
---|
213 | // Local Variables:
|
---|
214 | // mode: c++
|
---|
215 | // c-file-style: "CLJ"
|
---|
216 | // End:
|
---|