Loading...
Searching...
No Matches
feread.cc File Reference
`#include "kernel/mod2.h"`
`#include <errno.h>`
`#include <stdio.h>`
`#include "omalloc/omalloc.h"`
`#include "misc/options.h"`
`#include "kernel/oswrapper/feread.h"`
`#include "reporter/reporter.h"`
`#include <unistd.h>`
`#include "Singular/ipid.h"`
`#include <stdlib.h>`
`#include <sys/types.h>`
`#include <sys/file.h>`
`#include <sys/stat.h>`

Go to the source code of this file.

## Macros

#define | STDOUT_FILENO 1
#define | rl_filename_completion_function filename_completion_function
#define | rl_completion_matches completion_matches
#define | x_rl_line_buffer (*fe_rl_line_buffer)
#define | x_rl_completion_matches (*fe_completion_matches)
#define | x_rl_filename_completion_function (*fe_filename_completion_function)

## Typedefs

typedef char *(* | RL_PROC) (const char *, int)
typedef char ** | CPPFunction()
typedef char *(* | PROC) ()
typedef char ** | RL_CPPFunction(const char *, int, int)

## Functions

static char * | fe_fgets_stdin_init (const char *pr, char *s, int size)
char * | iiArithGetCmd (int)
char * | command_generator (char *text, int state)
char * | rl_filename_completion_function (const char *, int)
char ** | rl_completion_matches (const char *, RL_PROC)
char * | readline (const char *)
void | add_history (char *)
int | write_history ()
void | using_history ()
int | read_history (char *)
int | history_total_bytes ()
char * | fe_fgets_stdin_rl (const char *pr, char *s, int size)
int | fe_init_dyn_rl ()
char ** | singular_completion (char *text, int start, int end)
char * | fe_fgets_stdin_fe (const char *pr, char *s, int size)
char * | fe_fgets_stdin_emu (const char *pr, char *s, int size)
char * | fe_fgets_stdin_drl (const char *pr, char *s, int size)
char * | fe_fgets (const char *pr, char *s, int size)
char * | fe_fgets_dummy (const char *, char *, int)

## Variables

char *(* | fe_fgets_stdin )(const char *pr, char *s, int size) = fe_fgets_stdin_init
VAR BOOLEAN | using_history_called =FALSE
EXTERN_VAR char * | rl_readline_name
EXTERN_VAR char * | rl_line_buffer
EXTERN_VAR CPPFunction * | rl_attempted_completion_function
EXTERN_VAR FILE * | rl_outstream
char *(* | fe_filename_completion_function )()
char *(* | fe_readline )(char *)
VAR void(* | fe_add_history )(char *)
VAR char ** | fe_rl_readline_name
VAR char ** | fe_rl_line_buffer
char **(* | fe_completion_matches )(...)
VAR CPPFunction ** | fe_rl_attempted_completion_function
VAR FILE ** | fe_rl_outstream
VAR int(* | fe_write_history )()
VAR int(* | fe_history_total_bytes )()
VAR void(* | fe_using_history )()
VAR int(* | fe_read_history )(char *)

## Macro Definition Documentation

## rl_completion_matches

#define rl_completion_matches completion_matches

Definition at line 123 of file feread.cc.

## rl_filename_completion_function

#define rl_filename_completion_function filename_completion_function

Definition at line 122 of file feread.cc.

## STDOUT_FILENO

#define STDOUT_FILENO 1

Definition at line 43 of file feread.cc.

## x_rl_completion_matches

#define x_rl_completion_matches (*fe_completion_matches)

## x_rl_filename_completion_function

#define x_rl_filename_completion_function (*fe_filename_completion_function)

## x_rl_line_buffer

#define x_rl_line_buffer (*fe_rl_line_buffer)

## Typedef Documentation

## CPPFunction

typedef char ** CPPFunction()

Definition at line 130 of file feread.cc.

## PROC

typedef char *(* PROC) ()

Definition at line 143 of file feread.cc.

## RL_CPPFunction

typedef char ** RL_CPPFunction(const char *, int, int)

Definition at line 145 of file feread.cc.

## RL_PROC

typedef char *(* RL_PROC) (const char *, int)

Definition at line 107 of file feread.cc.

## Function Documentation

## add_history()

void add_history | ( | char * |  | ) |

extern

## command_generator()

char * command_generator | ( | char * | text,
|  | int | state )

Definition at line 52 of file feread.cc.

{
STATIC_VAR int list_index, len;
STATIC_VAR idhdl h;
const char *name;
/* If this is a new word to complete, initialize now. This includes
saving the length of TEXT for efficiency, and initializing the index
variable to 0. */
if (state==0)
{
list_index = 1;
len = strlen (text);
h=basePack->idroot;
}
/* Return the next name which partially matches from the command list. */
while ((name = iiArithGetCmd(list_index))!=NULL)
{
list_index++;
if (strncmp (name, text, len) == 0)
return (strdup(name));
}
if (len>1)
{
while (h!=NULL)
{
name=h->id;
h=h->next;
if (strncmp (name, text, len) == 0)
return (strdup(name));
}
}
/* If no names matched, then return NULL. */
return ((char *)NULL);
}
name
char name(const Variable &v)
Definition factory.h:189
iiArithGetCmd
char * iiArithGetCmd(int)
Definition iparith.cc:10083
STATIC_VAR
#define STATIC_VAR
Definition globaldefs.h:7
basePack
VAR package basePack
Definition ipid.cc:56
h
STATIC_VAR Poly * h
Definition janet.cc:971
strdup
#define strdup
Definition omAllocFunc.c:18
NULL
#define NULL
Definition omList.c:12
idhdl
idrec * idhdl
Definition ring.h:22

## fe_fgets()

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

Definition at line 309 of file feread.cc.

{
if (BVERBOSE(V_PROMPT))
{
fputs(pr,stdout);
}
mflush();
errno=0;
char *line=fgets(s,size,stdin);
if (line!=NULL)
{
for (int i=strlen(line)-1;i>=0;i--) line[i]=line[i]&127;
}
else
{
/* NULL can mean various things... */
switch(errno)
{
case 0: return NULL; /*EOF */
case EBADF: return NULL; /* stdin got closed */
case EINTR: return strcpy(s,"\n"); /* CTRL-C or other signal */
default: /* other error */
{
int errsv = errno;
fprintf(stderr,"fgets() failed with errno %d\n%s\n",errsv,strerror(errsv));
return NULL;
}
}
}
return line;
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
i
int i
Definition cfEzgcd.cc:132
s
const CanonicalForm int s
Definition facAbsFact.cc:51
BVERBOSE
#define BVERBOSE(a)
Definition options.h:35
V_PROMPT
#define V_PROMPT
Definition options.h:54
mflush
#define mflush()
Definition reporter.h:58

## fe_fgets_dummy()

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

Definition at line 455 of file feread.cc.

{
return NULL;
}

## fe_fgets_stdin_drl()

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

Definition at line 269 of file feread.cc.

{
if (!BVERBOSE(V_PROMPT))
{
pr="";
}
mflush();
char *line;
line = (*fe_readline) ((char*)pr);
if (line==NULL)
return NULL;
int l=strlen(line);
for (int i=l-1;i>=0;i--) line[i]=line[i]&127;
if (*line!='\0')
{
(*fe_add_history) (line);
}
if (l>=size-1)
{
strncpy(s,line,size);
}
else
{
strncpy(s,line,l);
s[l]='\n';
s[l+1]='\0';
}
free (line);
return s;
}
l
int l
Definition cfEzgcd.cc:100
free
#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 253 of file feread.cc.

{
if (!BVERBOSE(V_PROMPT))
{
pr="";
}
mflush();
return fe_fgets_stdin_fe(pr,s,size);
}
fe_fgets_stdin_fe
char * fe_fgets_stdin_fe(const char *pr, char *s, int size)

## fe_fgets_stdin_fe()

char * fe_fgets_stdin_fe | ( | const char * | pr,
|  | char * | s,
|  | int | size )

## fe_fgets_stdin_init()

char * fe_fgets_stdin_init | ( | const char * | pr,
|  | char * | s,
|  | int | size )

static

Definition at line 344 of file feread.cc.

{
#if (defined(HAVE_READLINE) || defined(HAVE_LIBREADLINE)) && !defined(HAVE_DYN_RL) && !defined(HAVE_FEREAD)
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name = (char*)"Singular";
/* Tell the completer that we want a crack first. */
#ifdef USE_READLINE4
rl_attempted_completion_function = (rl_completion_func_t *)singular_completion;
#else
rl_attempted_completion_function = (CPPFunction *)singular_completion;
#endif
/* set the output stream */
if(!isatty(STDOUT_FILENO))
{
#ifdef atarist
rl_outstream = fopen( "/dev/tty", "w" );
#else
char *fn=ttyname(fileno(stdin));//if stdout is not a tty, maybe stdin is?
if (fn!=NULL) rl_outstream = fopen( fn, "w" );
#endif
}
using_history_called=FALSE;
if(isatty(fileno(stdin)))
{
/* try to read a history */
using_history_called=TRUE;
using_history();
char *p = getenv("SINGULARHIST");
if (p==NULL) p=SINGULARHIST_FILE;
if (strlen(p) != 0)
{
read_history (p);
}
fe_fgets_stdin=fe_fgets_stdin_rl;
return(fe_fgets_stdin_rl(pr,s,size));
}
else
{
fe_fgets_stdin=fe_fgets;
return(fe_fgets(pr,s,size));
}
#endif
#ifdef HAVE_DYN_RL
/* do dynamic loading */
int res=fe_init_dyn_rl();
using_history_called=FALSE;
if (res!=0)
{
//if (res==1)
// WarnS("dynamic loading of libreadline failed");
//else
// Warn("dynamic loading failed: %d\n",res);
if (res!=1)
Warn("dynamic loading failed: %d\n",res);
#ifdef HAVE_FEREAD
fe_fgets_stdin=fe_fgets_stdin_emu;
#else
fe_fgets_stdin=fe_fgets;
#endif
return fe_fgets_stdin(pr,s,size);
}
else if (isatty(STDIN_FILENO))/*and could load libreadline: */
{
/* Allow conditional parsing of the ~/.inputrc file. */
*fe_rl_readline_name = "Singular";
/* Tell the completer that we want a crack first. */
*fe_rl_attempted_completion_function = (CPPFunction *)singular_completion;
/* try to read a history */
(*fe_using_history)();
using_history_called=TRUE;
char *p = getenv("SINGULARHIST");
if (p != NULL)
{
(*fe_read_history) (p);
}
/* set the output stream */
if(!isatty(STDOUT_FILENO))
{
#ifdef atarist
*fe_rl_outstream = fopen( "/dev/tty", "w" );
#else
char *fn=ttyname(fileno(stdin));//if stdout is not a tty, maybe stdin is?
if (fn!=NULL) *fe_rl_outstream = fopen( fn, "w" );
#endif
}
fe_fgets_stdin=fe_fgets_stdin_drl;
return fe_fgets_stdin_drl(pr,s,size);
}
else
{
fe_fgets_stdin=fe_fgets;
return fe_fgets(pr,s,size);
}
#else
#if !defined(HAVE_READLINE) && defined(HAVE_FEREAD)
fe_fgets_stdin=fe_fgets_stdin_emu;
return(fe_fgets_stdin_emu(pr,s,size));
#else
fe_fgets_stdin=fe_fgets;
return(fe_fgets(pr,s,size));
#endif
#endif
}
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
p
int p
Definition cfModGcd.cc:4086
Warn
#define Warn
Definition emacs.cc:77
res
CanonicalForm res
Definition facAbsFact.cc:60
getenv
char * getenv()
rl_attempted_completion_function
EXTERN_VAR CPPFunction * rl_attempted_completion_function
Definition feread.cc:133
rl_outstream
EXTERN_VAR FILE * rl_outstream
Definition feread.cc:134
CPPFunction
char ** CPPFunction()
Definition feread.cc:130
using_history_called
VAR BOOLEAN using_history_called
Definition feread.cc:106
fe_rl_readline_name
VAR char ** fe_rl_readline_name
Definition feread.cc:166
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
fe_rl_attempted_completion_function
VAR CPPFunction ** fe_rl_attempted_completion_function
Definition feread.cc:169
read_history
int read_history(char *)
singular_completion
char ** singular_completion(char *text, int start, int end)
Definition feread.cc:178
fe_fgets
char * fe_fgets(const char *pr, char *s, int size)
Definition feread.cc:309
STDOUT_FILENO
#define STDOUT_FILENO
Definition feread.cc:43
rl_readline_name
EXTERN_VAR char * rl_readline_name
Definition feread.cc:127
using_history
void using_history()
fe_fgets_stdin_rl
char * fe_fgets_stdin_rl(const char *pr, char *s, int size)
fe_fgets_stdin_drl
char * fe_fgets_stdin_drl(const char *pr, char *s, int size)
Definition feread.cc:269
fe_fgets_stdin_emu
char * fe_fgets_stdin_emu(const char *pr, char *s, int size)
Definition feread.cc:253
fe_rl_outstream
VAR FILE ** fe_rl_outstream
Definition feread.cc:170
fe_init_dyn_rl
int fe_init_dyn_rl()
Definition fereadl.c:756
SINGULARHIST_FILE
#define SINGULARHIST_FILE
Definition feread.h:20
STDIN_FILENO
#define STDIN_FILENO
Definition fereadl.c:52

## fe_fgets_stdin_rl()

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

## fe_init_dyn_rl()

int fe_init_dyn_rl | ( |  | ) |

Definition at line 756 of file fereadl.c.

{
int res=0;
loop
{
fe_rl_hdl=dynl_open("libreadline.so");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.2");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.3");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.4");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.5");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.6");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.7");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.8");
if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.9");
if (fe_rl_hdl==NULL) { return 1;}
fe_filename_completion_function=
dynl_sym(fe_rl_hdl, "filename_completion_function");
if (fe_filename_completion_function==NULL) { res=3; break; }
fe_readline=dynl_sym(fe_rl_hdl,"readline");
if (fe_readline==NULL) { res=4; break; }
fe_add_history=dynl_sym(fe_rl_hdl,"add_history");
if (fe_add_history==NULL) { res=5; break; }
fe_rl_readline_name=(char**)dynl_sym(fe_rl_hdl,"rl_readline_name");
if (fe_rl_readline_name==NULL) { res=6; break; }
fe_rl_line_buffer=(char**)dynl_sym(fe_rl_hdl,"rl_line_buffer");
if (fe_rl_line_buffer==NULL) { res=7; break; }
fe_completion_matches=dynl_sym(fe_rl_hdl,"completion_matches");
if (fe_completion_matches==NULL) { res=8; break; }
fe_rl_attempted_completion_function=
dynl_sym(fe_rl_hdl,"rl_attempted_completion_function");
if (fe_rl_attempted_completion_function==NULL) { res=9; break; }
fe_rl_outstream=(FILE**)dynl_sym(fe_rl_hdl,"rl_outstream");
if (fe_rl_outstream==NULL) { res=10; break; }
fe_write_history=dynl_sym(fe_rl_hdl,"write_history");
if (fe_write_history==NULL) { res=11; break; }
fe_history_total_bytes=dynl_sym(fe_rl_hdl,"history_total_bytes");
if (fe_history_total_bytes==NULL) { res=12; break; }
fe_using_history=dynl_sym(fe_rl_hdl,"using_history");
if (fe_using_history==NULL) { res=13; break; }
fe_read_history=dynl_sym(fe_rl_hdl,"read_history");
if (fe_read_history==NULL) { res=14; break; }
break;
}
using_history_called=FALSE;
if (res!=0) dynl_close(fe_rl_hdl);
else
{
char *p;
/* more init stuff: */
/* Allow conditional parsing of the ~/.inputrc file. */
(*fe_rl_readline_name) = "Singular";
/* Tell the completer that we want a crack first. */
(*fe_rl_attempted_completion_function) = (CPPFunction *)singular_completion;
/* try to read a history */
using_history_called=TRUE;
(*fe_using_history)();
p = getenv("SINGULARHIST");
if (p==NULL) p=SINGULARHIST_FILE;
if (strlen(p) != 0)
{
(*fe_read_history) (p);
}
}
return res;
}
fe_rl_line_buffer
VAR char ** fe_rl_line_buffer
Definition feread.cc:167
fe_read_history
VAR int(* fe_read_history)(char *)
Definition feread.cc:174
fe_write_history
VAR int(* fe_write_history)()
Definition feread.cc:171
fe_using_history
VAR void(* fe_using_history)()
Definition feread.cc:173
fe_readline
char *(* fe_readline)(char *)
Definition feread.cc:164
fe_history_total_bytes
VAR int(* fe_history_total_bytes)()
Definition feread.cc:172
fe_add_history
VAR void(* fe_add_history)(char *)
Definition feread.cc:165
fe_filename_completion_function
char *(* fe_filename_completion_function)()
Definition feread.cc:163
fe_completion_matches
char **(* fe_completion_matches)(...)
Definition feread.cc:168
fe_rl_hdl
VAR void * fe_rl_hdl
Definition fereadl.c:727
dynl_close
int dynl_close(void *handle)
Definition mod_raw.cc:170
dynl_sym
void * dynl_sym(void *handle, const char *symbol)
Definition mod_raw.cc:159
dynl_open
void * dynl_open(char *filename)
Definition mod_raw.cc:142
loop
#define loop
Definition structs.h:71

## history_total_bytes()

int history_total_bytes | ( |  | ) |

extern

## iiArithGetCmd()

char * iiArithGetCmd | ( | int | nPos | ) |

extern

Definition at line 10083 of file iparith.cc.

{
if(nPos<0) return NULL;
if(nPos<(int)sArithBase.nCmdUsed)
return sArithBase.sCmds[nPos].name;
return NULL;
}
sArithBase
STATIC_VAR SArithBase sArithBase
Base entry for arithmetic.
Definition iparith.cc:198

## read_history()

int read_history | ( | char * |  | ) |

extern

## readline()

char * readline | ( | const char * |  | ) |

extern

## rl_completion_matches()

char ** rl_completion_matches | ( | const char * | ,
|  | RL_PROC | )

extern

## rl_filename_completion_function()

char * rl_filename_completion_function | ( | const char * | ,
|  | int | )

## singular_completion()

char ** singular_completion | ( | char * | text,
|  | int | start,
|  | int | end )

Definition at line 178 of file feread.cc.

{
/* If this word is not in a string, then it may be a command
to complete. Otherwise it may be the name of a file in the current
directory. */
#ifdef HAVE_DYN_RL
#define x_rl_line_buffer (*fe_rl_line_buffer)
#define x_rl_completion_matches (*fe_completion_matches)
#define x_rl_filename_completion_function (*fe_filename_completion_function)
#else
#define x_rl_line_buffer rl_line_buffer
#define x_rl_completion_matches rl_completion_matches
#define x_rl_filename_completion_function rl_filename_completion_function
#endif
if ((start>0) && (x_rl_line_buffer[start-1]=='"'))
return x_rl_completion_matches (text, (RL_PROC)x_rl_filename_completion_function);
char **m=x_rl_completion_matches (text, (RL_PROC)command_generator);
#undef x_rl_line_buffer
#undef x_rl_completion_matches
if (m==NULL)
{
m=(char **)malloc(2*sizeof(char*));
m[0]=(char *)malloc(end-start+2);
strncpy(m[0],text,end-start+1);
m[1]=NULL;
}
return m;
}
m
int m
Definition cfEzgcd.cc:128
x_rl_filename_completion_function
#define x_rl_filename_completion_function
x_rl_completion_matches
#define x_rl_completion_matches
command_generator
char * command_generator(char *text, int state)
Definition feread.cc:52
RL_PROC
char *(* RL_PROC)(const char *, int)
Definition feread.cc:107
x_rl_line_buffer
#define x_rl_line_buffer
malloc
#define malloc
Definition omAllocFunc.c:12

## using_history()

void using_history | ( |  | ) |

extern

## write_history()

int write_history | ( |  | ) |

extern

## Variable Documentation

## fe_add_history

VAR void(* fe_add_history) (char *) | ( | char * |  | ) |

Definition at line 165 of file feread.cc.

## fe_completion_matches

char **(* fe_completion_matches) (...) | ( |  | ... | ) |

Definition at line 168 of file feread.cc.

## fe_fgets_stdin

char *(* fe_fgets_stdin) (const char *pr, char *s, int size) | ( | const char * | pr,
|  | char * | s,
|  | int | size ) = fe_fgets_stdin_init

Definition at line 32 of file feread.cc.

## fe_filename_completion_function

char *(* fe_filename_completion_function) () | ( |  | ) |

Definition at line 163 of file feread.cc.

## fe_history_total_bytes

VAR int(* fe_history_total_bytes) () | ( |  | ) |

Definition at line 172 of file feread.cc.

## fe_read_history

VAR int(* fe_read_history) (char *) | ( | char * |  | ) |

Definition at line 174 of file feread.cc.

## fe_readline

char *(* fe_readline) (char *) | ( | char * |  | ) |

Definition at line 164 of file feread.cc.

## fe_rl_attempted_completion_function

VAR CPPFunction** fe_rl_attempted_completion_function

Definition at line 169 of file feread.cc.

## fe_rl_line_buffer

VAR char** fe_rl_line_buffer

Definition at line 167 of file feread.cc.

## fe_rl_outstream

VAR FILE** fe_rl_outstream

Definition at line 170 of file feread.cc.

## fe_rl_readline_name

VAR char** fe_rl_readline_name

Definition at line 166 of file feread.cc.

## fe_using_history

VAR void(* fe_using_history) () | ( |  | ) |

Definition at line 173 of file feread.cc.

## fe_write_history

VAR int(* fe_write_history) () | ( |  | ) |

Definition at line 171 of file feread.cc.

## rl_attempted_completion_function

EXTERN_VAR CPPFunction* rl_attempted_completion_function

Definition at line 133 of file feread.cc.

## rl_line_buffer

EXTERN_VAR char* rl_line_buffer

Definition at line 128 of file feread.cc.

## rl_outstream

EXTERN_VAR FILE* rl_outstream

Definition at line 134 of file feread.cc.

## rl_readline_name

EXTERN_VAR char* rl_readline_name

Definition at line 127 of file feread.cc.

## using_history_called

VAR BOOLEAN using_history_called =FALSE

Definition at line 106 of file feread.cc.