My Project
Macros | Typedefs | Functions | Variables
fereadl.c File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <string.h>
#include "kernel/mod_raw.h"

Go to the source code of this file.

Macros

#define STDIN_FILENO   0
 
#define STDOUT_FILENO   1
 
#define feCTRL(C)   ((C) & 0x1F) /* <ctrl> character */
 
#define fe_hist_max   32
 

Typedefs

typedef char ** CPPFunction()
 

Functions

void fe_reset_fe (void)
 
void fe_temp_reset (void)
 
void fe_temp_set (void)
 
static int fe_out_char (int c)
 
static void fe_init (void)
 
static void fe_ctrl_k (char *s, int i)
 
static void fe_ctrl_u (char *s, int *i)
 
static void fe_add_hist (char *s)
 
static void fe_get_hist (char *s, int size, int *pos, int change, int incr)
 
static int fe_getchar ()
 
static void fe_set_cursor (char *s, int i)
 
char * fe_fgets_stdin_fe (char *pr, char *s, int size)
 
char * command_generator (char *text, int state)
 
char ** singular_completion (char *text, int start, int end)
 
int fe_init_dyn_rl ()
 
void fe_reset_input_mode ()
 

Variables

VAR struct termios fe_saved_attributes
 
STATIC_VAR BOOLEAN fe_stdout_is_tty
 
STATIC_VAR BOOLEAN fe_stdin_is_tty
 
VAR BOOLEAN fe_use_fgets =FALSE
 
STATIC_VAR BOOLEAN fe_is_initialized =FALSE
 
VAR FILE * fe_echo
 
VAR char ** fe_hist =NULL
 
VAR short fe_hist_pos
 
VAR BOOLEAN fe_is_raw_tty =0
 
VAR short fe_cursor_pos
 
VAR short fe_cursor_line
 
STATIC_VAR char termcap_buff [2048]
 
char *(* fe_filename_completion_function )()
 
char *(* fe_readline )()
 
VAR void(* fe_add_history )()
 
VAR char ** fe_rl_readline_name
 
VAR char ** fe_rl_line_buffer
 
char **(* fe_completion_matches )()
 
VAR CPPFunction ** fe_rl_attempted_completion_function
 
VAR FILE ** fe_rl_outstream
 
VAR int(* fe_write_history )()
 
VAR int(* fe_history_total_bytes )()
 
VAR void(* fe_using_history )()
 
VAR int(* fe_read_history )()
 
VAR void * fe_rl_hdl =NULL
 

Macro Definition Documentation

◆ fe_hist_max

#define fe_hist_max   32

Definition at line 68 of file fereadl.c.

◆ feCTRL

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

Definition at line 57 of file fereadl.c.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 51 of file fereadl.c.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

Definition at line 54 of file fereadl.c.

Typedef Documentation

◆ CPPFunction

typedef char ** CPPFunction()

Definition at line 711 of file fereadl.c.

Function Documentation

◆ command_generator()

char * command_generator ( char *  text,
int  state 
)

Definition at line 50 of file feread.cc.

51{
52 STATIC_VAR int list_index, len;
54 const char *name;
55
56 /* If this is a new word to complete, initialize now. This includes
57 saving the length of TEXT for efficiency, and initializing the index
58 variable to 0. */
59 if (state==0)
60 {
61 list_index = 1;
62 len = strlen (text);
63 h=basePack->idroot;
64 }
65
66 /* Return the next name which partially matches from the command list. */
67 while ((name = iiArithGetCmd(list_index))!=NULL)
68 {
69 list_index++;
70
71 if (strncmp (name, text, len) == 0)
72 return (strdup(name));
73 }
74 if (len>1)
75 {
76 while (h!=NULL)
77 {
78 name=h->id;
79 h=h->next;
80 if (strncmp (name, text, len) == 0)
81 return (strdup(name));
82 }
83 }
84 /* If no names matched, then return NULL. */
85 return ((char *)NULL);
86}
Definition: idrec.h:35
char name(const Variable &v)
Definition: factory.h:189
char * iiArithGetCmd(int)
Definition: iparith.cc:9779
#define STATIC_VAR
Definition: globaldefs.h:7
VAR package basePack
Definition: ipid.cc:58
STATIC_VAR Poly * h
Definition: janet.cc:971
#define strdup
Definition: omAllocFunc.c:18
#define NULL
Definition: omList.c:12

◆ fe_add_hist()

static void fe_add_hist ( char *  s)
static

Definition at line 276 of file fereadl.c.

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 */
296 {
298 }
299 /* and store a duplicate */
302 /* increment fe_hist_pos in a circular manner */
303 fe_hist_pos++;
305 }
306}
void * ADDRESS
Definition: auxiliary.h:119
const CanonicalForm int s
Definition: facAbsFact.cc:51
VAR char ** fe_hist
Definition: fereadl.c:69
#define fe_hist_max
Definition: fereadl.c:68
VAR short fe_hist_pos
Definition: fereadl.c:70
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omFree(addr)
Definition: omAllocDecl.h:261
void omMarkAsStaticAddr(void *addr)

◆ fe_ctrl_k()

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

Definition at line 244 of file fereadl.c.

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}
int i
Definition: cfEzgcd.cc:132
int j
Definition: facHensel.cc:110
VAR FILE * fe_echo
Definition: fereadl.c:66

◆ fe_ctrl_u()

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

Definition at line 260 of file fereadl.c.

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}
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:244

◆ fe_fgets_stdin_fe()

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

Definition at line 381 of file fereadl.c.

382{
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)
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--;
444 if(fe_cursor_pos<0)
445 {
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 {
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;
495 }
496 i=0;
497 fe_cursor_pos=strlen(pr);
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++;
519 {
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);
534 if(fe_cursor_pos<0)
535 {
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++;
550 {
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);
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);
640 {
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 */
658 {
659 while(fe_cursor_pos+l>=colmax)
660 {
662 l-=colmax;
663 }
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}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
void select(const ListCFList &ppi, int length, ListCFList &ppi1, ListCFList &ppi2)
int l
Definition: cfEzgcd.cc:100
#define Print
Definition: emacs.cc:80
STATIC_VAR BOOLEAN fe_is_initialized
Definition: fereadl.c:64
static void fe_get_hist(char *s, int size, int *pos, int change, int incr)
Definition: fereadl.c:308
static int fe_out_char(int c)
Definition: fereadl.c:134
VAR short fe_cursor_line
Definition: fereadl.c:73
VAR short fe_cursor_pos
Definition: fereadl.c:72
#define feCTRL(C)
Definition: fereadl.c:57
static void fe_ctrl_u(char *s, int *i)
Definition: fereadl.c:260
VAR BOOLEAN fe_is_raw_tty
Definition: fereadl.c:71
void fe_temp_set(void)
Definition: fereadl.c:117
STATIC_VAR BOOLEAN fe_stdin_is_tty
Definition: fereadl.c:62
static void fe_init(void)
Definition: fereadl.c:139
static void fe_set_cursor(char *s, int i)
Definition: fereadl.c:360
static int fe_getchar()
Definition: fereadl.c:326
void fe_temp_reset(void)
Definition: fereadl.c:109
#define STDIN_FILENO
Definition: fereadl.c:51
static void fe_add_hist(char *s)
Definition: fereadl.c:276
void PrintS(const char *s)
Definition: reporter.cc:284
void PrintLn()
Definition: reporter.cc:310
EXTERN_VAR int pagelength
Definition: reporter.h:17
EXTERN_VAR int colmax
Definition: reporter.h:17
#define loop
Definition: structs.h:75

◆ fe_get_hist()

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

Definition at line 308 of file fereadl.c.

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}

◆ fe_getchar()

static int fe_getchar ( )
static

Definition at line 326 of file fereadl.c.

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}
int status read
Definition: si_signals.h:59

◆ fe_init()

static void fe_init ( void  )
static

Definition at line 139 of file fereadl.c.

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
230
231 /* setup history */
232 fe_hist=(char **)omAlloc0(fe_hist_max*sizeof(char *));
234 fe_hist_pos=0;
235 }
236 else
237 {
239 fe_echo=stdout;
240 }
241}
#define TRUE
Definition: auxiliary.h:100
Definition: int_poly.h:33
char * getenv()
VAR struct termios fe_saved_attributes
Definition: fereadl.c:59
VAR BOOLEAN fe_use_fgets
Definition: fereadl.c:63
void fe_reset_fe(void)
Definition: fereadl.c:82
#define STDOUT_FILENO
Definition: fereadl.c:54
STATIC_VAR BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:61
STATIC_VAR char termcap_buff[2048]
Definition: fereadl.c:133
#define EXTERN_VAR
Definition: globaldefs.h:6
#define ECHO
Definition: libparse.cc:1343
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ fe_init_dyn_rl()

int fe_init_dyn_rl ( )

Definition at line 755 of file fereadl.c.

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) fe_rl_hdl=dynl_open("libreadline.so.8");
768 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.9");
769 if (fe_rl_hdl==NULL) { return 1;}
770
772 dynl_sym(fe_rl_hdl, "filename_completion_function");
773 if (fe_filename_completion_function==NULL) { res=3; break; }
774 fe_readline=dynl_sym(fe_rl_hdl,"readline");
775 if (fe_readline==NULL) { res=4; break; }
776 fe_add_history=dynl_sym(fe_rl_hdl,"add_history");
777 if (fe_add_history==NULL) { res=5; break; }
778 fe_rl_readline_name=(char**)dynl_sym(fe_rl_hdl,"rl_readline_name");
779 if (fe_rl_readline_name==NULL) { res=6; break; }
780 fe_rl_line_buffer=(char**)dynl_sym(fe_rl_hdl,"rl_line_buffer");
781 if (fe_rl_line_buffer==NULL) { res=7; break; }
782 fe_completion_matches=dynl_sym(fe_rl_hdl,"completion_matches");
783 if (fe_completion_matches==NULL) { res=8; break; }
785 dynl_sym(fe_rl_hdl,"rl_attempted_completion_function");
787 fe_rl_outstream=(FILE**)dynl_sym(fe_rl_hdl,"rl_outstream");
788 if (fe_rl_outstream==NULL) { res=10; break; }
789 fe_write_history=dynl_sym(fe_rl_hdl,"write_history");
790 if (fe_write_history==NULL) { res=11; break; }
791 fe_history_total_bytes=dynl_sym(fe_rl_hdl,"history_total_bytes");
792 if (fe_history_total_bytes==NULL) { res=12; break; }
793 fe_using_history=dynl_sym(fe_rl_hdl,"using_history");
794 if (fe_using_history==NULL) { res=13; break; }
795 fe_read_history=dynl_sym(fe_rl_hdl,"read_history");
796 if (fe_read_history==NULL) { res=14; break; }
797 break;
798 }
799 if (res!=0) dynl_close(fe_rl_hdl);
800 else
801 {
802 char *p;
803 /* more init stuff: */
804 /* Allow conditional parsing of the ~/.inputrc file. */
805 (*fe_rl_readline_name) = "Singular";
806 /* Tell the completer that we want a crack first. */
807 (*fe_rl_attempted_completion_function) = (CPPFunction *)singular_completion;
808 /* try to read a history */
809 (*fe_using_history)();
810 p = getenv("SINGULARHIST");
811 if (p != NULL)
812 {
813 (*fe_read_history) (p);
814 }
815 }
816 return res;
817}
int p
Definition: cfModGcd.cc:4078
CanonicalForm res
Definition: facAbsFact.cc:60
char ** CPPFunction()
Definition: fereadl.c:711
VAR char ** fe_rl_readline_name
Definition: fereadl.c:716
VAR char ** fe_rl_line_buffer
Definition: fereadl.c:717
char *(* fe_readline)()
Definition: fereadl.c:714
VAR int(* fe_read_history)()
Definition: fereadl.c:724
VAR void(* fe_add_history)()
Definition: fereadl.c:715
VAR int(* fe_write_history)()
Definition: fereadl.c:721
VAR void(* fe_using_history)()
Definition: fereadl.c:723
VAR CPPFunction ** fe_rl_attempted_completion_function
Definition: fereadl.c:719
VAR int(* fe_history_total_bytes)()
Definition: fereadl.c:722
char ** singular_completion(char *text, int start, int end)
Definition: fereadl.c:735
char **(* fe_completion_matches)()
Definition: fereadl.c:718
VAR void * fe_rl_hdl
Definition: fereadl.c:726
char *(* fe_filename_completion_function)()
Definition: fereadl.c:713
VAR FILE ** fe_rl_outstream
Definition: fereadl.c:720
int dynl_close(void *handle)
Definition: mod_raw.cc:170
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:159
void * dynl_open(char *filename)
Definition: mod_raw.cc:142

◆ fe_out_char()

static int fe_out_char ( int  c)
static

Definition at line 134 of file fereadl.c.

135{
136 fputc(c,fe_echo);
137 return c;
138}

◆ fe_reset_fe()

void fe_reset_fe ( void  )

Definition at line 82 of file fereadl.c.

85{
87 {
88 int i;
89 if (fe_is_raw_tty)
90 {
91 tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
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 *));
102 }
103 if (!fe_stdout_is_tty)
104 {
105 fclose(fe_echo);
106 }
107 }
108}
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

◆ fe_reset_input_mode()

void fe_reset_input_mode ( )

Definition at line 827 of file fereadl.c.

828{
829#if defined(HAVE_DYN_RL)
830 char *p = getenv("SINGULARHIST");
831 if ((p != NULL) && (fe_history_total_bytes != NULL))
832 {
833 if((*fe_history_total_bytes)()!=0)
834 (*fe_write_history) (p);
835 }
836#endif
837#if defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
838 char *p = getenv("SINGULARHIST");
839 if (p != NULL)
840 {
841 if(history_total_bytes()!=0)
843 }
844#endif
845#if defined(HAVE_FEREAD)
846 #ifndef HAVE_ATEXIT
848 #else
849 fe_reset_fe();
850 #endif
851#endif
852}
int history_total_bytes()
int write_history()

◆ fe_set_cursor()

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

Definition at line 360 of file fereadl.c.

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}

◆ fe_temp_reset()

void fe_temp_reset ( void  )

Definition at line 109 of file fereadl.c.

110{
111 if (fe_is_raw_tty)
112 {
113 tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
115 }
116}

◆ fe_temp_set()

void fe_temp_set ( void  )

Definition at line 117 of file fereadl.c.

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);
130 }
131}

◆ singular_completion()

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

Definition at line 735 of file fereadl.c.

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}
int m
Definition: cfEzgcd.cc:128
char * command_generator(char *text, int state)
Definition: feread.cc:50
void * malloc(size_t size)
Definition: omalloc.c:85

Variable Documentation

◆ fe_add_history

VAR void(* fe_add_history) () ( )

Definition at line 715 of file fereadl.c.

◆ fe_completion_matches

char **(* fe_completion_matches) () ( )

Definition at line 718 of file fereadl.c.

◆ fe_cursor_line

VAR short fe_cursor_line

Definition at line 73 of file fereadl.c.

◆ fe_cursor_pos

VAR short fe_cursor_pos

Definition at line 72 of file fereadl.c.

◆ fe_echo

VAR FILE* fe_echo

Definition at line 66 of file fereadl.c.

◆ fe_filename_completion_function

char *(* fe_filename_completion_function) () ( )

Definition at line 713 of file fereadl.c.

◆ fe_hist

VAR char** fe_hist =NULL

Definition at line 69 of file fereadl.c.

◆ fe_hist_pos

VAR short fe_hist_pos

Definition at line 70 of file fereadl.c.

◆ fe_history_total_bytes

VAR int(* fe_history_total_bytes) () ( )

Definition at line 722 of file fereadl.c.

◆ fe_is_initialized

STATIC_VAR BOOLEAN fe_is_initialized =FALSE

Definition at line 64 of file fereadl.c.

◆ fe_is_raw_tty

VAR BOOLEAN fe_is_raw_tty =0

Definition at line 71 of file fereadl.c.

◆ fe_read_history

VAR int(* fe_read_history) () ( )

Definition at line 724 of file fereadl.c.

◆ fe_readline

char *(* fe_readline) () ( )

Definition at line 714 of file fereadl.c.

◆ fe_rl_attempted_completion_function

VAR CPPFunction** fe_rl_attempted_completion_function

Definition at line 719 of file fereadl.c.

◆ fe_rl_hdl

VAR void* fe_rl_hdl =NULL

Definition at line 726 of file fereadl.c.

◆ fe_rl_line_buffer

VAR char** fe_rl_line_buffer

Definition at line 717 of file fereadl.c.

◆ fe_rl_outstream

VAR FILE** fe_rl_outstream

Definition at line 720 of file fereadl.c.

◆ fe_rl_readline_name

VAR char** fe_rl_readline_name

Definition at line 716 of file fereadl.c.

◆ fe_saved_attributes

VAR struct termios fe_saved_attributes

Definition at line 59 of file fereadl.c.

◆ fe_stdin_is_tty

STATIC_VAR BOOLEAN fe_stdin_is_tty

Definition at line 62 of file fereadl.c.

◆ fe_stdout_is_tty

STATIC_VAR BOOLEAN fe_stdout_is_tty

Definition at line 61 of file fereadl.c.

◆ fe_use_fgets

VAR BOOLEAN fe_use_fgets =FALSE

Definition at line 63 of file fereadl.c.

◆ fe_using_history

VAR void(* fe_using_history) () ( )

Definition at line 723 of file fereadl.c.

◆ fe_write_history

VAR int(* fe_write_history) () ( )

Definition at line 721 of file fereadl.c.

◆ termcap_buff

STATIC_VAR char termcap_buff[2048]

Definition at line 133 of file fereadl.c.