/* ARGSUSED0 */ int killbuffer (int f, int n) { BUFFER *bp; BUFFER *bp_alt; char bufn[NBUFN]; char prompt[NFILEN]; int s; sprintf(prompt, "Kill Buffer: (default %s) ", curbp->b_bname); s = mlreply (prompt, bufn, NBUFN); if (s == ABORT) return ABORT; else if (s == FALSE) { bp = curbp; } else { /* return if cant find named buffer */ if ((bp = bfind (bufn, FALSE, 0)) == NULL) return FALSE; } /* beep if attempt to kill buffer list */ if (bp == blistp) { (*term.t_beep) (); mlerase(); return FALSE; } /* find a buffer to switch to, not this one and not an internal buffer */ bp_alt = bheadp; while (bp_alt != NULL) { if (bp_alt != bp && (bp_alt->b_flag & BFTEMP) != BFTEMP) break; bp_alt = bp_alt->b_bufp; } /* no alternate buffer, try for scratch or create it */ if (bp_alt == NULL) { bp_alt = get_scratch(); } if (bp_alt == NULL) { return (FALSE); } swbuffer(bp_alt); s = zotbuf(bp); mlerase(); return s; }
/* * Rename the current buffer * * int f, n; default Flag & Numeric arg */ int namebuffer(int f, int n) { struct buffer *bp; /* pointer to scan through all buffers */ char bufn[NBUFN]; /* buffer to hold buffer name */ /* prompt for and get the new buffer name */ ask:if (mlreply("Change buffer name to: ", bufn, NBUFN) != TRUE) return FALSE; /* and check for duplicates */ bp = bheadp; while (bp != NULL) { if (bp != curbp) { /* if the names the same */ if (strcmp(bufn, bp->b_bname) == 0) goto ask; /* try again */ } bp = bp->b_bufp; /* onward */ } strcpy(curbp->b_bname, bufn); /* copy buffer name to structure */ curwp->w_flag |= WFMODE; /* make mode line replot */ mlerase(); return TRUE; }
int fisearch(int f, int n) { MARK curpos; /* current line on entryl */ /* remember the initial . on entry: */ curpos = DOT; /* save current point */ /* Save direction */ last_srch_direc = FORWARD; /* do the search */ if (!(isearch(f, n))) { /* Call ISearch forwards */ /* If error in search: */ DOT = curpos; /* reset */ curwp->w_flag |= WFMOVE; /* Say we've moved */ (void) update(FALSE); /* And force an update */ mlwarn("[I-Search failed]"); /* Say we died */ return FALSE; } else mlerase(); /* If happy, just erase the cmd line */ return TRUE; }
/* * Subroutine to do incremental reverse search. It actually uses the same * code as the normal incremental search, as both can go both ways. */ int risearch(int f, int n) { MARK curpos; /* Current point on entry */ /* remember the initial . on entry: */ curpos = DOT; /* Save the current point */ /* Save direction */ last_srch_direc = REVERSE; /* Make sure the search doesn't match where we already are: */ backchar(TRUE, 1); /* Back up a character */ if (!(isearch(f, -n))) { /* Call ISearch backwards */ /* If error in search: */ DOT = curpos; /* Reset the pointer */ curwp->w_flag |= WFMOVE; /* Say we've moved */ (void) update(FALSE); /* And force an update */ mlwarn("[I-Search failed]"); /* Say we died */ return FALSE; } else mlerase(); /* If happy, just erase the cmd line */ return TRUE; }
// The screen is garbage and needs major repair. Clear the physical and virtual screens and force a full update. // Return status. static int supd_redraw(void) { int i; char *strp,*strpz; for(i = 0; i < (int) term.t_nrow - 1; ++i) { // Exclude message line. vscreen[i]->v_flags |= VFCHGD; #if COLOR vscreen[i]->v_fcolor = gfcolor; vscreen[i]->v_bcolor = gbcolor; #endif pscreen[i]->v_left = FARRIGHT; pscreen[i]->v_right = 0; strpz = (strp = pscreen[i]->v_text) + term.t_ncol; do { *strp++ = ' '; } while(strp < strpz); pscreen[i]->v_flags &= ~VFNEW; } // Erase the screen. if(movecursor(0,0) != SUCCESS || TTeeop() != SUCCESS) return rc.status; opflags &= ~OPSCREDRAW; // Clear redraw flag. #if COLOR mlerase(MLFORCE); #endif return rc.status; }
/* * Clean up the virtual terminal system, in anticipation for a return to the * operating system. Move down to the last line and clear it out (the next * system prompt will be written in the line). Shut down the channel to the * terminal. */ int vttidy() { mlerase(); movecursor(term.t_nrow, 0); (*term.t_close)(); return TRUE; }
/* * updgar: * if the screen is garbage, clear the physical screen and * the virtual screen and force a full update */ void updgar(void) { unicode_t *txt; int i, j; for (i = 0; i < term.t_nrow; ++i) { vscreen[i]->v_flag |= VFCHG; #if REVSTA vscreen[i]->v_flag &= ~VFREV; #endif #if COLOR vscreen[i]->v_fcolor = gfcolor; vscreen[i]->v_bcolor = gbcolor; #endif #if MEMMAP == 0 || SCROLLCODE txt = pscreen[i]->v_text; for (j = 0; j < term.t_ncol; ++j) txt[j] = ' '; #endif } movecursor(0, 0); /* Erase the screen. */ (*term.t_eeop) (); sgarbf = FALSE; /* Erase-page clears */ mpresf = FALSE; /* the message area. */ #if COLOR mlerase(); /* needs to be cleared if colored */ #endif }
void vttidy() { mlerase(); movecursor(term.t_nrow, 0); TTflush(); TTclose(); TTkclose(); }
// Clean up the virtual terminal system, in anticipation for a return to the operating system. Move down to the last line and // clear it out (the next system prompt will be written in the line). Shut down the channel to the terminal. Return status. int vttidy(bool force) { // Don't close it if it ain't open. if(opflags & OPVTOPEN) { mlerase(MLFORCE); if((TTflush() == SUCCESS || force) && (TTclose() == SUCCESS || force)) (void) TTkclose(); opflags &= ~OPVTOPEN; } return rc.status; }
/* * Clean up the virtual terminal system, in anticipation for a return to the * operating system. Move down to the last line and clear it out (the next * system prompt will be written in the line). Shut down the channel to the * terminal. */ void vttidy(void) { mlerase(); movecursor(term.t_nrow, 0); TTflush(); TTclose(); TTkclose(); #ifdef PKCODE write(1, "\r", 1); #endif }
static int release_selection(int status) { TRACE(("MOUSE release selection\n")); if (doingsweep) { do_sweep(FALSE); if (status != TRUE) mlforce("[Sweeping: Aborted]"); else mlerase(); } sel_release(); return status; }
/* * abort_composer - ask the question here, then go quit or * return FALSE */ int abort_composer(int f, int n) { char *result; result = ""; Pmaster->arm_winch_cleanup++; if(Pmaster->canceltest){ if(((Pmaster->pine_flags & MDHDRONLY) && !any_header_changes()) || (result = (*Pmaster->canceltest)(redraw_pico_for_callback))){ pico_all_done = COMP_CANCEL; emlwrite(result, NULL); Pmaster->arm_winch_cleanup--; return(TRUE); } else{ /* TRANSLATORS: The user typed the Cancel command and was asked to confirm that. Instead they canceled the cancel command. */ emlwrite(_("Cancel Cancelled"), NULL); curwp->w_flag |= WFMODE; /* and modeline so we */ sgarbk = TRUE; /* redraw the keymenu */ pclear(term.t_nrow-1, term.t_nrow); Pmaster->arm_winch_cleanup--; return(FALSE); } } else switch(mlyesno_utf8(Pmaster->headents ? _("Cancel message (answering \"Yes\" will abandon your mail message)") : (anycb() == FALSE) ? _("Cancel Edit (and abandon changes)") : _("Cancel Edit"), FALSE)){ case TRUE: pico_all_done = COMP_CANCEL; return(TRUE); case ABORT: emlwrite(_("\007Cancel Cancelled"), NULL); break; default: mlerase(); } return(FALSE); }
int fisearch(f, n) { LINE *curline; /* Current line on entry */ int curoff; /* Current offset on entry */ /* remember the initial . on entry: */ curline = curwp->w_dotp; /* Save the current line pointer */ curoff = curwp->w_doto; /* Save the current offset */ /* do the search */ if (!(isearch(f, n))) /* Call ISearch forwards */ { /* If error in search: */ curwp->w_dotp = curline; /* Reset the line pointer */ curwp->w_doto = curoff; /* and the offset to original value */ curwp->w_flag |= WFMOVE; /* Say we've moved */ update(FALSE); /* And force an update */ mlwrite ("[search failed]"); /* Say we died */ } else mlerase (); /* If happy, just erase the cmd line */ }
/* * Get the string to use as an encryption string. */ static int get_encryption_key(char *key, /* where to write key */ size_t len) { int status; /* return status */ int save_vl_echo = vl_echo; char temp[NKEYLEN]; /* turn command input echo off */ vl_echo = FALSE; temp[0] = EOS; status = mlreply("-Encryption String: ", temp, (UINT) (len - 1)); vl_echo = save_vl_echo; if (status == TRUE) vl_make_encrypt_key(key, temp); mlerase(); return (status); }
int risearch(f, n) { LINE *curline; /* Current line on entry */ int curoff; /* Current offset on entry */ /* remember the initial . on entry: */ curline = curwp->w_dotp; /* Save the current line pointer */ curoff = curwp->w_doto; /* Save the current offset */ /* Make sure the search doesn't match where we already are: */ backchar(TRUE, 1); /* Back up a character */ if (!(isearch(f, -n))) /* Call ISearch backwards */ { /* If error in search: */ curwp->w_dotp = curline; /* Reset the line pointer */ curwp->w_doto = curoff; /* and the offset to original value */ curwp->w_flag |= WFMOVE; /* Say we've moved */ update(FALSE); /* And force an update */ mlwrite ("[search failed]"); /* Say we died */ } else mlerase (); /* If happy, just erase the cmd line */ }
/* * Kill the region. Ask "getregion" * to figure out the bounds of the region. * Move "." to the start, and kill the characters. * Bound to "C-W". */ int killregion(int f, int n) { REGION region; if (curbp->b_mode&MDVIEW) /* don't allow this command if */ return(rdonly()); /* we are in read only mode */ if (getregion(®ion, curwp->w_markp, curwp->w_marko) != TRUE){ return (killtext(f, n)); }else { mlerase(); } if ((lastflag&CFKILL) == 0) /* This is a kill type */ kdelete(); /* command, so do magic */ thisflag |= CFKILL; /* kill buffer stuff. */ curwp->w_dotp = region.r_linep; curwp->w_doto = region.r_offset; curwp->w_markp = NULL; #ifdef _WINDOWS mswin_allowcopycut(NULL); #endif if(ldelete(region.r_size, kinsert)){ if(curwp->w_dotp == curwp->w_linep && curwp->w_dotp == curbp->b_linep){ curwp->w_force = 0; /* Center dot. */ curwp->w_flag |= WFFORCE; } return(TRUE); } return (FALSE); }
int buffermenu(int f, int n) { BUFFER *bp; BUFFER *org_bp = curbp; int c,k; int bufptr; int bufcount = 0; bufptr = 1; start: listbuffers(f,n); swbuffer(blistp); onlywind(0,0); bufcount = count_buffers(); if (bufptr > bufcount) bufptr = bufcount; if (bufcount > 0) forwline(0, bufptr + 1); else forwline(0, 2); for (;;) { mlwrite("Buffer Menu: 1,2,s,v,k,q "); update(); c = ttgetc(); /* if no buffers, only allow exit */ if (bufcount == 0) { switch (c) { case 'q': case 'Q': case 'x': case 'X': break; default: (*term.t_beep) (); continue; } } /* * pre process escape sequence to get up/down arrows * convert to CTRL+N, CTRL+P */ if (c == ESC) { k = getctl(); if (k == '[') { k = getctl(); switch(k) { case 'A': c = CTRL_P; break; case 'B': c = CTRL_N; break; default: (*term.t_beep)(); continue; } } else { k = getctl(); (*term.t_beep) (); continue; } } /* if ESC */ switch (c) { case 'n': case 'N': case CTRL_N: if (bufcount == bufptr) { (*term.t_beep) (); break; } forwline(0,1); bufptr++; break; case 'p': case 'P': case CTRL_P: if (bufptr == 1) { (*term.t_beep) (); break; } backline(0,1); bufptr--; break; case '1': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; case '2': bp = get_buffer(bufptr); swbuffer(bp); onlywind(0,0); /* need to check or is still valid */ if (valid_buf(org_bp) == TRUE && bufcount > 1) { splitwind(0,0); swbuffer(org_bp); nextwind(0,0); } mlerase(); return TRUE; /* save file */ case 's': case 'S': bp = get_buffer(bufptr); if (bp != NULL) { curbp = bp; (void)filesave(0,0); curbp = blistp; goto start; } break; /* toggle read only */ case 'v': case 'V': case '%': bp = get_buffer(bufptr); if (bp != NULL) /* be defensive */ bp->b_flag ^= BFRO; goto start; break; /* kill buffer */ case 'k': case 'K': bp = get_buffer(bufptr); if (bp != NULL) zotbuf(bp); goto start; break; /* exit buffer menu */ case 'q': case 'Q': case 'x': case 'X': if (bufcount == 0) { bp = get_scratch(); swbuffer(bp); onlywind(0,0); mlerase(); return TRUE; } if (valid_buf(org_bp) == TRUE) swbuffer(org_bp); else swbuffer(bheadp); onlywind(0,0); mlerase(); return TRUE; /* any other key */ default: (*term.t_beep) (); break; } } mlerase(); return TRUE; }
/* * bktoshell - suspend and wait to be woken up */ int bktoshell(int f, int n) { UCS z = CTRL | 'Z'; if(!(gmode&MDSSPD)){ unknown_command(z); return(FALSE); } if(Pmaster){ if(!Pmaster->suspend){ unknown_command(z); return(FALSE); } if((*Pmaster->suspend)() == NO_OP_COMMAND){ int rv; if(km_popped){ term.t_mrow = 2; curwp->w_ntrows -= 2; } clearcursor(); mlerase(); rv = (*Pmaster->showmsg)('x'); ttresize(); picosigs(); if(rv) /* Did showmsg corrupt the display? */ pico_refresh(0, 1); /* Yes, repaint */ mpresf = 1; if(km_popped){ term.t_mrow = 0; curwp->w_ntrows += 2; } } else{ ttresize(); pclear(0, term.t_nrow); pico_refresh(0, 1); } return(TRUE); } if(gmode&MDSPWN){ char *shell; int dummy; vttidy(); movecursor(0, 0); (*term.t_eeop)(); printf("\n\n\nUse \"exit\" to return to Pi%s\n", (gmode & MDBRONLY) ? "lot" : "co"); system((shell = (char *)getenv("SHELL")) ? shell : "/bin/csh"); rtfrmshell(dummy); /* fixup tty */ } else { movecursor(term.t_nrow-1, 0); peeol(); movecursor(term.t_nrow, 0); peeol(); movecursor(term.t_nrow, 0); printf("\n\n\nUse \"fg\" to return to Pi%s\n", (gmode & MDBRONLY) ? "lot" : "co"); ttclose(); movecursor(term.t_nrow, 0); peeol(); (*term.t_flush)(); signal(SIGCONT, rtfrmshell); /* prepare to restart */ signal(SIGTSTP, SIG_DFL); /* prepare to stop */ kill(0, SIGTSTP); } return(TRUE); }
/* 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); }
static int findHelpItem(meUByte *item, int silent) { meWindow *wp ; meBuffer *bp, *hbp ; meLine *lp, *elp ; int sectLen, itemLen, ii ; meUByte *ss, cc, sect[5] ; itemLen = meStrlen(item) ; if((item[itemLen-1] == ')') && ((item[(ii=itemLen-3)] == '(') || (item[(ii=itemLen-4)] == '(') )) { sectLen = itemLen-ii-2 ; meStrcpy(sect,item+ii) ; itemLen = ii ; item[itemLen] = '\0' ; } else { sectLen = 0 ; sect[0] = '\0' ; sect[1] = '\0' ; } if((hbp=helpBufferFind()) == NULL) return meABORT ; elp = hbp->baseLine ; try_again: lp = meLineGetNext(elp) ; while(lp != elp) { if((lp->text[0] == '!') && (!sectLen || ((sect[1] == lp->text[2]) && (((sectLen == 1) && (lp->text[3] == ' ')) || (sect[2] == lp->text[3]))))) { if((cc=lp->text[1]) == ' ') { ii = meLineGetLength(lp) - 4 ; if(ii != itemLen) ii = -1 ; } else { ii = cc - '0' ; if(ii > itemLen) ii = -1 ; } if((ii > 0) && !meStrncmp(item,lp->text+4,ii)) break ; } lp = meLineGetNext(lp) ; } if(lp == elp) { meMacro *mac ; if(!meModeTest(hbp->mode,MDLOCK)) { if(helpBufferLoad(hbp) == meABORT) return meABORT ; goto try_again ; } if((getMacroTypeS(item) == TKCMD) && ((ii = decode_fncname(item,1)) >= CK_MAX) && ((mac = getMacro(ii)) != NULL) && (mac->hlp->flag & meMACRO_FILE)) { meModeClear(hbp->mode,MDVIEW) ; if(mac->fname != NULL) execFile(mac->fname,0,1) ; else execFile(mac->name,0,1) ; helpBufferReset(hbp) ; if(!(mac->hlp->flag & meMACRO_FILE)) goto try_again ; } if(!silent) mlwrite(MWABORT,(meUByte *)"[Can't find help on %s%s]",item,sect); return meABORT ; } if((wp = meWindowPopup(BhelpN,BFND_CREAT|BFND_CLEAR|WPOP_USESTR,NULL)) == NULL) return false ; if((sectLen == 0) && (lp->text[2] != ' ')) { ss = sect ; *ss++ = '(' ; *ss++ = lp->text[2] ; if(lp->text[3] != ' ') *ss++ = lp->text[3] ; *ss++ = ')' ; *ss = '\0' ; } bp = wp->buffer ; /* Add the header */ { meUByte buff[meBUF_SIZE_MAX] ; sprintf((char *)buff,"\033cD%s%s\033cA",lp->text+4,sect) ; addLineToEob(bp,buff) ; addLineToEob(bp,(meUByte *)"\n\033lsMicroEmacs\033lm[Home]\033le \033lsCommand G\033lm[Commands]\033le \033lsVariable \033lm[Variables]\033le \033lsMacro Lan\033lm[Macro-Dev]\033le \033lsGlobal G\033lm[Glossary]\033le") ; memset(buff,boxChars[BCEW],78) ; buff[78] = '\n' ; buff[79] = '\0' ; addLineToEob(bp,buff) ; } while(((lp=meLineGetNext(lp)) != elp) && (lp->text[0] == '!')) ; while((lp != elp) && ((cc=lp->text[0]) != '!')) { if(cc == '|') { if(meStrcmp(item,lp->text+1)) lp = meLineGetNext(lp) ; } else if(cc == '$') { if(lp->text[1] == 'a') { if(sect[1] == '5') { meUByte line[meBUF_SIZE_MAX], *ss ; if((ss = getval(item)) != NULL) { addLineToEob(bp,(meUByte *)"\n\n\033cEVALUE\033cA\n") ; meStrcpy(line," \"") ; meStrncpy(line+5,ss,meBUF_SIZE_MAX-13) ; line[meBUF_SIZE_MAX-2] = '\0' ; meStrcat(line,"\"") ; addLineToEob(bp,line) ; } } if(sect[1] == '2') { if((ii = decode_fncname(item,1)) >= 0) { meBind *ktp ; meUByte line[meBUF_SIZE_MAX], *ss ; addLineToEob(bp,(meUByte *)"\n\n\033cEBINDINGS\033cA\n") ; meStrcpy(line," ") ; ss = line+4 ; for(ktp = &keytab[0] ; ktp->code != ME_INVALID_KEY ; ktp++) { if(ktp->index == ii) { *ss++ = '"' ; meGetStringFromKey(ktp->code,ss); ss += meStrlen(ss) ; *ss++ = '"' ; *ss++ = ' ' ; } } if(ss == line+4) meStrcpy(ss,"none") ; else *ss = '\0' ; addLineToEob(bp,line) ; } } } } else addLineToEob(bp,lp->text) ; lp = meLineGetNext(lp) ; } /* Add the footer */ { meUByte buff[meBUF_SIZE_MAX] ; buff[0] = '\n' ; memset(buff+1,boxChars[BCEW],78) ; sprintf((char *)buff+79,"\n\033lsCopyright\033lm%s\033le",meCopyright) ; addLineToEob(bp,buff) ; } bp->dotLine = meLineGetNext(bp->baseLine); bp->dotOffset = 0 ; bp->dotLineNo = 0 ; meModeClear(bp->mode,MDEDIT) ; /* don't flag this as a change */ meModeSet(bp->mode,MDVIEW) ; /* put this buffer view mode */ resetBufferWindows(bp) ; /* Update the window */ mlerase(MWCLEXEC); /* clear the mode line */ return true ; }
int main (int argc, char *argv[]) { BUFFER *bp; char bname[NBUFN]; /* buffer name of file to read */ int c, f, n; int ffile; /* first file flag */ int carg; /* current arg to scan */ if (argc == 2 && 0 == strcmp("--version", argv[1])) { printf("%s\n", version); exit(0); } /* initialize the editor and process the startup file */ getwinsize(); /* find out the "real" screen size */ strncpy (bname, "*scratch*", 10); /* default buffer name */ edinit (bname); /* Buffers, windows */ vtinit (); /* Displays */ ffile = TRUE; /* no file to edit yet */ update (); /* let the user know we are here */ /* scan through the command line and get the files to edit */ for (carg = 1; carg < argc; ++carg) { /* set up a buffer for this file */ makename (bname, argv[carg]); /* if this is the first file, read it in */ if (ffile) { bp = curbp; makename (bname, argv[carg]); strncpy (bp->b_bname, bname, NBUFN); strncpy (bp->b_fname, argv[carg], NFILEN); if (readin (argv[carg]) == ABORT) { strncpy (bp->b_bname, "main", 5); strncpy (bp->b_fname, "", 1); } bp->b_dotp = bp->b_linep; bp->b_doto = 0; ffile = FALSE; } else { /* set this to inactive */ bp = bfind (bname, TRUE, 0); strncpy (bp->b_fname, argv[carg], NFILEN); bp->b_active = FALSE; } } /* setup to process commands */ lastflag = 0; /* Fake last flags */ curwp->w_flag |= WFMODE; /* and force an update */ loop: update (); /* Fix up the screen */ c = getkey (TRUE); if (mpresf != FALSE) { mlerase (); update (); } f = FALSE; n = 1; if (c == (CTRL | 'X')) /* ^X is a prefix */ c = CTLX | getctl (); if (kbdmip != NULL) { /* Save macro strokes */ if (c != (CTLX | ')') && kbdmip > &kbdm[NKBDM - 6]) { ctrlg (FALSE, 0); goto loop; } if (f != FALSE) { *kbdmip++ = (CTRL | 'U'); *kbdmip++ = n; } *kbdmip++ = c; } execute (c, f, n); /* Do it */ goto loop; }
// Display a pop-up window and page it for the user. If altmodeline is true, display buffer name and filename (only) on bottom // mode line. If endprompt is true, wait for user to press a key before returning (regardless of page size). Current bindings // (if any) for backPage, forwPage, backLine, and forwLine commands are recognized as well as 'b' (backward page), 'f' or space // (forward page), 'u' (backward half page), 'd' (forward half page), 'g' (goto first page), 'G' (goto last page), ESC or 'q' // (exit), and '?' (help). Any non-navigation key gets pushed back into the input stream to be interpeted later as a command. // Return status. int bpop(Buffer *bufp,bool altmodeline,bool endprompt) { Line *lnp1,*lnp,*lpmax; int crow; // Current screen row number. int disprows; // Total number of display rows. int halfpage; // Rows in a half page. int n; // Rows to move. ushort ek; // Input extended key. char *strp,*strpz; // Line text pointers. char *hprompt = NULL; // Help prompt; bool firstpass = true; // Display special mode line if requested. if(altmodeline) { // Find last window on screen and rewrite its mode line. wupd_modeline(wnextis(NULL),bufp); } // Set up and display a pop-up "window". disprows = term.t_nrow - 2; // Check if buffer will fit on one page and if not, set lpmax to first line of last page. lpmax = NULL; n = 0; for(lnp = lforw(bufp->b_hdrlnp); lnp != bufp->b_hdrlnp; lnp = lforw(lnp)) { if(++n > disprows) { // Find beginning of last page. lpmax = bufp->b_hdrlnp; n = disprows; do { lpmax = lback(lpmax); } while(--n > 0); break; } } // Begin at the beginning. lnp1 = lforw(bufp->b_hdrlnp); halfpage = disprows / 2; n = 0; // Display a page (beginning at line lnp1 + n) and prompt for a naviagtion command. Loop until exit key entered or // endprompt is false and buffer fits on one page (lpmax is NULL). for(;;) { lnp = lnp1; // Moving backward? if(n < 0) { do { // At beginning of buffer? if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp)) break; // No, back up one line. lnp1 = lback(lnp1); } while(++n < 0); } // Moving forward? else if(n > 0) { do { // At end of buffer or max line? if(lpmax == NULL || lnp1 == bufp->b_hdrlnp || lnp1 == lpmax) break; // No, move forward one line. lnp1 = lforw(lnp1); } while(--n > 0); } // Illegal command? if(n != 0 && lnp1 == lnp) // Yes, ignore it. n = 0; else { // Found first row ... display page. lnp = lnp1; crow = 0; do { // At end of buffer? if(lnp == bufp->b_hdrlnp) { // Yes, erase remaining lines on physical screen. while(crow < disprows) { vtmove(crow,0); vteeol(); #if COLOR vscreen[crow]->v_rfcolor = gfcolor; vscreen[crow]->v_rbcolor = gbcolor; #endif vscreen[crow]->v_left = FARRIGHT; vscreen[crow]->v_right = 0; #if COLOR vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR; #else vscreen[crow++]->v_flags |= VFCHGD; #endif } break; } // Update the virtual screen image for this line. Characters past right edge of screen won't be // displayed, so ignore those. vtmove(crow,0); strpz = (strp = ltext(lnp)) + (lused(lnp) <= (int) term.t_ncol ? lused(lnp) : term.t_ncol); while(strp < strpz) vtputc(*strp++); vteeol(); #if COLOR vscreen[crow]->v_rfcolor = gfcolor; vscreen[crow]->v_rbcolor = gbcolor; #endif vscreen[crow]->v_left = FARRIGHT; vscreen[crow]->v_right = 0; #if COLOR vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR; #else vscreen[crow++]->v_flags |= VFCHGD; #endif // On to the next line. lnp = lforw(lnp); } while(crow < disprows); // Screen is full. Copy the virtual screen to the physical screen. if(pupd_all(false) != SUCCESS) return rc.status; // Bail out if called from terminp() and one-page buffer. if(firstpass && !endprompt && lpmax == NULL) goto uexit; firstpass = false; } // Display prompt. mlputs(MLHOME | MLFORCE,hprompt != NULL ? hprompt : lpmax == NULL || lnp1 == lpmax ? text201 : ": "); // "End: " if(TTflush() != SUCCESS) return rc.status; // Get response. for(;;) { // Get a keystroke and decode it. if(getkey(&ek) != SUCCESS) return rc.status; // Exit? if(ek == (CTRL | '[') || ek == 'q') goto uexit; // Forward whole page? if(ek == ' ' || ek == 'f' || iscmd(ek,forwPage)) { n = disprows - overlap; break; } // Forward half page? if(ek == 'd') { n = halfpage; break; } // Backward whole page? if(ek == 'b' || iscmd(ek,backPage)) { n = overlap - disprows; break; } // Backward half page? if(ek == 'u') { n = -halfpage; break; } // Forward a line? if(iscmd(ek,forwLine)) { n = 1; break; } // Backward a line? if(iscmd(ek,backLine)) { n = -1; break; } // First page? if(ek == 'g') { if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp)) n = -1; // Force beep. else { lnp1 = lforw(bufp->b_hdrlnp); n = 0; } break; } // Last page? if(ek == 'G') { if(lpmax == NULL || lnp1 == lpmax) n = 1; // Force beep. else { lnp1 = lpmax; n = 0; } break; } // Help? if(ek == '?') { StrList msg; // Get string list... if(vopen(&msg,NULL,false) != 0) return vrcset(); // build prompt... if(vputs(text202,&msg) != 0) // "(<SPC>,f" return vrcset(); if(hkey(&msg,forwPage,0) != SUCCESS) return rc.status; if(vputs(text203,&msg) != 0) // ") +page (b" return vrcset(); if(hkey(&msg,backPage,0) != SUCCESS) return rc.status; if(vputs(text204,&msg) != 0) // ") -page (d) +half (u) -half" return vrcset(); if(hkey(&msg,forwLine,'+') != SUCCESS || hkey(&msg,backLine,'-') != SUCCESS) return rc.status; if(vputs(text206,&msg) != 0) // " (g) first (G) last (ESC,q) quit (?) help: " return vrcset(); // and display it. if(vclose(&msg) != 0) return vrcset(); mlputs(MLHOME | MLFORCE,msg.sl_vp->v_strp); } else { // Other key. "Unget" the key for reprocessing and return. tungetc(ek); goto uexit; } } } uexit: uphard(); if(endprompt) mlerase(MLFORCE); return rc.status; }
static void PerformEditCommand( void *theEnv) { register int c; register int f; register int n; register int mflag; register int rtn_flag; char bname[NBUFN]; int num_a; char *fileName = NULL; DATA_OBJECT arg_ptr; /*====================*/ /* Get the file name. */ /*====================*/ if ((num_a = EnvArgCountCheck(theEnv,"edit",NO_MORE_THAN,1)) == -1) return; if (num_a == 1) { if (EnvArgTypeCheck(theEnv,"edit",1,SYMBOL_OR_STRING,&arg_ptr) == FALSE) return; fileName = DOToString(arg_ptr); } if(bheadp == NULL) { /**********************************************/ /* Initial entry, set up buffers and pointers */ /**********************************************/ genstrcpy(bname, "main"); /* Work out the name of */ if (num_a > 0) /* the default buffer. */ makename(bname,fileName); edinit(theEnv,bname); /* Buffers, windows. */ vtinit(theEnv); /* Displays. */ if (num_a > 0) { update(); /* You have to update */ readin(theEnv,fileName); /* in case "[New file]" */ } init_cmp_router(theEnv); /* Prepare the compile */ EnvDeactivateRouter(theEnv,"cmp_router"); /* router. */ } else { /**********************************************************/ /* Return from temporary exit, reset necessary stuff only */ /**********************************************************/ (*term.t_open)(); if (num_a > 0) { filevisit_guts(theEnv,fileName); } } sgarbf = TRUE; /* Force screen update */ lastbufn[0] = '\0'; /* Make sure last name */ /* is cleared out */ lastflag = 0; /* Fake last flags. */ loop: update(); /* Fix up the screen */ c = getkey(); if (mpresf != FALSE) { mlerase(); update(); if (c == ' ') /* ITS EMACS does this */ goto loop; } f = FALSE; n = 1; if (c == (COTL|'U')) { /* ^U, start argument */ f = TRUE; n = 4; /* with argument of 4 */ mflag = 0; /* that can be discarded. */ mlwrite("Arg: 4"); while ((((c=getkey()) >='0') && (c<='9')) || (c==(COTL|'U')) || (c=='-')){ if (c == (COTL|'U')) n = n*4; /* * If dash, and start of argument string, set arg. * to -1. Otherwise, insert it. */ else if (c == '-') { if (mflag) break; n = 0; mflag = -1; } /* * If first digit entered, replace previous argument * with digit and set sign. Otherwise, append to arg. */ else { if (!mflag) { n = 0; mflag = 1; } n = 10*n + c - '0'; } mlwrite("Arg: %d", (mflag >=0) ? n : (n ? -n : -1)); } /* * Make arguments preceded by a minus sign negative and change * the special argument "^U -" to an effective "^U -1". */ if (mflag == -1) { if (n == 0) n++; n = -n; } } if (c == (COTL|'X')) /* ^X is a prefix */ c = CTLX | getctl(); if (kbdmip != NULL) { /* Save macro strokes. */ if (c!=(CTLX|')') && kbdmip>&kbdm[NKBDM-6]) { ctrlg(theEnv,FALSE, 0); goto loop; } if (f != FALSE) { *kbdmip++ = (COTL|'U'); *kbdmip++ = n; } *kbdmip++ = c; } rtn_flag = execute(theEnv,c, f, n); /* Do it. */ if(rtn_flag == EXIT) return; else goto loop; }
/* * pico - the main routine for Pine's composer. * */ int pico(PICO *pm) { UCS c; register int f; register int n; char bname[NBUFN]; /* buffer name of file to read */ extern struct on_display ods; int checkpointcnt = 0, input = 0; int ret; char chkptfile[NLINE]; #ifdef _WINDOWS int cursor_shown; #endif Pmaster = pm; gmode = MDWRAP; gmode |= pm->pine_flags; /* high 4 bits rsv'd for pine */ alt_speller = pm->alt_spell; pico_all_done = 0; km_popped = 0; if(!vtinit()) /* Init Displays. */ return(COMP_CANCEL); strncpy(bname, "main", sizeof(bname)); /* default buffer name */ bname[sizeof(bname)-1] = '\0'; edinit(bname); /* Buffers, windows. */ if(InitMailHeader(pm)) /* init mail header structure */ gmode &= ~(P_BODY | P_HEADEND); /* flip off special header stuff */ /* setup to process commands */ lastflag = 0; /* Fake last flags. */ curbp->b_mode |= gmode; /* and set default modes*/ if(Pmaster->pine_anchor) pico_anchor = utf8_to_ucs4_cpystr(Pmaster->pine_anchor); else pico_anchor = NULL; if(Pmaster->quote_str) glo_quote_str = utf8_to_ucs4_cpystr(Pmaster->quote_str); else glo_quote_str = NULL; if(Pmaster->wordseps) glo_wordseps = ucs4_cpystr(Pmaster->wordseps); else glo_wordseps = NULL; bindtokey(DEL, (gmode & P_DELRUBS) ? forwdel : backdel); if(pm->msgtext) breplace(pm->msgtext); #ifdef _WINDOWS cursor_shown = mswin_showcaret(1); /* turn on for main window */ mswin_allowpaste(MSWIN_PASTE_FULL); mswin_setscrollcallback (pico_scroll_callback); #endif /* prepare for checkpointing */ chkptfile[0] = '\0'; chkptinit((*Pmaster->ckptdir)(chkptfile, sizeof(chkptfile)), sizeof(chkptfile)); if(gmode & P_CHKPTNOW) writeout(chkptfile, TRUE); pico_all_done = setjmp(finstate); /* jump out of HUP handler ? */ if(gmode & MDALTNOW){ while(!pico_all_done){ if(((gmode & P_BODY) || !Pmaster->headents) && alt_editor(0, 1) < 0) break; /* if problem, drop into pico */ if(Pmaster->headents){ update(); /* paint screen, n' start editing... */ HeaderEditor((gmode & (P_HEADEND | P_BODY)) ? 2 : 0, 0); gmode |= P_BODY; /* make sure we enter alt ed next */ } else pico_all_done = COMP_EXIT; } } else if(!pico_all_done){ if(gmode & P_BODY){ /* begin editing the header? */ ArrangeHeader(); /* line up pointers */ /* * Move to the offset pine asked us to move to. * Perhaps we should be checking to see if this is * a reasonable number before moving. */ if(Pmaster && Pmaster->edit_offset) forwchar(FALSE, Pmaster->edit_offset); } else{ update(); /* paint screen, */ HeaderEditor((gmode & P_HEADEND) ? 2 : 0, 0); } } while(1){ if(pico_all_done){ #ifdef _WINDOWS if(!cursor_shown) mswin_showcaret(0); mswin_allowpaste(MSWIN_PASTE_DISABLE); mswin_setscrollcallback (NULL); #endif ret = anycb() ? BUF_CHANGED : 0; switch(pico_all_done){ /* prepare for/handle final events */ case COMP_EXIT : /* already confirmed */ packheader(); if(Pmaster && (Pmaster->strip_ws_before_send || Pmaster->allow_flowed_text)) cleanwhitespace(); ret |= COMP_EXIT; break; case COMP_CANCEL : /* also already confirmed */ packheader(); ret = COMP_CANCEL; break; case COMP_GOTHUP: /* * pack up and let caller know that we've received a SIGHUP */ if(ComposerEditing) /* expand addr if needed */ call_builder(&headents[ods.cur_e], NULL, NULL); packheader(); ret |= COMP_GOTHUP; break; case COMP_SUSPEND : default: /* safest if internal error */ /* * If we're in the headers mark the current header line * with start_here bit so caller knows where to reset. * Also set the edit_offset, which is either the offset * into this header line or the offset into the body. * Packheader will adjust edit_offset for multi-line * headers. */ if(ComposerEditing){ /* in the headers */ headents[ods.cur_e].start_here = 1; Pmaster->edit_offset = ods.p_ind; } else{ register LINE *clp; register long offset; for(clp = lforw(curbp->b_linep), offset = 0L; clp != curwp->w_dotp; clp = lforw(clp)) offset += (llength(clp) + 1); Pmaster->edit_offset = offset + curwp->w_doto; } packheader(); ret |= COMP_SUSPEND; break; } if(pico_anchor) fs_give((void **) &pico_anchor); if(glo_quote_str) fs_give((void **) &glo_quote_str); if(glo_wordseps) fs_give((void **) &glo_wordseps); vttidy(); /* clean up tty modes */ zotdisplay(); /* blast display buffers */ zotedit(); our_unlink(chkptfile); Pmaster = NULL; /* blat global */ return(ret); } if(km_popped){ km_popped--; if(km_popped == 0) /* cause bottom three lines to be repainted */ curwp->w_flag |= WFHARD; } if(km_popped){ /* temporarily change to cause menu to be painted */ term.t_mrow = 2; curwp->w_ntrows -= 2; curwp->w_flag |= WFMODE; movecursor(term.t_nrow-2, 0); /* clear status line, too */ peeol(); } update(); /* Fix up the screen */ if(km_popped){ term.t_mrow = 0; curwp->w_ntrows += 2; } #ifdef MOUSE #ifdef EX_MOUSE /* New mouse function for real mouse text seletion. */ register_mfunc(mouse_in_pico, 2, 0, term.t_nrow - (term.t_mrow+1), term.t_ncol); #else mouse_in_content(KEY_MOUSE, -1, -1, -1, 0); register_mfunc(mouse_in_content, 2, 0, term.t_nrow - (term.t_mrow + 1), term.t_ncol); #endif #endif #ifdef _WINDOWS mswin_setdndcallback (composer_file_drop); mswin_mousetrackcallback(pico_cursor); #endif c = GetKey(); if (term.t_nrow < 6 && c != NODATA){ (*term.t_beep)(); emlwrite(_("Please make the screen bigger."), NULL); continue; } #ifdef MOUSE #ifdef EX_MOUSE clear_mfunc(mouse_in_pico); #else clear_mfunc(mouse_in_content); #endif #endif #ifdef _WINDOWS mswin_cleardndcallback (); mswin_mousetrackcallback(NULL); #endif if(c == NODATA || time_to_check()){ /* new mail ? */ if((*Pmaster->newmail)(c == NODATA ? 0 : 2, 1) >= 0){ int rv; if(km_popped){ term.t_mrow = 2; curwp->w_ntrows -= 2; curwp->w_flag |= WFHARD; km_popped = 0; } clearcursor(); mlerase(); rv = (*Pmaster->showmsg)(c); ttresize(); picosigs(); /* restore altered handlers */ if(rv) /* Did showmsg corrupt the display? */ PaintBody(0); /* Yes, repaint */ mpresf = 1; input = 0; } clearcursor(); movecursor(0, 0); } if(km_popped) switch(c){ case NODATA: case (CTRL|'L'): km_popped++; break; default: mlerase(); break; } if(c == NODATA) /* no op, getkey timed out */ continue; else if(!input++) (*Pmaster->keybinput)(); if (mpresf != FALSE) { /* message stay around only */ if (mpresf++ > NMMESSDELAY) /* so long! */ mlerase(); } f = FALSE; /* vestigial */ n = 1; /* Do it. */ execute(normalize_cmd(c, pfkm, 2), f, n); if(++checkpointcnt >= CHKPTDELAY){ checkpointcnt = 0; writeout(chkptfile, TRUE); } } }
int main(int argc, char **argv) { int c = -1; /* command character */ int f; /* default flag */ int n; /* numeric repeat count */ int mflag; /* negative flag on repeat */ struct buffer *bp; /* temp buffer pointer */ int firstfile; /* first file flag */ int carg; /* current arg to scan */ int startflag; /* startup executed flag */ struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */ int basec; /* c stripped of meta character */ int viewflag; /* are we starting in view mode? */ int gotoflag; /* do we need to goto a line at start? */ int gline = 0; /* if so, what line? */ int searchflag; /* Do we need to search at start? */ int saveflag; /* temp store for lastflag */ int errflag; /* C error processing? */ char bname[NBUFN]; /* buffer name of file to read */ #if CRYPT int cryptflag; /* encrypting on the way in? */ char ekey[NPAT]; /* startup encryption key */ #endif int newc; #if PKCODE & VMS (void) umask(-1); /* Use old protection (this is at wrong place). */ #endif #if PKCODE & BSD sleep(1); /* Time for window manager. */ #endif #if UNIX #ifdef SIGWINCH signal(SIGWINCH, sizesignal); #endif #endif if (argc == 2) { if (strcmp(argv[1], "--help") == 0) { usage(EXIT_FAILURE); } if (strcmp(argv[1], "--version") == 0) { version(); exit(EXIT_SUCCESS); } } /* Initialize the editor. */ vtinit(); /* Display */ edinit("main"); /* Buffers, windows */ varinit(); /* user variables */ viewflag = FALSE; /* view mode defaults off in command line */ gotoflag = FALSE; /* set to off to begin with */ searchflag = FALSE; /* set to off to begin with */ firstfile = TRUE; /* no file to edit yet */ startflag = FALSE; /* startup file not executed yet */ errflag = FALSE; /* not doing C error parsing */ #if CRYPT cryptflag = FALSE; /* no encryption by default */ #endif /* Parse the command line */ for (carg = 1; carg < argc; ++carg) { /* Process Switches */ #if PKCODE if (argv[carg][0] == '+') { gotoflag = TRUE; gline = atoi(&argv[carg][1]); } else #endif if (argv[carg][0] == '-') { switch (argv[carg][1]) { /* Process Startup macroes */ case 'a': /* process error file */ case 'A': errflag = TRUE; break; case 'e': /* -e for Edit file */ case 'E': viewflag = FALSE; break; case 'g': /* -g for initial goto */ case 'G': gotoflag = TRUE; gline = atoi(&argv[carg][2]); break; #if CRYPT case 'k': /* -k<key> for code key */ case 'K': cryptflag = TRUE; strcpy(ekey, &argv[carg][2]); break; #endif #if PKCODE case 'n': /* -n accept null chars */ case 'N': nullflag = TRUE; break; #endif case 'r': /* -r restrictive use */ case 'R': restflag = TRUE; break; case 's': /* -s for initial search string */ case 'S': searchflag = TRUE; strncpy(pat, &argv[carg][2], NPAT); break; case 'v': /* -v for View File */ case 'V': viewflag = TRUE; break; default: /* unknown switch */ /* ignore this for now */ break; } } else if (argv[carg][0] == '@') { /* Process Startup macroes */ if (startup(&argv[carg][1]) == TRUE) /* don't execute emacs.rc */ startflag = TRUE; } else { /* Process an input file */ /* set up a buffer for this file */ makename(bname, argv[carg]); unqname(bname); /* set this to inactive */ bp = bfind(bname, TRUE, 0); strcpy(bp->b_fname, argv[carg]); bp->b_active = FALSE; if (firstfile) { firstbp = bp; firstfile = FALSE; } /* set the modes appropriatly */ if (viewflag) bp->b_mode |= MDVIEW; #if CRYPT if (cryptflag) { bp->b_mode |= MDCRYPT; myencrypt((char *) NULL, 0); myencrypt(ekey, strlen(ekey)); strncpy(bp->b_key, ekey, NPAT); } #endif } } #if UNIX signal(SIGHUP, emergencyexit); signal(SIGTERM, emergencyexit); #endif /* if we are C error parsing... run it! */ if (errflag) { if (startup("error.cmd") == TRUE) startflag = TRUE; } /* if invoked with no other startup files, run the system startup file here */ if (startflag == FALSE) { startup(""); startflag = TRUE; } discmd = TRUE; /* P.K. */ /* if there are any files to read, read the first one! */ bp = bfind("main", FALSE, 0); if (firstfile == FALSE && (gflags & GFREAD)) { swbuffer(firstbp); zotbuf(bp); } else bp->b_mode |= gmode; /* Deal with startup gotos and searches */ if (gotoflag && searchflag) { update(FALSE); mlwrite("(Can not search and goto at the same time!)"); } else if (gotoflag) { if (gotoline(TRUE, gline) == FALSE) { update(FALSE); mlwrite("(Bogus goto argument)"); } } else if (searchflag) { if (forwhunt(FALSE, 0) == FALSE) update(FALSE); } /* Setup to process commands. */ lastflag = 0; /* Fake last flags. */ loop: /* Execute the "command" macro...normally null. */ saveflag = lastflag; /* Preserve lastflag through this. */ execute(META | SPEC | 'C', FALSE, 1); lastflag = saveflag; #if TYPEAH && PKCODE if (typahead()) { newc = getcmd(); update(FALSE); do { fn_t execfunc; if (c == newc && (execfunc = getbind(c)) != NULL && execfunc != insert_newline && execfunc != insert_tab) newc = getcmd(); else break; } while (typahead()); c = newc; } else { update(FALSE); c = getcmd(); } #else /* Fix up the screen */ update(FALSE); /* get the next command from the keyboard */ c = getcmd(); #endif /* if there is something on the command line, clear it */ if (mpresf != FALSE) { mlerase(); update(FALSE); #if CLRMSG if (c == ' ') /* ITS EMACS does this */ goto loop; #endif } f = FALSE; n = 1; /* do META-# processing if needed */ basec = c & ~META; /* strip meta char off if there */ if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) { f = TRUE; /* there is a # arg */ n = 0; /* start with a zero default */ mflag = 1; /* current minus flag */ c = basec; /* strip the META */ while ((c >= '0' && c <= '9') || (c == '-')) { if (c == '-') { /* already hit a minus or digit? */ if ((mflag == -1) || (n != 0)) break; mflag = -1; } else { n = n * 10 + (c - '0'); } if ((n == 0) && (mflag == -1)) /* lonely - */ mlwrite("Arg:"); else mlwrite("Arg: %d", n * mflag); c = getcmd(); /* get the next key */ } n = n * mflag; /* figure in the sign */ } /* do ^U repeat argument processing */ if (c == reptc) { /* ^U, start argument */ f = TRUE; n = 4; /* with argument of 4 */ mflag = 0; /* that can be discarded. */ mlwrite("Arg: 4"); while (((c = getcmd()) >= '0' && c <= '9') || c == reptc || c == '-') { if (c == reptc) if ((n > 0) == ((n * 4) > 0)) n = n * 4; else n = 1; /* * If dash, and start of argument string, set arg. * to -1. Otherwise, insert it. */ else if (c == '-') { if (mflag) break; n = 0; mflag = -1; } /* * If first digit entered, replace previous argument * with digit and set sign. Otherwise, append to arg. */ else { if (!mflag) { n = 0; mflag = 1; } n = 10 * n + c - '0'; } mlwrite("Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)); } /* * Make arguments preceded by a minus sign negative and change * the special argument "^U -" to an effective "^U -1". */ if (mflag == -1) { if (n == 0) n++; n = -n; } } /* and execute the command */ execute(c, f, n); goto loop; }
int main(int argc, char *argv[]) { BUFFER *bp; char bname[NBUFN]; /* buffer name of file to read */ int c, f, n, mflag; int ffile; /* first file flag */ int basec; /* c stripped of meta character */ /* initialize the editor and process the startup file */ getwinsize(); /* find out the "real" screen size */ strncpy(bname, "main", 5); /* default buffer name */ edinit(bname); /* Buffers, windows */ vtinit(); /* Displays */ ffile = TRUE; /* no file to edit yet */ update(); /* let the user know we are here */ /* scan through the command line and get the files to edit */ if (argc > 2) { (void) fprintf(stderr, "Can only edit one file at a time\n"); exit(1); } else if (argc == 2) { /* set up a buffer for this file */ makename(bname, argv[1]); /* if this is the first file, read it in */ if (ffile) { bp = curbp; makename(bname, argv[1]); strncpy(bp->b_bname, bname, NBUFN); strncpy(bp->b_fname, argv[1], NFILEN); if (readin(argv[1]) == ABORT) { strncpy(bp->b_bname, "main", 5); strncpy(bp->b_fname, "", 1); } bp->b_dotp = bp->b_linep; bp->b_doto = 0; ffile = FALSE; } else { /* set this to inactive */ bp = bfind(bname, TRUE, 0); strncpy(bp->b_fname, argv[1], NFILEN); bp->b_active = FALSE; } } /* setup to process commands */ lastflag = 0; /* Fake last flags */ curwp->w_flag |= WFMODE; /* and force an update */ loop: update(); /* Fix up the screen */ c = getkey(); if (mpresf != FALSE) { mlerase(); update(); } f = FALSE; n = 1; /* do META-# processing if needed */ basec = c & ~META; /* strip meta char off if there */ if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) { f = TRUE; /* there is a # arg */ n = 0; /* start with a zero default */ mflag = 1; /* current minus flag */ c = basec; /* strip the META */ while ((c >= '0' && c <= '9') || (c == '-')) { if (c == '-') { /* already hit a minus or digit? */ if ((mflag == -1) || (n != 0)) break; mflag = -1; } else n = n * 10 + (c - '0'); if ((n == 0) && (mflag == -1)) /* lonely - */ mlwrite("Arg:"); else mlwrite("Arg: %d", n * mflag); c = getkey(); /* get the next key */ } n = n * mflag; /* figure in the sign */ } /* do ^U repeat argument processing */ if (c == (CTRL | 'U')) { /* ^U, start argument */ f = TRUE; n = 4; /* with argument of 4 */ mflag = 0; /* that can be discarded */ mlwrite("Arg: 4"); while (((c = getkey ()) >= '0') && ((c <= '9') || (c == (CTRL | 'U')) || (c == '-'))) { if (c == (CTRL | 'U')) n = n * 4; /* * If dash, and start of argument string, set arg. * to -1. Otherwise, insert it. */ else if (c == '-') { if (mflag) break; n = 0; mflag = -1; } /* * If first digit entered, replace previous argument * with digit and set sign. Otherwise, append to arg. */ else { if (!mflag) { n = 0; mflag = 1; } n = 10 * n + c - '0'; } mlwrite("Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)); } /* * Make arguments preceded by a minus sign negative and change * the special argument "^U -" to an effective "^U -1". */ if (mflag == -1) { if (n == 0) n++; n = -n; } } if (c == (CTRL | 'X')) /* ^X is a prefix */ c = CTLX | getctl (); if (kbdmip != NULL) { /* Save macro strokes */ if (c != (CTLX | ')') && kbdmip > &kbdm[NKBDM - 6]) { ctrlg(FALSE, 0); goto loop; } if (f != FALSE) { *kbdmip++ = (CTRL | 'U'); *kbdmip++ = n; } *kbdmip++ = c; } execute(c, f, n); /* Do it */ goto loop; }
/* For the "operator" commands -- the following command is a motion, or * the operator itself is repeated. All operate on regions. */ int operator(int f, int n, OpsFunc fn, const char *str) { int c; int thiskey; int status; const CMDFUNC *cfp; /* function to execute */ char tok[NSTRING]; /* command incoming */ BUFFER *ourbp; #if OPT_MOUSE WINDOW *wp0 = curwp; #endif doingopcmd = TRUE; pre_op_dot = DOT; ourbp = curbp; if (havemotion != NULL) { cfp = havemotion; havemotion = NULL; } else { mlwrite("%s operation pending...",str); (void)update(FALSE); /* get the next command from the keyboard */ /* or a command line, as approp. */ if (clexec) { macarg(tok); /* get the next token */ if (!strcmp(tok,"lines")) cfp = &f_godotplus; else cfp = engl2fnc(tok); } else { thiskey = lastkey; c = kbd_seq(); #if OPT_MOUSE if (curwp != wp0) { unkeystroke(c); doingopcmd = FALSE; return FALSE; } #endif /* allow second chance for entering counts */ do_repeats(&c,&f,&n); if (thiskey == lastkey) cfp = &f_godotplus; else cfp = kcod2fnc(c); } if (cfp) mlerase(); else mlforce("[No such function]"); } if (!cfp) { doingopcmd = FALSE; return FALSE; } if ((cfp->c_flags & MOTION) == 0) { kbd_alarm(); doingopcmd = FALSE; return(ABORT); } /* motion is interpreted as affecting full lines */ if (regionshape == EXACT) { if (cfp->c_flags & FL) regionshape = FULLLINE; if (cfp->c_flags & RECT) regionshape = RECTANGLE; } /* and execute the motion */ status = execute(cfp, f,n); if (status != TRUE) { doingopcmd = FALSE; regionshape = EXACT; mlforce("[Motion failed]"); return FALSE; } 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 { status = (fn)(); } if (ourbp == curbp) /* in case the func switched buffers on us */ swapmark(); if (regionshape == FULLLINE) (void)firstnonwhite(FALSE,1); regionshape = EXACT; doingopcmd = FALSE; haveregion = FALSE; return status; }
int forwsearch(int f, int n) { int status; int wrapt = FALSE, wrapt2 = FALSE; int repl_mode = FALSE; UCS defpat[NPAT]; int search = FALSE; EML eml; /* resolve the repeat count */ if (n == 0) n = 1; if (n < 1) /* search backwards */ FWS_RETURN(0); defpat[0] = '\0'; /* ask the user for the text of a pattern */ while(1){ if (gmode & MDREPLACE) status = srpat("Search", defpat, NPAT, repl_mode); else status = readpattern("Search", TRUE); switch(status){ case TRUE: /* user typed something */ search = TRUE; break; case HELPCH: /* help requested */ if(Pmaster){ VARS_TO_SAVE *saved_state; saved_state = save_pico_state(); (*Pmaster->helper)(Pmaster->search_help, _("Help for Searching"), 1); if(saved_state){ restore_pico_state(saved_state); free_pico_state(saved_state); } } else pico_help(SearchHelpText, _("Help for Searching"), 1); case (CTRL|'L'): /* redraw requested */ pico_refresh(FALSE, 1); update(); break; case (CTRL|'V'): gotoeob(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'Y'): gotobob(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'T') : switch(status = readnumpat(_("Search to Line Number : "))){ case -1 : emlwrite(_("Search to Line Number Cancelled"), NULL); FWS_RETURN(FALSE); case 0 : emlwrite(_("Line number must be greater than zero"), NULL); FWS_RETURN(FALSE); case -2 : emlwrite(_("Line number must contain only digits"), NULL); FWS_RETURN(FALSE); case -3 : continue; default : gotoline(0, status); mlerase(); FWS_RETURN(TRUE); } break; case (CTRL|'W'): { LINE *linep = curwp->w_dotp; int offset = curwp->w_doto; gotobop(0, 1); gotobol(0, 1); /* * if we're asked to backup and we're already * */ if((lastflag & CFSRCH) && linep == curwp->w_dotp && offset == curwp->w_doto && !(offset == 0 && lback(linep) == curbp->b_linep)){ backchar(0, 1); gotobop(0, 1); gotobol(0, 1); } } mlerase(); FWS_RETURN(TRUE); case (CTRL|'O'): if(curwp->w_dotp != curbp->b_linep){ gotoeop(0, 1); forwchar(0, 1); } mlerase(); FWS_RETURN(TRUE); case (CTRL|'U'): fillbuf(0, 1); mlerase(); FWS_RETURN(TRUE); case (CTRL|'R'): /* toggle replacement option */ repl_mode = !repl_mode; break; default: if(status == ABORT) emlwrite(_("Search Cancelled"), NULL); else mlerase(); FWS_RETURN(FALSE); } /* replace option is disabled */ if (!(gmode & MDREPLACE)){ ucs4_strncpy(defpat, pat, NPAT); defpat[NPAT-1] = '\0'; break; } else if (search){ /* search now */ ucs4_strncpy(pat, defpat, NPAT); /* remember this search for the future */ pat[NPAT-1] = '\0'; break; } } /* * This code is kind of dumb. What I want is successive C-W 's to * move dot to successive occurences of the pattern. So, if dot is * already sitting at the beginning of the pattern, then we'll move * forward a char before beginning the search. We'll let the * automatic wrapping handle putting the dot back in the right * place... */ status = 0; /* using "status" as int temporarily! */ while(1){ if(defpat[status] == '\0'){ forwchar(0, 1); break; /* find next occurence! */ } if(status + curwp->w_doto >= llength(curwp->w_dotp) || !eq(defpat[status],lgetc(curwp->w_dotp, curwp->w_doto + status).c)) break; /* do nothing! */ status++; } /* search for the pattern */ while (n-- > 0) { if((status = forscan(&wrapt,defpat,NULL,0,PTBEG)) == FALSE) break; } /* and complain if not there */ if (status == FALSE){ char *utf8; UCS x[1]; x[0] = '\0'; utf8 = ucs4_to_utf8_cpystr(defpat ? defpat : x); /* TRANSLATORS: reporting the result of a failed search */ eml.s = utf8; emlwrite(_("\"%s\" not found"), &eml); if(utf8) fs_give((void **) &utf8); } else if((gmode & MDREPLACE) && repl_mode == TRUE){ status = replace_pat(defpat, &wrapt2); /* replace pattern */ if (wrapt == TRUE || wrapt2 == TRUE){ eml.s = (status == ABORT) ? "cancelled but wrapped" : "Wrapped"; emlwrite("Replacement %s", &eml); } } else if(wrapt == TRUE){ emlwrite("Search Wrapped", NULL); } else if(status == TRUE){ emlwrite("", NULL); } FWS_RETURN(status); }
int main(int argc, char *argv[]) #endif { UCS c; register int f; register int n; register BUFFER *bp; int viewflag = FALSE; /* are we starting in view mode?*/ int starton = 0; /* where's dot to begin with? */ int setlocale_collate = 1; char bname[NBUFN]; /* buffer name of file to read */ char *file_to_edit = NULL; char *display_charmap = NULL, *dc; char *keyboard_charmap = NULL; int use_system = 0; char *err = NULL; set_input_timeout(600); Pmaster = NULL; /* turn OFF composer functionality */ km_popped = 0; /* * Read command line flags before initializing, otherwise, we never * know to init for f_keys... */ file_to_edit = pico_args(argc, argv, &starton, &viewflag, &setlocale_collate); set_collation(setlocale_collate, 1); #define cpstr(s) strcpy((char *)fs_get(1+strlen(s)), s) #ifdef _WINDOWS init_utf8_display(1, NULL); #else /* UNIX */ if(display_character_set) display_charmap = cpstr(display_character_set); #if HAVE_LANGINFO_H && defined(CODESET) else if((dc = nl_langinfo_codeset_wrapper()) != NULL) display_charmap = cpstr(dc); #endif if(!display_charmap) display_charmap = cpstr("US-ASCII"); if(keyboard_character_set) keyboard_charmap = cpstr(keyboard_character_set); else keyboard_charmap = cpstr(display_charmap); if(use_system_translation){ #if PREREQ_FOR_SYS_TRANSLATION use_system++; /* This modifies its arguments */ if(setup_for_input_output(use_system, &display_charmap, &keyboard_charmap, &input_cs, &err) == -1){ fprintf(stderr, "%s\n", err ? err : "trouble with character set"); exit(1); } else if(err){ fprintf(stderr, "%s\n", err); fs_give((void **) &err); } #endif } if(!use_system){ if(setup_for_input_output(use_system, &display_charmap, &keyboard_charmap, &input_cs, &err) == -1){ fprintf(stderr, "%s\n", err ? err : "trouble with character set"); exit(1); } else if(err){ fprintf(stderr, "%s\n", err); fs_give((void **) &err); } } if(keyboard_charmap){ set_locale_charmap(keyboard_charmap); free((void *) keyboard_charmap); } if(display_charmap) free((void *) display_charmap); #endif /* UNIX */ /* * There are a couple arguments that we need to be sure * are converted for internal use. */ if(alt_speller) alt_speller = cpstr(fname_to_utf8(alt_speller)); if(opertree && opertree[0]){ strncpy(opertree, fname_to_utf8(opertree), sizeof(opertree)); opertree[sizeof(opertree)-1] = '\0'; } if(glo_quote_str_orig) glo_quote_str = utf8_to_ucs4_cpystr(fname_to_utf8(glo_quote_str_orig)); if(glo_wordseps_orig) glo_wordseps = utf8_to_ucs4_cpystr(fname_to_utf8(glo_wordseps_orig)); if(file_to_edit) file_to_edit = cpstr(fname_to_utf8(file_to_edit)); #undef cpstr #if defined(DOS) || defined(OS2) if(file_to_edit){ /* strip quotes? */ int l; if(strchr("'\"", file_to_edit[0]) && (l = strlen(file_to_edit)) > 1 && file_to_edit[l-1] == file_to_edit[0]){ file_to_edit[l-1] = '\0'; /* blat trailing quote */ file_to_edit++; /* advance past leading quote */ } } #endif if(!vtinit()) /* Displays. */ exit(1); strncpy(bname, "main", sizeof(bname)); /* default buffer name */ bname[sizeof(bname)-1] = '\0'; edinit(bname); /* Buffers, windows. */ update(); /* let the user know we are here */ #ifdef _WINDOWS mswin_setwindow(NULL, NULL, NULL, NULL, NULL, NULL); mswin_showwindow(); mswin_showcaret(1); /* turn on for main window */ mswin_allowpaste(MSWIN_PASTE_FULL); mswin_setclosetext("Use the ^X command to exit Pico."); mswin_setscrollcallback (pico_scroll_callback); #endif #if defined(USE_TERMCAP) || defined(USE_TERMINFO) || defined(VMS) if(kbesc == NULL){ /* will arrow keys work ? */ (*term.t_putchar)('\007'); emlwrite("Warning: keypad keys may be non-functional", NULL); } #endif /* USE_TERMCAP/USE_TERMINFO/VMS */ if(file_to_edit){ /* Any file to edit? */ makename(bname, file_to_edit); /* set up a buffer for this file */ bp = curbp; /* read in first file */ makename(bname, file_to_edit); strncpy(bp->b_bname, bname, sizeof(bp->b_bname)); bp->b_bname[sizeof(bp->b_bname)-1] = '\0'; if(strlen(file_to_edit) >= NFILEN){ char buf[128]; snprintf(buf, sizeof(buf), "Filename \"%.10s...\" too long", file_to_edit); emlwrite(buf, NULL); file_to_edit = NULL; } else{ strncpy(bp->b_fname, file_to_edit, sizeof(bp->b_fname)); bp->b_fname[sizeof(bp->b_fname)-1] = '\0'; if (((gmode&MDTREE) && !in_oper_tree(file_to_edit)) || readin(file_to_edit, (viewflag==FALSE), TRUE) == ABORT) { if ((gmode&MDTREE) && !in_oper_tree(file_to_edit)){ EML eml; eml.s = opertree; emlwrite(_("Can't read file from outside of %s"), &eml); } file_to_edit = NULL; } } if(!file_to_edit){ strncpy(bp->b_bname, "main", sizeof(bp->b_bname)); bp->b_bname[sizeof(bp->b_bname)-1] = '\0'; strncpy(bp->b_fname, "", sizeof(bp->b_fname)); bp->b_fname[sizeof(bp->b_fname)-1] = '\0'; } bp->b_dotp = bp->b_linep; bp->b_doto = 0; if (viewflag) /* set the view mode */ bp->b_mode |= MDVIEW; } /* setup to process commands */ lastflag = 0; /* Fake last flags. */ curbp->b_mode |= gmode; /* and set default modes*/ curwp->w_flag |= WFMODE; /* and force an update */ if(timeoutset){ EML eml; eml.s = comatose(get_input_timeout()); emlwrite(_("Checking for new mail every %s seconds"), &eml); } forwline(0, starton - 1); /* move dot to specified line */ while(1){ if(km_popped){ km_popped--; if(km_popped == 0) /* cause bottom three lines to be repainted */ curwp->w_flag |= WFHARD; } if(km_popped){ /* temporarily change to cause menu to be painted */ term.t_mrow = 2; curwp->w_ntrows -= 2; curwp->w_flag |= WFMODE; movecursor(term.t_nrow-2, 0); /* clear status line, too */ peeol(); } update(); /* Fix up the screen */ if(km_popped){ term.t_mrow = 0; curwp->w_ntrows += 2; } #ifdef MOUSE #ifdef EX_MOUSE /* New mouse function for real mouse text seletion. */ register_mfunc(mouse_in_pico, 2, 0, term.t_nrow - (term.t_mrow + 1), term.t_ncol); #else mouse_in_content(KEY_MOUSE, -1, -1, 0, 0); register_mfunc(mouse_in_content, 2, 0, term.t_nrow - (term.t_mrow + 1), term.t_ncol); #endif #endif #ifdef _WINDOWS mswin_setdndcallback (pico_file_drop); mswin_mousetrackcallback(pico_cursor); #endif c = GetKey(); #ifdef MOUSE #ifdef EX_MOUSE clear_mfunc(mouse_in_pico); #else clear_mfunc(mouse_in_content); #endif #endif #ifdef _WINDOWS mswin_cleardndcallback (); mswin_mousetrackcallback(NULL); #endif if(timeoutset && (c == NODATA || time_to_check())){ if(pico_new_mail()) emlwrite(_("You may possibly have new mail."), NULL); } if(km_popped) switch(c){ case NODATA: case (CTRL|'L'): km_popped++; break; default: /* clear bottom three lines */ mlerase(); break; } if(c == NODATA) continue; if(mpresf){ /* erase message line? */ if(mpresf++ > MESSDELAY) mlerase(); } f = FALSE; n = 1; #ifdef MOUSE clear_mfunc(mouse_in_content); #endif /* Do it. */ execute(normalize_cmd(c, fkm, 1), f, n); } }
/* Replace a pattern with the pattern the user types in one or more times. */ int replace_pat(UCS *defpat, int *wrapt) { register int status; UCS lpat[NPAT], origpat[NPAT]; /* case sensitive pattern */ EXTRAKEYS menu_pat[2]; int repl_all = FALSE; UCS *b; char utf8tmp[NPMT]; UCS prompt[NPMT]; UCS *promptp; forscan(wrapt, defpat, NULL, 0, PTBEG); /* go to word to be replaced */ lpat[0] = '\0'; /* additional 'replace all' menu option */ menu_pat[0].name = "^X"; menu_pat[0].key = (CTRL|'X'); menu_pat[0].label = N_("Repl All"); KS_OSDATASET(&menu_pat[0], KS_NONE); menu_pat[1].name = NULL; while(1) { update(); (*term.t_rev)(1); get_pat_cases(origpat, defpat); pputs(origpat, 1); /* highlight word */ (*term.t_rev)(0); snprintf(utf8tmp, NPMT, "Replace%s \"", repl_all ? " every" : ""); b = utf8_to_ucs4_cpystr(utf8tmp); if(b){ ucs4_strncpy(prompt, b, NPMT); prompt[NPMT-1] = '\0'; fs_give((void **) &b); } promptp = &prompt[ucs4_strlen(prompt)]; expandp(defpat, promptp, NPMT-(promptp-prompt)); prompt[NPMT-1] = '\0'; promptp += ucs4_strlen(promptp); b = utf8_to_ucs4_cpystr("\" with"); if(b){ ucs4_strncpy(promptp, b, NPMT-(promptp-prompt)); promptp += ucs4_strlen(promptp); prompt[NPMT-1] = '\0'; fs_give((void **) &b); } if(rpat[0] != '\0'){ if((promptp-prompt) < NPMT-2){ *promptp++ = ' '; *promptp++ = '['; *promptp = '\0'; } expandp(rpat, promptp, NPMT-(promptp-prompt)); prompt[NPMT-1] = '\0'; promptp += ucs4_strlen(promptp); if((promptp-prompt) < NPMT-1){ *promptp++ = ']'; *promptp = '\0'; } } if((promptp-prompt) < NPMT-3){ *promptp++ = ' '; *promptp++ = ':'; *promptp++ = ' '; *promptp = '\0'; } prompt[NPMT-1] = '\0'; status = mlreplyd(prompt, lpat, NPAT, QDEFLT, menu_pat); curwp->w_flag |= WFMOVE; switch(status){ case TRUE : case FALSE : if(lpat[0]){ ucs4_strncpy(rpat, lpat, NPAT); /* remember default */ rpat[NPAT-1] = '\0'; } else{ ucs4_strncpy(lpat, rpat, NPAT); /* use default */ lpat[NPAT-1] = '\0'; } if (repl_all){ status = replace_all(defpat, lpat); } else{ chword(defpat, lpat); /* replace word */ update(); status = TRUE; } if(status == TRUE) emlwrite("", NULL); return(status); case HELPCH: /* help requested */ if(Pmaster){ VARS_TO_SAVE *saved_state; saved_state = save_pico_state(); (*Pmaster->helper)(Pmaster->search_help, _("Help for Searching"), 1); if(saved_state){ restore_pico_state(saved_state); free_pico_state(saved_state); } } else pico_help(SearchHelpText, _("Help for Searching"), 1); case (CTRL|'L'): /* redraw requested */ pico_refresh(FALSE, 1); update(); break; case (CTRL|'X'): /* toggle replace all option */ if (repl_all){ repl_all = FALSE; /* TRANSLATORS: abbreviation for Replace All occurences */ menu_pat[0].label = N_("Repl All"); } else{ repl_all = TRUE; /* TRANSLATORS: Replace just one occurence */ menu_pat[0].label = N_("Repl One"); } break; default: if(status == ABORT){ emlwrite(_("Replacement Cancelled"), NULL); pico_refresh(FALSE, 1); } else{ mlerase(); chword(defpat, origpat); } update(); return(FALSE); } } }