Macros | Functions | Variables
feOpt.cc File Reference
#include <kernel/mod2.h>
#include <string.h>
#include <stdlib.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

#define FE_OPT_STRUCTURE

Definition at line 18 of file feOpt.cc.

Function Documentation

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 }
feOptIndex
Definition: feOptGen.h:15
struct fe_option feOptSpec[]
char name(const Variable &v)
Definition: variable.h:95
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 }
feOptIndex
Definition: feOptGen.h:15
int val
Definition: fegetopt.h:88
struct fe_option feOptSpec[]
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
static const char * feOptAction ( feOptIndex  opt)
static

Definition at line 201 of file feOpt.cc.

202 {
203  // do some special actions
204  switch(opt)
205  {
206  case FE_OPT_BATCH:
207  if (feOptSpec[FE_OPT_BATCH].value)
209  return NULL;
210 
211  case FE_OPT_HELP:
213  return NULL;
214 
215  case FE_OPT_PROFILE:
216  traceit=1024;
217  return NULL;
218 
219  case FE_OPT_QUIET:
220  if (feOptSpec[FE_OPT_QUIET].value)
221  si_opt_2 &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
222  else
224  return NULL;
225 
226  case FE_OPT_NO_TTY:
227 #if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
228  if (feOptSpec[FE_OPT_NO_TTY].value)
230 #endif
231  return NULL;
232 
233  case FE_OPT_SDB:
234  #ifdef HAVE_SDB
235  if (feOptSpec[FE_OPT_SDB].value)
236  sdb_flags = 1;
237  else
238  sdb_flags = 0;
239  #endif
240  return NULL;
241 
242  case FE_OPT_VERSION:
243  {
244  char *s=versionString();
245  printf("%s",s);
246  omFree(s);
247  return NULL;
248  }
249 
250  case FE_OPT_ECHO:
251  si_echo = (int) ((long)(feOptSpec[FE_OPT_ECHO].value));
252  if (si_echo < 0 || si_echo > 9)
253  return "argument of option is not in valid range 0..9";
254  return NULL;
255 
256  case FE_OPT_RANDOM:
257  siRandomStart = (unsigned int) ((unsigned long)
258  (feOptSpec[FE_OPT_RANDOM].value));
261  return NULL;
262 
263  case FE_OPT_EMACS:
264  if (feOptSpec[FE_OPT_EMACS].value)
265  {
266  // print EmacsDir and InfoFile so that Emacs
267  // mode can pcik it up
268  Warn("EmacsDir: %s", (feResource('e' /*"EmacsDir"*/) != NULL ?
269  feResource('e' /*"EmacsDir"*/) : ""));
270  Warn("InfoFile: %s", (feResource('i' /*"InfoFile"*/) != NULL ?
271  feResource('i' /*"InfoFile"*/) : ""));
272  }
273  return NULL;
274 
275  case FE_OPT_NO_WARN:
276  if (feOptSpec[FE_OPT_NO_WARN].value)
277  feWarn = FALSE;
278  else
279  feWarn = TRUE;
280  return NULL;
281 
282  case FE_OPT_NO_OUT:
283  if (feOptSpec[FE_OPT_NO_OUT].value)
284  feOut = FALSE;
285  else
286  feOut = TRUE;
287  return NULL;
288 
289  case FE_OPT_MIN_TIME:
290  {
291  double mintime = atof((char*) feOptSpec[FE_OPT_MIN_TIME].value);
292  if (mintime <= 0) return "invalid float argument";
293  SetMinDisplayTime(mintime);
294  return NULL;
295  }
296 
297  case FE_OPT_BROWSER:
298  feHelpBrowser((char*) feOptSpec[FE_OPT_BROWSER].value, 1);
299 
300  case FE_OPT_TICKS_PER_SEC:
301  {
302  int ticks = (int) ((long)(feOptSpec[FE_OPT_TICKS_PER_SEC].value));
303  if (ticks <= 0)
304  return "integer argument must be larger than 0";
305  SetTimerResolution(ticks);
306  return NULL;
307  }
308 
309  case FE_OPT_DUMP_VERSIONTUPLE:
310  {
312  return NULL;
313  }
314 
315  default:
316  return NULL;
317  }
318 }
const char * feHelpBrowser(char *which, int warn)
Definition: fehelp.cc:260
const CanonicalForm int s
Definition: facAbsFact.cc:55
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:33
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:176
static double mintime
Definition: timer.cc:22
int sdb_flags
Definition: sdb.cc:32
char * versionString()
Definition: misc_ip.cc:783
#define FALSE
Definition: auxiliary.h:140
BOOLEAN feOut
Definition: reporter.cc:50
#define V_LOAD_LIB
Definition: options.h:45
static char * feResource(feResourceConfig config, int warn)
Definition: feResource.cc:252
char * fe_fgets(const char *pr, char *s, int size)
Definition: feread.cc:310
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:418
int siRandomStart
Definition: cntrlc.cc:103
#define TRUE
Definition: auxiliary.h:144
void * value
Definition: fegetopt.h:93
int traceit
Definition: febase.cc:47
#define Sy_bit(x)
Definition: options.h:30
void feOptDumpVersionTuple(void)
Definition: feOpt.cc:407
void SetTimerResolution(int res)
Definition: timer.cc:24
#define omFree(addr)
Definition: omAllocDecl.h:261
struct fe_option feOptSpec[]
void SetMinDisplayTime(double mtime)
Definition: timer.cc:29
char * feArgv0
Definition: feResource.cc:19
#define NULL
Definition: omList.c:10
int siSeed
Definition: sirandom.c:29
void feOptHelp(const char *name)
Definition: feOpt.cc:356
BOOLEAN feWarn
Definition: reporter.cc:49
unsigned si_opt_2
Definition: options.c:6
int si_echo
Definition: febase.cc:41
#define Warn
Definition: emacs.cc:80
void feOptDumpVersionTuple ( void  )

Definition at line 407 of file feOpt.cc.

408 {
409  printf("%s\n",VERSION);
410 }
#define VERSION
Definition: mod2.h:21
void feOptHelp ( const char *  name)

Definition at line 356 of file feOpt.cc.

357 {
358  int i = 0;
359  char tmp[20];
360 #if defined(ESINGULAR)
361  printf("ESingular starts up Singular within emacs;\n");
362 #elif defined(TSINGULAR)
363  printf("TSingular starts up Singular within a terminal window;\n");
364 #endif
365  printf("Singular is a Computer Algebra System (CAS) for Polynomial Computations.\n");
366  printf("Usage: %s [options] [file1 [file2 ...]]\n", name);
367  printf("Options:\n");
368 
369  while (feOptSpec[i].name != 0)
370  {
371  if (feOptSpec[i].help != NULL
372 #ifdef SING_NDEBUG
373  && *(feOptSpec[i].help) != '/'
374 #endif
375  )
376  {
377  if (feOptSpec[i].has_arg > 0)
378  {
379  if (feOptSpec[i].has_arg > 1)
380  sprintf(tmp, "%s[=%s]", feOptSpec[i].name, feOptSpec[i].arg_name);
381  else
382  sprintf(tmp, "%s=%s", feOptSpec[i].name, feOptSpec[i].arg_name);
383 
384  printf(" %c%c --%-20s %s\n",
385  (feOptSpec[i].val != LONG_OPTION_RETURN ? '-' : ' '),
386  (feOptSpec[i].val != LONG_OPTION_RETURN ? feOptSpec[i].val : ' '),
387  tmp,
388  feOptSpec[i].help);
389  }
390  else
391  {
392  printf(" %c%c --%-20s %s\n",
393  (feOptSpec[i].val != LONG_OPTION_RETURN ? '-' : ' '),
394  (feOptSpec[i].val != LONG_OPTION_RETURN ? feOptSpec[i].val : ' '),
395  feOptSpec[i].name,
396  feOptSpec[i].help);
397  }
398  }
399  i++;
400  }
401 
402  printf("\nFor more information, type `help;' from within Singular or visit\n");
403  printf("http://www.singular.uni-kl.de or consult the\n");
404  printf("Singular manual (available as on-line info or html manual).\n");
405 }
const char * arg_name
Definition: fegetopt.h:90
int has_arg
Definition: fegetopt.h:87
int val
Definition: fegetopt.h:88
struct fe_option feOptSpec[]
int i
Definition: cfEzgcd.cc:123
#define help
Definition: libparse.cc:1228
char name(const Variable &v)
Definition: variable.h:95
#define NULL
Definition: omList.c:10
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
void fePrintOptValues ( )

Definition at line 321 of file feOpt.cc.

322 {
323  int i = 0;
324 
325  while (feOptSpec[i].name != 0)
326  {
327  if (feOptSpec[i].help != NULL && feOptSpec[i].type != feOptUntyped
328 #ifndef SING_NDEBUG
329  && *(feOptSpec[i].help) != '/'
330 #endif
331  )
332  {
333  if (feOptSpec[i].type == feOptString)
334  {
335  if (feOptSpec[i].value == NULL)
336  {
337  Print("// --%-15s\n", feOptSpec[i].name);
338  }
339  else
340  {
341  Print("// --%-15s \"%s\"\n", feOptSpec[i].name, (char*) feOptSpec[i].value);
342  }
343  }
344  else
345  {
346  Print("// --%-15s %d\n", feOptSpec[i].name, (int)(long)feOptSpec[i].value);
347  }
348  }
349  i++;
350  }
351 }
feOptType type
Definition: fegetopt.h:92
#define Print
Definition: emacs.cc:83
void * value
Definition: fegetopt.h:93
struct fe_option feOptSpec[]
int i
Definition: cfEzgcd.cc:123
#define help
Definition: libparse.cc:1228
char name(const Variable &v)
Definition: variable.h:95
#define NULL
Definition: omList.c:10
const char* feSetOptValue ( feOptIndex  opt,
char *  optarg 
)

Definition at line 153 of file feOpt.cc.

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

Definition at line 187 of file feOpt.cc.

188 {
189  if (opt == FE_OPT_UNDEF) return "option undefined";
190 
191  if (feOptSpec[opt].type != feOptUntyped)
192  {
193  if (feOptSpec[opt].type == feOptString)
194  return "option value needs to be an integer";
195 
196  feOptSpec[opt].value = (void*)(long) optarg;
197  }
198  return feOptAction(opt);
199 }
feOptType type
Definition: fegetopt.h:92
void * value
Definition: fegetopt.h:93
static const char * feOptAction(feOptIndex opt)
Definition: feOpt.cc:201
struct fe_option feOptSpec[]

Variable Documentation

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

Definition at line 29 of file feOpt.cc.