static char * rbody(Biobuf *in) { Bufblock *buf; int r, lastr; char *p; lastr = '\n'; buf = newbuf(); for(;;) { r = Bgetrune(in); if (r < 0) break; if (lastr == '\n') { if (r == '#') rinsert(buf, r); else if (r != ' ' && r != '\t') { Bungetrune(in); break; } } else rinsert(buf, r); lastr = r; if (r == '\n') mkinline++; } insert(buf, 0); p = strdup(buf->start); freebuf(buf); return p; }
/* * Input an escaped token. Possible escape chars are single-quote, * double-quote and backslash. Only the first is a valid escape for * rc; the others are just inserted into the receiving buffer. */ int escapetoken(Biobuf *bp, Bufblock *buf, int preserve, int esc) { int c, line; if(esc != '\'') return 1; line = mkinline; while((c = nextrune(bp, 0)) > 0){ if(c == '\''){ if(preserve) rinsert(buf, c); c = Bgetrune(bp); if (c < 0) break; if(c != '\''){ Bungetrune(bp); return 1; } } rinsert(buf, c); } SYNERR(line); fprint(2, "missing closing %c\n", esc); return 0; }
/* * Assemble a line skipping blank lines, comments, and eliding * escaped newlines */ int assline(Biobuf *bp, Bufblock *buf) { int c; int lastc; buf->current=buf->start; while ((c = nextrune(bp, 1)) >= 0){ switch(c) { case '\r': /* consumes CRs for Win95 */ continue; case '\n': if (buf->current != buf->start) { insert(buf, 0); return 1; } break; /* skip empty lines */ case '\\': case '\'': case '"': rinsert(buf, c); if (escapetoken(bp, buf, 1, c) == 0) Exit(); break; case '`': if (bquote(bp, buf) == 0) Exit(); break; case '#': lastc = '#'; while ((c = Bgetc(bp)) != '\n') { if (c < 0) goto eof; if(c != '\r') lastc = c; } mkinline++; if (lastc == '\\') break; /* propagate escaped newlines??*/ if (buf->current != buf->start) { insert(buf, 0); return 1; } break; default: rinsert(buf, c); break; } } eof: insert(buf, 0); return *buf->start != 0; }
TREENODE *rinsert(TREENODE *subroot, VECTOR *vp, int level){ if(subroot == NULL){ /* we hit the bottom of the tree */ subroot = talloc(); subroot->pvec = veccopy(vp); return(subroot); } if( (vp->vec)[level] <= ((subroot->pvec)->vec)[level] ){ subroot->left = rinsert(subroot->left, vp, (level+1) % (vp->len) ); }else{ subroot->right = rinsert(subroot->right, vp, (level+1) % (vp->len) ); } return(subroot); /* although it didn't change */ }
common::sfv_t eigen_feature_mapper::revert(const eigen_svec_t& src) const { common::sfv_t ret; for (eigen_svec_t::InnerIterator it(src); it; ++it) { rinsert(std::make_pair(it.row(), static_cast<float>(it.value())), ret); } return ret; }
/* * extract a variable name */ static Bufblock* varname(char **s) { Bufblock *b; char *cp; Rune r; int n; b = newbuf(); cp = *s; for(;;){ n = chartorune(&r, cp); if (!WORDCHR(r)) break; rinsert(b, r); cp += n; } if (b->current == b->start){ SYNERR(-1); fprint(2, "missing variable name <%s>\n", *s); freebuf(b); return 0; } *s = cp; insert(b, 0); return b; }
TREENODE *insert(TREENODE *subroot, VECTOR *vp){ #ifdef DEBUG printf("tree insert was called with \n"); vecprint(vp); #endif return( rinsert(subroot, vp, 0) ); }
node *rinsert(node *p, int t){ if (p->val < t){ p->next = rinsert(p->next, t); } else if (p->val > t){ p = new node(t, p); n++; } return p; }
/* * extract an escaped token. Possible escape chars are single-quote, * double-quote,and backslash. Only the first is valid for rc. the * others are just inserted into the receiving buffer. */ char* expandquote(char *s, Rune r, Bufblock *b) { if (r != '\'') { rinsert(b, r); return s; } while(*s){ s += chartorune(&r, s); if(r == '\'') { if(*s == '\'') s++; else return s; } rinsert(b, r); } return 0; }
/* * copy a quoted string; s points to char after opening quote */ static char * copysingle(char *s, Rune q, Bufblock *buf) { Rune r; while(*s){ s += chartorune(&r, s); rinsert(buf, r); if(r == q) break; } return s; }
/* * extract an escaped token. Possible escape chars are single-quote, * double-quote,and backslash. */ static char* shexpandquote(char *s, Rune esc, Bufblock *b) { Rune r; if (esc == '\\') { s += chartorune(&r, s); rinsert(b, r); return s; } while(*s){ s += chartorune(&r, s); if(r == esc) return s; if (r == '\\') { rinsert(b, r); s += chartorune(&r, s); } rinsert(b, r); } return 0; }
/* * Input an escaped token. Possible escape chars are single-quote, * double-quote and backslash. */ static int shescapetoken(Biobuf *bp, Bufblock *buf, int preserve, int esc) { int c, line; if(esc == '\\') { c = Bgetrune(bp); if(c == '\r') c = Bgetrune(bp); if (c == '\n') mkinline++; rinsert(buf, c); return 1; } line = mkinline; while((c = nextrune(bp, 0)) >= 0){ if(c == esc){ if(preserve) rinsert(buf, c); return 1; } if(c == '\\') { rinsert(buf, c); c = Bgetrune(bp); if(c == '\r') c = Bgetrune(bp); if (c < 0) break; if (c == '\n') mkinline++; } rinsert(buf, c); } SYNERR(line); fprint(2, "missing closing %c\n", esc); return 0; }
/* * check for quoted strings. backquotes are handled here; single quotes above. * s points to char after opening quote, q. */ static char * shcopyq(char *s, Rune q, Bufblock *buf) { if(q == '\'' || q == '"') /* copy quoted string */ return copysingle(s, q, buf); if(q != '`') /* not quoted */ return s; while(*s){ /* copy backquoted string */ s += chartorune(&q, s); rinsert(buf, q); if(q == '`') break; if(q == '\'' || q == '"') s = copysingle(s, q, buf); /* copy quoted string */ } return s; }
/* * assemble a back-quoted shell command into a buffer */ static int bquote(Biobuf *bp, Bufblock *buf) { int c, line, term, depth; int start; line = mkinline; while((c = Bgetrune(bp)) == ' ' || c == '\t') ; if(c == '{'){ term = '}'; /* rc style */ while((c = Bgetrune(bp)) == ' ' || c == '\t') ; } else term = '`'; /* sh style */ depth = 1; start = buf->current-buf->start; for(;c > 0; c = nextrune(bp, 0)){ if(c == '{' && term == '}') depth++; if(c == term && --depth == 0){ insert(buf, '\n'); insert(buf,0); buf->current = buf->start+start; execinit(); execsh(0, buf->current, buf, envy); return 1; } if(c == '\n') break; if(c == '\'' || c == '"' || c == '\\'){ insert(buf, c); if(!escapetoken(bp, buf, 1, c)) return 0; continue; } rinsert(buf, c); } SYNERR(line); fprint(2, "missing closing %c after `\n", term); return 0; }
TREENODE *insert(TREENODE *subroot, VECTOR *vp){ return( rinsert(subroot, vp, 0) ); }
void insert(int t){ head = rinsert(head, t); }
void insert(int t){ int i = t / (1 + maxval / bins); bin[i] = rinsert(bin[i], t); }
void IntegerSetInterface::insert(int t){ head = rinsert(head, t); }