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

#define S_BUFF_LEN   4096

Definition at line 29 of file s_buff.cc.

Function Documentation

int s_close ( s_buff &  F)

Definition at line 56 of file s_buff.cc.

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

Definition at line 45 of file s_buff.cc.

46 {
47  if (F!=NULL)
48  {
49  omFreeSize(F->buff,S_BUFF_LEN);
50  omFreeSize(F,sizeof(*F));
51  F=NULL;
52  }
53  return 0;
54 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define S_BUFF_LEN
Definition: s_buff.cc:29
#define NULL
Definition: omList.c:10
int s_getc ( s_buff  F)

Definition at line 66 of file s_buff.cc.

67 {
68  if (F==NULL)
69  {
70  printf("link closed");
71  return 0;
72  }
73  if (F->bp>=F->end)
74  {
75  memset(F->buff,0,S_BUFF_LEN); /*debug*/
76  int r=si_read(F->fd,F->buff,S_BUFF_LEN);
77  if (r<=0)
78  {
79  F->is_eof=1;
80  return -1;
81  }
82  else
83  {
84  F->end=r-1;
85  F->bp=0;
86  return F->buff[0];
87  }
88  }
89  /*else*/
90  F->bp++;
91  return F->buff[F->bp];
92 }
const ring r
Definition: syzextra.cc:208
#define S_BUFF_LEN
Definition: s_buff.cc:29
#define NULL
Definition: omList.c:10
int s_iseof ( s_buff  F)

Definition at line 260 of file s_buff.cc.

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

Definition at line 93 of file s_buff.cc.

94 {
95  if (F==NULL)
96  {
97  printf("link closed");
98  return 0;
99  }
100  if (F->bp>=F->end) return 0;
101  int p=F->bp+1;
102  while((p<F->end)&&(F->buff[p]<=' ')) p++;
103  if (p>=F->end) return 0;
104  return 1;
105 }
return P p
Definition: myNF.cc:203
#define NULL
Definition: omList.c:10
s_buff s_open ( int  fd)

Definition at line 31 of file s_buff.cc.

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

Definition at line 39 of file s_buff.cc.

40 {
41  int fd=si_open(n,O_RDONLY);
42  return s_open(fd);
43 }
int status int fd
Definition: si_signals.h:59
#define si_open(...)
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
s_buff s_open(int fd)
Definition: s_buff.cc:31
int s_readbytes ( char *  buff,
int  len,
s_buff  F 
)

Definition at line 176 of file s_buff.cc.

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

Definition at line 120 of file s_buff.cc.

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

Definition at line 148 of file s_buff.cc.

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

Definition at line 192 of file s_buff.cc.

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

Definition at line 217 of file s_buff.cc.

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

Definition at line 107 of file s_buff.cc.

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