My Project
Loading...
Searching...
No Matches
Macros | Typedefs | Functions | Variables
fereadl.c File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "kernel/oswrapper/feread.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 (void)
 

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

◆ feCTRL

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

Definition at line 58 of file fereadl.c.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 52 of file fereadl.c.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

Definition at line 55 of file fereadl.c.

Typedef Documentation

◆ CPPFunction

typedef char ** CPPFunction()

Definition at line 712 of file fereadl.c.

Function Documentation

◆ command_generator()

char * command_generator ( char *  text,
int  state 
)

Definition at line 52 of file feread.cc.

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

◆ fe_add_hist()

static void fe_add_hist ( char *  s)
static

Definition at line 277 of file fereadl.c.

278{
279 if (s[0]!='\0') /* skip empty lines */
280 {
281 /* compare this line*/
282 if (fe_hist_pos!=0)
283 {
284 if ((fe_hist[fe_hist_pos-1]!=NULL)
285 && (strcmp(fe_hist[fe_hist_pos-1],s)==0))
286 return;
287 }
288 else
289 {
290 if ((fe_hist[fe_hist_max-1]!=NULL)
291 && (strcmp(fe_hist[fe_hist_max-1],s)==0))
292 return;
293 }
294 /* normal case: enter a new line */
295 /* first free the slot at position fe_hist_pos */
297 {
299 }
300 /* and store a duplicate */
303 /* increment fe_hist_pos in a circular manner */
304 fe_hist_pos++;
306 }
307}
void * ADDRESS
Definition: auxiliary.h:119
const CanonicalForm int s
Definition: facAbsFact.cc:51
VAR char ** fe_hist
Definition: fereadl.c:70
#define fe_hist_max
Definition: fereadl.c:69
VAR short fe_hist_pos
Definition: fereadl.c:71
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omFree(addr)
Definition: omAllocDecl.h:261
#define omMarkAsStaticAddr(A)
Definition: xalloc.h:245

◆ fe_ctrl_k()

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

Definition at line 245 of file fereadl.c.

246{
247 int j=i;
248 while(s[j]!='\0')
249 {
250 fputc(' ',fe_echo);
251 j++;
252 }
253 while(j>i)
254 {
255 fputc('\b',fe_echo);
256 j--;
257 }
258}
int i
Definition: cfEzgcd.cc:132
int j
Definition: facHensel.cc:110
VAR FILE * fe_echo
Definition: fereadl.c:67

◆ fe_ctrl_u()

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

Definition at line 261 of file fereadl.c.

262{
263 fe_ctrl_k(s,*i);
264 while((*i)>0)
265 {
266 (*i)--;
267 fputc('\b',fe_echo);
268 fputc(' ',fe_echo);
269 fputc('\b',fe_echo);
270 }
271}
static void fe_ctrl_k(char *s, int i)
Definition: fereadl.c:245

◆ fe_fgets_stdin_fe()

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

Definition at line 382 of file fereadl.c.

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

310{
311 if (change)
312 fe_add_hist(s);
313 do
314 {
315 (*pos)+=incr;
316 if((*pos)>=fe_hist_max) (*pos)-=fe_hist_max;
317 else if((*pos)<0) (*pos)+=fe_hist_max;
318 }
319 while (((*pos)!=0)&&(fe_hist[(*pos)]==NULL));
320 memset(s,0,size);
321 if (fe_hist[(*pos)]!=NULL)
322 {
323 strncpy(s,fe_hist[(*pos)],size-2);
324 }
325}

◆ fe_getchar()

static int fe_getchar ( )
static

Definition at line 327 of file fereadl.c.

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

◆ fe_init()

static void fe_init ( void  )
static

Definition at line 140 of file fereadl.c.

141{
143 if ((!fe_use_fgets) && (isatty (STDIN_FILENO)))
144 {
145 /* Make sure stdin is a terminal. */
146 char *term=getenv("TERM");
147
148 /*setup echo*/
149 if(isatty(STDOUT_FILENO))
150 {
152 fe_echo=stdout;
153 }
154 else
155 {
157 char *tty_name=ttyname(fileno(stdin));
158 if (tty_name!=NULL)
159 fe_echo = fopen( tty_name, "w" );
160 else
161 fe_echo = NULL;
162 if (fe_echo==NULL)
163 {
164 fe_echo=stdout;
165 printf("stdin is a tty, but ttyname fails\n");
166 return;
167 }
168 }
169 /* Save the terminal attributes so we can restore them later. */
170 {
171 struct termios tattr;
172 tcgetattr (STDIN_FILENO, &fe_saved_attributes);
173 #ifdef HAVE_FEREAD
174 #ifdef HAVE_ATEXIT
175 atexit(fe_reset_fe);
176 #else
177 on_exit(fe_reset_fe,NULL);
178 #endif
179 #endif
180
181 /* Set the funny terminal modes. */
182 tcgetattr (STDIN_FILENO, &tattr);
183 tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
184 tattr.c_cc[VMIN] = 1;
185 tattr.c_cc[VTIME] = 0;
186 tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
187 /*ospeed=cfgetospeed(&tattr);*/
188 }
189 if(term==NULL)
190 {
191 printf("need TERM\n");
192 }
193 else if(tgetent(termcap_buff,term)<=0)
194 {
195 printf("could not access termcap data base\n");
196 }
197 else
198 {
199 #ifndef __CYGWIN__
200 EXTERN_VAR char *BC;
201 EXTERN_VAR char *UP;
202 EXTERN_VAR char PC;
203 #endif
204 /* OB: why this ? HS: char t_buf[128] does not work with glibc2 systems */
205 char *t_buf=(char *)omAlloc(128);
206 /*char t_buf[128];*/
207 char *temp;
208 char** t_buf_ptr= &t_buf;
209 /* Extract information that termcap functions use. */
210 temp = tgetstr ("pc", t_buf_ptr);
211 PC = (temp!=NULL) ? *temp : '\0';
212 BC=tgetstr("le",t_buf_ptr);
213 UP=tgetstr("up",t_buf_ptr);
214
215 /* Extract information we will use */
216 colmax=tgetnum("co");
217 pagelength=tgetnum("li");
219
220 /* init screen */
221 temp = tgetstr ("ti", t_buf_ptr);
222 #if 0
223 if (temp!=NULL) tputs(temp,1,fe_out_char);
224 #endif
225
226 /* printf("TERM=%s, co=%d, li=%d\n",term,colmax,pagelength);*/
227 }
228
231
232 /* setup history */
233 fe_hist=(char **)omAlloc0(fe_hist_max*sizeof(char *));
235 fe_hist_pos=0;
236 }
237 else
238 {
240 fe_echo=stdout;
241 }
242}
#define TRUE
Definition: auxiliary.h:100
Definition: int_poly.h:33
char * getenv()
VAR struct termios fe_saved_attributes
Definition: fereadl.c:60
VAR BOOLEAN fe_use_fgets
Definition: fereadl.c:64
void fe_reset_fe(void)
Definition: fereadl.c:83
#define STDOUT_FILENO
Definition: fereadl.c:55
STATIC_VAR BOOLEAN fe_stdout_is_tty
Definition: fereadl.c:62
STATIC_VAR char termcap_buff[2048]
Definition: fereadl.c:134
#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 756 of file fereadl.c.

757{
758 int res=0;
759 loop
760 {
761 fe_rl_hdl=dynl_open("libreadline.so");
762 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.2");
763 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.3");
764 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.4");
765 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.5");
766 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.6");
767 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.7");
768 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.8");
769 if (fe_rl_hdl==NULL) fe_rl_hdl=dynl_open("libreadline.so.9");
770 if (fe_rl_hdl==NULL) { return 1;}
771
773 dynl_sym(fe_rl_hdl, "filename_completion_function");
774 if (fe_filename_completion_function==NULL) { res=3; break; }
775 fe_readline=dynl_sym(fe_rl_hdl,"readline");
776 if (fe_readline==NULL) { res=4; break; }
777 fe_add_history=dynl_sym(fe_rl_hdl,"add_history");
778 if (fe_add_history==NULL) { res=5; break; }
779 fe_rl_readline_name=(char**)dynl_sym(fe_rl_hdl,"rl_readline_name");
780 if (fe_rl_readline_name==NULL) { res=6; break; }
781 fe_rl_line_buffer=(char**)dynl_sym(fe_rl_hdl,"rl_line_buffer");
782 if (fe_rl_line_buffer==NULL) { res=7; break; }
783 fe_completion_matches=dynl_sym(fe_rl_hdl,"completion_matches");
784 if (fe_completion_matches==NULL) { res=8; break; }
786 dynl_sym(fe_rl_hdl,"rl_attempted_completion_function");
788 fe_rl_outstream=(FILE**)dynl_sym(fe_rl_hdl,"rl_outstream");
789 if (fe_rl_outstream==NULL) { res=10; break; }
790 fe_write_history=dynl_sym(fe_rl_hdl,"write_history");
791 if (fe_write_history==NULL) { res=11; break; }
792 fe_history_total_bytes=dynl_sym(fe_rl_hdl,"history_total_bytes");
793 if (fe_history_total_bytes==NULL) { res=12; break; }
794 fe_using_history=dynl_sym(fe_rl_hdl,"using_history");
795 if (fe_using_history==NULL) { res=13; break; }
796 fe_read_history=dynl_sym(fe_rl_hdl,"read_history");
797 if (fe_read_history==NULL) { res=14; break; }
798 break;
799 }
801 if (res!=0) dynl_close(fe_rl_hdl);
802 else
803 {
804 char *p;
805 /* more init stuff: */
806 /* Allow conditional parsing of the ~/.inputrc file. */
807 (*fe_rl_readline_name) = "Singular";
808 /* Tell the completer that we want a crack first. */
809 (*fe_rl_attempted_completion_function) = (CPPFunction *)singular_completion;
810 /* try to read a history */
812 (*fe_using_history)();
813 p = getenv("SINGULARHIST");
815 if (strlen(p) != 0)
816 {
817 (*fe_read_history) (p);
818 }
819 }
820 return res;
821}
#define FALSE
Definition: auxiliary.h:96
int p
Definition: cfModGcd.cc:4078
CanonicalForm res
Definition: facAbsFact.cc:60
VAR BOOLEAN using_history_called
Definition: feread.cc:106
#define SINGULARHIST_FILE
Definition: feread.h:20
char ** CPPFunction()
Definition: fereadl.c:712
VAR char ** fe_rl_readline_name
Definition: fereadl.c:717
VAR char ** fe_rl_line_buffer
Definition: fereadl.c:718
char *(* fe_readline)()
Definition: fereadl.c:715
VAR int(* fe_read_history)()
Definition: fereadl.c:725
VAR void(* fe_add_history)()
Definition: fereadl.c:716
VAR int(* fe_write_history)()
Definition: fereadl.c:722
VAR void(* fe_using_history)()
Definition: fereadl.c:724
VAR CPPFunction ** fe_rl_attempted_completion_function
Definition: fereadl.c:720
VAR int(* fe_history_total_bytes)()
Definition: fereadl.c:723
char ** singular_completion(char *text, int start, int end)
Definition: fereadl.c:736
char **(* fe_completion_matches)()
Definition: fereadl.c:719
VAR void * fe_rl_hdl
Definition: fereadl.c:727
char *(* fe_filename_completion_function)()
Definition: fereadl.c:714
VAR FILE ** fe_rl_outstream
Definition: fereadl.c:721
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 135 of file fereadl.c.

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

◆ fe_reset_fe()

void fe_reset_fe ( void  )

Definition at line 83 of file fereadl.c.

86{
88 {
89 int i;
90 if (fe_is_raw_tty)
91 {
92 tcsetattr (STDIN_FILENO, TCSANOW, &fe_saved_attributes);
94 }
95 if (fe_hist!=NULL)
96 {
97 for(i=fe_hist_max-1;i>=0;i--)
98 {
99 if (fe_hist[i] != NULL) omFree((ADDRESS)fe_hist[i]);
100 }
101 omFreeSize((ADDRESS)fe_hist,fe_hist_max*sizeof(char *));
103 }
104 if (!fe_stdout_is_tty)
105 {
106 fclose(fe_echo);
107 }
108 }
109}
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

◆ fe_reset_input_mode()

void fe_reset_input_mode ( void  )

Definition at line 831 of file fereadl.c.

832{
833#if defined(HAVE_DYN_RL)
834 char *p = getenv("SINGULARHIST");
836 if ((strlen(p) != 0) && (fe_history_total_bytes != NULL))
837 {
839 (*fe_write_history) (p);
840 }
841#elif defined(HAVE_READLINE) && !defined(HAVE_FEREAD) && !defined(HAVE_DYN_RL)
842 char *p = getenv("SINGULARHIST");
844 if (strlen(p) != 0)
845 {
848 }
849#elif defined(HAVE_FEREAD)
850 #ifndef HAVE_ATEXIT
852 #else
853 fe_reset_fe();
854 #endif
855#endif
856}
int history_total_bytes()
int write_history()

◆ fe_set_cursor()

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

Definition at line 361 of file fereadl.c.

362{
363 char tgoto_buf[40];
364 if (0)/*(fe_cursor_pos>1) && (i>0))*/
365 {
366 /*fputs(tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),fe_echo);*/
367 tputs(
368 tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos-1,fe_cursor_line),
370 fputc(s[i-1],fe_echo);
371 }
372 else
373 {
374 /*fputs(
375 tgoto(tgetstr("cm",&tgoto_buf),fe_cursor_pos,fe_cursor_line),fe_echo);*/
376 tputs(tgoto(tgetstr("cm",(char **)&tgoto_buf),fe_cursor_pos,fe_cursor_line),
378 }
379 fflush(fe_echo);
380}

◆ fe_temp_reset()

void fe_temp_reset ( void  )

Definition at line 110 of file fereadl.c.

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

◆ fe_temp_set()

void fe_temp_set ( void  )

Definition at line 118 of file fereadl.c.

119{
120 if(fe_is_raw_tty==0)
121 {
122 struct termios tattr;
123
124 /* Set the funny terminal modes. */
125 tcgetattr (STDIN_FILENO, &tattr);
126 tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */
127 tattr.c_cc[VMIN] = 1;
128 tattr.c_cc[VTIME] = 0;
129 tcsetattr (STDIN_FILENO, TCSAFLUSH, &tattr);
131 }
132}

◆ singular_completion()

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

Definition at line 736 of file fereadl.c.

737{
738 /* If this word is not in a string, then it may be a command
739 to complete. Otherwise it may be the name of a file in the current
740 directory. */
741 char **m;
742 if ((*fe_rl_line_buffer)[start-1]=='"')
744 m=(*fe_completion_matches) (text, command_generator);
745 if (m==NULL)
746 {
747 m=(char **)malloc(2*sizeof(char*));
748 m[0]=(char *)malloc(end-start+2);
749 strncpy(m[0],text,end-start+1);
750 m[1]=NULL;
751 }
752 return m;
753}
int m
Definition: cfEzgcd.cc:128
char * command_generator(char *text, int state)
Definition: feread.cc:52
#define malloc
Definition: omAllocFunc.c:12

Variable Documentation

◆ fe_add_history

VAR void(* fe_add_history) () ( )

Definition at line 716 of file fereadl.c.

◆ fe_completion_matches

char **(* fe_completion_matches) () ( )

Definition at line 719 of file fereadl.c.

◆ fe_cursor_line

VAR short fe_cursor_line

Definition at line 74 of file fereadl.c.

◆ fe_cursor_pos

VAR short fe_cursor_pos

Definition at line 73 of file fereadl.c.

◆ fe_echo

VAR FILE* fe_echo

Definition at line 67 of file fereadl.c.

◆ fe_filename_completion_function

char *(* fe_filename_completion_function) () ( )

Definition at line 714 of file fereadl.c.

◆ fe_hist

VAR char** fe_hist =NULL

Definition at line 70 of file fereadl.c.

◆ fe_hist_pos

VAR short fe_hist_pos

Definition at line 71 of file fereadl.c.

◆ fe_history_total_bytes

VAR int(* fe_history_total_bytes) () ( )

Definition at line 723 of file fereadl.c.

◆ fe_is_initialized

STATIC_VAR BOOLEAN fe_is_initialized =FALSE

Definition at line 65 of file fereadl.c.

◆ fe_is_raw_tty

VAR BOOLEAN fe_is_raw_tty =0

Definition at line 72 of file fereadl.c.

◆ fe_read_history

VAR int(* fe_read_history) () ( )

Definition at line 725 of file fereadl.c.

◆ fe_readline

char *(* fe_readline) () ( )

Definition at line 715 of file fereadl.c.

◆ fe_rl_attempted_completion_function

VAR CPPFunction** fe_rl_attempted_completion_function

Definition at line 720 of file fereadl.c.

◆ fe_rl_hdl

VAR void* fe_rl_hdl =NULL

Definition at line 727 of file fereadl.c.

◆ fe_rl_line_buffer

VAR char** fe_rl_line_buffer

Definition at line 718 of file fereadl.c.

◆ fe_rl_outstream

VAR FILE** fe_rl_outstream

Definition at line 721 of file fereadl.c.

◆ fe_rl_readline_name

VAR char** fe_rl_readline_name

Definition at line 717 of file fereadl.c.

◆ fe_saved_attributes

VAR struct termios fe_saved_attributes

Definition at line 60 of file fereadl.c.

◆ fe_stdin_is_tty

STATIC_VAR BOOLEAN fe_stdin_is_tty

Definition at line 63 of file fereadl.c.

◆ fe_stdout_is_tty

STATIC_VAR BOOLEAN fe_stdout_is_tty

Definition at line 62 of file fereadl.c.

◆ fe_use_fgets

VAR BOOLEAN fe_use_fgets =FALSE

Definition at line 64 of file fereadl.c.

◆ fe_using_history

VAR void(* fe_using_history) () ( )

Definition at line 724 of file fereadl.c.

◆ fe_write_history

VAR int(* fe_write_history) () ( )

Definition at line 722 of file fereadl.c.

◆ termcap_buff

STATIC_VAR char termcap_buff[2048]

Definition at line 134 of file fereadl.c.