Changeset c06a32 in git


Ignore:
Timestamp:
Sep 20, 1999, 8:03:51 PM (25 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
70883173be34d0af981d9af508ccbb1e77912676
Parents:
aef7ccb547c93eee9ab75ef2c46ce9149f6dd9ca
Message:
* New Handling of Command-line options


git-svn-id: file:///usr/local/Singular/svn/trunk@3623 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • Singular/Makefile.in

    raef7ccb rc06a32  
    6666###
    6767
     68# normal C++ source files
    6869CXXSOURCES=grammar.cc scanner.cc algmap.cc attrib.cc binom.cc clapconv.cc \
    69     clapmem.cc clapsing.cc claptmpl.cc cntrlc.cc \
    70     extra.cc febase.cc feread.cc fehelp.cc feResource.cc feCmdLineOptions.cc\
     70    clapmem.cc clapsing.cc cntrlc.cc\
     71    extra.cc febase.cc feread.cc fehelp.cc feResource.cc feOpt.cc\
    7172    ffields.cc hdegree.cc hilb.cc hutil.cc \
    72     ideals.cc intvec.cc iparith.cc \
     73    ideals.cc intvec.cc \
    7374    ipassign.cc ipconv.cc ipid.cc iplib.cc \
    7475    ipprint.cc ipshell.cc khstd.cc kstdfac.cc \
     
    8283    sing_dld.cc sing_dbm.cc spolys.cc spolys0.cc \
    8384    subexpr.cc syz.cc syz0.cc syz1.cc \
    84     tesths.cc timer.cc weight.cc \
    85     mpsr_Put.cc mpsr_PutPoly.cc mpsr_Tok.cc mpsr_GetPoly.cc \
     85    timer.cc weight.cc \
     86    mpsr_Put.cc mpsr_PutPoly.cc mpsr_GetPoly.cc \
    8687    mpsr_Get.cc mpsr_GetMisc.cc mpsr_Error.cc \
    8788    GMPrat.cc multicnt.cc npolygon.cc semic.cc spectrum.cc splist.cc \
     
    9091    mpr_inout.cc mpr_base.cc mpr_numeric.cc
    9192
    92 CSOURCES=gmalloc.c mmalloc.c mmheap.c mmpage.c mmcheck.c  mmisc.c mmtables.c \
    93     mmbt.c weight0.c find_exec.c getopt.c fereadl.c page.c
    94 
    95 SOURCES=${CSOURCES} ${CXXSOURCES} grammar.y scanner.l libparse.l spSpolyLoop.pl generate.pl
     93# normal C source files
     94CSOURCES=mmalloc.c mmheap.c mmpage.c mmcheck.c  mmisc.c mmtables.c \
     95    mmbt.c weight0.c find_exec.c fegetopt.c fereadl.c page.c
     96
     97# special source files (need extra compiling and/or linking)
     98ESOURCES=iparith.cc gmalloc.c tesths.cc mpsr_Tok.cc claptmpl.cc
     99
     100SOURCES=${CSOURCES} ${CXXSOURCES} ${ESOURCES} \
     101        grammar.y scanner.l libparse.l spSpolyLoop.pl generate.pl
    96102
    97103HEADERS=algmap.h hutil.h lists.h stairc.h attrib.h ideals.h \
     
    107113        kstdfac.h mpsr_Get.h spolys.h \
    108114        kutil.h mpsr_Put.h spolys0.h sing_dld.h\
    109         ndbm.h spSpolyLoop.h polys-impl.h polys-comp.h getopt.h libparse.h \
     115        ndbm.h spSpolyLoop.h polys-impl.h polys-comp.h libparse.h \
    110116        GMPrat.h multicnt.h npolygon.h semic.h spectrum.h splist.h multicnt.h \
    111117        pcv.h mod_raw.h kbuckets.h kbPolyProcs.h \
    112         mpr_global.h mpr_inout.h mpr_base.h mpr_numeric.h
    113 
    114 INCS=febase.inc polys.inc iparith.inc mpsr_Tok.inc spSpolyLoop.inc
     118        mpr_global.h mpr_inout.h mpr_base.h mpr_numeric.h \
     119        feOpt.h fegetopt.h
     120
     121INCS=febase.inc polys.inc iparith.inc mpsr_Tok.inc spSpolyLoop.inc feOpt.inc
    115122
    116123TESTS=${testdir}/comparecheck ${testdir}/fac_test.in ${testdir}/fac_test.out\
     
    123130        ${INCS}
    124131
    125 OBJS=grammar.o scanner.o matpol.o binom.o mpr_complex.o gnumpfl.o gnumpc.o \
    126      febase.o feread.o fehelp.o feResource.o timer.o intvec.o attrib.o lists.o\
    127      longrat.o longrat0.o misc.o ring.o numbers.o maps.o\
    128      hilb.o comm.o kstd1.o kstd2.o kutil.o khstd.o kstdfac.o modulop.o spolys.o\
    129      ideals.o subexpr.o hdegree.o hutil.o ffields.o shortfl.o \
    130      longalg.o spolys0.o syz.o syz0.o syz1.o weight.o weight0.o \
    131      ipid.o ipshell.o iplib.o ipassign.o ipconv.o ipprint.o\
    132      polys.o polys0.o polys1.o polys-impl.o extra.o sparsmat.o\
    133      mminit.o mmtables.o mmalloc.o mmheap.o mmpage.o page.o \
    134      mmisc.o mmcheck.o mmbt.o sing_dld.o sing_dbm.o silink.o \
    135      sing_mp.o fglm.o fglmzero.o fglmvec.o fglmhom.o fglmgauss.o cntrlc.o \
    136      algmap.o clapconv.o  clapmem.o clapsing.o claptmpl.o\
    137      mpsr_Error.o mpsr_Put.o mpsr_PutPoly.o mpsr_GetPoly.o \
    138      mpsr_Get.o mpsr_GetMisc.o ndbm.o spSpolyLoop.o libparse.o \
    139      find_exec.o getopt.o fereadl.o  mod_raw.o sdb.o \
    140      GMPrat.o multicnt.o npolygon.o semic.o spectrum.o splist.o \
    141      pcv.o kbuckets.o kbPolyProcs.o \
    142      mpr_inout.o mpr_base.o mpr_numeric.o
     132OBJS := $(CXXSOURCES:.cc=.o) $(CSOURCES:.c=.o)
    143133
    144134# Singular libraries which go into distribution
     
    179169
    180170Singular: mod2.h Makefile version.h scanner.cc gmalloc.o \
    181           ${OBJS} iparith.o mpsr_Tok.o tesths.cc libparse.cc
    182         ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -o Singular \
    183         tesths.cc iparith.o mpsr_Tok.o ${OBJS} ${LDFLAGS} ${LIBS} \
    184         ${LD_DYN_FLAGS} gmalloc.o ${LD_LIBC}
     171          ${OBJS} iparith.o tesths.cc libparse.cc claptmpl.o
     172        ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} \
     173          -o Singular \
     174          tesths.cc iparith.o mpsr_Tok.o claptmpl.o\
     175          ${OBJS} ${LDFLAGS} ${LIBS} ${LD_DYN_FLAGS} \
     176          gmalloc.o ${LD_LIBC}
    185177
    186178Singular-static: mod2.h Makefile version.h scanner.cc  gmalloc.o \
    187                 ${OBJS} iparith.o mpsr_Tok.o tesths.cc
     179                ${OBJS} iparith.o mpsr_Tok.o tesths.cc claptmpl.o
    188180        ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} \
    189         -o Singular-static \
    190         tesths.cc iparith.o mpsr_Tok.o \
    191         ${OBJS} ${STATIC_LDFLAGS} ${LDFLAGS} ${LIBS} ${LD_DYN_FLAGS} \
    192         gmalloc.o ${LD_LIBC}
     181          -o Singular-static \
     182          tesths.cc iparith.o mpsr_Tok.o claptmpl.o\
     183          ${OBJS} ${STATIC_LDFLAGS} ${LDFLAGS} ${LIBS} ${LD_DYN_FLAGS} \
     184          gmalloc.o ${LD_LIBC}
    193185
    194186iparith.o mpsr_Tok.o : iparith.inc mpsr_Tok.inc
     
    197189        ${CXX} ${CXXFLAGS}  ${CPPFLAGS} ${DEFS} -c $<   
    198190
    199 iparith.inc mpsr_Tok.inc: gmalloc.o iparith.cc ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h
     191iparith.inc mpsr_Tok.inc: gmalloc.o claptmpl.o iparith.cc \
     192                          ipconv.cc tok.h mpsr_Tok.cc grammar.h mod2.h
    200193        ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${CXXTEMPLFLAGS} ${DEFS} -DGENTABLE \
    201              -o gentable iparith.cc tesths.cc mpsr_Tok.cc \
     194             -o gentable claptmpl.o iparith.cc tesths.cc mpsr_Tok.cc \
    202195             ${OBJS} ${LDFLAGS} ${LIBS} gmalloc.o ${LD_LIBC}
    203196        ./gentable
     
    215208version.h: ${SOURCES} ${HEADERS} Makefile.in mod2.h.in \
    216209           configure.in
    217         echo "#define SINGULAR_VERSION_ID " `date '+%Y%m%d%H'` >version.h
     210        echo unsigned long feVersionId =  `date '+%Y%m%d%H'`\; >version.h
    218211
    219212kbPolyProcs.cc kbPolyProcs.dd : kbPolyProcs.pin
     
    235228        ${PERL5} spSpolyLoop.pl > spSpolyLoop.inc
    236229
    237 libparse: libparse_main.o utils.o getopt.o
    238         ${CXX} -o libparse libparse_main.o utils.o getopt.o
     230
     231libparse: libparse_main.o utils.o fegetopt.o
     232        ${CXX} -o libparse libparse_main.o utils.o fegetopt.o
    239233
    240234libparse_main.o: libparse.cc
     
    248242        ${LEX} -I -Pyylp -olibparse.cc libparse.l
    249243
    250 ESingular: getopt.o feResource.cc mod2.h feCmdLineOptions.cc version.h emacs.cc
    251         ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${DEFS} -o ESingular emacs.cc getopt.o ${LDFLAGS} ${LIBS}
     244ESingular: fegetopt.o feResource.cc mod2.h feOpt.cc version.h emacs.cc \
     245           feOptES.inc
     246        ${CXX} ${CXXFLAGS} ${CPPFLAGS} ${DEFS} -o ESingular emacs.cc fegetopt.o ${LDFLAGS} ${LIBS}
     247
     248feOpt.h: feOpt.inc feOptES.inc
     249
     250feOpt.inc: feOpt.cc
     251        $(CXX) -DGENERATE_OPTION_INDEX feOpt.cc
     252        ./a.out
     253        rm a.out
     254
     255feOptES.inc: feOpt.cc
     256        $(CXX) -DGENERATE_OPTION_INDEX -DESINGULAR feOpt.cc
     257        ./a.out
     258        rm a.out
    252259
    253260src: scanner.cc grammar.h grammar.cc libparse.cc spSpolyLoop.inc
     
    302309
    303310clean:
    304         -rm -f Singular Singularg Singularp Singularb libparse \
     311        -rm -f Singular Singularg Singularp Singularb libparse feOpt*.inc\
    305312            *.o *.og core *.op *.ob
    306313
     
    327334
    328335Singular-bindist: ${OBJS} Makefile
    329         echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
    330         echo "#define MAKE_DISTRIBUTION " >> version.h
     336        echo "#define MAKE_DISTRIBUTION " > distrib.h
    331337        ${MAKE} Singular ESingular
    332338        strip Singular ESingular
    333339        ${INSTALL} -s Singular Singular-bindist
    334340        ${INSTALL} -s ESingular ESingular-bindist
    335         echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
     341        echo "#undef MAKE_DISTRIBUTION " > distrib.h
    336342
    337343Singular-static-bindist: ${OBJS} Makefile
    338         echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
    339         echo "#define MAKE_DISTRIBUTION " >> version.h
     344        echo "#define MAKE_DISTRIBUTION " > distrib.h
    340345        ${MAKE} Singular-static ESingular
    341346        strip Singular-static ESingular
    342347        mv Singular-static Singular-static-bindist
    343348        ${INSTALL} -s ESingular ESingular-bindist
    344         echo "#define SINGULAR_VERSION_ID " `date '+%y%m%d%H'` >version.h
     349        echo "#undef MAKE_DISTRIBUTION " > distrib.h
    345350
    346351tar:
     
    380385##
    381386
    382 OBJG1=  grammar.og scanner.og matpol.og binom.og gnumpfl.og mpr_complex.og \
    383      febase.og feread.og fehelp.og feResource.og timer.og intvec.og attrib.og lists.og \
    384      gnumpc.og longrat.og longrat0.og misc.og ring.og numbers.og maps.og\
    385      hilb.og comm.og kstd1.og kstd2.og kutil.og khstd.og kstdfac.og modulop.og \
    386      spolys.og ideals.og subexpr.og hdegree.og hutil.og ffields.og shortfl.og \
    387      longalg.og spolys0.og syz.og syz0.og syz1.og weight.og \
    388      ipid.og ipshell.og iplib.og ipassign.og ipconv.og ipprint.og\
    389      polys.og polys0.og polys1.og polys-impl.og extra.og\
    390      mminit.og sing_dld.og sing_dbm.og silink.og sparsmat.og\
    391      sing_mp.og fglm.og fglmzero.og fglmvec.og fglmgauss.og fglmhom.og\
    392      algmap.og clapconv.og  clapmem.og clapsing.og cntrlc.og  sdb.og\
    393      mpsr_Error.og mpsr_Put.og mpsr_PutPoly.og mpsr_GetPoly.og \
    394      mpsr_Get.og mpsr_GetMisc.og \
    395      ndbm.og spSpolyLoop.og libparse.og  mod_raw.og \
    396      GMPrat.og multicnt.og npolygon.og semic.og spectrum.og splist.og \
    397      mpr_inout.og mpr_base.og mpr_numeric.og \
    398      pcv.og kbuckets.og kbPolyProcs.og
    399 
    400 OBJG2= mmalloc.og mmheap.og mmpage.og mmcheck.og mmbt.og page.og \
    401      mmisc.og mmtables.og weight0.og find_exec.og getopt.og fereadl.og
    402 
    403 
    404 OBJG=$(OBJG1) $(OBJG2) claptmpl.og
     387OBJG1 := $(CXXSOURCES:.cc=.og)
     388OBJG2 := $(CSOURCES:.c=.og)
     389
     390
     391OBJG=$(OBJG1) $(OBJG2)
    405392
    406393##
     
    410397claptmpl.og: claptmpl.cc mod2.h
    411398        $(CXXG)  ${CXXFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@
    412 $(OBJG1): %.og: %.cc
     399
     400$(OBJG1) : %.og: %.cc
    413401        $(CXXG) ${CXXFLAGSG} ${CXXTEMPLFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@
    414402
     
    416404        $(CCG)  ${CFLAGSG} ${CPPFLAGS} ${DEFSG} -c $< -o $@
    417405
    418 Singularg: scanner.cc gmalloc.og $(OBJG) iparith.og mpsr_Tok.og tesths.cc version.h
     406Singularg: scanner.cc gmalloc.og $(OBJG) iparith.og mpsr_Tok.og claptmpl.og tesths.cc version.h
    419407        $(CXXG) ${CXXFLAGSG} ${CXXTEMPLFLAGSG} ${CPPFLAGS} ${DEFSG} -o Singularg \
    420         tesths.cc iparith.og mpsr_Tok.og $(OBJG) ${LDFLAGS} ${LIBS} \
     408        tesths.cc iparith.og mpsr_Tok.og claptmpl.og $(OBJG) ${LDFLAGS} ${LIBS} \
    421409        ${LD_DYN_FLAGS} gmalloc.og
    422410
  • Singular/cntrlc.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: cntrlc.cc,v 1.24 1999-08-25 16:02:42 Singular Exp $ */
     4/* $Id: cntrlc.cc,v 1.25 1999-09-20 18:03:43 obachman Exp $ */
    55/*
    66* ABSTRACT - interupt handling
     
    1212#include <stdlib.h>
    1313#include <signal.h>
    14 #include "version.h"
    1514#include "mod2.h"
    1615#include "tok.h"
     
    109108void sigsegv_handler(int sig, sigcontext s)
    110109{
    111   fprintf(stderr,"Singular : signal %d (v: %d/%d):\n",sig,SINGULAR_VERSION,SINGULAR_VERSION_ID);
     110  fprintf(stderr,"Singular : signal %d (v: %d/%lu):\n",sig,SINGULAR_VERSION,feVersionId);
    112111  if (sig!=SIGINT)
    113112  {
     
    215214void sigsegv_handler(int sig, int code, struct sigcontext *scp, char *addr)
    216215{
    217   fprintf(stderr,"Singular : signal %d, code %d (v: %d/%d):\n",
    218     sig,code,SINGULAR_VERSION,SINGULAR_VERSION_ID);
     216  fprintf(stderr,"Singular : signal %d, code %d (v: %d/%lu):\n",
     217    sig,code,SINGULAR_VERSION,feVersionId);
    219218  if ((sig!=SIGINT)&&(sig!=SIGABRT))
    220219  {
     
    259258void sigsegv_handler(int sig)
    260259{
    261   fprintf(stderr,"Singular : signal %d (v: %d/%d):\n",
    262     sig,SINGULAR_VERSION,SINGULAR_VERSION_ID);
     260  fprintf(stderr,"Singular : signal %d (v: %d/%lu):\n",
     261    sig,SINGULAR_VERSION,feVersionId);
    263262  if (sig!=SIGINT)
    264263  {
  • Singular/emacs.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: emacs.cc,v 1.7 1999-09-07 08:36:09 Singular Exp $ */
     4/* $Id: emacs.cc,v 1.8 1999-09-20 18:03:43 obachman Exp $ */
    55/*
    66* ABSTRACT: Esingular main file
     
    5050  Warn("Bug occured at %s:%d ", file, line);
    5151  Warn("Message: %s ", msg);
    52   Warn("Version: " S_UNAME S_VERSION1 " (%d) " __DATE__ __TIME__,
    53        SINGULAR_VERSION_ID);
     52  Warn("Version: " S_UNAME S_VERSION1 " (%lu) " __DATE__ __TIME__,
     53       feVersionId);
    5454}
    5555
     
    6363}
    6464#include "feResource.cc"
    65 #include "feCmdLineOptions.cc"
     65#include "feOpt.cc"
     66
     67void mainUsage()
     68{
     69  fprintf(stderr, "Use `%s --help' for a complete list of options\n", feArgv0);
     70}
    6671
    6772int main(int argc, char** argv)
     
    8388  int optc, option_index;
    8489 
    85   while ((optc = getopt_long(argc, argv, SHORT_OPTS_STRING,
    86                              longopts, &option_index))
     90  while ((optc = fe_getopt_long_only(argc, argv, SHORT_OPTS_STRING,
     91                                     feOptSpec, &option_index))
    8792        != EOF)
    8893  {
     
    9095    {
    9196        case 'h':
    92           mainHelp(argv[0]);
     97          feOptHelp(feArgv0);
    9398          exit(0);
    9499         
    95100        case '?':
    96101        case ':':
    97           mainUsage(argv[0]);
     102        case '\0':
     103          mainUsage();
    98104          exit(1);
    99105
    100106        case  LONG_OPTION_RETURN:
    101           if (strcmp(longopts[option_index].name, LON_EMACS) == 0)
     107        {
     108          switch(option_index)
    102109          {
    103             emacs = optarg;
    104           }
    105           else if (strcmp(longopts[option_index].name, LON_EMACS_DIR) == 0)
    106           {
    107             emacs_dir = optarg;
    108           }
    109           else if (strcmp(longopts[option_index].name, LON_EMACS_LOAD) == 0)
    110           {
    111             emacs_load = optarg;
    112           }
    113           else if (strcmp(longopts[option_index].name, LON_SINGULAR) == 0)
    114           {
    115             singular = optarg;
    116           }
    117           else if (strcmp(longopts[option_index].name, LON_NO_EMACS_CALL) == 0)
    118           {
    119             no_emacs_call = 1;
    120           }
    121           else
    122           {
    123             break;
     110              case FE_OPT_EMACS:
     111                emacs = fe_optarg;
     112                break;
     113               
     114              case FE_OPT_EMACS_DIR:
     115                emacs_dir = fe_optarg;
     116                break;
     117               
     118              case FE_OPT_EMACS_LOAD:
     119                emacs_load = fe_optarg;
     120                break;
     121               
     122              case FE_OPT_SINGULAR:
     123                singular = fe_optarg;
     124                break;
     125
     126              case FE_OPT_NO_EMACS_CALL:
     127                no_emacs_call = 1;
     128                break;
     129               
     130              default:
     131                goto NEXT;
    124132          }
    125133          // delete options from option-list
    126           if (optind > 2 && *argv[optind-1] != '-' &&
    127               optarg != NULL && longopts[option_index].has_arg)
     134          if (fe_optind > 2 && *argv[fe_optind-1] != '-' &&
     135              fe_optarg != NULL && feOptSpec[option_index].has_arg)
    128136          {
    129             argv[optind-2] = NULL;
     137            argv[fe_optind-2] = NULL;
    130138          }
    131           argv[optind-1] = NULL;
    132     }
    133   }
     139          argv[fe_optind-1] = NULL;
     140        }
     141    }
     142    NEXT:{}
     143  }
    134144 
    135145  // make sure  emacs, singular, emacs_dir, emacs_load are set
     
    139149    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",
    140150            feResourceDefault("emacs"));
    141     mainUsage(argv[0]);
     151    mainUsage();
    142152    exit(1);
    143153  }
     
    148158    fprintf(stderr, "Error: Can't find singular executable.\nExpected it at %s\nSpecify with --singular option,\n  or set SINGULAR_EMACS environment variable.\n",
    149159            feResourceDefault("SingularEmacs"));
    150     mainUsage(argv[0]);
     160    mainUsage();
    151161    exit(1);
    152162  }
     
    157167    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",
    158168            feResourceDefault("EmacsDir"));
    159     mainUsage(argv[0]);
     169    mainUsage();
    160170    exit(1);
    161171  }
     
    182192          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",
    183193                  feResourceDefault("EmacsLoad")); 
    184           mainUsage(argv[0]);
     194          mainUsage();
    185195          exit(1);
    186196        }
     
    232242    {
    233243      fprintf(stderr, "Error: Executation of\n%s\n");
    234       mainUsage(argv[0]);
     244      mainUsage();
    235245      exit(1);
    236246    }
  • Singular/extra.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR      *
    33*****************************************/
    4 /* $Id: extra.cc,v 1.103 1999-08-20 16:06:49 Singular Exp $ */
     4/* $Id: extra.cc,v 1.104 1999-09-20 18:03:43 obachman Exp $ */
    55/*
    66* ABSTRACT: general interface to internals of Singular ("system" command)
     
    4949#include "syz.h"
    5050#include "sdb.h"
     51#include "feOpt.h"
     52#include "distrib.h"
    5153
    5254// Define to enable many more system commands
     
    237239      res->rtyp = STRING_CMD;
    238240      char* b = StringSetS("");
    239       feStringAppendBrowsers(1);
     241      feStringAppendBrowsers(0);
    240242      res->data = mstrdup(b);
    241243      return FALSE;
     
    316318    if (strstr(sys_cmd, "--") == sys_cmd)
    317319    {
    318       BOOLEAN mainGetSingOptionValue(const char* name, char** result);
    319       char* val;
    320 
    321       if (h != NULL)
    322       {
    323         if (strcmp(sys_cmd, "--browser") == 0)
    324         {
    325           if (h->Typ() == STRING_CMD)
    326           {
    327             if (strcmp(feHelpBrowser((char*) h->Data(), 1),
    328                        (char*) h->Data()) != 0)
    329             {
    330               Werror("Can not set HelpBrowser to '%s'", (char*) h->Data());
    331               return TRUE;
    332             }
    333           }
     320      if (strcmp(sys_cmd, "--") == 0)
     321      {
     322        fePrintOptValues();
     323        return FALSE;
     324      }
     325     
     326      feOptIndex opt = feGetOptIndex(&sys_cmd[2]);
     327      if (opt == FE_OPT_UNDEF)
     328      {
     329        Werror("Unknown option %s", sys_cmd);
     330        Werror("Use 'system(\"--\");' for listing of available options");
     331        return TRUE;
     332      }
     333     
     334      if (h == NULL)
     335      {
     336        if (feOptSpec[opt].type == feOptString)
     337        {
     338          res->rtyp = STRING_CMD;
     339          if (feOptSpec[opt].value != NULL)
     340            res->data = mstrdup((char*) feOptSpec[opt].value);
    334341          else
    335           {
    336             Werror("Need string to set HelpBrowser");
    337             return TRUE;
    338           }
     342            res->data = mstrdup("");
    339343        }
    340344        else
    341345        {
    342           Werror("Can not set value of option %s", sys_cmd);
     346          res->rtyp = INT_CMD;
     347          res->data = feOptSpec[opt].value;
     348        }
     349        return FALSE;
     350      }
     351     
     352      if (h->Typ() != STRING_CMD &&
     353          h->Typ() != INT_CMD)
     354      {
     355        Werror("Need string or int argument to set option value");
     356        return TRUE;
     357      }
     358      char* errormsg;
     359      if (h->Typ() == INT_CMD)
     360      {
     361        if (feOptSpec[opt].type == feOptString)
     362        {
     363          Werror("Need string argument to set value of option %s", sys_cmd);
    343364          return TRUE;
    344365        }
    345       }
    346 
    347       if (mainGetSingOptionValue(&(sys_cmd)[2], &val))
    348       {
    349         if ((unsigned int) val > 1)
    350         {
    351           res->rtyp=STRING_CMD;
    352           if (strcmp(sys_cmd, "--browser") == 0 &&
    353               (val == NULL || *val == '\0'))
    354             res->data = (void*) mstrdup(feHelpBrowser());
    355           else
    356             res->data = (void*) mstrdup( val );
    357         }
    358         else
    359         {
    360           res->rtyp=INT_CMD;
    361           res->data=(void *)val;
    362         }
    363         return FALSE;
    364       }
    365       else
    366       {
    367         Werror("Unknown option %s\n", sys_cmd);
    368         return TRUE;
    369       }
     366        errormsg = feSetOptValue(opt, (int) h->Data());
     367        if (errormsg != NULL)
     368          Werror("Option '--%s=%d' %s", sys_cmd, (int) h->Data(), errormsg);
     369      }
     370      else
     371      {
     372        errormsg = feSetOptValue(opt, (char*) h->Data());
     373        if (errormsg != NULL)
     374          Werror("Option '--%s=%s' %s", sys_cmd, (char*) h->Data(), errormsg);
     375      }
     376      if (errormsg != NULL) return TRUE;
     377      return FALSE;
    370378    }
    371379    else
     
    10051013    }
    10061014    else
    1007 /*==================== print all option values =================*/
    1008 #ifndef NDEBUG
    1009     if (strcmp(sys_cmd, "options") == 0)
    1010     {
    1011       void mainOptionValues();
    1012       mainOptionValues();
    1013       return FALSE;
    1014     }
    1015     else
    1016 #endif
    10171015/*==================== GF =================*/
    10181016#if 0
  • Singular/feResource.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: feResource.cc,v 1.10 1999-08-25 16:02:46 Singular Exp $ */
     4/* $Id: feResource.cc,v 1.11 1999-09-20 18:03:45 obachman Exp $ */
    55/*
    66* ABSTRACT: management of resources
     
    99#include <unistd.h>
    1010
    11 #include "version.h"
    1211#include "mod2.h"
    13 #include "version.h"
     12#include "distrib.h"
    1413#ifndef ESINGULAR
    1514#include "mmemory.h"
     
    9998 *
    10099 *****************************************************************/
    101 static char* feArgv0;
     100char* feArgv0;
    102101#define MAXRESOURCELEN 5*MAXPATHLEN
    103102char fePathSep =
     
    194193  }
    195194#ifdef RESOURCE_DEBUG
    196   printf("feInitResources: entering with argv0=%s=\n", argv0);
     195  printf("feInitResources: entering with argv0=%s=\n", feArgv0);
    197196#endif
    198197  // init some Resources
  • Singular/febase.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: febase.cc,v 1.81 1999-08-25 16:02:46 Singular Exp $ */
     4/* $Id: febase.cc,v 1.82 1999-09-20 18:03:46 obachman Exp $ */
    55/*
    66* ABSTRACT: i/o system
    77*/
    88
    9 #include "version.h"
    109#include "mod2.h"
    1110
     
    362361  Warn("Bug occured at %s:%d", file, line);
    363362  Warn("Message: %s", msg);
    364   Warn("Version: " S_UNAME S_VERSION1 " (%d) " __DATE__ __TIME__,
    365        SINGULAR_VERSION_ID);
     363  Warn("Version: " S_UNAME S_VERSION1 " (%lu) " __DATE__ __TIME__,
     364       feVersionId);
    366365}
    367366
  • Singular/febase.h

    raef7ccb rc06a32  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: febase.h,v 1.36 1999-08-25 16:02:46 Singular Exp $ */
     6/* $Id: febase.h,v 1.37 1999-09-20 18:03:47 obachman Exp $ */
    77/*
    88* ABSTRACT: basic i/o
     
    148148// display general help, otherwise
    149149void feHelp(char* str = NULL);
    150 // if browser != NULL or OptionValue("browser") != NULL
     150// if browser != NULL or feOpt("browser") != NULL
    151151//    set HelpBrowser to browser
    152152// otherwise, if browser was already set, leave as is,
    153153//            if not, choose first available browser
    154154// return string identifying current browser
    155 // keeps OptionValue("browser") up-to-date
     155// keeps feOpt("browser") up-to-date
    156156// Optional warn argument is as in feResource
    157157char* feHelpBrowser(char* browser = NULL, int warn = -1);
    158158void feStringAppendBrowsers(int warn = -1);
    159159
     160/*****************************************************************
     161 *
     162 * version Id
     163 *
     164 *****************************************************************/
     165extern unsigned long feVersionId;
     166
     167/*****************************************************************
     168 *
     169 * File Stuff
     170 *
     171 *****************************************************************/
    160172FILE *  feFopen(char *path, char *mode, char *where=NULL, int useWerror=FALSE);
    161173#ifndef __MWERKS__
  • Singular/fehelp.cc

    raef7ccb rc06a32  
    2121#include "ipshell.h"
    2222#include "libparse.h"
     23#include "feOpt.h"
    2324
    2425/*****************************************************************
     
    149150        Warn("No help for topic '%s' (not even for '*%s*')", str, str);
    150151        WarnS("Try '?;'       for general help");
    151         WarnS("or  '?Index;'  for all available help topics");
     152        WarnS("or  '?Index;'  for all available help topics.");
    152153        return;
    153154      }
     
    182183{
    183184  int i = 0;
    184   extern void mainSetSingOptionValue(const char* name, char* value);
    185   char* mainGetSingOptionValue(const char* name);
    186 
    187   // if no argument, see what we have as value to the option
    188   if (which == NULL || *which == '\0')
    189     which = mainGetSingOptionValue("browser");
    190185
    191186  // if no argument, choose first available help browser
    192187  if (which == NULL || *which == '\0')
    193188  {
    194     // unles one is already set
    195     if (heCurrentHelpBrowser != NULL) goto Finish;
    196 
     189    // return, if already set
     190    if (heCurrentHelpBrowser != NULL)
     191      return heCurrentHelpBrowser->browser;
     192
     193    // First, try emacs, if emacs-option is set
     194    if (feOptValue(FE_OPT_EMACS) != NULL)
     195    {
     196      while (heHelpBrowsers[i].browser != NULL)
     197      {
     198        if (strcmp(heHelpBrowsers[i].browser, "emacs") == 0 &&
     199            (heHelpBrowsers[i].init_proc(0)))
     200        {
     201          heCurrentHelpBrowser = &(heHelpBrowsers[i]);
     202          goto Finish;
     203        }
     204        i++;
     205      }
     206      i=0;
     207    }
    197208    while (heHelpBrowsers[i].browser != NULL)
    198209    {
     
    200211      {
    201212        heCurrentHelpBrowser = &(heHelpBrowsers[i]);
    202         return heCurrentHelpBrowser->browser;
     213        goto Finish;
    203214      }
    204215      i++;
     
    215226  if (heHelpBrowsers[i].browser == NULL)
    216227  {
    217     if (warn) Warn("No help browser '%s' available", which);
     228    if (warn) Warn("No help browser '%s' available.", which);
    218229  }
    219230  else
     
    230241  if (heCurrentHelpBrowser == NULL)
    231242  {
    232     // choose first available help browser
    233     mainSetSingOptionValue("browser", "");
    234243    feHelpBrowser();
    235244    assume(heCurrentHelpBrowser != NULL);
    236245    if (warn)
    237       Warn("Setting help browser to '%s'", heCurrentHelpBrowser->browser);
     246      Warn("Setting help browser to '%s'.", heCurrentHelpBrowser->browser);
    238247    return heCurrentHelpBrowser->browser;
    239248  }
     
    242251    // or, leave as is
    243252    if (warn)
    244       Warn("Help browser stays at '%s'",  heCurrentHelpBrowser->browser);
     253      Warn("Help browser stays at '%s'.",  heCurrentHelpBrowser->browser);
     254    return heCurrentHelpBrowser->browser;
    245255  }
    246256
    247257  Finish:
    248   mainSetSingOptionValue("browser", heCurrentHelpBrowser->browser);
     258  // update value of Browser Option
     259  if (feOptSpec[FE_OPT_BROWSER].value == NULL ||
     260      strcmp((char*) feOptSpec[FE_OPT_BROWSER].value, 
     261             heCurrentHelpBrowser->browser) != 0)
     262  {
     263    if (feOptSpec[FE_OPT_BROWSER].value == NULL)
     264      FreeL(feOptSpec[FE_OPT_BROWSER].value);
     265   feOptSpec[FE_OPT_BROWSER].value
     266     = (void*) mstrdup(heCurrentHelpBrowser->browser);
     267  }
    249268  return heCurrentHelpBrowser->browser;
    250269}
     
    642661    return;
    643662
    644   if (heCurrentHelpBrowser == NULL) feHelpBrowser();
     663  if (heCurrentHelpBrowser == NULL) feHelpBrowser(NULL, 0);
    645664  assume(heCurrentHelpBrowser != NULL);
    646665  if (! feHelpCalled)
     
    722741  {
    723742    if (warn) WarnS("no local HtmlDir found");
    724     if (warn) Warn("using %s instead", feResource('u' /*"ManualUrl"*/, warn));
     743    return FALSE;
     744//    if (warn) Warn("using %s instead", feResource('u' /*"ManualUrl"*/, warn));
    725745  }
    726746  return TRUE;
  • Singular/feread.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: feread.cc,v 1.22 1999-08-25 16:02:47 Singular Exp $ */
     4/* $Id: feread.cc,v 1.23 1999-09-20 18:03:48 obachman Exp $ */
    55/*
    66* ABSTRACT: input from ttys, simulating fgets
     
    88
    99
    10 #include "version.h"
    1110#include "mod2.h"
    1211#include "tok.h"
  • Singular/find_exec.c

    raef7ccb rc06a32  
    6464  {
    6565    if (((name[0] == '.') && (name[1] == '/')) ||
    66         ((name[0] == '.') && (name[1] == '.') && (name[2] == '/')))
    67     {
    68       strcpy (tbuf, (name[1] == '.' ? ".." : "."));
     66        ((name[0] == '.') && (name[1] == '.') && (name[2] == '/')) ||
     67        strchr(name, '/') != NULL)
     68    {
    6969
    7070#ifdef HAVE_GETCWD
     
    7777      strcat (tbuf, "/");
    7878      strcat (tbuf, name);
    79       return copy_of (tbuf);
    80     }
    81 
     79      if (! access(name, X_OK))
     80        return copy_of (tbuf);
     81    }
    8282
    8383    search = getenv("PATH");
  • Singular/getopt.h

    raef7ccb rc06a32  
    1616   Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
    1717
     18/* obachman: adapted to Singular by adding prefix fe_ to global variables
     19 */
    1820#ifndef _GETOPT_H
    1921#define _GETOPT_H 1
     
    2931   each non-option ARGV-element is returned here.  */
    3032
    31 extern char *optarg;
     33extern char *fe_optarg;
    3234
    3335/* Index in ARGV of the next element to be scanned.
     
    4345   how much of ARGV has been scanned so far.  */
    4446
    45 extern int optind;
     47extern int fe_optind;
    4648
    4749/* Callers store zero here to inhibit the error message `getopt' prints
    4850   for unrecognized options.  */
    4951
    50 extern int opterr;
     52extern int fe_opterr;
    5153
    5254/* Set to an option character which was unrecognized.  */
    5355
    54 extern int optopt;
     56extern int fe_optopt;
    5557
    5658/* Describe the long-named options requested by the application.
     
    7577   returns the contents of the `val' field.  */
    7678
    77 struct option
     79typedef enum {feOptBool=0, feOptInt, feOptString} feOptType;
     80struct fe_option
    7881{
    7982#if        __STDC__
     
    8790  int *flag;
    8891  int val;
     92  /* Stuff added for Singular  */
     93  const char*   arg_name;// name of argument, for display in help
     94  const char*   help;    // (short) help string
     95  feOptType     type;    // type of argument, if has_arg > 0
     96  void*         value;   // (default) value of option
     97  int           set;     // only relevant for strings: 0 if not set, 1 if set
    8998};
    9099
    91100/* Names for the values of the `has_arg' field of `struct option'.  */
    92101
    93 #define        no_argument                0
     102#define        no_argument       0
    94103#define required_argument        1
    95104#define optional_argument        2
     
    100109   differences in the consts, in stdlib.h.  To avoid compilation
    101110   errors, only prototype getopt for the GNU C library.  */
    102 extern int getopt (int argc, char *const *argv, const char *shortopts);
     111extern int fe_getopt (int argc, char *const *argv, const char *shortopts);
    103112#endif /* not __GNU_LIBRARY__ */
    104 extern int getopt_long (int argc, char *const *argv, const char *shortopts,
    105                         const struct option *longopts, int *longind);
    106 extern int getopt_long_only (int argc, char *const *argv,
     113extern int fe_getopt_long (int argc, char *const *argv, const char *shortopts,
     114                        const struct fe_option *longopts, int *longind);
     115extern int fe_getopt_long_only (int argc, char *const *argv,
    107116                             const char *shortopts,
    108                              const struct option *longopts, int *longind);
     117                             const struct fe_option *longopts, int *longind);
    109118
    110119/* Internal only.  Users should not call this directly.  */
    111 extern int _getopt_internal (int argc, char *const *argv,
     120extern int _fe_getopt_internal (int argc, char *const *argv,
    112121                             const char *shortopts,
    113                              const struct option *longopts, int *longind,
     122                             const struct fe_option *longopts, int *longind,
    114123                             int long_only);
    115124#else /* not __STDC__ */
    116 extern int getopt ();
    117 extern int getopt_long ();
    118 extern int getopt_long_only ();
     125extern int fe_getopt ();
     126extern int fe_getopt_long ();
     127extern int fe_getopt_long_only ();
    119128
    120 extern int _getopt_internal ();
     129extern int _fe_getopt_internal ();
    121130#endif /* not __STDC__ */
    122131
  • Singular/ipshell.h

    raef7ccb rc06a32  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: ipshell.h,v 1.19 1999-07-28 17:51:07 Singular Exp $ */
     6/* $Id: ipshell.h,v 1.20 1999-09-20 18:03:49 obachman Exp $ */
    77/*
    88* ABSTRACT
     
    2424extern int  myynest;
    2525extern char *  currid;
    26 extern char * thisfile;
     26extern char * feArgv0;
    2727extern int     iiRETURNEXPR_len;
    2828extern sleftv *iiRETURNEXPR;
  • Singular/kbPolyProcs.cc

    raef7ccb rc06a32  
    373373
    374374  // set characterisic
    375   if (r->ch > 1) ch = chMODP;
     375  if (rField_is_Zp(r)) ch = chMODP;
    376376 
    377377  // set Ordering Type
  • Singular/misc.cc

    raef7ccb rc06a32  
    1414#include <limits.h>
    1515
    16 #include "version.h"
    1716#include "mod2.h"
    1817#include "tok.h"
  • Singular/mmisc.c

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: mmisc.c,v 1.9 1999-08-18 09:18:28 obachman Exp $ */
     4/* $Id: mmisc.c,v 1.10 1999-09-20 18:03:50 obachman Exp $ */
    55
    66/*
     
    1313#include "mmpage.h"
    1414#include "febase.h"
     15#include "distrib.h"
     16
    1517#ifdef MTRACK
    1618#include "mmbt.h"
  • Singular/sing_mp.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: sing_mp.cc,v 1.26 1999-08-13 11:21:44 Singular Exp $ */
     4/* $Id: sing_mp.cc,v 1.27 1999-09-20 18:03:50 obachman Exp $ */
    55
    66/*
     
    2222#include "ipid.h"
    2323#include "silink.h"
     24#include "feOpt.h"
    2425
    2526static int Batch_ReadEval(si_link silink);
     
    164165 *
    165166 ***************************************************************/
    166 extern BOOLEAN mainGetSingOptionValue(const char* name, char** val);
    167 
    168167
    169168static MP_Link_pt slOpenMPConnect(int n_argc, char **n_argv)
     
    175174  char *host = IMP_GetCmdlineArg(n_argc, n_argv, "--MPhost");
    176175
    177   if (port == NULL) mainGetSingOptionValue("--MPport", &port);
    178   if (host == NULL) mainGetSingOptionValue("--MPhost", &host);
     176  if (port == NULL) port = (char*) feOptValue(FE_OPT_MP_PORT);
     177  if (host == NULL) host = (char*) feOptValue(FE_OPT_MP_HOST);
    179178
    180179  if (port != NULL)
     
    194193  char *port = IMP_GetCmdlineArg(n_argc, n_argv, "--MPport");
    195194
    196   if (port == NULL) mainGetSingOptionValue("--MPport", &port);
     195  if (port == NULL) port = (char*) feOptValue(FE_OPT_MP_HOST);
    197196
    198197  if (port != NULL) argv[5] = port;
  • Singular/tesths.cc

    raef7ccb rc06a32  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: tesths.cc,v 1.69 1999-08-25 15:26:02 obachman Exp $ */
     4/* $Id: tesths.cc,v 1.70 1999-09-20 18:03:51 obachman Exp $ */
    55
    66/*
     
    1515#include <time.h>
    1616#include <errno.h>
    17 #include "version.h"
    1817#include "mod2.h"
    1918#include "tok.h"
     
    2726#include "timer.h"
    2827#include "sdb.h"
     28#include "fegetopt.h"
     29#include "feOpt.h"
     30#include "distrib.h"
     31#include "version.h"
     32
    2933#ifdef HAVE_FACTORY
    3034#define SI_DONT_HAVE_GLOBAL_VARS
     
    3236#endif
    3337
    34 #include "feCmdLineOptions.cc"
    3538/*0 implementation*/
    3639int main(          /* main entry to Singular */
     
    3841    char** argv)   /* parameter array */
    3942{
    40   char * thisfile;
    41   /* initialize components */
    42   siRandomStart=inits();
    4343#ifdef INIT_BUG
    4444  jjInitTab1();
     
    5454  ttGen2();
    5555#else
    56   thisfile = argv[0];
    57   BOOLEAN load_std_lib=TRUE;
    58   BOOLEAN load_rc = TRUE;
    59   char* execute_string = NULL;
     56  /* initialize components */
     57  siRandomStart=inits();
     58  feOptSpec[FE_OPT_RANDOM].value = (void*) siRandomStart;
    6059  int optc, option_index;
     60  char* errormsg;
    6161
    6262  // do this first, because -v might print version path
    63   feInitResources(thisfile);
     63  feInitResources(argv[0]);
    6464
    6565  // parse command line options
    66   while((optc = getopt_long(argc, argv,
    67                             SHORT_OPTS_STRING, longopts, &option_index))
     66  while((optc = fe_getopt_long_only(argc, argv,
     67                               SHORT_OPTS_STRING, feOptSpec, &option_index))
     68//                               "", feOptSpec, &option_index))
    6869        != EOF)
    6970  {
    70     switch(optc)
    71     {
    72 
    73         case 'b':
    74 #ifdef HAVE_MPSR
    75           fe_fgets_stdin=fe_fgets_dummy;
    76           mainSetSingOptionValue(LON_BATCH, (char*) 1);
    77           break;
    78 #else
    79           printf("%s: Option `-b' not supported in this configuration\n", argv[0]);
    80           mainUsage(argv[0]);
    81           exit(1);
    82 #endif
    83         case 'h':
    84           mainHelp(argv[0]);
    85           exit(0);
    86 
    87         case 'q':
    88           verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
    89           mainSetSingOptionValue(LON_QUIET, (char*) 1);
    90           break;
    91 
    92         case 't':
    93 #if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
    94           fe_fgets_stdin=fe_fgets;
    95 #endif
    96           mainSetSingOptionValue(LON_NO_TTY, (char*) 1);
    97           break;
    98 
    99         case 'd':
    100           sdb_flags = 1;
    101           break;
    102 
    103         case 'v':
    104           printf("Singular for %s version %s  (%d)  %s %s\n",
    105                  S_UNAME, S_VERSION1,
    106                  SINGULAR_VERSION_ID,__DATE__,__TIME__);
    107           printf("with\n");
    108           printf(versionString());
    109           printf("\n\n");
    110           mainSetSingOptionValue(LON_VERSION, (char*) 1);
    111           break;
    112 
    113         case 'x':
    114 #ifdef HAVE_TCL
    115           tclmode = TRUE;
    116           fe_fgets_stdin=fe_fgets_tcl;
    117           mainSetSingOptionValue(LON_TCLMODE, (char*) 1);
    118           verbose|=Sy_bit(V_SHOW_MEM);
    119           break;
    120 #else
    121           printf("%s: Option `-x' not supported in this configuration\n", argv[0]);
    122           mainUsage(argv[0]);
    123           exit(1);
    124 #endif
    125 
    126         case 'e':
    127           if (optarg != NULL)
    128           {
    129             errno = 0;
    130             si_echo = strtol(optarg, NULL, 10);
    131             if (errno)
    132             {
    133               printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO);
    134               mainUsage(argv[0]);
    135               exit(1);
    136             }
    137             if (si_echo < 0 || si_echo > 9)
    138             {
    139               printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n",
    140                      argv[0], optarg, LON_ECHO);
    141               mainUsage(argv[0]);
    142               exit(1);
    143             }
    144             mainSetSingOptionValue(LON_ECHO, optarg);
    145           }
    146           else
    147           {
    148             si_echo = 1;
    149             mainSetSingOptionValue(LON_ECHO, "1");
    150           }
    151           break;
    152 
    153         case 'c':
    154           execute_string = optarg;
    155           mainSetSingOptionValue(LON_EXECUTE, optarg);
    156           break;
    157 
    158         case 'r':
    159           errno = 0;
    160           siRandomStart = strtol(optarg, NULL, 10);
    161           if (errno || siRandomStart == 0)
    162           {
    163             printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM);
    164             mainUsage(argv[0]);
    165             exit(1);
    166           }
    167           #ifdef buildin_rand
    168           siSeed=siRandomStart;
    169           #else
    170           srand((unsigned int)siRandomStart);
    171           #endif
    172           #ifdef HAVE_FACTORY
    173           factoryseed(siRandomStart);
    174           #endif
    175           mainSetSingOptionValue(LON_RANDOM, optarg);
    176           break;
    177 
    178         case 'u':
    179           mainSetSingOptionValue(LON_USER_OPTION, optarg);
    180           break;
    181 
    182         case LONG_OPTION_RETURN:
    183           if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0)
    184           {
    185             load_std_lib = FALSE;
    186             mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1);
    187           }
    188           else if (strcmp(longopts[option_index].name, LON_BROWSER) == 0)
    189           {
    190             mainSetSingOptionValue(LON_BROWSER, optarg);
    191           }
    192           else if (strcmp(longopts[option_index].name, LON_EMACS) == 0)
    193           {
    194             mainSetSingOptionValue(LON_EMACS, (char*) 1);
    195             // print EmacsDir and InfoFile so that Emacs
    196             // mode can pcik it up
    197             Warn("EmacsDir: %s", (feResource('e' /*"EmacsDir"*/) != NULL ?
    198                                   feResource('e' /*"EmacsDir"*/) : ""));
    199             Warn("InfoFile: %s", (feResource('i' /*"InfoFile"*/) != NULL ?
    200                                   feResource('i' /*"InfoFile"*/) : ""));
    201           }
    202           else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0)
    203           {
    204             load_rc = FALSE;
    205             mainSetSingOptionValue(LON_NO_RC, (char*) 1);
    206           }
    207           else if (strcmp(longopts[option_index].name, LON_NO_WARN) == 0)
    208           {
    209             feWarn = FALSE;
    210             mainSetSingOptionValue(LON_NO_WARN, (char*) 1);
    211           }
    212           else if (strcmp(longopts[option_index].name, LON_NO_OUT) == 0)
    213           {
    214             feOut = FALSE;
    215             mainSetSingOptionValue(LON_NO_OUT, (char*) 1);
    216           }
    217           else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0)
    218           {
    219             double mintime = atof(optarg);
    220             if (mintime <= 0)
    221             {
    222               printf("%s: `%s' invalid float argument for option `--%s'\n",
    223                      argv[0], optarg, LON_MIN_TIME);
    224               mainUsage(argv[0]);
    225               exit(1);
    226             }
    227             SetMinDisplayTime(mintime);
    228             mainSetSingOptionValue(LON_MIN_TIME, optarg);
    229           }
    230 #ifdef HAVE_MPSR
    231           else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0)
    232           {
    233             mainSetSingOptionValue(LON_MP_PORT, optarg);
    234           }
    235           else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0)
    236           {
    237             mainSetSingOptionValue(LON_MP_HOST, optarg);
    238           }
    239 #endif
    240           else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0)
    241           {
    242             int ticks = atoi(optarg);
    243             if (ticks <= 0)
    244             {
    245               printf("%s: `%s' invalid integer argument for option `--%s'\n",
    246                      argv[0], optarg, LON_TICKS_PER_SEC);
    247               mainUsage(argv[0]);
    248               exit(1);
    249             }
    250             SetTimerResolution(ticks);
    251             mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg);
    252           }
    253           else
    254             // undocumented options
    255 #ifdef HAVE_MPSR
    256             if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 ||
    257                 strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0)
    258             {
    259               /* ignore */
    260             }
    261           else
    262 #endif
    263             assume(0);
    264           break;
    265 
    266         default:
    267           // Error message already emmited by getopt_long
    268           mainUsage(argv[0]);
    269           exit(1);
    270     }
    271   }
     71    if (optc == '?' || optc == 0)
     72    {
     73      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
     74      exit(1);
     75    }
     76
     77    if (optc != LONG_OPTION_RETURN)
     78      option_index = feGetOptIndex(optc);
     79
     80    assume(option_index > 0 && option_index < (int) FE_OPT_UNDEF);
     81   
     82    if (fe_optarg == NULL &&
     83        (feOptSpec[option_index].type == feOptBool ||
     84         feOptSpec[option_index].has_arg == optional_argument))
     85      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
     86    else
     87      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
     88   
     89    if (errormsg)
     90    {
     91      if (fe_optarg == NULL)
     92        fprintf(stderr, "Error: Option '--%s' %s\n",
     93               feOptSpec[option_index].name, errormsg);
     94      else
     95        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
     96               feOptSpec[option_index].name, fe_optarg, errormsg);
     97      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
     98      exit(1);
     99    }
     100    if (optc == 'h') exit(0);
     101  }
     102
    272103  /* say hello */
    273104  {
     
    307138  }
    308139  slStandardInit();
    309   dlInit(thisfile);
     140  dlInit(feArgv0);
    310141  myynest=0;
    311   if (load_std_lib)
     142  if (! feOptValue(FE_OPT_NO_STDLIB))
    312143  {
    313144    int vv=verbose;
     
    327158
    328159  // Last thing to do is to execute given scripts
    329   if (optind < argc)
     160  if (fe_optind < argc)
    330161  {
    331162    int i = argc - 1;
    332     while (i >= optind)
     163    while (i >= fe_optind)
    333164    {
    334165      newFile(argv[i]);
     
    342173
    343174  // before scripts, we execute -c, if it was given
    344   // now execute -c, if it was given
    345   if (execute_string != NULL)
    346     newBuffer(mstrdup(execute_string), BT_execute);
     175  if (feOptValue(FE_OPT_EXECUTE) != NULL)
     176    newBuffer(mstrdup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
    347177
    348178  // first thing, however, is to load .singularrc
    349   if (load_rc)
     179  if (! feOptValue(FE_OPT_NO_RC))
    350180  {
    351181    FILE * rc=myfopen(".singularrc","r");
     
    378208#ifdef HAVE_MPSR
    379209    extern int Batch_do(const char* port, const char* host);
    380     return Batch_do(mainGetSingOptionValue(LON_MP_PORT),
    381                     mainGetSingOptionValue(LON_MP_HOST));
     210    return Batch_do((char*) feOptValue(FE_OPT_MP_PORT),
     211                    (char*) feOptValue(FE_OPT_MP_HOST));
    382212#else
    383213    assume(0);
     
    391221  return 0;
    392222}
     223
  • Singular/utils.cc

    raef7ccb rc06a32  
    33#include <stdlib.h>
    44#include <ctype.h>
    5 #include "getopt.h"
     5#include "fegetopt.h"
    66#include "utils.h"
    77#ifdef __MWERKS__
    88#define __GNU_LIBRARY__
    9 #include "getopt.h"
     9#include "fegetopt.h"
    1010#endif
    1111
     
    3838  char c;
    3939
    40   while((c=getopt(argc, argv, "ihd:sf:"))>=0) {
     40  while((c=fe_getopt(argc, argv, "ihd:sf:"))>=0) {
    4141    switch(c) {
    4242        case 'd':
    4343          lpverbose = 1;
    44           if(isdigit(argv[optind-1][0])) sscanf(optarg, "%d", &lpverbose);
    45           else optind--;
    46           break;
    47         case 'f': lib_file = argv[optind-1];
     44          if(isdigit(argv[fe_optind-1][0])) sscanf(optarg, "%d", &lpverbose);
     45          else fe_optind--;
     46          break;
     47        case 'f': lib_file = argv[fe_optind-1];
    4848          break;
    4949        case 's':
     
    5757          break;
    5858         
    59         case -1 : printf("no such option:%s\n", argv[optind]);
     59        case -1 : printf("no such option:%s\n", argv[fe_optind]);
    6060          usage(argv[0]);
    6161          break;
    62         default: printf("no such option.%x, %c %s\n", c&0xff, c, argv[optind]);
     62        default: printf("no such option.%x, %c %s\n", c&0xff, c, argv[fe_optind]);
    6363          usage(argv[0]);
    6464    }
     
    7373      printf("$library = \"%s\";\n", lib_file);
    7474  } else {
    75     while(argc>optind && yylpin==NULL) {
    76       yylpin = fopen( argv[optind], "rb" );
     75    while(argc>fe_optind && yylpin==NULL) {
     76      yylpin = fopen( argv[fe_optind], "rb" );
    7777      if(yylpin!=NULL)
    7878      {
    79         lib_file = argv[optind];
     79        lib_file = argv[fe_optind];
    8080        if (! texinfo_out)
    81           printf("Checking library '%s'\n", argv[optind]);
     81          printf("Checking library '%s'\n", argv[fe_optind]);
    8282        else
    8383          printf("$library = \"%s\";\n", lib_file);
    8484      }
    85       else optind++;
     85      else fe_optind++;
    8686    }
    8787  }
Note: See TracChangeset for help on using the changeset viewer.