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 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  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 }
236 
237 /* delete to end of line */
238 static void fe_ctrl_k(char *s,int i)
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 }
252 
253 /* delete the line */
254 static void fe_ctrl_u(char *s,int *i)
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 }
265 
266 /*2
267 * add s to the history
268 * if s is no the previous one, duplicate it
269 */
270 static void fe_add_hist(char *s)
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++;
298  if (fe_hist_pos==fe_hist_max) fe_hist_pos=0;
299  }
300 }
301 
302 static void fe_get_hist(char *s, int size, int *pos,int change, int incr)
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 }
319 
320 static int fe_getchar()
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 }
353 
354 static void fe_set_cursor(char *s,int i)
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 }
374 
375 char * fe_fgets_stdin_fe(char *pr,char *s, int size)
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 }
682 
683 //int main (void)
684 //{
685 // char b[200];
686 // char * m_eof;
687 //
688 // fe_init();
689 // while(1)
690 // {
691 // m_eof=fe_fgets_stdin_fe("> ",b,200);
692 // if (!m_eof) break;
693 // printf(">>%s<<\n",b);
694 // }
695 //
696 // return 0;
697 //}
698 #endif
699 
700 /* ================================================================ */
701 #if defined(HAVE_DYN_RL)
702 #include <unistd.h>
703 //#include <stdio.h>
704 //#include <stdlib.h>
705 //#include <sys/types.h>
706 //#include <sys/file.h>
707 //#include <sys/stat.h>
708 //#include <sys/errno.h>
709 //#include <dlfcn.h>
710 #include <kernel/mod_raw.h>
711 
712  typedef char **CPPFunction ();
713 
714  char *(*fe_filename_completion_function)(); /* 3 */
715  char *(* fe_readline) (); /* 4 */
716  void (*fe_add_history) (); /* 5 */
717  char ** fe_rl_readline_name; /* 6 */
718  char **fe_rl_line_buffer; /* 7 */
719  char **(*fe_completion_matches)(); /* 8 */
721  FILE ** fe_rl_outstream; /* 10 */
722  int (*fe_write_history) (); /* 11 */
723  int (*fe_history_total_bytes) (); /* 12 */
724  void (*fe_using_history) (); /* 13 */
725  int (*fe_read_history) (); /* 14 */
726 
728 
729 char *command_generator (char *text, int state);
730 
731 /* Attempt to complete on the contents of TEXT. START and END show the
732 * region of TEXT that contains the word to complete. We can use the
733 * entire line in case we want to do some simple parsing. Return the
734 * array of matches, or NULL if there aren't any.
735 */
736 char ** singular_completion (char *text, int start, int end)
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 }
754 
755 
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; }
783  fe_rl_attempted_completion_function=
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 }
817 #endif
818 
819 /* ===================================================================*/
820 /* = fe_reset_input_mode (all possibilities) = */
821 /* ===================================================================*/
822 #if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
823 extern int history_total_bytes();
824 extern int write_history (const char *);
825 #endif
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 }
852 
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:727
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:238
int(* fe_read_history)()
Definition: fereadl.c:725
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
Definition: int_poly.h:33
loop
Definition: myNF.cc:98
char *(* fe_filename_completion_function)()
Definition: fereadl.c:714
#define FALSE
Definition: auxiliary.h:97
#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:736
#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:302
#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:718
char * getenv()
#define TRUE
Definition: auxiliary.h:101
void * ADDRESS
Definition: auxiliary.h:118
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: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
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_init(void)
Definition: fereadl.c:143
void(* fe_using_history)()
Definition: fereadl.c:724
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:712
int m
Definition: cfEzgcd.cc:119
char ** fe_rl_readline_name
Definition: fereadl.c:717
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:723
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
void(* fe_add_history)()
Definition: fereadl.c:716
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:722
short fe_hist_pos
Definition: fereadl.c:74
char * fe_fgets_stdin_fe(char *pr, char *s, int size)
Definition: fereadl.c:375
static int fe_getchar()
Definition: fereadl.c:320
struct termios fe_saved_attributes
Definition: fereadl.c:62
int fe_init_dyn_rl()
Definition: fereadl.c:756
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:720
int colmax
Definition: febase.cc:43
char *(* fe_readline)()
Definition: fereadl.c:715
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:88
void fe_reset_input_mode()
Definition: fereadl.c:826
#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