My Project
Loading...
Searching...
No Matches
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 <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 29 of file s_buff.cc.

Function Documentation

◆ s_close()

int s_close ( s_buff &  F)

Definition at line 45 of file s_buff.cc.

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

◆ s_getc()

int s_getc ( s_buff  F)

Definition at line 58 of file s_buff.cc.

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

◆ s_iseof()

int s_iseof ( s_buff  F)

Definition at line 254 of file s_buff.cc.

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

◆ s_isready()

int s_isready ( s_buff  F)

Definition at line 85 of file s_buff.cc.

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

◆ s_open()

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}
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int status int fd
Definition: si_signals.h:59

◆ s_open_by_name()

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}
s_buff s_open(int fd)
Definition: s_buff.cc:31
#define si_open(...)

◆ s_readbytes()

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

Definition at line 168 of file s_buff.cc.

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

◆ s_readint()

int s_readint ( s_buff  F)

Definition at line 112 of file s_buff.cc.

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

◆ s_readlong()

long s_readlong ( s_buff  F)

Definition at line 140 of file s_buff.cc.

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

◆ s_readmpz()

void s_readmpz ( s_buff  F,
mpz_t  a 
)

Definition at line 184 of file s_buff.cc.

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

◆ s_readmpz_base()

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

Definition at line 209 of file s_buff.cc.

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

◆ s_ungetc()

void s_ungetc ( int  c,
s_buff  F 
)

Definition at line 99 of file s_buff.cc.

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