📄 edmisc.c
字号:
curwp->w_flag |= WFMOVE;
/*************************************************
* Read a character from standard i/o *
* if charater is a blank(comparable to Zmacs) *
* or 'y' or 'Y' the replacement will occur. *
* Else if character is 'n' or 'N' it will skip *
* and go to next occurence of string. *
* Else exit the function *
*************************************************/
mlwrite("Do you want to replace this? [y/n]");
update();
c = (*term.t_getchar)();
if((c ==' ')||(c == 'y')||(c == 'Y'))
{
lreplace(theEnv,pat2);
clp = curwp->w_dotp;
cbo = curwp->w_doto;
}
else if ((c == 'n')||(c == 'N'))
cbo = tbo;
else
return(TRUE);
}
}
}
curwp->w_flag |= WFMOVE;
curwp->w_doto -= strlen(pat);
update();
mlwrite("No more occurrences of [%s] in buffer",pat2);
genfree(theEnv,(void *) pat2,(unsigned) strlen(pat) + 1);
return(TRUE);
}
/***************************************************
* Replace old string with new string *
***************************************************/
globle int lreplace(
void *theEnv,
char *pat2)
{
int doto;
unsigned i;
char *cp1,*cp2;
LINE *lp1,*lp2;
WINDOW *wp;
lchange(WFEDIT);
lp1 = curwp->w_dotp;
doto = curwp->w_doto;
if((lp2 =lalloc(theEnv,(int) (lp1->l_used - strlen(pat2) + strlen(pat) ))) == NULL)
return(FALSE);
cp1 = &lp1->l_text[0];
cp2 = &lp2->l_text[0];
/* Copy first part of line which is containing old string to new line */
while(cp1 != &lp1->l_text[doto])
*cp2++ = *cp1++;
/* reseve space for new string in new line */
cp2 += strlen(pat);
cp1 += strlen(pat2);
/* Copy third part of line which is containing old string to new line */
while (cp1 != &lp1->l_text[lp1->l_used])
*cp2++ = *cp1++;
*cp2 = *cp1;
/* Rearrange pointer, insert new line and delete old line */
lp1->l_bp->l_fp = lp2;
lp2->l_fp = lp1->l_fp;
lp1->l_fp->l_bp = lp2;
lp2->l_bp = lp1->l_bp;
/* copy the new string in to new line */
for(i=0;i<strlen(pat);i++)
lp2->l_text[doto + i] = pat[i];
/* Up-date current pointers and values */
curwp->w_doto += strlen(pat2);
wp = wheadp;
while (wp != NULL)
{ if (wp->w_linep == lp1)
wp->w_linep = lp2;
if(wp->w_dotp == lp1)
wp->w_dotp = lp2;
if (wp == curwp)
wp->w_doto += (strlen(pat) - strlen(pat2));
if(wp->w_markp ==lp1)
{
wp->w_markp = lp2;
wp->w_marko += (strlen(pat) - strlen(pat2));
}
wp = wp->w_wndp;
}
genfree(theEnv,(void *) lp1,(unsigned) sizeof(LINE) + lp1->l_size);
return(TRUE);
}
/********************************************************
* This function will search for the matching bracket *
* of any bracket *
* It is currently bounded to C-X-^ *
********************************************************/
#if IBM_TBC
#pragma argsused
#endif
globle int smatchb(
void *theEnv,
int f,
int n)
{
int cbo,c;
LINE *clp;
clp = curwp->w_dotp;
cbo = curwp->w_doto;
c = lgetc(clp,cbo);
if((c == '{')||(c == '(')||(c=='['))
{
/* search forward for matched closing bracket '}' */
if(searchcl(c) == FALSE)
return(FALSE);
}
else if((c == '}')||(c == ')')||(c == ']'))
{
/* search backward for matched opening bracket '{'*/
if(searchop(c) == FALSE)
return(FALSE);
}
else
return(FALSE);
curwp->w_flag |= WFMOVE;
return(TRUE);
}
/***************************************************
* This function will search for closing bracket, *
* including '}' , ')' , ']' *
***************************************************
* The mechanism of this function is it will check *
* every character of the file from the current *
* position down and increase i by 1 every time it *
* find an openning bracket and decrease i by 1 *
* every time it find a closing bracket.When i = 0 *
* the matching bracket is found. *
***************************************************/
globle int searchcl(
int tempch)
{
LINE *lp;
int tbo,c,i=1;
lp = curwp->w_dotp;
tbo = curwp->w_doto + 1;
while(i > 0)
{
if(lp == curbp->b_linep)
{
mlwrite("Matched bracket is not found");
return(FALSE);
}
if(tbo== llength(lp))
{
lp = lforw(lp);
tbo = 0;
c = '\n';
}
else
c = lgetc(lp,tbo++);
switch(tempch)
{
case '{':
if (c == '{')
i++;
else if (c =='}')
i--;
break;
case '(':
if (c == '(')
i++;
else if (c ==')')
i--;
break;
case '[':
if (c == '[')
i++;
else if (c ==']')
i--;
break;
}
}
curwp->w_dotp = lp;
curwp->w_doto = tbo - 1;
return(TRUE);
}
/**************************************************************
* This function will search backward for the opening bracket,*
* including '{' , '(' , '[' . *
**************************************************************
* The mechanism of this function is similiar to the searchcl,*
* except that it will go through the file backward *
**************************************************************/
globle int searchop(
int tempch)
{
LINE *lp;
int tbo,c,i=1;
lp = curwp->w_dotp;
tbo = curwp->w_doto;
while(i>0)
{
if(tbo == 0)
{
lp = lback(lp);
if(lp == curbp->b_linep)
{
mlwrite("matched bracket is not found");
return(FALSE);
}
tbo = llength(lp) + 1;
}
if(--tbo == llength(lp))
c = '\n';
else
c = lgetc(lp,tbo);
switch(tempch)
{
case '}':
if(c == '}')
i++;
else if (c == '{')
i--;
break;
case ')':
if (c == ')')
i++;
else if (c =='(')
i--;
break;
case ']':
if (c == ']')
i++;
else if (c =='[')
i--;
break;
}
}
curwp->w_dotp = lp;
curwp->w_doto = tbo ;
return(TRUE);
}
/*
* Read a pattern. Stash it in the external variable "pat". The "pat" is not
* updated if the user types in an empty line. If the user typed an empty line,
* and there is no old pattern, it is an error. Display the old pattern, in the
* style of Jeff Lomicka. There is some do-it-yourself control expansion.
*/
globle int readpattern(
void *theEnv,
char *prompt)
{
register char *cp1;
register char *cp2;
register int c;
register int s;
char tpat[NPAT+20];
cp1 = &tpat[0]; /* Copy prompt */
cp2 = prompt;
while ((c = *cp2++) != '\0')
*cp1++ = (char) c;
if (pat[0] != '\0') /* Old pattern */
{
*cp1++ = ' ';
*cp1++ = '[';
cp2 = &pat[0];
while ((c = *cp2++) != 0)
{
if (cp1 < &tpat[NPAT+20-6]) /* "??]: \0" */
{
if (c<0x20 || c==0x7F) {
*cp1++ = '^';
c ^= 0x40;
}
else if (c == '%') /* Map "%" to */
*cp1++ = (char) c; /* "%%". */
*cp1++ = (char) c;
}
}
*cp1++ = ']';
}
*cp1++ = ':'; /* Finish prompt */
*cp1++ = ' ';
*cp1++ = '\0';
s = mlreply(theEnv,tpat, tpat, NPAT); /* Read pattern */
if (s == TRUE) /* Specified */
strcpy(pat, tpat);
else if (s == FALSE && pat[0] != 0) /* CR, but old one */
s = TRUE;
return (s);
}
/* =========================================================================
* SPAWN FUNCTIONS
* =========================================================================
*/
/*
* The routines in this section are called to create a subjob running a
* command interpreter.
*/
/*
* Create a subjob with a copy of the command intrepreter in it. When the
* command interpreter exits, mark the screen as garbage so that you do a full
* repaint. Bound to "C-C". The message at the start in VMS puts out a newline.
* Under some (unknown) condition, you don't get one free when DCL starts up.
*/
#if IBM_TBC
#pragma argsused
#endif
globle int spawncli(
void *theEnv,
int f,
int n)
{
#if UNIX_7 || UNIX_V || IBM_MSC || IBM_TBC || IBM_ZTC || IBM_ICB || IBM_SC || IBM_GCC
register char *cp;
#endif
#if VAX_VMS
movecursor(term.t_nrow, 0); /* In last line. */
mlputs("[Starting DCL]\r\n");
(*term.t_flush)(); /* Ignore "ttcol". */
sgarbf = TRUE;
return (sys(NULL)); /* NULL => DCL. */
#endif
#if IBM_MSC || IBM_TBC || IBM_ZTC || IBM_ICB || IBM_SC || IBM_GCC
cp = getenv("COMSPEC");
if (cp == NULL)
return(TRUE);
movecursor(term.t_nrow, 0); /* Seek to last line. */
(*term.t_flush)();
system(cp); /* Run CLI. */
sgarbf = TRUE;
return(TRUE);
#endif
#if UNIX_7 || UNIX_V
movecursor(term.t_nrow, 0); /* Seek to last line. */
(*term.t_flush)();
ttclose(); /* stty to old settings */
if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
system(cp);
else
system("exec /bin/sh");
sgarbf = TRUE;
sleep(2);
ttopen();
return(TRUE);
#endif
}
/*
* Run a one-liner in a subjob. When the command returns, wait for a single
* character to be typed, then mark the screen as garbage so a full repaint is
* done. Bound to "C-X !".
*/
#if IBM_TBC
#pragma argsused
#endif
globle int spawn(
void *theEnv,
int f,
int n)
{
register int s;
char line[NLINE];
#if VAX_VMS
if ((s=mlreply(theEnv,"DCL command: ", line, NLINE)) != TRUE)
return (s);
(*term.t_putchar)('\n'); /* Already have '\r' */
(*term.t_flush)();
s = sys(line); /* Run the command. */
mlputs("\r\n\n[End]"); /* Pause. */
(*term.t_flush)();
while ((*term.t_getchar)() != '\r')
;
sgarbf = TRUE;
return (s);
#endif
#if IBM_MSC || IBM_TBC || IBM_ZTC || IBM_ICB || IBM_SC || IBM_GCC
if ((s=mlreply(theEnv,"MS-DOS command: ", line, NLINE)) != TRUE)
return (s);
system(line);
mlwrite("Hit any key to continue");
(*term.t_getchar)(); /* Pause. */
sgarbf = TRUE;
return (TRUE);
#endif
#if UNIX_7 || UNIX_V
if ((s=mlreply(theEnv,"! ", line, NLINE)) != TRUE)
return (s);
(*term.t_putchar)('\n'); /* Already have '\r' */
(*term.t_flush)();
ttclose(); /* stty to old modes */
system(line);
sleep(2);
ttopen();
mlputs("[End]"); /* Pause. */
(*term.t_flush)();
while ((s = (*term.t_getchar)()) != '\r' && s != ' ')
;
sgarbf = TRUE;
return (TRUE);
#endif
}
#if VAX_VMS
/*
* Run a command. The "cmd" is a pointer to a command string, or NULL if you
* want to run a copy of DCL in the subjob (this is how the standard routine
* LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
* and the way out, because DCL does not want the channel to be in raw mode.
*/
globle int sys(
char *cmd)
{
struct dsc$descriptor cdsc;
struct dsc$descriptor *cdscp;
long status;
long substatus;
long iosb[2];
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
oldmode, sizeof(oldmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
return (FALSE);
cdscp = NULL; /* Assume DCL. */
if (cmd != NULL) { /* Build descriptor. */
cdsc.dsc$a_pointer = cmd;
cdsc.dsc$w_length = strlen(cmd);
cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
cdsc.dsc$b_class = DSC$K_CLASS_S;
cdscp = &cdsc;
}
status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
if (status != SS$_NORMAL)
substatus = status;
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
newmode, sizeof(newmode), 0, 0, 0, 0);
if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
return (FALSE);
if ((substatus&STS$M_SUCCESS) == 0) /* Command failed. */
return (FALSE);
return (TRUE);
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -