int lefdata(int i, int c) { int ck; if (i >= nlin) i = nlin - 1; if (ctype(i, c) == 's') { for (ck = c; ctype(i, ck) == 's'; ck--) ; if (thish(i, ck) == 0) return(0); } i = stynum[i]; i = lefline[c][i]; if (i > 0) return(i); if (dboxflg && c == 0) return(2); if (allflg) return(1); if (boxflg && c == 0) return(1); return(0); }
/* * Check and cast arguments for builtins. */ static int acnt(NODE *a, int narg, TWORD *tp) { NODE *q; TWORD t; if (a == NIL) return narg; for (; a->n_op == CM; a = a->n_left, narg--) { if (tp == NULL) continue; q = a->n_right; t = ctype(tp[narg-1]); if (q->n_type == t) continue; a->n_right = ccast(q, t, 0, NULL, 0); } /* Last arg is ugly to deal with */ if (narg == 1 && tp != NULL && a->n_type != tp[0]) { q = talloc(); *q = *a; q = ccast(q, ctype(tp[0]), 0, NULL, 0); *a = *q; nfree(q); } return narg != 1; }
/* Return a pointer to the first character past any legal variable name */ const char * skip_wdvarname(const char *s, /* skip array de-reference? */ bool aok) { if (s[0] == CHAR && ctype(s[1], C_ALPHX)) { do { s += 2; } while (s[0] == CHAR && ctype(s[1], C_ALNUX)); if (aok && s[0] == CHAR && ord(s[1]) == ord('[')) { /* skip possible array de-reference */ const char *p = s; char c; int depth = 0; while (/* CONSTCOND */ 1) { if (p[0] != CHAR) break; c = p[1]; p += 2; if (ord(c) == ord('[')) depth++; else if (ord(c) == ord(']') && --depth == 0) { s = p; break; } } } } return (s); }
lspan(i,c) { int k; if (ctype(i,c) != 's') return(0); c++; if (c < ncol && ctype(i,c)== 's') return(0); for(k=0; ctype(i,--c) == 's'; k++); return(k); }
int oneh(int lin) { int k, icol; k = ctype(lin,0); for(icol=1; icol<ncol; icol++) { if (k != ctype(lin,icol)) return(0); } return(k); }
int domore(char *dataln) { int icol, ch; if (prefix(".TE", dataln)) return(0); if (dataln[0] == '.' && !isdigit((uchar)dataln[1])) { Bprint(&tabout, "%s\n", dataln); return(1); } fullbot[0] = 0; instead[0] = (char *)0; if (dataln[1] == 0) switch (dataln[0]) { case '_': fullbot[0] = '-'; putline(useln, 0); return(1); case '=': fullbot[0] = '='; putline(useln, 0); return(1); } for (icol = 0; icol < ncol; icol++) { table[0][icol].col = dataln; table[0][icol].rcol = 0; for (; (ch = *dataln) != '\0' && ch != tab; dataln++) ; *dataln++ = '\0'; switch (ctype(useln, icol)) { case 'n': table[0][icol].rcol = maknew(table[0][icol].col); break; case 'a': table[0][icol].rcol = table[0][icol].col; table[0][icol].col = ""; break; } while (ctype(useln, icol + 1) == 's') /* spanning */ table[0][++icol].col = ""; if (ch == '\0') break; } while (++icol < ncol) table[0][icol].col = ""; putline(useln, 0); exstore = exspace; /* reuse space for numerical items */ return(1); }
/* * Return a pointer to the first char past a legal variable name * (returns the argument if there is no legal name, returns a pointer to * the terminating NUL if whole string is legal). */ const char * skip_varname(const char *s, bool aok) { size_t alen; if (s && ctype(*s, C_ALPHX)) { do { ++s; } while (ctype(*s, C_ALNUX)); if (aok && ord(*s) == ord('[') && (alen = array_ref_len(s))) s += alen; } return (s); }
makeline(i,c,lintype) { int cr, type, shortl; type = thish(i,c); if (type==0) return; cr=c; shortl = (table[i][c].col[0]=='\\'); if (c>0 && !shortl && thish(i,c-1) == type)return; if (shortl==0) for(cr=c; cr < ncol && (ctype(i,cr)=='s'||type==thish(i,cr)); cr++); else for(cr=c+1; cr<ncol && ctype(i,cr)=='s'; cr++); drawline(i, c, cr-1, lintype, 0, shortl); }
void runtabs(int lform, int ldata) { int c, ct, vforml, lf; fprintf(tabout, ".ta "); for(c=0; c<ncol; c++) { vforml=lform; for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf)) vforml=lf; if (fspan(vforml,c)) continue; switch(ct=ctype(vforml,c)) { case 'n': case 'a': if (table[ldata][c].rcol) if (lused[c]) /*Zero field width*/ fprintf(tabout, "\\n(%du ",c+CMID); case 'c': case 'l': case 'r': if (realsplit? rused[c]: (used[c]+lused[c])) fprintf(tabout, "\\n(%du ",c+CRIGHT); continue; case 's': if (lspan(lform, c)) fprintf(tabout, "\\n(%du ", c+CRIGHT); continue; } } fprintf(tabout, "\n"); }
static bool ctype(CVarRef v, int (*iswhat)(int)) { if (v.isInteger()) { int64_t n = v.toInt64(); if (n <= 255 && n >= 0) { return iswhat(n); } if (n >= -128 && n < 0) { return iswhat(n + 256); } return ctype(v.toString(), iswhat); } if (v.isString()) { String s = v.toString(); if (!s.empty()) { const char *p = s.data(); const char *e = s.data() + s.size(); while (p < e) { if (!iswhat((int)*(unsigned char *)(p++))) { return false; } } return true; } } return false; }
static struct symtab * addstr(char *n) { NODE *p = block(NAME, NIL, NIL, FLOAT, 0, 0); struct symtab *sp; NODE *q; struct attr *ap; struct rstack *rp; extern struct rstack *rpole; p->n_type = ctype(ULONGLONG); rpole = rp = bstruct(NULL, STNAME, NULL); soumemb(p, loti, 0); soumemb(p, hiti, 0); q = dclstruct(rp); sp = q->n_sp = lookup(addname(n), 0); defid(q, TYPEDEF); ap = attr_new(GCC_ATYP_MODE, 3); ap->sarg(0) = addname("TI"); ap->iarg(1) = 0; sp->sap = attr_add(sp->sap, ap); nfree(q); nfree(p); return sp; }
/* print variable/alias value using necessary quotes * (POSIX says they should be suitable for re-entry...) * No trailing newline is printed. */ void print_value_quoted(const char *s) { const char *p; int inquote = 0; /* Test if any quotes are needed */ for (p = s; *p; p++) if (ctype(*p, C_QUOTE)) break; if (!*p) { shprintf("%s", s); return; } for (p = s; *p; p++) { if (*p == '\'') { shprintf("'\\'" + 1 - inquote); inquote = 0; } else { if (!inquote) { shprintf("'"); inquote = 1; } shf_putc(*p, shl_stdout); } } if (inquote) shprintf("'"); }
thrust_rewriter::result_type thrust_rewriter::make_tuple_rewrite(const bind& n) { //The rhs must be an apply assert(detail::isinstance<apply>(n.rhs())); const apply& rhs = boost::get<const apply&>(n.rhs()); //The rhs must apply "thrust::make_tuple" assert(rhs.fn().id() == detail::snippet_make_tuple()); //Derive the types of all the inputs vector<shared_ptr<const ctype::type_t> > typified; for(auto i = rhs.args().begin(); i != rhs.args().end(); i++) { //Argument to make_tuple must be a name or a literal if (detail::isinstance<name>(*i)) { const name& name_i = boost::get<const name&>(*i); typified.push_back( make_shared<const ctype::monotype_t>( detail::typify( name_i.id()))); } else { typified.push_back(i->ctype().ptr()); } } const name& lhs = boost::get<const name&>(n.lhs()); shared_ptr<const name> n_lhs = make_shared<const name>(lhs.id(), lhs.type().ptr(), make_shared<const ctype::tuple_t>( std::move(typified))); return make_shared<const bind>( n_lhs, rhs.ptr()); }
int thish(int i, int c) { int t; char *s; struct colstr *pc; if (c<0)return(0); if (i<0) return(0); t = ctype(i,c); if (t=='_' || t == '-') return('-'); if (t=='=')return('='); if (t=='^') return(1); if (fullbot[i] ) return(fullbot[i]); if (t=='s') return(thish(i,c-1)); if (t==0) return(1); pc = &table[i][c]; s = (t=='a' ? pc->rcol : pc->col); if (s==0 || (point(s) && *s==0)) return(1); if (vspen(s)) return(1); if (t=barent( s)) return(t); return(0); }
template <class F> F CpuIterativeSolver<F>::initGeneral (const std::vector<ctype>& einc, std::ostream& log, const std::vector<ctype>& start, UNUSED Core::ProfilingDataPtr prof) { std::vector<ctype>& pvec = tmpVec1 (); for (int j = 0; j < 3; j++) for (uint32_t i = g ().nvCount (); i < g ().vecStride (); i++) pvec[i + j * g ().vecStride ()] = 0; g ().multMat (matVec ().cc ().cc_sqrt (), einc, pvec); ftype temp = LinAlg::norm (pvec); this->residScale = 1 / temp; ftype inprodR = 0.0 / 0.0; if (start.size () != 0) { std::vector<ctype>& xvec = this->xvec (); g ().multMatInv (matVec ().cc ().cc_sqrt (), start, xvec); // xvec = start / cc_sqrt std::vector<ctype>& Avecbuffer = this->Avecbuffer (); matVec ().apply (xvec, Avecbuffer, false); std::vector<ctype>& rvec = this->rvec (); LinAlg::linComb (Avecbuffer, ctype (-1), pvec, rvec); inprodR = LinAlg::norm (rvec); log << "Use loaded start value" << std::endl; } else { std::vector<ctype>& Avecbuffer = this->Avecbuffer (); matVec ().apply (pvec, Avecbuffer, false); std::vector<ctype>& rvec = this->rvec (); LinAlg::linComb (Avecbuffer, ctype (-1), pvec, rvec); inprodR = LinAlg::norm (rvec); log << "temp = " << temp << ", inprodR = " << inprodR << std::endl; std::vector<ctype>& xvec = this->xvec (); if (temp < inprodR) { log << "Use 0" << std::endl; LinAlg::fill<ctype> (xvec, 0); swap (rvec, pvec); inprodR = temp; } else { log << "Use pvec" << std::endl; swap (xvec, pvec); } } log << "|r_0|^2: " << temp << std::endl; return inprodR; }
bool run(void) { acl::string body; // 从本地文件中加载请求数据 if (acl::ifstream::load(file_, &body) == false) { logger_error("load %s error", file_.c_str()); return false; } // 创建 HTTP 请求客户端 acl::http_request req(server_addr_); // 添加 HTTP 请求头字段 acl::string ctype("text/"); ctype << stype_ << "; charset=" << charset_; acl::http_header& hdr = req.request_header(); // 请求头对象的引用 hdr.set_url("/"); hdr.set_content_type(ctype); // 发送 HTTP 请求数据 if (req.request(body.c_str(), body.length()) == false) { logger_error("send http request to %s error", server_addr_.c_str()); return false; } // 取出 HTTP 响应头的数据字段 const char* p = req.header_value("Content-Type"); if (p == NULL || *p == 0) { logger_error("no Content-Type"); return false; } // 分析 HTTP 响应头的数据类型 acl::http_ctype content_type; content_type.parse(p); // 响应头数据类型的子类型 const char* stype = content_type.get_stype(); bool ret; if (stype == NULL) ret = do_plain(req); else if (strcasecmp(stype, "xml") == 0) ret = do_xml(req); else if (strcasecmp(stype, "json") == 0) ret = do_json(req); else ret = do_plain(req); if (ret == true) printf("read ok!\r\n"); return ret; }
/// Get the charset from the CONTENT_TYPE header string_type charset() { string_type ctype(content_type()); std::size_t pos = ctype.find("charset="); string_type val(ctype.substr(pos+8, ctype.find(";", pos))); boost::algorithm::trim(val); return val.empty() ? BOOST_CGI_DEFAULT_CHARSET : val; }
ctspan(i,c) { int k; c++; for(k=1; c<ncol && ctype(i,c)=='s'; k++) c++; return(k); }
int domore(char *dataln) { int icol, ch; if (prefix(".TE", dataln)) return(0); if (dataln[0] == '.' && !isdigit(dataln[1])) { puts(dataln); return(1); } instead[0]=0; fullbot[0]=0; if (dataln[1]==0) switch(dataln[0]) { case '_': fullbot[0]= '-'; putline(useln,0); return(1); case '=': fullbot[0]= '='; putline(useln, 0); return(1); } for (icol = 0; icol <ncol; icol++) { table[0][icol].col = dataln; table[0][icol].rcol=0; for(; (ch= *dataln) != '\0' && ch != tab; dataln++) ; *dataln++ = '\0'; switch(ctype(useln,icol)) { case 'n': table[0][icol].rcol = (char *)maknew(table[0][icol].col); break; case 'a': table[0][icol].rcol = table[0][icol].col; table[0][icol].col= ""; break; } while (ctype(useln,icol+1)== 's') /* spanning */ table[0][++icol].col = ""; if (ch == '\0') break; } while (++icol <ncol) table[0][icol].col = ""; putline(useln,0); return(1); }
vspand(ir,ij,ifform) { if (ir<0) return(0); if (ir>=nlin)return(0); if (instead[ir]) return(0); if (ifform==0 && ctype(ir,ij)=='^') return(1); if (table[ir][ij].rcol!=0) return(0); if (fullbot[ir]) return(0); return(vspen(table[ir][ij].col)); }
choochar() { /* choose funny characters to delimit fields */ int had[128], ilin,icol, k; char *s; for(icol=0; icol<128; icol++) had[icol]=0; F1 = F2 = 0; for(ilin=0;ilin<nlin;ilin++) { if (instead[ilin]) continue; if (fullbot[ilin]) continue; for(icol=0; icol<ncol; icol++) { k = ctype(ilin, icol); if (k==0 || k == '-' || k == '=') continue; s = table[ilin][icol].col; if (point(s)) while (*s) had[*s++]=1; s=table[ilin][icol].rcol; if (point(s)) while (*s) had[*s++]=1; } } /* choose first funny character */ for( s="\002\003\005\006\007!%&#/?,:;<=>@`^~_{}+-*ABCDEFGHIJKMNOPQRSTUVWXYZabcdefgjkoqrstwxyz"; *s; s++) { if (had[*s]==0) { F1= *s; had[F1]=1; break; } } /* choose second funny character */ for( s="\002\003\005\006\007:_~^`@;,<=>#%&!/?{}+-*ABCDEFGHIJKMNOPQRSTUVWXZabcdefgjkoqrstuwxyz"; *s; s++) { if (had[*s]==0) { F2= *s; break; } } if (F1==0 || F2==0) error("couldn't find characters to use for delimiters"); return; }
midbcol(i,c) { int ct; while ( (ct=ctype(i,c)) == 's') c--; if (ct=='-' || ct == '=') return(ct); if (ct=barent(table[i][c].col)) return(ct); return(0); }
int nodata(int il) { int c; for (c=0; c<ncol;c++) { switch(ctype(il,c)) { case 'c': case 'n': case 'r': case 'l': case 's': case 'a': return(0); } } return(1); }
void SetupCamera::slotEditedCamera(const QString& title, const QString& model, const QString& port, const QString& path) { SetupCameraItem* const item = dynamic_cast<SetupCameraItem*>(d->listView->currentItem()); if (!item) { return; } CameraType ctype(title, model, port, path, 1); item->setCameraType(&ctype); }
int pprompt(const char *cp, int ntruncate) { char delimiter = 0; bool doprint = (ntruncate != -1); bool indelimit = false; int columns = 0, lines = 0; /* * Undocumented AT&T ksh feature: * If the second char in the prompt string is \r then the first * char is taken to be a non-printing delimiter and any chars * between two instances of the delimiter are not considered to * be part of the prompt length */ if (*cp && cp[1] == '\r') { delimiter = *cp; cp += 2; } for (; *cp; cp++) { if (indelimit && *cp != delimiter) ; else if (ctype(*cp, C_CR | C_LF)) { lines += columns / x_cols + ((*cp == '\n') ? 1 : 0); columns = 0; } else if (*cp == '\t') { columns = (columns | 7) + 1; } else if (*cp == '\b') { if (columns > 0) columns--; } else if (*cp == delimiter) indelimit = !indelimit; else if (UTFMODE && (rtt2asc(*cp) > 0x7F)) { const char *cp2; columns += utf_widthadj(cp, &cp2); if (doprint && (indelimit || (ntruncate < (x_cols * lines + columns)))) shf_write(cp, cp2 - cp, shl_out); cp = cp2 - /* loop increment */ 1; continue; } else columns++; if (doprint && (*cp != delimiter) && (indelimit || (ntruncate < (x_cols * lines + columns)))) shf_putc(*cp, shl_out); } if (doprint) shf_flush(shl_out); return (x_cols * lines + columns); }
void choochar(void) { /* choose funny characters to delimit fields */ int had[128], ilin, icol, k; char *s; for (icol = 0; icol < 128; icol++) had[icol] = 0; F1 = F2 = 0; for (ilin = 0; ilin < nlin; ilin++) { if (instead[ilin] || fullbot[ilin]) continue; for (icol = 0; icol < ncol; icol++) { k = ctype(ilin, icol); if (k == 0 || k == '-' || k == '=') continue; s = table[ilin][icol].col; if (point(s)) for (; *s; s++) if((unsigned char)*s < 128) had[(unsigned char)*s] = 1; s = table[ilin][icol].rcol; if (point(s)) for (; *s; s++) if((unsigned char)*s < 128) had[(unsigned char)*s] = 1; } } /* choose first funny character */ for (s = COMMON "Y"; *s; s++) { if (had[(uint8_t)*s] == 0) { F1 = *s; had[F1] = 1; break; } } /* choose second funny character */ for (s = COMMON "u"; *s; s++) { if (had[(uint8_t)*s] == 0) { F2 = *s; break; } } if (F1 == 0 || F2 == 0) error("couldn't find characters to use for delimiters"); }
/* * Used to calculate an array index for global()/local(). Sets *arrayp * to true if this is an array, sets *valp to the array index, returns * the basename of the array. May only be called from global()/local() * and must be their first callee. */ static const char * array_index_calc(const char *n, bool *arrayp, uint32_t *valp) { const char *p; size_t len; char *ap = NULL; *arrayp = false; redo_from_ref: p = skip_varname(n, false); if (innermost_refflag == SRF_NOP && (p != n) && ctype(n[0], C_ALPHX)) { struct tbl *vp; char *vn; strndupx(vn, n, p - n, ATEMP); /* check if this is a reference */ varsearch(e->loc, &vp, vn, hash(vn)); afree(vn, ATEMP); if (vp && (vp->flag & (DEFINED | ASSOC | ARRAY)) == (DEFINED | ASSOC)) { char *cp; /* gotcha! */ cp = shf_smprintf(Tf_ss, str_val(vp), p); afree(ap, ATEMP); n = ap = cp; goto redo_from_ref; } } innermost_refflag = SRF_NOP; if (p != n && ord(*p) == ord('[') && (len = array_ref_len(p))) { char *sub, *tmp; mksh_ari_t rval; /* calculate the value of the subscript */ *arrayp = true; strndupx(tmp, p + 1, len - 2, ATEMP); sub = substitute(tmp, 0); afree(tmp, ATEMP); strndupx(n, n, p - n, ATEMP); evaluate(sub, &rval, KSH_UNWIND_ERROR, true); *valp = (uint32_t)rval; afree(sub, ATEMP); } return (n); }
/* * Search for local variable, if not found create locally. */ struct tbl * local(const char *n, bool copy) { struct tbl *vp; union mksh_cchack vname; struct block *l = e->loc; bool array; uint32_t h, val; /* * check to see if this is an array; * dereference namerefs; must come first */ vn = array_index_calc(n, &array, &val); h = hash(vn); if (!ctype(*vn, C_ALPHX)) { vp = vtemp; vp->flag = DEFINED|RDONLY; vp->type = 0; vp->areap = ATEMP; goto out; } vp = ktenter(&l->vars, vn, h); if (copy && !(vp->flag & DEFINED)) { struct tbl *vq; varsearch(l->next, &vq, vn, h); if (vq != NULL) { vp->flag |= vq->flag & (EXPORT | INTEGER | RDONLY | LJUST | RJUST | ZEROFIL | LCASEV | UCASEV_AL | INT_U | INT_L); if (vq->flag & INTEGER) vp->type = vq->type; vp->u2.field = vq->u2.field; } } if (array) vp = arraysearch(vp, val); vp->flag |= DEFINED; if (special(vn)) vp->flag |= SPECIAL; out: last_lookup_was_array = array; if (vn != n) afree(vname.rw, ATEMP); return (vp); }
/* * Find number of beginning 0's in a word of type t. * t should be deunsigned. */ static NODE * builtin_ff(NODE *f, NODE *a, TWORD t) { NODE *t101, *t102; NODE *rn, *p; int l15, l16, l17; int sz; tfree(f); t = ctype(t); sz = (int)tsize(t, 0, 0)+1; t101 = tempnode(0, INT, 0, 0); t102 = tempnode(0, t, 0, 0); l15 = getlab(); l16 = getlab(); l17 = getlab(); rn = buildtree(ASSIGN, ccopy(t101), bcon(0)); rn = cmop(rn, buildtree(ASSIGN, ccopy(t102), a)); p = buildtree(CBRANCH, buildtree(EQ, ccopy(t102), bcon(0)), bcon(l15)); rn = cmop(rn, p); rn = cmop(rn, buildtree(INCR, ccopy(t101), bcon(1))); rn = cmop(rn, lblnod(l16)); p = buildtree(CBRANCH, buildtree(GE, ccopy(t101), bcon(sz)), bcon(l15)); rn = cmop(rn, p); p = buildtree(CBRANCH, buildtree(EQ, buildtree(AND, ccopy(t102), bcon(1)), bcon(0)), bcon(l17)); rn = cmop(rn, p); rn = cmop(rn, block(GOTO, bcon(l15), NIL, INT, 0, 0)); rn = cmop(rn, lblnod(l17)); rn = cmop(rn, buildtree(RSEQ, t102, bcon(1))); rn = cmop(rn, buildtree(INCR, ccopy(t101), bcon(1))); rn = cmop(rn, block(GOTO, bcon(l16), NIL, INT, 0, 0)); rn = cmop(rn, lblnod(l15)); return cmop(rn, t101); }
void nsHTMLObjectElement::StartObjectLoad(PRBool aNotify) { nsAutoString type; GetAttr(kNameSpaceID_None, nsGkAtoms::type, type); NS_ConvertUTF16toUTF8 ctype(type); nsAutoString uri; if (GetAttr(kNameSpaceID_None, nsGkAtoms::data, uri)) { LoadObject(uri, aNotify, ctype); } else { // Be sure to call the nsIURI version if we have no attribute // That handles the case where no URI is specified. An empty string would // get interpreted as the page itself, instead of absence of URI. LoadObject(nsnull, aNotify, ctype); } }