1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: tesths.cc,v 1.109 2006-09-27 17:46:12 Singular Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT - initialize SINGULARs components, run Script and start SHELL |
---|
8 | */ |
---|
9 | |
---|
10 | #include <unistd.h> |
---|
11 | #include <string.h> |
---|
12 | #include <stdio.h> |
---|
13 | #include <stddef.h> |
---|
14 | #include <stdlib.h> |
---|
15 | #include <time.h> |
---|
16 | #include <errno.h> |
---|
17 | #include "mod2.h" |
---|
18 | #include "tok.h" |
---|
19 | #include "ipshell.h" |
---|
20 | #include "sing_dld.h" |
---|
21 | #include "febase.h" |
---|
22 | #include "cntrlc.h" |
---|
23 | #include "omalloc.h" |
---|
24 | #include "silink.h" |
---|
25 | #include "ipid.h" |
---|
26 | #include "timer.h" |
---|
27 | #include "sdb.h" |
---|
28 | #include "fegetopt.h" |
---|
29 | #include "feOpt.h" |
---|
30 | #include "distrib.h" |
---|
31 | #include "version.h" |
---|
32 | #include "slInit.h" |
---|
33 | |
---|
34 | #ifdef HAVE_FACTORY |
---|
35 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
36 | #include <factory.h> |
---|
37 | #endif |
---|
38 | |
---|
39 | extern int iiInitArithmetic(); |
---|
40 | |
---|
41 | const char *singular_date=__DATE__ " " __TIME__; |
---|
42 | |
---|
43 | /*0 implementation*/ |
---|
44 | int main( /* main entry to Singular */ |
---|
45 | int argc, /* number of parameter */ |
---|
46 | char** argv) /* parameter array */ |
---|
47 | { |
---|
48 | #ifdef HAVE_FACTORY |
---|
49 | On(SW_USE_NTL); |
---|
50 | On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor... |
---|
51 | On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed |
---|
52 | On(SW_USE_EZGCD); |
---|
53 | Off(SW_USE_NTL_SORT); // may be changed by an command line option |
---|
54 | #endif |
---|
55 | |
---|
56 | #ifdef INIT_BUG |
---|
57 | jjInitTab1(); |
---|
58 | #endif |
---|
59 | #ifdef GENTABLE |
---|
60 | extern void ttGen1(); |
---|
61 | extern void ttGen2b(); |
---|
62 | extern void ttGen4(); |
---|
63 | extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables |
---|
64 | mpsr_ttGen(); |
---|
65 | ttGen4(); |
---|
66 | ttGen1(); |
---|
67 | ttGen2b(); |
---|
68 | #else |
---|
69 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
70 | omInitRet_2_Info(argv[0]); |
---|
71 | omInitGetBackTrace(); |
---|
72 | |
---|
73 | /* initialize components */ |
---|
74 | siRandomStart=inits(); |
---|
75 | feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart); |
---|
76 | int optc, option_index; |
---|
77 | char* errormsg; |
---|
78 | |
---|
79 | // do this first, because -v might print version path |
---|
80 | feInitResources(argv[0]); |
---|
81 | iiInitArithmetic(); |
---|
82 | |
---|
83 | // parse command line options |
---|
84 | while((optc = fe_getopt_long(argc, argv, |
---|
85 | SHORT_OPTS_STRING, feOptSpec, &option_index)) |
---|
86 | != EOF) |
---|
87 | { |
---|
88 | if (optc == '?' || optc == 0) |
---|
89 | { |
---|
90 | fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0); |
---|
91 | exit(1); |
---|
92 | } |
---|
93 | |
---|
94 | if (optc != LONG_OPTION_RETURN) |
---|
95 | option_index = feGetOptIndex(optc); |
---|
96 | |
---|
97 | assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF); |
---|
98 | |
---|
99 | if (fe_optarg == NULL && |
---|
100 | (feOptSpec[option_index].type == feOptBool || |
---|
101 | feOptSpec[option_index].has_arg == optional_argument)) |
---|
102 | errormsg = feSetOptValue((feOptIndex) option_index, (int) 1); |
---|
103 | else |
---|
104 | errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg); |
---|
105 | |
---|
106 | if (errormsg) |
---|
107 | { |
---|
108 | if (fe_optarg == NULL) |
---|
109 | fprintf(stderr, "Error: Option '--%s' %s\n", |
---|
110 | feOptSpec[option_index].name, errormsg); |
---|
111 | else |
---|
112 | fprintf(stderr, "Error: Option '--%s=%s' %s\n", |
---|
113 | feOptSpec[option_index].name, fe_optarg, errormsg); |
---|
114 | fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0); |
---|
115 | exit(1); |
---|
116 | } |
---|
117 | if (optc == 'h') exit(0); |
---|
118 | } |
---|
119 | |
---|
120 | /* say hello */ |
---|
121 | { |
---|
122 | #ifdef HAVE_NS |
---|
123 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
124 | currPack=basePack; |
---|
125 | idhdl h; |
---|
126 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
127 | IDPACKAGE(h)->language = LANG_TOP; |
---|
128 | IDPACKAGE(h)=basePack; |
---|
129 | currPackHdl=h; |
---|
130 | basePackHdl=h; |
---|
131 | #endif /* HAVE_NS */ |
---|
132 | } |
---|
133 | if (BVERBOSE(0)) |
---|
134 | { |
---|
135 | (printf)( |
---|
136 | " SINGULAR /" |
---|
137 | #ifndef MAKE_DISTRIBUTION |
---|
138 | " Development" |
---|
139 | #endif |
---|
140 | "\n" |
---|
141 | " A Computer Algebra System for Polynomial Computations / version %s\n" |
---|
142 | " 0<\n" |
---|
143 | " by: G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n" |
---|
144 | "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n" |
---|
145 | , S_VERSION1,S_VERSION2); |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | #ifdef HAVE_FACTORY |
---|
150 | if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT); |
---|
151 | #endif |
---|
152 | #ifdef HAVE_SDB |
---|
153 | sdb_flags = 0; |
---|
154 | #endif |
---|
155 | dup2(1,2); |
---|
156 | /* alternative: |
---|
157 | * memcpy(stderr,stdout,sizeof(FILE)); |
---|
158 | */ |
---|
159 | } |
---|
160 | slStandardInit(); |
---|
161 | dlInit(feArgv0); |
---|
162 | myynest=0; |
---|
163 | if (! feOptValue(FE_OPT_NO_STDLIB)) |
---|
164 | { |
---|
165 | int vv=verbose; |
---|
166 | verbose &= ~Sy_bit(V_LOAD_LIB); |
---|
167 | iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE); |
---|
168 | verbose=vv; |
---|
169 | } |
---|
170 | errorreported = 0; |
---|
171 | |
---|
172 | // and again, ifdef OM_NDEBUG this call is undef'ed |
---|
173 | // otherwise, it marks all memory allocated so far as static |
---|
174 | // i.e. as memory which is not mention on omPrintUsedAddr: |
---|
175 | //omMarkMemoryAsStatic(); |
---|
176 | |
---|
177 | setjmp(si_start_jmpbuf); |
---|
178 | |
---|
179 | // Now, put things on the stack of stuff to do |
---|
180 | // Last thing to do is to execute given scripts |
---|
181 | if (fe_optind < argc) |
---|
182 | { |
---|
183 | int i = argc - 1; |
---|
184 | FILE *fd; |
---|
185 | while (i >= fe_optind) |
---|
186 | { |
---|
187 | if ((fd = feFopen(argv[i], "r")) == NULL) |
---|
188 | { |
---|
189 | Warn("Can not open %s", argv[i]); |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | fclose(fd); |
---|
194 | newFile(argv[i]); |
---|
195 | } |
---|
196 | i--; |
---|
197 | } |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | currentVoice=feInitStdin(NULL); |
---|
202 | } |
---|
203 | |
---|
204 | // before scripts, we execute -c, if it was given |
---|
205 | if (feOptValue(FE_OPT_EXECUTE) != NULL) |
---|
206 | newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute); |
---|
207 | |
---|
208 | // first thing, however, is to load .singularrc from Singularpath |
---|
209 | // and cwd/$HOME (in that order). |
---|
210 | if (! feOptValue(FE_OPT_NO_RC)) |
---|
211 | { |
---|
212 | char buf[MAXPATHLEN]; |
---|
213 | FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf); |
---|
214 | if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf); |
---|
215 | if (rc == NULL) rc = feFopen(".singularrc", "r", buf); |
---|
216 | |
---|
217 | if (rc != NULL) |
---|
218 | { |
---|
219 | if (BVERBOSE(V_LOAD_LIB)) |
---|
220 | Print("// ** executing %s\n", buf); |
---|
221 | fclose(rc); |
---|
222 | newFile(buf); |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | /* start shell */ |
---|
227 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
228 | { |
---|
229 | #ifdef HAVE_MPSR |
---|
230 | BatchDoProc batch_do = slInitMPBatchDo(); |
---|
231 | if (batch_do != NULL) |
---|
232 | return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT), |
---|
233 | (char*) feOptValue(FE_OPT_MPHOST)); |
---|
234 | else |
---|
235 | return 1; |
---|
236 | #else |
---|
237 | assume(0); |
---|
238 | #endif |
---|
239 | } |
---|
240 | setjmp(si_start_jmpbuf); |
---|
241 | yyparse(); |
---|
242 | m2_end(0); |
---|
243 | #endif |
---|
244 | return 0; |
---|
245 | } |
---|
246 | |
---|