Macros | Typedefs | Functions | Variables
fereadl.c File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <string.h>
#include "kernel/mod_raw.h"

Go to the source code of this file.

Macros

#define STDIN_FILENO   0
 
#define STDOUT_FILENO   1
 
#define feCTRL(C)   ((C) & 0x1F) /* <ctrl> character */
 
#define fe_hist_max   32
 

Typedefs

typedef char ** CPPFunction()
 

Functions

void fe_reset_fe (void)
 
void fe_temp_reset (void)
 
void fe_temp_set (void)
 
static int fe_out_char (int c)
 
static void fe_init (void)
 
static void fe_ctrl_k (char *s, int i)
 
static void fe_ctrl_u (char *s, int *i)
 
static void fe_add_hist (char *s)
 
static void fe_get_hist (char *s, int size, int *pos, int change, int incr)
 
static int fe_getchar ()
 
static void fe_set_cursor (char *s, int i)
 
char * fe_fgets_stdin_fe (char *pr, char *s, int size)
 
char * command_generator (char *text, int state)
 
char ** singular_completion (char *text, int start, int end)
 
int fe_init_dyn_rl ()
 
void fe_reset_input_mode ()
 

Variables

struct termios fe_saved_attributes
 
static BOOLEAN fe_stdout_is_tty
 
static BOOLEAN fe_stdin_is_tty
 
BOOLEAN fe_use_fgets =FALSE
 
static BOOLEAN fe_is_initialized =FALSE
 
FILE * fe_echo
 
char ** fe_hist =NULL
 
short fe_hist_pos
 
BOOLEAN fe_is_raw_tty =0
 
short fe_cursor_pos
 
short fe_cursor_line
 
static char termcap_buff [2048]
 
char *(* fe_filename_completion_function )()
 
char *(* fe_readline )()
 
void(* fe_add_history )()
 
char ** fe_rl_readline_name
 
char ** fe_rl_line_buffer
 
char **(* fe_completion_matches )()
 
CPPFunction ** fe_rl_attempted_completion_function
 
FILE ** fe_rl_outstream
 
int(* fe_write_history )()
 
int(* fe_history_total_bytes )()
 
void(* fe_using_history )()
 
int(* fe_read_history )()
 
void * fe_rl_hdl =NULL
 

Macro Definition Documentation

◆ fe_hist_max

#define fe_hist_max   32

Definition at line 68 of file fereadl.c.

◆ feCTRL

#define feCTRL (   C)    ((C) & 0x1F) /* <ctrl> character */

Definition at line 57 of file fereadl.c.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 51 of file fereadl.c.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

Definition at line 54 of file fereadl.c.

Typedef Documentation

◆ CPPFunction

typedef char** CPPFunction()

Definition at line 711 of file fereadl.c.

Function Documentation

◆ command_generator()

char* command_generator ( char *  text,
int  state 
)

Definition at line 54 of file feread.cc.

55 {
56  static int list_index, len;
57  static idhdl h;
58  const char *name;
59 
60  /* If this is a new word to complete, initialize now. This includes
61  saving the length of TEXT for efficiency, and initializing the index
62  variable to 0. */
63  if (state==0)
64  {
65  list_index = 1;
66  len = strlen (text);
67  h=basePack->idroot;
68  }
69 
70  /* Return the next name which partially matches from the command list. */
71  while ((name = iiArithGetCmd(list_index))!=NULL)
72  {
73  list_index++;
74 
75  if (strncmp (name, text, len) == 0)
76  return (strdup(name));
77  }
78  if (len>1)
79  {
80  while (h!=NULL)
81  {
82  name=h->id;
83  h=h->next;
84  if (strncmp (name, text, len) == 0)
85  return (strdup(name));
86  }
87  }
88  /* If no names matched, then return NULL. */
89  return ((char *)NULL);
90 }
Definition: idrec.h:34
char * iiArithGetCmd(int)
Definition: iparith.cc:9207
idhdl next
Definition: idrec.h:38
char name(const Variable &v)
Definition: factory.h:180
#define strdup
Definition: omAllocFunc.c:19
#define NULL
Definition: omList.c:12
package basePack
Definition: ipid.cc:58
const char * id
Definition: idrec.h:39
static Poly * h
Definition: janet.cc:971

◆ fe_add_hist()

static void fe_add_hist ( char *  s)
static

Definition at line 276 of file fereadl.c.

277 {
278  if (s[0]!='\0') /* skip empty lines */
279  {
280  /* compare this line*/
281  if (fe_hist_pos!=0)
282  {
283  if ((fe_hist[fe_hist_pos-1]!=NULL)
284  && (strcmp(fe_hist[fe_hist_pos-1],s)==0))
285  return;
286  }
287  else
288  {
289  if ((fe_hist[fe_hist_max-1]!=NULL)
290  && (strcmp(fe_hist[fe_hist_max-1],s)==0))
291  return;
292  }
293  /* normal case: enter a new line */
294  /* first free the slot at position fe_hist_pos */
295  if (fe_hist[fe_hist_pos]!=NULL)
296  {
298  }
299  /* and store a duplicate */
302  /* increment fe_hist_pos in a circular manner */
303  fe_hist_pos++;
305  }
306 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void * ADDRESS
Definition: auxiliary.h:133
#define omFree(addr)
Definition: omAllocDecl.h:261
char ** fe_hist
Definition: fereadl.c:69
#define NULL
Definition: omList.c:12
short fe_hist_pos
Definition: fereadl.c:70
void omMarkAsStaticAddr(void *addr)
#define fe_hist_max
Definition: fereadl.c:68
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ fe_ctrl_k()

static void fe_ctrl_k ( char *  s,
int  i 
)
static

Definition at line 244 of file fereadl.c.

245 {
246  int j=i;
247  while(s[j]!='\0')
248  {
249  fputc(' ',fe_echo);
250  j++;
251  }
252  while(j>i)
253  {
254  fputc('\b',fe_echo);
255  j--;
256  }
257 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int j
Definition: facHensel.cc:105
FILE * fe_echo
Definition: fereadl.c:66
int i
Definition: cfEzgcd.cc:125

◆ fe_ctrl_u()

static void fe_ctrl_u ( char *  s,
int *  i 
)
static

Definition at line 260 of file fereadl.c.

261 {
262  fe_ctrl_k(s,*i);
263  while((*i)>0)
264  {
265  (*i)--;
266  fputc('\b',fe_echo);
267  fputc(' ',fe_echo);
268  fputc('\b',fe_echo);
269  }
270 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:244
FILE * fe_echo
Definition: fereadl.c:66
int i
Definition: cfEzgcd.cc:125

◆ fe_fgets_stdin_fe()

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

Definition at line 381 of file fereadl.c.

382 {
383  if(!fe_is_initialized)
384  fe_init();
385  if (fe_stdin_is_tty)
386  {
387  int h=fe_hist_pos;
388  int change=0;
389  char c;
390  int i=0;
391 
392  if (fe_is_raw_tty==0)
393  {
394  fe_temp_set();
395  }
396 
397  fputs(pr,fe_echo); fflush(fe_echo);
398  fe_cursor_pos=strlen(pr); /* prompt */
399 
400  memset(s,0,size);
401 
402  loop
403  {
404  c=fe_getchar();
405  switch(c)
406  {
407  case feCTRL('M'):
408  case feCTRL('J'):
409  {
410  fd_set fdset;
411  struct timeval tv;
412  int sel;
413 
414  fe_add_hist(s);
415  i=strlen(s);
416  if (i<size-1) s[i]='\n';
417  fputc('\n',fe_echo);
418  fflush(fe_echo);
419 
420  FD_ZERO (&fdset);
421  FD_SET(STDIN_FILENO, &fdset);
422  tv.tv_sec = 0;
423  tv.tv_usec = 0;
424  do
425  {
426  sel = select (STDIN_FILENO+1,
427 #ifdef hpux
428  (int *)fdset.fds_bits,
429 #else
430  &fdset,
431 #endif
432  NULL, NULL, &tv);
433  } while( (sel == -1) && (errno == EINTR) );
434  if (sel==0)
435  fe_temp_reset();
436  return s;
437  }
438  case feCTRL('H'):
439  case 127: /*delete the character left of the cursor*/
440  {
441  if (i==0) break;
442  i--;
443  fe_cursor_pos--;
444  if(fe_cursor_pos<0)
445  {
446  fe_cursor_line--;
448  fe_set_cursor(s,i);
449  }
450  else
451  {
452  fputc('\b',fe_echo);
453  }
454  /* NO BREAK : next: feCTRL('D') */
455  }
456  case feCTRL('D'): /*delete the character under the cursor or eof*/
457  {
458  int j;
459  if ((i==0) &&(s[0]=='\0')) return NULL; /*eof*/
460  if (s[i]!='\0')
461  {
462  j=i;
463  while(s[j]!='\0')
464  {
465  s[j]=s[j+1];
466  fputc(s[j],fe_echo);
467  j++;
468  }
469  fputc(' ',fe_echo);
470  if (fe_cursor_pos+(j-i)>=colmax)
471  {
472  fe_set_cursor(s,i);
473  }
474  else
475  {
476  while(j>i)
477  {
478  fputc('\b',fe_echo);
479  j--;
480  }
481  }
482  }
483  change=1;
484  fflush(fe_echo);
485  break;
486  }
487  case feCTRL('A'): /* move the cursor to the beginning of the line */
488  {
489  if (i>=colmax-strlen(pr))
490  {
491  while (i>=colmax-strlen(pr))
492  {
493  i-=colmax;
494  fe_cursor_line--;
495  }
496  i=0;
497  fe_cursor_pos=strlen(pr);
498  fe_set_cursor(s,i);
499  }
500  else
501  {
502  while(i>0)
503  {
504  i--;
505  fputc('\b',fe_echo);
506  }
507  fe_cursor_pos=strlen(pr);
508  }
509  break;
510  }
511  case feCTRL('E'): /* move the cursor to the end of the line */
512  {
513  while(s[i]!='\0')
514  {
515  fputc(s[i],fe_echo);
516  i++;
517  fe_cursor_pos++;
518  if(fe_cursor_pos>=colmax)
519  {
520  fe_cursor_pos=0;
521  if(fe_cursor_line!=(pagelength-1))
522  fe_cursor_line++;
523  }
524  }
525  break;
526  }
527  case feCTRL('B'): /* move the cursor backward one character */
528  {
529  if (i>0)
530  {
531  i--;
532  fputc('\b',fe_echo);
533  fe_cursor_pos--;
534  if(fe_cursor_pos<0)
535  {
537  fe_cursor_line--;
538  }
539  }
540  break;
541  }
542  case feCTRL('F'): /* move the cursor forward one character */
543  {
544  if(s[i]!='\0')
545  {
546  fputc(s[i],fe_echo);
547  i++;
548  fe_cursor_pos++;
549  if(fe_cursor_pos>=colmax)
550  {
551  fe_cursor_pos=0;
552  if(fe_cursor_line!=(pagelength-1))
553  fe_cursor_line++;
554  }
555  }
556  break;
557  }
558  case feCTRL('U'): /* delete entire input line */
559  {
560  fe_ctrl_u(s,&i);
561  fe_cursor_pos=strlen(pr);
562  memset(s,0,size);
563  change=1;
564  break;
565  }
566  #if 0
567  case feCTRL('W'): /* test hist. */
568  {
569  int i;
570  PrintS("\nstart hist\n");
571  for(i=0;i<fe_hist_max;i++)
572  {
573  if(fe_hist[i]!=NULL)
574  {
575  Print("%2d ",i);
576  if(i==fe_hist_pos) PrintS("-"); else PrintS(" ");
577  if(i==h) PrintS(">"); else PrintS(" ");
578  PrintS(fe_hist[i]);
579  PrintLn();
580  }
581  }
582  Print("end hist, next_pos=%d\n",fe_hist_pos);
583  break;
584  }
585  #endif
586  case feCTRL('K'): /* delete up to the end of the line */
587  {
588  fe_ctrl_k(s,i);
589  memset(&(s[i]),'\0',size-i);
590  /* s[i]='\0';*/
591  change=1;
592  break;
593  }
594  case feCTRL('L'): /* redraw screen */
595  {
596  char t_buf[40];
597  char *t=t_buf;
599  /*fputs(tgetstr("cl",&t),fe_echo);*/
600  tputs(tgetstr("cl",&t),pagelength,fe_out_char);
601  fflush(fe_echo);
602  fputs(pr,fe_echo);
603  fputs(s,fe_echo);
604  fe_set_cursor(s,i);
605  break;
606  }
607  case feCTRL('P'): /* previous line */
608  {
609  fe_ctrl_u(s,&i);
610  fe_get_hist(s,size,&h,change,-1);
611  while(s[i]!='\0')
612  {
613  fputc(s[i],fe_echo);
614  i++;
615  }
616  fe_cursor_pos=strlen(pr)+i/*strlen(s)*/;
617  change=0;
618  break;
619  }
620  case feCTRL('N'): /* next line */
621  {
622  fe_ctrl_u(s,&i);
623  fe_get_hist(s,size,&h,change,1);
624  while(s[i]!='\0')
625  {
626  fputc(s[i],fe_echo);
627  i++;
628  }
629  fe_cursor_pos=strlen(pr)+i/*strlen(s)*/;
630  change=0;
631  break;
632  }
633  default:
634  {
635  if ((c>=' ')&&(c<=126))
636  {
637  fputc (c,fe_echo);
638  fe_cursor_pos++;
639  if(fe_cursor_pos>=colmax)
640  {
641  fe_cursor_pos=0;
642  if(fe_cursor_line!=(pagelength-1))
643  fe_cursor_line++;
644  }
645  if (s[i]!='\0')
646  {
647  /* shift by 1 to the right */
648  int j=i;
649  int l;
650  while ((s[j]!='\0')&&(j<size-2)) j++;
651  l=j-i;
652  while (j>i) { s[j]=s[j-1]; j--; }
653  /* display */
654  fwrite(s+i+1,l,1,fe_echo);
655  fflush(fe_echo);
656  /* set cursor */
657  if(fe_cursor_pos+l>=colmax)
658  {
659  while(fe_cursor_pos+l>=colmax)
660  {
661  fe_cursor_line--;
662  l-=colmax;
663  }
664  fe_set_cursor(s,i);
665  }
666  else
667  {
668  while(l>0)
669  {
670  l--;
671  fputc('\b',fe_echo);
672  }
673  }
674  fflush(fe_echo);
675  }
676  if (i<size-1) s[i]=c;
677  i++;
678  change=1;
679  }
680  }
681  } /* switch */
682  fflush(fe_echo);
683  } /* loop */
684  }
685  /*else*/
686  return fgets(s,size,stdin);
687 }
short fe_cursor_line
Definition: fereadl.c:73
const CanonicalForm int s
Definition: facAbsFact.cc:55
int j
Definition: facHensel.cc:105
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:244
static void fe_add_hist(char *s)
Definition: fereadl.c:276
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:80
static void fe_ctrl_u(char *s, int *i)
Definition: fereadl.c:260
static int fe_out_char(int c)
Definition: fereadl.c:134
short fe_cursor_pos
Definition: fereadl.c:72
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
FILE * fe_echo
Definition: fereadl.c:66
#define feCTRL(C)
Definition: fereadl.c:57
static BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:62
static void fe_get_hist(char *s, int size, int *pos, int change, int incr)
Definition: fereadl.c:308
#define STDIN_FILENO
Definition: fereadl.c:51
int pagelength
Definition: febase.cc:38
#define loop
Definition: structs.h:80
static void fe_init(void)
Definition: fereadl.c:139
static BOOLEAN fe_is_initialized
Definition: fereadl.c:64
void select(const ListCFList &ppi, int length, ListCFList &ppi1, ListCFList &ppi2)
int i
Definition: cfEzgcd.cc:125
void PrintS(const char *s)
Definition: reporter.cc:284
static void fe_set_cursor(char *s, int i)
Definition: fereadl.c:360
char ** fe_hist
Definition: fereadl.c:69
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
short fe_hist_pos
Definition: fereadl.c:70
static int fe_getchar()
Definition: fereadl.c:326
void fe_temp_reset(void)
Definition: fereadl.c:109
int colmax
Definition: febase.cc:37
static Poly * h
Definition: janet.cc:971
int l
Definition: cfEzgcd.cc:93
#define fe_hist_max
Definition: fereadl.c:68
void fe_temp_set(void)
Definition: fereadl.c:117

◆ fe_get_hist()

static void fe_get_hist ( char *  s,
int  size,
int *  pos,
int  change,
int  incr 
)
static

Definition at line 308 of file fereadl.c.

309 {
310  if (change)
311  fe_add_hist(s);
312  do
313  {
314  (*pos)+=incr;
315  if((*pos)>=fe_hist_max) (*pos)-=fe_hist_max;
316  else if((*pos)<0) (*pos)+=fe_hist_max;
317  }
318  while (((*pos)!=0)&&(fe_hist[(*pos)]==NULL));
319  memset(s,0,size);
320  if (fe_hist[(*pos)]!=NULL)
321  {
322  strncpy(s,fe_hist[(*pos)],size-2);
323  }
324 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static void fe_add_hist(char *s)
Definition: fereadl.c:276
char ** fe_hist
Definition: fereadl.c:69
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 fe_hist_max
Definition: fereadl.c:68

◆ fe_getchar()

static int fe_getchar ( )
static

Definition at line 326 of file fereadl.c.

327 {
328  char c='\0';
329  while (1!=read (STDIN_FILENO, &c, 1));
330  if (c == 033)
331  {
332  /* check for CSI */
333  c='\0';
334  while((-1 == read (STDIN_FILENO, &c, 1)) && (errno == EINTR));
335  if (c == '[')
336  {
337  /* get command character */
338  c='\0';
339  while((-1 == read (STDIN_FILENO, &c, 1)) && (errno == EINTR));
340  switch (c)
341  {
342  case 'D': /* left arrow key */
343  c = feCTRL('B')/*002*/;
344  break;
345  case 'C': /* right arrow key */
346  c = feCTRL('F')/*006*/;
347  break;
348  case 'A': /* up arrow key */
349  c = feCTRL('P')/*020*/;
350  break;
351  case 'B': /* down arrow key */
352  c = feCTRL('N')/*016*/;
353  break;
354  }
355  }
356  }
357  return c;
358 }
#define feCTRL(C)
Definition: fereadl.c:57
#define STDIN_FILENO
Definition: fereadl.c:51
int status read
Definition: si_signals.h:59

◆ fe_init()

static void fe_init ( void  )
static

Definition at line 139 of file fereadl.c.

140 {
142  if ((!fe_use_fgets) && (isatty (STDIN_FILENO)))
143  {
144  /* Make sure stdin is a terminal. */
145  char *term=getenv("TERM");
146 
147  /*setup echo*/
148  if(isatty(STDOUT_FILENO))
149  {
151  fe_echo=stdout;
152  }
153  else
154  {
156  char *tty_name=ttyname(fileno(stdin));
157  if (tty_name!=NULL)
158  fe_echo = fopen( tty_name, "w" );
159  else
160  fe_echo = NULL;
161  if (fe_echo==NULL)
162  {
163  fe_echo=stdout;
164  printf("stdin is a tty, but ttyname fails\n");
165  return;
166  }
167  }
168  /* Save the terminal attributes so we can restore them later. */
169  {
170  struct termios tattr;
171  tcgetattr (STDIN_FILENO, &fe_saved_attributes);
172  #ifdef HAVE_FEREAD
173  #ifdef HAVE_ATEXIT
174  atexit(fe_reset_fe);
175  #else
176  on_exit(fe_reset_fe,NULL);
177  #endif
178  #endif
179 
180  /* Set the funny terminal modes. */
181  tcgetattr (STDIN_FILENO, &tattr);
182  tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
183  tattr.c_cc[VMIN] = 1;
184  tattr.c_cc[VTIME] = 0;
185  tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
186  /*ospeed=cfgetospeed(&tattr);*/
187  }
188  if(term==NULL)
189  {
190  printf("need TERM\n");
191  }
192  else if(tgetent(termcap_buff,term)<=0)
193  {
194  printf("could not access termcap data base\n");
195  }
196  else
197  {
198  #ifndef __CYGWIN__
199  extern char *BC;
200  extern char *UP;
201  extern char PC;
202  #endif
203  /* OB: why this ? HS: char t_buf[128] does not work with glibc2 systems */
204  char *t_buf=(char *)omAlloc(128);
205  /*char t_buf[128];*/
206  char *temp;
207  char** t_buf_ptr= &t_buf;
208  /* Extract information that termcap functions use. */
209  temp = tgetstr ("pc", t_buf_ptr);
210  PC = (temp!=NULL) ? *temp : '\0';
211  BC=tgetstr("le",t_buf_ptr);
212  UP=tgetstr("up",t_buf_ptr);
213 
214  /* Extract information we will use */
215  colmax=tgetnum("co");
216  pagelength=tgetnum("li");
218 
219  /* init screen */
220  temp = tgetstr ("ti", t_buf_ptr);
221  #if 0
222  if (temp!=NULL) tputs(temp,1,fe_out_char);
223  #endif
224 
225  /* printf("TERM=%s, co=%d, li=%d\n",term,colmax,pagelength);*/
226  }
227 
228  fe_stdin_is_tty=1;
229  fe_is_raw_tty=1;
230 
231  /* setup history */
232  fe_hist=(char **)omAlloc0(fe_hist_max*sizeof(char *));
234  fe_hist_pos=0;
235  }
236  else
237  {
238  fe_stdin_is_tty=0;
239  fe_echo=stdout;
240  }
241 }
#define ECHO
Definition: libparse.cc:1341
short fe_cursor_line
Definition: fereadl.c:73
static int fe_out_char(int c)
Definition: fereadl.c:134
Definition: int_poly.h:33
#define STDOUT_FILENO
Definition: fereadl.c:54
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
FILE * fe_echo
Definition: fereadl.c:66
static BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:62
#define STDIN_FILENO
Definition: fereadl.c:51
static BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:61
char * getenv()
#define TRUE
Definition: auxiliary.h:98
void fe_reset_fe(void)
Definition: fereadl.c:82
int pagelength
Definition: febase.cc:38
#define omAlloc(size)
Definition: omAllocDecl.h:210
static BOOLEAN fe_is_initialized
Definition: fereadl.c:64
static char termcap_buff[2048]
Definition: fereadl.c:133
char ** fe_hist
Definition: fereadl.c:69
#define NULL
Definition: omList.c:12
short fe_hist_pos
Definition: fereadl.c:70
struct termios fe_saved_attributes
Definition: fereadl.c:59
void omMarkAsStaticAddr(void *addr)
BOOLEAN fe_use_fgets
Definition: fereadl.c:63
int colmax
Definition: febase.cc:37
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define fe_hist_max
Definition: fereadl.c:68

◆ fe_init_dyn_rl()

int fe_init_dyn_rl ( )

Definition at line 755 of file fereadl.c.

756 {
757  int res=0;
758  loop
759  {
760  fe_rl_hdl=dynl_open("libreadline.so");
761  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.2");
762  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.3");
763  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.4");
764  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.5");
765  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.6");
766  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.7");
767  if (fe_rl_hdl==NULL) { return 1;}
768 
770  dynl_sym(fe_rl_hdl, "filename_completion_function");
771  if (fe_filename_completion_function==NULL) { res=3; break; }
772  fe_readline=dynl_sym(fe_rl_hdl,"readline");
773  if (fe_readline==NULL) { res=4; break; }
774  fe_add_history=dynl_sym(fe_rl_hdl,"add_history");
775  if (fe_add_history==NULL) { res=5; break; }
776  fe_rl_readline_name=(char**)dynl_sym(fe_rl_hdl,"rl_readline_name");
777  if (fe_rl_readline_name==NULL) { res=6; break; }
778  fe_rl_line_buffer=(char**)dynl_sym(fe_rl_hdl,"rl_line_buffer");
779  if (fe_rl_line_buffer==NULL) { res=7; break; }
780  fe_completion_matches=dynl_sym(fe_rl_hdl,"completion_matches");
781  if (fe_completion_matches==NULL) { res=8; break; }
783  dynl_sym(fe_rl_hdl,"rl_attempted_completion_function");
784  if (fe_rl_attempted_completion_function==NULL) { res=9; break; }
785  fe_rl_outstream=(FILE**)dynl_sym(fe_rl_hdl,"rl_outstream");
786  if (fe_rl_outstream==NULL) { res=10; break; }
787  fe_write_history=dynl_sym(fe_rl_hdl,"write_history");
788  if (fe_write_history==NULL) { res=11; break; }
789  fe_history_total_bytes=dynl_sym(fe_rl_hdl,"history_total_bytes");
790  if (fe_history_total_bytes==NULL) { res=12; break; }
791  fe_using_history=dynl_sym(fe_rl_hdl,"using_history");
792  if (fe_using_history==NULL) { res=13; break; }
793  fe_read_history=dynl_sym(fe_rl_hdl,"read_history");
794  if (fe_read_history==NULL) { res=14; break; }
795  break;
796  }
797  if (res!=0) dynl_close(fe_rl_hdl);
798  else
799  {
800  char *p;
801  /* more init stuff: */
802  /* Allow conditional parsing of the ~/.inputrc file. */
803  (*fe_rl_readline_name) = "Singular";
804  /* Tell the completer that we want a crack first. */
805  (*fe_rl_attempted_completion_function) = (CPPFunction *)singular_completion;
806  /* try to read a history */
807  (*fe_using_history)();
808  p = getenv("SINGULARHIST");
809  if (p != NULL)
810  {
811  (*fe_read_history) (p);
812  }
813  }
814  return res;
815 }
void * fe_rl_hdl
Definition: fereadl.c:726
int(* fe_read_history)()
Definition: fereadl.c:724
char *(* fe_filename_completion_function)()
Definition: fereadl.c:713
char ** singular_completion(char *text, int start, int end)
Definition: fereadl.c:735
char ** fe_rl_line_buffer
Definition: fereadl.c:717
char * getenv()
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:159
#define loop
Definition: structs.h:80
FILE ** fe_rl_outstream
Definition: fereadl.c:720
char **(* fe_completion_matches)()
Definition: fereadl.c:718
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
CanonicalForm res
Definition: facAbsFact.cc:64
void(* fe_using_history)()
Definition: fereadl.c:723
char ** CPPFunction()
Definition: fereadl.c:711
char ** fe_rl_readline_name
Definition: fereadl.c:716
int(* fe_history_total_bytes)()
Definition: fereadl.c:722
void(* fe_add_history)()
Definition: fereadl.c:715
int dynl_close(void *handle)
Definition: mod_raw.cc:170
#define NULL
Definition: omList.c:12
int(* fe_write_history)()
Definition: fereadl.c:721
int p
Definition: cfModGcd.cc:4019
CPPFunction ** fe_rl_attempted_completion_function
Definition: fereadl.c:719
char *(* fe_readline)()
Definition: fereadl.c:714

◆ fe_out_char()

static int fe_out_char ( int  c)
static

Definition at line 134 of file fereadl.c.

135 {
136  fputc(c,fe_echo);
137  return c;
138 }
FILE * fe_echo
Definition: fereadl.c:66

◆ 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 }
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
FILE * fe_echo
Definition: fereadl.c:66
static BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:62
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define STDIN_FILENO
Definition: fereadl.c:51
static BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:61
void * ADDRESS
Definition: auxiliary.h:133
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:125
char ** fe_hist
Definition: fereadl.c:69
#define NULL
Definition: omList.c:12
struct termios fe_saved_attributes
Definition: fereadl.c:59
#define fe_hist_max
Definition: fereadl.c:68

◆ fe_reset_input_mode()

void fe_reset_input_mode ( )

Definition at line 825 of file fereadl.c.

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

◆ fe_set_cursor()

static void fe_set_cursor ( char *  s,
int  i 
)
static

Definition at line 360 of file fereadl.c.

361 {
362  char tgoto_buf[40];
363  if (0)/*(fe_cursor_pos>1) && (i>0))*/
364  {
365  /*fputs(tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),fe_echo);*/
366  tputs(
367  tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),
369  fputc(s[i-1],fe_echo);
370  }
371  else
372  {
373  /*fputs(
374  tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos,fe_cursor_line),fe_echo);*/
375  tputs(tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos,fe_cursor_line),
377  }
378  fflush(fe_echo);
379 }
short fe_cursor_line
Definition: fereadl.c:73
const CanonicalForm int s
Definition: facAbsFact.cc:55
static int fe_out_char(int c)
Definition: fereadl.c:134
short fe_cursor_pos
Definition: fereadl.c:72
FILE * fe_echo
Definition: fereadl.c:66
int pagelength
Definition: febase.cc:38
int i
Definition: cfEzgcd.cc:125

◆ fe_temp_reset()

void fe_temp_reset ( void  )

Definition at line 109 of file fereadl.c.

110 {
111  if (fe_is_raw_tty)
112  {
113  tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
114  fe_is_raw_tty=0;
115  }
116 }
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
#define STDIN_FILENO
Definition: fereadl.c:51
struct termios fe_saved_attributes
Definition: fereadl.c:59

◆ fe_temp_set()

void fe_temp_set ( void  )

Definition at line 117 of file fereadl.c.

118 {
119  if(fe_is_raw_tty==0)
120  {
121  struct termios tattr;
122 
123  /* Set the funny terminal modes. */
124  tcgetattr (STDIN_FILENO, &tattr);
125  tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
126  tattr.c_cc[VMIN] = 1;
127  tattr.c_cc[VTIME] = 0;
128  tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
129  fe_is_raw_tty=1;
130  }
131 }
#define ECHO
Definition: libparse.cc:1341
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
#define STDIN_FILENO
Definition: fereadl.c:51

◆ singular_completion()

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

Definition at line 735 of file fereadl.c.

736 {
737  /* If this word is not in a string, then it may be a command
738  to complete. Otherwise it may be the name of a file in the current
739  directory. */
740  char **m;
741  if ((*fe_rl_line_buffer)[start-1]=='"')
743  m=(*fe_completion_matches) (text, command_generator);
744  if (m==NULL)
745  {
746  m=(char **)malloc(2*sizeof(char*));
747  m[0]=(char *)malloc(end-start+2);
748  strncpy(m[0],text,end-start+1);
749  m[1]=NULL;
750  }
751  return m;
752 }
char *(* fe_filename_completion_function)()
Definition: fereadl.c:713
char ** fe_rl_line_buffer
Definition: fereadl.c:717
char **(* fe_completion_matches)()
Definition: fereadl.c:718
void * malloc(size_t size)
Definition: omalloc.c:92
int m
Definition: cfEzgcd.cc:121
#define NULL
Definition: omList.c:12
char * command_generator(char *text, int state)
Definition: feread.cc:54

Variable Documentation

◆ fe_add_history

void(* fe_add_history) ()

Definition at line 715 of file fereadl.c.

◆ fe_completion_matches

char**(* fe_completion_matches) ()

Definition at line 718 of file fereadl.c.

◆ fe_cursor_line

short fe_cursor_line

Definition at line 73 of file fereadl.c.

◆ fe_cursor_pos

short fe_cursor_pos

Definition at line 72 of file fereadl.c.

◆ fe_echo

FILE* fe_echo

Definition at line 66 of file fereadl.c.

◆ fe_filename_completion_function

char*(* fe_filename_completion_function) ()

Definition at line 713 of file fereadl.c.

◆ fe_hist

char** fe_hist =NULL

Definition at line 69 of file fereadl.c.

◆ fe_hist_pos

short fe_hist_pos

Definition at line 70 of file fereadl.c.

◆ fe_history_total_bytes

int(* fe_history_total_bytes) ()

Definition at line 722 of file fereadl.c.

◆ fe_is_initialized

BOOLEAN fe_is_initialized =FALSE
static

Definition at line 64 of file fereadl.c.

◆ fe_is_raw_tty

BOOLEAN fe_is_raw_tty =0

Definition at line 71 of file fereadl.c.

◆ fe_read_history

int(* fe_read_history) ()

Definition at line 724 of file fereadl.c.

◆ fe_readline

char*(* fe_readline) ()

Definition at line 714 of file fereadl.c.

◆ fe_rl_attempted_completion_function

CPPFunction** fe_rl_attempted_completion_function

Definition at line 719 of file fereadl.c.

◆ fe_rl_hdl

void* fe_rl_hdl =NULL

Definition at line 726 of file fereadl.c.

◆ fe_rl_line_buffer

char** fe_rl_line_buffer

Definition at line 717 of file fereadl.c.

◆ fe_rl_outstream

FILE** fe_rl_outstream

Definition at line 720 of file fereadl.c.

◆ fe_rl_readline_name

char** fe_rl_readline_name

Definition at line 716 of file fereadl.c.

◆ fe_saved_attributes

struct termios fe_saved_attributes

Definition at line 59 of file fereadl.c.

◆ fe_stdin_is_tty

BOOLEAN fe_stdin_is_tty
static

Definition at line 62 of file fereadl.c.

◆ fe_stdout_is_tty

BOOLEAN fe_stdout_is_tty
static

Definition at line 61 of file fereadl.c.

◆ fe_use_fgets

BOOLEAN fe_use_fgets =FALSE

Definition at line 63 of file fereadl.c.

◆ fe_using_history

void(* fe_using_history) ()

Definition at line 723 of file fereadl.c.

◆ fe_write_history

int(* fe_write_history) ()

Definition at line 721 of file fereadl.c.

◆ termcap_buff

char termcap_buff[2048]
static

Definition at line 133 of file fereadl.c.