My Project  UNKNOWN_GIT_VERSION
Macros | Functions | Variables
fevoices.cc File Reference
#include "kernel/mod2.h"
#include "omalloc/omalloc.h"
#include "misc/options.h"
#include "reporter/reporter.h"
#include "kernel/oswrapper/feread.h"
#include "Singular/fevoices.h"
#include "Singular/subexpr.h"
#include "Singular/ipshell.h"
#include "Singular/sdb.h"
#include "misc/mylimits.h"
#include <unistd.h>

Go to the source code of this file.

Macros

#define fePutChar(c)   fputc((unsigned char)(c),stdout)
 
#define MAX_FILE_BUFFER   4*4096
 
#define STDIN_FILENO   0
 

Functions

const char * VoiceName ()
 
void VoiceBackTrack ()
 
BOOLEAN newFile (char *fname)
 
void newBuffer (char *s, feBufferTypes t, procinfo *pi, int lineno)
 
BOOLEAN exitBuffer (feBufferTypes typ)
 
BOOLEAN contBuffer (feBufferTypes typ)
 
BOOLEAN exitVoice ()
 
static void feShowPrompt (void)
 
static int fePrintEcho (char *anf, char *)
 
int feReadLine (char *b, int l)
 
VoicefeInitStdin (Voice *pp)
 

Variables

char fe_promptstr [] =" "
 
FILE * File_Profiling =NULL
 
int blocknest
 
int yy_noeof =0
 
int yy_blocklineno
 
VoicecurrentVoice = NULL
 
const char sNoName_fe [] ="_"
 

Macro Definition Documentation

◆ fePutChar

#define fePutChar (   c)    fputc((unsigned char)(c),stdout)

Definition at line 29 of file fevoices.cc.

◆ MAX_FILE_BUFFER

#define MAX_FILE_BUFFER   4*4096

Definition at line 39 of file fevoices.cc.

◆ STDIN_FILENO

#define STDIN_FILENO   0

Definition at line 655 of file fevoices.cc.

Function Documentation

◆ contBuffer()

BOOLEAN contBuffer ( feBufferTypes  typ)

Definition at line 295 of file fevoices.cc.

296 {
297  //printf("contBuffer: %d(%s),(%x)\n",
298  // typ,BT_name[typ], currentVoice);
299  if (typ == BT_break) // valid inside for, while. may skip if, else
300  {
301  // first check for valid buffer type
303  loop
304  {
305  if ((p->typ != BT_if)
306  &&(p->typ != BT_else))
307  {
308  if (p->typ == BT_break /*typ*/)
309  {
310  while (p != currentVoice)
311  {
312  exitVoice();
313  }
315  currentVoice->fptr=0;
316  return FALSE;
317  }
318  else return TRUE;
319  }
320  if (p->prev==NULL) break;
321  p=p->prev;
322  }
323  }
324  return TRUE;
325 }

◆ exitBuffer()

BOOLEAN exitBuffer ( feBufferTypes  typ)

Definition at line 227 of file fevoices.cc.

228 {
229  //printf("exitBuffer: %d(%s),(%x)\n",
230  // typ,BT_name[typ], currentVoice);
231  //Voice *p=currentVoice;
232  //PrintS("-----------------\ncurr:");
233  //do
234  //{
235  //Print("voice fn:%s\n",p->filename);
236  //p=p->prev;
237  //}
238  //while (p!=NULL);
239  //PrintS("----------------\n");
240  if (typ == BT_break) // valid inside for, while. may skip if, else
241  {
242  /*4 first check for valid buffer type, skip if/else*/
244  loop
245  {
246  if ((p->typ != BT_if)
247  &&(p->typ != BT_else))
248  {
249  if (p->typ == BT_break /*typ*/)
250  {
251  while (p != currentVoice)
252  {
253  exitVoice();
254  }
255  exitVoice();
256  return FALSE;
257  }
258  else return TRUE;
259  }
260  if (p->prev==NULL) break;
261  p=p->prev;
262  }
263  /*4 break not inside a for/while: return an error*/
264  if (/*typ*/ BT_break != currentVoice->typ) return 1;
265  return exitVoice();
266  }
267 
268  if ((typ == BT_proc)
269  || (typ == BT_example))
270  {
272  loop
273  {
274  if ((p->typ == BT_proc)
275  || (p->typ == BT_example))
276  {
277  while (p != currentVoice)
278  {
279  exitVoice();
280  }
281  exitVoice();
282  return FALSE;
283  }
284  if (p->prev==NULL) break;
285  p=p->prev;
286  }
287  }
288  /*4 return not inside a proc: return an error*/
289  return TRUE;
290 }

◆ exitVoice()

BOOLEAN exitVoice ( )

Definition at line 332 of file fevoices.cc.

333 {
334  //printf("exitVoice: %d(%s),(%x)\n",
335  // currentVoice->typ,BT_name[currentVoice->typ], currentVoice);
336  //{
337  //Voice *p=currentVoice;
338  //PrintS("-----------------\ncurr:");
339  //do
340  //{
341  //Print("voice fn:%s\n",p->filename);
342  //p=p->prev;
343  //}
344  //while (p!=NULL);
345  //PrintS("----------------\n");
346  //}
347  if (currentVoice!=NULL)
348  {
349  if (currentVoice->oldb!=NULL)
350  {
353  }
354  if (currentVoice->filename!=NULL)
355  {
358  }
359  if (currentVoice->buffer!=NULL)
360  {
363  }
364  if ((currentVoice->prev==NULL)
365  &&(currentVoice->sw==BI_file)
366  &&(currentVoice->files!=stdin))
367  {
369  }
370  if (currentVoice->prev!=NULL)
371  {
372  //printf("exitVoice typ %d(%s)\n",
373  // currentVoice->typ,BT_name[currentVoice->typ]);
374  if (currentVoice->typ==BT_if)
375  {
376  currentVoice->prev->ifsw=2;
377  }
378  else
379  {
380  currentVoice->prev->ifsw=0;
381  }
382  if ((currentVoice->sw == BI_file)
383  && (currentVoice->files!=NULL))
384  {
385  fclose(currentVoice->files);
386  }
389  }
391  delete currentVoice;
392  currentVoice=p;
393  }
394  return currentVoice==NULL;
395 }

◆ feInitStdin()

Voice* feInitStdin ( Voice pp)

Definition at line 656 of file fevoices.cc.

657 {
658  Voice *p = new Voice;
659  p->files = stdin;
660  p->sw = (isatty(STDIN_FILENO)) ? BI_stdin : BI_file;
661  if ((pp!=NULL) && (pp->sw==BI_stdin) && (pp->files==stdin))
662  {
663  p->files=freopen("/dev/tty","r",stdin);
664  //stdin=p->files;
665  if (p->files==NULL)
666  {
667  p->files = stdin;
668  p->sw = BI_file;
669  }
670  else
671  p->sw = BI_stdin;
672  }
673  p->filename = omStrDup("STDIN");
674  p->start_lineno = 1;
676  omMarkAsStaticAddr(p->filename);
677  return p;
678 }

◆ fePrintEcho()

static int fePrintEcho ( char *  anf,
char *   
)
static

Definition at line 409 of file fevoices.cc.

410 {
411  char *ss=strrchr(anf,'\n');
412  int len_s;
413  if (ss==NULL)
414  {
415  len_s=strlen(anf);
416  }
417  else
418  {
419  len_s=ss-anf+1;
420  }
421  // my_yylinebuf:
422  int mrc=si_min(len_s,79)-1;
423  strcpy(my_yylinebuf,anf+(len_s-1)-mrc);
424  if (my_yylinebuf[mrc] == '\n') my_yylinebuf[mrc] = '\0';
425  mrc--;
426  // handle echo:
427  if (((si_echo>myynest)
428  && ((currentVoice->typ==BT_proc)
430  || (currentVoice->typ==BT_file)
431  || (currentVoice->typ==BT_none)
432  )
433  && (strncmp(anf,";return();",10)!=0)
434  )
437  {
439  {
440  if (currentVoice->filename==NULL)
441  Print("(none) %3d%c ",yylineno,prompt_char);
442  else
444  }
445  {
446  fwrite(anf,1,len_s,stdout);
447  mflush();
448  }
450  {
451  while(fgetc(stdin)!='\n');
452  }
453  }
454  else if (traceit&TRACE_SHOW_LINENO)
455  {
456  Print("{%d}",yylineno);
457  mflush();
458  }
459  else if (traceit&TRACE_PROFILING)
460  {
461  if (File_Profiling==NULL)
462  File_Profiling=fopen("smon.out","a");
463  if (File_Profiling==NULL)
464  traceit &= (~TRACE_PROFILING);
465  else
466  {
467  if (currentVoice->filename==NULL)
468  fprintf(File_Profiling,"(none) %d\n",yylineno);
469  else
470  fprintf(File_Profiling,"%s %d\n",currentVoice->filename,yylineno);
471  }
472  }
473 #ifdef HAVE_SDB
474  if ((blocknest==0)
475  && (currentVoice->pi!=NULL)
476  && (currentVoice->pi->trace_flag!=0))
477  {
478  sdb(currentVoice, anf, len_s);
479  }
480 #endif
481  prompt_char = '.';
482  return len_s;
483 }

◆ feReadLine()

int feReadLine ( char *  b,
int  l 
)

Definition at line 485 of file fevoices.cc.

486 {
487  char *s=NULL;
488  int offset = 0; /* will not be used if s==NULL*/
489  // try to read from the buffer into b, max l chars
490  if (currentVoice!=NULL)
491  {
492  if((currentVoice->buffer!=NULL)
493  && (currentVoice->buffer[currentVoice->fptr]!='\0'))
494  {
495  NewBuff:
496  REGISTER int i=0;
497  long startfptr=currentVoice->fptr;
498  long tmp_ptr=currentVoice->fptr;
499  l--;
500  loop
501  {
502  REGISTER char c=
503  b[i]=currentVoice->buffer[tmp_ptr/*currentVoice->fptr*/];
504  i++;
505  if (yy_noeof==noeof_block)
506  {
507  if (c<' ') yylineno++;
508  else if (c=='}') break;
509  }
510  else
511  {
512  if ((c<' ') ||
513  (c==';') ||
514  (c==')')
515  )
516  break;
517  }
518  if (i>=l) break;
519  tmp_ptr++;/*currentVoice->fptr++;*/
520  if(currentVoice->buffer[tmp_ptr/*currentVoice->fptr*/]=='\0') break;
521  }
522  currentVoice->fptr=tmp_ptr;
523  b[i]='\0';
524  if (currentVoice->sw==BI_buffer)
525  {
526  BOOLEAN show_echo=FALSE;
527  char *anf;
528  long len;
529  if (startfptr==0)
530  {
531  anf=currentVoice->buffer;
532  const char *ss=strchr(anf,'\n');
533  if (ss==NULL) len=strlen(anf);
534  else len=ss-anf;
535  show_echo=TRUE;
536  }
537  else if (/*(startfptr>0) &&*/
538  (currentVoice->buffer[startfptr-1]=='\n'))
539  {
540  anf=currentVoice->buffer+startfptr;
541  const char *ss=strchr(anf,'\n');
542  if (ss==NULL) len=strlen(anf);
543  else len=ss-anf;
544  yylineno++;
545  show_echo=TRUE;
546  }
547  if (show_echo)
548  {
549  char *s=(char *)omAlloc(len+2);
550  strncpy(s,anf,len+2);
551  s[len+1]='\0';
552  fePrintEcho(s,b);
553  omFree((ADDRESS)s);
554  }
555  }
556  currentVoice->fptr++;
557  return i;
558  }
559  // no buffer there or e-o-buffer or eoln:
560  if (currentVoice->sw!=BI_buffer)
561  {
562  currentVoice->fptr=0;
563  if (currentVoice->buffer==NULL)
564  {
567  }
568  }
569  offset=0;
570  NewRead:
571  yylineno++;
572  if (currentVoice->sw==BI_stdin)
573  {
574  feShowPrompt();
578  //int i=0;
579  //if (s!=NULL)
580  // while((s[i]!='\0') /*&& (i<MAX_FILE_BUFFER)*/) {s[i] &= (char)127;i++;}
581  }
582  else if (currentVoice->sw==BI_file)
583  {
587  if (s!=NULL)
588  {
590  // ftell returns -1 for non-seekable streams, such as pipes
591  if (currentVoice->ftellptr<0)
593  }
594  }
595  //else /* BI_buffer */ s==NULL => return 0
596  // done by the default return
597  }
598  if (s!=NULL)
599  {
600  // handle prot:
601  if (feProt&SI_PROT_I)
602  {
603  fputs(s,feProtFile);
604  }
605  int rc=fePrintEcho(s,b)+1;
606  //s[strlen(s)+1]='\0'; add an second \0 at the end of the string
607  s[rc]='\0';
608  // handel \\ :
609  rc-=3; if (rc<0) rc=0;
610  if ((s[rc]=='\\')&&(currentVoice->sw!=BI_buffer))
611  {
612  s[rc]='\0';
613  offset+=rc;
614  if (offset<(int)omSizeOfAddr(currentVoice->buffer)) goto NewRead;
615  }
616  goto NewBuff;
617  }
618  /* else if (s==NULL) */
619  {
620  const char *err;
621  switch(yy_noeof)
622  {
623  case noeof_brace:
624  case noeof_block:
625  err="{...}";
626  break;
627  case noeof_asstring:
628  err="till `.`";
629  break;
630  case noeof_string:
631  err="string";
632  break;
633  case noeof_bracket:
634  err="(...)";
635  break;
636  case noeof_procname:
637  err="proc";
638  break;
639  case noeof_comment:
640  err="/*...*/";
641  break;
642  default:
643  return 0;
644  }
645  Werror("premature end of file while reading %s",err);
646  return 0;
647  }
648 }

◆ feShowPrompt()

static void feShowPrompt ( void  )
static

Definition at line 401 of file fevoices.cc.

402 {
404 }

◆ newBuffer()

void newBuffer ( char *  s,
feBufferTypes  t,
procinfo pi,
int  lineno 
)

Definition at line 157 of file fevoices.cc.

158 {
159  currentVoice->Next();
160  //Print(":Buffer%d(%s):%s(%x)\n",
161  // t,BT_name[t],pname,currentVoice);
162  if (pi!=NULL)
163  {
164  long l=strlen(pi->procname);
165  if (pi->libname!=NULL) l+=strlen(pi->libname);
166  currentVoice->filename = (char *)omAlloc(l+3);
167  *currentVoice->filename='\0';
168  if (pi->libname!=NULL) strcat(currentVoice->filename,pi->libname);
169  strcat(currentVoice->filename,"::");
170  strcat(currentVoice->filename,pi->procname);
171  currentVoice->pi = pi;
172  }
173  else
174  {
175  if(currentVoice->prev!=NULL)
176  {
179  }
180  else
181  {
183  currentVoice->pi = pi;
184  }
185  }
186  currentVoice->buffer = s;
188  currentVoice->typ = t;
189  switch (t)
190  {
191  case BT_execute:
192  yylineno-=2;
193  break;
194  case BT_proc:
195  case BT_example:
197  yylineno = lineno+1;
198  break;
199  case BT_if:
200  case BT_else:
201  case BT_break:
203  break;
204  //case BT_file:
205  default:
206  yylineno = 1;
207  break;
208  }
209  //Print("start body (%s) at line %d\n",BT_name[t],yylineno);
211  //printf("start buffer typ %d\n",t);
212  //Voice *p=currentVoice;
213  //PrintS("-----------------\ncurr:");
214  //do
215  //{
216  //Print("voice fn:%s\n",p->filename);
217  //p=p->prev;
218  //}
219  //while (p!=NULL);
220  //PrintS("----------------\n");
221 }

◆ newFile()

BOOLEAN newFile ( char *  fname)

Definition at line 120 of file fevoices.cc.

121 {
122  currentVoice->Next();
123  //Print(":File%d(%s):%s(%x)\n",
124  // currentVoice->typ,BT_name[currentVoice->typ],fname,currentVoice);
125  currentVoice->filename = omStrDup(fname);
127  if (strcmp(fname,"STDIN") == 0)
128  {
129  currentVoice->files = stdin;
132  }
133  else
134  {
135  currentVoice->sw = BI_file; /* needed by exitVoice below */
136  currentVoice->files = feFopen(fname,"r",NULL,TRUE);
137  if (currentVoice->files==NULL)
138  {
139  exitVoice();
140  return TRUE;
141  }
143  }
145  //Voice *p=currentVoice;
146  //PrintS("-----------------\ncurr:");
147  //do
148  //{
149  //Print("voice fn:%s\n",p->filename);
150  //p=p->prev;
151  //}
152  //while (p!=NULL);
153  //PrintS("----------------\n");
154  return FALSE;
155 }

◆ VoiceBackTrack()

void VoiceBackTrack ( )

Definition at line 68 of file fevoices.cc.

69 {
71  while (p->prev!=NULL)
72  {
73  p=p->prev;
74  char *s=p->filename;
75  if (s==NULL)
76  PrintS("-- called from ? --\n");
77  else
78  Print("-- called from %s --\n",s);
79  }
80 }

◆ VoiceName()

const char* VoiceName ( )

Definition at line 57 of file fevoices.cc.

58 {
59  if ((currentVoice!=NULL)
60  && (currentVoice->filename!=NULL))
61  return currentVoice->filename;
62  return sNoName_fe;
63 }

Variable Documentation

◆ blocknest

int blocknest

Definition at line 581 of file scanner.cc.

◆ currentVoice

Voice* currentVoice = NULL

Definition at line 48 of file fevoices.cc.

◆ fe_promptstr

char fe_promptstr[] =" "

Definition at line 32 of file fevoices.cc.

◆ File_Profiling

FILE* File_Profiling =NULL

Definition at line 33 of file fevoices.cc.

◆ sNoName_fe

const char sNoName_fe[] ="_"

Definition at line 56 of file fevoices.cc.

◆ yy_blocklineno

int yy_blocklineno

Definition at line 47 of file fevoices.cc.

◆ yy_noeof

int yy_noeof =0

Definition at line 46 of file fevoices.cc.

yy_noeof
int yy_noeof
Definition: fevoices.cc:46
si_min
static int si_min(const int a, const int b)
Definition: auxiliary.h:139
feProtFile
FILE * feProtFile
Definition: reporter.cc:57
FALSE
#define FALSE
Definition: auxiliary.h:94
MAX_FILE_BUFFER
#define MAX_FILE_BUFFER
Definition: fevoices.cc:38
si_echo
int si_echo
Definition: febase.cc:35
REGISTER
#define REGISTER
Definition: omalloc.h:22
SEEK_SET
#define SEEK_SET
Definition: mod2.h:116
Voice::buffer
char * buffer
Definition: fevoices.h:69
noeof_asstring
@ noeof_asstring
Definition: fevoices.h:37
feFopen
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
omSizeOfAddr
size_t omSizeOfAddr(const void *addr)
Definition: omAllocSystem.c:100
BT_none
@ BT_none
Definition: fevoices.h:20
Voice::Next
void Next()
Definition: fevoices.cc:85
procinfo::trace_flag
char trace_flag
Definition: subexpr.h:62
BT_execute
@ BT_execute
Definition: fevoices.h:25
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
noeof_procname
@ noeof_procname
Definition: fevoices.h:41
exitVoice
BOOLEAN exitVoice()
Definition: fevoices.cc:332
BT_proc
@ BT_proc
Definition: fevoices.h:22
Voice::curr_lineno
int curr_lineno
Definition: fevoices.h:75
BT_file
@ BT_file
Definition: fevoices.h:24
TRACE_SHOW_LINE1
#define TRACE_SHOW_LINE1
Definition: reporter.h:37
yylineno
int yylineno
Definition: febase.cc:40
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:263
Voice::filename
char * filename
Definition: fevoices.h:63
Voice::ifsw
char ifsw
Definition: fevoices.h:79
noeof_bracket
@ noeof_bracket
Definition: fevoices.h:39
File_Profiling
FILE * File_Profiling
Definition: fevoices.cc:33
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:34
loop
#define loop
Definition: structs.h:78
b
CanonicalForm b
Definition: cfModGcd.cc:4044
BT_example
@ BT_example
Definition: fevoices.h:23
myynewbuffer
void * myynewbuffer()
Definition: scanner.cc:2316
pi
#define pi
Definition: libparse.cc:1143
STDIN_FILENO
#define STDIN_FILENO
Definition: fevoices.cc:654
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
BT_else
@ BT_else
Definition: fevoices.h:27
BI_buffer
@ BI_buffer
Definition: fevoices.h:31
PrintS
void PrintS(const char *s)
Definition: reporter.cc:284
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
blocknest
int blocknest
Definition: scanner.cc:581
Voice::pi
procinfo * pi
Definition: fevoices.h:64
sNoName_fe
const char sNoName_fe[]
Definition: fevoices.cc:56
Voice::typ
feBufferTypes typ
Definition: fevoices.h:84
currentVoice
Voice * currentVoice
Definition: fevoices.cc:48
TRACE_SHOW_LINENO
#define TRACE_SHOW_LINENO
Definition: reporter.h:30
sdb
void sdb(Voice *currentVoice, const char *currLine, int len)
Definition: sdb.cc:201
Voice::next
Voice * next
Definition: fevoices.h:61
Voice::prev
Voice * prev
Definition: fevoices.h:62
feShowPrompt
static void feShowPrompt(void)
Definition: fevoices.cc:401
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
BI_stdin
@ BI_stdin
Definition: fevoices.h:30
Voice::start_lineno
int start_lineno
Definition: fevoices.h:74
yy_blocklineno
int yy_blocklineno
Definition: fevoices.cc:47
BT_break
@ BT_break
Definition: fevoices.h:21
noeof_brace
@ noeof_brace
Definition: fevoices.h:36
myynest
int myynest
Definition: febase.cc:41
pp
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
noeof_block
@ noeof_block
Definition: fevoices.h:38
TRACE_PROFILING
#define TRACE_PROFILING
Definition: reporter.h:49
myyoldbuffer
void myyoldbuffer(void *oldb)
Definition: scanner.cc:2323
my_yylinebuf
char my_yylinebuf[80]
Definition: febase.cc:43
Voice::oldb
void * oldb
Definition: fevoices.h:65
feInitStdin
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:656
fe_promptstr
char fe_promptstr[]
Definition: fevoices.cc:32
SI_PROT_I
#define SI_PROT_I
Definition: reporter.h:52
Print
#define Print
Definition: emacs.cc:80
omMarkAsStaticAddr
void omMarkAsStaticAddr(void *addr)
Werror
void Werror(const char *fmt,...)
Definition: reporter.cc:189
Voice
Definition: fevoices.h:59
noeof_string
@ noeof_string
Definition: fevoices.h:42
Voice::files
FILE * files
Definition: fevoices.h:67
fePrintEcho
static int fePrintEcho(char *anf, char *)
Definition: fevoices.cc:409
NULL
#define NULL
Definition: omList.c:10
TRACE_SHOW_LINE
#define TRACE_SHOW_LINE
Definition: reporter.h:32
mflush
#define mflush()
Definition: reporter.h:57
l
int l
Definition: cfEzgcd.cc:93
traceit
int traceit
Definition: febase.cc:42
BT_if
@ BT_if
Definition: fevoices.h:26
p
int p
Definition: cfModGcd.cc:4019
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
offset
int offset
Definition: libparse.cc:1091
Voice::ftellptr
long ftellptr
Definition: fevoices.h:71
feProt
int feProt
Definition: reporter.cc:56
noeof_comment
@ noeof_comment
Definition: fevoices.h:40
prompt_char
char prompt_char
Definition: febase.cc:39
BI_file
@ BI_file
Definition: fevoices.h:32
Voice::fptr
long fptr
Definition: fevoices.h:70
Voice::sw
feBufferInputs sw
Definition: fevoices.h:76