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"
17
18#include "ipshell.h"
19#include "cntrlc.h"
20#include "links/silink.h"
21#include "ipid.h"
22#include "sdb.h"
23#include "feOpt.h"
24#include "misc/distrib.h"
25#include "mmalloc.h"
26#include "tok.h"
27#include "resources/fegetopt.h"
28
29#include "Singular/countedref.h"
31
32#include <unistd.h>
33#ifdef HAVE_NTL
34#include <NTL/config.h>
35#endif
36
37
38extern void siInit(char *);
39#ifdef PSINGULAR
41#endif
44
45int mmInit( void )
46{
47#ifndef X_OMALLOC
48#if defined(OMALLOC_USES_MALLOC)
49 /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
50 /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
51 /* do not rely on the default in Singular as libsingular may be different */
53#else
55#endif
56#endif
57 return 1;
58}
59
60/*0 implementation*/
61int main( /* main entry to Singular */
62 int argc, /* number of parameter */
63 char** argv) /* parameter array */
64{
65 mmInit();
66 // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
69
70#ifdef PSINGULAR
71 global_argv0 = argv[0];
72#endif
73 siInit(argv[0]);
75
76 // parse command line options
77 int optc, option_index;
78 const char* errormsg;
79 while((optc = fe_getopt_long(argc, argv,
81 != EOF)
82 {
83 if (optc == '?' || optc == 0)
84 {
85 fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
86 exit(1);
87 }
88
91
93
94 if (fe_optarg == NULL &&
98 else
100
101 if (errormsg)
102 {
103 if (fe_optarg == NULL)
104 fprintf(stderr, "Error: Option '--%s' %s\n",
106 else
107 fprintf(stderr, "Error: Option '--%s=%s' %s\n",
109 fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
110 exit(1);
111 }
112 if (optc == 'h') exit(0);
113 switch(option_index)
114 {
116 exit(0);
117 break;
118 default: ;
119 }
120 }
121
122 /* say hello */
123
124 if (TEST_V_QUIET)
125 {
126 (printf)(
127" SINGULAR /"
129" Development"
130#endif
131"\n"
132" A Computer Algebra System for Polynomial Computations / version %s\n"
133" 0<\n"
134" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
135"FB Mathematik der Universitaet, D-67653 Kaiserslautern \\ Debian " DEB_PKG_VERSION "\n"
138 {
139 WarnS("running in restricted mode:"
140 " shell invocation and links are disallowed");
142 }
143 }
144 else
145 {
148 dup2(1,2);
149 /* alternative:
150 * memcpy(stderr,stdout,sizeof(FILE));
151 */
152 }
154 {
155 int pid=getpid();
156 char *buf=(char*)malloc(10+strlen((char*) feOptSpec[FE_OPT_LOG].value));
157 sprintf(buf,"%s.%d",(char*) feOptSpec[FE_OPT_LOG].value,pid);
158 File_Log=fopen(buf,"w");
159 }
160
161#ifdef SINGULAR_PYOBJECT_SETUP_H
163#endif
164#ifdef SI_COUNTEDREF_AUTOLOAD
166#endif
167 errorreported = 0;
168
169 // -- example for "static" modules ------
170 //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
171 //module_help_main("huhu.so","Help for huhu\nhaha\n");
172 //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
174
175 // Now, put things on the stack of stuff to do
176 // Last thing to do is to execute given scripts
177 if (fe_optind < argc)
178 {
179 int i = argc - 1;
180 FILE *fd;
181 while (i >= fe_optind)
182 {
183 if ((fd = feFopen(argv[i], "r")) == NULL)
184 {
185 Warn("Can not open %s", argv[i]);
186 }
187 else
188 {
189 fclose(fd);
190 newFile(argv[i]);
191 }
192 i--;
193 }
194 }
195 else
196 {
198 }
199
200 // before scripts, we execute -c, if it was given
203
204 // first thing, however, is to load .singularrc from Singularpath
205 // and cwd/$HOME (in that order).
207 {
208 char buf[MAXPATHLEN];
209 FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
210 if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
211 if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
212
213 if (rc != NULL)
214 {
215 if (BVERBOSE(V_LOAD_LIB))
216 Print("// ** executing %s\n", buf);
217 fclose(rc);
218 newFile(buf);
219 }
220 }
221
222 /* start shell */
224 {
226 char *linkname=(char*) feOptValue(FE_OPT_LINK);
227 if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
228 {
229 return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
230 //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
231 //exit(0);
232 }
233 else
234 {
235 Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
236 return 1;
237 }
238 }
240 yyparse();
241 m2_end(0);
242 return 0;
243}
244
int BOOLEAN
Definition auxiliary.h:87
#define TRUE
Definition auxiliary.h:100
#define FALSE
Definition auxiliary.h:96
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:92
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:527
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
char name(const Variable &v)
Definition factory.h:189
#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
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:2111
#define assume(x)
Definition mod2.h:389
void m2_end(int i)
Definition misc_ip.cc:1097
#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:133
#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 void * buf
Definition si_signals.h:59
int status int fd
Definition si_signals.h:59
EXTERN_VAR FILE * File_Log
Definition tesths.cc:42
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition tesths.cc:43
void siInit(char *)
Definition misc_ip.cc:1370
int mmInit(void)
Definition tesths.cc:45
#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