/* * Common function for prompting for shell/pipe command, and for recording the * last shell/pipe command so that we can support "!!" convention. * * Note that for 'pipecmd()', we must retain a leading "!". */ static int ShellPrompt( TBUFF **holds, char *result, int rerun) /* TRUE/FALSE: spawn, -TRUE: pipecmd */ { register int s; register SIZE_T len; static const char bang[] = SHPIPE_LEFT; BUFFER *bp; int cb = any_changed_buf(&bp), fix = (rerun != -TRUE); char save[NLINE], temp[NLINE], line[NLINE+1]; if ((len = tb_length(*holds)) != 0) { (void)strncpy(save, tb_values(*holds), len); } save[len] = EOS; /* if it doesn't start with '!', or if that's all it is */ if (!isShellOrPipe(save) || save[1] == EOS) (void)strcpy(save, bang); (void)strcpy(line, save); if (rerun != TRUE) { if (cb != 0) { if (cb > 1) { (void)lsprintf(temp, "Warning: %d modified buffers: %s", cb, bang); } else { (void)lsprintf(temp, "Warning: buffer \"%s\" is modified: %s", bp->b_bname, bang); } } else { (void)lsprintf(temp, "%s%s", rerun == -TRUE ? "" : ": ", bang); } if ((s = mlreply_no_bs(temp, line+1, NLINE)) != TRUE) return s; } if (line[1] == EOS) return FALSE; *holds = tb_scopy(holds, line); (void)strcpy(result, line+fix); return TRUE; }
int var_CDPATH(TBUFF **rp, const char *vp) { if (rp) { tb_scopy(rp, get_cdpath()); return TRUE; } else if (vp) { SetEnv(&cdpath, vp); return TRUE; } else { return FALSE; } }
static int any_HOOK(TBUFF **rp, const char *vp, HOOK * hook) { if (rp) { tb_scopy(rp, hook->proc); return TRUE; } else if (vp) { (void) strncpy0(hook->proc, vp, (size_t) NBUFN); return TRUE; } else { return FALSE; } }
static int any_rw_TXT(TBUFF **rp, const char *vp, char **value) { if (rp) { tb_scopy(rp, *value); return TRUE; } else if (vp) { SetEnv(value, vp); return TRUE; } else { return FALSE; } }
static int any_ro_STR(TBUFF **rp, const char *vp, const char *value) { if (rp) { if (value != 0) { tb_scopy(rp, value); return TRUE; } } else if (vp) { return ABORT; /* read-only */ } return FALSE; }
static int any_rw_TBUFF(TBUFF **rp, const char *vp, TBUFF **value) { if (rp) { if (value != 0) { tb_copy(rp, *value); return TRUE; } } else if (vp) { tb_scopy(value, vp); return TRUE; } return FALSE; }
static int attributehyperregion(void) { char line[NLINE]; int status; line[0] = 0; status = mlreply_no_opts("Hypertext Command: ", line, NLINE); if (status != TRUE) return status; tb_scopy(&hypercmd, line); return attributeregion(); }
int var_BFLAGS(TBUFF **rp, const char *vp) { char temp[80]; if (rp) { buffer_flags(temp, curbp); tb_scopy(rp, temp); return TRUE; } else if (vp) { return ABORT; /* read-only */ } else { return FALSE; } }
int var_CBUFNAME(TBUFF **rp, const char *vp) { if (rp) { tb_scopy(rp, valid_buffer(curbp) ? curbp->b_bname : ""); return TRUE; } else if (vp) { if (valid_buffer(curbp)) { set_bname(curbp, vp); curwp->w_flag |= WFMODE; } return TRUE; } else { return FALSE; } }
int var_CRYPTKEY(TBUFF **rp, const char *vp) { if (rp) { tb_scopy(rp, WRITE_ONLY); return TRUE; } else if (vp) { beginDisplay(); FreeIfNeeded(cryptkey); cryptkey = typeallocn(char, NKEYLEN); endofDisplay(); if (cryptkey == 0) return no_memory("var_CRYPTKEY"); vl_make_encrypt_key(cryptkey, vp); return TRUE; } else { return FALSE;
int attributeregion_in_region(REGION * rp, REGIONSHAPE shape, unsigned vattr, char *hc) { haveregion = rp; DOT = rp->r_orig; MK = rp->r_end; if (shape == rgn_FULLLINE) MK.l = lback(MK.l); regionshape = shape; /* Not that the following actually cares */ videoattribute = (VIDEO_ATTR) vattr; #if OPT_HYPERTEXT tb_scopy(&hypercmd, hc); #endif /* OPT_HYPERTEXT */ return attributeregion(); }
int var_BRIGHTNESS(TBUFF **rp, const char *vp) { char temp[80]; if (rp) { lsprintf(temp, "%d %d %d", rgb_gray, rgb_normal, rgb_bright); tb_scopy(rp, temp); return TRUE; } else if (vp) { rgb_gray = parse_rgb(&vp, 140); rgb_normal = parse_rgb(&vp, 180); rgb_bright = parse_rgb(&vp, 255); return vile_refresh(FALSE, 1); } else { return FALSE; } }
static int any_rw_EXPR(TBUFF **rp, const char *vp, TBUFF **value) { if (rp) { if (value != 0) { tb_copy(rp, *value); return TRUE; } } else if (vp) { regexp *exp = regcomp(vp, strlen(vp), TRUE); if (exp != 0) { beginDisplay(); free(exp); endofDisplay(); tb_scopy(value, vp); return TRUE; } } return FALSE; }
int var_CHAR(TBUFF **rp, const char *vp) { int status = FALSE; if (rp) { if (valid_buffer(curbp) && !is_empty_buf(curbp)) { render_int(rp, CharAtDot()); } else { tb_scopy(rp, error_val); } status = TRUE; } else if (vp) { if ((status = check_editable(curbp)) == TRUE) { int c; mayneedundo(); (void) ldel_chars(1L, FALSE); /* delete 1 char */ c = scan_int(vp); if ((status = bputc(c)) == TRUE) (void) backchar(FALSE, 1); } } return status; }
/* For the "operator" commands -- the following command is a motion, or * the operator itself is repeated. All operate on regions. */ int vile_op(int f, int n, OpsFunc fn, const char *str) { int c = 0; int thiskey; int status; const CMDFUNC *cfp; /* function to execute */ const CMDFUNC *save_cmd_motion = cmd_motion; BUFFER *ourbp; #if OPT_MOUSE WINDOW *wp0 = curwp; #endif TRACE((T_CALLED "vile_op(%s)\n", str)); doingopcmd = TRUE; pre_op_dot = DOT; ourbp = curbp; if (havemotion != NULL) { cfp = havemotion; havemotion = NULL; } else { TBUFF *tok = 0; mlwrite("%s operation pending...", str); (void) update(FALSE); /* get the next command from the keyboard */ /* or a command line, as approp. */ if (clexec) { char *value = mac_unquotedarg(&tok); /* get the next token */ if (value != 0 && strcmp(value, "lines")) cfp = engl2fnc(value); else cfp = &f_godotplus; } else { thiskey = lastkey; c = kbd_seq(); #if OPT_MOUSE if (curwp != wp0) { unkeystroke(c); doingopcmd = FALSE; returnCode(FALSE); } #endif /* allow second chance for entering counts */ do_repeats(&c, &f, &n); if (thiskey == lastkey) cfp = &f_godotplus; else cfp = DefaultKeyBinding(c); } if (cfp != 0) { mlerase(); } else { if (!clexec) { char temp[NSTRING]; lsprintf(temp, "(%d)", c); tb_scopy(&tok, temp); } (void) no_such_function(tb_values(tok)); } tb_free(&tok); } if (!cfp) { status = FALSE; } else if ((cfp->c_flags & MOTION) == 0) { kbd_alarm(); status = ABORT; } else { /* motion is interpreted as affecting full lines */ if (regionshape == rgn_EXACT) { if (cfp->c_flags & FL) regionshape = rgn_FULLLINE; if (cfp->c_flags & VL_RECT) regionshape = rgn_RECTANGLE; } /* and execute the motion */ if ((status = execute(cfp, f, n)) == TRUE) { post_op_dot = DOT; } else { mlforce("[Motion failed]"); status = FALSE; } } if (status == TRUE) { opcmd = 0; MK = pre_op_dot; /* we've successfully set up a region */ if (!fn) { /* be defensive */ mlforce("BUG -- null func pointer in operator"); status = FALSE; } else if (fn == user_operator) { swapmark(); cmd_motion = cfp; status = dobuf(find_b_name(str), 1, f ? n : 1); } else { status = (fn) (); } if (ourbp == curbp) /* in case the func switched buffers on us */ swapmark(); if (regionshape == rgn_FULLLINE) (void) firstnonwhite(FALSE, 1); } regionshape = rgn_EXACT; doingopcmd = FALSE; haveregion = FALSE; cmd_motion = save_cmd_motion; returnCode(status); }