Loading...
Searching...
No Matches
s_buff.cc File Reference
`#include "misc/auxiliary.h"`
`#include <unistd.h>`
`#include <stdio.h>`
`#include <ctype.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include <fcntl.h>`
`#include <gmp.h>`
`#include "omalloc/omalloc.h"`
`#include "reporter/s_buff.h"`
`#include "reporter/si_signals.h"`
`#include "reporter/reporter.h"`

Go to the source code of this file.

## Macros

#define | S_BUFF_LEN (4096-SIZEOF_LONG)

## Functions

s_buff | s_open (int fd)
s_buff | s_open_by_name (const char *n)
int | s_close (s_buff &F)
int | s_getc (s_buff F)
int | s_isready (s_buff F)
void | s_ungetc (int c, s_buff F)
int | s_readint (s_buff F)
int | s_readint_S (char **s)
long | s_readlong (s_buff F)
long | s_readlong_S (char **s)
int | s_readbytes (char *buff, int len, s_buff F)
void | s_readmpz (s_buff F, mpz_t a)
void | s_readmpz_S (char **s, mpz_t a)
void | s_readmpz_base (s_buff F, mpz_ptr a, int base)
void | s_readmpz_base_S (char **s, mpz_ptr a, int base)
int | s_iseof (s_buff F)

## Macro Definition Documentation

## S_BUFF_LEN

#define S_BUFF_LEN (4096-SIZEOF_LONG)

Definition at line 30 of file s_buff.cc.

## Function Documentation

## s_close()

int s_close | ( | s_buff & | F | ) |

Definition at line 46 of file s_buff.cc.

{
if (F!=NULL)
{
int r=close(F->fd);
omFreeSize(F->buff,S_BUFF_LEN);
omFreeSize(F,sizeof(*F));
F=NULL;
return r;
}
return 0;
}
omFreeSize
#define omFreeSize(addr, size)
Definition omAllocDecl.h:260
NULL
#define NULL
Definition omList.c:12
S_BUFF_LEN
#define S_BUFF_LEN
Definition s_buff.cc:30

## s_getc()

int s_getc | ( | s_buff | F | ) |

Definition at line 59 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return 0;
}
if (F->bp>=F->end)
{
memset(F->buff,0,S_BUFF_LEN); /*debug*/
int r=si_read(F->fd,F->buff,S_BUFF_LEN);
if (r<=0)
{
F->is_eof=1;
return -1;
}
else
{
F->end=r-1;
F->bp=0;
return F->buff[0];
}
}
/*else*/
F->bp++;
return F->buff[F->bp];
}

## s_iseof()

int s_iseof | ( | s_buff | F | ) |

Definition at line 352 of file s_buff.cc.

{
if (F!=NULL) return F->is_eof;
else return 1;
}

## s_isready()

int s_isready | ( | s_buff | F | ) |

Definition at line 86 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return 0;
}
if (F->bp>=F->end) return 0;
int p=F->bp+1;
while((p<F->end)&&(F->buff[p]<=' ')) p++;
if (p>=F->end) return 0;
return 1;
}
p
int p
Definition cfModGcd.cc:4086

## s_open()

s_buff s_open | ( | int | fd | ) |

Definition at line 32 of file s_buff.cc.

{
s_buff F=(s_buff)omAlloc0(sizeof(*F));
F->fd=fd;
F->buff=(char*)omAlloc(S_BUFF_LEN);
return F;
}
omAlloc
#define omAlloc(size)
Definition omAllocDecl.h:210
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
fd
int status int fd
Definition si_signals.h:69

## s_open_by_name()

s_buff s_open_by_name | ( | const char * | n | ) |

Definition at line 40 of file s_buff.cc.

{
int fd=si_open(n,O_RDONLY);
return s_open(fd);
}
s_open
s_buff s_open(int fd)
Definition s_buff.cc:32
si_open
#define si_open(...)

## s_readbytes()

int s_readbytes | ( | char * | buff,
|  | int | len,
|  | s_buff | F )

Definition at line 203 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return 0;
}
int i=0;
while((!F->is_eof)&&(i<len))
{
buff[i]=s_getc(F);
i++;
}
return i;
}
i
int i
Definition cfEzgcd.cc:132
s_getc
int s_getc(s_buff F)
Definition s_buff.cc:59

## s_readint()

int s_readint | ( | s_buff | F | ) |

Definition at line 113 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return 0;
}
char c;
int neg=1;
int r=0;
//int digit=0;
do
{
c=s_getc(F);
} while((!F->is_eof) && (c<=' '));
if (c=='-') { neg=-1; c=s_getc(F); }
while(isdigit(c))
{
//digit++;
r=r*10+(c-'0');
c=s_getc(F);
}
s_ungetc(c,F);
//if (digit==0) { printf("unknown char %c(%d)\n",c,c); /*debug*/
// printf("buffer:%s\np=%d,e=%d\n",F->buff,F->bp,F->end);fflush(stdout); } /*debug*/
return r*neg;
}
s_ungetc
void s_ungetc(int c, s_buff F)
Definition s_buff.cc:100

## s_readint_S()

int s_readint_S | ( | char ** | s | ) |

Definition at line 141 of file s_buff.cc.

{
char *c=*s;
int n=0;
int neg=1;
while(*c<=' ') // skip white space
{
c++;
}
if (*c=='-') { neg=-1; c++; }
while(isdigit(*c))
{
n=n*10+(*c-'0');
c++;
}
*s=c;
return n*neg;
}
s
const CanonicalForm int s
Definition facAbsFact.cc:51

## s_readlong()

long s_readlong | ( | s_buff | F | ) |

Definition at line 160 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return 0;
}
char c;
long neg=1;
long r=0;
do
{
c=s_getc(F);
} while((!F->is_eof) && (c<=' '));
if (c=='-') { neg=-1; c=s_getc(F); }
while(isdigit(c))
{
r=r*10+(c-'0');
c=s_getc(F);
}
s_ungetc(c,F);
return r*neg;
}

## s_readlong_S()

long s_readlong_S | ( | char ** | s | ) |

Definition at line 184 of file s_buff.cc.

{
char *c=*s;
long n=0;
long neg=1;
while(*c<=' ') // skip white space
{
c++;
}
if (*c=='-') { neg=-1; c++; }
while(isdigit(*c))
{
n=n*10+(*c-'0');
c++;
}
*s=c;
return n*neg;
}

## s_readmpz()

void s_readmpz | ( | s_buff | F,
|  | mpz_t | a )

Definition at line 219 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return;
}
mpz_set_ui(a,0);
char c;
int neg=1;
do // skip white space
{
c=s_getc(F);
} while((!F->is_eof) && (c<=' '));
if (c=='-') { neg=-1; c=s_getc(F); }
while(isdigit(c))
{
mpz_mul_ui(a,a,10);
mpz_add_ui(a,a,(c-'0'));
c=s_getc(F);
}
s_ungetc(c,F);
if (neg==-1) mpz_neg(a,a);
}

## s_readmpz_base()

void s_readmpz_base | ( | s_buff | F,
|  | mpz_ptr | a,
|  | int | base )

Definition at line 264 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
return;
}
mpz_set_ui(a,0);
char c;
int neg=1;
do
{
c=s_getc(F);
} while((!F->is_eof) && (c<=' '));
if (c=='-') { neg=-1; c=s_getc(F); }
char *str=(char*)omAlloc0(128);
int str_l=128;
int str_p=0;
while(c>' ')
{
if ((isdigit(c))
|| ((c>='a') && (c<='z'))
|| ((c>='A') && (c<='Z')))
{
str[str_p]=c;
str_p++;
}
else
{
s_ungetc(c,F);
break;
}
if (str_p>=str_l-1)
{
int old_str_l=str_l;
str_l=str_l*2;
str=(char*)omRealloc(str,str_l);
memset(str+old_str_l,0,old_str_l);
}
c=s_getc(F);
}
if(mpz_set_str(a,str,base)!=0) WerrorS("wrong mpz number");
omFreeSize(str,str_l);
if (neg==-1) mpz_neg(a,a);
}
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
LibThread::str
char * str(leftv arg)
Definition shared.cc:699
omRealloc
#define omRealloc(addr, size)
Definition omAllocDecl.h:225

## s_readmpz_base_S()

void s_readmpz_base_S | ( | char ** | s,
|  | mpz_ptr | a,
|  | int | base )

Definition at line 310 of file s_buff.cc.

{
mpz_set_ui(a,0);
char* c=*s;
int neg=1;
do
{
c++;
} while(*c<=' ');
if (*c=='-') { neg=-1; c++; }
char *str=(char*)omAlloc0(128);
int str_l=128;
int str_p=0;
while(*c>' ')
{
if ((isdigit(*c))
|| ((*c>='a') && (*c<='z'))
|| ((*c>='A') && (*c<='Z')))
{
str[str_p]=*c;
str_p++;
}
else
{
c--;
break;
}
if (str_p>=str_l-1)
{
int old_str_l=str_l;
str_l=str_l*2;
str=(char*)omRealloc(str,str_l);
memset(str+old_str_l,0,old_str_l);
}
c++;
}
if(mpz_set_str(a,str,base)!=0) WerrorS("wrong mpz number");
omFreeSize(str,str_l);
if (neg==-1) mpz_neg(a,a);
*s=c;
}

## s_readmpz_S()

void s_readmpz_S | ( | char ** | s,
|  | mpz_t | a )

Definition at line 244 of file s_buff.cc.

{
mpz_set_ui(a,0);
char c;
int neg=1;
do // skip while space
{
c=**s;(*s)++;
} while (c<=' ');
if (c=='-') { neg=-1; c=**s;(*s)++; }
while(isdigit(c))
{
mpz_mul_ui(a,a,10);
mpz_add_ui(a,a,(c-'0'));
c=**s;(*s)++;
}
(*s)--;
if (neg==-1) mpz_neg(a,a);
}

## s_ungetc()

void s_ungetc | ( | int | c,
|  | s_buff | F )

Definition at line 100 of file s_buff.cc.

{
if (F==NULL)
{
printf("link closed");
}
else if (F->bp>=0)
{
F->buff[F->bp]=c;
F->bp--;
}
}