My Project
Loading...
Searching...
No Matches
tesths.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4
5/*
6* ABSTRACT - initialize SINGULARs components, run Script and start SHELL
7*/
8
9
10#include "kernel/mod2.h"
11#include "omalloc/omalloc.h"
12#include "misc/options.h"
13#include "factory/factory.h"
15#include "Singular/fevoices.h"
18
19#include "ipshell.h"
20#include "cntrlc.h"
21#include "links/silink.h"
22#include "ipid.h"
23#include "sdb.h"
24#include "feOpt.h"
25#include "misc/distrib.h"
26#include "mmalloc.h"
27#include "tok.h"
28#include "resources/fegetopt.h"
29
30#include "Singular/countedref.h"
32
33#include <unistd.h>
34#ifdef HAVE_NTL
35#include <NTL/config.h>
36#endif
37
38#ifdef HAVE_SIMPLEIPC
40#endif
41
42
43extern void siInit(char *);
44#ifdef PSINGULAR
45GLOBAL_VAR char *global_argv0;
46#endif
49
50int mmInit( void )
51{
52#ifndef X_OMALLOC
53#if defined(OMALLOC_USES_MALLOC)
54 /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
55 /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
56 /* do not rely on the default in Singular as libsingular may be different */
57 mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
58#else
59 mp_set_memory_functions(malloc,reallocSize,freeSize);
60#endif
61#endif
62 return 1;
63}
64
65/*0 implementation*/
66int main( /* main entry to Singular */
67 int argc, /* number of parameter */
68 char** argv) /* parameter array */
69{
70 mmInit();
71 // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
72 omInitRet_2_Info(argv[0]);
74
75#ifdef PSINGULAR
76 global_argv0 = argv[0];
77#endif
78// how many processes ? -----------------------------------------------------
79 {
80 int cpus=1;
81 int cpu_n;
82 #ifdef _SC_NPROCESSORS_ONLN
83 if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
84 #elif defined(_SC_NPROCESSORS_CONF)
85 if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
86 #endif
87 #ifdef HAVE_SIMPLEIPC
89 #endif
90 feSetOptValue(FE_OPT_CPUS, cpus);
91// how many threads ? -----------------------------------------------------
92 feSetOptValue(FE_OPT_THREADS, cpus);
93 }
94 siInit(argv[0]);
96
97 // parse command line options
98 int optc, option_index;
99 const char* errormsg;
100 while((optc = fe_getopt_long(argc, argv,
101 SHORT_OPTS_STRING, feOptSpec, &option_index))
102 != EOF)
103 {
104 if (optc == '?' || optc == 0)
105 {
106 fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
107 exit(1);
108 }
109
110 if (optc != LONG_OPTION_RETURN)
111 option_index = feGetOptIndex(optc);
112
113 assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
114
115 if (fe_optarg == NULL &&
116 (feOptSpec[option_index].type == feOptBool ||
117 feOptSpec[option_index].has_arg == optional_argument))
118 errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
119 else
120 errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
121 // not more than MAX_PROCESS cpus
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 switch(option_index)
136 {
137 case FE_OPT_DUMP_VERSIONTUPLE:
138 exit(0);
139 break;
140 default: ;
141 }
142 }
143 long cpus=(long)feOptValue(FE_OPT_CPUS);
144 #ifdef HAVE_VSPACE
146 {
148 feSetOptValue(FE_OPT_CPUS,cpus);
149 }
150 #endif
151
152 /* say hello */
153
154 if (TEST_V_QUIET)
155 {
156 (printf)(
157" SINGULAR /"
158#ifndef MAKE_DISTRIBUTION
159" Development"
160#endif
161"\n"
162" A Computer Algebra System for Polynomial Computations / version %s\n"
163" 0<\n"
164" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
165"FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n"
166, VERSION, VERSION_DATE);
167 if (feOptValue(FE_OPT_NO_SHELL))
168 {
169 WarnS("running in restricted mode:"
170 " shell invocation and file links are disallowed");
172 }
173 }
174 else
175 {
177 if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
178 dup2(1,2);
179 /* alternative:
180 * memcpy(stderr,stdout,sizeof(FILE));
181 */
182 }
183 if (feOptValue(FE_OPT_LOG)!=NULL)
184 {
185 int pid=getpid();
186 char *buf=(char*)malloc(10+strlen((char*) feOptSpec[FE_OPT_LOG].value));
187 snprintf(buf,10+strlen((char*) feOptSpec[FE_OPT_LOG].value),
188 "%s.%d",(char*) feOptSpec[FE_OPT_LOG].value,pid);
189 File_Log=fopen(buf,"w");
190 }
191
192#ifdef SINGULAR_PYOBJECT_SETUP_H
194#endif
195#ifdef SI_COUNTEDREF_AUTOLOAD
197#endif
198 errorreported = 0;
199
200 // -- example for "static" modules ------
201 //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
202 //module_help_main("huhu.so","Help for huhu\nhaha\n");
203 //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
204 setjmp(si_start_jmpbuf);
205
206 // Now, put things on the stack of stuff to do
207 // Last thing to do is to execute given scripts
208 if (fe_optind < argc)
209 {
210 int i = argc - 1;
211 FILE *fd;
212 while (i >= fe_optind)
213 {
214 if ((fd = feFopen(argv[i], "r")) == NULL)
215 {
216 Warn("Can not open %s", argv[i]);
217 }
218 else
219 {
220 fclose(fd);
221 newFile(argv[i]);
222 }
223 i--;
224 }
225 }
226 else
227 {
229 }
230
231 // before scripts, we execute -c, if it was given
232 if (feOptValue(FE_OPT_EXECUTE) != NULL)
233 newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
234
235 // first thing, however, is to load .singularrc from Singularpath
236 // and cwd/$HOME (in that order).
237 if (! feOptValue(FE_OPT_NO_RC))
238 {
239 char buf[MAXPATHLEN];
240 FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
241 if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
242 if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
243
244 if (rc != NULL)
245 {
246 if (BVERBOSE(V_LOAD_LIB))
247 Print("// ** executing %s\n", buf);
248 fclose(rc);
249 newFile(buf);
250 }
251 }
252
253 /* start shell */
255 {
257 char *linkname=(char*) feOptValue(FE_OPT_LINK);
258 if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
259 {
260 return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
261 //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
262 //exit(0);
263 }
264 else
265 {
266 Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
267 return 1;
268 }
269 }
270 setjmp(si_start_jmpbuf);
271 yyparse();
272 m2_end(0);
273 return 0;
274}
275
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void On(int sw)
switches
int i
Definition cfEzgcd.cc:132
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition cf_defs.h:39
VAR jmp_buf si_start_jmpbuf
Definition cntrlc.cc:98
VAR BOOLEAN singular_in_batchmode
Definition cntrlc.cc:62
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
Definition cntrlc.cc:530
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
void countedref_init()
Definition countedref.h:458
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition extra.cc:166
factory.h' is the user interface to Factory.
#define VERSION
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
VAR short errorreported
Definition feFopen.cc:23
feOptIndex
Definition feOptGen.h:15
@ FE_OPT_UNDEF
Definition feOptGen.h:15
#define LONG_OPTION_RETURN
Definition feOptTab.h:4
const char SHORT_OPTS_STRING[]
Definition feOpt.cc:29
feOptIndex feGetOptIndex(const char *name)
Definition feOpt.cc:104
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
EXTERN_VAR struct fe_option feOptSpec[]
Definition feOpt.h:17
VAR char * feArgv0
Definition feResource.cc:19
#define DIR_SEPP
Definition feResource.h:7
int fe_getopt_long(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
Definition fegetopt.c:664
char * fe_optarg
Definition fegetopt.c:94
int fe_optind
Definition fegetopt.c:109
@ feOptBool
Definition fegetopt.h:77
#define optional_argument
Definition fegetopt.h:101
char * fe_fgets_dummy(const char *, char *, int)
Definition feread.cc:455
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition fevoices.cc:166
VAR Voice * currentVoice
Definition fevoices.cc:49
VAR FILE * File_Log
Definition fevoices.cc:33
BOOLEAN newFile(char *fname)
Definition fevoices.cc:129
Voice * feInitStdin(Voice *pp)
Definition fevoices.cc:677
@ BT_execute
Definition fevoices.h:23
#define GLOBAL_VAR
Definition globaldefs.h:11
#define EXTERN_VAR
Definition globaldefs.h:6
int yyparse(void)
Definition grammar.cc:2149
#define assume(x)
Definition mod2.h:389
void m2_end(int i)
Definition misc_ip.cc:1106
static const int MAX_PROCESS
Definition vspace.h:1419
#define omStrDup(s)
#define freeSize
Definition omAllocFunc.c:15
#define malloc
Definition omAllocFunc.c:12
#define reallocSize
Definition omAllocFunc.c:17
#define omInitGetBackTrace()
#define NULL
Definition omList.c:12
#define MAXPATHLEN
Definition omRet2Info.c:22
#define BVERBOSE(a)
Definition options.h:35
#define TEST_V_QUIET
Definition options.h:135
#define V_LOAD_LIB
Definition options.h:47
int main()
void pyobject_setup()
initialize blackbox support for pyobject; functionilty os autoloaded on demand
int status int fd
Definition si_signals.h:69
int status int void * buf
Definition si_signals.h:69
#define SIPC_MAX_SEMAPHORES
Definition simpleipc.h:10
int name
New type name for int.
void siInit(char *)
Definition misc_ip.cc:1366
int mmInit(void)
Definition tesths.cc:50
#define omFreeSizeFunc
Definition xalloc.h:285
#define omReallocSizeFunc
Definition xalloc.h:286
#define omMallocFunc
Definition xalloc.h:284
#define omInitRet_2_Info(argv0)
Definition xalloc.h:274