Loading...
Searching...
No Matches
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)
#define | MAX_FILE_BUFFER 4*4096
#define | STDIN_FILENO 0

## Functions

const char * | VoiceName ()
int | VoiceLine ()
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)
Voice * | feInitStdin (Voice *pp)

## Variables

VAR char | fe_promptstr [] =" "
VAR FILE * | File_Profiling =NULL
VAR FILE * | File_Log =NULL
VAR BOOLEAN | File_Log_written =FALSE
EXTERN_VAR int | blocknest
VAR int | yy_noeof =0
VAR int | yy_blocklineno
VAR Voice * | currentVoice = NULL
const char | sNoName_fe [] ="_"

## Macro Definition Documentation

## fePutChar

#define fePutChar | ( |  | c | ) |

Value:
fputc((unsigned char)(c),stdout)

Definition at line 27 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 675 of file fevoices.cc.

## Function Documentation

## contBuffer()

BOOLEAN contBuffer | ( | feBufferTypes | typ | ) |

Definition at line 304 of file fevoices.cc.

{
//printf("contBuffer: %d(%s),(%x)\n",
// typ,BT_name[typ], currentVoice);
if (typ == BT_break) // valid inside for, while. may skip if, else
{
// first check for valid buffer type
Voice *p=currentVoice;
loop
{
if ((p->typ != BT_if)
&&(p->typ != BT_else))
{
if (p->typ == BT_break /*typ*/)
{
while (p != currentVoice)
{
exitVoice();
}
yylineno = currentVoice->start_lineno;
currentVoice->fptr=0;
return FALSE;
}
else return TRUE;
}
if (p->prev==NULL) break;
p=p->prev;
}
}
return TRUE;
}
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
p
int p
Definition cfModGcd.cc:4086
Voice
Definition fevoices.h:59
yylineno
VAR int yylineno
Definition febase.cc:40
currentVoice
VAR Voice * currentVoice
Definition fevoices.cc:49
exitVoice
BOOLEAN exitVoice()
Definition fevoices.cc:341
BT_else
@ BT_else
Definition fevoices.h:25
BT_if
@ BT_if
Definition fevoices.h:24
BT_break
@ BT_break
Definition fevoices.h:19
NULL
#define NULL
Definition omList.c:12
loop
#define loop
Definition structs.h:71

## exitBuffer()

BOOLEAN exitBuffer | ( | feBufferTypes | typ | ) |

Definition at line 236 of file fevoices.cc.

{
//printf("exitBuffer: %d(%s),(%x)\n",
// typ,BT_name[typ], currentVoice);
//Voice *p=currentVoice;
//PrintS("-----------------\ncurr:");
//do
//{
//Print("voice fn:%s\n",p->filename);
//p=p->prev;
//}
//while (p!=NULL);
//PrintS("----------------\n");
if (typ == BT_break) // valid inside for, while. may skip if, else
{
/*4 first check for valid buffer type, skip if/else*/
Voice *p=currentVoice;
loop
{
if ((p->typ != BT_if)
&&(p->typ != BT_else))
{
if (p->typ == BT_break /*typ*/)
{
while (p != currentVoice)
{
exitVoice();
}
exitVoice();
return FALSE;
}
else return TRUE;
}
if (p->prev==NULL) break;
p=p->prev;
}
/*4 break not inside a for/while: return an error*/
if (/*typ*/ BT_break != currentVoice->typ) return 1;
return exitVoice();
}
if ((typ == BT_proc)
|| (typ == BT_example))
{
Voice *p=currentVoice;
loop
{
if ((p->typ == BT_proc)
|| (p->typ == BT_example))
{
while (p != currentVoice)
{
exitVoice();
}
exitVoice();
return FALSE;
}
if (p->prev==NULL) break;
p=p->prev;
}
}
/*4 return not inside a proc: return an error*/
return TRUE;
}
BT_example
@ BT_example
Definition fevoices.h:21
BT_proc
@ BT_proc
Definition fevoices.h:20

## exitVoice()

BOOLEAN exitVoice | ( |  | ) |

Definition at line 341 of file fevoices.cc.

{
//printf("exitVoice: %d(%s),(%x)\n",
// currentVoice->typ,BT_name[currentVoice->typ], currentVoice);
//{
//Voice *p=currentVoice;
//PrintS("-----------------\ncurr:");
//do
//{
//Print("voice fn:%s\n",p->filename);
//p=p->prev;
//}
//while (p!=NULL);
//PrintS("----------------\n");
//}
if (currentVoice!=NULL)
{
if (currentVoice->oldb!=NULL)
{
myyoldbuffer(currentVoice->oldb);
currentVoice->oldb=NULL;
}
if (currentVoice->filename!=NULL)
{
omFree((ADDRESS)currentVoice->filename);
currentVoice->filename=NULL;
}
if (currentVoice->buffer!=NULL)
{
omFree((ADDRESS)currentVoice->buffer);
currentVoice->buffer=NULL;
}
if ((currentVoice->prev==NULL)
&&(currentVoice->sw==BI_file)
&&(currentVoice->files!=stdin))
{
currentVoice->prev=feInitStdin(currentVoice);
}
if (currentVoice->prev!=NULL)
{
//printf("exitVoice typ %d(%s)\n",
// currentVoice->typ,BT_name[currentVoice->typ]);
if (currentVoice->typ==BT_if)
{
currentVoice->prev->ifsw=2;
}
else
{
currentVoice->prev->ifsw=0;
}
if ((currentVoice->sw == BI_file)
&& (currentVoice->files!=NULL))
{
fclose(currentVoice->files);
}
yylineno=currentVoice->prev->curr_lineno;
currentVoice->prev->next=NULL;
}
Voice *p=currentVoice->prev;
delete currentVoice;
currentVoice=p;
}
return currentVoice==NULL;
}
ADDRESS
void * ADDRESS
Definition auxiliary.h:120
feInitStdin
Voice * feInitStdin(Voice *pp)
Definition fevoices.cc:677
BI_file
@ BI_file
Definition fevoices.h:32
myyoldbuffer
void myyoldbuffer(void *oldb)
Definition scanner.cc:2304
omFree
#define omFree(addr)
Definition omAllocDecl.h:261

## feInitStdin()

Voice * feInitStdin | ( | Voice * | pp | ) |

Definition at line 677 of file fevoices.cc.

{
Voice *p = new Voice;
p->files = stdin;
p->sw = (isatty(STDIN_FILENO)) ? BI_stdin : BI_file;
if ((pp!=NULL) && (pp->sw==BI_stdin) && (pp->files==stdin))
{
p->files=freopen("/dev/tty","r",stdin);
//stdin=p->files;
if (p->files==NULL)
{
p->files = stdin;
p->sw = BI_file;
}
else
p->sw = BI_stdin;
}
p->filename = omStrDup("STDIN");
p->start_lineno = 1;
omMarkAsStaticAddr(p);
omMarkAsStaticAddr(p->filename);
return p;
}
pp
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f ).
Definition cf_gcd.cc:676
STDIN_FILENO
#define STDIN_FILENO
Definition fereadl.c:52
BI_stdin
@ BI_stdin
Definition fevoices.h:30
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omMarkAsStaticAddr
#define omMarkAsStaticAddr(A)
Definition xalloc.h:245

## fePrintEcho()

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

static

Definition at line 418 of file fevoices.cc.

{
char *ss=strrchr(anf,'\n');
int len_s;
if (ss==NULL)
{
len_s=strlen(anf);
}
else
{
len_s=ss-anf+1;
}
// my_yylinebuf:
int mrc=si_min(len_s,79)-1;
strcpy(my_yylinebuf,anf+(len_s-1)-mrc);
if (my_yylinebuf[mrc] == '\n') my_yylinebuf[mrc] = '\0';
mrc--;
// handle echo:
if (((si_echo>myynest)
&& ((currentVoice->typ==BT_proc)
|| (currentVoice->typ==BT_example)
|| (currentVoice->typ==BT_file)
|| (currentVoice->typ==BT_none)
)
&& (strncmp(anf,";return();",10)!=0)
)
|| (traceit&TRACE_SHOW_LINE)
|| (traceit&TRACE_SHOW_LINE1))
{
if (currentVoice->typ!=BT_example)
{
if (currentVoice->filename==NULL)
Print("(none) %3d%c ",yylineno,prompt_char);
else
Print("%s %3d%c ",currentVoice->filename,yylineno,prompt_char);
}
{
fwrite(anf,1,len_s,stdout);
mflush();
}
if (traceit&TRACE_SHOW_LINE)
{
char c;
do
{
c=fgetc(stdin);
if (c=='n') traceit_stop=1;
}
while(c!='\n');
}
}
else if (traceit&TRACE_SHOW_LINENO)
{
Print("{%d}",yylineno);
mflush();
}
else if (traceit&TRACE_PROFILING)
{
if (File_Profiling==NULL)
File_Profiling=fopen("smon.out","a");
if (File_Profiling==NULL)
traceit &= (~TRACE_PROFILING);
else
{
if (currentVoice->filename==NULL)
fprintf(File_Profiling,"(none) %d\n",yylineno);
else
fprintf(File_Profiling,"%s %d\n",currentVoice->filename,yylineno);
}
}
#ifdef HAVE_SDB
if ((blocknest==0)
&& (currentVoice->pi!=NULL)
&& (currentVoice->pi->trace_flag!=0))
{
sdb(currentVoice, anf, len_s);
}
#endif
prompt_char = '.';
return len_s;
}
si_min
static int si_min(const int a, const int b)
Definition auxiliary.h:126
Print
#define Print
Definition emacs.cc:80
my_yylinebuf
VAR char my_yylinebuf[80]
Definition febase.cc:44
si_echo
VAR int si_echo
Definition febase.cc:35
myynest
VAR int myynest
Definition febase.cc:41
prompt_char
EXTERN_VAR char prompt_char
Definition feread.h:10
File_Profiling
VAR FILE * File_Profiling
Definition fevoices.cc:32
blocknest
EXTERN_VAR int blocknest
Definition fevoices.cc:45
BT_none
@ BT_none
Definition fevoices.h:18
BT_file
@ BT_file
Definition fevoices.h:22
TRACE_SHOW_LINENO
#define TRACE_SHOW_LINENO
Definition reporter.h:31
TRACE_SHOW_LINE
#define TRACE_SHOW_LINE
Definition reporter.h:33
traceit
EXTERN_VAR int traceit
Definition reporter.h:24
traceit_stop
EXTERN_VAR int traceit_stop
Definition reporter.h:25
TRACE_SHOW_LINE1
#define TRACE_SHOW_LINE1
Definition reporter.h:38
TRACE_PROFILING
#define TRACE_PROFILING
Definition reporter.h:50
mflush
#define mflush()
Definition reporter.h:58
sdb
void sdb(Voice *currentVoice, const char *currLine, int len)
Definition sdb.cc:210

## feReadLine()

int feReadLine | ( | char * | b,
|  | int | l )

Definition at line 500 of file fevoices.cc.

{
char *s=NULL;
int offset = 0; /* will not be used if s==NULL*/
// try to read from the buffer into b, max l chars
if (currentVoice!=NULL)
{
if((currentVoice->buffer!=NULL)
&& (currentVoice->buffer[currentVoice->fptr]!='\0'))
{
NewBuff:
REGISTER int i=0;
long startfptr=currentVoice->fptr;
long tmp_ptr=currentVoice->fptr;
l--;
loop
{
REGISTER char c=
b[i]=currentVoice->buffer[tmp_ptr/*currentVoice->fptr*/];
i++;
if (yy_noeof==noeof_block)
{
if (c<' ') yylineno++;
else if (c=='}') break;
}
else
{
if ((c<' ') ||
(c==';') ||
(c==')')
)
break;
}
if (i>=l) break;
tmp_ptr++;/*currentVoice->fptr++;*/
if(currentVoice->buffer[tmp_ptr/*currentVoice->fptr*/]=='\0') break;
}
currentVoice->fptr=tmp_ptr;
b[i]='\0';
if (currentVoice->sw==BI_buffer)
{
BOOLEAN show_echo=FALSE;
char *anf;
long len;
if (startfptr==0)
{
anf=currentVoice->buffer;
const char *ss=strchr(anf,'\n');
if (ss==NULL) len=strlen(anf);
else len=ss-anf;
show_echo=TRUE;
}
else if /*(startfptr>0) &&*/
(currentVoice->buffer[startfptr-1]=='\n')
{
anf=currentVoice->buffer+startfptr;
const char *ss=strchr(anf,'\n');
if (ss==NULL) len=strlen(anf);
else len=ss-anf;
yylineno++;
show_echo=TRUE;
}
if (show_echo)
{
char *s=(char *)omAlloc(len+2);
strncpy(s,anf,len+2);
s[len+1]='\0';
fePrintEcho(s,b);
omFree((ADDRESS)s);
}
}
currentVoice->fptr++;
return i;
}
// no buffer there or e-o-buffer or eoln:
if (currentVoice->sw!=BI_buffer)
{
currentVoice->fptr=0;
if (currentVoice->buffer==NULL)
{
currentVoice->buff_size=MAX_FILE_BUFFER-sizeof(ADDRESS);
currentVoice->buffer=(char *)omAlloc(currentVoice->buff_size);
omMarkAsStaticAddr(currentVoice->buffer);
}
}
offset=0;
NewRead:
yylineno++;
if (currentVoice->sw==BI_stdin)
{
feShowPrompt();
s=fe_fgets_stdin(fe_promptstr,
&(currentVoice->buffer[offset]),
currentVoice->buff_size-1-offset);
//int i=0;
//if (s!=NULL)
// while((s[i]!='\0') /*&& (i<MAX_FILE_BUFFER)*/) {s[i] &= (char)127;i++;}
}
else if (currentVoice->sw==BI_file)
{
fseek(currentVoice->files,currentVoice->ftellptr,SEEK_SET);
s=fgets(currentVoice->buffer+offset,(MAX_FILE_BUFFER-1-sizeof(ADDRESS))-offset,
currentVoice->files);
if (s!=NULL)
{
currentVoice->ftellptr=ftell(currentVoice->files);
// ftell returns -1 for non-seekable streams, such as pipes
if (currentVoice->ftellptr<0)
currentVoice->ftellptr=0;
}
}
//else /* BI_buffer */ s==NULL => return 0
// done by the default return
}
if (s!=NULL)
{
// handle prot:
if (feProt&SI_PROT_I)
{
fputs(s,feProtFile);
}
if (File_Log!=NULL)
{
File_Log_written=TRUE;
fputs(s,File_Log);
}
int rc=fePrintEcho(s,b)+1;
//s[strlen(s)+1]='\0'; add an second \0 at the end of the string
s[rc]='\0';
// handel \\ :
rc-=3; if (rc<0) rc=0;
if ((s[rc]=='\\')&&(currentVoice->sw!=BI_buffer))
{
s[rc]='\0';
offset+=rc;
if (offset<currentVoice->buff_size) goto NewRead;
}
goto NewBuff;
}
/* else if (s==NULL) */
{
const char *err;
switch(yy_noeof)
{
case noeof_brace:
case noeof_block:
err="{...}";
break;
case noeof_asstring:
err="till `.`";
break;
case noeof_string:
err="string";
break;
case noeof_bracket:
err="(...)";
break;
case noeof_procname:
err="proc";
break;
case noeof_comment:
err="/*...*/";
break;
default:
return 0;
}
Werror("premature end of file while reading %s",err);
return 0;
}
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
l
int l
Definition cfEzgcd.cc:100
i
int i
Definition cfEzgcd.cc:132
b
CanonicalForm b
Definition cfModGcd.cc:4111
s
const CanonicalForm int s
Definition facAbsFact.cc:51
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition feread.cc:32
fe_promptstr
VAR char fe_promptstr[]
Definition fevoices.cc:31
File_Log_written
VAR BOOLEAN File_Log_written
Definition fevoices.cc:34
File_Log
VAR FILE * File_Log
Definition fevoices.cc:33
fePrintEcho
static int fePrintEcho(char *anf, char *)
Definition fevoices.cc:418
feShowPrompt
static void feShowPrompt(void)
Definition fevoices.cc:410
BI_buffer
@ BI_buffer
Definition fevoices.h:31
noeof_string
@ noeof_string
Definition fevoices.h:42
noeof_brace
@ noeof_brace
Definition fevoices.h:36
noeof_comment
@ noeof_comment
Definition fevoices.h:40
noeof_asstring
@ noeof_asstring
Definition fevoices.h:37
noeof_block
@ noeof_block
Definition fevoices.h:38
noeof_procname
@ noeof_procname
Definition fevoices.h:41
noeof_bracket
@ noeof_bracket
Definition fevoices.h:39
offset
STATIC_VAR int offset
Definition janet.cc:29
SEEK_SET
#define SEEK_SET
Definition mod2.h:115
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
REGISTER
#define REGISTER
Definition omalloc.h:27
MAX_FILE_BUFFER
#define MAX_FILE_BUFFER
Definition reporter.cc:38
feProt
VAR int feProt
Definition reporter.cc:56
feProtFile
VAR FILE * feProtFile
Definition reporter.cc:57
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189
yy_noeof
EXTERN_VAR int yy_noeof
Definition reporter.h:19
SI_PROT_I
#define SI_PROT_I
Definition reporter.h:53

## feShowPrompt()

void feShowPrompt | ( | void |  | ) |

static

Definition at line 410 of file fevoices.cc.

{
fe_promptstr[0]=prompt_char;
}

## newBuffer()

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

Definition at line 166 of file fevoices.cc.

{
currentVoice->Next();
//Print(":Buffer%d(%s):%s(%x)\n",
// t,BT_name[t],pname,currentVoice);
if (pi!=NULL)
{
long l=strlen(pi->procname);
if (pi->libname!=NULL) l+=strlen(pi->libname);
currentVoice->filename = (char *)omAlloc(l+3);
*currentVoice->filename='\0';
if (pi->libname!=NULL) strcat(currentVoice->filename,pi->libname);
strcat(currentVoice->filename,"::");
strcat(currentVoice->filename,pi->procname);
currentVoice->pi = pi;
}
else
{
if(currentVoice->prev!=NULL)
{
currentVoice->filename = omStrDup(currentVoice->prev->filename);
currentVoice->pi = currentVoice->prev->pi;
}
else
{
currentVoice->filename = omStrDup("");
currentVoice->pi = pi;
}
}
currentVoice->buffer = s;
currentVoice->sw = BI_buffer;
currentVoice->typ = t;
switch (t)
{
case BT_execute:
yylineno-=2;
break;
case BT_proc:
case BT_example:
currentVoice->oldb=myynewbuffer();
yylineno = lineno+1;
break;
case BT_if:
case BT_else:
case BT_break:
yylineno = yy_blocklineno-1;
break;
//case BT_file:
default:
yylineno = 1;
break;
}
//Print("start body (%s) at line %d\n",BT_name[t],yylineno);
currentVoice->start_lineno = yylineno;
//printf("start buffer typ %d\n",t);
//Voice *p=currentVoice;
//PrintS("-----------------\ncurr:");
//do
//{
//Print("voice fn:%s\n",p->filename);
//p=p->prev;
//}
//while (p!=NULL);
//PrintS("----------------\n");
}
BT_execute
@ BT_execute
Definition fevoices.h:23
myynewbuffer
void * myynewbuffer()
Definition scanner.cc:2297
pi
#define pi
Definition libparse.cc:1145
yy_blocklineno
EXTERN_VAR int yy_blocklineno
Definition reporter.h:18

## newFile()

BOOLEAN newFile | ( | char * | fname | ) |

Definition at line 129 of file fevoices.cc.

{
currentVoice->Next();
//Print(":File%d(%s):%s(%x)\n",
// currentVoice->typ,BT_name[currentVoice->typ],fname,currentVoice);
currentVoice->filename = omStrDup(fname);
omMarkAsStaticAddr(currentVoice->filename);
if (strcmp(fname,"STDIN") == 0)
{
currentVoice->files = stdin;
currentVoice->sw = BI_stdin;
currentVoice->start_lineno = 1;
}
else
{
currentVoice->sw = BI_file; /* needed by exitVoice below */
currentVoice->files = feFopen(fname,"r",NULL,TRUE);
if (currentVoice->files==NULL)
{
exitVoice();
return TRUE;
}
currentVoice->start_lineno = 0;
}
yylineno=currentVoice->start_lineno;
//Voice *p=currentVoice;
//PrintS("-----------------\ncurr:");
//do
//{
//Print("voice fn:%s\n",p->filename);
//p=p->prev;
//}
//while (p!=NULL);
//PrintS("----------------\n");
return FALSE;
}
feFopen
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47

## VoiceBackTrack()

void VoiceBackTrack | ( |  | ) |

Definition at line 77 of file fevoices.cc.

{
Voice *p=currentVoice;
while (p->prev!=NULL)
{
p=p->prev;
char *s=p->filename;
if (s==NULL)
PrintS("-- called from ? --\n");
else
Print("-- called from %s:%d --\n",s, p->curr_lineno);
}
}
PrintS
void PrintS(const char *s)
Definition reporter.cc:288

## VoiceLine()

int VoiceLine | ( |  | ) |

Definition at line 66 of file fevoices.cc.

{
if ((currentVoice!=NULL)
&& (currentVoice->curr_lineno>=0))
return currentVoice->curr_lineno;
return -1;
}

## VoiceName()

const char * VoiceName | ( |  | ) |

Definition at line 58 of file fevoices.cc.

{
if ((currentVoice!=NULL)
&& (currentVoice->filename!=NULL))
return currentVoice->filename;
return sNoName_fe;
}
sNoName_fe
const char sNoName_fe[]
Definition fevoices.cc:57

## Variable Documentation

## blocknest

EXTERN_VAR int blocknest

Definition at line 45 of file fevoices.cc.

## currentVoice

VAR Voice* currentVoice = NULL

Definition at line 49 of file fevoices.cc.

## fe_promptstr

VAR char fe_promptstr[] =" "

Definition at line 31 of file fevoices.cc.

## File_Log

VAR FILE* File_Log =NULL

Definition at line 33 of file fevoices.cc.

## File_Log_written

VAR BOOLEAN File_Log_written =FALSE

Definition at line 34 of file fevoices.cc.

## File_Profiling

VAR FILE* File_Profiling =NULL

Definition at line 32 of file fevoices.cc.

## sNoName_fe

const char sNoName_fe[] ="_"

Definition at line 57 of file fevoices.cc.

## yy_blocklineno

VAR int yy_blocklineno

Definition at line 48 of file fevoices.cc.

## yy_noeof

VAR int yy_noeof =0

Definition at line 47 of file fevoices.cc.