source: git/Singular/tesths.cc @ 0fb34ba

spielwiese
Last change on this file since 0fb34ba was 0fb34ba, checked in by Hans Schoenemann <hannes@…>, 13 years ago
start with dir Singular: fix includes and makefile
  • Property mode set to 100644
File size: 6.0 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[341696]4/* $Id$ */
[32df82]5
[0e1846]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>
[32df82]16#include <errno.h>
[b1dfaf]17#include <kernel/mod2.h>
[599326]18#include <Singular/tok.h>
[0fb34ba]19#include <misc/options.h>
[599326]20#include <Singular/ipshell.h>
21#include <kernel/febase.h>
22#include <Singular/cntrlc.h>
[b1dfaf]23#include <omalloc/omalloc.h>
[599326]24#include <Singular/silink.h>
25#include <Singular/ipid.h>
26#include <kernel/timer.h>
27#include <Singular/sdb.h>
28#include <kernel/fegetopt.h>
29#include <Singular/feOpt.h>
30#include <Singular/distrib.h>
31#include <Singular/version.h>
32#include <Singular/slInit.h>
[841fec]33#include <Singular/ssiLink.h>
[d315d69]34#include <Singular/bigintm.h>
[1cb879]35#include <Singular/pyobject_setup.h>
[5374da]36#include <omalloc/omalloc.h>
[1cb879]37
[3ec4fce]38#ifdef HAVE_FANS
[898605]39#include <kernel/bbcone.h>
[3ec4fce]40#include <kernel/bbfan.h>
41#endif
[c06a32]42
[43d6c5]43#ifdef HAVE_FACTORY
[fda54cc]44#define SI_DONT_HAVE_GLOBAL_VARS
[b1dfaf]45#include <factory/factory.h>
[43d6c5]46#endif
[40edb03]47
[3645fc]48extern int siInit(char *);
[b6e51b]49
[672783]50#if ! defined(LIBSINGULAR)
[896561]51int mmInit2( void )
[5374da]52{
53#if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC)
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  return 1;
62}
[896561]63int mmInit( void )
64{
65#ifndef SI_THREADS
66  return mmInit2();
67#else
68  return 1;
69#endif
70}
[5374da]71
[0e1846]72/*0 implementation*/
73int main(          /* main entry to Singular */
74    int argc,      /* number of parameter */
75    char** argv)   /* parameter array */
76{
[896561]77  //mmInit();
[c232af]78  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
79  omInitRet_2_Info(argv[0]);
80  omInitGetBackTrace();
81
[3645fc]82  siInit(argv[0]);
[d3b70ae]83  init_signals();
[eea2b0]84
85  // parse command line options
[3645fc]86  int optc, option_index;
87  const char* errormsg;
[9b4b45]88  while((optc = fe_getopt_long(argc, argv,
[c06a32]89                               SHORT_OPTS_STRING, feOptSpec, &option_index))
[eea2b0]90        != EOF)
[0e1846]91  {
[8c71e8]92    if (optc == '?' || optc == 0)
[0e1846]93    {
[c06a32]94      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
95      exit(1);
96    }
[e0d91c]97
[c06a32]98    if (optc != LONG_OPTION_RETURN)
99      option_index = feGetOptIndex(optc);
[eea2b0]100
[9b4b45]101    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
[8c71e8]102
103    if (fe_optarg == NULL &&
[c06a32]104        (feOptSpec[option_index].type == feOptBool ||
105         feOptSpec[option_index].has_arg == optional_argument))
106      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
107    else
108      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
[8c71e8]109
[c06a32]110    if (errormsg)
111    {
112      if (fe_optarg == NULL)
[8c71e8]113        fprintf(stderr, "Error: Option '--%s' %s\n",
[c06a32]114               feOptSpec[option_index].name, errormsg);
115      else
[8c71e8]116        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
[c06a32]117               feOptSpec[option_index].name, fe_optarg, errormsg);
118      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
119      exit(1);
[0e1846]120    }
[c06a32]121    if (optc == 'h') exit(0);
[0e1846]122  }
[c06a32]123
[726d50]124  /* say hello */
[3645fc]125  //for official version: not active
126  //bigintm_setup();
127
[6c4db17]128  if (TEST_V_QUIET)
[0e1846]129  {
[50cbdc]130    (printf)(
[1492bb]131"                     SINGULAR                                 /"
[3854a98]132#ifndef MAKE_DISTRIBUTION
[9a11fe]133"  Development"
[3854a98]134#endif
135"\n"
[1492bb]136" A Computer Algebra System for Polynomial Computations       /   version %s\n"
137"                                                           0<\n"
138" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
139"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
[49eeee]140, S_VERSION1,S_VERSION2);
[0e1846]141  }
142  else
143  {
[ff8601]144#ifdef HAVE_FACTORY
145    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
146#endif
[50cbdc]147#ifdef HAVE_SDB
[473707b]148    sdb_flags = 0;
[a3bc95e]149#endif
[f4edee]150    dup2(1,2);
[48ce9a]151    /* alternative:
152    *    memcpy(stderr,stdout,sizeof(FILE));
153    */
[0e1846]154  }
[595d47]155  pyobject_setup();
[d3b70ae]156#ifdef HAVE_FANS
157  bbcone_setup();
158  bbfan_setup();
159#endif /* HAVE_FANS */
[9ea9c6]160  errorreported = 0;
[c232af]161
[dfc6b54]162  setjmp(si_start_jmpbuf);
[eea2b0]163
164  // Now, put things on the stack of stuff to do
165  // Last thing to do is to execute given scripts
[c06a32]166  if (fe_optind < argc)
[057e93c]167  {
[eea2b0]168    int i = argc - 1;
[b7b08c]169    FILE *fd;
[c06a32]170    while (i >= fe_optind)
[eea2b0]171    {
[b7b08c]172      if ((fd = feFopen(argv[i], "r")) == NULL)
173      {
174        Warn("Can not open %s", argv[i]);
175      }
176      else
177      {
178        fclose(fd);
179        newFile(argv[i]);
180      }
[eea2b0]181      i--;
182    }
[057e93c]183  }
184  else
185  {
[3bd82d]186    currentVoice=feInitStdin(NULL);
[057e93c]187  }
[eea2b0]188
189  // before scripts, we execute -c, if it was given
[c06a32]190  if (feOptValue(FE_OPT_EXECUTE) != NULL)
[c232af]191    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
[eea2b0]192
[6123fa2]193  // first thing, however, is to load .singularrc from Singularpath
194  // and cwd/$HOME (in that order).
[c06a32]195  if (! feOptValue(FE_OPT_NO_RC))
[7def32f]196  {
[6123fa2]197    char buf[MAXPATHLEN];
[b6f537]198    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
199    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
200    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
[8c71e8]201
[b6f537]202    if (rc != NULL)
[7def32f]203    {
[b6f537]204      if (BVERBOSE(V_LOAD_LIB))
205        Print("// ** executing %s\n", buf);
[7def32f]206      fclose(rc);
[6123fa2]207      newFile(buf);
208    }
[7def32f]209  }
[eea2b0]210
[0e1846]211  /* start shell */
[f4edee]212  if (fe_fgets_stdin==fe_fgets_dummy)
[0e1846]213  {
[655e1f]214    singular_in_batchmode=TRUE;
[425e33c]215    char *linkname=(char*) feOptValue(FE_OPT_LINK);
216    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
217    {
218      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
219      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
220      //exit(0);
221    }
[6b32990]222    else
[425e33c]223    {
224    #ifdef HAVE_MPSR
225      BatchDoProc batch_do = slInitMPBatchDo();
226      if (batch_do != NULL)
227        return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
228                         (char*) feOptValue(FE_OPT_MPHOST));
229      else
230        return 1;
231    #else
232      assume(0);
233    #endif
234    }
[0e1846]235  }
[07dacd]236  setjmp(si_start_jmpbuf);
[0e1846]237  yyparse();
[057e93c]238  m2_end(0);
[0e1846]239  return 0;
240}
[a1ab2a]241#endif // not LIBSINGULAR
[c06a32]242
Note: See TracBrowser for help on using the repository browser.