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)
 
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 712 of file fereadl.c.

Function Documentation

§ command_generator()

char* command_generator ( char *  text,
int  state 
)

Definition at line 53 of file feread.cc.

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

§ fe_add_hist()

static void fe_add_hist ( char *  s)
static

Definition at line 270 of file fereadl.c.

271 {
272  if (s[0]!='\0') /* skip empty lines */
273  {
274  /* compare this line*/
275  if (fe_hist_pos!=0)
276  {
277  if ((fe_hist[fe_hist_pos-1]!=NULL)
278  && (strcmp(fe_hist[fe_hist_pos-1],s)==0))
279  return;
280  }
281  else
282  {
283  if ((fe_hist[fe_hist_max-1]!=NULL)
284  && (strcmp(fe_hist[fe_hist_max-1],s)==0))
285  return;
286  }
287  /* normal case: enter a new line */
288  /* first free the slot at position fe_hist_pos */
289  if (fe_hist[fe_hist_pos]!=NULL)
290  {
292  }
293  /* and store a duplicate */
296  /* increment fe_hist_pos in a circular manner */
297  fe_hist_pos++;
299  }
300 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void * ADDRESS
Definition: auxiliary.h:118
#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 238 of file fereadl.c.

239 {
240  int j=i;
241  while(s[j]!='\0')
242  {
243  fputc(' ',fe_echo);
244  j++;
245  }
246  while(j>i)
247  {
248  fputc('\b',fe_echo);
249  j--;
250  }
251 }
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 254 of file fereadl.c.

255 {
256  fe_ctrl_k(s,*i);
257  while((*i)>0)
258  {
259  (*i)--;
260  fputc('\b',fe_echo);
261  fputc(' ',fe_echo);
262  fputc('\b',fe_echo);
263  }
264 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:238
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 375 of file fereadl.c.

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

303 {
304  if (change)
305  fe_add_hist(s);
306  do
307  {
308  (*pos)+=incr;
309  if((*pos)>=fe_hist_max) (*pos)-=fe_hist_max;
310  else if((*pos)<0) (*pos)+=fe_hist_max;
311  }
312  while (((*pos)!=0)&&(fe_hist[(*pos)]==NULL));
313  memset(s,0,size);
314  if (fe_hist[(*pos)]!=NULL)
315  {
316  strncpy(s,fe_hist[(*pos)],size-2);
317  }
318 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
static void fe_add_hist(char *s)
Definition: fereadl.c:270
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 320 of file fereadl.c.

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

§ fe_init()

void fe_init ( void  )

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  fe_echo = fopen( ttyname(fileno(stdin)), "w" );
161  }
162  /* Save the terminal attributes so we can restore them later. */
163  {
164  struct termios tattr;
165  tcgetattr (STDIN_FILENO, &fe_saved_attributes);
166  #ifdef HAVE_FEREAD
167  #ifdef HAVE_ATEXIT
168  atexit(fe_reset_fe);
169  #else
170  on_exit(fe_reset_fe,NULL);
171  #endif
172  #endif
173 
174  /* Set the funny terminal modes. */
175  tcgetattr (STDIN_FILENO, &tattr);
176  tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
177  tattr.c_cc[VMIN] = 1;
178  tattr.c_cc[VTIME] = 0;
179  tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
180  /*ospeed=cfgetospeed(&tattr);*/
181  }
182  if(term==NULL)
183  {
184  printf("need TERM\n");
185  }
186  else if(tgetent(termcap_buff,term)<=0)
187  {
188  printf("could not access termcap data base\n");
189  }
190  else
191  {
192  #ifndef __CYGWIN__
193  extern char *BC;
194  extern char *UP;
195  extern char PC;
196  #endif
197  /* OB: why this ? HS: char t_buf[128] does not work with glibc2 systems */
198  char *t_buf=(char *)omAlloc(128);
199  /*char t_buf[128];*/
200  char *temp;
201  char** t_buf_ptr= &t_buf;
202  /* Extract information that termcap functions use. */
203  temp = tgetstr ("pc", t_buf_ptr);
204  PC = (temp!=NULL) ? *temp : '\0';
205  BC=tgetstr("le",t_buf_ptr);
206  UP=tgetstr("up",t_buf_ptr);
207 
208  /* Extract information we will use */
209  colmax=tgetnum("co");
210  pagelength=tgetnum("li");
212 
213  /* init screen */
214  temp = tgetstr ("ti", t_buf_ptr);
215  #if 0
216  if (temp!=NULL) tputs(temp,1,fe_out_char);
217  #endif
218 
219  /* printf("TERM=%s, co=%d, li=%d\n",term,colmax,pagelength);*/
220  }
221 
222  fe_stdin_is_tty=1;
223  fe_is_raw_tty=1;
224 
225  /* setup history */
226  fe_hist=(char **)omAlloc0(fe_hist_max*sizeof(char *));
228  fe_hist_pos=0;
229  }
230  else
231  {
232  fe_stdin_is_tty=0;
233  fe_echo=stdout;
234  }
235 }
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:101
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 756 of file fereadl.c.

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

§ 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:118
#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 826 of file fereadl.c.

827 {
828 #if defined(HAVE_DYN_RL)
829  char *p = getenv("SINGULARHIST");
830  if ((p != NULL) && (fe_history_total_bytes != NULL))
831  {
832  if((*fe_history_total_bytes)()!=0)
833  (*fe_write_history) (p);
834  }
835 #endif
836 #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
837  char *p = getenv("SINGULARHIST");
838  if (p != NULL)
839  {
840  if(history_total_bytes()!=0)
841  write_history (p);
842  }
843 #endif
844 #if defined(HAVE_FEREAD)
845  #ifndef HAVE_ATEXIT
847  #else
848  fe_reset_fe();
849  #endif
850 #endif
851 }
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:723
#define NULL
Definition: omList.c:10

§ fe_set_cursor()

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

Definition at line 354 of file fereadl.c.

355 {
356  char tgoto_buf[40];
357  if (0)/*(fe_cursor_pos>1) && (i>0))*/
358  {
359  /*fputs(tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),fe_echo);*/
360  tputs(
361  tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),
363  fputc(s[i-1],fe_echo);
364  }
365  else
366  {
367  /*fputs(
368  tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos,fe_cursor_line),fe_echo);*/
369  tputs(tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos,fe_cursor_line),
371  }
372  fflush(fe_echo);
373 }
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 736 of file fereadl.c.

737 {
738  /* If this word is not in a string, then it may be a command
739  to complete. Otherwise it may be the name of a file in the current
740  directory. */
741  char **m;
742  if ((*fe_rl_line_buffer)[start-1]=='"')
744  m=(*fe_completion_matches) (text, command_generator);
745  if (m==NULL)
746  {
747  m=(char **)malloc(2*sizeof(char*));
748  m[0]=(char *)malloc(end-start+2);
749  strncpy(m[0],text,end-start+1);
750  m[1]=NULL;
751  }
752  return m;
753 }
char *(* fe_filename_completion_function)()
Definition: fereadl.c:714
char ** fe_rl_line_buffer
Definition: fereadl.c:718
char **(* fe_completion_matches)()
Definition: fereadl.c:719
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:53

Variable Documentation

§ fe_add_history

void(* fe_add_history) ()

Definition at line 716 of file fereadl.c.

§ fe_completion_matches

char**(* fe_completion_matches) ()

Definition at line 719 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 714 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 723 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 725 of file fereadl.c.

§ fe_readline

char*(* fe_readline) ()

Definition at line 715 of file fereadl.c.

§ fe_rl_attempted_completion_function

CPPFunction** fe_rl_attempted_completion_function

Definition at line 720 of file fereadl.c.

§ fe_rl_hdl

void* fe_rl_hdl =NULL

Definition at line 727 of file fereadl.c.

§ fe_rl_line_buffer

char** fe_rl_line_buffer

Definition at line 718 of file fereadl.c.

§ fe_rl_outstream

FILE** fe_rl_outstream

Definition at line 721 of file fereadl.c.

§ fe_rl_readline_name

char** fe_rl_readline_name

Definition at line 717 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 724 of file fereadl.c.

§ fe_write_history

int(* fe_write_history) ()

Definition at line 722 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.