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
 
static int pagelength = 24
 
FILE * fe_echo
 
char ** fe_hist =NULL
 
short fe_hist_pos
 
BOOLEAN fe_is_raw_tty =0
 
int fe_cursor_pos
 
int 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 72 of file fereadl.c.

◆ feCTRL

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

Definition at line 60 of file fereadl.c.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 54 of file fereadl.c.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

Definition at line 57 of file fereadl.c.

Typedef Documentation

◆ CPPFunction

typedef char** CPPFunction()

Definition at line 722 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:9032
char name(const Variable &v)
Definition: factory.h:178
#define strdup
Definition: omAllocFunc.c:17
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
static Poly * h
Definition: janet.cc:978

◆ fe_add_hist()

static void fe_add_hist ( char *  s)
static

Definition at line 280 of file fereadl.c.

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

◆ fe_ctrl_k()

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

Definition at line 248 of file fereadl.c.

249 {
250  int j=i;
251  while(s[j]!='\0')
252  {
253  fputc(' ',fe_echo);
254  j++;
255  }
256  while(j>i)
257  {
258  fputc('\b',fe_echo);
259  j--;
260  }
261 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
FILE * fe_echo
Definition: fereadl.c:70
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123

◆ fe_ctrl_u()

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

Definition at line 264 of file fereadl.c.

265 {
266  fe_ctrl_k(s,*i);
267  while((*i)>0)
268  {
269  (*i)--;
270  fputc('\b',fe_echo);
271  fputc(' ',fe_echo);
272  fputc('\b',fe_echo);
273  }
274 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:248
FILE * fe_echo
Definition: fereadl.c:70
int i
Definition: cfEzgcd.cc:123

◆ fe_fgets_stdin_fe()

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

Definition at line 385 of file fereadl.c.

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

◆ fe_get_hist()

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

Definition at line 312 of file fereadl.c.

313 {
314  if (change)
315  fe_add_hist(s);
316  do
317  {
318  (*pos)+=incr;
319  if((*pos)>=fe_hist_max) (*pos)-=fe_hist_max;
320  else if((*pos)<0) (*pos)+=fe_hist_max;
321  }
322  while (((*pos)!=0)&&(fe_hist[(*pos)]==NULL));
323  memset(s,0,size);
324  if (fe_hist[(*pos)]!=NULL)
325  {
326  strncpy(s,fe_hist[(*pos)],size-2);
327  }
328 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static void fe_add_hist(char *s)
Definition: fereadl.c:280
char ** fe_hist
Definition: fereadl.c:73
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:10
#define fe_hist_max
Definition: fereadl.c:72

◆ fe_getchar()

static int fe_getchar ( )
static

Definition at line 330 of file fereadl.c.

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

◆ fe_init()

static void fe_init ( void  )
static

Definition at line 143 of file fereadl.c.

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

◆ fe_init_dyn_rl()

int fe_init_dyn_rl ( )

Definition at line 766 of file fereadl.c.

767 {
768  int res=0;
769  loop
770  {
771  fe_rl_hdl=dynl_open("libreadline.so");
772  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.2");
773  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.3");
774  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.4");
775  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.5");
776  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.6");
777  if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.7");
778  if (fe_rl_hdl==NULL) { return 1;}
779 
781  dynl_sym(fe_rl_hdl, "filename_completion_function");
782  if (fe_filename_completion_function==NULL) { res=3; break; }
783  fe_readline=dynl_sym(fe_rl_hdl,"readline");
784  if (fe_readline==NULL) { res=4; break; }
785  fe_add_history=dynl_sym(fe_rl_hdl,"add_history");
786  if (fe_add_history==NULL) { res=5; break; }
787  fe_rl_readline_name=(char**)dynl_sym(fe_rl_hdl,"rl_readline_name");
788  if (fe_rl_readline_name==NULL) { res=6; break; }
789  fe_rl_line_buffer=(char**)dynl_sym(fe_rl_hdl,"rl_line_buffer");
790  if (fe_rl_line_buffer==NULL) { res=7; break; }
791  fe_completion_matches=dynl_sym(fe_rl_hdl,"completion_matches");
792  if (fe_completion_matches==NULL) { res=8; break; }
794  dynl_sym(fe_rl_hdl,"rl_attempted_completion_function");
795  if (fe_rl_attempted_completion_function==NULL) { res=9; break; }
796  fe_rl_outstream=(FILE**)dynl_sym(fe_rl_hdl,"rl_outstream");
797  if (fe_rl_outstream==NULL) { res=10; break; }
798  fe_write_history=dynl_sym(fe_rl_hdl,"write_history");
799  if (fe_write_history==NULL) { res=11; break; }
800  fe_history_total_bytes=dynl_sym(fe_rl_hdl,"history_total_bytes");
801  if (fe_history_total_bytes==NULL) { res=12; break; }
802  fe_using_history=dynl_sym(fe_rl_hdl,"using_history");
803  if (fe_using_history==NULL) { res=13; break; }
804  fe_read_history=dynl_sym(fe_rl_hdl,"read_history");
805  if (fe_read_history==NULL) { res=14; break; }
806  break;
807  }
808  if (res!=0) dynl_close(fe_rl_hdl);
809  else
810  {
811  char *p;
812  /* more init stuff: */
813  /* Allow conditional parsing of the ~/.inputrc file. */
814  (*fe_rl_readline_name) = "Singular";
815  /* Tell the completer that we want a crack first. */
816  (*fe_rl_attempted_completion_function) = (CPPFunction *)singular_completion;
817  /* try to read a history */
818  (*fe_using_history)();
819  p = getenv("SINGULARHIST");
820  if (p != NULL)
821  {
822  (*fe_read_history) (p);
823  }
824  }
825  return res;
826 }
void * fe_rl_hdl
Definition: fereadl.c:737
int(* fe_read_history)()
Definition: fereadl.c:735
loop
Definition: myNF.cc:98
char *(* fe_filename_completion_function)()
Definition: fereadl.c:724
return P p
Definition: myNF.cc:203
char ** singular_completion(char *text, int start, int end)
Definition: fereadl.c:746
char ** fe_rl_line_buffer
Definition: fereadl.c:728
char * getenv()
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:167
FILE ** fe_rl_outstream
Definition: fereadl.c:731
char **(* fe_completion_matches)()
Definition: fereadl.c:729
void * dynl_open(char *filename)
Definition: mod_raw.cc:153
poly res
Definition: myNF.cc:322
void(* fe_using_history)()
Definition: fereadl.c:734
char ** CPPFunction()
Definition: fereadl.c:722
char ** fe_rl_readline_name
Definition: fereadl.c:727
int(* fe_history_total_bytes)()
Definition: fereadl.c:733
void(* fe_add_history)()
Definition: fereadl.c:726
int dynl_close(void *handle)
Definition: mod_raw.cc:178
#define NULL
Definition: omList.c:10
int(* fe_write_history)()
Definition: fereadl.c:732
CPPFunction ** fe_rl_attempted_completion_function
Definition: fereadl.c:730
char *(* fe_readline)()
Definition: fereadl.c:725

◆ fe_out_char()

static int fe_out_char ( int  c)
static

Definition at line 138 of file fereadl.c.

139 {
140  fputc(c,fe_echo);
141  return c;
142 }
FILE * fe_echo
Definition: fereadl.c:70

◆ fe_reset_fe()

void fe_reset_fe ( void  )

Definition at line 86 of file fereadl.c.

89 {
90  if (fe_stdin_is_tty)
91  {
92  int i;
93  if (fe_is_raw_tty)
94  {
95  tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
96  fe_is_raw_tty=0;
97  }
98  if (fe_hist!=NULL)
99  {
100  for(i=fe_hist_max-1;i>=0;i--)
101  {
102  if (fe_hist[i] != NULL) omFree((ADDRESS)fe_hist[i]);
103  }
104  omFreeSize((ADDRESS)fe_hist,fe_hist_max*sizeof(char *));
105  fe_hist=NULL;
106  }
107  if (!fe_stdout_is_tty)
108  {
109  fclose(fe_echo);
110  }
111  }
112 }
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:75
FILE * fe_echo
Definition: fereadl.c:70
static BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:65
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define STDIN_FILENO
Definition: fereadl.c:54
static BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:64
void * ADDRESS
Definition: auxiliary.h:115
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:123
char ** fe_hist
Definition: fereadl.c:73
#define NULL
Definition: omList.c:10
struct termios fe_saved_attributes
Definition: fereadl.c:62
#define fe_hist_max
Definition: fereadl.c:72

◆ fe_reset_input_mode()

void fe_reset_input_mode ( )

Definition at line 836 of file fereadl.c.

837 {
838 #if defined(HAVE_DYN_RL)
839  char *p = getenv("SINGULARHIST");
840  if ((p != NULL) && (fe_history_total_bytes != NULL))
841  {
842  if((*fe_history_total_bytes)()!=0)
843  (*fe_write_history) (p);
844  }
845 #endif
846 #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
847  char *p = getenv("SINGULARHIST");
848  if (p != NULL)
849  {
850  if(history_total_bytes()!=0)
851  write_history (p);
852  }
853 #endif
854 #if defined(HAVE_FEREAD)
855  #ifndef HAVE_ATEXIT
857  #else
858  fe_reset_fe();
859  #endif
860 #endif
861 }
return P p
Definition: myNF.cc:203
char * getenv()
void fe_reset_fe(void)
Definition: fereadl.c:86
int write_history()
int history_total_bytes()
int(* fe_history_total_bytes)()
Definition: fereadl.c:733
#define NULL
Definition: omList.c:10

◆ fe_set_cursor()

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

Definition at line 364 of file fereadl.c.

365 {
366  char tgoto_buf[40];
367  if (0)/*(fe_cursor_pos>1) && (i>0))*/
368  {
369  /*fputs(tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),fe_echo);*/
370  tputs(
371  tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),
373  fputc(s[i-1],fe_echo);
374  }
375  else
376  {
377  /*fputs(
378  tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos,fe_cursor_line),fe_echo);*/
379  tputs(tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos,fe_cursor_line),
381  }
382  fflush(fe_echo);
383 }
static int pagelength
Definition: fereadl.c:68
const CanonicalForm int s
Definition: facAbsFact.cc:55
static int fe_out_char(int c)
Definition: fereadl.c:138
FILE * fe_echo
Definition: fereadl.c:70
int fe_cursor_pos
Definition: fereadl.c:76
int fe_cursor_line
Definition: fereadl.c:77
int i
Definition: cfEzgcd.cc:123

◆ fe_temp_reset()

void fe_temp_reset ( void  )

Definition at line 113 of file fereadl.c.

114 {
115  if (fe_is_raw_tty)
116  {
117  tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
118  fe_is_raw_tty=0;
119  }
120 }
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:75
#define STDIN_FILENO
Definition: fereadl.c:54
struct termios fe_saved_attributes
Definition: fereadl.c:62

◆ fe_temp_set()

void fe_temp_set ( void  )

Definition at line 121 of file fereadl.c.

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

◆ singular_completion()

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

Definition at line 746 of file fereadl.c.

747 {
748  /* If this word is not in a string, then it may be a command
749  to complete. Otherwise it may be the name of a file in the current
750  directory. */
751  char **m;
752  if ((*fe_rl_line_buffer)[start-1]=='"')
754  m=(*fe_completion_matches) (text, command_generator);
755  if (m==NULL)
756  {
757  m=(char **)malloc(2*sizeof(char*));
758  m[0]=(char *)malloc(end-start+2);
759  strncpy(m[0],text,end-start+1);
760  m[1]=NULL;
761  }
762  return m;
763 }
char *(* fe_filename_completion_function)()
Definition: fereadl.c:724
char ** fe_rl_line_buffer
Definition: fereadl.c:728
char **(* fe_completion_matches)()
Definition: fereadl.c:729
void * malloc(size_t size)
Definition: omalloc.c:92
int m
Definition: cfEzgcd.cc:119
#define NULL
Definition: omList.c:10
char * command_generator(char *text, int state)
Definition: feread.cc:54

Variable Documentation

◆ fe_add_history

void(* fe_add_history) ()

Definition at line 726 of file fereadl.c.

◆ fe_completion_matches

char**(* fe_completion_matches) ()

Definition at line 729 of file fereadl.c.

◆ fe_cursor_line

int fe_cursor_line

Definition at line 77 of file fereadl.c.

◆ fe_cursor_pos

int fe_cursor_pos

Definition at line 76 of file fereadl.c.

◆ fe_echo

FILE* fe_echo

Definition at line 70 of file fereadl.c.

◆ fe_filename_completion_function

char*(* fe_filename_completion_function) ()

Definition at line 724 of file fereadl.c.

◆ fe_hist

char** fe_hist =NULL

Definition at line 73 of file fereadl.c.

◆ fe_hist_pos

short fe_hist_pos

Definition at line 74 of file fereadl.c.

◆ fe_history_total_bytes

int(* fe_history_total_bytes) ()

Definition at line 733 of file fereadl.c.

◆ fe_is_initialized

BOOLEAN fe_is_initialized =FALSE
static

Definition at line 67 of file fereadl.c.

◆ fe_is_raw_tty

BOOLEAN fe_is_raw_tty =0

Definition at line 75 of file fereadl.c.

◆ fe_read_history

int(* fe_read_history) ()

Definition at line 735 of file fereadl.c.

◆ fe_readline

char*(* fe_readline) ()

Definition at line 725 of file fereadl.c.

◆ fe_rl_attempted_completion_function

CPPFunction** fe_rl_attempted_completion_function

Definition at line 730 of file fereadl.c.

◆ fe_rl_hdl

void* fe_rl_hdl =NULL

Definition at line 737 of file fereadl.c.

◆ fe_rl_line_buffer

char** fe_rl_line_buffer

Definition at line 728 of file fereadl.c.

◆ fe_rl_outstream

FILE** fe_rl_outstream

Definition at line 731 of file fereadl.c.

◆ fe_rl_readline_name

char** fe_rl_readline_name

Definition at line 727 of file fereadl.c.

◆ fe_saved_attributes

struct termios fe_saved_attributes

Definition at line 62 of file fereadl.c.

◆ fe_stdin_is_tty

BOOLEAN fe_stdin_is_tty
static

Definition at line 65 of file fereadl.c.

◆ fe_stdout_is_tty

BOOLEAN fe_stdout_is_tty
static

Definition at line 64 of file fereadl.c.

◆ fe_use_fgets

BOOLEAN fe_use_fgets =FALSE

Definition at line 66 of file fereadl.c.

◆ fe_using_history

void(* fe_using_history) ()

Definition at line 734 of file fereadl.c.

◆ fe_write_history

int(* fe_write_history) ()

Definition at line 732 of file fereadl.c.

◆ pagelength

int pagelength = 24
static

Definition at line 68 of file fereadl.c.

◆ termcap_buff

char termcap_buff[2048]
static

Definition at line 137 of file fereadl.c.