/* keep track of enough state to give us a hint as to whether we need to redo the visual matches */ static int need_to_rehilite(void) { /* save static copies of state that affects the search */ if ((curbp->b_highlight & (HILITE_ON | HILITE_DIRTY)) == (HILITE_ON | HILITE_DIRTY) || tb_length(searchpat) != tb_length(savepat) || (tb_length(searchpat) != 0 && tb_length(savepat) != 0 && memcmp(tb_values(searchpat), tb_values(savepat), tb_length(savepat))) || save_igncase != ignorecase || save_vattr != b_val(curbp, VAL_HILITEMATCH) || save_magic != b_val(curbp, MDMAGIC) || (!hilite_suppressed && save_curbp != curbp)) { tb_copy(&savepat, searchpat); save_igncase = ignorecase; save_vattr = (VIDEO_ATTR) b_val(curbp, VAL_HILITEMATCH); save_magic = b_val(curbp, MDMAGIC); save_curbp = curbp; return TRUE; } return FALSE; }
/* ARGSUSED */ int vl_setkey(int f GCC_UNUSED, int n GCC_UNUSED) { char result[NKEYLEN]; int rc = get_encryption_key(result, sizeof(result)); if (rc == TRUE) { TRACE(("set key for %s\n", curbp->b_bname)); (void) vl_strncpy(curbp->b_cryptkey, result, sizeof(curbp->b_cryptkey)); make_local_b_val(curbp, MDCRYPT); set_b_val(curbp, MDCRYPT, TRUE); curwp->w_flag |= WFMODE; } else if (rc == FALSE) { if (curbp->b_cryptkey[0] != EOS) { rc = mlyesno("Discard encryption key"); if (rc == TRUE) { TRACE(("reset key for %s\n", curbp->b_bname)); curbp->b_cryptkey[0] = EOS; if (global_b_val(MDCRYPT)) { make_local_b_val(curbp, MDCRYPT); set_b_val(curbp, MDCRYPT, FALSE); curwp->w_flag |= WFMODE; } else if (b_val(curbp, MDCRYPT)) { make_global_val(curbp->b_values.bv, global_b_values.bv, MDCRYPT); curwp->w_flag |= WFMODE; } } } } return (rc); }
int operyank(int f, int n) { MARK savedot; REGION region; int s; savedot = DOT; opcmd = OPDEL; wantregion = ®ion; s = vile_op(f, n, yankregion, "Yank"); wantregion = 0; /* * If the associated motion was to the left, or up, we want to set DOT to * the beginning of the region, to match vi's behavior. Otherwise leave * DOT where it is. */ if (s == TRUE && b_val(curbp, MDYANKMOTION)) { if (line_no(curbp, post_op_dot.l) != 0 && line_no(curbp, post_op_dot.l) < line_no(curbp, savedot.l)) { savedot = post_op_dot; } else if (!samepoint(region.r_orig, region.r_end)) { if (sameline(region.r_orig, savedot) && sameline(region.r_end, savedot) && region.r_orig.o < savedot.o) { savedot = region.r_orig; } } } DOT = savedot; return s; }
int main(void) { char b; int cnt = 0; printf("\n%5s%5s%5s%5s%5s%5s%7s%7s%11s\n\n", "Cnt", "b1", "b2", "b3", "b4", "b5", "fct1", "fct2", "majority"); for (b = 0; b < 32; ++b) { printf("%5d%5d%5d%5d%5d%5d%6d%7d%9d\n", ++cnt, b_val(5, b), b_val(4, b), b_val(3, b), b_val(2, b), b_val(1, b), fct1(b), fct2(b), majority(b)); } putchar('\n'); return 0; }
int check_editable(BUFFER *bp) { int status = TRUE; if (valid_buffer(bp) && b_val(bp, MDVIEW)) status = rdonly(); return status; }
inline Eigen::Matrix<fvar<T2>,R1,C2> mdivide_left_ldlt(const stan::math::LDLT_factor<double,R1,C1> &A, const Eigen::Matrix<fvar<T2>,R2,C2> &b) { stan::math::check_multiplicable("mdivide_left_ldlt", "A", A, "b", b); Eigen::Matrix<T2,R2,C2> b_val(b.rows(), b.cols()); Eigen::Matrix<T2,R2,C2> b_der(b.rows(), b.cols()); for (int i = 0; i < b.rows(); i++) for (int j = 0; j < b.cols(); j++) { b_val(i,j) = b(i,j).val_; b_der(i,j) = b(i,j).d_; } return to_fvar(mdivide_left_ldlt(A, b_val), mdivide_left_ldlt(A, b_der)); }
RCP<const UnivariateIntPolynomial> mul_poly(const UnivariateIntPolynomial &a, const UnivariateIntPolynomial &b) { RCP<const Symbol> var = symbol(""); if (a.get_var()->get_name() == "") { var = b.get_var(); } else if (b.get_var()->get_name() == "") { var = a.get_var(); } else if (!(a.get_var()->__eq__(*b.get_var()))) { throw std::runtime_error("Error: variables must agree."); } else { var = a.get_var(); } bool neg = false; if ((--(a.get_dict().end()))->second < 0) neg = not neg; if ((--(b.get_dict().end()))->second < 0) neg = not neg; unsigned int N = bit_length(std::min(a.get_degree() + 1, b.get_degree() + 1)) + bit_length(a.max_abs_coef()) + bit_length(b.max_abs_coef()); integer_class a1(1), b1; a1 <<= N; integer_class a2 = a1 / 2; integer_class mask = a1 - 1; integer_class a_val(a.eval_bit(N)), b_val(b.eval_bit(N)); integer_class s_val(a_val * b_val); integer_class r = mp_abs(s_val); std::vector<integer_class> v; integer_class carry(0); while (r != 0 or carry != 0) { mp_and(b1, r, mask); if (b1 < a2) { v.push_back(b1 + carry); carry = 0; } else { v.push_back(b1 - a1 + carry); carry = 1; } r >>= N; } if (neg) return neg_poly(*UnivariateIntPolynomial::from_vec(var, v)); else return UnivariateIntPolynomial::from_vec(var, v); }
int paste_selection(void) { if (!doingsweep) { TRACE(("MOUSE paste selection\n")); if (b_val(curbp, MDVIEW)) { kbd_alarm(); return FALSE; } mayneedundo(); return putafter(FALSE, 1); } return SEL_PASTE; }
static int attribute_directly(void) { BUFFER *bp = curbp; int code = FALSE; #if OPT_MAJORMODE if (valid_buffer(bp)) { #if OPT_AUTOCOLOR VL_ELAPSED begin_time; (void) vl_elapsed(&begin_time, TRUE); #endif discard_syntax_highlighting(); if (b_val(bp, MDHILITE)) { char *filtername = 0; TBUFF *token = 0; if (clexec || isnamedcmd) filtername = mac_unquotedarg(&token); if (filtername == 0 && bp->majr != 0) filtername = bp->majr->shortname; if (filtername != 0 && flt_start(filtername)) { TRACE(("attribute_directly(%s) using %s\n", bp->b_bname, filtername)); flt_finish(); code = TRUE; } tb_free(&token); } attach_attrib(selbufp, &selregion); attach_attrib(startbufp, &startregion); #if OPT_HILITEMATCH if (bp->b_highlight & HILITE_ON) { bp->b_highlight |= HILITE_DIRTY; attrib_matches(); } #endif #if OPT_AUTOCOLOR bp->last_autocolor_time = vl_elapsed(&begin_time, FALSE); bp->next_autocolor_time = 0; #endif } #endif return code; }
char *subtraction(char *op1, char *op2, char **av) { long long s[4]; int v[5]; char *r; s[0] = ft_strlen(op1) - 1; s[1] = ft_strlen(op2) - 1; v[3] = 0; if (s[0] < s[1] || (s[0] == s[1] && b_strcmp(op1, op2, av[1]) < 0)) { ft_swap(&op1, &op2); v[3] = 1; } r = sub_part1(s, v, r, av); while (s[2] > s[3]) { v[0] = (s[0] > -1) ? b_val(op1[s[0]], av[1]) : 0; v[1] = (s[1] > -1) ? b_val(op2[s[1]], av[1]) : 0; sub_part2(s, v, r, av); } rmv_zero(r, v[3], av[1]); return (r); }
/* * This hack will search for the next occurrence of <searchpat> in the buffer, * either forward or backward. It is called with the status of the prior * search attempt, so that it knows not to bother if it didn't work last * time. If we can't find any more matches, "point" is left where it was * before. If we do find a match, "point" will be at the end of the matched * string for forward searches and at the beginning of the matched string for * reverse searches. */ static int scanmore( /* search forward or back for a pattern */ TBUFF *patrn, /* string to scan for */ int dir) /* direction to search */ { int sts = FALSE; /* current search status */ FreeIfNeeded(gregexp); gregexp = regcomp(tb_values(patrn), tb_length(patrn), b_val(curbp, MDMAGIC)); if (gregexp != 0) { ignorecase = window_b_val(curwp, MDIGNCASE); sts = scanner(gregexp, (dir < 0) ? REVERSE : FORWARD, FALSE, (int *) 0); if (!sts) { kbd_alarm(); /* beep the terminal if we fail */ } #if OPT_EXTRA_COLOR else { MARK save_MK; int *attrp = lookup_extra_color(XCOLOR_ISEARCH); if (!isEmpty(attrp)) { /* clear any existing search-match */ clear_match_attrs(TRUE, 1); /* draw the new search-match */ regionshape = rgn_EXACT; save_MK = MK; MK.l = DOT.l; MK.o = DOT.o + (C_NUM) tb_length(patrn); videoattribute = (VIDEO_ATTR) * attrp; videoattribute |= VOWN_MATCHES; (void) attributeregion(); /* fix for clear_match_attrs */ curbp->b_highlight |= HILITE_ON; MK = save_MK; } } #endif } return (sts); /* else, don't even try */ }
/* * Set the buffer's encryption key if needed. */ int vl_resetkey(BUFFER *bp, const char *fname) { register int s; /* temporary return value */ /* flag the buffer as not having encryption */ ffdocrypt(FALSE); /* if we want to encrypt */ if (b_val(bp, MDCRYPT)) { char temp[NFILEN]; /* don't automatically inherit key from other buffers */ if (bp->b_cryptkey[0] != EOS && !b_is_argument(bp) && strcmp(lengthen_path(vl_strncpy(temp, fname, sizeof(temp))), bp->b_fname)) { char prompt[80]; (void) lsprintf(prompt, "Use crypt-key from %s", bp->b_bname); s = mlyesno(prompt); if (s != TRUE) return (s == FALSE); } /* make a key if we don't have one */ if (bp->b_cryptkey[0] == EOS) { s = get_encryption_key(bp->b_cryptkey, sizeof(bp->b_cryptkey)); if (s != TRUE) return (s == FALSE); } ffdocrypt(TRUE); vl_setup_encrypt(bp->b_cryptkey, seed); } return TRUE; }
/* * Check if the given file exists. If so, try to reuse its record-format when * creating a new version. * * Note: using a '0' protection on VMS C 'open()' tells it to use an existing * file's protection, or (if the file doesn't exist) the user's default * protection. */ int vms_creat(char *filename) { char rfm_option[80]; char rat_option[80]; char len_option[80]; struct stat sb; int my_rfm = b_val(curbp, VAL_RECORD_FORMAT); int my_rat = b_val(curbp, VAL_RECORD_ATTRS); int my_len = b_val(curbp, VAL_RECORD_LENGTH); int fd; /* * Only check for the previous file's record-format if the mode has not * been specified. */ if (my_rfm == FAB$C_UDF) { if (file_stat(filename, &sb) == 0) { my_rfm = sb.st_fab_rfm; my_rat = sb.st_fab_rat; my_len = sb.st_fab_mrs; /* Ignore the old record attributes, since 'cr' is the * only one we know anything about. */ } if (my_rfm == FAB$C_UDF) my_rfm = FAB$C_STMLF; } lsprintf(rfm_option, "rfm=%s", vms_record_format(my_rfm)); lsprintf(rat_option, "rat=%s", vms_record_attrs(my_rat)); lsprintf(len_option, "mrs=%d", my_len); switch (my_rfm) { case FAB$C_FIX: fd = creat(filename, 0, rfm_option, len_option, rat_option); break; case FAB$C_VFC: /* * FIXME: Must specify the fixed-length control field size * (there's no interface for that at the moment, so I * hardwired it at two bytes. Tom, I'm punting this one * back to you. * * C. Morgan 11/29/1998. * * VFC files can only up to 32768 bytes/record, so the control * field size is "always" 2 bytes -TD */ fd = creat(filename, 0, rfm_option, len_option, "fsz=2", /* Fixed-length control field size */ rat_option); break; default: /* * The stmlf and var record-formats are really all that is * required. Other combinations are experimental. */ fd = creat(filename, 0, rfm_option, "rat=cr"); break; } return fd; }
/* * readpattern -- read a pattern. if it is the * search string, recompile it. * pattern not updated if the user types in an empty line. */ int readpattern(const char *prompt, TBUFF **apat, regexp ** srchexpp, int c, int fromscreen) { char temp[NPAT]; int status; TRACE((T_CALLED "readpattern(%s, %s, %p, %d, %d)\n", prompt ? prompt : "", tb_visible(*apat), (void *) srchexpp, c, fromscreen)); if (fromscreen) { if ((status = screen_to_ident(temp, sizeof(temp))) == TRUE) { if (tb_init(apat, EOS) == 0 || tb_bappend(apat, temp, strlen(temp)) == 0) { status = FALSE; } } if (status != TRUE) returnCode(status); } else { /* don't expand #, %, :, and never process backslashes since they're handled by regexp directly for the search pattern, and in delins() for the replacement pattern */ hst_glue(c); /* * kbd_reply() expects a trailing null, to simplify calls from * kbd_string(). */ if (tb_values(*apat) != 0) tb_append(apat, EOS); status = kbd_reply(prompt, apat, eol_history, c, KBD_EXPPAT | KBD_0CHAR, no_completion); if (tb_length(*apat) != 0) tb_unput(*apat); /* trim the trailing null */ } if (status == TRUE) { if (srchexpp) { /* compile it */ beginDisplay(); FreeIfNeeded(*srchexpp); endofDisplay(); *srchexpp = regcomp(tb_values(*apat), tb_length(*apat), b_val(curbp, MDMAGIC)); if (!*srchexpp) returnCode(FALSE); } } else if (status == FALSE && tb_length(*apat) != 0) { /* Old one */ status = TRUE; } returnCode(status); }
void attrib_matches(void) { #if OPT_HILITEMATCH MARK origdot; MARK nextdot; int status; REGIONSHAPE oregionshape = regionshape; VIDEO_ATTR vattr; assert(curwp != 0); ignorecase = window_b_val(curwp, MDIGNCASE); if (!need_to_rehilite()) return; if (tb_length(searchpat) == 0 || gregexp == NULL) return; /* #define track_hilite 1 */ #ifdef track_hilite mlwrite("rehighlighting"); #endif vattr = (VIDEO_ATTR) b_val(curbp, VAL_HILITEMATCH); if (vattr == 0) return; (void) clear_match_attrs(TRUE, 1); if (curwp == 0) return; origdot = DOT; DOT.l = buf_head(curbp); DOT.o = 0; nextdot = DOT; scanboundry(FALSE, DOT, FORWARD); do { if (b_val(curbp, MDHILITEOVERLAP)) { movenext(&(DOT), FORWARD); } else { movenext(&nextdot, FORWARD); DOT = nextdot; } status = scanner(gregexp, FORWARD, FALSE, (int *) 0); if (status != TRUE) break; if (vattr != VACOLOR) videoattribute = vattr; else { int c; for (c = NSUBEXP - 1; c > 0; c--) if (gregexp->startp[c] == gregexp->startp[0] && gregexp->endp[c] == gregexp->endp[0]) break; if (c > NCOLORS - 1) videoattribute = VCOLORATTR(NCOLORS - 1); else videoattribute = VCOLORATTR(c + 1); } MK.l = DOT.l; MK.o = DOT.o + (C_NUM) gregexp->mlen; /* provide a location for the next non-overlapping match */ nextdot = MK; if (gregexp->mlen > 0) nextdot.o -= BytesBefore(nextdot.l, nextdot.o); /* show highlighting from DOT to MK */ regionshape = rgn_EXACT; videoattribute |= VOWN_MATCHES; status = attributeregion(); } while (status == TRUE); DOT = origdot; regionshape = oregionshape; curbp->b_highlight = HILITE_ON; /* & ~HILITE_DIRTY */ hilite_suppressed = FALSE; #endif /* OPT_HILITEMATCH */ }
static int attribute_from_filter(void) { BUFFER *bp = curbp; LINE *pastline; int skip; size_t nbytes; size_t n; int done; int result = TRUE; int drained = FALSE; TRACE((T_CALLED "attribute_from_filter\n")); if ((pastline = setup_region()) == 0) { result = FALSE; #ifdef MDHILITE } else if (!b_val(bp, MDHILITE)) { discard_syntax_highlighting(); #endif } else if (open_region_filter() == TRUE) { discard_syntax_highlighting(); while (DOT.l != pastline) { if (interrupted()) { result = FALSE; break; } if (ffgetline(&nbytes) > FIOSUC) { drained = TRUE; break; } DOT.o = 0; for (n = 0; n < nbytes; n++) { if (fflinebuf[n] == CONTROL_A) { done = decode_attribute(fflinebuf, nbytes, n, &skip); if (done) { n = (size_t) (done - 1); set_mark_after(skip, 1); if (apply_attribute()) (void) attributeregion(); } } else { DOT.o += BytesAt(DOT.l, DOT.o); } } DOT.l = lforw(DOT.l); } /* some pipes will hang if they're not drained */ if (!drained) { while (ffgetline(&nbytes) <= FIOSUC) { ; } } (void) ffclose(); /* Ignore errors. */ attach_attrib(selbufp, &selregion); attach_attrib(startbufp, &startregion); #if OPT_HILITEMATCH if (bp->b_highlight & HILITE_ON) { bp->b_highlight |= HILITE_DIRTY; attrib_matches(); } #endif } returnCode(result); }