My Project  UNKNOWN_GIT_VERSION
Macros | Functions | Variables
feOpt.cc File Reference
#include "kernel/mod2.h"
#include "factory/factory.h"
#include "feOpt.h"
#include "misc/options.h"
#include "misc/sirandom.h"
#include "fehelp.h"
#include "omalloc/omalloc.h"
#include "resources/feResource.h"
#include "kernel/oswrapper/feread.h"
#include "kernel/oswrapper/timer.h"
#include "ipshell.h"
#include "tok.h"
#include "sdb.h"
#include "cntrlc.h"
#include <errno.h>

Go to the source code of this file.

Macros

#define FE_OPT_STRUCTURE
 

Functions

feOptIndex feGetOptIndex (const char *name)
 
feOptIndex feGetOptIndex (int optc)
 
static const char * feOptAction (feOptIndex opt)
 
const char * feSetOptValue (feOptIndex opt, char *optarg)
 
const char * feSetOptValue (feOptIndex opt, int optarg)
 
void fePrintOptValues ()
 
void feOptHelp (const char *name)
 
void feOptDumpVersionTuple (void)
 

Variables

const char SHORT_OPTS_STRING [] = "bdhpqstvxec:r:u:"
 

Macro Definition Documentation

◆ FE_OPT_STRUCTURE

#define FE_OPT_STRUCTURE

Definition at line 16 of file feOpt.cc.

Function Documentation

◆ feGetOptIndex() [1/2]

feOptIndex feGetOptIndex ( const char *  name)

Definition at line 101 of file feOpt.cc.

102 {
103  int opt = 0;
104 
105  while (opt != (int) FE_OPT_UNDEF)
106  {
107  if (strcmp(feOptSpec[opt].name, name) == 0)
108  return (feOptIndex) opt;
109  opt = opt + 1;
110  }
111  return FE_OPT_UNDEF;
112 }

◆ feGetOptIndex() [2/2]

feOptIndex feGetOptIndex ( int  optc)

Definition at line 114 of file feOpt.cc.

115 {
116  int opt = 0;
117 
118  if (optc == LONG_OPTION_RETURN) return FE_OPT_UNDEF;
119 
120  while (opt != (int) FE_OPT_UNDEF)
121  {
122  if (feOptSpec[opt].val == optc)
123  return (feOptIndex) opt;
124  opt = opt + 1;
125  }
126  return FE_OPT_UNDEF;
127 }

◆ feOptAction()

static const char * feOptAction ( feOptIndex  opt)
static

Definition at line 198 of file feOpt.cc.

199 {
200  // do some special actions
201  switch(opt)
202  {
203  case FE_OPT_BATCH:
204  if (feOptSpec[FE_OPT_BATCH].value)
206  return NULL;
207 
208  case FE_OPT_HELP:
210  return NULL;
211 
212  case FE_OPT_PROFILE:
213  traceit=1024;
214  return NULL;
215 
216  case FE_OPT_QUIET:
217  if (feOptSpec[FE_OPT_QUIET].value)
218  si_opt_2 &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
219  else
221  return NULL;
222 
223  case FE_OPT_NO_TTY:
224  if (feOptSpec[FE_OPT_NO_TTY].value)
226  return NULL;
227 
228  case FE_OPT_SDB:
229  #ifdef HAVE_SDB
230  if (feOptSpec[FE_OPT_SDB].value)
231  sdb_flags = 1;
232  else
233  sdb_flags = 0;
234  #endif
235  return NULL;
236 
237  case FE_OPT_VERSION:
238  {
239  char *s=versionString();
240  printf("%s",s);
241  omFree(s);
242  return NULL;
243  }
244 
245  case FE_OPT_ECHO:
246  si_echo = (int) ((long)(feOptSpec[FE_OPT_ECHO].value));
247  if (si_echo < 0 || si_echo > 9)
248  return "argument of option is not in valid range 0..9";
249  return NULL;
250 
251  case FE_OPT_RANDOM:
252  siRandomStart = (unsigned int) ((unsigned long)
253  (feOptSpec[FE_OPT_RANDOM].value));
256  return NULL;
257 
258  case FE_OPT_EMACS:
259  if (feOptSpec[FE_OPT_EMACS].value)
260  {
261  // print EmacsDir and InfoFile so that Emacs
262  // mode can pcik it up
263  Warn("EmacsDir: %s", (feResource('e' /*"EmacsDir"*/) != NULL ?
264  feResource('e' /*"EmacsDir"*/) : ""));
265  Warn("InfoFile: %s", (feResource('i' /*"InfoFile"*/) != NULL ?
266  feResource('i' /*"InfoFile"*/) : ""));
267  }
268  return NULL;
269 
270  case FE_OPT_NO_WARN:
271  if (feOptSpec[FE_OPT_NO_WARN].value)
272  feWarn = FALSE;
273  else
274  feWarn = TRUE;
275  return NULL;
276 
277  case FE_OPT_NO_OUT:
278  if (feOptSpec[FE_OPT_NO_OUT].value)
279  feOut = FALSE;
280  else
281  feOut = TRUE;
282  return NULL;
283 
284  case FE_OPT_MIN_TIME:
285  {
286  double mintime = atof((char*) feOptSpec[FE_OPT_MIN_TIME].value);
287  if (mintime <= 0) return "invalid float argument";
289  return NULL;
290  }
291 
292  case FE_OPT_BROWSER:
293  feHelpBrowser((char*) feOptSpec[FE_OPT_BROWSER].value, 1);
294 
295  case FE_OPT_TICKS_PER_SEC:
296  {
297  int ticks = (int) ((long)(feOptSpec[FE_OPT_TICKS_PER_SEC].value));
298  if (ticks <= 0)
299  return "integer argument must be larger than 0";
300  SetTimerResolution(ticks);
301  return NULL;
302  }
303 
304  case FE_OPT_DUMP_VERSIONTUPLE:
305  {
307  return NULL;
308  }
309 
310  default:
311  return NULL;
312  }
313 }

◆ feOptDumpVersionTuple()

void feOptDumpVersionTuple ( void  )

Definition at line 402 of file feOpt.cc.

403 {
404  printf("%s\n",VERSION);
405 }

◆ feOptHelp()

void feOptHelp ( const char *  name)

Definition at line 351 of file feOpt.cc.

352 {
353  int i = 0;
354  char tmp[20];
355 #if defined(ESINGULAR)
356  printf("ESingular starts up Singular within emacs;\n");
357 #elif defined(TSINGULAR)
358  printf("TSingular starts up Singular within a terminal window;\n");
359 #endif
360  printf("Singular is a Computer Algebra System (CAS) for Polynomial Computations.\n");
361  printf("Usage: %s [options] [file1 [file2 ...]]\n", name);
362  printf("Options:\n");
363 
364  while (feOptSpec[i].name != 0)
365  {
366  if (feOptSpec[i].help != NULL
367 #ifdef SING_NDEBUG
368  && *(feOptSpec[i].help) != '/'
369 #endif
370  )
371  {
372  if (feOptSpec[i].has_arg > 0)
373  {
374  if (feOptSpec[i].has_arg > 1)
375  sprintf(tmp, "%s[=%s]", feOptSpec[i].name, feOptSpec[i].arg_name);
376  else
377  sprintf(tmp, "%s=%s", feOptSpec[i].name, feOptSpec[i].arg_name);
378 
379  printf(" %c%c --%-20s %s\n",
380  (feOptSpec[i].val != LONG_OPTION_RETURN ? '-' : ' '),
382  tmp,
383  feOptSpec[i].help);
384  }
385  else
386  {
387  printf(" %c%c --%-20s %s\n",
388  (feOptSpec[i].val != LONG_OPTION_RETURN ? '-' : ' '),
390  feOptSpec[i].name,
391  feOptSpec[i].help);
392  }
393  }
394  i++;
395  }
396 
397  printf("\nFor more information, type `help;' from within Singular or visit\n");
398  printf("http://www.singular.uni-kl.de or consult the\n");
399  printf("Singular manual (available as on-line info or html manual).\n");
400 }

◆ fePrintOptValues()

void fePrintOptValues ( )

Definition at line 316 of file feOpt.cc.

317 {
318  int i = 0;
319 
320  while (feOptSpec[i].name != 0)
321  {
323 #ifndef SING_NDEBUG
324  && *(feOptSpec[i].help) != '/'
325 #endif
326  )
327  {
328  if (feOptSpec[i].type == feOptString)
329  {
330  if (feOptSpec[i].value == NULL)
331  {
332  Print("// --%-15s\n", feOptSpec[i].name);
333  }
334  else
335  {
336  Print("// --%-15s \"%s\"\n", feOptSpec[i].name, (char*) feOptSpec[i].value);
337  }
338  }
339  else
340  {
341  Print("// --%-15s %d\n", feOptSpec[i].name, (int)(long)feOptSpec[i].value);
342  }
343  }
344  i++;
345  }
346 }

◆ feSetOptValue() [1/2]

const char* feSetOptValue ( feOptIndex  opt,
char *  optarg 
)

Definition at line 150 of file feOpt.cc.

151 {
152  if (opt == FE_OPT_UNDEF) return "option undefined";
153 
154  if (feOptSpec[opt].type != feOptUntyped)
155  {
156  if (feOptSpec[opt].type != feOptString)
157  {
158  if (optarg != NULL)
159  {
160  errno = 0;
161  feOptSpec[opt].value = (void*) strtol(optarg, NULL, 10);
162  if (errno) return "invalid integer argument";
163  }
164  else
165  {
166  feOptSpec[opt].value = (void*) 0;
167  }
168  }
169  else
170  {
171  assume(feOptSpec[opt].type == feOptString);
172  if (feOptSpec[opt].set && feOptSpec[opt].value != NULL)
173  omFree(feOptSpec[opt].value);
174  if (optarg != NULL)
175  feOptSpec[opt].value = omStrDup(optarg);
176  else
177  feOptSpec[opt].value = NULL;
178  feOptSpec[opt].set = 1;
179  }
180  }
181  return feOptAction(opt);
182 }

◆ feSetOptValue() [2/2]

const char* feSetOptValue ( feOptIndex  opt,
int  optarg 
)

Definition at line 184 of file feOpt.cc.

185 {
186  if (opt == FE_OPT_UNDEF) return "option undefined";
187 
188  if (feOptSpec[opt].type != feOptUntyped)
189  {
190  if (feOptSpec[opt].type == feOptString)
191  return "option value needs to be an integer";
192 
193  feOptSpec[opt].value = (void*)(long) optarg;
194  }
195  return feOptAction(opt);
196 }

Variable Documentation

◆ SHORT_OPTS_STRING

const char SHORT_OPTS_STRING[] = "bdhpqstvxec:r:u:"

Definition at line 26 of file feOpt.cc.

feOptAction
static const char * feOptAction(feOptIndex opt)
Definition: feOpt.cc:198
FALSE
#define FALSE
Definition: auxiliary.h:94
fe_fgets_dummy
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:451
si_echo
int si_echo
Definition: febase.cc:35
versionString
char * versionString()
Definition: misc_ip.cc:789
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
VERSION
#define VERSION
Definition: mod2.h:18
fe_option::val
int val
Definition: fegetopt.h:88
feOptIndex
feOptIndex
Definition: feOptGen.h:15
SetMinDisplayTime
void SetMinDisplayTime(double mtime)
Definition: timer.cc:29
feOptUntyped
@ feOptUntyped
Definition: fegetopt.h:77
LONG_OPTION_RETURN
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:263
V_LOAD_LIB
#define V_LOAD_LIB
Definition: options.h:47
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:34
siRandomStart
int siRandomStart
Definition: cntrlc.cc:98
feOptDumpVersionTuple
void feOptDumpVersionTuple(void)
Definition: feOpt.cc:402
feArgv0
char * feArgv0
Definition: feResource.cc:19
fe_option::set
int set
Definition: fegetopt.h:94
factoryseed
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:176
feOut
BOOLEAN feOut
Definition: reporter.cc:50
fe_fgets
char * fe_fgets(const char *pr, char *s, int size)
Definition: feread.cc:310
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
feWarn
BOOLEAN feWarn
Definition: reporter.cc:49
Sy_bit
#define Sy_bit(x)
Definition: options.h:32
mintime
static double mintime
Definition: timer.cc:22
fe_option::arg_name
const char * arg_name
Definition: fegetopt.h:90
fe_option::type
feOptType type
Definition: fegetopt.h:92
help
#define help
Definition: libparse.cc:1228
feOptSpec
struct fe_option feOptSpec[]
feResource
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:258
Print
#define Print
Definition: emacs.cc:80
FE_OPT_UNDEF
@ FE_OPT_UNDEF
Definition: feOptGen.h:15
name
char name(const Variable &v)
Definition: factory.h:180
assume
#define assume(x)
Definition: mod2.h:390
NULL
#define NULL
Definition: omList.c:10
siSeed
int siSeed
Definition: sirandom.c:29
fe_option::value
void * value
Definition: fegetopt.h:93
Warn
#define Warn
Definition: emacs.cc:77
traceit
int traceit
Definition: febase.cc:42
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
SING_NDEBUG
#define SING_NDEBUG
Definition: factoryconf.h:269
SetTimerResolution
void SetTimerResolution(int res)
Definition: timer.cc:24
fe_option::has_arg
int has_arg
Definition: fegetopt.h:87
feOptHelp
void feOptHelp(const char *name)
Definition: feOpt.cc:351
feHelpBrowser
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:252
sdb_flags
int sdb_flags
Definition: sdb.cc:32
si_opt_2
unsigned si_opt_2
Definition: options.c:6
feOptString
@ feOptString
Definition: fegetopt.h:77