My Project
Functions | Variables
feread.h File Reference

Go to the source code of this file.

Functions

char * fe_fgets_stdin_drl (const char *pr, char *s, int size)
 
void fe_reset_input_mode ()
 
void fe_reset_fe (void)
 
char * fe_fgets_stdin_rl (const char *pr, char *s, int size)
 
char * fe_fgets_stdin_emu (const char *pr, char *s, int size)
 
char * fe_fgets (const char *pr, char *s, int size)
 
char * fe_fgets_dummy (const char *pr, char *s, int size)
 
const char * eati (const char *s, int *i)
 

Variables

EXTERN_VAR char prompt_char
 
char *(* fe_fgets_stdin )(const char *pr, char *s, int size)
 

Function Documentation

◆ eati()

const char* eati ( const char *  s,
int *  i 
)

Definition at line 373 of file reporter.cc.

374 {
375  int l=0;
376 
377  if (*s >= '0' && *s <= '9')
378  {
379  *i = 0;
380  while (*s >= '0' && *s <= '9')
381  {
382  *i *= 10;
383  *i += *s++ - '0';
384  l++;
385  if ((l>=MAX_INT_LEN)||((*i) <0))
386  {
387  s-=l;
388  Werror("`%s` greater than %d(max. integer representation)",
389  s,MAX_INT_VAL);
390  return s;
391  }
392  }
393  }
394  else *i = 1;
395  return s;
396 }
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
const CanonicalForm int s
Definition: facAbsFact.cc:51
const int MAX_INT_VAL
Definition: mylimits.h:12
const int MAX_INT_LEN
Definition: mylimits.h:13
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ fe_fgets()

char* fe_fgets ( const char *  pr,
char *  s,
int  size 
)

Definition at line 306 of file feread.cc.

307 {
308  if (BVERBOSE(V_PROMPT))
309  {
310  fputs(pr,stdout);
311  }
312  mflush();
313  errno=0;
314  char *line=fgets(s,size,stdin);
315  if (line!=NULL)
316  {
317  for (int i=strlen(line)-1;i>=0;i--) line[i]=line[i]&127;
318  }
319  else
320  {
321  /* NULL can mean various things... */
322  switch(errno)
323  {
324  case 0: return NULL; /*EOF */
325  case EBADF: return NULL; /* stdin got closed */
326  case EINTR: return strcpy(s,"\n"); /* CTRL-C or other signal */
327  default: /* other error */
328  {
329  int errsv = errno;
330  fprintf(stderr,"fgets() failed with errno %d\n%s\n",errsv,strerror(errsv));
331  return NULL;
332  }
333  }
334  }
335  return line;
336 }
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define NULL
Definition: omList.c:12
#define BVERBOSE(a)
Definition: options.h:34
#define V_PROMPT
Definition: options.h:53
#define mflush()
Definition: reporter.h:58

◆ fe_fgets_dummy()

char* fe_fgets_dummy ( const char *  pr,
char *  s,
int  size 
)

Definition at line 447 of file feread.cc.

448 {
449  return NULL;
450 }

◆ fe_fgets_stdin_drl()

char* fe_fgets_stdin_drl ( const char *  pr,
char *  s,
int  size 
)

Definition at line 266 of file feread.cc.

267 {
268  if (!BVERBOSE(V_PROMPT))
269  {
270  pr="";
271  }
272  mflush();
273 
274  char *line;
275  line = (*fe_readline) ((char*)pr);
276 
277  if (line==NULL)
278  return NULL;
279 
280  int l=strlen(line);
281  for (int i=l-1;i>=0;i--) line[i]=line[i]&127;
282 
283  if (*line!='\0')
284  {
285  (*fe_add_history) (line);
286  }
287  if (l>=size-1)
288  {
289  strncpy(s,line,size);
290  }
291  else
292  {
293  strncpy(s,line,l);
294  s[l]='\n';
295  s[l+1]='\0';
296  }
297  free (line);
298 
299  return s;
300 }
#define free
Definition: omAllocFunc.c:14

◆ fe_fgets_stdin_emu()

char* fe_fgets_stdin_emu ( const char *  pr,
char *  s,
int  size 
)

Definition at line 250 of file feread.cc.

251 {
252  if (!BVERBOSE(V_PROMPT))
253  {
254  pr="";
255  }
256  mflush();
257  return fe_fgets_stdin_fe(pr,s,size);
258 }
char * fe_fgets_stdin_fe(const char *pr, char *s, int size)

◆ fe_fgets_stdin_rl()

char* fe_fgets_stdin_rl ( const char *  pr,
char *  s,
int  size 
)

◆ fe_reset_fe()

void fe_reset_fe ( void  )

Definition at line 82 of file fereadl.c.

85 {
86  if (fe_stdin_is_tty)
87  {
88  int i;
89  if (fe_is_raw_tty)
90  {
91  tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
92  fe_is_raw_tty=0;
93  }
94  if (fe_hist!=NULL)
95  {
96  for(i=fe_hist_max-1;i>=0;i--)
97  {
98  if (fe_hist[i] != NULL) omFree((ADDRESS)fe_hist[i]);
99  }
100  omFreeSize((ADDRESS)fe_hist,fe_hist_max*sizeof(char *));
101  fe_hist=NULL;
102  }
103  if (!fe_stdout_is_tty)
104  {
105  fclose(fe_echo);
106  }
107  }
108 }
void * ADDRESS
Definition: auxiliary.h:119
VAR struct termios fe_saved_attributes
Definition: fereadl.c:59
VAR char ** fe_hist
Definition: fereadl.c:69
#define fe_hist_max
Definition: fereadl.c:68
VAR BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
VAR FILE * fe_echo
Definition: fereadl.c:66
STATIC_VAR BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:62
STATIC_VAR BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:61
#define STDIN_FILENO
Definition: fereadl.c:51
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ fe_reset_input_mode()

void fe_reset_input_mode ( )

Definition at line 827 of file fereadl.c.

828 {
829 #if defined(HAVE_DYN_RL)
830  char *p = getenv("SINGULARHIST");
831  if ((p != NULL) && (fe_history_total_bytes != NULL))
832  {
833  if((*fe_history_total_bytes)()!=0)
834  (*fe_write_history) (p);
835  }
836 #endif
837 #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
838  char *p = getenv("SINGULARHIST");
839  if (p != NULL)
840  {
841  if(history_total_bytes()!=0)
842  write_history (p);
843  }
844 #endif
845 #if defined(HAVE_FEREAD)
846  #ifndef HAVE_ATEXIT
848  #else
849  fe_reset_fe();
850  #endif
851 #endif
852 }
int p
Definition: cfModGcd.cc:4078
char * getenv()
int history_total_bytes()
int write_history()
void fe_reset_fe(void)
Definition: fereadl.c:82
VAR int(* fe_history_total_bytes)()
Definition: fereadl.c:722

Variable Documentation

◆ fe_fgets_stdin

char*(* fe_fgets_stdin) (const char *pr, char *s, int size) ( const char *  pr,
char *  s,
int  size 
)

Definition at line 15 of file feread.h.

◆ prompt_char

EXTERN_VAR char prompt_char

Definition at line 10 of file feread.h.