Loading...
Searching...
No Matches
tesths.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT - initialize SINGULARs components, run Script and start SHELL
*/
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/options.h"
#include "factory/factory.h"
#include "kernel/oswrapper/feread.h"
#include "Singular/fevoices.h"
#include "kernel/oswrapper/timer.h"
#include "kernel/oswrapper/vspace.h"
#include "ipshell.h"
#include "cntrlc.h"
#include "links/silink.h"
#include "ipid.h"
#include "sdb.h"
#include "feOpt.h"
#include "misc/distrib.h"
#include "mmalloc.h"
#include "tok.h"
#include "resources/fegetopt.h"
#include "Singular/countedref.h"
#include "Singular/pyobject_setup.h"
#include <unistd.h>
#ifdef HAVE_NTL
#include <NTL/config.h>
#endif
#ifdef HAVE_SIMPLEIPC
#include "Singular/links/simpleipc.h"
#endif
extern void siInit(char *);
#ifdef PSINGULAR
GLOBAL_VAR char *global_argv0;
#endif
EXTERN_VAR FILE* File_Log;
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG;
int mmInit( void )
{
#ifndef X_OMALLOC
#if defined(OMALLOC_USES_MALLOC)
/* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
/* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
/* do not rely on the default in Singular as libsingular may be different */
mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
#else
mp_set_memory_functions(malloc,reallocSize,freeSize);
#endif
#endif
return 1;
}
/*0 implementation*/
int main( /* main entry to Singular */
int argc, /* number of parameter */
char** argv) /* parameter array */
{
mmInit();
// Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
omInitRet_2_Info(argv[0]);
omInitGetBackTrace();
#ifdef PSINGULAR
global_argv0 = argv[0];
#endif
// how many processes ? -----------------------------------------------------
{
int cpus=1;
int cpu_n;
#ifdef _SC_NPROCESSORS_ONLN
if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
#elif defined(_SC_NPROCESSORS_CONF)
if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
#endif
#ifdef HAVE_SIMPLEIPC
if (cpus>SIPC_MAX_SEMAPHORES) cpus=SIPC_MAX_SEMAPHORES;
#endif
feSetOptValue(FE_OPT_CPUS, cpus);
// how many threads ? -----------------------------------------------------
feSetOptValue(FE_OPT_THREADS, cpus);
}
siInit(argv[0]);
init_signals();
// parse command line options
int optc, option_index;
const char* errormsg;
while((optc = fe_getopt_long(argc, argv,
SHORT_OPTS_STRING, feOptSpec, &option_index))
!= EOF)
{
if (optc == '?' || optc == 0)
{
fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
exit(1);
}
if (optc != LONG_OPTION_RETURN)
option_index = feGetOptIndex(optc);
assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
if (fe_optarg == NULL &&
(feOptSpec[option_index].type == feOptBool ||
feOptSpec[option_index].has_arg == optional_argument))
errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
else
errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
// not more than MAX_PROCESS cpus
if (errormsg)
{
if (fe_optarg == NULL)
fprintf(stderr, "Error: Option '--%s' %s\n",
feOptSpec[option_index].name, errormsg);
else
fprintf(stderr, "Error: Option '--%s=%s' %s\n",
feOptSpec[option_index].name, fe_optarg, errormsg);
fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
exit(1);
}
if (optc == 'h') exit(0);
switch(option_index)
{
case FE_OPT_DUMP_VERSIONTUPLE:
exit(0);
break;
default: ;
}
}
long cpus=(long)feOptValue(FE_OPT_CPUS);
#ifdef HAVE_VSPACE
if (cpus>vspace::internals::MAX_PROCESS)
{
cpus=vspace::internals::MAX_PROCESS;
feSetOptValue(FE_OPT_CPUS,cpus);
}
#endif
/* say hello */
if (TEST_V_QUIET)
{
(printf)(
" SINGULAR /"
#ifndef MAKE_DISTRIBUTION
" Development"
#endif
"\n"
" A Computer Algebra System for Polynomial Computations / version %s\n"
" 0<\n"
" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
"FB Mathematik der Universitaet, D-67653 Kaiserslautern \\ Debian " DEB_PKG_VERSION "\n"
, VERSION, VERSION_DATE);
if (feOptValue(FE_OPT_NO_SHELL))
{
WarnS("running in restricted mode:"
" shell invocation and file links are disallowed");
FE_OPT_NO_SHELL_FLAG=TRUE;
}
}
else
{
FE_OPT_NO_SHELL_FLAG=FALSE;
if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
dup2(1,2);
/* alternative:
* memcpy(stderr,stdout,sizeof(FILE));
*/
}
if (feOptValue(FE_OPT_LOG)!=NULL)
{
int pid=getpid();
char *buf=(char*)malloc(10+strlen((char*) feOptSpec[FE_OPT_LOG].value));
snprintf(buf,10+strlen((char*) feOptSpec[FE_OPT_LOG].value),
"%s.%d",(char*) feOptSpec[FE_OPT_LOG].value,pid);
File_Log=fopen(buf,"w");
}
#ifdef SINGULAR_PYOBJECT_SETUP_H
pyobject_setup();
#endif
#ifdef SI_COUNTEDREF_AUTOLOAD
countedref_init();
#endif
errorreported = 0;
// -- example for "static" modules ------
//load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
//module_help_main("huhu.so","Help for huhu\nhaha\n");
//module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
setjmp(si_start_jmpbuf);
// Now, put things on the stack of stuff to do
// Last thing to do is to execute given scripts
if (fe_optind < argc)
{
int i = argc - 1;
FILE *fd;
while (i >= fe_optind)
{
if ((fd = feFopen(argv[i], "r")) == NULL)
{
Warn("Can not open %s", argv[i]);
}
else
{
fclose(fd);
newFile(argv[i]);
}
i--;
}
}
else
{
currentVoice=feInitStdin(NULL);
}
// before scripts, we execute -c, if it was given
if (feOptValue(FE_OPT_EXECUTE) != NULL)
newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
// first thing, however, is to load .singularrc from Singularpath
// and cwd/$HOME (in that order).
if (! feOptValue(FE_OPT_NO_RC))
{
char buf[MAXPATHLEN];
FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
if (rc != NULL)
{
if (BVERBOSE(V_LOAD_LIB))
Print("// ** executing %s\n", buf);
fclose(rc);
newFile(buf);
}
}
/* start shell */
if (fe_fgets_stdin==fe_fgets_dummy)
{
singular_in_batchmode=TRUE;
char *linkname=(char*) feOptValue(FE_OPT_LINK);
if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
{
return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
//Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
//exit(0);
}
else
{
Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
return 1;
}
}
setjmp(si_start_jmpbuf);
yyparse();
m2_end(0);
return 0;
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
On
void On(int sw)
switches
Definition canonicalform.cc:1957
i
int i
Definition cfEzgcd.cc:132
SW_USE_NTL_SORT
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition cf_defs.h:39
si_start_jmpbuf
VAR jmp_buf si_start_jmpbuf
Definition cntrlc.cc:98
singular_in_batchmode
VAR BOOLEAN singular_in_batchmode
Definition cntrlc.cc:62
init_signals
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
Definition cntrlc.cc:530
cntrlc.h
countedref.h
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
countedref_init
void countedref_init()
Definition countedref.h:458
distrib.h
Print
#define Print
Definition emacs.cc:80
Warn
#define Warn
Definition emacs.cc:77
WarnS
#define WarnS
Definition emacs.cc:78
FE_OPT_NO_SHELL_FLAG
EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG
Definition extra.cc:166
factory.h
factory.h' is the user interface to Factory.
name
char name(const Variable &v)
Definition factory.h:189
VERSION
#define VERSION
Definition factoryconf.h:277
feFopen
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
errorreported
VAR short errorreported
Definition feFopen.cc:23
feOptIndex
feOptIndex
Definition feOptGen.h:15
FE_OPT_UNDEF
@ FE_OPT_UNDEF
Definition feOptGen.h:15
LONG_OPTION_RETURN
#define LONG_OPTION_RETURN
Definition feOptTab.h:4
SHORT_OPTS_STRING
const char SHORT_OPTS_STRING[]
Definition feOpt.cc:29
feGetOptIndex
feOptIndex feGetOptIndex(const char *name)
Definition feOpt.cc:104
feSetOptValue
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition feOpt.cc:154
feOpt.h
feOptValue
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
feOptSpec
EXTERN_VAR struct fe_option feOptSpec[]
Definition feOpt.h:17
feArgv0
VAR char * feArgv0
Definition feResource.cc:19
DIR_SEPP
#define DIR_SEPP
Definition feResource.h:7
fe_getopt_long
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
fe_optarg
char * fe_optarg
Definition fegetopt.c:94
fe_optind
int fe_optind
Definition fegetopt.c:109
fegetopt.h
feOptBool
@ feOptBool
Definition fegetopt.h:77
optional_argument
#define optional_argument
Definition fegetopt.h:101
fe_fgets_dummy
char * fe_fgets_dummy(const char *, char *, int)
Definition feread.cc:455
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
feread.h
newBuffer
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition fevoices.cc:166
currentVoice
VAR Voice * currentVoice
Definition fevoices.cc:49
File_Log
VAR FILE * File_Log
Definition fevoices.cc:33
newFile
BOOLEAN newFile(char *fname)
Definition fevoices.cc:129
feInitStdin
Voice * feInitStdin(Voice *pp)
Definition fevoices.cc:677
fevoices.h
BT_execute
@ BT_execute
Definition fevoices.h:23
GLOBAL_VAR
#define GLOBAL_VAR
Definition globaldefs.h:11
EXTERN_VAR
#define EXTERN_VAR
Definition globaldefs.h:6
yyparse
int yyparse(void)
Definition grammar.cc:2149
ipid.h
ipshell.h
mmalloc.h
mod2.h
assume
#define assume(x)
Definition mod2.h:389
m2_end
void m2_end(int i)
Definition misc_ip.cc:1104
vspace::internals::MAX_PROCESS
static const int MAX_PROCESS
Definition vspace.h:1419
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
freeSize
#define freeSize
Definition omAllocFunc.c:15
malloc
#define malloc
Definition omAllocFunc.c:12
reallocSize
#define reallocSize
Definition omAllocFunc.c:17
omInitGetBackTrace
#define omInitGetBackTrace()
Definition omGetBackTrace.h:14
NULL
#define NULL
Definition omList.c:12
MAXPATHLEN
#define MAXPATHLEN
Definition omRet2Info.c:22
omalloc.h
options.h
BVERBOSE
#define BVERBOSE(a)
Definition options.h:35
TEST_V_QUIET
#define TEST_V_QUIET
Definition options.h:135
V_LOAD_LIB
#define V_LOAD_LIB
Definition options.h:47
main
int main()
Definition p_Procs_Generate.cc:219
pyobject_setup
void pyobject_setup()
initialize blackbox support for pyobject; functionilty os autoloaded on demand
Definition pyobject_setup.cc:39
pyobject_setup.h
sdb.h
fd
int status int fd
Definition si_signals.h:69
buf
int status int void * buf
Definition si_signals.h:69
silink.h
ssiBatch
int ssiBatch(const char *host, const char *port)
Definition ssiLink.cc:3123
simpleipc.h
SIPC_MAX_SEMAPHORES
#define SIPC_MAX_SEMAPHORES
Definition simpleipc.h:10
siInit
void siInit(char *)
Definition misc_ip.cc:1364
mmInit
int mmInit(void)
Definition tesths.cc:50
timer.h
tok.h
vspace.h
omFreeSizeFunc
#define omFreeSizeFunc
Definition xalloc.h:285
omReallocSizeFunc
#define omReallocSizeFunc
Definition xalloc.h:286
omMallocFunc
#define omMallocFunc
Definition xalloc.h:284
omInitRet_2_Info
#define omInitRet_2_Info(argv0)
Definition xalloc.h:274