My Project
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)
 
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 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.

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 255 of file s_buff.cc.

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

◆ 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 169 of file s_buff.cc.

170{
171 if (F==NULL)
172 {
173 printf("link closed");
174 return 0;
175 }
176 int i=0;
177 while((!F->is_eof)&&(i<len))
178 {
179 buff[i]=s_getc(F);
180 i++;
181 }
182 return i;
183}
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_readlong()

long s_readlong ( s_buff F)

Definition at line 141 of file s_buff.cc.

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

◆ s_readmpz()

void s_readmpz ( s_buff F,
mpz_t a )

Definition at line 185 of file s_buff.cc.

186{
187 if (F==NULL)
188 {
189 printf("link closed");
190 return;
191 }
192 mpz_set_ui(a,0);
193 char c;
194 int neg=1;
195 do
196 {
197 c=s_getc(F);
198 } while((!F->is_eof) && (c<=' '));
199 if (c=='-') { neg=-1; c=s_getc(F); }
200 while(isdigit(c))
201 {
202 mpz_mul_ui(a,a,10);
203 mpz_add_ui(a,a,(c-'0'));
204 c=s_getc(F);
205 }
206 s_ungetc(c,F);
207 if (neg==-1) mpz_neg(a,a);
208}

◆ s_readmpz_base()

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

Definition at line 210 of file s_buff.cc.

211{
212 if (F==NULL)
213 {
214 printf("link closed");
215 return;
216 }
217 mpz_set_ui(a,0);
218 char c;
219 int neg=1;
220 do
221 {
222 c=s_getc(F);
223 } while((!F->is_eof) && (c<=' '));
224 if (c=='-') { neg=-1; c=s_getc(F); }
225 char *str=(char*)omAlloc0(128);
226 int str_l=128;
227 int str_p=0;
228 while(c>' ')
229 {
230 if ((isdigit(c))
231 || ((c>='a') && (c<='z'))
232 || ((c>='A') && (c<='Z')))
233 {
234 str[str_p]=c;
235 str_p++;
236 }
237 else
238 {
239 s_ungetc(c,F);
240 break;
241 }
242 if (str_p>=str_l-1)
243 {
244 int old_str_l=str_l;
245 str_l=str_l*2;
246 str=(char*)omRealloc(str,str_l);
247 memset(str+old_str_l,0,old_str_l);
248 }
249 c=s_getc(F);
250 }
251 if(mpz_set_str(a,str,base)!=0) WerrorS("wrong mpz number");
252 omFreeSize(str,str_l);
253 if (neg==-1) mpz_neg(a,a);
254}
void WerrorS(const char *s)
Definition feFopen.cc:24
char * str(leftv arg)
Definition shared.cc:699
#define omRealloc(addr, size)

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