fereadl.c
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: input from ttys, simulating fgets
6 */
7 
8 
9 
10 
11 
12 #include <kernel/mod2.h>
13 #include <omalloc/omalloc.h>
14 
15 // #include <kernel/structs.h>
16 
17 
18 #ifdef HAVE_FEREAD
19  #include <unistd.h>
20  #include <stdio.h>
21  #include <stdlib.h>
22  #include <sys/time.h>
23  #include <sys/types.h>
24  #include <string.h>
25 
26  #if 0
27  #include <pc.h>
28  #else
29  #ifdef SunOS_5
30  /* solaris special, found with v 5.7 */
31  #define _XOPEN_SOURCE_EXTENDED
32  #include "/usr/xpg4/include/term.h"
33  #endif
34  #if 0
35  #ifndef SunOS_5
36  #include <term.h>
37  #endif
38  #elif HAVE_TERMCAP_H
39  #ifndef SunOS_5
40  #include <termcap.h>
41  #endif
42  #endif
43  #if defined(HAVE_TERMIOS_H) && ! defined(TCSANOW)
44  #include <termios.h>
45  #endif
46  #if defined(HAVE_TERM_H) && ! defined(TCSANOW)
47  #include <term.h>
48  #endif
49 
50  #endif
51 
52 
53 #ifndef STDIN_FILENO
54  #define STDIN_FILENO 0
55 #endif
56 #ifndef STDOUT_FILENO
57  #define STDOUT_FILENO 1
58 #endif
59 
60 #define feCTRL(C) ((C) & 0x1F) /* <ctrl> character */
61 
62 struct termios fe_saved_attributes;
63 
68 static int pagelength = 24;
69 
70 FILE * fe_echo; /*the output file for echoed characters*/
71 
72 #define fe_hist_max 32
73 char ** fe_hist=NULL;
76 int fe_cursor_pos; /* 0..colmax-1*/
77 int fe_cursor_line; /* 0..pagelength-1*/
78 
79 #ifndef HAVE_ATEXIT
80  int on_exit(void (*f)(int, void *), void *arg);
81  #ifdef HAVE_FEREAD
82  void fe_reset_fe (int i, void *v)
83  #endif
84 #else
85  #ifdef HAVE_FEREAD
86  void fe_reset_fe (void)
87  #endif
88 #endif
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 }
113 void fe_temp_reset (void)
114 {
115  if (fe_is_raw_tty)
116  {
117  tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
118  fe_is_raw_tty=0;
119  }
120 }
121 void fe_temp_set (void)
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 }
136 
137 static char termcap_buff[2048];
138 static int fe_out_char(int c)
139 {
140  fputc(c,fe_echo);
141  return c;
142 }
143 static void fe_init (void)
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 }
246 
247 /* delete to end of line */
248 static void fe_ctrl_k(char *s,int i)
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 }
262 
263 /* delete the line */
264 static void fe_ctrl_u(char *s,int *i)
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 }
275 
276 /*2
277 * add s to the history
278 * if s is no the previous one, duplicate it
279 */
280 static void fe_add_hist(char *s)
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++;
308  if (fe_hist_pos==fe_hist_max) fe_hist_pos=0;
309  }
310 }
311 
312 static void fe_get_hist(char *s, int size, int *pos,int change, int incr)
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 }
329 
330 static int fe_getchar()
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 }
363 
364 static void fe_set_cursor(char *s,int i)
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 }
384 
385 char * fe_fgets_stdin_fe(char *pr,char *s, int size)
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 }
692 
693 //int main (void)
694 //{
695 // char b[200];
696 // char * m_eof;
697 //
698 // fe_init();
699 // while(1)
700 // {
701 // m_eof=fe_fgets_stdin_fe("> ",b,200);
702 // if (!m_eof) break;
703 // printf(">>%s<<\n",b);
704 // }
705 //
706 // return 0;
707 //}
708 #endif
709 
710 /* ================================================================ */
711 #if defined(HAVE_DYN_RL)
712 #include <unistd.h>
713 //#include <stdio.h>
714 //#include <stdlib.h>
715 //#include <sys/types.h>
716 //#include <sys/file.h>
717 //#include <sys/stat.h>
718 //#include <sys/errno.h>
719 //#include <dlfcn.h>
720 #include <kernel/mod_raw.h>
721 
722  typedef char **CPPFunction ();
723 
724  char *(*fe_filename_completion_function)(); /* 3 */
725  char *(* fe_readline) (); /* 4 */
726  void (*fe_add_history) (); /* 5 */
727  char ** fe_rl_readline_name; /* 6 */
728  char **fe_rl_line_buffer; /* 7 */
729  char **(*fe_completion_matches)(); /* 8 */
731  FILE ** fe_rl_outstream; /* 10 */
732  int (*fe_write_history) (); /* 11 */
733  int (*fe_history_total_bytes) (); /* 12 */
734  void (*fe_using_history) (); /* 13 */
735  int (*fe_read_history) (); /* 14 */
736 
738 
739 char *command_generator (char *text, int state);
740 
741 /* Attempt to complete on the contents of TEXT. START and END show the
742 * region of TEXT that contains the word to complete. We can use the
743 * entire line in case we want to do some simple parsing. Return the
744 * array of matches, or NULL if there aren't any.
745 */
746 char ** singular_completion (char *text, int start, int end)
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 }
764 
765 
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; }
793  fe_rl_attempted_completion_function=
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 }
827 #endif
828 
829 /* ===================================================================*/
830 /* = fe_reset_input_mode (all possibilities) = */
831 /* ===================================================================*/
832 #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
833 extern int history_total_bytes();
834 extern int write_history (const char *);
835 #endif
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 }
862 
static int pagelength
Definition: fereadl.c:68
#define ECHO
Definition: libparse.cc:1341
const CanonicalForm int s
Definition: facAbsFact.cc:55
void * fe_rl_hdl
Definition: fereadl.c:737
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:248
int(* fe_read_history)()
Definition: fereadl.c:735
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
Definition: int_poly.h:33
loop
Definition: myNF.cc:98
char *(* fe_filename_completion_function)()
Definition: fereadl.c:724
#define FALSE
Definition: auxiliary.h:95
#define STDOUT_FILENO
Definition: fereadl.c:57
return P p
Definition: myNF.cc:203
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:75
FILE * fe_echo
Definition: fereadl.c:70
char ** singular_completion(char *text, int start, int end)
Definition: fereadl.c:746
#define feCTRL(C)
Definition: fereadl.c:60
static BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:65
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
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
static BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:64
char ** fe_rl_line_buffer
Definition: fereadl.c:728
char * getenv()
#define TRUE
Definition: auxiliary.h:99
void * ADDRESS
Definition: auxiliary.h:116
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:167
void fe_reset_fe(void)
Definition: fereadl.c:86
int fe_cursor_pos
Definition: fereadl.c:76
int write_history()
#define omAlloc(size)
Definition: omAllocDecl.h:210
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
static void fe_init(void)
Definition: fereadl.c:143
poly res
Definition: myNF.cc:322
static BOOLEAN fe_is_initialized
Definition: fereadl.c:67
int history_total_bytes()
int fe_cursor_line
Definition: fereadl.c:77
int j
Definition: myNF.cc:70
#define omFree(addr)
Definition: omAllocDecl.h:261
void(* fe_using_history)()
Definition: fereadl.c:734
int status read
Definition: si_signals.h:59
void * malloc(size_t size)
Definition: omalloc.c:92
void select(const ListCFList &ppi, int length, ListCFList &ppi1, ListCFList &ppi2)
char ** CPPFunction()
Definition: fereadl.c:722
int m
Definition: cfEzgcd.cc:119
char ** fe_rl_readline_name
Definition: fereadl.c:727
static char termcap_buff[2048]
Definition: fereadl.c:137
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:284
int(* fe_history_total_bytes)()
Definition: fereadl.c:733
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
void(* fe_add_history)()
Definition: fereadl.c:726
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
int dynl_close(void *handle)
Definition: mod_raw.cc:178
#define NULL
Definition: omList.c:10
int(* fe_write_history)()
Definition: fereadl.c:732
short fe_hist_pos
Definition: fereadl.c:74
char * fe_fgets_stdin_fe(char *pr, char *s, int size)
Definition: fereadl.c:385
static int fe_getchar()
Definition: fereadl.c:330
struct termios fe_saved_attributes
Definition: fereadl.c:62
int fe_init_dyn_rl()
Definition: fereadl.c:766
void fe_temp_reset(void)
Definition: fereadl.c:113
void omMarkAsStaticAddr(void *addr)
BOOLEAN fe_use_fgets
Definition: fereadl.c:66
CPPFunction ** fe_rl_attempted_completion_function
Definition: fereadl.c:730
int colmax
Definition: febase.cc:43
char *(* fe_readline)()
Definition: fereadl.c:725
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:86
void fe_reset_input_mode()
Definition: fereadl.c:836
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
#define fe_hist_max
Definition: fereadl.c:72
char * command_generator(char *text, int state)
Definition: feread.cc:53
void fe_temp_set(void)
Definition: fereadl.c:121
#define omStrDup(s)
Definition: omAllocDecl.h:263