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