Deleted Added
full compact
main.c (8855) main.c (17516)
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

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

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 *
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

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

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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 * $Id: main.c,v 1.4 1995/03/19 13:28:34 joerg Exp $
28 * $Id: main.c,v 1.5 1995/05/30 00:06:47 rgrimes Exp $
29 */
30
31#ifndef lint
32char *copyright =
33"@(#) Copyright (c) 1993 Andrew Moore, Talke Studio. \n\
34 All rights reserved.\n";
35#endif /* not lint */
36

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

54 *
55 */
56
57#include <sys/ioctl.h>
58#include <sys/wait.h>
59#include <ctype.h>
60#include <setjmp.h>
61#include <pwd.h>
29 */
30
31#ifndef lint
32char *copyright =
33"@(#) Copyright (c) 1993 Andrew Moore, Talke Studio. \n\
34 All rights reserved.\n";
35#endif /* not lint */
36

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

54 *
55 */
56
57#include <sys/ioctl.h>
58#include <sys/wait.h>
59#include <ctype.h>
60#include <setjmp.h>
61#include <pwd.h>
62#include <locale.h>
62
63#include "ed.h"
64
65
66#ifdef _POSIX_SOURCE
67sigjmp_buf env;
68#else
69jmp_buf env;

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

107int
108main(argc, argv)
109 int argc;
110 char **argv;
111{
112 int c, n;
113 long status = 0;
114
63
64#include "ed.h"
65
66
67#ifdef _POSIX_SOURCE
68sigjmp_buf env;
69#else
70jmp_buf env;

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

108int
109main(argc, argv)
110 int argc;
111 char **argv;
112{
113 int c, n;
114 long status = 0;
115
116 (void)setlocale(LC_ALL, "");
117
115 red = (n = strlen(argv[0])) > 2 && argv[0][n - 3] == 'r';
116top:
117 while ((c = getopt(argc, argv, "p:sx")) != EOF)
118 switch(c) {
119 case 'p': /* set prompt */
120 prompt = optarg;
121 break;
122 case 's': /* run script */

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

275 current_addr = addr;
276 }
277 if ((addr_cnt = min(addr_cnt, 2)) == 1 || second_addr != addr)
278 first_addr = second_addr;
279 return (addr == ERR) ? ERR : 0;
280}
281
282
118 red = (n = strlen(argv[0])) > 2 && argv[0][n - 3] == 'r';
119top:
120 while ((c = getopt(argc, argv, "p:sx")) != EOF)
121 switch(c) {
122 case 'p': /* set prompt */
123 prompt = optarg;
124 break;
125 case 's': /* run script */

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

278 current_addr = addr;
279 }
280 if ((addr_cnt = min(addr_cnt, 2)) == 1 || second_addr != addr)
281 first_addr = second_addr;
282 return (addr == ERR) ? ERR : 0;
283}
284
285
283#define SKIP_BLANKS() while (isspace(*ibufp) && *ibufp != '\n') ibufp++
286#define SKIP_BLANKS() while (isspace((unsigned char)*ibufp) && *ibufp != '\n') ibufp++
284
285#define MUST_BE_FIRST() \
286 if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
287
288/* next_addr: return the next line address in the command buffer */
289long
290next_addr()
291{

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

300 switch (c = *ibufp) {
301 case '+':
302 case '\t':
303 case ' ':
304 case '-':
305 case '^':
306 ibufp++;
307 SKIP_BLANKS();
287
288#define MUST_BE_FIRST() \
289 if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
290
291/* next_addr: return the next line address in the command buffer */
292long
293next_addr()
294{

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

303 switch (c = *ibufp) {
304 case '+':
305 case '\t':
306 case ' ':
307 case '-':
308 case '^':
309 ibufp++;
310 SKIP_BLANKS();
308 if (isdigit(*ibufp)) {
311 if (isdigit((unsigned char)*ibufp)) {
309 STRTOL(n, ibufp);
310 addr += (c == '-' || c == '^') ? -n : n;
312 STRTOL(n, ibufp);
313 addr += (c == '-' || c == '^') ? -n : n;
311 } else if (!isspace(c))
314 } else if (!isspace((unsigned char)c))
312 addr += (c == '-' || c == '^') ? -1 : 1;
313 break;
314 case '0': case '1': case '2':
315 case '3': case '4': case '5':
316 case '6': case '7': case '8': case '9':
317 MUST_BE_FIRST();
318 STRTOL(addr, ibufp);
319 break;

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

485 case 'e':
486 if (modified && !scripted)
487 return EMOD;
488 /* fall through */
489 case 'E':
490 if (addr_cnt > 0) {
491 sprintf(errmsg, "unexpected address");
492 return ERR;
315 addr += (c == '-' || c == '^') ? -1 : 1;
316 break;
317 case '0': case '1': case '2':
318 case '3': case '4': case '5':
319 case '6': case '7': case '8': case '9':
320 MUST_BE_FIRST();
321 STRTOL(addr, ibufp);
322 break;

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

488 case 'e':
489 if (modified && !scripted)
490 return EMOD;
491 /* fall through */
492 case 'E':
493 if (addr_cnt > 0) {
494 sprintf(errmsg, "unexpected address");
495 return ERR;
493 } else if (!isspace(*ibufp)) {
496 } else if (!isspace((unsigned char)*ibufp)) {
494 sprintf(errmsg, "unexpected command suffix");
495 return ERR;
496 } else if ((fnp = get_filename()) == NULL)
497 return ERR;
498 GET_COMMAND_SUFFIX();
499 if (delete_lines(1, addr_last) < 0)
500 return ERR;
501 clear_undo_stack();

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

515 clear_undo_stack();
516 modified = 0;
517 u_current_addr = u_addr_last = -1;
518 break;
519 case 'f':
520 if (addr_cnt > 0) {
521 sprintf(errmsg, "unexpected address");
522 return ERR;
497 sprintf(errmsg, "unexpected command suffix");
498 return ERR;
499 } else if ((fnp = get_filename()) == NULL)
500 return ERR;
501 GET_COMMAND_SUFFIX();
502 if (delete_lines(1, addr_last) < 0)
503 return ERR;
504 clear_undo_stack();

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

518 clear_undo_stack();
519 modified = 0;
520 u_current_addr = u_addr_last = -1;
521 break;
522 case 'f':
523 if (addr_cnt > 0) {
524 sprintf(errmsg, "unexpected address");
525 return ERR;
523 } else if (!isspace(*ibufp)) {
526 } else if (!isspace((unsigned char)*ibufp)) {
524 sprintf(errmsg, "unexpected command suffix");
525 return ERR;
526 } else if ((fnp = get_filename()) == NULL)
527 return ERR;
528 else if (*fnp == '!') {
529 sprintf(errmsg, "invalid redirection");
530 return ERR;
531 }

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

646 if (addr_cnt > 0) {
647 sprintf(errmsg, "unexpected address");
648 return ERR;
649 }
650 GET_COMMAND_SUFFIX();
651 gflag = (modified && !scripted && c == 'q') ? EMOD : EOF;
652 break;
653 case 'r':
527 sprintf(errmsg, "unexpected command suffix");
528 return ERR;
529 } else if ((fnp = get_filename()) == NULL)
530 return ERR;
531 else if (*fnp == '!') {
532 sprintf(errmsg, "invalid redirection");
533 return ERR;
534 }

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

649 if (addr_cnt > 0) {
650 sprintf(errmsg, "unexpected address");
651 return ERR;
652 }
653 GET_COMMAND_SUFFIX();
654 gflag = (modified && !scripted && c == 'q') ? EMOD : EOF;
655 break;
656 case 'r':
654 if (!isspace(*ibufp)) {
657 if (!isspace((unsigned char)*ibufp)) {
655 sprintf(errmsg, "unexpected command suffix");
656 return ERR;
657 } else if (addr_cnt == 0)
658 second_addr = addr_last;
659 if ((fnp = get_filename()) == NULL)
660 return ERR;
661 GET_COMMAND_SUFFIX();
662 if (!isglobal) clear_undo_stack();

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

779 return ERR;
780 break;
781 case 'w':
782 case 'W':
783 if ((n = *ibufp) == 'q' || n == 'Q') {
784 gflag = EOF;
785 ibufp++;
786 }
658 sprintf(errmsg, "unexpected command suffix");
659 return ERR;
660 } else if (addr_cnt == 0)
661 second_addr = addr_last;
662 if ((fnp = get_filename()) == NULL)
663 return ERR;
664 GET_COMMAND_SUFFIX();
665 if (!isglobal) clear_undo_stack();

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

782 return ERR;
783 break;
784 case 'w':
785 case 'W':
786 if ((n = *ibufp) == 'q' || n == 'Q') {
787 gflag = EOF;
788 ibufp++;
789 }
787 if (!isspace(*ibufp)) {
790 if (!isspace((unsigned char)*ibufp)) {
788 sprintf(errmsg, "unexpected command suffix");
789 return ERR;
790 } else if ((fnp = get_filename()) == NULL)
791 return ERR;
792 if (addr_cnt == 0 && !addr_last)
793 first_addr = second_addr = 0;
794 else if (check_addr_range(1, addr_last) < 0)
795 return ERR;

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

1255int markno; /* line marker count */
1256
1257/* mark_line_node: set a line node mark */
1258int
1259mark_line_node(lp, n)
1260 line_t *lp;
1261 int n;
1262{
791 sprintf(errmsg, "unexpected command suffix");
792 return ERR;
793 } else if ((fnp = get_filename()) == NULL)
794 return ERR;
795 if (addr_cnt == 0 && !addr_last)
796 first_addr = second_addr = 0;
797 else if (check_addr_range(1, addr_last) < 0)
798 return ERR;

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

1258int markno; /* line marker count */
1259
1260/* mark_line_node: set a line node mark */
1261int
1262mark_line_node(lp, n)
1263 line_t *lp;
1264 int n;
1265{
1263 if (!islower(n)) {
1266 if (!islower((unsigned char)n)) {
1264 sprintf(errmsg, "invalid mark character");
1265 return ERR;
1266 } else if (mark[n - 'a'] == NULL)
1267 markno++;
1268 mark[n - 'a'] = lp;
1269 return 0;
1270}
1271
1272
1273/* get_marked_node_addr: return address of a marked line */
1274long
1275get_marked_node_addr(n)
1276 int n;
1277{
1267 sprintf(errmsg, "invalid mark character");
1268 return ERR;
1269 } else if (mark[n - 'a'] == NULL)
1270 markno++;
1271 mark[n - 'a'] = lp;
1272 return 0;
1273}
1274
1275
1276/* get_marked_node_addr: return address of a marked line */
1277long
1278get_marked_node_addr(n)
1279 int n;
1280{
1278 if (!islower(n)) {
1281 if (!islower((unsigned char)n)) {
1279 sprintf(errmsg, "invalid mark character");
1280 return ERR;
1281 }
1282 return get_line_node_addr(mark[n - 'a']);
1283}
1284
1285
1286/* unmark_line_node: clear line node mark */

--- 148 unchanged lines hidden ---
1282 sprintf(errmsg, "invalid mark character");
1283 return ERR;
1284 }
1285 return get_line_node_addr(mark[n - 'a']);
1286}
1287
1288
1289/* unmark_line_node: clear line node mark */

--- 148 unchanged lines hidden ---