Index: Singular/Makefile.in
===================================================================
--- Singular/Makefile.in	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/Makefile.in	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -66,9 +66,10 @@
 ###
 
+# normal C++ source files
 CXXSOURCES=grammar.cc scanner.cc algmap.cc attrib.cc binom.cc clapconv.cc \
-    clapmem.cc clapsing.cc claptmpl.cc cntrlc.cc \
-    extra.cc febase.cc feread.cc fehelp.cc feResource.cc feCmdLineOptions.cc\
+    clapmem.cc clapsing.cc cntrlc.cc\
+    extra.cc febase.cc feread.cc fehelp.cc feResource.cc feOpt.cc\
     ffields.cc hdegree.cc hilb.cc hutil.cc \
-    ideals.cc intvec.cc iparith.cc \
+    ideals.cc intvec.cc \
     ipassign.cc ipconv.cc ipid.cc iplib.cc \
     ipprint.cc ipshell.cc khstd.cc kstdfac.cc \
@@ -82,6 +83,6 @@
     sing_dld.cc sing_dbm.cc spolys.cc spolys0.cc \
     subexpr.cc syz.cc syz0.cc syz1.cc \
-    tesths.cc timer.cc weight.cc \
-    mpsr_Put.cc mpsr_PutPoly.cc mpsr_Tok.cc mpsr_GetPoly.cc \
+    timer.cc weight.cc \
+    mpsr_Put.cc mpsr_PutPoly.cc mpsr_GetPoly.cc \
     mpsr_Get.cc mpsr_GetMisc.cc mpsr_Error.cc \
     GMPrat.cc multicnt.cc npolygon.cc semic.cc spectrum.cc splist.cc \
@@ -90,8 +91,13 @@
     mpr_inout.cc mpr_base.cc mpr_numeric.cc
 
-CSOURCES=gmalloc.c mmalloc.c mmheap.c mmpage.c mmcheck.c  mmisc.c mmtables.c \
-    mmbt.c weight0.c find_exec.c getopt.c fereadl.c page.c
-
-SOURCES=${CSOURCES} ${CXXSOURCES} grammar.y scanner.l libparse.l spSpolyLoop.pl generate.pl
+# normal C source files
+CSOURCES=mmalloc.c mmheap.c mmpage.c mmcheck.c  mmisc.c mmtables.c \
+    mmbt.c weight0.c find_exec.c fegetopt.c fereadl.c page.c
+
+# special source files (need extra compiling and/or linking)
+ESOURCES=iparith.cc gmalloc.c tesths.cc mpsr_Tok.cc claptmpl.cc
+
+SOURCES=${CSOURCES} ${CXXSOURCES} ${ESOURCES} \
+	grammar.y scanner.l libparse.l spSpolyLoop.pl generate.pl
 
 HEADERS=algmap.h hutil.h lists.h stairc.h attrib.h ideals.h \
@@ -107,10 +113,11 @@
 	kstdfac.h mpsr_Get.h spolys.h \
 	kutil.h mpsr_Put.h spolys0.h sing_dld.h\
-	ndbm.h spSpolyLoop.h polys-impl.h polys-comp.h getopt.h libparse.h \
+	ndbm.h spSpolyLoop.h polys-impl.h polys-comp.h libparse.h \
         GMPrat.h multicnt.h npolygon.h semic.h spectrum.h splist.h multicnt.h \
 	pcv.h mod_raw.h kbuckets.h kbPolyProcs.h \
-	mpr_global.h mpr_inout.h mpr_base.h mpr_numeric.h 
-
-INCS=febase.inc polys.inc iparith.inc mpsr_Tok.inc spSpolyLoop.inc
+	mpr_global.h mpr_inout.h mpr_base.h mpr_numeric.h \
+	feOpt.h fegetopt.h
+
+INCS=febase.inc polys.inc iparith.inc mpsr_Tok.inc spSpolyLoop.inc feOpt.inc
 
 TESTS=${testdir}/comparecheck ${testdir}/fac_test.in ${testdir}/fac_test.out\
@@ -123,22 +130,5 @@
 	${INCS}
 
-OBJS=grammar.o scanner.o matpol.o binom.o mpr_complex.o gnumpfl.o gnumpc.o \
-     febase.o feread.o fehelp.o feResource.o timer.o intvec.o attrib.o lists.o\
-     longrat.o longrat0.o misc.o ring.o numbers.o maps.o\
-     hilb.o comm.o kstd1.o kstd2.o kutil.o khstd.o kstdfac.o modulop.o spolys.o\
-     ideals.o subexpr.o hdegree.o hutil.o ffields.o shortfl.o \
-     longalg.o spolys0.o syz.o syz0.o syz1.o weight.o weight0.o \
-     ipid.o ipshell.o iplib.o ipassign.o ipconv.o ipprint.o\
-     polys.o polys0.o polys1.o polys-impl.o extra.o sparsmat.o\
-     mminit.o mmtables.o mmalloc.o mmheap.o mmpage.o page.o \
-     mmisc.o mmcheck.o mmbt.o sing_dld.o sing_dbm.o silink.o \
-     sing_mp.o fglm.o fglmzero.o fglmvec.o fglmhom.o fglmgauss.o cntrlc.o \
-     algmap.o clapconv.o  clapmem.o clapsing.o claptmpl.o\
-     mpsr_Error.o mpsr_Put.o mpsr_PutPoly.o mpsr_GetPoly.o \
-     mpsr_Get.o mpsr_GetMisc.o ndbm.o spSpolyLoop.o libparse.o \
-     find_exec.o getopt.o fereadl.o  mod_raw.o sdb.o \
-     GMPrat.o multicnt.o npolygon.o semic.o spectrum.o splist.o \
-     pcv.o kbuckets.o kbPolyProcs.o \
-     mpr_inout.o mpr_base.o mpr_numeric.o
+OBJS := $(CXXSOURCES:.cc=.o) $(CSOURCES:.c=.o)
 
 # Singular libraries which go into distribution
@@ -179,16 +169,18 @@
 
 Singular: mod2.h Makefile version.h scanner.cc gmalloc.o \
-          ${OBJS} iparith.o mpsr_Tok.o tesths.cc libparse.cc 
-	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -o Singular \
-	tesths.cc iparith.o mpsr_Tok.o ${OBJS} ${LDFLAGS} ${LIBS} \
-	${LD_DYN_FLAGS} gmalloc.o ${LD_LIBC}
+          ${OBJS} iparith.o tesths.cc libparse.cc claptmpl.o
+	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} \
+	  -o Singular \
+	  tesths.cc iparith.o mpsr_Tok.o claptmpl.o\
+	  ${OBJS} ${LDFLAGS} ${LIBS} ${LD_DYN_FLAGS} \
+	  gmalloc.o ${LD_LIBC}
 
 Singular-static: mod2.h Makefile version.h scanner.cc  gmalloc.o \
-	        ${OBJS} iparith.o mpsr_Tok.o tesths.cc
+	        ${OBJS} iparith.o mpsr_Tok.o tesths.cc claptmpl.o
 	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} \
-	-o Singular-static \
-	tesths.cc iparith.o mpsr_Tok.o \
-	${OBJS} ${STATIC_LDFLAGS} ${LDFLAGS} ${LIBS} ${LD_DYN_FLAGS} \
-	gmalloc.o ${LD_LIBC}
+	  -o Singular-static \
+	  tesths.cc iparith.o mpsr_Tok.o claptmpl.o\
+	  ${OBJS} ${STATIC_LDFLAGS} ${LDFLAGS} ${LIBS} ${LD_DYN_FLAGS} \
+	  gmalloc.o ${LD_LIBC}
 
 iparith.o mpsr_Tok.o : iparith.inc mpsr_Tok.inc
@@ -197,7 +189,8 @@
 	${CXX} ${CXXFLAGS}  ${CPPFLAGS} ${DEFS} -c $<	
 
-iparith.inc mpsr_Tok.inc: gmalloc.o iparith.cc ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h
+iparith.inc mpsr_Tok.inc: gmalloc.o claptmpl.o iparith.cc \
+                          ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h
 	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -DGENTABLE \
-	     -o gentable iparith.cc tesths.cc mpsr_Tok.cc \
+	     -o gentable claptmpl.o iparith.cc tesths.cc mpsr_Tok.cc \
 	     ${OBJS} ${LDFLAGS} ${LIBS} gmalloc.o ${LD_LIBC}
 	./gentable
@@ -215,5 +208,5 @@
 version.h: ${SOURCES} ${HEADERS} Makefile.in mod2.h.in \
            configure.in
-	echo "#define SINGULAR_VERSION_ID " `date '+%Y%m%d%H'` >version.h
+	echo unsigned long feVersionId =  `date '+%Y%m%d%H'`\; >version.h
 
 kbPolyProcs.cc kbPolyProcs.dd : kbPolyProcs.pin 
@@ -235,6 +228,7 @@
 	${PERL5} spSpolyLoop.pl > spSpolyLoop.inc
 
-libparse: libparse_main.o utils.o getopt.o
-	${CXX} -o libparse libparse_main.o utils.o getopt.o
+
+libparse: libparse_main.o utils.o fegetopt.o
+	${CXX} -o libparse libparse_main.o utils.o fegetopt.o
 
 libparse_main.o: libparse.cc
@@ -248,6 +242,19 @@
 	${LEX} -I -Pyylp -olibparse.cc libparse.l
 
-ESingular: getopt.o feResource.cc mod2.h feCmdLineOptions.cc version.h emacs.cc
-	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${DEFS} -o ESingular emacs.cc getopt.o ${LDFLAGS} ${LIBS}
+ESingular: fegetopt.o feResource.cc mod2.h feOpt.cc version.h emacs.cc \
+           feOptES.inc
+	${CXX} ${CXXFLAGS} ${CPPFLAGS} ${DEFS} -o ESingular emacs.cc fegetopt.o ${LDFLAGS} ${LIBS}
+
+feOpt.h: feOpt.inc feOptES.inc
+
+feOpt.inc: feOpt.cc
+	$(CXX) -DGENERATE_OPTION_INDEX feOpt.cc
+	./a.out
+	rm a.out
+
+feOptES.inc: feOpt.cc
+	$(CXX) -DGENERATE_OPTION_INDEX -DESINGULAR feOpt.cc
+	./a.out
+	rm a.out
 
 src: scanner.cc grammar.h grammar.cc libparse.cc spSpolyLoop.inc
@@ -302,5 +309,5 @@
 
 clean:
-	-rm -f Singular Singularg Singularp Singularb libparse \
+	-rm -f Singular Singularg Singularp Singularb libparse feOpt*.inc\
             *.o *.og core *.op *.ob 
 
@@ -327,20 +334,18 @@
 
 Singular-bindist: ${OBJS} Makefile
-	echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
-	echo "#define MAKE_DISTRIBUTION	" >> version.h
+	echo "#define MAKE_DISTRIBUTION	" > distrib.h
 	${MAKE} Singular ESingular
 	strip Singular ESingular
 	${INSTALL} -s Singular Singular-bindist
 	${INSTALL} -s ESingular ESingular-bindist
-	echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
+	echo "#undef MAKE_DISTRIBUTION " > distrib.h
 
 Singular-static-bindist: ${OBJS} Makefile
-	echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
-	echo "#define MAKE_DISTRIBUTION	" >> version.h
+	echo "#define MAKE_DISTRIBUTION	" > distrib.h
 	${MAKE} Singular-static ESingular
 	strip Singular-static ESingular
 	mv Singular-static Singular-static-bindist
 	${INSTALL} -s ESingular ESingular-bindist
-	echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
+	echo "#undef MAKE_DISTRIBUTION " > distrib.h
 
 tar:
@@ -380,27 +385,9 @@
 ## 
 
-OBJG1=	grammar.og scanner.og matpol.og binom.og gnumpfl.og mpr_complex.og \
-     febase.og feread.og fehelp.og feResource.og timer.og intvec.og attrib.og lists.og \
-     gnumpc.og longrat.og longrat0.og misc.og ring.og numbers.og maps.og\
-     hilb.og comm.og kstd1.og kstd2.og kutil.og khstd.og kstdfac.og modulop.og \
-     spolys.og ideals.og subexpr.og hdegree.og hutil.og ffields.og shortfl.og \
-     longalg.og spolys0.og syz.og syz0.og syz1.og weight.og \
-     ipid.og ipshell.og iplib.og ipassign.og ipconv.og ipprint.og\
-     polys.og polys0.og polys1.og polys-impl.og extra.og\
-     mminit.og sing_dld.og sing_dbm.og silink.og sparsmat.og\
-     sing_mp.og fglm.og fglmzero.og fglmvec.og fglmgauss.og fglmhom.og\
-     algmap.og clapconv.og  clapmem.og clapsing.og cntrlc.og  sdb.og\
-     mpsr_Error.og mpsr_Put.og mpsr_PutPoly.og mpsr_GetPoly.og \
-     mpsr_Get.og mpsr_GetMisc.og \
-     ndbm.og spSpolyLoop.og libparse.og  mod_raw.og \
-     GMPrat.og multicnt.og npolygon.og semic.og spectrum.og splist.og \
-     mpr_inout.og mpr_base.og mpr_numeric.og \
-     pcv.og kbuckets.og kbPolyProcs.og
-
-OBJG2= mmalloc.og mmheap.og mmpage.og mmcheck.og mmbt.og page.og \
-     mmisc.og mmtables.og weight0.og find_exec.og getopt.og fereadl.og
-
-
-OBJG=$(OBJG1) $(OBJG2) claptmpl.og 
+OBJG1 := $(CXXSOURCES:.cc=.og) 
+OBJG2 := $(CSOURCES:.c=.og) 
+
+
+OBJG=$(OBJG1) $(OBJG2) 
 
 ##
@@ -410,5 +397,6 @@
 claptmpl.og: claptmpl.cc mod2.h
 	$(CXXG)  ${CXXFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@
-$(OBJG1): %.og: %.cc
+
+$(OBJG1) : %.og: %.cc
 	$(CXXG) ${CXXFLAGSG} ${CXXTEMPLFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@
 
@@ -416,7 +404,7 @@
 	$(CCG)  ${CFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@
 
-Singularg: scanner.cc gmalloc.og $(OBJG) iparith.og mpsr_Tok.og tesths.cc version.h 
+Singularg: scanner.cc gmalloc.og $(OBJG) iparith.og mpsr_Tok.og claptmpl.og tesths.cc version.h 
 	$(CXXG) ${CXXFLAGSG} ${CXXTEMPLFLAGSG} ${CPPFLAGS} ${DEFSG} -o Singularg \
-	tesths.cc iparith.og mpsr_Tok.og $(OBJG) ${LDFLAGS} ${LIBS} \
+	tesths.cc iparith.og mpsr_Tok.og claptmpl.og $(OBJG) ${LDFLAGS} ${LIBS} \
 	${LD_DYN_FLAGS} gmalloc.og
 
Index: Singular/cntrlc.cc
===================================================================
--- Singular/cntrlc.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/cntrlc.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: cntrlc.cc,v 1.24 1999-08-25 16:02:42 Singular Exp $ */
+/* $Id: cntrlc.cc,v 1.25 1999-09-20 18:03:43 obachman Exp $ */
 /*
 * ABSTRACT - interupt handling
@@ -12,5 +12,4 @@
 #include <stdlib.h>
 #include <signal.h>
-#include "version.h"
 #include "mod2.h"
 #include "tok.h"
@@ -109,5 +108,5 @@
 void sigsegv_handler(int sig, sigcontext s)
 {
-  fprintf(stderr,"Singular : signal %d (v: %d/%d):\n",sig,SINGULAR_VERSION,SINGULAR_VERSION_ID);
+  fprintf(stderr,"Singular : signal %d (v: %d/%lu):\n",sig,SINGULAR_VERSION,feVersionId);
   if (sig!=SIGINT)
   {
@@ -215,6 +214,6 @@
 void sigsegv_handler(int sig, int code, struct sigcontext *scp, char *addr)
 {
-  fprintf(stderr,"Singular : signal %d, code %d (v: %d/%d):\n",
-    sig,code,SINGULAR_VERSION,SINGULAR_VERSION_ID);
+  fprintf(stderr,"Singular : signal %d, code %d (v: %d/%lu):\n",
+    sig,code,SINGULAR_VERSION,feVersionId);
   if ((sig!=SIGINT)&&(sig!=SIGABRT))
   {
@@ -259,6 +258,6 @@
 void sigsegv_handler(int sig)
 {
-  fprintf(stderr,"Singular : signal %d (v: %d/%d):\n",
-    sig,SINGULAR_VERSION,SINGULAR_VERSION_ID);
+  fprintf(stderr,"Singular : signal %d (v: %d/%lu):\n",
+    sig,SINGULAR_VERSION,feVersionId);
   if (sig!=SIGINT)
   {
Index: Singular/emacs.cc
===================================================================
--- Singular/emacs.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/emacs.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: emacs.cc,v 1.7 1999-09-07 08:36:09 Singular Exp $ */
+/* $Id: emacs.cc,v 1.8 1999-09-20 18:03:43 obachman Exp $ */
 /*
 * ABSTRACT: Esingular main file
@@ -50,6 +50,6 @@
   Warn("Bug occured at %s:%d ", file, line);
   Warn("Message: %s ", msg);
-  Warn("Version: " S_UNAME S_VERSION1 " (%d) " __DATE__ __TIME__,
-       SINGULAR_VERSION_ID);
+  Warn("Version: " S_UNAME S_VERSION1 " (%lu) " __DATE__ __TIME__,
+       feVersionId);
 }
 
@@ -63,5 +63,10 @@
 }
 #include "feResource.cc"
-#include "feCmdLineOptions.cc"
+#include "feOpt.cc"
+
+void mainUsage()
+{
+  fprintf(stderr, "Use `%s --help' for a complete list of options\n", feArgv0);
+}
 
 int main(int argc, char** argv)
@@ -83,6 +88,6 @@
   int optc, option_index;
   
-  while ((optc = getopt_long(argc, argv, SHORT_OPTS_STRING, 
-                             longopts, &option_index))
+  while ((optc = fe_getopt_long_only(argc, argv, SHORT_OPTS_STRING, 
+                                     feOptSpec, &option_index))
         != EOF)
   {
@@ -90,46 +95,51 @@
     {
         case 'h':
-          mainHelp(argv[0]);
+          feOptHelp(feArgv0);
           exit(0);
           
         case '?':
         case ':':
-          mainUsage(argv[0]);
+        case '\0':
+          mainUsage();
           exit(1);
 
         case  LONG_OPTION_RETURN:
-          if (strcmp(longopts[option_index].name, LON_EMACS) == 0)
+        {
+          switch(option_index)
           {
-            emacs = optarg;
-          }
-          else if (strcmp(longopts[option_index].name, LON_EMACS_DIR) == 0)
-          {
-            emacs_dir = optarg;
-          }
-          else if (strcmp(longopts[option_index].name, LON_EMACS_LOAD) == 0)
-          {
-            emacs_load = optarg;
-          }
-          else if (strcmp(longopts[option_index].name, LON_SINGULAR) == 0)
-          {
-            singular = optarg;
-          }
-          else if (strcmp(longopts[option_index].name, LON_NO_EMACS_CALL) == 0)
-          {
-            no_emacs_call = 1;
-          }
-          else
-          {
-            break;
+              case FE_OPT_EMACS:
+                emacs = fe_optarg;
+                break;
+                
+              case FE_OPT_EMACS_DIR:
+                emacs_dir = fe_optarg;
+                break;
+                
+              case FE_OPT_EMACS_LOAD:
+                emacs_load = fe_optarg;
+                break;
+                
+              case FE_OPT_SINGULAR:
+                singular = fe_optarg;
+                break;
+
+              case FE_OPT_NO_EMACS_CALL:
+                no_emacs_call = 1;
+                break;
+                
+              default:
+                goto NEXT;
           }
           // delete options from option-list
-          if (optind > 2 && *argv[optind-1] != '-' && 
-              optarg != NULL && longopts[option_index].has_arg)
+          if (fe_optind > 2 && *argv[fe_optind-1] != '-' && 
+              fe_optarg != NULL && feOptSpec[option_index].has_arg)
           {
-            argv[optind-2] = NULL;
+            argv[fe_optind-2] = NULL;
           }
-          argv[optind-1] = NULL;
-    }
-  } 
+          argv[fe_optind-1] = NULL;
+        }
+    }
+    NEXT:{}
+  }
   
   // make sure  emacs, singular, emacs_dir, emacs_load are set
@@ -139,5 +149,5 @@
     fprintf(stderr, "Error: Can't find emacs executable. \nExpected it at %s\n. Specify alternative with --emacs option,\n or set EMACS environment variable.\n", 
             feResourceDefault("emacs"));
-    mainUsage(argv[0]);
+    mainUsage();
     exit(1);
   }
@@ -148,5 +158,5 @@
     fprintf(stderr, "Error: Can't find singular executable.\nExpected it at %s\nSpecify with --singular option,\n  or set SINGULAR_EMACS environment variable.\n", 
             feResourceDefault("SingularEmacs"));
-    mainUsage(argv[0]);
+    mainUsage();
     exit(1);
   }
@@ -157,5 +167,5 @@
     fprintf(stderr, "Error: Can't find emacs directory for Singular lisp files. \nExpected it at %s\nSpecify with --emacs_dir option,\n  or set SINGULAR_EMACS_DIR environment variable.\n", 
             feResourceDefault("EmacsDir"));
-    mainUsage(argv[0]);
+    mainUsage();
     exit(1);
   }
@@ -182,5 +192,5 @@
           fprintf(stderr, "Error: Can't find emacs load file for Singular mode. \nExpected it at %s\nSpecify with --emacs_load option,\n or set SINGULAR_EMACS_LOAD environment variable,\n or put file '.emacs-singular' in your home directory.\n", 
                   feResourceDefault("EmacsLoad"));  
-          mainUsage(argv[0]);
+          mainUsage();
           exit(1);
         }
@@ -232,5 +242,5 @@
     {
       fprintf(stderr, "Error: Executation of\n%s\n");
-      mainUsage(argv[0]);
+      mainUsage();
       exit(1);
     }
Index: Singular/extra.cc
===================================================================
--- Singular/extra.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/extra.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR      *
 *****************************************/
-/* $Id: extra.cc,v 1.103 1999-08-20 16:06:49 Singular Exp $ */
+/* $Id: extra.cc,v 1.104 1999-09-20 18:03:43 obachman Exp $ */
 /*
 * ABSTRACT: general interface to internals of Singular ("system" command)
@@ -49,4 +49,6 @@
 #include "syz.h"
 #include "sdb.h"
+#include "feOpt.h"
+#include "distrib.h"
 
 // Define to enable many more system commands
@@ -237,5 +239,5 @@
       res->rtyp = STRING_CMD;
       char* b = StringSetS("");
-      feStringAppendBrowsers(1);
+      feStringAppendBrowsers(0);
       res->data = mstrdup(b);
       return FALSE;
@@ -316,56 +318,62 @@
     if (strstr(sys_cmd, "--") == sys_cmd)
     {
-      BOOLEAN mainGetSingOptionValue(const char* name, char** result);
-      char* val;
-
-      if (h != NULL)
-      {
-        if (strcmp(sys_cmd, "--browser") == 0)
-        {
-          if (h->Typ() == STRING_CMD)
-          {
-            if (strcmp(feHelpBrowser((char*) h->Data(), 1),
-                       (char*) h->Data()) != 0)
-            {
-              Werror("Can not set HelpBrowser to '%s'", (char*) h->Data());
-              return TRUE;
-            }
-          }
+      if (strcmp(sys_cmd, "--") == 0)
+      {
+        fePrintOptValues();
+        return FALSE;
+      }
+      
+      feOptIndex opt = feGetOptIndex(&sys_cmd[2]);
+      if (opt == FE_OPT_UNDEF)
+      {
+        Werror("Unknown option %s", sys_cmd);
+        Werror("Use 'system(\"--\");' for listing of available options");
+        return TRUE;
+      }
+      
+      if (h == NULL)
+      {
+        if (feOptSpec[opt].type == feOptString)
+        {
+          res->rtyp = STRING_CMD;
+          if (feOptSpec[opt].value != NULL)
+            res->data = mstrdup((char*) feOptSpec[opt].value);
           else
-          {
-            Werror("Need string to set HelpBrowser");
-            return TRUE;
-          }
+            res->data = mstrdup("");
         }
         else
         {
-          Werror("Can not set value of option %s", sys_cmd);
+          res->rtyp = INT_CMD;
+          res->data = feOptSpec[opt].value;
+        }
+        return FALSE;
+      }
+      
+      if (h->Typ() != STRING_CMD && 
+          h->Typ() != INT_CMD)
+      {
+        Werror("Need string or int argument to set option value");
+        return TRUE;
+      }
+      char* errormsg;
+      if (h->Typ() == INT_CMD)
+      {
+        if (feOptSpec[opt].type == feOptString)
+        {
+          Werror("Need string argument to set value of option %s", sys_cmd);
           return TRUE;
         }
-      }
-
-      if (mainGetSingOptionValue(&(sys_cmd)[2], &val))
-      {
-        if ((unsigned int) val > 1)
-        {
-          res->rtyp=STRING_CMD;
-          if (strcmp(sys_cmd, "--browser") == 0 &&
-              (val == NULL || *val == '\0'))
-            res->data = (void*) mstrdup(feHelpBrowser());
-          else
-            res->data = (void*) mstrdup( val );
-        }
-        else
-        {
-          res->rtyp=INT_CMD;
-          res->data=(void *)val;
-        }
-        return FALSE;
-      }
-      else
-      {
-        Werror("Unknown option %s\n", sys_cmd);
-        return TRUE;
-      }
+        errormsg = feSetOptValue(opt, (int) h->Data());
+        if (errormsg != NULL) 
+          Werror("Option '--%s=%d' %s", sys_cmd, (int) h->Data(), errormsg);
+      }
+      else
+      {
+        errormsg = feSetOptValue(opt, (char*) h->Data());
+        if (errormsg != NULL)
+          Werror("Option '--%s=%s' %s", sys_cmd, (char*) h->Data(), errormsg);
+      }
+      if (errormsg != NULL) return TRUE;
+      return FALSE;
     }
     else
@@ -1005,14 +1013,4 @@
     }
     else
-/*==================== print all option values =================*/
-#ifndef NDEBUG
-    if (strcmp(sys_cmd, "options") == 0)
-    {
-      void mainOptionValues();
-      mainOptionValues();
-      return FALSE;
-    }
-    else
-#endif
 /*==================== GF =================*/
 #if 0
Index: Singular/feOpt.cc
===================================================================
--- Singular/feOpt.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
+++ Singular/feOpt.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -0,0 +1,516 @@
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+/* $Id: feOpt.cc,v 1.1 1999-09-20 18:03:45 obachman Exp $ */
+/*
+* ABSTRACT: Implementation of option buisness
+*/
+
+#include "mod2.h"
+#include "feOpt.h"
+
+// Define here which cmd-line options are recognized
+struct fe_option feOptSpec[] =
+{
+//
+//  Has to be of the form 
+//    {name, has_arg, flag, val,
+//     arg_name, help, type, value, set} 
+//  where:
+//
+//        name   is the name of the long option.
+// 
+//        has_arg
+//               is:  no_argument (or 0) if the option does not take
+//               an argument, required_argument (or 1) if the option
+//               requires  an  argument, or optional_argument (or 2)
+//               if the option takes an optional argument.
+// 
+//        flag   specifies how  results  are  returned  for  a  long
+//               option.    If  flag  is  NULL,  then  getopt_long()
+//               returns val.  (For example, the calling program may
+//               set  val to the equivalent short option character.)
+//               Otherwise, getopt_long() returns 0, and flag points
+//               to  a variable which is set to val if the option is
+//               found, but left unchanged  if  the  option  is  not
+//               found.
+//               SHOULD ALWAYS BE ZERO FOR SINGULAR
+// 
+//        val    is  the  value  to  return,  or  to  load  into the
+//               variable pointed to by flag.
+//               NEEDS TO BE LONG_OPTION_RETURN, for long option
+//                           short option char,  for short option
+//
+//        arg_name if set, uses this value as name for argument in 
+//                display of help
+//      
+//        help  one-line description of option
+//
+//        type  one of feOptBool, feOptInt, feOptString
+//
+//        value (default) value of option
+//         
+//       set   only relevant for feOptString: 
+//             1: if value different from default value
+//             0: otherwise      
+//
+// The order in which options are specified is the order in which 
+// their help is printed on -h
+//
+// Options whose hel starts with an "//" are considered undocumented,
+// i.e., their help is not printed on -h
+// 
+#ifdef ESINGULAR
+// options only relevant for ESINGULAR
+  {"emacs",         required_argument,  0,  LONG_OPTION_RETURN,
+   "EMACS",     "Use EMACS as emacs program to run Singular",          feOptString, 0,   0},
+
+  {"emacs-dir",         required_argument,  0,  LONG_OPTION_RETURN,
+   "DIR",       "Use DIR as directory to look for emacs lisp files",   feOptString, 0,   0},
+
+  {"emacs-load",        required_argument,  0,  LONG_OPTION_RETURN,
+   "FILE",      "Load FILE on emacs start-up, instead of default",     feOptString, 0,   0},
+  
+  {"singular",          required_argument,  0,  LONG_OPTION_RETURN,
+   "PROG",      "Start PROG as Singular program within emacs",         feOptString, 0,   0},
+
+  {"no-emacs-call",     no_argument,  0,  LONG_OPTION_RETURN,
+   0,          "Do not start emacs. Print emacs-call to stdout",       feOptBool,   0,   0},
+#endif
+
+#ifdef HAVE_MPSR
+  {"batch",             no_argument,  0,  'b',
+   0,          "Run in MP batch mode",                                 feOptBool,    0,     0},
+#endif
+
+  {"execute",           required_argument,  0,  'c',
+   "STRING",   "Execute STRING on start-up",                           feOptString, 0,   0},
+   
+  {"sdb",               no_argument,  0,  'd',
+   0,          "Enable source code debugger (experimental)",           feOptBool,    0,      0},
+
+  {"echo",              optional_argument, 0,  'e',
+   "VAL",       "Set value of variable `echo' to (integer) VAL",        feOptInt,    0,      0},
+   
+  {"help",              no_argument,  0,  'h',
+   0,          "Print help message and exit",                          feOptBool,    0,      0},
+
+  {"quiet",             no_argument,  0,  'q',
+   0,          "Do not print start-up banner and lib load messages",   feOptBool,    0,      0},
+
+  {"random",            required_argument,  0,  'r',
+   "SEED",     "Seed random generator with integer (integer) SEED",    feOptInt,    0,      0},
+
+  {"no-tty",            no_argument,  0,  't',
+   0,          "Do not redefine the terminal characteristics",         feOptBool,    0,      0},
+
+  {"user-option",       required_argument,  0,  'u',
+   "STRING",   "Return STRING on `system(\"--user-option\")'",         feOptString, 0,   0},
+
+  {"version",           no_argument,  0,  'v',
+   0,          "Print extended version and configuration info",        feOptBool,    0,      0},
+
+#ifdef HAVE_TCL
+  {"tclmode",           no_argument,  0,  'x',
+   0,          "Run in TCL mode, i.e., with TCL user interface",       feOptBool,    0,      0},
+#endif
+
+  {"browser",           required_argument,  0,  LONG_OPTION_RETURN,
+   "BROWSER",  "Display help in BROWSER ([x,tk]info, netscape)",       feOptString, 0,   0},
+
+#ifndef ESINGULAR
+  {"emacs",             no_argument,  0,  LONG_OPTION_RETURN,
+   0,          "Set defaults for running within emacs",                feOptBool,    0,      0},
+#endif
+
+  {"no-stdlib",         no_argument,  0,  LONG_OPTION_RETURN,
+   0,          "Do not load `standard.lib' on start-up",               feOptBool,    0,      0},
+  
+  {"no-rc",             no_argument,  0,  LONG_OPTION_RETURN,
+   0,          "Do not execute `.singularrc' file on start-up",        feOptBool,    0,      0},
+
+  {"no-warn",           no_argument,  0,  LONG_OPTION_RETURN,
+   0,          "Do not display warning messages",                      feOptBool,    0,      0},
+
+  {"no-out",            no_argument,  0,  LONG_OPTION_RETURN,
+   0,          "Suppress all output",                                  feOptBool,    0,      0},
+
+  {"min-time",          required_argument,  0,  LONG_OPTION_RETURN,
+  "SECS",     "Do not display times smaller than SECS (in seconds)",   feOptString, "0.5",  0}, 
+
+#ifdef HAVE_MPSR
+  {"mp-port",           required_argument,  0,  LONG_OPTION_RETURN,
+   "PORT",     "Use PORT number for MP conections",                    feOptString,    0,      0},
+
+  {"mp-host",           required_argument,  0,  LONG_OPTION_RETURN,
+   "HOST",     "Use HOST for MP connections",                          feOptString,    0,   0},
+#endif
+
+  {"ticks-per-sec",     required_argument,  0,  LONG_OPTION_RETURN,
+   "TICKS",     "Sets unit of timer to TICKS per second",               feOptInt,    (void*)1,      0},
+
+// undocumented options
+#ifdef HAVE_MPSR
+  {"mp-transp",         required_argument,  0,  LONG_OPTION_RETURN,
+   "TRANSP",    "// Use TRANSP for MP connections",                     feOptString,    0,   0},
+   
+  {"mp-mode",           required_argument,  0,  LONG_OPTION_RETURN,
+   "MODE",      "// Use MODE for MP connections",                       feOptString,    0,   0},
+#endif
+    
+// terminator -- do NOT remove
+  { 0, 0, 0, 0 , 0, 0, feOptInt, 0, 0}
+};
+
+const char SHORT_OPTS_STRING[] = "bdhqtvxec:r:u:";
+
+//////////////////////////////////////////////////////////////
+//
+// Generation of feOptIndex
+//
+#ifdef GENERATE_OPTION_INDEX
+
+#include <stdio.h>
+main()
+{
+  FILE* fd;
+#ifdef ESINGULAR
+  fd = fopen("feOptES.inc", "w");
+#else  
+  fd = fopen("feOpt.inc", "w");
+#endif
+
+  if (fd == NULL) exit(1);
+
+  int i = 0;
+  
+  fputs("typedef enum\n{\n  ", fd);
+  
+  while (feOptSpec[i].name != NULL)
+  {
+    const char* name = feOptSpec[i].name;
+    fputs("FE_OPT_", fd);
+    while (*name != 0)
+    {
+      if (*name == '-') 
+      {
+        putc('_', fd);
+      }
+      else if (*name >= 97 && *name <= 122)
+      {
+        putc(*name - 32, fd);
+      }
+      else
+      {
+        putc(*name, fd);
+      }
+      name++;
+    }
+    if (i == 0)
+    {
+      fputs("=0", fd);
+    }
+    i++;
+    fputs(",\n  ", fd);
+  }
+  
+  fprintf(fd, "FE_OPT_UNDEF\n} feOptIndex;\n");
+  fclose(fd);
+  exit(0);
+}
+
+#else // ! GENERATE_OPTION_INDEX
+
+///////////////////////////////////////////////////////////////
+//
+// Getting Values
+//
+
+feOptIndex feGetOptIndex(const char* name)
+{
+  int opt = 0;
+  
+  while (opt != (int) FE_OPT_UNDEF)
+  {
+    if (strcmp(feOptSpec[opt].name, name) == 0) 
+      return (feOptIndex) opt;
+    opt = opt + 1;
+  }
+  return FE_OPT_UNDEF;
+}
+
+feOptIndex feGetOptIndex(int optc)
+{
+  int opt = 0;
+  
+  if (optc == LONG_OPTION_RETURN) return FE_OPT_UNDEF;
+  
+  while (opt != (int) FE_OPT_UNDEF)
+  {
+    if (feOptSpec[opt].val == optc)
+      return (feOptIndex) opt;
+    opt = opt + 1;
+  }
+  return FE_OPT_UNDEF;
+}
+
+///////////////////////////////////////////////////////////////
+//
+// Setting Values
+//
+static void feOptHelp(const char* name);
+//
+// Return: NULL -- everything ok
+//         "error-string" on error
+#ifndef ESINGULAR
+#include "mmemory.h"
+#include "febase.h"
+#include "ipshell.h"
+#include "tok.h"
+#include "sdb.h"
+#include "cntrlc.h"
+#include "timer.h"
+
+#ifdef HAVE_FACTORY
+#define SI_DONT_HAVE_GLOBAL_VARS
+#include <factory.h>
+#endif
+#include <errno.h>
+
+static char* feOptAction(feOptIndex opt);
+char* feSetOptValue(feOptIndex opt, char* optarg)
+{
+  if (opt == FE_OPT_UNDEF) return "option undefined";
+  
+  if (feOptSpec[opt].type != feOptString)
+  {
+    if (optarg != NULL)
+    {
+      errno = 0;
+      feOptSpec[opt].value = (void*) strtol(optarg, NULL, 10);
+      if (errno) return "invalid integer argument";
+    }
+    else
+    {
+      feOptSpec[opt].value = (void*) 0;
+    }
+  }
+  else
+  {
+    assume(feOptSpec[opt].type == feOptString);
+    if (feOptSpec[opt].set && feOptSpec[opt].value != NULL)
+      FreeL(feOptSpec[opt].value);
+    if (optarg != NULL)
+      feOptSpec[opt].value = mstrdup(optarg);
+    else
+      feOptSpec[opt].value = NULL;
+    feOptSpec[opt].set = 1;
+  }
+  
+  return feOptAction(opt);
+}
+
+char* feSetOptValue(feOptIndex opt, int optarg)
+{
+  if (opt == FE_OPT_UNDEF) return "option undefined";
+  
+  if (feOptSpec[opt].type == feOptString)
+    return "option value needs to be a string";
+  
+  feOptSpec[opt].value = (void*) optarg;
+  return feOptAction(opt);
+}
+
+static char* feOptAction(feOptIndex opt)
+{
+  // do some special actions
+  switch(opt)
+  {
+#ifdef HAVE_MPSR
+      case FE_OPT_BATCH:
+        fe_fgets_stdin=fe_fgets_dummy;
+        return NULL;
+#endif
+
+      case FE_OPT_HELP:
+        feOptHelp(feArgv0);
+        return NULL;
+
+      case FE_OPT_QUIET:
+        verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
+        return NULL;
+
+      case FE_OPT_NO_TTY:
+#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
+        fe_fgets_stdin=fe_fgets;
+#endif
+        return NULL;
+
+      case FE_OPT_SDB:
+        sdb_flags = 1;
+        return NULL;
+
+      case FE_OPT_VERSION:
+        printf("Singular for %s version %s  (%lu)  %s %s\n",
+               S_UNAME, S_VERSION1,
+               feVersionId,__DATE__,__TIME__);
+        printf("with\n");
+        printf(versionString());
+        printf("\n\n");
+        return NULL;
+
+#ifdef HAVE_TCL
+      case FE_OPT_TCLMODE:
+        tclmode = TRUE;
+        fe_fgets_stdin=fe_fgets_tcl;
+        verbose|=Sy_bit(V_SHOW_MEM);
+        return NULL;
+#endif
+
+      case FE_OPT_ECHO:
+        si_echo = (int) feOptSpec[opt].value;
+        if (si_echo < 0 || si_echo > 9)
+          return "argument of option is not in valid range 0..9";
+        return NULL;
+        
+      case 'r':
+        siRandomStart = (unsigned int) feOptSpec[opt].value;
+#ifdef buildin_rand
+        siSeed=siRandomStart;
+#else
+        srand((unsigned int)siRandomStart);
+#endif
+#ifdef HAVE_FACTORY
+        factoryseed(siRandomStart);
+#endif
+        return NULL;
+
+      case FE_OPT_EMACS:
+        // print EmacsDir and InfoFile so that Emacs
+        // mode can pcik it up
+        Warn("EmacsDir: %s", (feResource('e' /*"EmacsDir"*/) != NULL ?
+                              feResource('e' /*"EmacsDir"*/) : ""));
+        Warn("InfoFile: %s", (feResource('i' /*"InfoFile"*/) != NULL ?
+                              feResource('i' /*"InfoFile"*/) : ""));
+        return NULL;
+
+      case FE_OPT_NO_WARN:
+        feWarn = FALSE;
+        return NULL;
+        
+      case FE_OPT_NO_OUT:
+        feOut = FALSE;
+        return NULL;
+
+      case FE_OPT_MIN_TIME:
+      {
+        double mintime = atof((char*) feOptSpec[FE_OPT_MIN_TIME].value);
+        if (mintime <= 0) return "invalid float argument";
+        SetMinDisplayTime(mintime);
+        return NULL;
+      }
+
+      case FE_OPT_BROWSER:
+        feHelpBrowser(feOptSpec[FE_OPT_BROWSER].value, 1);
+
+      case FE_OPT_TICKS_PER_SEC:
+      {
+        int ticks = (int) feOptSpec[opt].value;
+        if (ticks <= 0)
+          return "integer argument must be larger than 0";
+        SetTimerResolution(ticks);
+        return NULL;
+      }
+      default:
+        return NULL;
+  }
+}
+
+// Prints usage message
+void fePrintOptValues()
+{
+  int i = 0;
+
+  while (feOptSpec[i].name != 0)
+  {
+    if (feOptSpec[i].help != NULL
+#ifndef NDEBUG
+        && *(feOptSpec[i].help) != '/'
+#endif
+        )
+    {
+      if (feOptSpec[i].type == feOptString)
+      {
+        if (feOptSpec[i].value == NULL)
+        {
+          Print("// --%-15s\n", feOptSpec[i].name);
+        }
+        else
+        {
+          Print("// --%-15s \"%s\"\n", feOptSpec[i].name, (char*) feOptSpec[i].value);
+        }
+      }
+      else
+      {
+        Print("// --%-15s %d\n", feOptSpec[i].name, feOptSpec[i].value);
+      }
+    }
+    i++;
+  }
+}
+
+#endif // ! ESingular
+
+// Prints help message
+static void feOptHelp(const char* name)
+{
+  int i = 0;
+  char tmp[20];
+#ifdef ESINGULAR
+  printf("ESingular: A Program that starts-up Singular within emacs, for\n");
+#endif  
+  printf("Singular version %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1);
+  printf("   %s [options] [file1 [file2 ...]]\n", name);
+  printf("Options:\n");
+
+  while (feOptSpec[i].name != 0)
+  {
+    if (feOptSpec[i].help != NULL 
+#ifdef NDEBUG
+        && *(feOptSpec[i].help) != '/'
+#endif
+        )
+    {
+      if (feOptSpec[i].has_arg > 0)
+      {
+        if  (feOptSpec[i].has_arg > 1)
+          sprintf(tmp, "%s[=%s]", feOptSpec[i].name, feOptSpec[i].arg_name);
+        else
+          sprintf(tmp, "%s=%s", feOptSpec[i].name, feOptSpec[i].arg_name);
+
+        printf(" %c%c --%-19s %s\n",
+               (feOptSpec[i].val != 0 ? '-' : ' '),
+               (feOptSpec[i].val != 0 ? feOptSpec[i].val : ' '),
+               tmp,
+               feOptSpec[i].help);
+      }
+      else
+      {
+        printf(" %c%c --%-19s %s\n",
+               (feOptSpec[i].val != 0 ? '-' : ' '),
+               (feOptSpec[i].val != 0 ? feOptSpec[i].val : ' '),
+               feOptSpec[i].name,
+               feOptSpec[i].help);
+      }
+    }
+    i++;
+  }
+
+  printf("\nFor more information, type `help;' from within Singular or visit\n");
+  printf("http://www.mathematik.uni-kl.de/~zca/Singular or consult the\n");
+  printf("Singular manual (available as on-line info or printed manual).\n");
+}
+
+
+
+#endif // GENERATE_OPTION_INDEX
Index: Singular/feOpt.h
===================================================================
--- Singular/feOpt.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
+++ Singular/feOpt.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -0,0 +1,76 @@
+#ifndef FEOPTS_H
+#define FEOPTS_H
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+/* $Id: feOpt.h,v 1.1 1999-09-20 18:03:45 obachman Exp $ */
+/*
+* ABSTRACT: Declarations for working with Options
+*/
+
+#include "mod2.h"
+#include "fegetopt.h"
+
+extern const char SHORT_OPTS_STRING[];
+#define LONG_OPTION_RETURN 13 
+
+// specifies format of options
+extern struct fe_option feOptSpec[];
+
+#ifndef GENERATE_OPTION_INDEX
+
+// provides feOptIndex enum type for fast accesses to feOptSpec
+#ifndef GENTABLE
+#ifdef ESINGULAR
+#include "feOptES.inc"
+#else
+#include "feOpt.inc"
+#endif
+#else
+typedef enum {FE_OPT_UNDEF}  feOptIndex;
+#endif
+
+inline void* feOptValue(feOptIndex opt)
+{
+  return feOptSpec[(int)opt].value;
+}
+inline int feOptValue(feOptIndex opt, char** val)
+{
+  if (opt != FE_OPT_UNDEF && feOptSpec[(int)opt].type == feOptString) 
+  {
+    *val = (char*) feOptSpec[(int)opt].value;
+    return TRUE;
+  }
+  *val = NULL;
+  return FALSE;
+}
+inline int feOptValue(feOptIndex opt, int* val)
+{
+  if (opt != FE_OPT_UNDEF && feOptSpec[(int)opt].type != feOptString) 
+  {
+    *val = (int) feOptSpec[(int)opt].value;
+    return TRUE;
+  }
+  *val = 0;
+  return FALSE;
+}
+ 
+// maps name to otions
+feOptIndex feGetOptIndex(const char* name);
+feOptIndex feGetOptIndex(int optc);
+
+// Setting option values:
+// Return: NULL -- everything ok
+//         "error-string" on error
+
+// opt->type must be feOptInt or feOptBool
+char* feSetOptValue(feOptIndex opt, int optarg);
+// for opt->type != feOptString, optarg is converted
+// to an int
+char* feSetOptValue(feOptIndex opt, char* optarg);
+
+void fePrintOptValues();
+
+#endif // ! GENERATE_OPTION_INDEX
+
+#endif //  FEOPTS_H
Index: Singular/feResource.cc
===================================================================
--- Singular/feResource.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/feResource.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: feResource.cc,v 1.10 1999-08-25 16:02:46 Singular Exp $ */
+/* $Id: feResource.cc,v 1.11 1999-09-20 18:03:45 obachman Exp $ */
 /*
 * ABSTRACT: management of resources
@@ -9,7 +9,6 @@
 #include <unistd.h>
 
-#include "version.h"
 #include "mod2.h"
-#include "version.h"
+#include "distrib.h"
 #ifndef ESINGULAR
 #include "mmemory.h"
@@ -99,5 +98,5 @@
  *
  *****************************************************************/
-static char* feArgv0;
+char* feArgv0;
 #define MAXRESOURCELEN 5*MAXPATHLEN
 char fePathSep = 
@@ -194,5 +193,5 @@
   }
 #ifdef RESOURCE_DEBUG
-  printf("feInitResources: entering with argv0=%s=\n", argv0);
+  printf("feInitResources: entering with argv0=%s=\n", feArgv0);
 #endif
   // init some Resources
Index: Singular/febase.cc
===================================================================
--- Singular/febase.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/febase.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,10 +2,9 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: febase.cc,v 1.81 1999-08-25 16:02:46 Singular Exp $ */
+/* $Id: febase.cc,v 1.82 1999-09-20 18:03:46 obachman Exp $ */
 /*
 * ABSTRACT: i/o system
 */
 
-#include "version.h"
 #include "mod2.h"
 
@@ -362,6 +361,6 @@
   Warn("Bug occured at %s:%d", file, line);
   Warn("Message: %s", msg);
-  Warn("Version: " S_UNAME S_VERSION1 " (%d) " __DATE__ __TIME__,
-       SINGULAR_VERSION_ID);
+  Warn("Version: " S_UNAME S_VERSION1 " (%lu) " __DATE__ __TIME__,
+       feVersionId);
 }
 
Index: Singular/febase.h
===================================================================
--- Singular/febase.h	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/febase.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -4,5 +4,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: febase.h,v 1.36 1999-08-25 16:02:46 Singular Exp $ */
+/* $Id: febase.h,v 1.37 1999-09-20 18:03:47 obachman Exp $ */
 /*
 * ABSTRACT: basic i/o
@@ -148,14 +148,26 @@
 // display general help, otherwise
 void feHelp(char* str = NULL);
-// if browser != NULL or OptionValue("browser") != NULL 
+// if browser != NULL or feOpt("browser") != NULL 
 //    set HelpBrowser to browser 
 // otherwise, if browser was already set, leave as is, 
 //            if not, choose first available browser
 // return string identifying current browser
-// keeps OptionValue("browser") up-to-date
+// keeps feOpt("browser") up-to-date
 // Optional warn argument is as in feResource
 char* feHelpBrowser(char* browser = NULL, int warn = -1);
 void feStringAppendBrowsers(int warn = -1);
 
+/*****************************************************************
+ *
+ * version Id
+ *
+ *****************************************************************/
+extern unsigned long feVersionId;
+
+/*****************************************************************
+ *
+ * File Stuff
+ *
+ *****************************************************************/
 FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE);
 #ifndef __MWERKS__
Index: Singular/fegetopt.c
===================================================================
--- Singular/fegetopt.c	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
+++ Singular/fegetopt.c	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -0,0 +1,757 @@
+/****************************************
+*  Computer Algebra System SINGULAR     *
+****************************************/
+/* $Id: fegetopt.c,v 1.1 1999-09-20 18:03:47 obachman Exp $ */
+
+/* Getopt for GNU.
+   NOTE: getopt is now part of the C library, so if you don't know what
+   "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
+   before changing it!
+
+   Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94
+        Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+/* 
+   obachman 9/99: adapted to Singular by 
+    * adding prefix fe_ to global variables
+    * extended fe_option structure    
+*/
+
+
+#include "mod2.h"
+
+#ifndef __STDC__
+#  ifndef const
+#    define const
+#  endif
+#endif
+
+/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.  */
+#ifndef _NO_PROTO
+#define _NO_PROTO
+#endif
+
+#include <stdio.h>
+/* #include "tailor.h" */
+
+/* Comment out all this code if we are using the GNU C Library, and are not
+   actually compiling the library itself.  This code is part of the GNU C
+   Library, but also included in many other GNU distributions.  Compiling
+   and linking in this code is a waste when using the GNU C library
+   (especially if it is a shared library).  Rather than having every GNU
+   program understand `configure --with-gnu-libc' and omit the object files,
+   it is simpler to just do this in the source for each such file.  */
+
+/* This needs to come after some library #include
+   to get __GNU_LIBRARY__ defined.  */
+#ifdef  __GNU_LIBRARY__
+/* Don't include stdlib.h for non-GNU C libraries because some of them
+   contain conflicting prototypes for getopt.  */
+#include <stdlib.h>
+#endif  /* GNU C library.  */
+
+/* If GETOPT_COMPAT is defined, `+' as well as `--' can introduce a
+   long-named option.  Because this is not POSIX.2 compliant, it is
+   being phased out.  */
+/* #define GETOPT_COMPAT */
+
+/* This version of `getopt' appears to the caller like standard Unix `getopt'
+   but it behaves differently for the user, since it allows the user
+   to intersperse the options with the other arguments.
+
+   As `getopt' works, it permutes the elements of ARGV so that,
+   when it is done, all the options precede everything else.  Thus
+   all application programs are extended to handle flexible argument order.
+
+   Setting the environment variable POSIXLY_CORRECT disables permutation.
+   Then the behavior is completely standard.
+
+   GNU application programs can use a third alternative mode in which
+   they can distinguish the relative order of options and other arguments.  */
+
+#include "getopt.h"
+
+/* For communication from `getopt' to the caller.
+   When `getopt' finds an option that takes an argument,
+   the argument value is returned here.
+   Also, when `ordering' is RETURN_IN_ORDER,
+   each non-option ARGV-element is returned here.  */
+
+char *fe_optarg = 0;
+
+/* Index in ARGV of the next element to be scanned.
+   This is used for communication to and from the caller
+   and for communication between successive calls to `getopt'.
+
+   On entry to `getopt', zero means this is the first call; initialize.
+
+   When `getopt' returns EOF, this is the index of the first of the
+   non-option elements that the caller should itself scan.
+
+   Otherwise, `fe_optind' communicates from one call to the next
+   how much of ARGV has been scanned so far.  */
+
+/* XXX 1003.2 says this must be 1 before any call.  */
+int fe_optind = 0;
+
+/* The next char to be scanned in the option-element
+   in which the last option character we returned was found.
+   This allows us to pick up the scan where we left off.
+
+   If this is zero, or a null string, it means resume the scan
+   by advancing to the next ARGV-element.  */
+
+static char *nextchar;
+
+/* Callers store zero here to inhibit the error message
+   for unrecognized options.  */
+
+int fe_opterr = 1;
+
+/* Set to an option character which was unrecognized.
+   This must be initialized on some systems to avoid linking in the
+   system's own getopt implementation.  */
+
+#define BAD_OPTION '\0'
+int fe_optopt = BAD_OPTION;
+
+/* Describe how to deal with options that follow non-option ARGV-elements.
+
+   If the caller did not specify anything,
+   the default is REQUIRE_ORDER if the environment variable
+   POSIXLY_CORRECT is defined, PERMUTE otherwise.
+
+   REQUIRE_ORDER means don't recognize them as options;
+   stop option processing when the first non-option is seen.
+   This is what Unix does.
+   This mode of operation is selected by either setting the environment
+   variable POSIXLY_CORRECT, or using `+' as the first character
+   of the list of option characters.
+
+   PERMUTE is the default.  We permute the contents of ARGV as we scan,
+   so that eventually all the non-options are at the end.  This allows options
+   to be given in any order, even with programs that were not written to
+   expect this.
+
+   RETURN_IN_ORDER is an option available to programs that were written
+   to expect options and other ARGV-elements in any order and that care about
+   the ordering of the two.  We describe each non-option ARGV-element
+   as if it were the argument of an option with character code 1.
+   Using `-' as the first character of the list of option characters
+   selects this mode of operation.
+
+   The special argument `--' forces an end of option-scanning regardless
+   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
+   `--' can cause `getopt' to return EOF with `fe_optind' != ARGC.  */
+
+static enum
+{
+  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+} ordering;
+
+#ifdef  __GNU_LIBRARY__
+/* We want to avoid inclusion of string.h with non-GNU libraries
+   because there are many ways it can cause trouble.
+   On some systems, it contains special magic macros that don't work
+   in GCC.  */
+#include <string.h>
+#define my_index        strchr
+#define my_strlen       strlen
+#else
+
+/* Avoid depending on library functions or files
+   whose names are inconsistent.  */
+
+#if __STDC__ || defined(PROTO)
+extern char *getenv(const char *name);
+extern int  strcmp (const char *s1, const char *s2);
+/*extern int  strncmp(const char *s1, const char *s2, int n);*/
+
+static int my_strlen(const char *s);
+static char *my_index (const char *str, int chr);
+#else
+extern char *getenv ();
+#endif
+
+static int my_strlen (const char *str)
+{
+  int n = 0;
+  while (*str++)
+    n++;
+  return n;
+}
+
+static char * my_index (const char *str, int chr)
+{
+  while (*str)
+    {
+      if (*str == chr)
+        return (char *) str;
+      str++;
+    }
+  return 0;
+}
+
+#endif                          /* GNU C library.  */
+
+/* Handle permutation of arguments.  */
+
+/* Describe the part of ARGV that contains non-options that have
+   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
+   `last_nonopt' is the index after the last of them.  */
+
+static int first_nonopt;
+static int last_nonopt;
+
+/* Exchange two adjacent subsequences of ARGV.
+   One subsequence is elements [first_nonopt,last_nonopt)
+   which contains all the non-options that have been skipped so far.
+   The other is elements [last_nonopt,fe_optind), which contains all
+   the options processed since those non-options were skipped.
+
+   `first_nonopt' and `last_nonopt' are relocated so that they describe
+   the new indices of the non-options in ARGV after they are moved.
+
+   To perform the swap, we first reverse the order of all elements. So
+   all options now come before all non options, but they are in the
+   wrong order. So we put back the options and non options in original
+   order by reversing them again. For example:
+       original input:      a b c -x -y
+       reverse all:         -y -x c b a
+       reverse options:     -x -y c b a
+       reverse non options: -x -y a b c
+*/
+
+#if __STDC__ || defined(PROTO)
+static void exchange (char **argv);
+#endif
+
+static void exchange (char **argv)
+{
+  char *temp, **first, **last;
+
+  /* Reverse all the elements [first_nonopt, fe_optind) */
+  first = &argv[first_nonopt];
+  last  = &argv[fe_optind-1];
+  while (first < last) {
+    temp = *first; *first = *last; *last = temp; first++; last--;
+  }
+  /* Put back the options in order */
+  first = &argv[first_nonopt];
+  first_nonopt += (fe_optind - last_nonopt);
+  last  = &argv[first_nonopt - 1];
+  while (first < last) {
+    temp = *first; *first = *last; *last = temp; first++; last--;
+  }
+
+  /* Put back the non options in order */
+  first = &argv[first_nonopt];
+  last_nonopt = fe_optind;
+  last  = &argv[last_nonopt-1];
+  while (first < last) {
+    temp = *first; *first = *last; *last = temp; first++; last--;
+  }
+}
+
+/* Scan elements of ARGV (whose length is ARGC) for option characters
+   given in OPTSTRING.
+
+   If an element of ARGV starts with '-', and is not exactly "-" or "--",
+   then it is an option element.  The characters of this element
+   (aside from the initial '-') are option characters.  If `getopt'
+   is called repeatedly, it returns successively each of the option characters
+   from each of the option elements.
+
+   If `getopt' finds another option character, it returns that character,
+   updating `fe_optind' and `nextchar' so that the next call to `getopt' can
+   resume the scan with the following option character or ARGV-element.
+
+   If there are no more option characters, `getopt' returns `EOF'.
+   Then `fe_optind' is the index in ARGV of the first ARGV-element
+   that is not an option.  (The ARGV-elements have been permuted
+   so that those that are not options now come last.)
+
+   OPTSTRING is a string containing the legitimate option characters.
+   If an option character is seen that is not listed in OPTSTRING,
+   return BAD_OPTION after printing an error message.  If you set `fe_opterr' to
+   zero, the error message is suppressed but we still return BAD_OPTION.
+
+   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
+   so the following text in the same ARGV-element, or the text of the following
+   ARGV-element, is returned in `fe_optarg'.  Two colons mean an option that
+   wants an optional arg; if there is text in the current ARGV-element,
+   it is returned in `fe_optarg', otherwise `fe_optarg' is set to zero.
+
+   If OPTSTRING starts with `-' or `+', it requests different methods of
+   handling the non-option ARGV-elements.
+   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
+
+   Long-named options begin with `--' instead of `-'.
+   Their names may be abbreviated as long as the abbreviation is unique
+   or is an exact match for some defined option.  If they have an
+   argument, it follows the option name in the same ARGV-element, separated
+   from the option name by a `=', or else the in next ARGV-element.
+   When `getopt' finds a long-named option, it returns 0 if that option's
+   `flag' field is nonzero, the value of the option's `val' field
+   if the `flag' field is zero.
+
+   The elements of ARGV aren't really const, because we permute them.
+   But we pretend they're const in the prototype to be compatible
+   with other systems.
+
+   LONGOPTS is a vector of `struct fe_option' terminated by an
+   element containing a name which is zero.
+
+   LONGIND returns the index in LONGOPT of the long-named option found.
+   It is only valid when a long-named option has been found by the most
+   recent call.
+
+   If LONG_ONLY is nonzero, '-' as well as '--' can introduce
+   long-named options.  */
+
+int _fe_getopt_internal (
+     int argc,
+     char *const *argv,
+     const char *optstring,
+     const struct fe_option *longopts,
+     int *longind,
+     int long_only)
+{
+  int option_index;
+
+  fe_optarg = 0;
+
+  /* Initialize the internal data when the first call is made.
+     Start processing options with ARGV-element 1 (since ARGV-element 0
+     is the program name); the sequence of previously skipped
+     non-option ARGV-elements is empty.  */
+
+  if (fe_optind == 0)
+    {
+      first_nonopt = last_nonopt = fe_optind = 1;
+
+      nextchar = NULL;
+
+      /* Determine how to handle the ordering of options and nonoptions.  */
+
+      if (optstring[0] == '-')
+        {
+          ordering = RETURN_IN_ORDER;
+          ++optstring;
+        }
+      else if (optstring[0] == '+')
+        {
+          ordering = REQUIRE_ORDER;
+          ++optstring;
+        }
+      else if (getenv ("POSIXLY_CORRECT") != NULL)
+        ordering = REQUIRE_ORDER;
+      else
+        ordering = PERMUTE;
+    }
+
+  if (nextchar == NULL || *nextchar == '\0')
+    {
+      if (ordering == PERMUTE)
+        {
+          /* If we have just processed some options following some non-options,
+             exchange them so that the options come first.  */
+
+          if (first_nonopt != last_nonopt && last_nonopt != fe_optind)
+            exchange ((char **) argv);
+          else if (last_nonopt != fe_optind)
+            first_nonopt = fe_optind;
+
+          /* Now skip any additional non-options
+             and extend the range of non-options previously skipped.  */
+
+          while (fe_optind < argc
+                 && (argv[fe_optind][0] != '-' || argv[fe_optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+                 && (longopts == NULL
+                     || argv[fe_optind][0] != '+' || argv[fe_optind][1] == '\0')
+#endif                          /* GETOPT_COMPAT */
+                 )
+            fe_optind++;
+          last_nonopt = fe_optind;
+        }
+
+      /* Special ARGV-element `--' means premature end of options.
+         Skip it like a null option,
+         then exchange with previous non-options as if it were an option,
+         then skip everything else like a non-option.  */
+
+      if (fe_optind != argc && !strcmp (argv[fe_optind], "--"))
+        {
+          fe_optind++;
+
+          if (first_nonopt != last_nonopt && last_nonopt != fe_optind)
+            exchange ((char **) argv);
+          else if (first_nonopt == last_nonopt)
+            first_nonopt = fe_optind;
+          last_nonopt = argc;
+
+          fe_optind = argc;
+        }
+
+      /* If we have done all the ARGV-elements, stop the scan
+         and back over any non-options that we skipped and permuted.  */
+
+      if (fe_optind == argc)
+        {
+          /* Set the next-arg-index to point at the non-options
+             that we previously skipped, so the caller will digest them.  */
+          if (first_nonopt != last_nonopt)
+            fe_optind = first_nonopt;
+          return EOF;
+        }
+
+      /* If we have come to a non-option and did not permute it,
+         either stop the scan or describe it to the caller and pass it by.  */
+
+      if ((argv[fe_optind][0] != '-' || argv[fe_optind][1] == '\0')
+#ifdef GETOPT_COMPAT
+          && (longopts == NULL
+              || argv[fe_optind][0] != '+' || argv[fe_optind][1] == '\0')
+#endif                          /* GETOPT_COMPAT */
+          )
+        {
+          if (ordering == REQUIRE_ORDER)
+            return EOF;
+          fe_optarg = argv[fe_optind++];
+          return 1;
+        }
+
+      /* We have found another option-ARGV-element.
+         Start decoding its characters.  */
+
+      nextchar = (argv[fe_optind] + 1
+                  + (longopts != NULL && argv[fe_optind][1] == '-'));
+    }
+
+  if (longopts != NULL
+      && ((argv[fe_optind][0] == '-'
+           && (argv[fe_optind][1] == '-' || long_only))
+#ifdef GETOPT_COMPAT
+          || argv[fe_optind][0] == '+'
+#endif                          /* GETOPT_COMPAT */
+          ))
+    {
+      const struct fe_option *p;
+      char *s = nextchar;
+      int exact = 0;
+      int ambig = 0;
+      const struct fe_option *pfound = NULL;
+      int indfound = 0;
+
+      while (*s && *s != '=')
+        s++;
+
+      /* Test all options for either exact match or abbreviated matches.  */
+      for (p = longopts, option_index = 0; p->name;
+           p++, option_index++)
+        if (!strncmp (p->name, nextchar, s - nextchar))
+          {
+            if (s - nextchar == my_strlen (p->name))
+              {
+                /* Exact match found.  */
+                pfound = p;
+                indfound = option_index;
+                exact = 1;
+                break;
+              }
+            else if (pfound == NULL)
+              {
+                /* First nonexact match found.  */
+                pfound = p;
+                indfound = option_index;
+              }
+            else
+              /* Second nonexact match found.  */
+              ambig = 1;
+          }
+
+      if (ambig && !exact)
+        {
+          if (fe_opterr)
+            fprintf (stderr, "%s: option `%s' is ambiguous\n",
+                     argv[0], argv[fe_optind]);
+          nextchar += my_strlen (nextchar);
+          fe_optind++;
+          return BAD_OPTION;
+        }
+
+      if (pfound != NULL)
+        {
+          option_index = indfound;
+          fe_optind++;
+          if (*s)
+            {
+              /* Don't test has_arg with >, because some C compilers don't
+                 allow it to be used on enums.  */
+              if (pfound->has_arg)
+                fe_optarg = s + 1;
+              else
+                {
+                  if (fe_opterr)
+                    {
+                      if (argv[fe_optind - 1][1] == '-')
+                        /* --option */
+                        fprintf (stderr,
+                                 "%s: option `--%s' doesn't allow an argument\n",
+                                 argv[0], pfound->name);
+                      else
+                        /* +option or -option */
+                        fprintf (stderr,
+                             "%s: option `%c%s' doesn't allow an argument\n",
+                             argv[0], argv[fe_optind - 1][0], pfound->name);
+                    }
+                  nextchar += my_strlen (nextchar);
+                  return BAD_OPTION;
+                }
+            }
+          else if (pfound->has_arg == 1)
+            {
+              if (fe_optind < argc)
+                fe_optarg = argv[fe_optind++];
+              else
+                {
+                  if (fe_opterr)
+                    fprintf (stderr, "%s: option `%s' requires an argument\n",
+                             argv[0], argv[fe_optind - 1]);
+                  nextchar += my_strlen (nextchar);
+                  return optstring[0] == ':' ? ':' : BAD_OPTION;
+                }
+            }
+          nextchar += my_strlen (nextchar);
+          if (longind != NULL)
+            *longind = option_index;
+          if (pfound->flag)
+            {
+              *(pfound->flag) = pfound->val;
+              return 0;
+            }
+          return pfound->val;
+        }
+      /* Can't find it as a long option.  If this is not getopt_long_only,
+         or the option starts with '--' or is not a valid short
+         option, then it's an error.
+         Otherwise interpret it as a short option.  */
+      if (!long_only || argv[fe_optind][1] == '-'
+#ifdef GETOPT_COMPAT
+          || argv[fe_optind][0] == '+'
+#endif                          /* GETOPT_COMPAT */
+          || my_index (optstring, *nextchar) == NULL)
+        {
+          if (fe_opterr)
+            {
+              if (argv[fe_optind][1] == '-')
+                /* --option */
+                fprintf (stderr, "%s: unrecognized option `--%s'\n",
+                         argv[0], nextchar);
+              else
+                /* +option or -option */
+                fprintf (stderr, "%s: unrecognized option `%c%s'\n",
+                         argv[0], argv[fe_optind][0], nextchar);
+            }
+          nextchar = (char *) "";
+          fe_optind++;
+          return BAD_OPTION;
+        }
+    }
+
+  /* Look at and handle the next option-character.  */
+
+  {
+    char c = *nextchar++;
+    char *temp = my_index (optstring, c);
+
+    /* Increment `fe_optind' when we start to process its last character.  */
+    if (*nextchar == '\0')
+      ++fe_optind;
+
+    if (temp == NULL || c == ':')
+      {
+        if (fe_opterr)
+          {
+#if 0
+            if (c < 040 || c >= 0177)
+              fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
+                       argv[0], c);
+            else
+              fprintf (stderr, "%s: unrecognized option `-%c'\n", argv[0], c);
+#else
+            /* 1003.2 specifies the format of this message.  */
+            fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c);
+#endif
+          }
+        fe_optopt = c;
+        return BAD_OPTION;
+      }
+    if (temp[1] == ':')
+      {
+        if (temp[2] == ':')
+          {
+            /* This is an option that accepts an argument optionally.  */
+            if (*nextchar != '\0')
+              {
+                fe_optarg = nextchar;
+                fe_optind++;
+              }
+            else
+              fe_optarg = 0;
+            nextchar = NULL;
+          }
+        else
+          {
+            /* This is an option that requires an argument.  */
+            if (*nextchar != '\0')
+              {
+                fe_optarg = nextchar;
+                /* If we end this ARGV-element by taking the rest as an arg,
+                   we must advance to the next element now.  */
+                fe_optind++;
+              }
+            else if (fe_optind == argc)
+              {
+                if (fe_opterr)
+                  {
+#if 0
+                    fprintf (stderr, "%s: option `-%c' requires an argument\n",
+                             argv[0], c);
+#else
+                    /* 1003.2 specifies the format of this message.  */
+                    fprintf (stderr, "%s: option requires an argument -- %c\n",
+                             argv[0], c);
+#endif
+                  }
+                fe_optopt = c;
+                if (optstring[0] == ':')
+                  c = ':';
+                else
+                  c = BAD_OPTION;
+              }
+            else
+              /* We already incremented `fe_optind' once;
+                 increment it again when taking next ARGV-elt as argument.  */
+              fe_optarg = argv[fe_optind++];
+            nextchar = NULL;
+          }
+      }
+    return c;
+  }
+}
+
+int fe_getopt (
+     int argc,
+     char *const *argv,
+     const char *optstring)
+{
+  return _fe_getopt_internal (argc, argv, optstring,
+                           (const struct fe_option *) 0,
+                           (int *) 0,
+                           0);
+}
+
+int fe_getopt_long (
+     int argc,
+     char *const *argv,
+     const char *options,
+     const struct fe_option *long_options,
+     int *opt_index)
+{
+  return _fe_getopt_internal (argc, argv, options, long_options, opt_index, 0);
+}
+
+int fe_getopt_long_only (
+     int argc,
+     char *const *argv,
+     const char *options,
+     const struct fe_option *long_options,
+     int *opt_index)
+{
+  return _fe_getopt_internal (argc, argv, options, long_options, opt_index, 1);
+}
+
+#ifdef TEST_GETOPT
+
+/* Compile with -DTEST_GETOPT to make an executable for use in testing
+   the above definition of `getopt'.  */
+
+int main (int argc, char **argv)
+{
+  int c;
+  int digit_optind = 0;
+
+  while (1)
+    {
+      int this_option_optind = optind ? optind : 1;
+
+      c = fe_getopt (argc, argv, "abc:d:0123456789");
+      if (c == EOF)
+        break;
+
+      switch (c)
+        {
+        case '0':
+        case '1':
+        case '2':
+        case '3':
+        case '4':
+        case '5':
+        case '6':
+        case '7':
+        case '8':
+        case '9':
+          if (digit_optind != 0 && digit_optind != this_option_optind)
+            printf ("digits occur in two different argv-elements.\n");
+          digit_optind = this_option_optind;
+          printf ("option %c\n", c);
+          break;
+
+        case 'a':
+          printf ("option a\n");
+          break;
+
+        case 'b':
+          printf ("option b\n");
+          break;
+
+        case 'c':
+          printf ("option c with value `%s'\n", fe_optarg);
+          break;
+
+        case BAD_OPTION:
+          break;
+
+        default:
+          printf ("?? fe_getopt returned character code 0%o ??\n", c);
+        }
+    }
+
+  if (fe_optind < argc)
+    {
+      printf ("non-option ARGV-elements: ");
+      while (fe_optind < argc)
+        printf ("%s ", argv[fe_optind++]);
+      printf ("\n");
+    }
+
+  exit (0);
+}
+
+#endif /* TEST_GETOPT */
Index: Singular/fegetopt.h
===================================================================
--- Singular/fegetopt.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
+++ Singular/fegetopt.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -0,0 +1,139 @@
+/* Declarations for getopt.
+   Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 2, or (at your option) any
+   later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+/* 
+   obachman 9/99: adapted to Singular by 
+    * adding prefix fe_ to global variables
+    * extended fe_option structure    
+*/
+
+#ifndef _GETOPT_H
+#define _GETOPT_H 1
+
+#ifdef        __cplusplus
+extern "C" {
+#endif
+
+/* For communication from `getopt' to the caller.
+   When `getopt' finds an option that takes an argument,
+   the argument value is returned here.
+   Also, when `ordering' is RETURN_IN_ORDER,
+   each non-option ARGV-element is returned here.  */
+
+extern char *fe_optarg;
+
+/* Index in ARGV of the next element to be scanned.
+   This is used for communication to and from the caller
+   and for communication between successive calls to `getopt'.
+
+   On entry to `getopt', zero means this is the first call; initialize.
+
+   When `getopt' returns EOF, this is the index of the first of the
+   non-option elements that the caller should itself scan.
+
+   Otherwise, `optind' communicates from one call to the next
+   how much of ARGV has been scanned so far.  */
+
+extern int fe_optind;
+
+/* Callers store zero here to inhibit the error message `getopt' prints
+   for unrecognized options.  */
+
+extern int fe_opterr;
+
+/* Set to an option character which was unrecognized.  */
+
+extern int fe_optopt;
+
+/* Describe the long-named options requested by the application.
+   The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
+   of `struct option' terminated by an element containing a name which is
+   zero.
+
+   The field `has_arg' is:
+   no_argument                (or 0) if the option does not take an argument,
+   required_argument        (or 1) if the option requires an argument,
+   optional_argument         (or 2) if the option takes an optional argument.
+
+   If the field `flag' is not NULL, it points to a variable that is set
+   to the value given in the field `val' when the option is found, but
+   left unchanged if the option is not found.
+
+   To have a long-named option do something other than set an `int' to
+   a compiled-in constant, such as set a value from `optarg', set the
+   option's `flag' field to zero and its `val' field to a nonzero
+   value (the equivalent single-letter option character, if there is
+   one).  For long options that have a zero `flag' field, `getopt'
+   returns the contents of the `val' field.  */
+
+typedef enum {feOptBool=0, feOptInt, feOptString} feOptType;
+struct fe_option
+{
+#if        __STDC__
+  const char *name;
+#else
+  char *name;
+#endif
+  /* has_arg can't be an enum because some compilers complain about
+     type mismatches in all the code that assumes it is an int.  */
+  int has_arg;
+  int *flag;
+  int val;
+  /* Stuff added for Singular  */
+  const char*   arg_name;// name of argument, for display in help
+  const char*   help;    // (short) help string
+  feOptType     type;    // type of argument, if has_arg > 0
+  void*         value;   // (default) value of option 
+  int           set;     // only relevant for strings: 0 if not set, 1 if set
+};
+
+/* Names for the values of the `has_arg' field of `struct option'.  */
+
+#define        no_argument       0
+#define required_argument        1
+#define optional_argument        2
+
+#if __STDC__ || defined(PROTO) || defined(__MWERKS__)
+#if defined(__GNU_LIBRARY__)
+/* Many other libraries have conflicting prototypes for getopt, with
+   differences in the consts, in stdlib.h.  To avoid compilation
+   errors, only prototype getopt for the GNU C library.  */
+extern int fe_getopt (int argc, char *const *argv, const char *shortopts);
+#endif /* not __GNU_LIBRARY__ */
+extern int fe_getopt_long (int argc, char *const *argv, const char *shortopts,
+                        const struct fe_option *longopts, int *longind);
+extern int fe_getopt_long_only (int argc, char *const *argv,
+                             const char *shortopts,
+                             const struct fe_option *longopts, int *longind);
+
+/* Internal only.  Users should not call this directly.  */
+extern int _fe_getopt_internal (int argc, char *const *argv,
+                             const char *shortopts,
+                             const struct fe_option *longopts, int *longind,
+                             int long_only);
+#else /* not __STDC__ */
+extern int fe_getopt ();
+extern int fe_getopt_long ();
+extern int fe_getopt_long_only ();
+
+extern int _fe_getopt_internal ();
+#endif /* not __STDC__ */
+
+#ifdef        __cplusplus
+}
+#endif
+
+#endif /* _GETOPT_H */
Index: Singular/fehelp.cc
===================================================================
--- Singular/fehelp.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/fehelp.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -21,4 +21,5 @@
 #include "ipshell.h"
 #include "libparse.h"
+#include "feOpt.h"
 
 /*****************************************************************
@@ -149,5 +150,5 @@
         Warn("No help for topic '%s' (not even for '*%s*')", str, str);
         WarnS("Try '?;'       for general help");
-        WarnS("or  '?Index;'  for all available help topics");
+        WarnS("or  '?Index;'  for all available help topics.");
         return;
       }
@@ -182,17 +183,27 @@
 {
   int i = 0;
-  extern void mainSetSingOptionValue(const char* name, char* value);
-  char* mainGetSingOptionValue(const char* name);
-
-  // if no argument, see what we have as value to the option
-  if (which == NULL || *which == '\0')
-    which = mainGetSingOptionValue("browser");
 
   // if no argument, choose first available help browser
   if (which == NULL || *which == '\0')
   {
-    // unles one is already set
-    if (heCurrentHelpBrowser != NULL) goto Finish;
-
+    // return, if already set
+    if (heCurrentHelpBrowser != NULL) 
+      return heCurrentHelpBrowser->browser;
+
+    // First, try emacs, if emacs-option is set
+    if (feOptValue(FE_OPT_EMACS) != NULL)
+    {
+      while (heHelpBrowsers[i].browser != NULL)
+      {
+        if (strcmp(heHelpBrowsers[i].browser, "emacs") == 0 &&
+            (heHelpBrowsers[i].init_proc(0)))
+        {
+          heCurrentHelpBrowser = &(heHelpBrowsers[i]);
+          goto Finish;
+        }
+        i++;
+      }
+      i=0;
+    }
     while (heHelpBrowsers[i].browser != NULL)
     {
@@ -200,5 +211,5 @@
       {
         heCurrentHelpBrowser = &(heHelpBrowsers[i]);
-        return heCurrentHelpBrowser->browser;
+        goto Finish;
       }
       i++;
@@ -215,5 +226,5 @@
   if (heHelpBrowsers[i].browser == NULL)
   {
-    if (warn) Warn("No help browser '%s' available", which);
+    if (warn) Warn("No help browser '%s' available.", which);
   }
   else
@@ -230,10 +241,8 @@
   if (heCurrentHelpBrowser == NULL)
   {
-    // choose first available help browser
-    mainSetSingOptionValue("browser", "");
     feHelpBrowser();
     assume(heCurrentHelpBrowser != NULL);
     if (warn)
-      Warn("Setting help browser to '%s'", heCurrentHelpBrowser->browser);
+      Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
     return heCurrentHelpBrowser->browser;
   }
@@ -242,9 +251,19 @@
     // or, leave as is
     if (warn)
-      Warn("Help browser stays at '%s'",  heCurrentHelpBrowser->browser);
+      Warn("Help browser stays at '%s'.",  heCurrentHelpBrowser->browser);
+    return heCurrentHelpBrowser->browser;
   }
 
   Finish:
-  mainSetSingOptionValue("browser", heCurrentHelpBrowser->browser);
+  // update value of Browser Option
+  if (feOptSpec[FE_OPT_BROWSER].value == NULL ||
+      strcmp((char*) feOptSpec[FE_OPT_BROWSER].value,  
+             heCurrentHelpBrowser->browser) != 0)
+  {
+    if (feOptSpec[FE_OPT_BROWSER].value == NULL) 
+      FreeL(feOptSpec[FE_OPT_BROWSER].value);
+   feOptSpec[FE_OPT_BROWSER].value 
+     = (void*) mstrdup(heCurrentHelpBrowser->browser);
+  }
   return heCurrentHelpBrowser->browser;
 }
@@ -642,5 +661,5 @@
     return;
 
-  if (heCurrentHelpBrowser == NULL) feHelpBrowser();
+  if (heCurrentHelpBrowser == NULL) feHelpBrowser(NULL, 0);
   assume(heCurrentHelpBrowser != NULL);
   if (! feHelpCalled)
@@ -722,5 +741,6 @@
   {
     if (warn) WarnS("no local HtmlDir found");
-    if (warn) Warn("using %s instead", feResource('u' /*"ManualUrl"*/, warn));
+    return FALSE;
+//    if (warn) Warn("using %s instead", feResource('u' /*"ManualUrl"*/, warn));
   }
   return TRUE;
Index: Singular/feread.cc
===================================================================
--- Singular/feread.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/feread.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: feread.cc,v 1.22 1999-08-25 16:02:47 Singular Exp $ */
+/* $Id: feread.cc,v 1.23 1999-09-20 18:03:48 obachman Exp $ */
 /*
 * ABSTRACT: input from ttys, simulating fgets
@@ -8,5 +8,4 @@
 
 
-#include "version.h"
 #include "mod2.h"
 #include "tok.h"
Index: Singular/find_exec.c
===================================================================
--- Singular/find_exec.c	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/find_exec.c	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -64,7 +64,7 @@
   {
     if (((name[0] == '.') && (name[1] == '/')) ||
-        ((name[0] == '.') && (name[1] == '.') && (name[2] == '/')))
-    {
-      strcpy (tbuf, (name[1] == '.' ? ".." : "."));
+        ((name[0] == '.') && (name[1] == '.') && (name[2] == '/')) ||
+        strchr(name, '/') != NULL)
+    {
 
 #ifdef HAVE_GETCWD
@@ -77,7 +77,7 @@
       strcat (tbuf, "/");
       strcat (tbuf, name);
-      return copy_of (tbuf);
-    }
-
+      if (! access(name, X_OK))
+        return copy_of (tbuf);
+    }
 
     search = getenv("PATH");
Index: Singular/getopt.h
===================================================================
--- Singular/getopt.h	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/getopt.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -16,4 +16,6 @@
    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
+/* obachman: adapted to Singular by adding prefix fe_ to global variables
+ */
 #ifndef _GETOPT_H
 #define _GETOPT_H 1
@@ -29,5 +31,5 @@
    each non-option ARGV-element is returned here.  */
 
-extern char *optarg;
+extern char *fe_optarg;
 
 /* Index in ARGV of the next element to be scanned.
@@ -43,14 +45,14 @@
    how much of ARGV has been scanned so far.  */
 
-extern int optind;
+extern int fe_optind;
 
 /* Callers store zero here to inhibit the error message `getopt' prints
    for unrecognized options.  */
 
-extern int opterr;
+extern int fe_opterr;
 
 /* Set to an option character which was unrecognized.  */
 
-extern int optopt;
+extern int fe_optopt;
 
 /* Describe the long-named options requested by the application.
@@ -75,5 +77,6 @@
    returns the contents of the `val' field.  */
 
-struct option
+typedef enum {feOptBool=0, feOptInt, feOptString} feOptType;
+struct fe_option
 {
 #if        __STDC__
@@ -87,9 +90,15 @@
   int *flag;
   int val;
+  /* Stuff added for Singular  */
+  const char*   arg_name;// name of argument, for display in help
+  const char*   help;    // (short) help string
+  feOptType     type;    // type of argument, if has_arg > 0
+  void*         value;   // (default) value of option 
+  int           set;     // only relevant for strings: 0 if not set, 1 if set
 };
 
 /* Names for the values of the `has_arg' field of `struct option'.  */
 
-#define        no_argument                0
+#define        no_argument       0
 #define required_argument        1
 #define optional_argument        2
@@ -100,23 +109,23 @@
    differences in the consts, in stdlib.h.  To avoid compilation
    errors, only prototype getopt for the GNU C library.  */
-extern int getopt (int argc, char *const *argv, const char *shortopts);
+extern int fe_getopt (int argc, char *const *argv, const char *shortopts);
 #endif /* not __GNU_LIBRARY__ */
-extern int getopt_long (int argc, char *const *argv, const char *shortopts,
-                        const struct option *longopts, int *longind);
-extern int getopt_long_only (int argc, char *const *argv,
+extern int fe_getopt_long (int argc, char *const *argv, const char *shortopts,
+                        const struct fe_option *longopts, int *longind);
+extern int fe_getopt_long_only (int argc, char *const *argv,
                              const char *shortopts,
-                             const struct option *longopts, int *longind);
+                             const struct fe_option *longopts, int *longind);
 
 /* Internal only.  Users should not call this directly.  */
-extern int _getopt_internal (int argc, char *const *argv,
+extern int _fe_getopt_internal (int argc, char *const *argv,
                              const char *shortopts,
-                             const struct option *longopts, int *longind,
+                             const struct fe_option *longopts, int *longind,
                              int long_only);
 #else /* not __STDC__ */
-extern int getopt ();
-extern int getopt_long ();
-extern int getopt_long_only ();
+extern int fe_getopt ();
+extern int fe_getopt_long ();
+extern int fe_getopt_long_only ();
 
-extern int _getopt_internal ();
+extern int _fe_getopt_internal ();
 #endif /* not __STDC__ */
 
Index: Singular/ipshell.h
===================================================================
--- Singular/ipshell.h	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/ipshell.h	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -4,5 +4,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: ipshell.h,v 1.19 1999-07-28 17:51:07 Singular Exp $ */
+/* $Id: ipshell.h,v 1.20 1999-09-20 18:03:49 obachman Exp $ */
 /*
 * ABSTRACT
@@ -24,5 +24,5 @@
 extern int  myynest;
 extern char *  currid;
-extern char * thisfile;
+extern char * feArgv0;
 extern int     iiRETURNEXPR_len;
 extern sleftv *iiRETURNEXPR;
Index: Singular/kbPolyProcs.cc
===================================================================
--- Singular/kbPolyProcs.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/kbPolyProcs.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -373,5 +373,5 @@
 
   // set characterisic
-  if (r->ch > 1) ch = chMODP;
+  if (rField_is_Zp(r)) ch = chMODP;
   
   // set Ordering Type
Index: Singular/misc.cc
===================================================================
--- Singular/misc.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/misc.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -14,5 +14,4 @@
 #include <limits.h>
 
-#include "version.h"
 #include "mod2.h"
 #include "tok.h"
Index: Singular/mmisc.c
===================================================================
--- Singular/mmisc.c	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/mmisc.c	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: mmisc.c,v 1.9 1999-08-18 09:18:28 obachman Exp $ */
+/* $Id: mmisc.c,v 1.10 1999-09-20 18:03:50 obachman Exp $ */
 
 /*
@@ -13,4 +13,6 @@
 #include "mmpage.h"
 #include "febase.h"
+#include "distrib.h"
+
 #ifdef MTRACK
 #include "mmbt.h"
Index: Singular/sing_mp.cc
===================================================================
--- Singular/sing_mp.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/sing_mp.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: sing_mp.cc,v 1.26 1999-08-13 11:21:44 Singular Exp $ */
+/* $Id: sing_mp.cc,v 1.27 1999-09-20 18:03:50 obachman Exp $ */
 
 /*
@@ -22,4 +22,5 @@
 #include "ipid.h"
 #include "silink.h"
+#include "feOpt.h"
 
 static int Batch_ReadEval(si_link silink);
@@ -164,6 +165,4 @@
  *
  ***************************************************************/
-extern BOOLEAN mainGetSingOptionValue(const char* name, char** val);
-
 
 static MP_Link_pt slOpenMPConnect(int n_argc, char **n_argv)
@@ -175,6 +174,6 @@
   char *host = IMP_GetCmdlineArg(n_argc, n_argv, "--MPhost");
 
-  if (port == NULL) mainGetSingOptionValue("--MPport", &port);
-  if (host == NULL) mainGetSingOptionValue("--MPhost", &host);
+  if (port == NULL) port = (char*) feOptValue(FE_OPT_MP_PORT);
+  if (host == NULL) host = (char*) feOptValue(FE_OPT_MP_HOST);
 
   if (port != NULL)
@@ -194,5 +193,5 @@
   char *port = IMP_GetCmdlineArg(n_argc, n_argv, "--MPport");
 
-  if (port == NULL) mainGetSingOptionValue("--MPport", &port);
+  if (port == NULL) port = (char*) feOptValue(FE_OPT_MP_HOST);
 
   if (port != NULL) argv[5] = port;
Index: Singular/tesths.cc
===================================================================
--- Singular/tesths.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/tesths.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: tesths.cc,v 1.69 1999-08-25 15:26:02 obachman Exp $ */
+/* $Id: tesths.cc,v 1.70 1999-09-20 18:03:51 obachman Exp $ */
 
 /*
@@ -15,5 +15,4 @@
 #include <time.h>
 #include <errno.h>
-#include "version.h"
 #include "mod2.h"
 #include "tok.h"
@@ -27,4 +26,9 @@
 #include "timer.h"
 #include "sdb.h"
+#include "fegetopt.h"
+#include "feOpt.h"
+#include "distrib.h"
+#include "version.h"
+
 #ifdef HAVE_FACTORY
 #define SI_DONT_HAVE_GLOBAL_VARS
@@ -32,5 +36,4 @@
 #endif
 
-#include "feCmdLineOptions.cc"
 /*0 implementation*/
 int main(          /* main entry to Singular */
@@ -38,7 +41,4 @@
     char** argv)   /* parameter array */
 {
-  char * thisfile;
-  /* initialize components */
-  siRandomStart=inits();
 #ifdef INIT_BUG
   jjInitTab1();
@@ -54,220 +54,51 @@
   ttGen2();
 #else
-  thisfile = argv[0];
-  BOOLEAN load_std_lib=TRUE;
-  BOOLEAN load_rc = TRUE;
-  char* execute_string = NULL;
+  /* initialize components */
+  siRandomStart=inits();
+  feOptSpec[FE_OPT_RANDOM].value = (void*) siRandomStart;
   int optc, option_index;
+  char* errormsg;
 
   // do this first, because -v might print version path
-  feInitResources(thisfile);
+  feInitResources(argv[0]);
 
   // parse command line options
-  while((optc = getopt_long(argc, argv,
-                            SHORT_OPTS_STRING, longopts, &option_index))
+  while((optc = fe_getopt_long_only(argc, argv,
+                               SHORT_OPTS_STRING, feOptSpec, &option_index))
+//                               "", feOptSpec, &option_index))
         != EOF)
   {
-    switch(optc)
-    {
-
-        case 'b':
-#ifdef HAVE_MPSR
-          fe_fgets_stdin=fe_fgets_dummy;
-          mainSetSingOptionValue(LON_BATCH, (char*) 1);
-          break;
-#else
-          printf("%s: Option `-b' not supported in this configuration\n", argv[0]);
-          mainUsage(argv[0]);
-          exit(1);
-#endif
-        case 'h':
-          mainHelp(argv[0]);
-          exit(0);
-
-        case 'q':
-          verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
-          mainSetSingOptionValue(LON_QUIET, (char*) 1);
-          break;
-
-        case 't':
-#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
-          fe_fgets_stdin=fe_fgets;
-#endif
-          mainSetSingOptionValue(LON_NO_TTY, (char*) 1);
-          break;
-
-        case 'd':
-          sdb_flags = 1;
-          break;
-
-        case 'v':
-          printf("Singular for %s version %s  (%d)  %s %s\n",
-                 S_UNAME, S_VERSION1,
-                 SINGULAR_VERSION_ID,__DATE__,__TIME__);
-          printf("with\n");
-          printf(versionString());
-          printf("\n\n");
-          mainSetSingOptionValue(LON_VERSION, (char*) 1);
-          break;
-
-        case 'x':
-#ifdef HAVE_TCL
-          tclmode = TRUE;
-          fe_fgets_stdin=fe_fgets_tcl;
-          mainSetSingOptionValue(LON_TCLMODE, (char*) 1);
-          verbose|=Sy_bit(V_SHOW_MEM);
-          break;
-#else
-          printf("%s: Option `-x' not supported in this configuration\n", argv[0]);
-          mainUsage(argv[0]);
-          exit(1);
-#endif
-
-        case 'e':
-          if (optarg != NULL)
-          {
-            errno = 0;
-            si_echo = strtol(optarg, NULL, 10);
-            if (errno)
-            {
-              printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO);
-              mainUsage(argv[0]);
-              exit(1);
-            }
-            if (si_echo < 0 || si_echo > 9)
-            {
-              printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n",
-                     argv[0], optarg, LON_ECHO);
-              mainUsage(argv[0]);
-              exit(1);
-            }
-            mainSetSingOptionValue(LON_ECHO, optarg);
-          }
-          else
-          {
-            si_echo = 1;
-            mainSetSingOptionValue(LON_ECHO, "1");
-          }
-          break;
-
-        case 'c':
-          execute_string = optarg;
-          mainSetSingOptionValue(LON_EXECUTE, optarg);
-          break;
-
-        case 'r':
-          errno = 0;
-          siRandomStart = strtol(optarg, NULL, 10);
-          if (errno || siRandomStart == 0)
-          {
-            printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM);
-            mainUsage(argv[0]);
-            exit(1);
-          }
-          #ifdef buildin_rand
-          siSeed=siRandomStart;
-          #else
-          srand((unsigned int)siRandomStart);
-          #endif
-          #ifdef HAVE_FACTORY
-          factoryseed(siRandomStart);
-          #endif
-          mainSetSingOptionValue(LON_RANDOM, optarg);
-          break;
-
-        case 'u':
-          mainSetSingOptionValue(LON_USER_OPTION, optarg);
-          break;
-
-        case LONG_OPTION_RETURN:
-          if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0)
-          {
-            load_std_lib = FALSE;
-            mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1);
-          }
-          else if (strcmp(longopts[option_index].name, LON_BROWSER) == 0)
-          {
-            mainSetSingOptionValue(LON_BROWSER, optarg);
-          }
-          else if (strcmp(longopts[option_index].name, LON_EMACS) == 0)
-          {
-            mainSetSingOptionValue(LON_EMACS, (char*) 1);
-            // print EmacsDir and InfoFile so that Emacs
-            // mode can pcik it up
-            Warn("EmacsDir: %s", (feResource('e' /*"EmacsDir"*/) != NULL ?
-                                  feResource('e' /*"EmacsDir"*/) : ""));
-            Warn("InfoFile: %s", (feResource('i' /*"InfoFile"*/) != NULL ?
-                                  feResource('i' /*"InfoFile"*/) : ""));
-          }
-          else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0)
-          {
-            load_rc = FALSE;
-            mainSetSingOptionValue(LON_NO_RC, (char*) 1);
-          }
-          else if (strcmp(longopts[option_index].name, LON_NO_WARN) == 0)
-          {
-            feWarn = FALSE;
-            mainSetSingOptionValue(LON_NO_WARN, (char*) 1);
-          }
-          else if (strcmp(longopts[option_index].name, LON_NO_OUT) == 0)
-          {
-            feOut = FALSE;
-            mainSetSingOptionValue(LON_NO_OUT, (char*) 1);
-          }
-          else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0)
-          {
-            double mintime = atof(optarg);
-            if (mintime <= 0)
-            {
-              printf("%s: `%s' invalid float argument for option `--%s'\n",
-                     argv[0], optarg, LON_MIN_TIME);
-              mainUsage(argv[0]);
-              exit(1);
-            }
-            SetMinDisplayTime(mintime);
-            mainSetSingOptionValue(LON_MIN_TIME, optarg);
-          }
-#ifdef HAVE_MPSR
-          else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0)
-          {
-            mainSetSingOptionValue(LON_MP_PORT, optarg);
-          }
-          else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0)
-          {
-            mainSetSingOptionValue(LON_MP_HOST, optarg);
-          }
-#endif
-          else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0)
-          {
-            int ticks = atoi(optarg);
-            if (ticks <= 0)
-            {
-              printf("%s: `%s' invalid integer argument for option `--%s'\n",
-                     argv[0], optarg, LON_TICKS_PER_SEC);
-              mainUsage(argv[0]);
-              exit(1);
-            }
-            SetTimerResolution(ticks);
-            mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg);
-          }
-          else
-            // undocumented options
-#ifdef HAVE_MPSR
-            if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 ||
-                strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0)
-            {
-              /* ignore */
-            }
-          else
-#endif
-            assume(0);
-          break;
-
-        default:
-          // Error message already emmited by getopt_long
-          mainUsage(argv[0]);
-          exit(1);
-    }
-  }
+    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);
+    
+    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);
+  }
+
   /* say hello */
   {
@@ -307,7 +138,7 @@
   }
   slStandardInit();
-  dlInit(thisfile);
+  dlInit(feArgv0);
   myynest=0;
-  if (load_std_lib)
+  if (! feOptValue(FE_OPT_NO_STDLIB))
   {
     int vv=verbose;
@@ -327,8 +158,8 @@
 
   // Last thing to do is to execute given scripts
-  if (optind < argc)
+  if (fe_optind < argc)
   {
     int i = argc - 1;
-    while (i >= optind)
+    while (i >= fe_optind)
     {
       newFile(argv[i]);
@@ -342,10 +173,9 @@
 
   // before scripts, we execute -c, if it was given
-  // now execute -c, if it was given
-  if (execute_string != NULL)
-    newBuffer(mstrdup(execute_string), BT_execute);
+  if (feOptValue(FE_OPT_EXECUTE) != NULL)
+    newBuffer(mstrdup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
 
   // first thing, however, is to load .singularrc
-  if (load_rc)
+  if (! feOptValue(FE_OPT_NO_RC))
   {
     FILE * rc=myfopen(".singularrc","r");
@@ -378,6 +208,6 @@
 #ifdef HAVE_MPSR
     extern int Batch_do(const char* port, const char* host);
-    return Batch_do(mainGetSingOptionValue(LON_MP_PORT),
-                    mainGetSingOptionValue(LON_MP_HOST));
+    return Batch_do((char*) feOptValue(FE_OPT_MP_PORT),
+                    (char*) feOptValue(FE_OPT_MP_HOST));
 #else
     assume(0);
@@ -391,2 +221,3 @@
   return 0;
 }
+
Index: Singular/utils.cc
===================================================================
--- Singular/utils.cc	(revision aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca)
+++ Singular/utils.cc	(revision c06a32460a4bb62e5728330353d1cea3b60af90d)
@@ -3,9 +3,9 @@
 #include <stdlib.h>
 #include <ctype.h>
-#include "getopt.h"
+#include "fegetopt.h"
 #include "utils.h"
 #ifdef __MWERKS__
 #define __GNU_LIBRARY__
-#include "getopt.h"
+#include "fegetopt.h"
 #endif
 
@@ -38,12 +38,12 @@
   char c;
 
-  while((c=getopt(argc, argv, "ihd:sf:"))>=0) {
+  while((c=fe_getopt(argc, argv, "ihd:sf:"))>=0) {
     switch(c) {
         case 'd':
           lpverbose = 1;
-          if(isdigit(argv[optind-1][0])) sscanf(optarg, "%d", &lpverbose);
-          else optind--;
-          break;
-        case 'f': lib_file = argv[optind-1];
+          if(isdigit(argv[fe_optind-1][0])) sscanf(optarg, "%d", &lpverbose);
+          else fe_optind--;
+          break;
+        case 'f': lib_file = argv[fe_optind-1];
           break;
         case 's':
@@ -57,8 +57,8 @@
           break;
           
-        case -1 : printf("no such option:%s\n", argv[optind]);
+        case -1 : printf("no such option:%s\n", argv[fe_optind]);
           usage(argv[0]);
           break;
-        default: printf("no such option.%x, %c %s\n", c&0xff, c, argv[optind]);
+        default: printf("no such option.%x, %c %s\n", c&0xff, c, argv[fe_optind]);
           usage(argv[0]);
     }
@@ -73,15 +73,15 @@
       printf("$library = \"%s\";\n", lib_file);
   } else {
-    while(argc>optind && yylpin==NULL) {
-      yylpin = fopen( argv[optind], "rb" );
+    while(argc>fe_optind && yylpin==NULL) {
+      yylpin = fopen( argv[fe_optind], "rb" );
       if(yylpin!=NULL) 
       {
-        lib_file = argv[optind];
+        lib_file = argv[fe_optind];
         if (! texinfo_out) 
-          printf("Checking library '%s'\n", argv[optind]);
+          printf("Checking library '%s'\n", argv[fe_optind]);
         else
           printf("$library = \"%s\";\n", lib_file);
       }
-      else optind++;
+      else fe_optind++;
     }
   }
