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
 

Functions

s_buff s_open (int fd)
 
s_buff s_open_by_name (const char *n)
 
int s_free (s_buff &F)
 
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

Definition at line 28 of file s_buff.cc.

Function Documentation

§ s_close()

int s_close ( s_buff &  F)

Definition at line 55 of file s_buff.cc.

56 {
57  if (F!=NULL)
58  {
59  int r=close(F->fd);
60  return r;
61  }
62  return 0;
63 }
const ring r
Definition: syzextra.cc:208
#define NULL
Definition: omList.c:10

§ s_free()

int s_free ( s_buff &  F)

Definition at line 44 of file s_buff.cc.

45 {
46  if (F!=NULL)
47  {
48  omFreeSize(F->buff,S_BUFF_LEN);
49  omFreeSize(F,sizeof(*F));
50  F=NULL;
51  }
52  return 0;
53 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#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 65 of file s_buff.cc.

66 {
67  if (F==NULL)
68  {
69  printf("link closed");
70  return 0;
71  }
72  if (F->bp>=F->end)
73  {
74  memset(F->buff,0,S_BUFF_LEN); /*debug*/
75  int r=si_read(F->fd,F->buff,S_BUFF_LEN);
76  if (r<=0)
77  {
78  F->is_eof=1;
79  return -1;
80  }
81  else
82  {
83  F->end=r-1;
84  F->bp=0;
85  return F->buff[0];
86  }
87  }
88  /*else*/
89  F->bp++;
90  return F->buff[F->bp];
91 }
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 259 of file s_buff.cc.

260 {
261  if (F!=NULL) return F->is_eof;
262  else return 1;
263 }
#define NULL
Definition: omList.c:10

§ s_isready()

int s_isready ( s_buff  F)

Definition at line 92 of file s_buff.cc.

93 {
94  if (F==NULL)
95  {
96  printf("link closed");
97  return 0;
98  }
99  if (F->bp>=F->end) return 0;
100  int p=F->bp+1;
101  while((p<F->end)&&(F->buff[p]<=' ')) p++;
102  if (p>=F->end) return 0;
103  return 1;
104 }
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 175 of file s_buff.cc.

176 {
177  if (F==NULL)
178  {
179  printf("link closed");
180  return 0;
181  }
182  int i=0;
183  while((!F->is_eof)&&(i<len))
184  {
185  buff[i]=s_getc(F);
186  i++;
187  }
188  return i;
189 }
int s_getc(s_buff F)
Definition: s_buff.cc:65
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10

§ s_readint()

int s_readint ( s_buff  F)

Definition at line 119 of file s_buff.cc.

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

§ s_readlong()

long s_readlong ( s_buff  F)

Definition at line 147 of file s_buff.cc.

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

§ s_readmpz()

void s_readmpz ( s_buff  F,
mpz_t  a 
)

Definition at line 191 of file s_buff.cc.

192 {
193  if (F==NULL)
194  {
195  printf("link closed");
196  return;
197  }
198  mpz_set_ui(a,0);
199  char c;
200  int neg=1;
201  do
202  {
203  c=s_getc(F);
204  } while((!F->is_eof) && (c<=' '));
205  if (c=='-') { neg=-1; c=s_getc(F); }
206  while(isdigit(c))
207  {
208  mpz_mul_ui(a,a,10);
209  mpz_add_ui(a,a,(c-'0'));
210  c=s_getc(F);
211  }
212  s_ungetc(c,F);
213  if (neg==-1) mpz_neg(a,a);
214 }
const poly a
Definition: syzextra.cc:212
int s_getc(s_buff F)
Definition: s_buff.cc:65
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:106
#define NULL
Definition: omList.c:10

§ s_readmpz_base()

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

Definition at line 216 of file s_buff.cc.

217 {
218  if (F==NULL)
219  {
220  printf("link closed");
221  return;
222  }
223  mpz_set_ui(a,0);
224  char c;
225  int neg=1;
226  do
227  {
228  c=s_getc(F);
229  } while((!F->is_eof) && (c<=' '));
230  if (c=='-') { neg=-1; c=s_getc(F); }
231  char *str=(char*)omAlloc0(128);
232  int str_l=128;
233  int str_p=0;
234  while(c>' ')
235  {
236  if ((isdigit(c))
237  || ((c>='a') && (c<='z'))
238  || ((c>='A') && (c<='Z')))
239  {
240  str[str_p]=c;
241  str_p++;
242  }
243  else
244  {
245  s_ungetc(c,F);
246  break;
247  }
248  if (str_p>=str_l)
249  {
250  str_l=str_l*2;
251  str=(char*)omRealloc0(str,str_l);
252  }
253  c=s_getc(F);
254  }
255  mpz_set_str(a,str,base);
256  omFreeSize(str,str_l);
257  if (neg==-1) mpz_neg(a,a);
258 }
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:65
void s_ungetc(int c, s_buff F)
Definition: s_buff.cc:106
#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 106 of file s_buff.cc.

107 {
108  if (F==NULL)
109  {
110  printf("link closed");
111  }
112  else if (F->bp>=0)
113  {
114  F->buff[F->bp]=c;
115  F->bp--;
116  }
117 }
#define NULL
Definition: omList.c:10