*/
#ifndef lint
-static char sccsid[] = "@(#)c.c 5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)c.c 5.5 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
FILE *inputt;
int *errnum;
{
+ int l_flag=1;
+
if (Start_default && End_default)
Start = End = current;
else
return;
}
Start_default = End_default = 0;
+ if (End == bottom)
+ l_flag = 0;
/* first delete the lines */
d(inputt, errnum);
return;
*errnum = 0;
- if ((current != NULL) && (current != bottom))
+ /*if ((current != NULL) && (current != bottom)) RMSR */
+ if ((current != NULL) && l_flag)
current = current->above;
add_flag = 1;
Start_default = End_default = 1;
*/
#ifndef lint
-static char sccsid[] = "@(#)e.c 5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)e.c 5.7 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
}
}
change_flag = 0;
+ *errnum = 1;
}
.\"
.\" %sccs.include.redist.roff%
.\"
-.\" @(#)ed.1 5.8 (Berkeley) %G%
+.\" @(#)ed.1 5.9 (Berkeley) %G%
.\"
.TH ED 1 ""
.SH NAME
RE's are, outside of this document, now refered to as
.IR "basic regular expressions" .
Basic regular expressions (BRE's), traditionally described in \fIed(1)\fR are
-now fully described in regex(1). BRE's are, for the most part, the same as
+now fully described in regex(7). BRE's are, for the most part, the same as
the old RE's - the name has changed and the expressions extended to meet
POSIX 1003.2 specifications. (See the search command for more details.)
.TP
The move command moves the addressed lines in the buffer
to after the address
.BR a .
-Line 0 is valid for this command.
+Line 0 is valid as the address \fBa\fR for this command.
.B Current
is the location in the
.B buffer
.B buffer
to after the address
.BR a .
-Address 0 is valid for this command.
+Address 0 is valid as the address \fBa\fR for this command.
.B Current
is the last line transcribed.
.TP 5
.I
Advanced editing on UNIX
.br
-regex(7), sed(1), learn(1), ex(1), POSIX 1003.2 (4.20)
+ex(1), learn(1), regex(3), regex(7), sed(1), vi(1), POSIX 1003.2 (4.20)
.SH "AUTHOR"
Rodney Ruddock
.SH DIAGNOSTICS
under POSIX 1003.2. Old scripts with RE's should work without
modification.
.PP
+Regular expression logic is very tight. If you believe a command with a
+regular expression in it has performed erroneously then a close reading
+of regex(7) is likely required.
+.PP
+Address `0' is legal only for those commands which explicitly state that
+it may be used; its use is illegal for all other commands.
+.PP
The special form of substitute has been maintained for backward
compatability and should not be used in scripts if they are to
portable.
*/
#ifndef lint
-static char sccsid[] = "@(#)filename.c 5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)filename.c 5.7 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
l_fname[l_cnt] = '\0';
break;
} else
- if ((ss == '!') && (l_esc == 0))
+ if ((ss == '!') && (l_esc == 0) && (l_cnt < 2))
l_bang_flag = 1;
else
if ((ss != ' ') || (l_bang_flag))
*/
#ifndef lint
-static char sccsid[] = "@(#)g.c 5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)g.c 5.10 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
int *errnum;
{
static char *l_template_g;
- char *l_patt, l_ohm[130];
+ char *l_patt;
static int l_template_flag = 0;
int l_re_success, l_flag_v = 0, l_err, l_num;
register l_gut_cnt, a;
l_posix_cur = current;
#endif
current = Start;
- strcpy(l_ohm, help_msg);
sigspecial++;
}
point:
- strcpy(help_msg, l_ohm);
if (GV_flag == 0) {
fclose(l_fp);
unlink(l_template_g);
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)main.c 5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c 5.12 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
int argc;
char *argv[];
{
- int l_num, errnum = 0, l_err = 0;
+ int l_num, errnum=0, l_err=0;
char *l_fnametmp, *l_col, buf[2];
struct winsize win;
start_up_flag = 0;
/* simulate the 'e' at startup */
e2(inputt, errnum);
+ if (*errnum == 0)
+ goto errmsg2;
}
}
for (;;) {
case 'e':
case 'E':
e(inputt, errnum);
+ if (*errnum == 0)
+ goto errmsg2;
break;
case 'f':
f(inputt, errnum);
/*ss = 'q';*/
case 'q':
case 'Q':
+ if ((!isatty(STDIN_FILENO)) && (ss == 'q'))
+ ss = 'Q';
q(inputt, errnum);
break;
case 'r':
r(inputt, errnum);
+ if (*errnum == 0)
+ goto errmsg2;
break;
case 's':
s(inputt, errnum);
else if (*errnum < 0) {
errmsg: while (((ss = getc(inputt)) != '\n') &&
(ss != EOF));
+ (void)printf("?\n");
+errmsg2: if (help_flag)
+ (void)printf("%s\n", help_msg);
exit_code = 4;
- if (g_flag == 0) {
- (void)printf("?\n");
- if (help_flag)
- (void)printf("%s\n", help_msg);
- }
/* for people wanting scripts to carry on after a cmd error, then
* define NOENDONSCRIPT on the compile line.
*/
*/
#ifndef lint
-static char sccsid[] = "@(#)r.c 5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)r.c 5.8 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
if (sigint_flag && (!sigspecial))
SIGINT_ACTION;
} else {
+ if (End_default) {
+ End = bottom;
+ End_default = 0;
+ }
l_temp = filename(inputt, errnum);
if (*errnum == 1)
l_filename_read = l_temp;
pclose(l_fp);
else
fclose(l_fp);
- change_flag = 1;
+ /*change_flag = 1; done in input_lines() already */
if (sigint_flag)
SIGINT_ACTION;
*errnum = 1;
*/
#ifndef lint
-static char sccsid[] = "@(#)re.c 5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)re.c 5.6 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
{
int l_cnt, l_flag=0;
#ifndef REG_STARTEND
- char *l_offset = strg;
+ char *l_offset=strg, *l_end;
#endif
if (n <= 0)
if (pass)
reprematch[0].rm_so = 0;
reprematch[0].rm_eo = len;
- if (!reprematch[0].rm_so)
- l_flag = 1;
#else
strg = &strg[offset];
- if (!offset)
- l_flag = 1;
+ l_end = &strg[strlen(strg)];
#endif
for (l_cnt = 0;;) {
if (regexec(reprecomp,
l_cnt++;
else
return (REG_NOMATCH);
- /* to skip over null RE matchings */
- if (l_flag)
- l_flag = 0;
- else
- if (reprematch[0].rm_so == reprematch[0].rm_eo) {
- l_cnt--;
- if ((++reprematch[0].rm_eo) > len)
- return (REG_NOMATCH);
- }
+
if (l_cnt >= n)
break;
#ifdef REG_STARTEND
+ if (reprematch[0].rm_so == reprematch[0].rm_eo)
+ reprematch[0].rm_eo++;
reprematch[0].rm_so = reprematch[0].rm_eo;
+ if (reprematch[0].rm_so == len)
+ return (REG_NOMATCH);
reprematch[0].rm_eo = len;
#else
strg = &strg[reprematch[0].rm_eo];
+ if (strg == l_end)
+ return (REG_NOMATCH);
#endif
/* if a "^" started the current RE we only loop once */
if (RE_sol)
* l_slen[0] == len of what is to be replaced.
* l_slen[1-9] == len of each backref.
*/
- if ((*replacer == '%') && (replacer[1] == 1)) {
+ if ((*replacer == '%') && (replacer[1] == '\0')) {
l_string = calloc(l_len_whole - l_slen[0] +
(strlen(l_prev_r)) + 2, sizeof(char));
if (l_string == NULL) {
l_string[l_len_before + offset] = '\0';
#endif
strcat(l_string, l_prev_r);
+ l_new_rm_eo = strlen(l_string);
#ifdef REG_STARTEND
strcat(l_string, &line[repmatch[0].rm_eo]);
#else
strcat(l_string, &line[repmatch[0].rm_eo + offset]);
#endif
+ repmatch[0].rm_eo = l_new_rm_eo;
return (l_string);
}
*/
#ifndef lint
-static char sccsid[] = "@(#)sub.c 5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)sub.c 5.8 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
static int l_count2 = 1, l_global = 0, l_print = 0;
static int l_first_pass_flag = 0;
static char *l_match = NULL, *l_repl = NULL;
- LINE *l_s_ret, *l_temp_line, *l_temp_line2, *l_kval, *l_last;
+ LINE *l_s_ret, *l_temp_line, *l_temp_line2, *l_kval, *l_last, *l_cur;
int l_s_flag, l_count, l_matched, l_nflag, l_cnt, yy, l_sr_flag = 0;
- int l_err, l_sl, l_rep_flag, l_u_reuse_flag=0, l_local_len;
+ int l_err, l_sl, l_rep_flag, l_u_reuse_flag=0, l_local_len, l_nudge=0;
char *l_match2 = NULL, *l_local = NULL, *l_local_temp = NULL;
#ifndef REG_STARTEND
size_t l_offset = 0;
if (sigint_flag && (!sigspecial))
SIGINT_ACTION;
bcg2:
+ l_cur = current;
current = Start;
l_s_flag = 0;
do {
#endif
do {
RE_match[0].rm_so = RE_match[0].rm_eo;
+ if (l_nudge)
+ RE_match[0].rm_so++;
+ l_nudge = 0;
#ifdef REG_STARTEND
l_matched = regexec_n(&RE_comp, l_local,
(size_t)RE_SEC, RE_match, 0, l_count,
&l_offset, 0);
#endif
if (l_matched == 0) {
- if ((l_s_flag == 0) && (g_flag == 0))
+ if ((l_s_flag == 0) && (g_flag == 0)) {
+ current = l_cur;
u_clr_stk();
+ current = Start;
+ }
l_count = l_s_flag = 1;
l_rep_flag = 0;
/*
* position of that character has changed
* because of the replacement.
*/
+ if (RE_match[0].rm_so == RE_match[0].rm_eo)
+ l_nudge = 1;
#ifdef REG_STARTEND
l_local = re_replace(l_local,
(size_t)(RE_SEC - 1), RE_match, &l_repl[1]);
if (l_s_flag == 0) {
current = Start;
- strcpy(help_msg, "no matches found for substitution");
- *errnum = -1;
- ungetc('\n', inputt);
+ if (!g_flag) {
+ strcpy(help_msg, "no matches found for substitution");
+ *errnum = -1;
+ ungetc('\n', inputt);
+ }
+ else
+ *errnum = 0;
return;
}
change_flag = 1;
*/
#ifndef lint
-static char sccsid[] = "@(#)u.c 5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)u.c 5.5 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#include "ed.h"
#include "extern.h"
+struct d_layer *old_d_stk=NULL;
+
+
/*
* This restores the buffer to the state it was in just before the
* last buffer modifying command - the global commands (with command
{
LINE *l_current, *l_bottom, *l_top;
struct u_layer *l_old_u_stk, *l_temp;
+ struct d_layer *l_d_temp;
sigspecial++;
/* This is done because undo can be undone. */
u_top = top;
u_bottom = bottom;
+ l_d_temp = old_d_stk;
+ old_d_stk = d_stk;
+ d_stk = l_d_temp;
+
l_old_u_stk = u_stk;
u_stk = NULL;
free(l_temp);
}
u_stk = NULL; /* Just to sure. */
+ old_d_stk = NULL; /* so something in use isn't freed! */
sigspecial--;
if (sigint_flag && (!sigspecial))
SIGINT_ACTION;
*/
#ifndef lint
-static char sccsid[] = "@(#)w.c 5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)w.c 5.8 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
} else
if (Start_default)
Start = End;
- if (Start == NULL) {
- strcpy(help_msg, "buffer empty");
- *errnum = -1;
- return;
- }
Start_default = End_default = 0;
l_sl = ss;
goto point;
/* Write it out and get a report on the number of bytes written. */
- l_ttl = edwrite(l_fp, Start, End);
+ if (Start == NULL)
+ l_ttl = 0;
+ else
+ l_ttl = edwrite(l_fp, Start, End);
if (explain_flag > 0) /* For -s option. */
printf("%d\n", l_ttl);