本文整理汇总了C++中GETC函数的典型用法代码示例。如果您正苦于以下问题:C++ GETC函数的具体用法?C++ GETC怎么用?C++ GETC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GETC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getnum
static int getnum(int *chp, ftnlen *val)
{
register int ch, sign;
register ftnlen x;
while(GETC(ch) <= ' ' && ch >= 0);
if (ch == '-') {
sign = 1;
GETC(ch);
}
else {
sign = 0;
if (ch == '+')
GETC(ch);
}
x = ch - '0';
if (x < 0 || x > 9)
return 115;
while(GETC(ch) >= '0' && ch <= '9')
x = 10*x + ch - '0';
while(ch <= ' ' && ch >= 0)
GETC(ch);
if (ch == EOF)
return EOF;
*val = sign ? -x : x;
*chp = ch;
return 0;
}
示例2: getline_alloc
/* lifted from img.c Should be put somewhere common? JPNP*/
static char *
getline_alloc(FILE *fh, size_t ilen)
{
int ch;
size_t i = 0;
size_t len = ilen;
char *buf = xosmalloc(len);
if (!buf) return NULL;
ch = GETC(fh);
while (ch != '\n' && ch != '\r' && ch != EOF) {
buf[i++] = ch;
if (i == len - 1) {
char *p;
len += len;
p = xosrealloc(buf, len);
if (!p) {
osfree(buf);
return NULL;
}
buf = p;
}
ch = GETC(fh);
}
if (ch == '\n' || ch == '\r') {
int otherone = ch ^ ('\n' ^ '\r');
ch = GETC(fh);
/* if it's not the other eol character, put it back */
if (ch != otherone) ungetc(ch, fh);
}
buf[i++] = '\0';
return buf;
}
示例3: l_C
int
l_C()
{ int ch;
if(lcount>0) return(0);
ltype=0;
for(GETC(ch);isblnk(ch);GETC(ch));
if(ch==',')
{ lcount=1;
return(0);
}
if(ch=='/')
{ lquit=1;
return(0);
}
if(ch!='(')
{ if(fscanf(cf,"%d",&lcount)!=1) {
if(!feof(cf)) err(elist->cierr,112,"no rep")
else err(elist->cierr,(EOF),"lread");
}
if(GETC(ch)!='*')
{ ungetc(ch,cf);
if(!feof(cf)) err(elist->cierr,112,"no star")
else err(elist->cierr,(EOF),"lread");
}
if(GETC(ch)!='(')
{ ungetc(ch,cf);
return(0);
}
}
示例4: l_L
static int
l_L(Void)
{
int ch, rv, sawdot;
if(f__lcount>0)
return(0);
f__lcount = 1;
f__ltype=0;
GETC(ch);
if(isdigit(ch))
{
rd_count(ch);
if(GETC(ch)!='*') {
if(!f__cf || !feof(f__cf)) {
errfl(f__elist->cierr,112,"no star");
}
else {
err(f__elist->cierr,(EOF),"lread");
}
}
GETC(ch);
}
sawdot = 0;
if(ch == '.') {
sawdot = 1;
GETC(ch);
}
switch(ch)
{
case 't':
case 'T':
if (nml_read && Lfinish(ch, sawdot, &rv))
return rv;
f__lx=1;
break;
case 'f':
case 'F':
if (nml_read && Lfinish(ch, sawdot, &rv))
return rv;
f__lx=0;
break;
default:
if(isblnk(ch) || issep(ch) || ch==EOF)
{ (void) Ungetc(ch,f__cf);
return(0);
}
if (nml_read > 1) {
Ungetc(ch,f__cf);
f__lquit = 2;
return 0;
}
errfl(f__elist->cierr,112,"logical");
}
f__ltype=TYLONG;
while(!issep(GETC(ch)) && ch!=EOF);
Ungetc(ch, f__cf);
return(0);
}
示例5: getC
/*
* getC to read skipping the comments from the file.
*
* Each comment returns a newline or EOF
*
* Reading strings normal getc is used!
*/
static int getC(tpLspObject pLSP,
FILE *f){
int ch;
if( (ch=GETC(f)) == ';' )
while( (ch=GETC(f)) != '\n' && ch != EOF )
;
return ch;
}
示例6: l_R
int
l_R()
{ double a,b,c,d;
int i,ch,sign=0,da,db,dc;
a=b=c=d=0;
da=db=dc=0;
if(lcount>0) return(0);
ltype=0;
for(GETC(ch);isblnk(ch);GETC(ch));
if(ch==',')
{ lcount=1;
return(0);
}
if(ch=='/')
{ lquit=1;
return(0);
}
ungetc(ch,cf);
da=rd_int(&a);
if(da== -1) sign=da;
if(GETC(ch)!='*')
{ ungetc(ch,cf);
db=1;
b=a;
a=1;
}
else
db=rd_int(&b);
if(GETC(ch)!='.')
{ dc=c=0;
ungetc(ch,cf);
}
else dc=rd_int(&c);
if(isexp(GETC(ch))) db=rd_int(&d);
else
{ ungetc(ch,cf);
d=0;
}
lcount=a;
if(!db && !dc)
return(0);
if(db && b<0)
{ sign=1;
b = -b;
}
for(i=0;i<dc;i++) c/=10;
b=b+c;
for(i=0;i<d;i++) b *= 10;
for(i=0;i< -d;i++) b /= 10;
if(sign) b = -b;
ltype=TYLONG;
lx=b;
return(0);
}
示例7: kgdb_recv
/*
* Receive a packet.
*/
static int
kgdb_recv(u_char *bp, int maxlen)
{
u_char *p;
int c, csum;
int len;
do {
p = bp;
csum = len = 0;
while ((c = GETC()) != KGDB_START)
;
while ((c = GETC()) != KGDB_END && len < maxlen) {
c &= 0x7f;
csum += c;
*p++ = c;
len++;
}
csum &= 0xff;
*p = '\0';
if (len >= maxlen) {
PUTC(KGDB_BADP);
continue;
}
csum -= digit2i(GETC()) * 16;
csum -= digit2i(GETC());
if (csum == 0) {
PUTC(KGDB_GOODP);
/* Sequence present? */
if (bp[2] == ':') {
PUTC(bp[0]);
PUTC(bp[1]);
len -= 3;
kgdb_copy(bp + 3, bp, len);
}
break;
}
PUTC(KGDB_BADP);
} while (1);
#ifdef DEBUG_KGDB
printf("kgdb_recv: %s\n", bp);
#endif
return (len);
}
示例8: SKIPWS
static ZZJSON *parse_value(ZZJSON_CONFIG *config) {
ZZJSON *retval = NULL;
int c;
SKIPWS();
c = GETC();
UNGETC(c);
switch (c) {
case '"': retval = parse_string2(config); break;
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9': case '-':
retval = parse_number(config); break;
case '{': retval = parse_object(config); break;
case '[': retval = parse_array(config); break;
case 't': retval = parse_true(config); break;
case 'f': retval = parse_false(config); break;
case 'n': retval = parse_null(config); break;
}
if (!retval) {
ERROR("value: invalid value");
return retval;
}
return retval;
}
示例9: wordcount
void
wordcount(FILE_TYPE file, long *result)
{
int c;
long linec, wordc, charc;
int inword = 0;
linec = wordc = charc = 0;
while ((c = GETC(file)) != EOF) {
charc++;
if (c == '\n')
linec++;
if (isspace(c)) {
if (inword)
inword = 0;
} else {
if (!inword) {
inword = 1;
wordc++;
}
}
}
result[0] = linec;
result[1] = wordc;
result[2] = charc;
}
示例10: Lfinish
Lfinish(int ch, int dot, int *rvp)
#endif
{
char *s, *se;
static char what[] = "namelist input";
s = nmLbuf + 2;
se = nmLbuf + sizeof(nmLbuf) - 1;
*s++ = ch;
while(!issep(GETC(ch)) && ch!=EOF) {
if (s >= se) {
nmLbuf_ovfl:
return *rvp = err__fl(f__elist->cierr,131,what);
}
*s++ = ch;
if (ch != '=')
continue;
if (dot)
return *rvp = err__fl(f__elist->cierr,112,what);
got_eq:
*s = 0;
nmL_getc_save = l_getc;
l_getc = nmL_getc;
nmL_ungetc_save = l_ungetc;
l_ungetc = nmL_ungetc;
nmLbuf[1] = *(nmL_next = nmLbuf) = ',';
*rvp = f__lcount = 0;
return 1;
}
if (dot)
goto done;
for(;;) {
if (s >= se)
goto nmLbuf_ovfl;
*s++ = ch;
if (!isblnk(ch))
break;
if (GETC(ch) == EOF)
goto done;
}
if (ch == '=')
goto got_eq;
done:
Ungetc(ch, f__cf);
return 0;
}
示例11: scanerror
/* scanerror -- called for lexical errors */
static void scanerror(char *s) {
int c;
/* TODO: check previous character? rc's last hack? */
while ((c = GETC()) != '\n' && c != EOF)
;
goterror = TRUE;
yyerror(s);
}
示例12: rd_int
int
rd_int(double *x)
{ int ch,sign=0,i;
double y;
i=0;
y=0;
if(GETC(ch)=='-') sign = -1;
else if(ch=='+') sign=0;
else ungetc(ch,cf);
while(isdigit(GETC(ch)))
{ i++;
y=10*y+ch-'0';
}
ungetc(ch,cf);
if(sign) y = -y;
*x = y;
return(y!=0?i:sign);
}
示例13: getfds
static Boolean getfds(int fd[2], int c, int default0, int default1) {
int n;
fd[0] = default0;
fd[1] = default1;
if (c != '[') {
UNGETC(c);
return TRUE;
}
if ((unsigned int) (n = GETC() - '0') > 9) {
scanerror("expected digit after '['");
return FALSE;
}
while ((unsigned int) (c = GETC() - '0') <= 9)
n = n * 10 + c;
fd[0] = n;
switch (c += '0') {
case '=':
if ((unsigned int) (n = GETC() - '0') > 9) {
if (n != ']' - '0') {
scanerror("expected digit or ']' after '='");
return FALSE;
}
fd[1] = CLOSED;
} else {
while ((unsigned int) (c = GETC() - '0') <= 9)
n = n * 10 + c;
if (c != ']' - '0') {
scanerror("expected ']' after digit");
return FALSE;
}
fd[1] = n;
}
break;
case ']':
break;
default:
scanerror("expected '=' or ']' after digit");
return FALSE;
}
return TRUE;
}
示例14: getpw
int
getpw(uid_t uid, char buf[])
{
int n, c;
char *bp;
FILE *fp;
rmutex_t *lk;
if (pwf == NULL) {
fp = fopen(PASSWD, "rF");
lmutex_lock(&_pwlock);
if (pwf == NULL) {
if ((pwf = fp) == NULL) {
lmutex_unlock(&_pwlock);
return (1);
}
fp = NULL;
}
lmutex_unlock(&_pwlock);
if (fp != NULL) /* someone beat us to it */
(void) fclose(fp);
}
FLOCKFILE(lk, pwf);
_rewind_unlocked(pwf);
for (;;) {
bp = buf;
while ((c = GETC(pwf)) != '\n') {
if (c == EOF) {
FUNLOCKFILE(lk);
return (1);
}
*bp++ = (char)c;
}
*bp = '\0';
bp = buf;
n = 3;
while (--n)
while ((c = *bp++) != ':')
if (c == '\n') {
FUNLOCKFILE(lk);
return (1);
}
while ((c = *bp++) != ':')
if (isdigit(c))
n = n*10+c-'0';
else
continue;
if (n == uid) {
FUNLOCKFILE(lk);
return (0);
}
}
}
示例15: getname
static int getname(register char *s, int slen)
{
register char *se = s + slen - 1;
register int ch;
GETC(ch);
if (!(*s++ = Alpha[ch & 0xff])) {
if (ch != EOF)
ch = 115;
errfl(f__elist->cierr, ch, "namelist read");
}
while(*s = Alphanum[GETC(ch) & 0xff])
if (s < se)
s++;
if (ch == EOF)
err(f__elist->cierr, EOF, "namelist read");
if (ch > ' ')
Ungetc(ch,f__cf);
return *s = 0;
}