Macros | Functions
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 <signal.h>
#include <gmp.h>
#include <omalloc/omalloc.h>
#include <reporter/s_buff.h>
#include <reporter/si_signals.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)
 
long s_readlong (s_buff F)
 
int s_readbytes (char *buff, int len, s_buff F)
 
void s_readmpz (s_buff F, mpz_t a)
 
void s_readmpz_base (s_buff F, 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 28 of file s_buff.cc.

Function Documentation

§ s_close()

int s_close ( s_buff &  F)

Definition at line 44 of file s_buff.cc.

45 {
46  if (F!=NULL)
47  {
48  int r=close(F->fd);
49  omFreeSize(F->buff,S_BUFF_LEN);
50  omFreeSize(F,sizeof(*F));
51  F=NULL;
52  return r;
53  }
54  return 0;
55 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
const ring r
Definition: syzextra.cc:208
#define S_BUFF_LEN
Definition: s_buff.cc:28
#define NULL
Definition: omList.c:10

§ s_getc()

int s_getc ( s_buff  F)

Definition at line 57 of file s_buff.cc.

58 {
59  if (F==NULL)
60  {
61  printf("link closed");
62  return 0;
63  }
64  if (F->bp>=F->end)
65  {
66  memset(F->buff,0,S_BUFF_LEN); /*debug*/
67  int r=si_read(F->fd,F->buff,S_BUFF_LEN);
68  if (r<=0)
69  {
70  F->is_eof=1;
71  return -1;
72  }
73  else
74  {
75  F->end=r-1;
76  F->bp=0;
77  return F->buff[0];
78  }
79  }
80  /*else*/
81  F->bp++;
82  return F->buff[F->bp];
83 }
const ring r
Definition: syzextra.cc:208
#define S_BUFF_LEN
Definition: s_buff.cc:28
#define NULL
Definition: omList.c:10

§ s_iseof()

int s_iseof ( s_buff  F)

Definition at line 251 of file s_buff.cc.

252 {
253  if (F!=NULL) return F->is_eof;
254  else return 1;
255 }
#define NULL
Definition: omList.c:10

§ s_isready()

int s_isready ( s_buff  F)

Definition at line 84 of file s_buff.cc.

85 {
86  if (F==NULL)
87  {
88  printf("link closed");
89  return 0;
90  }
91  if (F->bp>=F->end) return 0;
92  int p=F->bp+1;
93  while((p<F->end)&&(F->buff[p]<=' ')) p++;
94  if (p>=F->end) return 0;
95  return 1;
96 }
return P p
Definition: myNF.cc:203
#define NULL
Definition: omList.c:10

§ s_open()

s_buff s_open ( int  fd)

Definition at line 30 of file s_buff.cc.

31 {
32  s_buff F=(s_buff)omAlloc0(sizeof(*F));
33  F->fd=fd;
34  F->buff=(char*)omAlloc(S_BUFF_LEN);
35  return F;
36 }
int status int fd
Definition: si_signals.h:59
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define S_BUFF_LEN
Definition: s_buff.cc:28
#define omAlloc0(size)
Definition: omAllocDecl.h:211

§ s_open_by_name()

s_buff s_open_by_name ( const char *  n)

Definition at line 38 of file s_buff.cc.

39 {
40  int fd=si_open(n,O_RDONLY);
41  return s_open(fd);
42 }
int status int fd
Definition: si_signals.h:59
#define si_open(...)
s_buff s_open(int fd)
Definition: s_buff.cc:30

§ s_readbytes()

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

Definition at line 167 of file s_buff.cc.

168 {
169  if (F==NULL)
170  {
171  printf("link closed");
172  return 0;
173  }
174  int i=0;
175  while((!F->is_eof)&&(i<len))
176  {
177  buff[i]=s_getc(F);
178  i++;
179  }
180  return i;
181 }
int s_getc(s_buff F)
Definition: s_buff.cc:57
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10

§ s_readint()

int s_readint ( s_buff  F)

Definition at line 111 of file s_buff.cc.

112 {
113  if (F==NULL)
114  {
115  printf("link closed");
116  return 0;
117  }
118  char c;
119  int neg=1;
120  int r=0;
121  //int digit=0;
122  do
123  {
124  c=s_getc(F);
125  } while((!F->is_eof) && (c<=' '));
126  if (c=='-') { neg=-1; c=s_getc(F); }
127  while(isdigit(c))
128  {
129  //digit++;
130  r=r*10+(c-'0');
131  c=s_getc(F);
132  }
133  s_ungetc(c,F);
134  //if (digit==0) { printf("unknown char %c(%d)\n",c,c); /*debug*/
135  // printf("buffer:%s\np=%d,e=%d\n",F->buff,F->bp,F->end);fflush(stdout); } /*debug*/
136  return r*neg;
137 }
int s_getc(s_buff F)
Definition: s_buff.cc:57
const ring r
Definition: syzextra.cc:208
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:98
#define NULL
Definition: omList.c:10

§ s_readlong()

long s_readlong ( s_buff  F)

Definition at line 139 of file s_buff.cc.

140 {
141  if (F==NULL)
142  {
143  printf("link closed");
144  return 0;
145  }
146  char c;
147  long neg=1;
148  long r=0;
149  //int digit=0;
150  do
151  {
152  c=s_getc(F);
153  } while((!F->is_eof) && (c<=' '));
154  if (c=='-') { neg=-1; c=s_getc(F); }
155  while(isdigit(c))
156  {
157  //digit++;
158  r=r*10+(c-'0');
159  c=s_getc(F);
160  }
161  s_ungetc(c,F);
162  //if (digit==0) { printf("unknown char %c(%d)\n",c,c); /*debug*/
163  // printf("buffer:%s\np=%d,e=%d\n",F->buff,F->bp,F->end);fflush(stdout); } /*debug*/
164  return r*neg;
165 }
int s_getc(s_buff F)
Definition: s_buff.cc:57
const ring r
Definition: syzextra.cc:208
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:98
#define NULL
Definition: omList.c:10

§ s_readmpz()

void s_readmpz ( s_buff  F,
mpz_t  a 
)

Definition at line 183 of file s_buff.cc.

184 {
185  if (F==NULL)
186  {
187  printf("link closed");
188  return;
189  }
190  mpz_set_ui(a,0);
191  char c;
192  int neg=1;
193  do
194  {
195  c=s_getc(F);
196  } while((!F->is_eof) && (c<=' '));
197  if (c=='-') { neg=-1; c=s_getc(F); }
198  while(isdigit(c))
199  {
200  mpz_mul_ui(a,a,10);
201  mpz_add_ui(a,a,(c-'0'));
202  c=s_getc(F);
203  }
204  s_ungetc(c,F);
205  if (neg==-1) mpz_neg(a,a);
206 }
const poly a
Definition: syzextra.cc:212
int s_getc(s_buff F)
Definition: s_buff.cc:57
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:98
#define NULL
Definition: omList.c:10

§ s_readmpz_base()

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

Definition at line 208 of file s_buff.cc.

209 {
210  if (F==NULL)
211  {
212  printf("link closed");
213  return;
214  }
215  mpz_set_ui(a,0);
216  char c;
217  int neg=1;
218  do
219  {
220  c=s_getc(F);
221  } while((!F->is_eof) && (c<=' '));
222  if (c=='-') { neg=-1; c=s_getc(F); }
223  char *str=(char*)omAlloc0(128);
224  int str_l=128;
225  int str_p=0;
226  while(c>' ')
227  {
228  if ((isdigit(c))
229  || ((c>='a') && (c<='z'))
230  || ((c>='A') && (c<='Z')))
231  {
232  str[str_p]=c;
233  str_p++;
234  }
235  else
236  {
237  s_ungetc(c,F);
238  break;
239  }
240  if (str_p>=str_l)
241  {
242  str_l=str_l*2;
243  str=(char*)omRealloc0(str,str_l);
244  }
245  c=s_getc(F);
246  }
247  mpz_set_str(a,str,base);
248  omFreeSize(str,str_l);
249  if (neg==-1) mpz_neg(a,a);
250 }
const poly a
Definition: syzextra.cc:212
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
char N base
Definition: ValueTraits.h:144
int s_getc(s_buff F)
Definition: s_buff.cc:57
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:98
#define NULL
Definition: omList.c:10
#define omRealloc0(addr, size)
Definition: omAllocDecl.h:226
#define omAlloc0(size)
Definition: omAllocDecl.h:211

§ s_ungetc()

void s_ungetc ( int  c,
s_buff  F 
)

Definition at line 98 of file s_buff.cc.

99 {
100  if (F==NULL)
101  {
102  printf("link closed");
103  }
104  else if (F->bp>=0)
105  {
106  F->buff[F->bp]=c;
107  F->bp--;
108  }
109 }
#define NULL
Definition: omList.c:10