My Project
Macros | Functions | Variables
feOpt.cc File Reference
#include <string.h>
#include "kernel/mod2.h"
#include "factory/factory.h"
#include "feOpt.h"
#include "misc/options.h"
#include "misc/sirandom.h"
#include "fehelp.h"
#include <flint/flint.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 15 of file feOpt.cc.

Function Documentation

◆ feGetOptIndex() [1/2]

feOptIndex feGetOptIndex ( const char *  name)

Definition at line 104 of file feOpt.cc.

105 {
106  int opt = 0;
107 
108  while (opt != (int) FE_OPT_UNDEF)
109  {
110  if (strcmp(feOptSpec[opt].name, name) == 0)
111  return (feOptIndex) opt;
112  opt = opt + 1;
113  }
114  return FE_OPT_UNDEF;
115 }
char name(const Variable &v)
Definition: factory.h:196
feOptIndex
Definition: feOptGen.h:15
@ FE_OPT_UNDEF
Definition: feOptGen.h:15
EXTERN_VAR struct fe_option feOptSpec[]
Definition: feOpt.h:17

◆ feGetOptIndex() [2/2]

feOptIndex feGetOptIndex ( int  optc)

Definition at line 117 of file feOpt.cc.

118 {
119  int opt = 0;
120 
121  if (optc == LONG_OPTION_RETURN) return FE_OPT_UNDEF;
122 
123  while (opt != (int) FE_OPT_UNDEF)
124  {
125  if (feOptSpec[opt].val == optc)
126  return (feOptIndex) opt;
127  opt = opt + 1;
128  }
129  return FE_OPT_UNDEF;
130 }
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4

◆ feOptAction()

static const char * feOptAction ( feOptIndex  opt)
static

Definition at line 202 of file feOpt.cc.

203 {
204  // do some special actions
205  switch(opt)
206  {
207  case FE_OPT_BATCH:
208  if (feOptSpec[FE_OPT_BATCH].value)
210  return NULL;
211 
212  case FE_OPT_HELP:
214  return NULL;
215 
216  case FE_OPT_PROFILE:
217  traceit=1024;
218  return NULL;
219 
220  case FE_OPT_QUIET:
221  if (feOptSpec[FE_OPT_QUIET].value)
222  si_opt_2 &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
223  else
225  return NULL;
226 
227  case FE_OPT_NO_TTY:
228  if (feOptSpec[FE_OPT_NO_TTY].value)
230  return NULL;
231 
232  case FE_OPT_SDB:
233  #ifdef HAVE_SDB
234  if (feOptSpec[FE_OPT_SDB].value)
235  sdb_flags = 1;
236  else
237  sdb_flags = 0;
238  #endif
239  return NULL;
240 
241  case FE_OPT_VERSION:
242  {
243  char *s=versionString();
244  printf("%s",s);
245  omFree(s);
246  return NULL;
247  }
248 
249  case FE_OPT_ECHO:
250  si_echo = (int) ((long)(feOptSpec[FE_OPT_ECHO].value));
251  if (si_echo < 0 || si_echo > 9)
252  return "argument of option is not in valid range 0..9";
253  return NULL;
254 
255  case FE_OPT_RANDOM:
256  siRandomStart = (unsigned int) ((unsigned long)
257  (feOptSpec[FE_OPT_RANDOM].value));
260  return NULL;
261 
262  case FE_OPT_EMACS:
263  if (feOptSpec[FE_OPT_EMACS].value)
264  {
265  // print EmacsDir and InfoFile so that Emacs
266  // mode can pcik it up
267  Warn("EmacsDir: %s", (feResource('e' /*"EmacsDir"*/) != NULL ?
268  feResource('e' /*"EmacsDir"*/) : ""));
269  Warn("InfoFile: %s", (feResource('i' /*"InfoFile"*/) != NULL ?
270  feResource('i' /*"InfoFile"*/) : ""));
271  }
272  return NULL;
273 
274  case FE_OPT_NO_WARN:
275  if (feOptSpec[FE_OPT_NO_WARN].value)
276  feWarn = FALSE;
277  else
278  feWarn = TRUE;
279  return NULL;
280 
281  case FE_OPT_NO_OUT:
282  if (feOptSpec[FE_OPT_NO_OUT].value)
283  feOut = FALSE;
284  else
285  feOut = TRUE;
286  return NULL;
287 
288  case FE_OPT_MIN_TIME:
289  {
290  double mintime = atof((char*) feOptSpec[FE_OPT_MIN_TIME].value);
291  if (mintime <= 0) return "invalid float argument";
293  return NULL;
294  }
295 
296  case FE_OPT_BROWSER:
297  feHelpBrowser((char*) feOptSpec[FE_OPT_BROWSER].value, 1);
298 
299  case FE_OPT_TICKS_PER_SEC:
300  {
301  int ticks = (int) ((long)(feOptSpec[FE_OPT_TICKS_PER_SEC].value));
302  if (ticks <= 0)
303  return "integer argument must be larger than 0";
304  SetTimerResolution(ticks);
305  return NULL;
306  }
307 
308  case FE_OPT_DUMP_VERSIONTUPLE:
309  {
311  return NULL;
312  }
313 
314  #ifdef HAVE_FLINT
315  #if __FLINT_RELEASE >= 20503
316  case FE_OPT_FLINT_THREADS:
317  {
318  slong nthreads = (slong)feOptSpec[FE_OPT_FLINT_THREADS].value;
319  nthreads = FLINT_MAX(nthreads, WORD(1));
320  flint_set_num_threads(nthreads);
321  int * cpu_affinities = new int[nthreads];
322  for (slong i = 0; i < nthreads; i++)
323  cpu_affinities[i] = (int)i;
324  flint_set_thread_affinity(cpu_affinities, nthreads);
325  delete[] cpu_affinities;
326  return NULL;
327  }
328  #endif
329  #endif
330 
331  default:
332  return NULL;
333  }
334 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:189
VAR int siRandomStart
Definition: cntrlc.cc:101
#define Warn
Definition: emacs.cc:77
#define slong
const CanonicalForm int s
Definition: facAbsFact.cc:51
void feOptDumpVersionTuple(void)
Definition: feOpt.cc:423
void feOptHelp(const char *name)
Definition: feOpt.cc:372
VAR char * feArgv0
Definition: feResource.cc:19
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:258
VAR int si_echo
Definition: febase.cc:35
void * value
Definition: fegetopt.h:93
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:248
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:30
char * fe_fgets(const char *pr, char *s, int size)
Definition: feread.cc:306
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:447
char * versionString()
Definition: misc_ip.cc:778
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:12
VAR unsigned si_opt_2
Definition: options.c:6
#define Sy_bit(x)
Definition: options.h:31
#define V_LOAD_LIB
Definition: options.h:46
VAR BOOLEAN feWarn
Definition: reporter.cc:49
VAR BOOLEAN feOut
Definition: reporter.cc:50
EXTERN_VAR int traceit
Definition: reporter.h:24
VAR int sdb_flags
Definition: sdb.cc:31
VAR int siSeed
Definition: sirandom.c:30
void SetMinDisplayTime(double mtime)
Definition: timer.cc:27
STATIC_VAR double mintime
Definition: timer.cc:20
void SetTimerResolution(int res)
Definition: timer.cc:22

◆ feOptDumpVersionTuple()

void feOptDumpVersionTuple ( void  )

Definition at line 423 of file feOpt.cc.

424 {
425  printf("%s\n",VERSION);
426 }
#define VERSION
Definition: factoryconf.h:282

◆ feOptHelp()

void feOptHelp ( const char *  name)

Definition at line 372 of file feOpt.cc.

373 {
374  int i = 0;
375  char tmp[60];
376 #if defined(ESINGULAR)
377  printf("ESingular starts up Singular within emacs;\n");
378 #elif defined(TSINGULAR)
379  printf("TSingular starts up Singular within a terminal window;\n");
380 #endif
381  printf("Singular is a Computer Algebra System (CAS) for Polynomial Computations.\n");
382  printf("Usage: %s [options] [file1 [file2 ...]]\n", name);
383  printf("Options:\n");
384 
385  while (feOptSpec[i].name != 0)
386  {
387  if (feOptSpec[i].help != NULL
388 #ifdef SING_NDEBUG
389  && *(feOptSpec[i].help) != '/'
390 #endif
391  )
392  {
393  if (feOptSpec[i].has_arg > 0)
394  {
395  if (feOptSpec[i].has_arg > 1)
396  sprintf(tmp, "%s[=%s]", feOptSpec[i].name, feOptSpec[i].arg_name);
397  else
398  sprintf(tmp, "%s=%s", feOptSpec[i].name, feOptSpec[i].arg_name);
399 
400  printf(" %c%c --%-20s %s\n",
401  (feOptSpec[i].val != LONG_OPTION_RETURN ? '-' : ' '),
402  (feOptSpec[i].val != LONG_OPTION_RETURN ? feOptSpec[i].val : ' '),
403  tmp,
404  feOptSpec[i].help);
405  }
406  else
407  {
408  printf(" %c%c --%-20s %s\n",
409  (feOptSpec[i].val != LONG_OPTION_RETURN ? '-' : ' '),
410  (feOptSpec[i].val != LONG_OPTION_RETURN ? feOptSpec[i].val : ' '),
411  feOptSpec[i].name,
412  feOptSpec[i].help);
413  }
414  }
415  i++;
416  }
417 
418  printf("\nFor more information, type `help;' from within Singular or visit\n");
419  printf("https://www.singular.uni-kl.de or consult the\n");
420  printf("Singular manual (available as on-line info or html manual).\n");
421 }
#define SING_NDEBUG
Definition: factoryconf.h:264
#define help
Definition: libparse.cc:1230

◆ fePrintOptValues()

void fePrintOptValues ( )

Definition at line 337 of file feOpt.cc.

338 {
339  int i = 0;
340 
341  while (feOptSpec[i].name != 0)
342  {
343  if (feOptSpec[i].help != NULL && feOptSpec[i].type != feOptUntyped
344 #ifndef SING_NDEBUG
345  && *(feOptSpec[i].help) != '/'
346 #endif
347  )
348  {
349  if (feOptSpec[i].type == feOptString)
350  {
351  if (feOptSpec[i].value == NULL)
352  {
353  Print("// --%-15s\n", feOptSpec[i].name);
354  }
355  else
356  {
357  Print("// --%-15s \"%s\"\n", feOptSpec[i].name, (char*) feOptSpec[i].value);
358  }
359  }
360  else
361  {
362  Print("// --%-15s %d\n", feOptSpec[i].name, (int)(long)feOptSpec[i].value);
363  }
364  }
365  i++;
366  }
367 }
#define Print
Definition: emacs.cc:80
@ feOptUntyped
Definition: fegetopt.h:77
@ feOptString
Definition: fegetopt.h:77

◆ feSetOptValue() [1/2]

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

Definition at line 154 of file feOpt.cc.

155 {
156  if (opt == FE_OPT_UNDEF) return "option undefined";
157 
158  if (feOptSpec[opt].type != feOptUntyped)
159  {
160  if (feOptSpec[opt].type != feOptString)
161  {
162  if (optarg != NULL)
163  {
164  errno = 0;
165  feOptSpec[opt].value = (void*) strtol(optarg, NULL, 10);
166  if (errno) return "invalid integer argument";
167  }
168  else
169  {
170  feOptSpec[opt].value = (void*) 0;
171  }
172  }
173  else
174  {
175  assume(feOptSpec[opt].type == feOptString);
176  if (feOptSpec[opt].set && feOptSpec[opt].value != NULL)
177  omFree(feOptSpec[opt].value);
178  if (optarg != NULL)
179  feOptSpec[opt].value = omStrDup(optarg);
180  else
181  feOptSpec[opt].value = NULL;
182  feOptSpec[opt].set = 1;
183  }
184  }
185  return feOptAction(opt);
186 }
static const char * feOptAction(feOptIndex opt)
Definition: feOpt.cc:202
int set
Definition: fegetopt.h:94
#define assume(x)
Definition: mod2.h:387
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ feSetOptValue() [2/2]

const char* feSetOptValue ( feOptIndex  opt,
int  optarg 
)

Definition at line 188 of file feOpt.cc.

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

Variable Documentation

◆ SHORT_OPTS_STRING

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

Definition at line 29 of file feOpt.cc.