source: git/Singular/tesths.cc @ f5a3a23

spielwiese
Last change on this file since f5a3a23 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
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
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>
16#include <errno.h>
17#include <kernel/mod2.h>
18#include <Singular/tok.h>
19#include <misc/options.h>
20#include <Singular/ipshell.h>
21#include <kernel/febase.h>
22#include <Singular/cntrlc.h>
23#include <omalloc/omalloc.h>
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>
33#include <Singular/ssiLink.h>
34#include <Singular/bigintm.h>
35#include <Singular/pyobject_setup.h>
36#include <omalloc/omalloc.h>
37
38#ifdef HAVE_FANS
39#include <kernel/bbcone.h>
40#include <kernel/bbfan.h>
41#endif
42
43#ifdef HAVE_FACTORY
44#define SI_DONT_HAVE_GLOBAL_VARS
45#include <factory/factory.h>
46#endif
47
48extern int siInit(char *);
49
50#if ! defined(LIBSINGULAR)
51int mmInit2( void )
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}
63int mmInit( void )
64{
65#ifndef SI_THREADS
66  return mmInit2();
67#else
68  return 1;
69#endif
70}
71
72/*0 implementation*/
73int main(          /* main entry to Singular */
74    int argc,      /* number of parameter */
75    char** argv)   /* parameter array */
76{
77  //mmInit();
78  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
79  omInitRet_2_Info(argv[0]);
80  omInitGetBackTrace();
81
82  siInit(argv[0]);
83  init_signals();
84
85  // parse command line options
86  int optc, option_index;
87  const char* errormsg;
88  while((optc = fe_getopt_long(argc, argv,
89                               SHORT_OPTS_STRING, feOptSpec, &option_index))
90        != EOF)
91  {
92    if (optc == '?' || optc == 0)
93    {
94      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
95      exit(1);
96    }
97
98    if (optc != LONG_OPTION_RETURN)
99      option_index = feGetOptIndex(optc);
100
101    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
102
103    if (fe_optarg == NULL &&
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);
109
110    if (errormsg)
111    {
112      if (fe_optarg == NULL)
113        fprintf(stderr, "Error: Option '--%s' %s\n",
114               feOptSpec[option_index].name, errormsg);
115      else
116        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
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);
120    }
121    if (optc == 'h') exit(0);
122  }
123
124  /* say hello */
125  //for official version: not active
126  //bigintm_setup();
127
128  if (TEST_V_QUIET)
129  {
130    (printf)(
131"                     SINGULAR                                 /"
132#ifndef MAKE_DISTRIBUTION
133"  Development"
134#endif
135"\n"
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"
140, S_VERSION1,S_VERSION2);
141  }
142  else
143  {
144#ifdef HAVE_FACTORY
145    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
146#endif
147#ifdef HAVE_SDB
148    sdb_flags = 0;
149#endif
150    dup2(1,2);
151    /* alternative:
152    *    memcpy(stderr,stdout,sizeof(FILE));
153    */
154  }
155  pyobject_setup();
156#ifdef HAVE_FANS
157  bbcone_setup();
158  bbfan_setup();
159#endif /* HAVE_FANS */
160  errorreported = 0;
161
162  setjmp(si_start_jmpbuf);
163
164  // Now, put things on the stack of stuff to do
165  // Last thing to do is to execute given scripts
166  if (fe_optind < argc)
167  {
168    int i = argc - 1;
169    FILE *fd;
170    while (i >= fe_optind)
171    {
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      }
181      i--;
182    }
183  }
184  else
185  {
186    currentVoice=feInitStdin(NULL);
187  }
188
189  // before scripts, we execute -c, if it was given
190  if (feOptValue(FE_OPT_EXECUTE) != NULL)
191    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
192
193  // first thing, however, is to load .singularrc from Singularpath
194  // and cwd/$HOME (in that order).
195  if (! feOptValue(FE_OPT_NO_RC))
196  {
197    char buf[MAXPATHLEN];
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);
201
202    if (rc != NULL)
203    {
204      if (BVERBOSE(V_LOAD_LIB))
205        Print("// ** executing %s\n", buf);
206      fclose(rc);
207      newFile(buf);
208    }
209  }
210
211  /* start shell */
212  if (fe_fgets_stdin==fe_fgets_dummy)
213  {
214    singular_in_batchmode=TRUE;
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    }
222    else
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    }
235  }
236  setjmp(si_start_jmpbuf);
237  yyparse();
238  m2_end(0);
239  return 0;
240}
241#endif // not LIBSINGULAR
242
Note: See TracBrowser for help on using the repository browser.