MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
cl.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/utils/cl.cc,v 1.32 2017/01/12 15:10:27 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  */
30 
31 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
32 
33 #include <iostream>
34 #include <sstream>
35 
36 #include "input.h"
37 #include "mathp.h"
38 
39 /* plugins per math parser */
40 #include "dummypgin.h"
41 
42 int
43 main(int argc, const char* const argv[])
44 {
45  int verbose = 1;
46 
47  if (argc > 1) {
48  if (strcmp(argv[1], "-?") == 0
49  || strcmp(argv[1], "-h") == 0
50  || strcmp(argv[1], "--help") == 0) {
51  std::cerr
52  << "usage: " << argv[0]
53  << " reads from stdin" << std::endl
54  << " " << argv[0] << " {-?|-h|--help}"
55  " prints this message" << std::endl
56  << " " << argv[0]
57  << " <arg1> [<arg2> ...]"
58  " evaluates the expressions" << std::endl;
59  exit(EXIT_SUCCESS);
60  } else if (strcmp(argv[1], "-s") == 0) {
61  verbose = 0;
62  argv++;
63  argc--;
64  }
65  }
66 
67 #ifdef USE_TABLE
68  //Table t(1);
69  Table t(true);
70 #endif /* USE_TABLE */
71 
72  if (argc > 1) {
73  for (int i = 1; i < argc; i++) {
74  std::istringstream in(argv[i]);
75  InputStream In(in);
76 #ifdef USE_TABLE
77  MathParser mp(In, t);
78 #else /* !USE_TABLE */
79  MathParser mp(In);
80 #endif /* !USE_TABLE */
81 
82  if (verbose) {
83  std::cout << "argv[" << i << "] = ";
84  }
85 
86  try {
87  mp.GetForever(std::cout, "; ");
88  std::cout << std::endl;
89  } catch (...) {
90  std::cout << std::endl;
91  exit(EXIT_FAILURE);
92  }
93  }
94  exit(EXIT_SUCCESS);
95  }
96 
97  InputStream In(std::cin);
98 #ifdef USE_TABLE
99  MathParser mp(In, t);
100 #else /* !USE_TABLE */
101  MathParser mp(In);
102 #endif /* !USE_TABLE */
103 
104  try {
105  mp.GetForever(std::cout, "\n");
106  std::cout << std::endl;
107  exit(EXIT_SUCCESS);
108  } catch (...) {
109  std::cout << std::endl;
110  exit(EXIT_FAILURE);
111  }
112 }
113 
int main(int argc, const char *const argv[])
Definition: cl.cc:43
void GetForever(std::ostream &out, const char *const sep="\n")
Definition: mathp.cc:4565
static int verbose
Definition: ann_tr.c:51
Definition: table.h:43