Deleted Added
full compact
main.c (78939) main.c (81220)
1/* main.c: This file contains the main control and user-interface routines
2 for the ed line editor. */
3/*-
4 * Copyright (c) 1993 Andrew Moore, Talke Studio.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifndef lint
1/* main.c: This file contains the main control and user-interface routines
2 for the ed line editor. */
3/*-
4 * Copyright (c) 1993 Andrew Moore, Talke Studio.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifndef lint
30static char * const copyright =
30static const char copyright[] =
31"@(#) Copyright (c) 1993 Andrew Moore, Talke Studio. \n\
32 All rights reserved.\n";
33#endif /* not lint */
34
35#ifndef lint
31"@(#) Copyright (c) 1993 Andrew Moore, Talke Studio. \n\
32 All rights reserved.\n";
33#endif /* not lint */
34
35#ifndef lint
36#if 0
37static char * const rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
38#else
39static char * const rcsid =
40 "$FreeBSD: head/bin/ed/main.c 78939 2001-06-28 22:06:27Z dd $";
41#endif
36static const char rcsid[] =
37 "$FreeBSD: head/bin/ed/main.c 81220 2001-08-06 22:01:31Z mike $";
42#endif /* not lint */
43
44/*
45 * CREDITS
46 *
47 * This program is based on the editor algorithm described in
48 * Brian W. Kernighan and P. J. Plauger's book "Software Tools
49 * in Pascal," Addison-Wesley, 1981.

--- 45 unchanged lines hidden (view full) ---

95int scripted = 0; /* if set, suppress diagnostics */
96int sigflags = 0; /* if set, signals received while mutex set */
97int sigactive = 0; /* if set, signal handlers are enabled */
98
99char old_filename[PATH_MAX] = ""; /* default filename */
100long current_addr; /* current address in editor buffer */
101long addr_last; /* last address in editor buffer */
102int lineno; /* script line number */
38#endif /* not lint */
39
40/*
41 * CREDITS
42 *
43 * This program is based on the editor algorithm described in
44 * Brian W. Kernighan and P. J. Plauger's book "Software Tools
45 * in Pascal," Addison-Wesley, 1981.

--- 45 unchanged lines hidden (view full) ---

91int scripted = 0; /* if set, suppress diagnostics */
92int sigflags = 0; /* if set, signals received while mutex set */
93int sigactive = 0; /* if set, signal handlers are enabled */
94
95char old_filename[PATH_MAX] = ""; /* default filename */
96long current_addr; /* current address in editor buffer */
97long addr_last; /* last address in editor buffer */
98int lineno; /* script line number */
103char *prompt; /* command-line prompt */
104char *dps = "*"; /* default command-line prompt */
99const char *prompt; /* command-line prompt */
100const char *dps = "*"; /* default command-line prompt */
105
106const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n";
107
108/* ed: line editor */
109int
110main(argc, argv)
111 int argc;
112 char **argv;

--- 51 unchanged lines hidden (view full) ---

164 signal(SIGINT, signal_int);
165#ifdef _POSIX_SOURCE
166 if ((status = sigsetjmp(env, 1)))
167#else
168 if ((status = setjmp(env)))
169#endif
170 {
171 fputs("\n?\n", stderr);
101
102const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n";
103
104/* ed: line editor */
105int
106main(argc, argv)
107 int argc;
108 char **argv;

--- 51 unchanged lines hidden (view full) ---

160 signal(SIGINT, signal_int);
161#ifdef _POSIX_SOURCE
162 if ((status = sigsetjmp(env, 1)))
163#else
164 if ((status = setjmp(env)))
165#endif
166 {
167 fputs("\n?\n", stderr);
172 sprintf(errmsg, "interrupt");
168 errmsg = "interrupt";
173 } else {
174 init_buffers();
175 sigactive = 1; /* enable signal handlers */
176 if (argc && **argv && is_legal_filename(*argv)) {
177 if (read_file(*argv, 0) < 0 && !isatty(0))
178 quit(2);
179 else if (**argv != '!')
180 if (strlcpy(old_filename, *argv, sizeof(old_filename))
181 >= sizeof(old_filename))
182 quit(2);
183 } else if (argc) {
184 fputs("?\n", stderr);
185 if (**argv == '\0')
169 } else {
170 init_buffers();
171 sigactive = 1; /* enable signal handlers */
172 if (argc && **argv && is_legal_filename(*argv)) {
173 if (read_file(*argv, 0) < 0 && !isatty(0))
174 quit(2);
175 else if (**argv != '!')
176 if (strlcpy(old_filename, *argv, sizeof(old_filename))
177 >= sizeof(old_filename))
178 quit(2);
179 } else if (argc) {
180 fputs("?\n", stderr);
181 if (**argv == '\0')
186 sprintf(errmsg, "invalid filename");
182 errmsg = "invalid filename";
187 if (!isatty(0))
188 quit(2);
189 }
190 }
191 for (;;) {
192 if (status < 0 && garrulous)
193 fprintf(stderr, "%s\n", errmsg);
194 if (prompt) {
195 printf("%s", prompt);
196 fflush(stdout);
197 }
198 if ((n = get_tty_line()) < 0) {
199 status = ERR;
200 continue;
201 } else if (n == 0) {
202 if (modified && !scripted) {
203 fputs("?\n", stderr);
183 if (!isatty(0))
184 quit(2);
185 }
186 }
187 for (;;) {
188 if (status < 0 && garrulous)
189 fprintf(stderr, "%s\n", errmsg);
190 if (prompt) {
191 printf("%s", prompt);
192 fflush(stdout);
193 }
194 if ((n = get_tty_line()) < 0) {
195 status = ERR;
196 continue;
197 } else if (n == 0) {
198 if (modified && !scripted) {
199 fputs("?\n", stderr);
204 sprintf(errmsg, "warning: file modified");
200 errmsg = "warning: file modified";
205 if (!isatty(0)) {
206 fprintf(stderr, garrulous ?
207 "script, line %d: %s\n" :
208 "", lineno, errmsg);
209 quit(2);
210 }
211 clearerr(stdin);
212 modified = 0;
213 status = EMOD;
214 continue;
215 } else
216 quit(0);
217 } else if (ibuf[n - 1] != '\n') {
218 /* discard line */
201 if (!isatty(0)) {
202 fprintf(stderr, garrulous ?
203 "script, line %d: %s\n" :
204 "", lineno, errmsg);
205 quit(2);
206 }
207 clearerr(stdin);
208 modified = 0;
209 status = EMOD;
210 continue;
211 } else
212 quit(0);
213 } else if (ibuf[n - 1] != '\n') {
214 /* discard line */
219 sprintf(errmsg, "unexpected end-of-file");
215 errmsg = "unexpected end-of-file";
220 clearerr(stdin);
221 status = ERR;
222 continue;
223 }
224 isglobal = 0;
225 if ((status = extract_addr_range()) >= 0 &&
226 (status = exec_command()) >= 0)
227 if (!status ||
228 (status = display_lines(current_addr, current_addr,
229 status)) >= 0)
230 continue;
231 switch (status) {
232 case EOF:
233 quit(0);
234 case EMOD:
235 modified = 0;
236 fputs("?\n", stderr); /* give warning */
216 clearerr(stdin);
217 status = ERR;
218 continue;
219 }
220 isglobal = 0;
221 if ((status = extract_addr_range()) >= 0 &&
222 (status = exec_command()) >= 0)
223 if (!status ||
224 (status = display_lines(current_addr, current_addr,
225 status)) >= 0)
226 continue;
227 switch (status) {
228 case EOF:
229 quit(0);
230 case EMOD:
231 modified = 0;
232 fputs("?\n", stderr); /* give warning */
237 sprintf(errmsg, "warning: file modified");
233 errmsg = "warning: file modified";
238 if (!isatty(0)) {
239 fprintf(stderr, garrulous ?
240 "script, line %d: %s\n" :
241 "", lineno, errmsg);
242 quit(2);
243 }
244 break;
245 case FATAL:

--- 42 unchanged lines hidden (view full) ---

288 if ((addr_cnt = min(addr_cnt, 2)) == 1 || second_addr != addr)
289 first_addr = second_addr;
290 return (addr == ERR) ? ERR : 0;
291}
292
293
294#define SKIP_BLANKS() while (isspace((unsigned char)*ibufp) && *ibufp != '\n') ibufp++
295
234 if (!isatty(0)) {
235 fprintf(stderr, garrulous ?
236 "script, line %d: %s\n" :
237 "", lineno, errmsg);
238 quit(2);
239 }
240 break;
241 case FATAL:

--- 42 unchanged lines hidden (view full) ---

284 if ((addr_cnt = min(addr_cnt, 2)) == 1 || second_addr != addr)
285 first_addr = second_addr;
286 return (addr == ERR) ? ERR : 0;
287}
288
289
290#define SKIP_BLANKS() while (isspace((unsigned char)*ibufp) && *ibufp != '\n') ibufp++
291
296#define MUST_BE_FIRST() \
297 if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
292#define MUST_BE_FIRST() do { \
293 if (!first) { \
294 errmsg = "invalid address"; \
295 return ERR; \
296 } \
297} while (0);
298
299/* next_addr: return the next line address in the command buffer */
300long
301next_addr()
302{
298
299/* next_addr: return the next line address in the command buffer */
300long
301next_addr()
302{
303 char *hd;
303 const char *hd;
304 long addr = current_addr;
305 long n;
306 int first = 1;
307 int c;
308
309 SKIP_BLANKS();
310 for (hd = ibufp;; first = 0)
311 switch (c = *ibufp) {

--- 47 unchanged lines hidden (view full) ---

359 addr = addr_last;
360 break;
361 }
362 /* FALL THROUGH */
363 default:
364 if (ibufp == hd)
365 return EOF;
366 else if (addr < 0 || addr_last < addr) {
304 long addr = current_addr;
305 long n;
306 int first = 1;
307 int c;
308
309 SKIP_BLANKS();
310 for (hd = ibufp;; first = 0)
311 switch (c = *ibufp) {

--- 47 unchanged lines hidden (view full) ---

359 addr = addr_last;
360 break;
361 }
362 /* FALL THROUGH */
363 default:
364 if (ibufp == hd)
365 return EOF;
366 else if (addr < 0 || addr_last < addr) {
367 sprintf(errmsg, "invalid address");
367 errmsg = "invalid address";
368 return ERR;
369 } else
370 return addr;
371 }
372 /* NOTREACHED */
373}
374
375
376#ifdef BACKWARDS
377/* GET_THIRD_ADDR: get a legal address from the command buffer */
378#define GET_THIRD_ADDR(addr) \
379{ \
380 long ol1, ol2; \
381\
382 ol1 = first_addr, ol2 = second_addr; \
383 if (extract_addr_range() < 0) \
384 return ERR; \
385 else if (addr_cnt == 0) { \
368 return ERR;
369 } else
370 return addr;
371 }
372 /* NOTREACHED */
373}
374
375
376#ifdef BACKWARDS
377/* GET_THIRD_ADDR: get a legal address from the command buffer */
378#define GET_THIRD_ADDR(addr) \
379{ \
380 long ol1, ol2; \
381\
382 ol1 = first_addr, ol2 = second_addr; \
383 if (extract_addr_range() < 0) \
384 return ERR; \
385 else if (addr_cnt == 0) { \
386 sprintf(errmsg, "destination expected"); \
386 errmsg = "destination expected"; \
387 return ERR; \
388 } else if (second_addr < 0 || addr_last < second_addr) { \
387 return ERR; \
388 } else if (second_addr < 0 || addr_last < second_addr) { \
389 sprintf(errmsg, "invalid address"); \
389 errmsg = "invalid address"; \
390 return ERR; \
391 } \
392 addr = second_addr; \
393 first_addr = ol1, second_addr = ol2; \
394}
395#else /* BACKWARDS */
396/* GET_THIRD_ADDR: get a legal address from the command buffer */
397#define GET_THIRD_ADDR(addr) \
398{ \
399 long ol1, ol2; \
400\
401 ol1 = first_addr, ol2 = second_addr; \
402 if (extract_addr_range() < 0) \
403 return ERR; \
404 if (second_addr < 0 || addr_last < second_addr) { \
390 return ERR; \
391 } \
392 addr = second_addr; \
393 first_addr = ol1, second_addr = ol2; \
394}
395#else /* BACKWARDS */
396/* GET_THIRD_ADDR: get a legal address from the command buffer */
397#define GET_THIRD_ADDR(addr) \
398{ \
399 long ol1, ol2; \
400\
401 ol1 = first_addr, ol2 = second_addr; \
402 if (extract_addr_range() < 0) \
403 return ERR; \
404 if (second_addr < 0 || addr_last < second_addr) { \
405 sprintf(errmsg, "invalid address"); \
405 errmsg = "invalid address"; \
406 return ERR; \
407 } \
408 addr = second_addr; \
409 first_addr = ol1, second_addr = ol2; \
410}
411#endif
412
413

--- 11 unchanged lines hidden (view full) ---

425 case 'n': \
426 gflag |= GNP, ibufp++; \
427 break; \
428 default: \
429 done++; \
430 } \
431 } while (!done); \
432 if (*ibufp++ != '\n') { \
406 return ERR; \
407 } \
408 addr = second_addr; \
409 first_addr = ol1, second_addr = ol2; \
410}
411#endif
412
413

--- 11 unchanged lines hidden (view full) ---

425 case 'n': \
426 gflag |= GNP, ibufp++; \
427 break; \
428 default: \
429 done++; \
430 } \
431 } while (!done); \
432 if (*ibufp++ != '\n') { \
433 sprintf(errmsg, "invalid command suffix"); \
433 errmsg = "invalid command suffix"; \
434 return ERR; \
435 } \
436}
437
438
439/* sflags */
440#define SGG 001 /* complement previous global substitute suffix */
441#define SGP 002 /* complement previous print suffix */

--- 52 unchanged lines hidden (view full) ---

494 current_addr = addr;
495 break;
496 case 'e':
497 if (modified && !scripted)
498 return EMOD;
499 /* fall through */
500 case 'E':
501 if (addr_cnt > 0) {
434 return ERR; \
435 } \
436}
437
438
439/* sflags */
440#define SGG 001 /* complement previous global substitute suffix */
441#define SGP 002 /* complement previous print suffix */

--- 52 unchanged lines hidden (view full) ---

494 current_addr = addr;
495 break;
496 case 'e':
497 if (modified && !scripted)
498 return EMOD;
499 /* fall through */
500 case 'E':
501 if (addr_cnt > 0) {
502 sprintf(errmsg, "unexpected address");
502 errmsg = "unexpected address";
503 return ERR;
504 } else if (!isspace((unsigned char)*ibufp)) {
503 return ERR;
504 } else if (!isspace((unsigned char)*ibufp)) {
505 sprintf(errmsg, "unexpected command suffix");
505 errmsg = "unexpected command suffix";
506 return ERR;
507 } else if ((fnp = get_filename()) == NULL)
508 return ERR;
509 GET_COMMAND_SUFFIX();
510 if (delete_lines(1, addr_last) < 0)
511 return ERR;
512 clear_undo_stack();
513 if (close_sbuf() < 0)
514 return ERR;
515 else if (open_sbuf() < 0)
516 return FATAL;
517 if (*fnp && *fnp != '!') strcpy(old_filename, fnp);
518#ifdef BACKWARDS
519 if (*fnp == '\0' && *old_filename == '\0') {
506 return ERR;
507 } else if ((fnp = get_filename()) == NULL)
508 return ERR;
509 GET_COMMAND_SUFFIX();
510 if (delete_lines(1, addr_last) < 0)
511 return ERR;
512 clear_undo_stack();
513 if (close_sbuf() < 0)
514 return ERR;
515 else if (open_sbuf() < 0)
516 return FATAL;
517 if (*fnp && *fnp != '!') strcpy(old_filename, fnp);
518#ifdef BACKWARDS
519 if (*fnp == '\0' && *old_filename == '\0') {
520 sprintf(errmsg, "no current filename");
520 errmsg = "no current filename";
521 return ERR;
522 }
523#endif
524 if (read_file(*fnp ? fnp : old_filename, 0) < 0)
525 return ERR;
526 clear_undo_stack();
527 modified = 0;
528 u_current_addr = u_addr_last = -1;
529 break;
530 case 'f':
531 if (addr_cnt > 0) {
521 return ERR;
522 }
523#endif
524 if (read_file(*fnp ? fnp : old_filename, 0) < 0)
525 return ERR;
526 clear_undo_stack();
527 modified = 0;
528 u_current_addr = u_addr_last = -1;
529 break;
530 case 'f':
531 if (addr_cnt > 0) {
532 sprintf(errmsg, "unexpected address");
532 errmsg = "unexpected address";
533 return ERR;
534 } else if (!isspace((unsigned char)*ibufp)) {
533 return ERR;
534 } else if (!isspace((unsigned char)*ibufp)) {
535 sprintf(errmsg, "unexpected command suffix");
535 errmsg = "unexpected command suffix";
536 return ERR;
537 } else if ((fnp = get_filename()) == NULL)
538 return ERR;
539 else if (*fnp == '!') {
536 return ERR;
537 } else if ((fnp = get_filename()) == NULL)
538 return ERR;
539 else if (*fnp == '!') {
540 sprintf(errmsg, "invalid redirection");
540 errmsg = "invalid redirection";
541 return ERR;
542 }
543 GET_COMMAND_SUFFIX();
544 if (*fnp) strcpy(old_filename, fnp);
545 printf("%s\n", strip_escapes(old_filename));
546 break;
547 case 'g':
548 case 'v':
549 case 'G':
550 case 'V':
551 if (isglobal) {
541 return ERR;
542 }
543 GET_COMMAND_SUFFIX();
544 if (*fnp) strcpy(old_filename, fnp);
545 printf("%s\n", strip_escapes(old_filename));
546 break;
547 case 'g':
548 case 'v':
549 case 'G':
550 case 'V':
551 if (isglobal) {
552 sprintf(errmsg, "cannot nest global commands");
552 errmsg = "cannot nest global commands";
553 return ERR;
554 } else if (check_addr_range(1, addr_last) < 0)
555 return ERR;
556 else if (build_active_list(c == 'g' || c == 'G') < 0)
557 return ERR;
558 else if ((n = (c == 'G' || c == 'V')))
559 GET_COMMAND_SUFFIX();
560 isglobal++;
561 if (exec_global(n, gflag) < 0)
562 return ERR;
563 break;
564 case 'h':
565 if (addr_cnt > 0) {
553 return ERR;
554 } else if (check_addr_range(1, addr_last) < 0)
555 return ERR;
556 else if (build_active_list(c == 'g' || c == 'G') < 0)
557 return ERR;
558 else if ((n = (c == 'G' || c == 'V')))
559 GET_COMMAND_SUFFIX();
560 isglobal++;
561 if (exec_global(n, gflag) < 0)
562 return ERR;
563 break;
564 case 'h':
565 if (addr_cnt > 0) {
566 sprintf(errmsg, "unexpected address");
566 errmsg = "unexpected address";
567 return ERR;
568 }
569 GET_COMMAND_SUFFIX();
570 if (*errmsg) fprintf(stderr, "%s\n", errmsg);
571 break;
572 case 'H':
573 if (addr_cnt > 0) {
567 return ERR;
568 }
569 GET_COMMAND_SUFFIX();
570 if (*errmsg) fprintf(stderr, "%s\n", errmsg);
571 break;
572 case 'H':
573 if (addr_cnt > 0) {
574 sprintf(errmsg, "unexpected address");
574 errmsg = "unexpected address";
575 return ERR;
576 }
577 GET_COMMAND_SUFFIX();
578 if ((garrulous = 1 - garrulous) && *errmsg)
579 fprintf(stderr, "%s\n", errmsg);
580 break;
581 case 'i':
582 if (second_addr == 0) {
575 return ERR;
576 }
577 GET_COMMAND_SUFFIX();
578 if ((garrulous = 1 - garrulous) && *errmsg)
579 fprintf(stderr, "%s\n", errmsg);
580 break;
581 case 'i':
582 if (second_addr == 0) {
583 sprintf(errmsg, "invalid address");
583 errmsg = "invalid address";
584 return ERR;
585 }
586 GET_COMMAND_SUFFIX();
587 if (!isglobal) clear_undo_stack();
588 if (append_lines(second_addr - 1) < 0)
589 return ERR;
590 break;
591 case 'j':
592 if (check_addr_range(current_addr, current_addr + 1) < 0)
593 return ERR;
594 GET_COMMAND_SUFFIX();
595 if (!isglobal) clear_undo_stack();
596 if (first_addr != second_addr &&
597 join_lines(first_addr, second_addr) < 0)
598 return ERR;
599 break;
600 case 'k':
601 c = *ibufp++;
602 if (second_addr == 0) {
584 return ERR;
585 }
586 GET_COMMAND_SUFFIX();
587 if (!isglobal) clear_undo_stack();
588 if (append_lines(second_addr - 1) < 0)
589 return ERR;
590 break;
591 case 'j':
592 if (check_addr_range(current_addr, current_addr + 1) < 0)
593 return ERR;
594 GET_COMMAND_SUFFIX();
595 if (!isglobal) clear_undo_stack();
596 if (first_addr != second_addr &&
597 join_lines(first_addr, second_addr) < 0)
598 return ERR;
599 break;
600 case 'k':
601 c = *ibufp++;
602 if (second_addr == 0) {
603 sprintf(errmsg, "invalid address");
603 errmsg = "invalid address";
604 return ERR;
605 }
606 GET_COMMAND_SUFFIX();
607 if (mark_line_node(get_addressed_line_node(second_addr), c) < 0)
608 return ERR;
609 break;
610 case 'l':
611 if (check_addr_range(current_addr, current_addr) < 0)
612 return ERR;
613 GET_COMMAND_SUFFIX();
614 if (display_lines(first_addr, second_addr, gflag | GLS) < 0)
615 return ERR;
616 gflag = 0;
617 break;
618 case 'm':
619 if (check_addr_range(current_addr, current_addr) < 0)
620 return ERR;
621 GET_THIRD_ADDR(addr);
622 if (first_addr <= addr && addr < second_addr) {
604 return ERR;
605 }
606 GET_COMMAND_SUFFIX();
607 if (mark_line_node(get_addressed_line_node(second_addr), c) < 0)
608 return ERR;
609 break;
610 case 'l':
611 if (check_addr_range(current_addr, current_addr) < 0)
612 return ERR;
613 GET_COMMAND_SUFFIX();
614 if (display_lines(first_addr, second_addr, gflag | GLS) < 0)
615 return ERR;
616 gflag = 0;
617 break;
618 case 'm':
619 if (check_addr_range(current_addr, current_addr) < 0)
620 return ERR;
621 GET_THIRD_ADDR(addr);
622 if (first_addr <= addr && addr < second_addr) {
623 sprintf(errmsg, "invalid destination");
623 errmsg = "invalid destination";
624 return ERR;
625 }
626 GET_COMMAND_SUFFIX();
627 if (!isglobal) clear_undo_stack();
628 if (move_lines(addr) < 0)
629 return ERR;
630 break;
631 case 'n':

--- 9 unchanged lines hidden (view full) ---

641 return ERR;
642 GET_COMMAND_SUFFIX();
643 if (display_lines(first_addr, second_addr, gflag | GPR) < 0)
644 return ERR;
645 gflag = 0;
646 break;
647 case 'P':
648 if (addr_cnt > 0) {
624 return ERR;
625 }
626 GET_COMMAND_SUFFIX();
627 if (!isglobal) clear_undo_stack();
628 if (move_lines(addr) < 0)
629 return ERR;
630 break;
631 case 'n':

--- 9 unchanged lines hidden (view full) ---

641 return ERR;
642 GET_COMMAND_SUFFIX();
643 if (display_lines(first_addr, second_addr, gflag | GPR) < 0)
644 return ERR;
645 gflag = 0;
646 break;
647 case 'P':
648 if (addr_cnt > 0) {
649 sprintf(errmsg, "unexpected address");
649 errmsg = "unexpected address";
650 return ERR;
651 }
652 GET_COMMAND_SUFFIX();
653 prompt = prompt ? NULL : optarg ? optarg : dps;
654 break;
655 case 'q':
656 case 'Q':
657 if (addr_cnt > 0) {
650 return ERR;
651 }
652 GET_COMMAND_SUFFIX();
653 prompt = prompt ? NULL : optarg ? optarg : dps;
654 break;
655 case 'q':
656 case 'Q':
657 if (addr_cnt > 0) {
658 sprintf(errmsg, "unexpected address");
658 errmsg = "unexpected address";
659 return ERR;
660 }
661 GET_COMMAND_SUFFIX();
662 gflag = (modified && !scripted && c == 'q') ? EMOD : EOF;
663 break;
664 case 'r':
665 if (!isspace((unsigned char)*ibufp)) {
659 return ERR;
660 }
661 GET_COMMAND_SUFFIX();
662 gflag = (modified && !scripted && c == 'q') ? EMOD : EOF;
663 break;
664 case 'r':
665 if (!isspace((unsigned char)*ibufp)) {
666 sprintf(errmsg, "unexpected command suffix");
666 errmsg = "unexpected command suffix";
667 return ERR;
668 } else if (addr_cnt == 0)
669 second_addr = addr_last;
670 if ((fnp = get_filename()) == NULL)
671 return ERR;
672 GET_COMMAND_SUFFIX();
673 if (!isglobal) clear_undo_stack();
674 if (*old_filename == '\0' && *fnp != '!')
675 strcpy(old_filename, fnp);
676#ifdef BACKWARDS
677 if (*fnp == '\0' && *old_filename == '\0') {
667 return ERR;
668 } else if (addr_cnt == 0)
669 second_addr = addr_last;
670 if ((fnp = get_filename()) == NULL)
671 return ERR;
672 GET_COMMAND_SUFFIX();
673 if (!isglobal) clear_undo_stack();
674 if (*old_filename == '\0' && *fnp != '!')
675 strcpy(old_filename, fnp);
676#ifdef BACKWARDS
677 if (*fnp == '\0' && *old_filename == '\0') {
678 sprintf(errmsg, "no current filename");
678 errmsg = "no current filename";
679 return ERR;
680 }
681#endif
682 if ((addr = read_file(*fnp ? fnp : old_filename, second_addr)) < 0)
683 return ERR;
684 else if (addr && addr != addr_last)
685 modified = 1;
686 break;

--- 18 unchanged lines hidden (view full) ---

705 case '0': case '1': case '2': case '3': case '4':
706 case '5': case '6': case '7': case '8': case '9':
707 STRTOL(sgnum, ibufp);
708 sflags |= SGF;
709 sgflag &= ~GSG; /* override GSG */
710 break;
711 default:
712 if (sflags) {
679 return ERR;
680 }
681#endif
682 if ((addr = read_file(*fnp ? fnp : old_filename, second_addr)) < 0)
683 return ERR;
684 else if (addr && addr != addr_last)
685 modified = 1;
686 break;

--- 18 unchanged lines hidden (view full) ---

705 case '0': case '1': case '2': case '3': case '4':
706 case '5': case '6': case '7': case '8': case '9':
707 STRTOL(sgnum, ibufp);
708 sflags |= SGF;
709 sgflag &= ~GSG; /* override GSG */
710 break;
711 default:
712 if (sflags) {
713 sprintf(errmsg, "invalid command suffix");
713 errmsg = "invalid command suffix";
714 return ERR;
715 }
716 }
717 } while (sflags && *ibufp != '\n');
718 if (sflags && !pat) {
714 return ERR;
715 }
716 }
717 } while (sflags && *ibufp != '\n');
718 if (sflags && !pat) {
719 sprintf(errmsg, "no previous substitution");
719 errmsg = "no previous substitution";
720 return ERR;
721 } else if (sflags & SGG)
722 sgnum = 0; /* override numeric arg */
723 if (*ibufp != '\n' && *(ibufp + 1) == '\n') {
720 return ERR;
721 } else if (sflags & SGG)
722 sgnum = 0; /* override numeric arg */
723 if (*ibufp != '\n' && *(ibufp + 1) == '\n') {
724 sprintf(errmsg, "invalid pattern delimiter");
724 errmsg = "invalid pattern delimiter";
725 return ERR;
726 }
727 tpat = pat;
728 SPL1();
729 if ((!sflags || (sflags & SGR)) &&
730 (tpat = get_compiled_pattern()) == NULL) {
731 SPL0();
732 return ERR;

--- 44 unchanged lines hidden (view full) ---

777 GET_THIRD_ADDR(addr);
778 GET_COMMAND_SUFFIX();
779 if (!isglobal) clear_undo_stack();
780 if (copy_lines(addr) < 0)
781 return ERR;
782 break;
783 case 'u':
784 if (addr_cnt > 0) {
725 return ERR;
726 }
727 tpat = pat;
728 SPL1();
729 if ((!sflags || (sflags & SGR)) &&
730 (tpat = get_compiled_pattern()) == NULL) {
731 SPL0();
732 return ERR;

--- 44 unchanged lines hidden (view full) ---

777 GET_THIRD_ADDR(addr);
778 GET_COMMAND_SUFFIX();
779 if (!isglobal) clear_undo_stack();
780 if (copy_lines(addr) < 0)
781 return ERR;
782 break;
783 case 'u':
784 if (addr_cnt > 0) {
785 sprintf(errmsg, "unexpected address");
785 errmsg = "unexpected address";
786 return ERR;
787 }
788 GET_COMMAND_SUFFIX();
789 if (pop_undo_stack() < 0)
790 return ERR;
791 break;
792 case 'w':
793 case 'W':
794 if ((n = *ibufp) == 'q' || n == 'Q') {
795 gflag = EOF;
796 ibufp++;
797 }
798 if (!isspace((unsigned char)*ibufp)) {
786 return ERR;
787 }
788 GET_COMMAND_SUFFIX();
789 if (pop_undo_stack() < 0)
790 return ERR;
791 break;
792 case 'w':
793 case 'W':
794 if ((n = *ibufp) == 'q' || n == 'Q') {
795 gflag = EOF;
796 ibufp++;
797 }
798 if (!isspace((unsigned char)*ibufp)) {
799 sprintf(errmsg, "unexpected command suffix");
799 errmsg = "unexpected command suffix";
800 return ERR;
801 } else if ((fnp = get_filename()) == NULL)
802 return ERR;
803 if (addr_cnt == 0 && !addr_last)
804 first_addr = second_addr = 0;
805 else if (check_addr_range(1, addr_last) < 0)
806 return ERR;
807 GET_COMMAND_SUFFIX();
808 if (*old_filename == '\0' && *fnp != '!')
809 strcpy(old_filename, fnp);
810#ifdef BACKWARDS
811 if (*fnp == '\0' && *old_filename == '\0') {
800 return ERR;
801 } else if ((fnp = get_filename()) == NULL)
802 return ERR;
803 if (addr_cnt == 0 && !addr_last)
804 first_addr = second_addr = 0;
805 else if (check_addr_range(1, addr_last) < 0)
806 return ERR;
807 GET_COMMAND_SUFFIX();
808 if (*old_filename == '\0' && *fnp != '!')
809 strcpy(old_filename, fnp);
810#ifdef BACKWARDS
811 if (*fnp == '\0' && *old_filename == '\0') {
812 sprintf(errmsg, "no current filename");
812 errmsg = "no current filename";
813 return ERR;
814 }
815#endif
816 if ((addr = write_file(*fnp ? fnp : old_filename,
817 (c == 'W') ? "a" : "w", first_addr, second_addr)) < 0)
818 return ERR;
819 else if (addr == addr_last)
820 modified = 0;
821 else if (modified && !scripted && n == 'q')
822 gflag = EMOD;
823 break;
824 case 'x':
825 if (addr_cnt > 0) {
813 return ERR;
814 }
815#endif
816 if ((addr = write_file(*fnp ? fnp : old_filename,
817 (c == 'W') ? "a" : "w", first_addr, second_addr)) < 0)
818 return ERR;
819 else if (addr == addr_last)
820 modified = 0;
821 else if (modified && !scripted && n == 'q')
822 gflag = EMOD;
823 break;
824 case 'x':
825 if (addr_cnt > 0) {
826 sprintf(errmsg, "unexpected address");
826 errmsg = "unexpected address";
827 return ERR;
828 }
829 GET_COMMAND_SUFFIX();
830#ifdef DES
831 des = get_keyword();
832#else
827 return ERR;
828 }
829 GET_COMMAND_SUFFIX();
830#ifdef DES
831 des = get_keyword();
832#else
833 sprintf(errmsg, "crypt unavailable");
833 errmsg = "crypt unavailable";
834 return ERR;
835#endif
836 break;
837 case 'z':
838#ifdef BACKWARDS
839 if (check_addr_range(first_addr = 1, current_addr + 1) < 0)
840#else
841 if (check_addr_range(first_addr = 1, current_addr + !isglobal) < 0)

--- 8 unchanged lines hidden (view full) ---

850 gflag = 0;
851 break;
852 case '=':
853 GET_COMMAND_SUFFIX();
854 printf("%ld\n", addr_cnt ? second_addr : addr_last);
855 break;
856 case '!':
857 if (addr_cnt > 0) {
834 return ERR;
835#endif
836 break;
837 case 'z':
838#ifdef BACKWARDS
839 if (check_addr_range(first_addr = 1, current_addr + 1) < 0)
840#else
841 if (check_addr_range(first_addr = 1, current_addr + !isglobal) < 0)

--- 8 unchanged lines hidden (view full) ---

850 gflag = 0;
851 break;
852 case '=':
853 GET_COMMAND_SUFFIX();
854 printf("%ld\n", addr_cnt ? second_addr : addr_last);
855 break;
856 case '!':
857 if (addr_cnt > 0) {
858 sprintf(errmsg, "unexpected address");
858 errmsg = "unexpected address";
859 return ERR;
860 } else if ((sflags = get_shell_command()) < 0)
861 return ERR;
862 GET_COMMAND_SUFFIX();
863 if (sflags) printf("%s\n", shcmd + 1);
864 system(shcmd + 1);
865 if (!scripted) printf("!\n");
866 break;
867 case '\n':
868#ifdef BACKWARDS
869 if (check_addr_range(first_addr = 1, current_addr + 1) < 0
870#else
871 if (check_addr_range(first_addr = 1, current_addr + !isglobal) < 0
872#endif
873 || display_lines(second_addr, second_addr, 0) < 0)
874 return ERR;
875 break;
876 default:
859 return ERR;
860 } else if ((sflags = get_shell_command()) < 0)
861 return ERR;
862 GET_COMMAND_SUFFIX();
863 if (sflags) printf("%s\n", shcmd + 1);
864 system(shcmd + 1);
865 if (!scripted) printf("!\n");
866 break;
867 case '\n':
868#ifdef BACKWARDS
869 if (check_addr_range(first_addr = 1, current_addr + 1) < 0
870#else
871 if (check_addr_range(first_addr = 1, current_addr + !isglobal) < 0
872#endif
873 || display_lines(second_addr, second_addr, 0) < 0)
874 return ERR;
875 break;
876 default:
877 sprintf(errmsg, "unknown command");
877 errmsg = "unknown command";
878 return ERR;
879 }
880 return gflag;
881}
882
883
884/* check_addr_range: return status of address range check */
885int
886check_addr_range(n, m)
887 long n, m;
888{
889 if (addr_cnt == 0) {
890 first_addr = n;
891 second_addr = m;
892 }
893 if (first_addr > second_addr || 1 > first_addr ||
894 second_addr > addr_last) {
878 return ERR;
879 }
880 return gflag;
881}
882
883
884/* check_addr_range: return status of address range check */
885int
886check_addr_range(n, m)
887 long n, m;
888{
889 if (addr_cnt == 0) {
890 first_addr = n;
891 second_addr = m;
892 }
893 if (first_addr > second_addr || 1 > first_addr ||
894 second_addr > addr_last) {
895 sprintf(errmsg, "invalid address");
895 errmsg = "invalid address";
896 return ERR;
897 }
898 return 0;
899}
900
901
902/* get_matching_node_addr: return the address of the next line matching a
903 pattern in a given direction. wrap around begin/end of editor buffer if

--- 14 unchanged lines hidden (view full) ---

918 if ((s = get_sbuf_line(lp)) == NULL)
919 return ERR;
920 if (isbinary)
921 NUL_TO_NEWLINE(s, lp->len);
922 if (!regexec(pat, s, 0, NULL, 0))
923 return n;
924 }
925 } while (n != current_addr);
896 return ERR;
897 }
898 return 0;
899}
900
901
902/* get_matching_node_addr: return the address of the next line matching a
903 pattern in a given direction. wrap around begin/end of editor buffer if

--- 14 unchanged lines hidden (view full) ---

918 if ((s = get_sbuf_line(lp)) == NULL)
919 return ERR;
920 if (isbinary)
921 NUL_TO_NEWLINE(s, lp->len);
922 if (!regexec(pat, s, 0, NULL, 0))
923 return n;
924 }
925 } while (n != current_addr);
926 sprintf(errmsg, "no match");
926 errmsg = "no match";
927 return ERR;
928}
929
930
931/* get_filename: return pointer to copy of filename in the command buffer */
932char *
933get_filename()
934{
935 static char *file = NULL;
936 static int filesz = 0;
937
938 int n;
939
940 if (*ibufp != '\n') {
941 SKIP_BLANKS();
942 if (*ibufp == '\n') {
927 return ERR;
928}
929
930
931/* get_filename: return pointer to copy of filename in the command buffer */
932char *
933get_filename()
934{
935 static char *file = NULL;
936 static int filesz = 0;
937
938 int n;
939
940 if (*ibufp != '\n') {
941 SKIP_BLANKS();
942 if (*ibufp == '\n') {
943 sprintf(errmsg, "invalid filename");
943 errmsg = "invalid filename";
944 return NULL;
945 } else if ((ibufp = get_extended_line(&n, 1)) == NULL)
946 return NULL;
947 else if (*ibufp == '!') {
948 ibufp++;
949 if ((n = get_shell_command()) < 0)
950 return NULL;
951 if (n)
952 printf("%s\n", shcmd + 1);
953 return shcmd;
954 } else if (n > PATH_MAX - 1) {
944 return NULL;
945 } else if ((ibufp = get_extended_line(&n, 1)) == NULL)
946 return NULL;
947 else if (*ibufp == '!') {
948 ibufp++;
949 if ((n = get_shell_command()) < 0)
950 return NULL;
951 if (n)
952 printf("%s\n", shcmd + 1);
953 return shcmd;
954 } else if (n > PATH_MAX - 1) {
955 sprintf(errmsg, "filename too long");
955 errmsg = "filename too long";
956 return NULL;
957 }
958 }
959#ifndef BACKWARDS
960 else if (*old_filename == '\0') {
956 return NULL;
957 }
958 }
959#ifndef BACKWARDS
960 else if (*old_filename == '\0') {
961 sprintf(errmsg, "no current filename");
961 errmsg = "no current filename";
962 return NULL;
963 }
964#endif
965 REALLOC(file, filesz, PATH_MAX, NULL);
966 for (n = 0; *ibufp != '\n';)
967 file[n++] = *ibufp++;
968 file[n] = '\0';
969 return is_legal_filename(file) ? file : NULL;

--- 8 unchanged lines hidden (view full) ---

978 static char *buf = NULL;
979 static int n = 0;
980
981 char *s; /* substitution char pointer */
982 int i = 0;
983 int j = 0;
984
985 if (red) {
962 return NULL;
963 }
964#endif
965 REALLOC(file, filesz, PATH_MAX, NULL);
966 for (n = 0; *ibufp != '\n';)
967 file[n++] = *ibufp++;
968 file[n] = '\0';
969 return is_legal_filename(file) ? file : NULL;

--- 8 unchanged lines hidden (view full) ---

978 static char *buf = NULL;
979 static int n = 0;
980
981 char *s; /* substitution char pointer */
982 int i = 0;
983 int j = 0;
984
985 if (red) {
986 sprintf(errmsg, "shell access restricted");
986 errmsg = "shell access restricted";
987 return ERR;
988 } else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)
989 return ERR;
990 REALLOC(buf, n, j + 1, ERR);
991 buf[i++] = '!'; /* prefix command w/ bang */
992 while (*ibufp != '\n')
993 switch (*ibufp) {
994 default:

--- 8 unchanged lines hidden (view full) ---

1003 buf[i++] = *ibufp++;
1004 }
1005#ifdef BACKWARDS
1006 else if (shcmd == NULL || *(shcmd + 1) == '\0')
1007#else
1008 else if (shcmd == NULL)
1009#endif
1010 {
987 return ERR;
988 } else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)
989 return ERR;
990 REALLOC(buf, n, j + 1, ERR);
991 buf[i++] = '!'; /* prefix command w/ bang */
992 while (*ibufp != '\n')
993 switch (*ibufp) {
994 default:

--- 8 unchanged lines hidden (view full) ---

1003 buf[i++] = *ibufp++;
1004 }
1005#ifdef BACKWARDS
1006 else if (shcmd == NULL || *(shcmd + 1) == '\0')
1007#else
1008 else if (shcmd == NULL)
1009#endif
1010 {
1011 sprintf(errmsg, "no previous command");
1011 errmsg = "no previous command";
1012 return ERR;
1013 } else {
1014 REALLOC(buf, n, i + shcmdi, ERR);
1015 for (s = shcmd + 1; s < shcmd + shcmdi;)
1016 buf[i++] = *s++;
1017 s = ibufp++;
1018 }
1019 break;
1020 case '%':
1021 if (*old_filename == '\0') {
1012 return ERR;
1013 } else {
1014 REALLOC(buf, n, i + shcmdi, ERR);
1015 for (s = shcmd + 1; s < shcmd + shcmdi;)
1016 buf[i++] = *s++;
1017 s = ibufp++;
1018 }
1019 break;
1020 case '%':
1021 if (*old_filename == '\0') {
1022 sprintf(errmsg, "no current filename");
1022 errmsg = "no current filename";
1023 return ERR;
1024 }
1025 j = strlen(s = strip_escapes(old_filename));
1026 REALLOC(buf, n, i + j, ERR);
1027 while (j--)
1028 buf[i++] = *s++;
1029 s = ibufp++;
1030 break;

--- 7 unchanged lines hidden (view full) ---

1038
1039/* append_lines: insert text from stdin to after line n; stop when either a
1040 single period is read or EOF; return status */
1041int
1042append_lines(n)
1043 long n;
1044{
1045 int l;
1023 return ERR;
1024 }
1025 j = strlen(s = strip_escapes(old_filename));
1026 REALLOC(buf, n, i + j, ERR);
1027 while (j--)
1028 buf[i++] = *s++;
1029 s = ibufp++;
1030 break;

--- 7 unchanged lines hidden (view full) ---

1038
1039/* append_lines: insert text from stdin to after line n; stop when either a
1040 single period is read or EOF; return status */
1041int
1042append_lines(n)
1043 long n;
1044{
1045 int l;
1046 char *lp = ibuf;
1047 char *eot;
1046 const char *lp = ibuf;
1047 const char *eot;
1048 undo_t *up = NULL;
1049
1050 for (current_addr = n;;) {
1051 if (!isglobal) {
1052 if ((l = get_tty_line()) < 0)
1053 return ERR;
1054 else if (l == 0 || ibuf[l - 1] != '\n') {
1055 clearerr(stdin);

--- 185 unchanged lines hidden (view full) ---

1241 long to;
1242 int gflag;
1243{
1244 line_t *bp;
1245 line_t *ep;
1246 char *s;
1247
1248 if (!from) {
1048 undo_t *up = NULL;
1049
1050 for (current_addr = n;;) {
1051 if (!isglobal) {
1052 if ((l = get_tty_line()) < 0)
1053 return ERR;
1054 else if (l == 0 || ibuf[l - 1] != '\n') {
1055 clearerr(stdin);

--- 185 unchanged lines hidden (view full) ---

1241 long to;
1242 int gflag;
1243{
1244 line_t *bp;
1245 line_t *ep;
1246 char *s;
1247
1248 if (!from) {
1249 sprintf(errmsg, "invalid address");
1249 errmsg = "invalid address";
1250 return ERR;
1251 }
1252 ep = get_addressed_line_node(INC_MOD(to, addr_last));
1253 bp = get_addressed_line_node(from);
1254 for (; bp != ep; bp = bp->q_forw) {
1255 if ((s = get_sbuf_line(bp)) == NULL)
1256 return ERR;
1257 if (put_tty_line(s, bp->len, current_addr = from++, gflag) < 0)

--- 10 unchanged lines hidden (view full) ---

1268
1269/* mark_line_node: set a line node mark */
1270int
1271mark_line_node(lp, n)
1272 line_t *lp;
1273 int n;
1274{
1275 if (!islower((unsigned char)n)) {
1250 return ERR;
1251 }
1252 ep = get_addressed_line_node(INC_MOD(to, addr_last));
1253 bp = get_addressed_line_node(from);
1254 for (; bp != ep; bp = bp->q_forw) {
1255 if ((s = get_sbuf_line(bp)) == NULL)
1256 return ERR;
1257 if (put_tty_line(s, bp->len, current_addr = from++, gflag) < 0)

--- 10 unchanged lines hidden (view full) ---

1268
1269/* mark_line_node: set a line node mark */
1270int
1271mark_line_node(lp, n)
1272 line_t *lp;
1273 int n;
1274{
1275 if (!islower((unsigned char)n)) {
1276 sprintf(errmsg, "invalid mark character");
1276 errmsg = "invalid mark character";
1277 return ERR;
1278 } else if (mark[n - 'a'] == NULL)
1279 markno++;
1280 mark[n - 'a'] = lp;
1281 return 0;
1282}
1283
1284
1285/* get_marked_node_addr: return address of a marked line */
1286long
1287get_marked_node_addr(n)
1288 int n;
1289{
1290 if (!islower((unsigned char)n)) {
1277 return ERR;
1278 } else if (mark[n - 'a'] == NULL)
1279 markno++;
1280 mark[n - 'a'] = lp;
1281 return 0;
1282}
1283
1284
1285/* get_marked_node_addr: return address of a marked line */
1286long
1287get_marked_node_addr(n)
1288 int n;
1289{
1290 if (!islower((unsigned char)n)) {
1291 sprintf(errmsg, "invalid mark character");
1291 errmsg = "invalid mark character";
1292 return ERR;
1293 }
1294 return get_line_node_addr(mark[n - 'a']);
1295}
1296
1297
1298/* unmark_line_node: clear line node mark */
1299void

--- 14 unchanged lines hidden (view full) ---

1314line_t *
1315dup_line_node(lp)
1316 line_t *lp;
1317{
1318 line_t *np;
1319
1320 if ((np = (line_t *) malloc(sizeof(line_t))) == NULL) {
1321 fprintf(stderr, "%s\n", strerror(errno));
1292 return ERR;
1293 }
1294 return get_line_node_addr(mark[n - 'a']);
1295}
1296
1297
1298/* unmark_line_node: clear line node mark */
1299void

--- 14 unchanged lines hidden (view full) ---

1314line_t *
1315dup_line_node(lp)
1316 line_t *lp;
1317{
1318 line_t *np;
1319
1320 if ((np = (line_t *) malloc(sizeof(line_t))) == NULL) {
1321 fprintf(stderr, "%s\n", strerror(errno));
1322 sprintf(errmsg, "out of memory");
1322 errmsg = "out of memory";
1323 return NULL;
1324 }
1325 np->seek = lp->seek;
1326 np->len = lp->len;
1327 return np;
1328}
1329
1330

--- 49 unchanged lines hidden (view full) ---

1380
1381
1382void
1383handle_hup(signo)
1384 int signo;
1385{
1386 char *hup = NULL; /* hup filename */
1387 char *s;
1323 return NULL;
1324 }
1325 np->seek = lp->seek;
1326 np->len = lp->len;
1327 return np;
1328}
1329
1330

--- 49 unchanged lines hidden (view full) ---

1380
1381
1382void
1383handle_hup(signo)
1384 int signo;
1385{
1386 char *hup = NULL; /* hup filename */
1387 char *s;
1388 char ed_hup[] = "ed.hup";
1388 int n;
1389
1390 if (!sigactive)
1391 quit(1);
1392 sigflags &= ~(1 << (signo - 1));
1389 int n;
1390
1391 if (!sigactive)
1392 quit(1);
1393 sigflags &= ~(1 << (signo - 1));
1393 if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 &&
1394 if (addr_last && write_file(ed_hup, "w", 1, addr_last) < 0 &&
1394 (s = getenv("HOME")) != NULL &&
1395 (n = strlen(s)) + 8 <= PATH_MAX && /* "ed.hup" + '/' */
1396 (hup = (char *) malloc(n + 10)) != NULL) {
1397 strcpy(hup, s);
1398 if (hup[n - 1] != '/')
1399 hup[n] = '/', hup[n+1] = '\0';
1400 strcat(hup, "ed.hup");
1401 write_file(hup, "w", 1, addr_last);

--- 37 unchanged lines hidden (view full) ---

1439
1440
1441/* is_legal_filename: return a legal filename */
1442int
1443is_legal_filename(s)
1444 char *s;
1445{
1446 if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) {
1395 (s = getenv("HOME")) != NULL &&
1396 (n = strlen(s)) + 8 <= PATH_MAX && /* "ed.hup" + '/' */
1397 (hup = (char *) malloc(n + 10)) != NULL) {
1398 strcpy(hup, s);
1399 if (hup[n - 1] != '/')
1400 hup[n] = '/', hup[n+1] = '\0';
1401 strcat(hup, "ed.hup");
1402 write_file(hup, "w", 1, addr_last);

--- 37 unchanged lines hidden (view full) ---

1440
1441
1442/* is_legal_filename: return a legal filename */
1443int
1444is_legal_filename(s)
1445 char *s;
1446{
1447 if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) {
1447 sprintf(errmsg, "shell access restricted");
1448 errmsg = "shell access restricted";
1448 return 0;
1449 }
1450 return 1;
1451}
1449 return 0;
1450 }
1451 return 1;
1452}