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

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

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 =
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

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

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 69247 2000-11-27 06:26:48Z kris $";
40 "$FreeBSD: head/bin/ed/main.c 77407 2001-05-29 18:03:14Z imp $";
41#endif
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

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

91int isglobal; /* if set, doing a global command */
92int modified; /* if set, buffer modified since last write */
93int mutex = 0; /* if set, signals set "sigflags" */
94int red = 0; /* if set, restrict shell/directory access */
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
41#endif
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

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

91int isglobal; /* if set, doing a global command */
92int modified; /* if set, buffer modified since last write */
93int mutex = 0; /* if set, signals set "sigflags" */
94int red = 0; /* if set, restrict shell/directory access */
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[MAXPATHLEN + 1] = ""; /* default filename */
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 */
103char *prompt; /* command-line prompt */
104char *dps = "*"; /* default command-line prompt */
105
106const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n";
107

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

943 sprintf(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;
100long current_addr; /* current address in editor buffer */
101long addr_last; /* last address in editor buffer */
102int lineno; /* script line number */
103char *prompt; /* command-line prompt */
104char *dps = "*"; /* default command-line prompt */
105
106const char usage[] = "usage: %s [-] [-sx] [-p string] [name]\n";
107

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

943 sprintf(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) printf("%s\n", shcmd + 1);
951 if (n)
952 printf("%s\n", shcmd + 1);
952 return shcmd;
953 return shcmd;
953 } else if (n - 1 > MAXPATHLEN) {
954 } else if (n > PATH_MAX - 1) {
954 sprintf(errmsg, "filename too long");
955 return NULL;
956 }
957 }
958#ifndef BACKWARDS
959 else if (*old_filename == '\0') {
960 sprintf(errmsg, "no current filename");
961 return NULL;
962 }
963#endif
955 sprintf(errmsg, "filename too long");
956 return NULL;
957 }
958 }
959#ifndef BACKWARDS
960 else if (*old_filename == '\0') {
961 sprintf(errmsg, "no current filename");
962 return NULL;
963 }
964#endif
964 REALLOC(file, filesz, MAXPATHLEN + 1, NULL);
965 REALLOC(file, filesz, PATH_MAX, NULL);
965 for (n = 0; *ibufp != '\n';)
966 file[n++] = *ibufp++;
967 file[n] = '\0';
968 return is_legal_filename(file) ? file : NULL;
969}
970
971
972/* get_shell_command: read a shell command from stdin; return substitution

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

1333has_trailing_escape(s, t)
1334 char *s;
1335 char *t;
1336{
1337 return (s == t || *(t - 1) != '\\') ? 0 : !has_trailing_escape(s, t - 1);
1338}
1339
1340
966 for (n = 0; *ibufp != '\n';)
967 file[n++] = *ibufp++;
968 file[n] = '\0';
969 return is_legal_filename(file) ? file : NULL;
970}
971
972
973/* get_shell_command: read a shell command from stdin; return substitution

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

1334has_trailing_escape(s, t)
1335 char *s;
1336 char *t;
1337{
1338 return (s == t || *(t - 1) != '\\') ? 0 : !has_trailing_escape(s, t - 1);
1339}
1340
1341
1341/* strip_escapes: return copy of escaped string of at most length MAXPATHLEN */
1342/* strip_escapes: return copy of escaped string of at most length PATH_MAX */
1342char *
1343strip_escapes(s)
1344 char *s;
1345{
1346 static char *file = NULL;
1347 static int filesz = 0;
1348
1349 int i = 0;
1350
1343char *
1344strip_escapes(s)
1345 char *s;
1346{
1347 static char *file = NULL;
1348 static int filesz = 0;
1349
1350 int i = 0;
1351
1351 REALLOC(file, filesz, MAXPATHLEN + 1, NULL);
1352 REALLOC(file, filesz, PATH_MAX, NULL);
1352 while (i < filesz - 1 /* Worry about a possible trailing escape */
1353 && (file[i++] = (*s == '\\') ? *++s : *s))
1354 s++;
1355 return file;
1356}
1357
1358
1359void

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

1386 char *s;
1387 int n;
1388
1389 if (!sigactive)
1390 quit(1);
1391 sigflags &= ~(1 << (signo - 1));
1392 if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 &&
1393 (s = getenv("HOME")) != NULL &&
1353 while (i < filesz - 1 /* Worry about a possible trailing escape */
1354 && (file[i++] = (*s == '\\') ? *++s : *s))
1355 s++;
1356 return file;
1357}
1358
1359
1360void

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

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

--- 48 unchanged lines hidden ---
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);
1402 }
1403 quit(2);

--- 48 unchanged lines hidden ---