void tm_saveevent( void ) /***********************/ { int i; int c; if( new_sample ) { tm_error(); return; } switch( MouseType ) { case M_NONE: /* eat the remainder of the version ID response. */ for( ;; ) { c = nextc( 20 ); if( c == -1 ) return; if( c == 't' ) break; } if( strstr( GetTermType(), "qnx" ) != 0 ) { DoMouseInit( M_QW, QNX_HDR QW_INIT, QNX_HDR "3" ); } else { DoMouseInit( M_AW, ANSI_HDR QW_INIT, ANSI_HDR "3" ); } return; case M_QW: case M_AW: for( i = 0; i < MAXBUF; ++i ) { c = nextc( 20 ); if( c == -1 ) { tm_error(); return; } buf[i] = c; if( buf[i] == 't' ) break; if( buf[i] == '\x1b' ) { tm_error(); c = nextc( 20 ); if( c == -1 ) { tm_error(); return; } i = 0; } } break; case M_XT: for( i = 0; i < 3; ++i ) { c = nextc( 10 ); if( c == -1 ) { tm_error(); return; } buf[i] = c; } break; } if( i == MAXBUF ) tm_error(); buf[i+1] = '\0'; new_sample = 1; }
String* getregexp(int delim) { String *buf, *r; int i, c; buf = allocstring(0); for(i=0; ; i++){ if((c = getch())=='\\'){ if(nextc()==delim) c = getch(); else if(nextc()=='\\'){ Straddc(buf, c); c = getch(); } }else if(c==delim || c=='\n') break; if(i >= RBUFSIZE) editerror("regular expression too long"); Straddc(buf, c); } if(c!=delim && c) ungetch(); if(buf->n > 0){ patset = TRUE; freestring(lastpat); lastpat = buf; }else freestring(buf); if(lastpat->n == 0) editerror("no regular expression defined"); r = newstring(lastpat->n); runemove(r->r, lastpat->r, lastpat->n); /* newstring put \0 at end */ return r; }
String* /* BUGGERED */ getregexp(int delim) { String *r = newre(); int c; for(Strzero(&genstr); ; Straddc(&genstr, c)) if((c = getch())=='\\'){ if(nextc()==delim) c = getch(); else if(nextc()=='\\'){ Straddc(&genstr, c); c = getch(); } }else if(c==delim || c=='\n') break; if(c!=delim && c) ungetch(); if(genstr.n > 0){ patset = TRUE; Strduplstr(&lastpat, &genstr); Straddc(&lastpat, '\0'); } if(lastpat.n <= 1) error(Epattern); Strduplstr(r, &lastpat); return r; }
static void copycurl( void ) { do { while( ch != '%' && ch != EOF ) { fputc( ch, actout ); nextc(); } } while( nextc() != '}' && ch != EOF ); nextc(); }
void colon(char *addr, char *cp) { int argc; char *argv[100]; char tbuf[512]; cp = nextc(cp); switch(*cp) { default: Bprint(bioout, "?\n"); return; case 'b': breakpoint(addr, cp+1); return; case 'd': delbpt(addr); return; /* These fall through to print the stopped address */ case 'r': reset(); argc = buildargv(cp+1, argv, 100); initstk(argc, argv); count = 0; atbpt = 0; run(); break; case 'c': count = 0; atbpt = 0; run(); break; case 's': cp = nextc(cp+1); count = 0; if(*cp) count = strtoul(cp, 0, 0); if(count == 0) count = 1; atbpt = 0; run(); break; } dot = reg.pc; Bprint(bioout, "%s at #%lux ", atbpt ? "breakpoint" : "stopped", dot); symoff(tbuf, sizeof(tbuf), dot, CTEXT); Bprint(bioout, tbuf); if(fmt == 'z') printsource(dot); Bprint(bioout, "\n"); }
/* get IDENT after '$' ... match rules for IDENT in main scanner */ static int get_ident(char *namebuf) { int c; int d = 0; int i; char *namebuf_start = namebuf; c = nextc(); if (c == '\'') { d = c; c = nextc(); } if (!isalpha(c)) { fprintf(stderr, "macro name must begin with an alphabetic (not '%c')\n", c); lexSync(); return 0; } i = 0; do { if (c == '\\') c = nextc(); *namebuf++ = c; i++; c = nextc(); } while (i < LEX_MAX && c != EOF && (isalpha(c) || isdigit(c) || c == '_' || (d && c != d))); if (i == LEX_MAX) { namebuf_start[20] = '\0'; fprintf(stderr, "macro name too long: $%s...\n", namebuf_start); lexSync(); return 0; } if (c == EOF) { *namebuf = '\0'; fprintf(stderr, "unexpected end of file in macro name: $%s\n", namebuf_start); lexSync(); return 0; } if (!d) prevc(c); *namebuf = '\0'; #if PCP_DEBUG if (pmDebug & DBG_TRACE_APPL0) fprintf(stderr, "get_ident() -> macro name \"%s\"\n", namebuf_start); #endif return 1; }
/* For METAR, check if the HHMMZ time string is present */ static int whas_yyggZ(xbuf *buf) { int ch; /* skip white space */ do{ ch = nextc(buf); }while((isascii(ch) && !isgraph(ch))); unnextc(buf,ch); if(buf->cnt < 4) { return 0; /* not enough characters */ } else if(buf->get[4] == 'Z' || buf->get[6] == 'Z' ) { return 1; } else if( isdigit(buf->get[3]) && isdigit(buf->get[2]) && isdigit(buf->get[1]) && isdigit(buf->get[0])) { return 1; } else if( isdigit(buf->get[5]) && isdigit(buf->get[4]) && isdigit(buf->get[3]) && isdigit(buf->get[2]) && isdigit(buf->get[1]) && isdigit(buf->get[0])) { return 1; } return 0; /* failed */ }
String * collecttext(void) { String *s; int begline, i, c, delim; s = newstring(0); if(cmdskipbl()=='\n'){ getch(); i = 0; do{ begline = i; while((c = getch())>0 && c!='\n') i++, Straddc(s, c); i++, Straddc(s, '\n'); if(c < 0) goto Return; }while(s->r[begline]!='.' || s->r[begline+1]!='\n'); s->r[s->n-2] = '\0'; s->n -= 2; }else{ okdelim(delim = getch()); getrhs(s, delim, 'a'); if(nextc()==delim) getch(); atnl(); } Return: return s; }
void breakpoint(char *addr, char *cp) { Breakpoint *b; int type; cp = nextc(cp); type = Instruction; switch(*cp) { case 'r': membpt++; type = Read; break; case 'a': membpt++; type = Access; break; case 'w': membpt++; type = Write; break; case 'e': membpt++; type = Equal; break; } b = emalloc(sizeof(Breakpoint)); b->addr = expr(addr); b->type = type; b->count = cmdcount; b->done = cmdcount; b->next = bplist; bplist = b; }
static void cswitch(char *dst, int *dn, const char *src, int *sn) { int c; #ifdef MB if (mb_cur_max > 1) { nextc(c, src, *sn); if (c & INVBIT) { *dst = *src; *dn = *sn = 1; } else { if (iswupper(c)) c = towlower(c); else if (iswlower(c)) c = towupper(c); if ((*dn = wctomb(dst, c)) > *sn) { *dst = *src; *dn = *sn = 1; } } } else #endif /* MB */ { c = *src & 0377; if (isupper(c)) *dst = tolower(c); else if (islower(c)) *dst = toupper(c); else *dst = c; *dn = *sn = 1; } }
/* * scan for literal string. (up to 16 chars) * If it is there, swallow it, return !0; * else, back up and return 0; */ int hasSTR( xbuf *buf, char *str) { int ii; int cbuf[16]; for(ii = 0; ii < 16 ; ii++ ) { if(str[ii] == 0) break; /* success */ cbuf[ii] = nextc(buf); if(cbuf[ii] != str[ii]) { /* unwind */ while( ii >= 0 ) { if(cbuf[ii] != EOB) unnextc(buf, cbuf[ii]); ii--; } return 0; } } return !0; }
void setreg(char *addr, char *cp) { int rn; dot = expr(addr); cp = nextc(cp); if(strcmp(cp, "pc") == 0) { reg.pc = dot; return; } if(strcmp(cp, "sp") == 0) { reg.r[1] = dot; return; } if(strcmp(cp, "y") == 0) { reg.Y = dot; return; } if(strcmp(cp, "psr") == 0) { reg.psr = dot; return; } if(*cp++ == 'r') { rn = strtoul(cp, 0, 10); if(rn > 0 && rn < 32) { reg.r[rn] = dot; return; } } Bprint(bioout, "bad register\n"); }
String * collecttext(void) { String *s = newstring(); int begline, i, c, delim; if(skipbl()=='\n'){ getch(); i = 0; do{ begline = i; while((c = getch())>0 && c!='\n') i++, Straddc(s, c); i++, Straddc(s, '\n'); if(c < 0) goto Return; }while(s->s[begline]!='.' || s->s[begline+1]!='\n'); Strdelete(s, s->n-2, s->n); }else{ okdelim(delim = getch()); getrhs(s, delim, 'a'); if(nextc()==delim) getch(); atnl(); } Return: Straddc(s, 0); /* JUST FOR CMDPRINT() */ return s; }
/* * get the next numeric token, handle solidus * may NOT have leading white space */ int dget_num( xbuf *buf, int *num, int maxlen) { int ch; int len; int accum = 0; int failnum = -1; for(len = 0; len < maxlen ; len++ ) { ch = nextc(buf); if(!(isascii(ch) && isdigit(ch))) { if( ch == '/' ) /* handle the solidus */ { accum = failnum; continue; } /* else */ unnextc(buf,ch); break; } if(accum) accum *= 10; accum += (ch - '0'); /* N.B. */ } *num = len ? accum : failnum; return ch; }
void quesie(char *p) { int c, count, i; char tbuf[512]; c = 0; symoff(tbuf, sizeof(tbuf), dot, CTEXT); Bprint(bioout, "%s?\t", tbuf); while(*p) { p = nextc(p); if(*p == '"') { for(p++; *p && *p != '"'; p++) { Bputc(bioout, *p); c++; } if(*p) p++; continue; } count = 0; while(*p >= '0' && *p <= '9') count = count*10 + (*p++ - '0'); if(count == 0) count = 1; p = nextc(p); if(*p == '\0') { p[0] = fmt; p[1] = '\0'; } for(i = 0; i < count; i++) { c += pfmt(*p, 1, 0); dot += inc; if(c > width) { Bprint(bioout, "\n"); symoff(tbuf, sizeof(tbuf), dot, CTEXT); Bprint(bioout, "%s?\t", tbuf); c = 0; } } fmt = *p++; p = nextc(p); } Bprint(bioout, "\n"); }
int wskipright(char *line, char *pos) { int c, n; (void)line; nextc(c, pos, n); return n; }
Posn getnum(int signok) { Posn n=0; int c, sign; sign = 1; if(signok>1 && nextc()=='-'){ sign = -1; getch(); } if((c=nextc())<'0' || '9'<c) /* no number defaults to 1 */ return sign; while('0'<=(c=getch()) && c<='9') n = n*10 + (c-'0'); ungetch(); return sign*n; }
/* For METAR, get the bulletin time, if possible */ static void get_wyyggZ(xbuf *buf, dtime *time) { if(!whas_yyggZ(buf)) return; (void)get_yygg(buf, time); (void)nextc(buf); /* eat the 'Z' */ return; }
static int readrepc(unsigned char *buf, ssize_t bsize, int *bat, int fd) { /* read and parse a () count */ int at = *bat; int nextc(void) { if (at < bsize) return buf[at++]; unsigned char c; ssize_t t = read(fd, &c, 1); if (t < 0) die("read error"); if (t == 0) return -1; return c; } int c = 0, ch; ch = nextc(); if (ch != '*' && ch != '%') fail("bad char after (): %c", ch); while (1) { ch = nextc(); if (ch < '0' || ch > '9') break; c = c*10 + (ch - '0'); if (c > MAXCYCLES) { c = MAXCYCLES; ch = 0; break; } } buf[--at] = ch; *bat = at-1; return c; }
/* * Skip white space in buf and * initialize a clone xbuf that starts at buf's * current position and ends just before the next '=' or EOB * Used to extract individual obs from reports which contain multiple obs. */ int get_weqxbuf( xbuf *buf, xbuf *clone) { int ch = 0; /* assert(buf != NULL && clone != NULL ); */ if(buf->cnt == 0 ) return EOB; do{ ch = nextc(buf); }while(Wisspace(ch)); unnextc(buf,ch); if(buf->cnt < 5 ) return EOB; clone->base = buf->get; do { ch = nextc(buf); } while(ch != EQ && ch != RECORD_SEP && ch != EOB); clone->bufsiz = buf->get - clone->base; if(clone->bufsiz < 5) return EOB; /* don't bother */ clone->cnt = (ptrdiff_t) clone->bufsiz; clone->get = clone->base; clone->put = clone->base + clone->bufsiz - 1; /* trim whitespace from end */ while((clone->put >= clone->base) && (Wisspace(*clone->put) || *clone->put == EQ)) { clone->put--; clone->bufsiz--; clone->cnt--; } return(ch > 0 ? ch : ETX); }
/* discard input to next ';' or EOF */ void lexSync(void) { int c; do c = nextc(); while (c != ';' && c != EOF) ; prevc(c); }
EVENT TrieRead( void ) { eTrie *trie; char *buf; int c; int cpos = 0; EVENT ev = EV_UNUSED; int ev_pos = 0; eNode *node; int timeout; buf = alloca( KeyTrieDepth + 1 ); trie = &KeyTrie; buf[0] = '\0'; timeout = 0; for( ;; ) { c = nextc( timeout ); if( c <= 0 ) break; if( c == 256 ) return( EV_MOUSE_PRESS ); buf[cpos++] = c; if( trie->num_child == 0 ) break; node = bsearch( &c, trie->child, trie->num_child, sizeof( eNode ), (int (*)(const void *, const void *))child_comp ); if( node == NULL ) break; if( node->ev != EV_UNUSED ) { ev = node->ev; ev_pos = cpos; } trie = node->trie; if( trie == NULL ) break; timeout = 3; } if( ev == EV_UNUSED ) { ev = buf[0]; ev_pos = 1; } // when we get down here cpos will be the number of chars in buf // note that the nul-char is not considered to actually be there // (the nul is sent on time-outs, and is guaranteed to never appear // in a terminfo keysequence as they are all nul-terminated.) if( cpos > ev_pos ) { nextc_unget( &buf[ev_pos], cpos-ev_pos ); } return( ev ); }
int wskipleft(char *lp, char *pos) { int c, n; do { nextc(c, lp, n); lp += n; } while (lp < pos); return -n; }
int whasSTR( xbuf *buf, char *str) { int ch; do{ ch = nextc(buf); }while(Wisspace(ch)); unnextc(buf,ch); return( hasSTR(buf,str) ); }
char *getname(void) { register char *s, *t; register int c; register char *v; do { c = nextc(); } while(c==' ' || c=='\n' || c=='\t'); s = buf; while(c!=' ' && c!='\t' && c!='\n' && c!=EOF) { *s++ = c; c = nextc(); } *s = '\0'; peekc = c; v = t = alloc(strlen(buf)+1); s = buf; while (*t++ = *s++) ; return (v); }
/* * skip leading white space and get the rest of the line */ int get_wline( xbuf *buf, char *str, int maxlen) { int ch; do{ ch = nextc(buf); }while(ch == SP || ch == '\t'); /* don't soak up CR or NL :-) */ unnextc(buf,ch); return( get_line(buf, str, maxlen) ); }
Posn getnum(void) { Posn n=0; int c; if((c=nextc())<'0' || '9'<c) /* no number defaults to 1 */ return 1; while('0'<=(c=getch()) && c<='9') n = n*10 + (c-'0'); ungetch(); return n; }
/* * skip leading white space, get the next numeric token, handle solidus */ int dget_wnum( xbuf *buf, int *num, int maxlen) { int ch; do{ ch = nextc(buf); }while(Wisspace(ch)); unnextc(buf,ch); return( dget_num(buf, num, maxlen) ); }
/* * skip leading white space, get the next alphanumeric token */ int get_wstr( xbuf *buf, char *str, int maxlen) { int ch; do{ ch = nextc(buf); }while((isascii(ch) && !isgraph(ch))); unnextc(buf,ch); return( get_str(buf, str, maxlen) ); }
int skipline( xbuf *buf, int maxskip) { int ch = 0; do { if(maxskip <= 0) break; ch = nextc(buf); maxskip--; } while(ch != NL && ch != EOB); return ch; }