1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | /* |
---|
6 | * ABSTRACT - initialize SINGULARs components, run Script and start SHELL |
---|
7 | */ |
---|
8 | |
---|
9 | #include "config.h" |
---|
10 | #include <kernel/mod2.h> |
---|
11 | #include "countedref.h" |
---|
12 | #include <omalloc/omalloc.h> |
---|
13 | |
---|
14 | #include <misc/auxiliary.h> |
---|
15 | #include <misc/options.h> |
---|
16 | |
---|
17 | #ifdef HAVE_FACTORY |
---|
18 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
19 | #include <factory/factory.h> |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <kernel/febase.h> |
---|
23 | #include <kernel/timer.h> |
---|
24 | |
---|
25 | #ifdef HAVE_FANS |
---|
26 | #include <kernel/bbcone.h> |
---|
27 | #include <kernel/bbfan.h> |
---|
28 | #endif |
---|
29 | |
---|
30 | #include "ipshell.h" |
---|
31 | #include "cntrlc.h" |
---|
32 | #include "silink.h" |
---|
33 | #include "ipid.h" |
---|
34 | #include "sdb.h" |
---|
35 | #include "feOpt.h" |
---|
36 | #include "distrib.h" |
---|
37 | #include "version.h" |
---|
38 | #include "slInit.h" |
---|
39 | #include <Singular/links/ssiLink.h> |
---|
40 | #include "bigintm.h" |
---|
41 | #include "mmalloc.h" |
---|
42 | #include "tok.h" |
---|
43 | #include "fegetopt.h" |
---|
44 | |
---|
45 | // #include "pyobject_setup.h" |
---|
46 | |
---|
47 | #include <unistd.h> |
---|
48 | #include <string.h> |
---|
49 | #include <stddef.h> |
---|
50 | #include <stdlib.h> |
---|
51 | #include <time.h> |
---|
52 | #include <errno.h> |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | extern int siInit(char *); |
---|
57 | |
---|
58 | #if ! defined(LIBSINGULAR) |
---|
59 | |
---|
60 | #ifdef HAVE_FACTORY |
---|
61 | int initializeGMP(){ return 1; } |
---|
62 | #endif |
---|
63 | |
---|
64 | int mmInit2( void ) |
---|
65 | { |
---|
66 | #if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC) |
---|
67 | /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */ |
---|
68 | /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */ |
---|
69 | /* do not rely on the default in Singular as libsingular may be different */ |
---|
70 | mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc); |
---|
71 | #else |
---|
72 | mp_set_memory_functions(malloc,reallocSize,freeSize); |
---|
73 | #endif |
---|
74 | return 1; |
---|
75 | } |
---|
76 | int mmInit( void ) |
---|
77 | { |
---|
78 | #ifndef SI_THREADS |
---|
79 | return mmInit2(); |
---|
80 | #else |
---|
81 | return 1; |
---|
82 | #endif |
---|
83 | } |
---|
84 | |
---|
85 | /*0 implementation*/ |
---|
86 | int main( /* main entry to Singular */ |
---|
87 | int argc, /* number of parameter */ |
---|
88 | char** argv) /* parameter array */ |
---|
89 | { |
---|
90 | //mmInit(); |
---|
91 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
92 | omInitRet_2_Info(argv[0]); |
---|
93 | omInitGetBackTrace(); |
---|
94 | |
---|
95 | siInit(argv[0]); |
---|
96 | init_signals(); |
---|
97 | |
---|
98 | // parse command line options |
---|
99 | int optc, option_index; |
---|
100 | const char* errormsg; |
---|
101 | while((optc = fe_getopt_long(argc, argv, |
---|
102 | SHORT_OPTS_STRING, feOptSpec, &option_index)) |
---|
103 | != EOF) |
---|
104 | { |
---|
105 | if (optc == '?' || optc == 0) |
---|
106 | { |
---|
107 | fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0); |
---|
108 | exit(1); |
---|
109 | } |
---|
110 | |
---|
111 | if (optc != LONG_OPTION_RETURN) |
---|
112 | option_index = feGetOptIndex(optc); |
---|
113 | |
---|
114 | assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF); |
---|
115 | |
---|
116 | if (fe_optarg == NULL && |
---|
117 | (feOptSpec[option_index].type == feOptBool || |
---|
118 | feOptSpec[option_index].has_arg == optional_argument)) |
---|
119 | errormsg = feSetOptValue((feOptIndex) option_index, (int) 1); |
---|
120 | else |
---|
121 | errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg); |
---|
122 | |
---|
123 | if (errormsg) |
---|
124 | { |
---|
125 | if (fe_optarg == NULL) |
---|
126 | fprintf(stderr, "Error: Option '--%s' %s\n", |
---|
127 | feOptSpec[option_index].name, errormsg); |
---|
128 | else |
---|
129 | fprintf(stderr, "Error: Option '--%s=%s' %s\n", |
---|
130 | feOptSpec[option_index].name, fe_optarg, errormsg); |
---|
131 | fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0); |
---|
132 | exit(1); |
---|
133 | } |
---|
134 | if (optc == 'h') exit(0); |
---|
135 | } |
---|
136 | |
---|
137 | /* say hello */ |
---|
138 | //for official version: not active |
---|
139 | //bigintm_setup(); |
---|
140 | |
---|
141 | if (TEST_V_QUIET) |
---|
142 | { |
---|
143 | (printf)( |
---|
144 | " SINGULAR /" |
---|
145 | #ifndef MAKE_DISTRIBUTION |
---|
146 | " Development" |
---|
147 | #endif |
---|
148 | "\n" |
---|
149 | " A Computer Algebra System for Polynomial Computations / version %s\n" |
---|
150 | " 0<\n" |
---|
151 | " by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n" |
---|
152 | "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n" |
---|
153 | , S_VERSION1,S_VERSION2); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | #ifdef HAVE_FACTORY |
---|
158 | if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT); |
---|
159 | #endif |
---|
160 | #ifdef HAVE_SDB |
---|
161 | sdb_flags = 0; |
---|
162 | #endif |
---|
163 | dup2(1,2); |
---|
164 | /* alternative: |
---|
165 | * memcpy(stderr,stdout,sizeof(FILE)); |
---|
166 | */ |
---|
167 | } |
---|
168 | |
---|
169 | #ifdef SINGULAR_PYOBJECT_SETUP_H |
---|
170 | pyobject_setup(); |
---|
171 | #endif |
---|
172 | countedref_init(); |
---|
173 | #ifdef HAVE_FANS |
---|
174 | bbcone_setup(); |
---|
175 | bbfan_setup(); |
---|
176 | #endif /* HAVE_FANS */ |
---|
177 | errorreported = 0; |
---|
178 | |
---|
179 | setjmp(si_start_jmpbuf); |
---|
180 | |
---|
181 | // Now, put things on the stack of stuff to do |
---|
182 | // Last thing to do is to execute given scripts |
---|
183 | if (fe_optind < argc) |
---|
184 | { |
---|
185 | int i = argc - 1; |
---|
186 | FILE *fd; |
---|
187 | while (i >= fe_optind) |
---|
188 | { |
---|
189 | if ((fd = feFopen(argv[i], "r")) == NULL) |
---|
190 | { |
---|
191 | Warn("Can not open %s", argv[i]); |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | fclose(fd); |
---|
196 | newFile(argv[i]); |
---|
197 | } |
---|
198 | i--; |
---|
199 | } |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | currentVoice=feInitStdin(NULL); |
---|
204 | } |
---|
205 | |
---|
206 | // before scripts, we execute -c, if it was given |
---|
207 | if (feOptValue(FE_OPT_EXECUTE) != NULL) |
---|
208 | newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute); |
---|
209 | |
---|
210 | // first thing, however, is to load .singularrc from Singularpath |
---|
211 | // and cwd/$HOME (in that order). |
---|
212 | if (! feOptValue(FE_OPT_NO_RC)) |
---|
213 | { |
---|
214 | char buf[MAXPATHLEN]; |
---|
215 | FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf); |
---|
216 | if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf); |
---|
217 | if (rc == NULL) rc = feFopen(".singularrc", "r", buf); |
---|
218 | |
---|
219 | if (rc != NULL) |
---|
220 | { |
---|
221 | if (BVERBOSE(V_LOAD_LIB)) |
---|
222 | Print("// ** executing %s\n", buf); |
---|
223 | fclose(rc); |
---|
224 | newFile(buf); |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | /* start shell */ |
---|
229 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
230 | { |
---|
231 | singular_in_batchmode=TRUE; |
---|
232 | char *linkname=(char*) feOptValue(FE_OPT_LINK); |
---|
233 | if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0)) |
---|
234 | { |
---|
235 | return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT)); |
---|
236 | //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST)); |
---|
237 | //exit(0); |
---|
238 | } |
---|
239 | } |
---|
240 | setjmp(si_start_jmpbuf); |
---|
241 | yyparse(); |
---|
242 | m2_end(0); |
---|
243 | return 0; |
---|
244 | } |
---|
245 | #endif // not LIBSINGULAR |
---|
246 | |
---|