本文整理汇总了C++中Bgetc函数的典型用法代码示例。如果您正苦于以下问题:C++ Bgetc函数的具体用法?C++ Bgetc怎么用?C++ Bgetc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bgetc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Breadnumber
static int
Breadnumber(Biobuf *b, char *buf)
{
int i;
int c;
int havedigits;
havedigits = 0;
for(i=0; i<22; i++){
if((c = Bgetc(b)) == Beof)
return -1;
if('0' <= c && c <= '9'){
*buf++ = c;
havedigits = 1;
}else if(c == ' '){
if(havedigits){
while((c = Bgetc(b)) == ' ')
;
if(c != Beof)
Bungetc(b);
break;
}
}else{
werrstr("bad character %.2x", c);
return -1;
}
}
*buf = 0;
return 0;
}
示例2: readline
static int
readline(Biobuf *bp, char *buf)
{
int c;
char *p, *e;
p = buf;
e = p + MAXLINELEN-1;
do {
c = Bgetc(bp);
if (c < 0) {
if (p == buf)
return -1;
break;
}
if (c == '\n')
break;
*p++ = c;
} while (p < e);
*p = 0;
if (c != '\n' && c >= 0) {
do c = Bgetc(bp);
while (c >= 0 && c != '\n');
}
return p - buf;
}
示例3: Bgetrune
long
Bgetrune(Biobuf *bp)
{
int c, i;
Rune rune;
char str[UTFmax];
c = Bgetc(bp);
if(c < Runeself) { /* one char */
bp->runesize = 1;
return c;
}
str[0] = c;
for(i=1;;) {
c = Bgetc(bp);
if(c < 0)
return c;
str[i++] = c;
if(fullrune(str, i)) {
bp->runesize = chartorune(&rune, str);
while(i > bp->runesize) {
Bungetc(bp);
i--;
}
return rune;
}
}
}
示例4: pass1
static char *
pass1(State *s, char *buf, int *alloc)
{
int c, t, used, state;
enum { Lost, String, Cplusplus, Comment };
used = 0;
state = Lost;
while((c = Bgetc(s->bp)) != -1){
if(c == '\n'){
s->line++;
if(state == Cplusplus)
state = Lost;
}
if(c == '/'){
t = Bgetc(s->bp);
if(t == '*' && state == Lost)
state = Comment;
else
if(t == '/' && state == Lost)
state = Cplusplus;
else
Bungetc(s->bp);
}
if(c == '*'){
t = Bgetc(s->bp);
if(t == '/' && state == Comment){
state = Lost;
c = ' ';
}
else
Bungetc(s->bp);
}
if(c == '\\'){
t = Bgetc(s->bp);
if(t == '\n')
c = ' ';
else
Bungetc(s->bp);
}
if(c == '\n' && state == Lost)
break;
if(state != Comment && state != Cplusplus){
if(used >= *alloc-1){
*alloc += Memchunk;
buf = erealloc(buf, *alloc);
}
buf[used++] = c;
}
}
if(c == -1)
return nil;
buf[used] = 0;
return buf;
}
示例5: Bgetle2
int
Bgetle2(Biobuf *bp)
{
int l, h;
l = Bgetc(bp);
h = Bgetc(bp);
return l|(h<<8);
}
示例6: _read5
int
_read5(Biobuf *bp, Prog *p)
{
int as, n;
Addr a;
as = Bgetc(bp); /* as */
if(as < 0)
return 0;
p->kind = aNone;
p->sig = 0;
if(as == ANAME || as == ASIGNAME){
if(as == ASIGNAME){
Bread(bp, &p->sig, 4);
p->sig = leswal(p->sig);
}
p->kind = aName;
p->type = type2char(Bgetc(bp)); /* type */
p->sym = Bgetc(bp); /* sym */
n = 0;
for(;;) {
as = Bgetc(bp);
if(as < 0)
return 0;
n++;
if(as == 0)
break;
}
p->id = malloc(n);
if(p->id == 0)
return 0;
Bseek(bp, -n, 1);
if(Bread(bp, p->id, n) != n)
return 0;
return 1;
}
if(as == ATEXT)
p->kind = aText;
else if(as == AGLOBL)
p->kind = aData;
skip(bp, 6); /* scond(1), reg(1), lineno(4) */
a = addr(bp);
addr(bp);
if(a.type != D_OREG || a.name != D_STATIC && a.name != D_EXTERN)
p->kind = aNone;
p->sym = a.sym;
return 1;
}
示例7: varread
void
varread(void) /* read into variable */
{
Datum d;
extern Biobuf *bin;
Symbol *var = (Symbol *) *pc++;
int c;
Again:
do
c = Bgetc(bin);
while(c==' ' || c=='\t' || c=='\n');
if(c == Beof){
Iseof:
if(moreinput())
goto Again;
d.val = var->u.val = 0.0;
goto Return;
}
if(strchr("+-.0123456789", c) == 0)
execerror("non-number read into", var->name);
Bungetc(bin);
if(Bgetd(bin, &var->u.val) == Beof)
goto Iseof;
else
d.val = 1.0;
Return:
var->type = VAR;
push(d);
}
示例8: readc
int
readc(void)
{
loop:
if((readptr != &readstk[0]) && (*readptr != 0)) {
if(sfeof(*readptr) == 0)
return(lastchar = sgetc(*readptr));
release(*readptr);
readptr--;
goto loop;
}
lastchar = Bgetc(curfile);
if(lastchar != -1)
return(lastchar);
if(readptr != &readptr[0]) {
readptr--;
if(*readptr == 0)
curfile = &bin;
goto loop;
}
if(curfile != &bin) {
Bterm(curfile);
curfile = &bin;
goto loop;
}
exits(0);
return 0; /* shut up ken */
}
示例9: pcollgnextoff
int32_t
pcollgnextoff(int32_t fromoff)
{
int c, state = 0, defoff = -1;
if(Bseek(bdict, fromoff, 0) < 0)
return -1;
while((c = Bgetc(bdict)) >= 0){
if(c == '\r')
defoff = Boffset(bdict);
switch(state){
case 0:
if(c == 0x05)
state = 1;
break;
case 1:
if(c == 'h')
state = 2;
else
state = 0;
break;
case 2:
if(c == 0x06)
return (Boffset(bdict)-3);
else
state = 0;
break;
}
}
return defoff;
}
示例10: getpassword
static int
getpassword(char *buf, char *e)
{
char *p;
int c;
int consctl, rv = 0;
consctl = open("/dev/consctl", OWRITE);
if(consctl >= 0)
write(consctl, "rawon", 5);
print("Password: ");
e--;
for(p = buf; p <= e; p++){
c = Bgetc(&stdin);
if(c < 0){
rv = -1;
goto out;
}
if(c == '\n' || c == '\r')
break;
*p = c;
}
*p = 0;
print("\n");
out:
if(consctl >= 0)
close(consctl);
return rv;
}
示例11: escchar
int
escchar(char c)
{
int n;
char buf[32];
if(c >= '0' && c <= '9') {
n = 1;
buf[0] = c;
for(;;) {
c = Bgetc(bin);
if(c == Eof)
fatal("%d: <eof> in escape sequence", line);
if(strchr("0123456789xX", c) == 0) {
Bungetc(bin);
break;
}
buf[n++] = c;
}
buf[n] = '\0';
return strtol(buf, 0, 0);
}
n = cmap[c];
if(n == 0)
return c;
return n-1;
}
示例12: getcrnl
/*
* get a line that ends in crnl or cr, turn terminating crnl into a nl
*
* return 0 on EOF
*/
static int
getcrnl(char *buf, int n)
{
int c;
char *ep;
char *bp;
Biobuf *fp = ∈
Bflush(&out);
bp = buf;
ep = bp + n - 1;
while(bp != ep){
c = Bgetc(fp);
if(debug) {
seek(2, 0, 2);
fprint(2, "%c", c);
}
switch(c){
case -1:
*bp = 0;
if(bp==buf)
return 0;
else
return bp-buf;
case '\r':
c = Bgetc(fp);
if(c == '\n'){
if(debug) {
seek(2, 0, 2);
fprint(2, "%c", c);
}
*bp = 0;
return bp-buf;
}
Bungetc(fp);
c = '\r';
break;
case '\n':
*bp = 0;
return bp-buf;
}
*bp++ = c;
}
*bp = 0;
return bp-buf;
}
示例13: peek
int
peek(void)
{
if (ugtop > 0)
return ugbuf[ugtop-1];
ugbuf[ugtop] = Bgetc(bdf);
return ugbuf[ugtop++];
}
示例14: pgwnextoff
/*
* Return offset into bdict where next webster entry after fromoff starts.
* Webster entries start with <p><hw>
*/
long
pgwnextoff(long fromoff)
{
long a, n;
int c;
a = Bseek(bdict, fromoff, 0);
if(a != fromoff)
return -1;
n = 0;
for(;;) {
c = Bgetc(bdict);
if(c < 0)
break;
if(c == '<' && Bgetc(bdict) == 'p' && Bgetc(bdict) == '>') {
c = Bgetc(bdict);
if(c == '<') {
if (Bgetc(bdict) == 'h' && Bgetc(bdict) == 'w'
&& Bgetc(bdict) == '>')
n = 7;
} else if (c == '{')
n = 4;
if(n)
break;
}
}
return (Boffset(bdict)-n);
}
示例15: getnext
char *
getnext(int must){
int c;
char *beg;
int prect,nlct;
prect = nlct = 0;
if(tptr > lastplace){
tptr = lastplace = temp;
err = 0;
inswitch = 0;
}
tp = lastplace;
if(inswitch && tptr <= lastplace)
if (isalnum((uchar)*lastplace)||ispunct((uchar)*lastplace)||isop((uchar)*lastplace))return(lastplace);
space:
while(isspace(c=Bgetc(input)))puttmp(c,1);
beg = tp;
puttmp(c,1);
if(c == '/'){
if(puttmp(Bgetc(input),1) == '*'){
cont:
while((c=Bgetc(input)) != '*'){
puttmp(c,0);
if(must == 0 && c == '\n')
if(nlct++ > 2)goto done;
}
puttmp(c,1);
star:
if(puttmp((c=Bgetc(input)),1) == '/'){
beg = tp;
puttmp((c=Bgetc(input)),1);
}
else if(c == '*')goto star;
else goto cont;
}
else goto done;
}
if(isspace(c))goto space;
if(c == '#' && tp > temp+1 && *(tp-2) == '\n'){
if(prect++ > 2)goto done;
while(puttmp((c=Bgetc(input)),1) != '\n')
if(c == '\\')puttmp(Bgetc(input),1);
goto space;
}
if(isalnum(c)){
while(isalnum(c = Bgetc(input)))puttmp(c,1);
Bungetc(input);
}
done:
puttmp('\0',1);
lastplace = tp-1;
inswitch = 1;
return(beg);
}