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 #ifdef HAVE_FEREAD
16  #include <unistd.h>
17  #include <stdio.h>
18  #include <stdlib.h>
19  #include <sys/time.h>
20  #include <sys/types.h>
21  #include <string.h>
22 
23  #if 0
24  #include <pc.h>
25  #else
26  #ifdef SunOS_5
27  /* solaris special, found with v 5.7 */
28  #define _XOPEN_SOURCE_EXTENDED
29  #include "/usr/xpg4/include/term.h"
30  #endif
31  #if 0
32  #ifndef SunOS_5
33  #include <term.h>
34  #endif
35  #elif HAVE_TERMCAP_H
36  #ifndef SunOS_5
37  #include <termcap.h>
38  #endif
39  #endif
40  #if defined(HAVE_TERMIOS_H) && ! defined(TCSANOW)
41  #include <termios.h>
42  #endif
43  #if defined(HAVE_TERM_H) && ! defined(TCSANOW)
44  #include <term.h>
45  #endif
46 
47  #endif
48 
49 
50 #ifndef STDIN_FILENO
51  #define STDIN_FILENO 0
52 #endif
53 #ifndef STDOUT_FILENO
54  #define STDOUT_FILENO 1
55 #endif
56 
57 #define feCTRL(C) ((C) & 0x1F) /* <ctrl> character */
58 
59 VAR struct termios fe_saved_attributes;
60 
65 
66 VAR FILE * fe_echo; /*the output file for echoed characters*/
67 
68 #define fe_hist_max 32
69 VAR char ** fe_hist=NULL;
72 VAR short fe_cursor_pos; /* 0..colmax-1*/
73 VAR short fe_cursor_line; /* 0..pagelength-1*/
74 
75 #ifndef HAVE_ATEXIT
76  int on_exit(void (*f)(int, void *), void *arg);
77  #ifdef HAVE_FEREAD
78  void fe_reset_fe (int i, void *v)
79  #endif
80 #else
81  #ifdef HAVE_FEREAD
82  void fe_reset_fe (void)
83  #endif
84 #endif
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 }
109 void fe_temp_reset (void)
110 {
111  if (fe_is_raw_tty)
112  {
113  tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
114  fe_is_raw_tty=0;
115  }
116 }
117 void fe_temp_set (void)
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 }
132 
134 static int fe_out_char(int c)
135 {
136  fputc(c,fe_echo);
137  return c;
138 }
139 static void fe_init (void)
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_VAR char *BC;
200  EXTERN_VAR char *UP;
201  EXTERN_VAR 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 }
242 
243 /* delete to end of line */
244 static void fe_ctrl_k(char *s,int i)
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 }
258 
259 /* delete the line */
260 static void fe_ctrl_u(char *s,int *i)
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 }
271 
272 /*2
273 * add s to the history
274 * if s is no the previous one, duplicate it
275 */
276 static void fe_add_hist(char *s)
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++;
304  if (fe_hist_pos==fe_hist_max) fe_hist_pos=0;
305  }
306 }
307 
308 static void fe_get_hist(char *s, int size, int *pos,int change, int incr)
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 }
325 
326 static int fe_getchar()
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 }
359 
360 static void fe_set_cursor(char *s,int i)
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 }
380 
381 char * fe_fgets_stdin_fe(char *pr,char *s, int size)
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 }
688 
689 //int main (void)
690 //{
691 // char b[200];
692 // char * m_eof;
693 //
694 // fe_init();
695 // while(1)
696 // {
697 // m_eof=fe_fgets_stdin_fe("> ",b,200);
698 // if (!m_eof) break;
699 // printf(">>%s<<\n",b);
700 // }
701 //
702 // return 0;
703 //}
704 #endif
705 
706 /* ================================================================ */
707 #if defined(HAVE_DYN_RL)
708 #include <unistd.h>
709 #include "kernel/mod_raw.h"
710 
711  typedef char **CPPFunction ();
712 
713  char *(*fe_filename_completion_function)(); /* 3 */
714  char *(* fe_readline) (); /* 4 */
715  VAR void (*fe_add_history) (); /* 5 */
716  VAR char ** fe_rl_readline_name; /* 6 */
717  VAR char **fe_rl_line_buffer; /* 7 */
718  char **(*fe_completion_matches)(); /* 8 */
720  VAR FILE ** fe_rl_outstream; /* 10 */
721  VAR int (*fe_write_history) (); /* 11 */
722  VAR int (*fe_history_total_bytes) (); /* 12 */
723  VAR void (*fe_using_history) (); /* 13 */
724  VAR int (*fe_read_history) (); /* 14 */
725 
727 
728 char *command_generator (char *text, int state);
729 
730 /* Attempt to complete on the contents of TEXT. START and END show the
731 * region of TEXT that contains the word to complete. We can use the
732 * entire line in case we want to do some simple parsing. Return the
733 * array of matches, or NULL if there aren't any.
734 */
735 char ** singular_completion (char *text, int start, int end)
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 }
753 
754 
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; }
782  fe_rl_attempted_completion_function=
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 }
816 #endif
817 
818 /* ===================================================================*/
819 /* = fe_reset_input_mode (all possibilities) = */
820 /* ===================================================================*/
821 #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
822 extern int history_total_bytes();
823 extern int write_history (const char *);
824 #endif
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 }
851 
#define ECHO
Definition: libparse.cc:1343
const CanonicalForm int s
Definition: facAbsFact.cc:55
VAR char ** fe_rl_readline_name
Definition: fereadl.c:716
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
STATIC_VAR BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:61
Definition: int_poly.h:33
char *(* fe_filename_completion_function)()
Definition: fereadl.c:713
#define FALSE
Definition: auxiliary.h:96
#define STDOUT_FILENO
Definition: fereadl.c:54
VAR short fe_cursor_line
Definition: fereadl.c:73
VAR int(* fe_history_total_bytes)()
Definition: fereadl.c:722
VAR short fe_cursor_pos
Definition: fereadl.c:72
char ** singular_completion(char *text, int start, int end)
Definition: fereadl.c:735
#define EXTERN_VAR
Definition: globaldefs.h:6
#define feCTRL(C)
Definition: fereadl.c:57
#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:308
#define STDIN_FILENO
Definition: fereadl.c:51
char * getenv()
#define TRUE
Definition: auxiliary.h:100
void * ADDRESS
Definition: auxiliary.h:135
#define VAR
Definition: globaldefs.h:5
VAR void * fe_rl_hdl
Definition: fereadl.c:726
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:162
void fe_reset_fe(void)
Definition: fereadl.c:82
#define loop
Definition: structs.h:80
int write_history()
#define omAlloc(size)
Definition: omAllocDecl.h:210
STATIC_VAR BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:62
char **(* fe_completion_matches)()
Definition: fereadl.c:718
VAR BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
VAR struct termios fe_saved_attributes
Definition: fereadl.c:59
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
STATIC_VAR char termcap_buff[2048]
Definition: fereadl.c:133
VAR FILE ** fe_rl_outstream
Definition: fereadl.c:720
static void fe_init(void)
Definition: fereadl.c:139
VAR int(* fe_write_history)()
Definition: fereadl.c:721
VAR CPPFunction ** fe_rl_attempted_completion_function
Definition: fereadl.c:719
CanonicalForm res
Definition: facAbsFact.cc:64
int history_total_bytes()
VAR BOOLEAN fe_use_fgets
Definition: fereadl.c:63
#define omFree(addr)
Definition: omAllocDecl.h:261
int status read
Definition: si_signals.h:59
VAR char ** fe_hist
Definition: fereadl.c:69
void * malloc(size_t size)
Definition: omalloc.c:92
VAR void(* fe_using_history)()
Definition: fereadl.c:723
void select(const ListCFList &ppi, int length, ListCFList &ppi1, ListCFList &ppi2)
char ** CPPFunction()
Definition: fereadl.c:711
int m
Definition: cfEzgcd.cc:121
#define STATIC_VAR
Definition: globaldefs.h:7
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
void PrintS(const char *s)
Definition: reporter.cc:284
VAR int(* fe_read_history)()
Definition: fereadl.c:724
static void fe_set_cursor(char *s, int i)
Definition: fereadl.c:360
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
VAR char ** fe_rl_line_buffer
Definition: fereadl.c:717
VAR void(* fe_add_history)()
Definition: fereadl.c:715
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
VAR short fe_hist_pos
Definition: fereadl.c:70
STATIC_VAR Poly * h
Definition: janet.cc:971
int dynl_close(void *handle)
Definition: mod_raw.cc:173
#define NULL
Definition: omList.c:12
char * fe_fgets_stdin_fe(char *pr, char *s, int size)
Definition: fereadl.c:381
static int fe_getchar()
Definition: fereadl.c:326
EXTERN_VAR int pagelength
Definition: reporter.h:17
int fe_init_dyn_rl()
Definition: fereadl.c:755
void fe_temp_reset(void)
Definition: fereadl.c:109
VAR FILE * fe_echo
Definition: fereadl.c:66
void omMarkAsStaticAddr(void *addr)
STATIC_VAR BOOLEAN fe_is_initialized
Definition: fereadl.c:64
int p
Definition: cfModGcd.cc:4019
char *(* fe_readline)()
Definition: fereadl.c:714
int BOOLEAN
Definition: auxiliary.h:87
void fe_reset_input_mode()
Definition: fereadl.c:825
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:93
#define fe_hist_max
Definition: fereadl.c:68
char * command_generator(char *text, int state)
Definition: feread.cc:54
EXTERN_VAR int colmax
Definition: reporter.h:17
void fe_temp_set(void)
Definition: fereadl.c:117
#define omStrDup(s)
Definition: omAllocDecl.h:263