My Project
Loading...
Searching...
No Matches
s_buff.h File Reference
#include "coeffs/si_gmp.h"

Go to the source code of this file.

Data Structures

struct  s_buff
struct  ssiInfo

Macros

#define SI_RING_CACHE   20

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)
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_ptr 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_isready (s_buff F)
int s_iseof (s_buff F)

Data Structure Documentation

◆ s_buff_s

struct s_buff_s

Definition at line 6 of file s_buff.h.

Data Fields
int bp
char * buff
int end
int fd
int is_eof

◆ ssiInfo

struct ssiInfo

Definition at line 20 of file s_buff.h.

Data Fields
s_buff f_read
FILE * f_write
int fd_read
int fd_write
char level
pid_t pid
char quit_sent
ring r
ring rings[SI_RING_CACHE]
char send_quit_at_exit

Macro Definition Documentation

◆ SI_RING_CACHE

#define SI_RING_CACHE   20

Definition at line 30 of file s_buff.h.

Function Documentation

◆ s_close()

int s_close ( s_buff & f)

Definition at line 46 of file s_buff.cc.

47{
48 if (F!=NULL)
49 {
50 int r=close(F->fd);
51 omFreeSize(F->buff,S_BUFF_LEN);
52 omFreeSize(F,sizeof(*F));
53 F=NULL;
54 return r;
55 }
56 return 0;
57}
#define omFreeSize(addr, size)
#define NULL
Definition omList.c:12
#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.

60{
61 if (F==NULL)
62 {
63 printf("link closed");
64 return 0;
65 }
66 if (F->bp>=F->end)
67 {
68 memset(F->buff,0,S_BUFF_LEN); /*debug*/
69 int r=si_read(F->fd,F->buff,S_BUFF_LEN);
70 if (r<=0)
71 {
72 F->is_eof=1;
73 return -1;
74 }
75 else
76 {
77 F->end=r-1;
78 F->bp=0;
79 return F->buff[0];
80 }
81 }
82 /*else*/
83 F->bp++;
84 return F->buff[F->bp];
85}

◆ s_iseof()

int s_iseof ( s_buff F)

Definition at line 352 of file s_buff.cc.

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

◆ s_isready()

int s_isready ( s_buff F)

Definition at line 86 of file s_buff.cc.

87{
88 if (F==NULL)
89 {
90 printf("link closed");
91 return 0;
92 }
93 if (F->bp>=F->end) return 0;
94 int p=F->bp+1;
95 while((p<F->end)&&(F->buff[p]<=' ')) p++;
96 if (p>=F->end) return 0;
97 return 1;
98}
int p
Definition cfModGcd.cc:4086

◆ s_open()

s_buff s_open ( int fd)

Definition at line 32 of file s_buff.cc.

33{
34 s_buff F=(s_buff)omAlloc0(sizeof(*F));
35 F->fd=fd;
36 F->buff=(char*)omAlloc(S_BUFF_LEN);
37 return F;
38}
#define omAlloc(size)
#define omAlloc0(size)
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.

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

◆ s_readbytes()

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

Definition at line 203 of file s_buff.cc.

204{
205 if (F==NULL)
206 {
207 printf("link closed");
208 return 0;
209 }
210 int i=0;
211 while((!F->is_eof)&&(i<len))
212 {
213 buff[i]=s_getc(F);
214 i++;
215 }
216 return i;
217}
int i
Definition cfEzgcd.cc:132
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.

114{
115 if (F==NULL)
116 {
117 printf("link closed");
118 return 0;
119 }
120 char c;
121 int neg=1;
122 int r=0;
123 //int digit=0;
124 do
125 {
126 c=s_getc(F);
127 } while((!F->is_eof) && (c<=' '));
128 if (c=='-') { neg=-1; c=s_getc(F); }
129 while(isdigit(c))
130 {
131 //digit++;
132 r=r*10+(c-'0');
133 c=s_getc(F);
134 }
135 s_ungetc(c,F);
136 //if (digit==0) { printf("unknown char %c(%d)\n",c,c); /*debug*/
137 // printf("buffer:%s\np=%d,e=%d\n",F->buff,F->bp,F->end);fflush(stdout); } /*debug*/
138 return r*neg;
139}
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.

142{
143 char *c=*s;
144 int n=0;
145 int neg=1;
146 while(*c<=' ') // skip white space
147 {
148 c++;
149 }
150 if (*c=='-') { neg=-1; c++; }
151 while(isdigit(*c))
152 {
153 n=n*10+(*c-'0');
154 c++;
155 }
156 *s=c;
157 return n*neg;
158}
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.

161{
162 if (F==NULL)
163 {
164 printf("link closed");
165 return 0;
166 }
167 char c;
168 long neg=1;
169 long r=0;
170 do
171 {
172 c=s_getc(F);
173 } while((!F->is_eof) && (c<=' '));
174 if (c=='-') { neg=-1; c=s_getc(F); }
175 while(isdigit(c))
176 {
177 r=r*10+(c-'0');
178 c=s_getc(F);
179 }
180 s_ungetc(c,F);
181 return r*neg;
182}

◆ s_readlong_S()

long s_readlong_S ( char ** s)

Definition at line 184 of file s_buff.cc.

185{
186 char *c=*s;
187 long n=0;
188 long neg=1;
189 while(*c<=' ') // skip white space
190 {
191 c++;
192 }
193 if (*c=='-') { neg=-1; c++; }
194 while(isdigit(*c))
195 {
196 n=n*10+(*c-'0');
197 c++;
198 }
199 *s=c;
200 return n*neg;
201}

◆ s_readmpz()

void s_readmpz ( s_buff F,
mpz_ptr 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.

265{
266 if (F==NULL)
267 {
268 printf("link closed");
269 return;
270 }
271 mpz_set_ui(a,0);
272 char c;
273 int neg=1;
274 do
275 {
276 c=s_getc(F);
277 } while((!F->is_eof) && (c<=' '));
278 if (c=='-') { neg=-1; c=s_getc(F); }
279 char *str=(char*)omAlloc0(128);
280 int str_l=128;
281 int str_p=0;
282 while(c>' ')
283 {
284 if ((isdigit(c))
285 || ((c>='a') && (c<='z'))
286 || ((c>='A') && (c<='Z')))
287 {
288 str[str_p]=c;
289 str_p++;
290 }
291 else
292 {
293 s_ungetc(c,F);
294 break;
295 }
296 if (str_p>=str_l-1)
297 {
298 int old_str_l=str_l;
299 str_l=str_l*2;
300 str=(char*)omRealloc(str,str_l);
301 memset(str+old_str_l,0,old_str_l);
302 }
303 c=s_getc(F);
304 }
305 if(mpz_set_str(a,str,base)!=0) WerrorS("wrong mpz number");
306 omFreeSize(str,str_l);
307 if (neg==-1) mpz_neg(a,a);
308}
void WerrorS(const char *s)
Definition feFopen.cc:24
char * str(leftv arg)
Definition shared.cc:699
#define omRealloc(addr, size)

◆ 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.

311{
312 mpz_set_ui(a,0);
313 char* c=*s;
314 int neg=1;
315 do
316 {
317 c++;
318 } while(*c<=' ');
319 if (*c=='-') { neg=-1; c++; }
320 char *str=(char*)omAlloc0(128);
321 int str_l=128;
322 int str_p=0;
323 while(*c>' ')
324 {
325 if ((isdigit(*c))
326 || ((*c>='a') && (*c<='z'))
327 || ((*c>='A') && (*c<='Z')))
328 {
329 str[str_p]=*c;
330 str_p++;
331 }
332 else
333 {
334 c--;
335 break;
336 }
337 if (str_p>=str_l-1)
338 {
339 int old_str_l=str_l;
340 str_l=str_l*2;
341 str=(char*)omRealloc(str,str_l);
342 memset(str+old_str_l,0,old_str_l);
343 }
344 c++;
345 }
346 if(mpz_set_str(a,str,base)!=0) WerrorS("wrong mpz number");
347 omFreeSize(str,str_l);
348 if (neg==-1) mpz_neg(a,a);
349 *s=c;
350}

◆ s_readmpz_S()

void s_readmpz_S ( char ** s,
mpz_t a )

Definition at line 244 of file s_buff.cc.

245{
246 mpz_set_ui(a,0);
247 char c;
248 int neg=1;
249 do // skip while space
250 {
251 c=**s;(*s)++;
252 } while (c<=' ');
253 if (c=='-') { neg=-1; c=**s;(*s)++; }
254 while(isdigit(c))
255 {
256 mpz_mul_ui(a,a,10);
257 mpz_add_ui(a,a,(c-'0'));
258 c=**s;(*s)++;
259 }
260 (*s)--;
261 if (neg==-1) mpz_neg(a,a);
262}

◆ s_ungetc()

void s_ungetc ( int c,
s_buff F )

Definition at line 100 of file s_buff.cc.

101{
102 if (F==NULL)
103 {
104 printf("link closed");
105 }
106 else if (F->bp>=0)
107 {
108 F->buff[F->bp]=c;
109 F->bp--;
110 }
111}