// scan comments // they are effectively ignored i.e. not included in the parse output void rcomment() { // comments in oberon are (* ..... *) // also there can be nested comments // start this method when (* already found char temp; // nextchar was already called so on first char in comment int clev = 0; // comment level 0 is first level while( true) { temp = ch; nextchar(); if (temp == '(' && ch == '*') { ++ clev; nextchar(); } if (temp == '*' && ch == ')') { -- clev; if (clev < 0) break; } if( ch == EOF) // uh oh { error( invalid_sym, 45); exit( 0); } } nextchar(); } // end rcomment
void skip_decl(void) { char c; int done = 0; while (!done) { if ((c = nextchar()) == 0) { Swig_error(cparse_file,cparse_line,"Missing semicolon. Reached end of input.\n"); return; } if (c == '{') { last_brace = num_brace; num_brace++; break; } yylen = 0; if (c == ';') done = 1; } if (!done) { while (num_brace > last_brace) { if ((c = nextchar()) == 0) { Swig_error(cparse_file,cparse_line,"Missing '}'. Reached end of input.\n"); return; } if (c == '{') num_brace++; if (c == '}') num_brace--; yylen = 0; } } }
Expression parseAtom() { char id[MAXIDENTNAMELENGTH]; int i=0; /* identifier/true/false */ if (!isalpha(curchar)) { showLocation(); printf("parse error, expected false, true, identifier or (expression)\n"); exit(EXIT_FAILURE); } while ((i < MAXIDENTNAMELENGTH) && (isalnum(curchar))) { id[i++] = curchar; nextchar(FALSE); } id[i] = '\0'; if (i > MAXIDENTNAMELENGTH) { printf("Error: identifier (%s..) too long ", id); printf("(maximum length is %d characters)\n", MAXIDENTNAMELENGTH); exit(EXIT_FAILURE); } id[i] = '\0'; if ((curchar == ' ') || (curchar == '\t') || (curchar == '\n')) { nextchar(TRUE); } return makeIdentifier(id); }
/* * move the cursor right one character */ void CHtmlInputBuf::move_right(int extend, int word) { size_t idx; /* if not already showing the caret, make it visible again */ show_caret(); /* if we're already at the end of the command, there's nothing to do */ if (caret_ == len_) return; /* see if we're doing a word or a character */ if (word) { /* move right until we find a space */ idx = caret_; while (idx < len_ && !is_space(buf_[idx])) idx = nextchar(idx); /* move right until we find something other than a space */ while (idx < len_ && isspace(buf_[idx])) idx = nextchar(idx); } else { /* move by one character */ idx = nextchar(caret_); } /* adjust selection */ adjust_sel(idx, extend); }
void match(char *str) { int i; if (curchar != str[0]) matchFailure(str); for (i=1; str[i] != '\0'; i++) { if (nextchar(FALSE) != str[i]) matchFailure(str); } nextchar(TRUE); }
yylex() { register c; int i; if (pass == PASS_1) { /* scan the input file */ do c = nextchar(); while (isspace(c) && c != '\n'); if (ISALPHA(c)) c = inident(c); else if (isdigit(c)) c = innumber(c); else switch (c) { case '=': case '<': case '>': case '|': case '&': c = induo(c); break; case ASC_SQUO: case ASC_DQUO: c = instring(c); break; case ASC_COMM: do c = nextchar(); while (c != '\n' && c != '\0'); break; case CTRL('A'): c = CODE1; readcode(1); break; case CTRL('B'): c = CODE2; readcode(2); break; case CTRL('C'): c = CODE4; readcode(4); break; } /* produce the intermediate token file */ if (c <= 0) return(0); if (c <= 127) putc(c, tempfile); else putval(c); } else { /* read from intermediate token file */ c = getc(tempfile); if (c == EOF) return(0); if (c > 127) { c += 128; c = getval(c); } } return(c); }
// check if assignment statement := void idassign() { sym = colon; nextchar(); if ( ch == '=') { sym = assign; nextchar(); } } // end idassign
static int cutint(int fd) { int c; int n = 0; do { c = nextchar(fd); } while (isspace(c)); while (isdigit(c)) { n = n * 10 + c - '0'; c = nextchar(fd); } return n; }
// check if relational operator with 2 chars // this will be >= or <= void idrelop() { sym = spsym[ ch]; nextchar(); if ( sym == lt && ch == '=') { sym = lte; nextchar(); } else if (sym == gt && ch == '=') { sym = gte; nextchar(); } } // end idrelop
void SwigScanner_skip_line(SwigScanner *s) { char c; int done = 0; Clear(s->text); Setfile(s->text,Getfile(s->str)); Setline(s->text,Getline(s->str)); while (!done) { if ((c = nextchar(s)) == 0) return; if (c == '\\') c = nextchar(s); else if (c == '\n') done = 1; } return; }
// scan a string " char* " or ' char* ' void scanstr() { strlength = 0; do { do { nextchar(); char temp = ' '; if ( ch == '\\') { temp = '\\'; nextchar(); } if ( ch == EOF) { error( string, 50); // missing "" for the string exit( 0); // end the program } if ( temp == '\\') // don't get rid of actual metachars { if ( ch == 't') ch = '\t'; else if ( ch == 'n') ch = '\n'; else if ( ch == '\r') ch = '\r'; } strbuff[ strlength] = ch; ++ strlength; if (temp == '\\' && ch == strToMatch) // not end of string ch = ' '; } while( ch != strToMatch); nextchar(); } while( ch == strToMatch); strbuff[ --strlength] = '\0'; // null character to end the string // also last char is not in the string (it's the quote) if (strlength == 1) sym = CHAR_SYM; // a single char is a char instead of a string else sym = string; } // end scanstr
char *ppm_load(char *path, int *h, int *w) { char *d; int fd = open(path, O_RDONLY); if (fd < 0 || nextchar(fd) != 'P' || nextchar(fd) != '6') return NULL; *w = cutint(fd); /* image width */ *h = cutint(fd); /* image height */ cutint(fd); /* max color val */ d = malloc(*h * *w * 3); read(fd, d, *h * *w * 3); close(fd); return d; }
int caccept(int addr, cell count, int up) { int c; int p; if (isinteractive()) { linemode(); } // Uses the operating system's terminal driver to do the line editing for (p = addr; count > 0; count--) { c = nextchar(); if (c == '\n' || c == EOF) { break; } CHARS(p++) = c; } if (isinteractive()) { // We must do this because the terminal driver does the echoing, // and the 'return' that ends the line puts the cursor at column 0 V(NUM_OUT) = 0; } return ((cell)(p - addr)); }
static /*err*/int parse_integer(parser_t * parser, int c) { int err; int value = c - '0'; for (;;) { c = peekchar(&parser->buffer); if ('0' <= c && c <= '9') { c = nextchar(&parser->buffer); if (value > INT_MAX/10) { print_error(parser, "integer value too large\n"); return EOVERFLOW; } value *= 10; if (value > INT_MAX - (c - '0')) { print_error(parser, "integer value too large\n"); return EOVERFLOW; } value += c - '0'; } else { break; } } err = matchinteger_parser(parser, value); return err; }
static int vyyerror(char *fmt, va_list ap) { extern char *cmdname; char msgbuf[1024]; /* if (synerr) return; */ vsnprintf(msgbuf, sizeof msgbuf, fmt, ap); /* for debugging */ va_end(ap); if (!batch) writemessage(msgbuf, 12, 1); fprintf(stderr, "%s: %s\n", cmdname, msgbuf); if (curfile->fin != NULL) { fprintf(stderr, " near line %d, file %s\n", curfile->lineno, curfile->fname); eprint(); synerr = 1; #if 0 while (srcp > src) /* If not at level of original input, */ nextchar(); /* skip until we are. This is an attempt */ /* to clean up the buffers. -- DBK */ #endif } #if 1 if (curfile->fin == NULL) { /* see if this works */ eprint(); synerr = 1; } #endif errno = 0; return 0; }
void Buffer::update(int ch) { switch (ch) { case KEY_UP: prevline(); break; case KEY_DOWN: nextline(); break; case KEY_RIGHT: nextchar(); break; case KEY_LEFT: prevchar(); break; case KEY_HOME: begofline(); break; case KEY_END: endofline(); break; case 127: delchar(); break; case '\n': case '\r': newline(); break; default: addchar(ch); } }
void CGramAly::N1_bool_expr() { if (m_Shrase.at(m_pos).type == ">") { cmpshrase(">"); ST_to("O"); } else if (m_Shrase.at(m_pos).type == "<") { cmpshrase("<"); ST_to("O"); } else if (m_Shrase.at(m_pos).type == ">=") { cmpshrase(">="); ST_to("O"); } else if (m_Shrase.at(m_pos).type == "<=") { cmpshrase("<="); ST_to("O"); } else if (m_Shrase.at(m_pos).type == "==") { nextchar(); ST_to("O"); } else if (m_Shrase.at(m_pos).type == "!=") { cmpshrase("!="); ST_to("O"); } else if (infrfl(m_Shrase.at(m_pos).type, FL_N1)) return; else error(1,"N1"); }
// build identifier // this method is called when it's already an ident // so, char (char | dig)* void bldident() { // clear old ident int k; for ( k = 0; k < idbuffsize; ++ k) idbuff[ k] = '\0'; k = 0; // number of chars in the ident do // read in chars into ident while they're numbers or letters { if (k < idbuffsize) { idbuff[ k] = ch; ++ k; } // end if nextchar(); } while (( inDigits(ch) || inLetters(ch))); if (k >= idlen) idlen = k; else // new ident shorter than old ident so rewrite end of buffer { do { idbuff[ idlen] = '\0'; // write blanks over leftover chars -- idlen; } while (idlen != k); } // end else // don't convert to lowercase b/c Oberon is case sensitive!!! } // end bldident
// skip separators at the beginning of the line // recall separators are whitespace, \n, \t, \r void skipsep() { while (inSeparators( ch)) { nextchar(); } }
void Buffer::newline() { string new_line = m_lines[m_cur.y].substr(m_cur.x); m_lines[m_cur.y].erase(m_cur.x); auto new_pos = m_lines.begin() + m_cur.y + 1; m_lines.insert(new_pos, new_line); nextchar(); }
void echo (void) { int c; mtch = tail; if ((c = nextchar ()) != EOF) { accept (); putchar (c); } }
int match (char *str) { int c; unsigned char *s = (unsigned char *) str; mtch = tail; while (*s && *s == nextchar ()) s++; if (*s) mtch = tail; return !*s; }
size_t count_characters(size_t size, const utf8 chars) { utf8index p = 0; size_t c = 0; while ((p = nextchar(chars, p)) <= size) { c++; } return c; }
/* *---------------------------------------------------------------------- * findfile-- * Finds a file in a : separated list of paths. ~ expansion is also * done. * * Returns: * The complete path for the file (in a newly allocated string) or * NULL if the file was not found. * * Side effects: * A new string is allocated. It must be freed later. * *---------------------------------------------------------------------- */ char* wfindfile(char *paths, char *file) { char *path; char *tmp, *tmp2; int len, flen; char *fullpath; if (!file) return NULL; if (*file=='/' || *file=='~' || *file=='$' || !paths || *paths==0) { if (access(file, F_OK)<0) { fullpath = wexpandpath(file); if (!fullpath) return NULL; if (access(fullpath, F_OK)<0) { wfree(fullpath); return NULL; } else { return fullpath; } } else { return wstrdup(file); } } flen = strlen(file); tmp = paths; while (*tmp) { tmp = skipchar(tmp, ':'); if (*tmp==0) break; tmp2 = nextchar(tmp, ':'); len = tmp2 - tmp; path = wmalloc(len+flen+2); path = memcpy(path, tmp, len); path[len]=0; if (path[len-1] != '/') strcat(path, "/"); strcat(path, file); fullpath = wexpandpath(path); wfree(path); if (fullpath) { if (access(fullpath, F_OK)==0) { return fullpath; } wfree(fullpath); } tmp = tmp2; } return NULL; }
static void lex_mltln_comment(secd_parser_t *p) { while (true) { nextchar(p); switch (p->lc) { case '"': lexstring(p); break; case '#': if (nextchar(p) == '|') lex_mltln_comment(p); break; case '|': if (nextchar(p) == '#') { nextchar(p); return; } break; } } }
static inline /*char*/int peekchar(buffer_t * buffer) { int c = nextchar(buffer); if (c) { -- buffer->off; -- buffer->col; } return c; }
bool strcpy(char * dest) { int i = 0; do { int byte = nextchar(); if(byte == EOF) return false; *dest = (char) byte; i--; } while(*dest++); skip(i); //Seek back return true; }
int strcmp(const char * data) { int i = 0; int byte; do { byte = nextchar(); if(byte == EOF) return -1; i--; } while(*data++ && (char)byte == *(data-1)); skip(i); //Seek back return byte - *(data-1); }
size_t strlen() { size_t i = (size_t)-1; int byte; do { byte = nextchar(); if(byte == EOF) return -1; i++; } while(byte); skip(-(int)i-1); //Seek back return i; }
int dwb_input(void) { register int c; if (thru && begin) { do_thru(); begin = 0; } c = nextchar(); if (ep >= ebuf + sizeof ebuf) ep = ebuf; return *ep++ = c; }