[0e1846] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[3b1a83c] | 4 | /* $Id: tesths.cc,v 1.88 2001-10-23 14:04:26 Singular Exp $ */ |
---|
[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> |
---|
[0e1846] | 17 | #include "mod2.h" |
---|
| 18 | #include "tok.h" |
---|
| 19 | #include "ipshell.h" |
---|
[6a6dccc] | 20 | #include "sing_dld.h" |
---|
[0e1846] | 21 | #include "febase.h" |
---|
| 22 | #include "cntrlc.h" |
---|
[512a2b] | 23 | #include "omalloc.h" |
---|
[0e1846] | 24 | #include "silink.h" |
---|
[7def32f] | 25 | #include "ipid.h" |
---|
[ea986d] | 26 | #include "timer.h" |
---|
[473707b] | 27 | #include "sdb.h" |
---|
[c06a32] | 28 | #include "fegetopt.h" |
---|
| 29 | #include "feOpt.h" |
---|
| 30 | #include "distrib.h" |
---|
| 31 | #include "version.h" |
---|
[6b32990] | 32 | #include "slInit.h" |
---|
[c06a32] | 33 | |
---|
[43d6c5] | 34 | #ifdef HAVE_FACTORY |
---|
[fda54cc] | 35 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 36 | #include <factory.h> |
---|
[43d6c5] | 37 | #endif |
---|
[40edb03] | 38 | |
---|
[923c27] | 39 | char *singular_date=__DATE__ " " __TIME__; |
---|
| 40 | |
---|
[0e1846] | 41 | /*0 implementation*/ |
---|
| 42 | int main( /* main entry to Singular */ |
---|
| 43 | int argc, /* number of parameter */ |
---|
| 44 | char** argv) /* parameter array */ |
---|
| 45 | { |
---|
| 46 | #ifdef INIT_BUG |
---|
| 47 | jjInitTab1(); |
---|
| 48 | #endif |
---|
| 49 | #ifdef GENTABLE |
---|
[9c756f] | 50 | extern void ttGen1(); |
---|
| 51 | extern void ttGen2(); |
---|
| 52 | #ifndef __MWERKS__ |
---|
[a70441f] | 53 | extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables |
---|
[99965c5] | 54 | mpsr_ttGen(); |
---|
| 55 | #endif |
---|
[0e1846] | 56 | ttGen1(); |
---|
| 57 | ttGen2(); |
---|
| 58 | #else |
---|
[c232af] | 59 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
| 60 | omInitRet_2_Info(argv[0]); |
---|
| 61 | omInitGetBackTrace(); |
---|
| 62 | |
---|
[c06a32] | 63 | /* initialize components */ |
---|
| 64 | siRandomStart=inits(); |
---|
| 65 | feOptSpec[FE_OPT_RANDOM].value = (void*) siRandomStart; |
---|
[eea2b0] | 66 | int optc, option_index; |
---|
[c06a32] | 67 | char* errormsg; |
---|
[eea2b0] | 68 | |
---|
| 69 | // do this first, because -v might print version path |
---|
[c06a32] | 70 | feInitResources(argv[0]); |
---|
[eea2b0] | 71 | |
---|
| 72 | // parse command line options |
---|
[9b4b45] | 73 | while((optc = fe_getopt_long(argc, argv, |
---|
[c06a32] | 74 | SHORT_OPTS_STRING, feOptSpec, &option_index)) |
---|
[eea2b0] | 75 | != EOF) |
---|
[0e1846] | 76 | { |
---|
[8c71e8] | 77 | if (optc == '?' || optc == 0) |
---|
[0e1846] | 78 | { |
---|
[c06a32] | 79 | fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0); |
---|
| 80 | exit(1); |
---|
| 81 | } |
---|
[e0d91c] | 82 | |
---|
[c06a32] | 83 | if (optc != LONG_OPTION_RETURN) |
---|
| 84 | option_index = feGetOptIndex(optc); |
---|
[eea2b0] | 85 | |
---|
[9b4b45] | 86 | assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF); |
---|
[8c71e8] | 87 | |
---|
| 88 | if (fe_optarg == NULL && |
---|
[c06a32] | 89 | (feOptSpec[option_index].type == feOptBool || |
---|
| 90 | feOptSpec[option_index].has_arg == optional_argument)) |
---|
| 91 | errormsg = feSetOptValue((feOptIndex) option_index, (int) 1); |
---|
| 92 | else |
---|
| 93 | errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg); |
---|
[8c71e8] | 94 | |
---|
[c06a32] | 95 | if (errormsg) |
---|
| 96 | { |
---|
| 97 | if (fe_optarg == NULL) |
---|
[8c71e8] | 98 | fprintf(stderr, "Error: Option '--%s' %s\n", |
---|
[c06a32] | 99 | feOptSpec[option_index].name, errormsg); |
---|
| 100 | else |
---|
[8c71e8] | 101 | fprintf(stderr, "Error: Option '--%s=%s' %s\n", |
---|
[c06a32] | 102 | feOptSpec[option_index].name, fe_optarg, errormsg); |
---|
| 103 | fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0); |
---|
| 104 | exit(1); |
---|
[0e1846] | 105 | } |
---|
[c06a32] | 106 | if (optc == 'h') exit(0); |
---|
[0e1846] | 107 | } |
---|
[c06a32] | 108 | |
---|
[726d50] | 109 | /* say hello */ |
---|
[77ff8e] | 110 | { |
---|
[46d09b] | 111 | #ifdef HAVE_NAMESPACES |
---|
[bd4cb92] | 112 | namespaceroot->push(NULL, "Top", 0, TRUE); |
---|
[50cbdc] | 113 | idhdl h; |
---|
[3b1a83c] | 114 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
[77ff8e] | 115 | IDPACKAGE(h) = NSPACK(namespaceroot); |
---|
[daeb6d] | 116 | IDPACKAGE(h)->language = LANG_TOP; |
---|
[bd4cb92] | 117 | #endif /* HAVE_NAMESPACES */ |
---|
| 118 | #ifdef HAVE_NS |
---|
| 119 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
| 120 | currPack=basePack; |
---|
| 121 | idhdl h; |
---|
[3b1a83c] | 122 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
[bd4cb92] | 123 | IDPACKAGE(h)->language = LANG_TOP; |
---|
| 124 | IDPACKAGE(h)=basePack; |
---|
| 125 | currPackHdl=h; |
---|
[a3bc95e] | 126 | basePackHdl=h; |
---|
[46d09b] | 127 | #endif /* HAVE_NAMESPACES */ |
---|
[77ff8e] | 128 | } |
---|
[f4edee] | 129 | if (BVERBOSE(0)) |
---|
[0e1846] | 130 | { |
---|
[50cbdc] | 131 | (printf)( |
---|
[3854a98] | 132 | " SINGULAR /" |
---|
| 133 | #ifndef MAKE_DISTRIBUTION |
---|
[9a11fe] | 134 | " Development" |
---|
[3854a98] | 135 | #endif |
---|
| 136 | "\n" |
---|
[49e4cf] | 137 | " A Computer Algebra System for Polynomial Computations / version %s\n" |
---|
[0cb8c8] | 138 | " 0<\n" |
---|
[451bcd] | 139 | " by: G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n" |
---|
[0cb8c8] | 140 | "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n" |
---|
[49eeee] | 141 | , S_VERSION1,S_VERSION2); |
---|
[0e1846] | 142 | } |
---|
| 143 | else |
---|
| 144 | { |
---|
[50cbdc] | 145 | #ifdef HAVE_SDB |
---|
[473707b] | 146 | sdb_flags = 0; |
---|
[a3bc95e] | 147 | #endif |
---|
[9c756f] | 148 | #ifdef __MWERKS__ |
---|
[f4edee] | 149 | memcpy(stderr,stdout,sizeof(FILE)); |
---|
[0e1846] | 150 | #else |
---|
[f4edee] | 151 | dup2(1,2); |
---|
[0e1846] | 152 | #endif |
---|
| 153 | } |
---|
| 154 | slStandardInit(); |
---|
[c06a32] | 155 | dlInit(feArgv0); |
---|
[0e1846] | 156 | myynest=0; |
---|
[c06a32] | 157 | if (! feOptValue(FE_OPT_NO_STDLIB)) |
---|
[055021a] | 158 | { |
---|
[e54eb4] | 159 | int vv=verbose; |
---|
| 160 | verbose &= ~Sy_bit(V_LOAD_LIB); |
---|
[0a3ddd] | 161 | #ifdef HAVE_NAMESPACES |
---|
[c232af] | 162 | iiLibCmd(omStrDup("standard.lib"),TRUE, TRUE); |
---|
[0a3ddd] | 163 | #else /* HAVE_NAMESPACES */ |
---|
[c232af] | 164 | iiLibCmd(omStrDup("standard.lib"), TRUE); |
---|
[0a3ddd] | 165 | #endif /* HAVE_NAMESPACES */ |
---|
[e54eb4] | 166 | verbose=vv; |
---|
| 167 | } |
---|
[9ea9c6] | 168 | errorreported = 0; |
---|
[c232af] | 169 | |
---|
| 170 | // and again, ifdef OM_NDEBUG this call is undef'ed |
---|
| 171 | // otherwise, it marks all memory allocated so far as static |
---|
| 172 | // i.e. as memory which is not mention on omPrintUsedAddr: |
---|
[50cbdc] | 173 | //omMarkMemoryAsStatic(); |
---|
[c232af] | 174 | |
---|
[dfc6b54] | 175 | setjmp(si_start_jmpbuf); |
---|
[eea2b0] | 176 | |
---|
| 177 | // Now, put things on the stack of stuff to do |
---|
| 178 | // Last thing to do is to execute given scripts |
---|
[c06a32] | 179 | if (fe_optind < argc) |
---|
[057e93c] | 180 | { |
---|
[eea2b0] | 181 | int i = argc - 1; |
---|
[b7b08c] | 182 | FILE *fd; |
---|
[c06a32] | 183 | while (i >= fe_optind) |
---|
[eea2b0] | 184 | { |
---|
[b7b08c] | 185 | if ((fd = feFopen(argv[i], "r")) == NULL) |
---|
| 186 | { |
---|
| 187 | Warn("Can not open %s", argv[i]); |
---|
| 188 | } |
---|
| 189 | else |
---|
| 190 | { |
---|
| 191 | fclose(fd); |
---|
| 192 | newFile(argv[i]); |
---|
| 193 | } |
---|
[eea2b0] | 194 | i--; |
---|
| 195 | } |
---|
[057e93c] | 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
| 199 | currentVoice=feInitStdin(); |
---|
| 200 | } |
---|
[eea2b0] | 201 | |
---|
| 202 | // before scripts, we execute -c, if it was given |
---|
[c06a32] | 203 | if (feOptValue(FE_OPT_EXECUTE) != NULL) |
---|
[c232af] | 204 | newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute); |
---|
[eea2b0] | 205 | |
---|
[6123fa2] | 206 | // first thing, however, is to load .singularrc from Singularpath |
---|
| 207 | // and cwd/$HOME (in that order). |
---|
[c06a32] | 208 | if (! feOptValue(FE_OPT_NO_RC)) |
---|
[7def32f] | 209 | { |
---|
[6123fa2] | 210 | char buf[MAXPATHLEN]; |
---|
[b6f537] | 211 | FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf); |
---|
| 212 | if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf); |
---|
| 213 | if (rc == NULL) rc = feFopen(".singularrc", "r", buf); |
---|
[8c71e8] | 214 | |
---|
[b6f537] | 215 | if (rc != NULL) |
---|
[7def32f] | 216 | { |
---|
[b6f537] | 217 | if (BVERBOSE(V_LOAD_LIB)) |
---|
| 218 | Print("// ** executing %s\n", buf); |
---|
[7def32f] | 219 | fclose(rc); |
---|
[6123fa2] | 220 | newFile(buf); |
---|
| 221 | } |
---|
[7def32f] | 222 | } |
---|
[eea2b0] | 223 | |
---|
[0e1846] | 224 | /* start shell */ |
---|
[f4edee] | 225 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
[0e1846] | 226 | { |
---|
[d754b7] | 227 | #ifdef HAVE_MPSR |
---|
[6b32990] | 228 | BatchDoProc batch_do = slInitMPBatchDo(); |
---|
| 229 | if (batch_do != NULL) |
---|
| 230 | return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT), |
---|
| 231 | (char*) feOptValue(FE_OPT_MPHOST)); |
---|
| 232 | else |
---|
| 233 | return 1; |
---|
[d754b7] | 234 | #else |
---|
[eea2b0] | 235 | assume(0); |
---|
| 236 | #endif |
---|
[0e1846] | 237 | } |
---|
[07dacd] | 238 | setjmp(si_start_jmpbuf); |
---|
[0e1846] | 239 | yyparse(); |
---|
[057e93c] | 240 | m2_end(0); |
---|
[958e16] | 241 | #endif |
---|
[0e1846] | 242 | return 0; |
---|
| 243 | } |
---|
[c06a32] | 244 | |
---|