reformat to KNF, prototype the world, fix lint bugs
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 24 Jan 1993 07:48:00 +0000 (23:48 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Sun, 24 Jan 1993 07:48:00 +0000 (23:48 -0800)
SCCS-vsn: contrib/ed/a.c 5.2
SCCS-vsn: contrib/ed/add_line.c 5.2
SCCS-vsn: contrib/ed/address.c 5.2
SCCS-vsn: contrib/ed/bang.c 5.2
SCCS-vsn: contrib/ed/c.c 5.2
SCCS-vsn: contrib/ed/d.c 5.2
SCCS-vsn: contrib/ed/e.c 5.2
SCCS-vsn: contrib/ed/ed.h 5.2
SCCS-vsn: contrib/ed/edhup.c 5.2
SCCS-vsn: contrib/ed/equal.c 5.2
SCCS-vsn: contrib/ed/f.c 5.2
SCCS-vsn: contrib/ed/filename.c 5.2
SCCS-vsn: contrib/ed/g.c 5.2
SCCS-vsn: contrib/ed/get_line.c 5.2
SCCS-vsn: contrib/ed/get_pattern.c 5.2
SCCS-vsn: contrib/ed/i.c 5.2
SCCS-vsn: contrib/ed/input_lines.c 5.2
SCCS-vsn: contrib/ed/j.c 5.2
SCCS-vsn: contrib/ed/k.c 5.2
SCCS-vsn: contrib/ed/l.c 5.2
SCCS-vsn: contrib/ed/line_number.c 5.2
SCCS-vsn: contrib/ed/m.c 5.2
SCCS-vsn: contrib/ed/main.c 5.2
SCCS-vsn: contrib/ed/p.c 5.2
SCCS-vsn: contrib/ed/q.c 5.2
SCCS-vsn: contrib/ed/r.c 5.2
SCCS-vsn: contrib/ed/re.c 5.2
SCCS-vsn: contrib/ed/rol.c 5.2
SCCS-vsn: contrib/ed/search.c 5.2
SCCS-vsn: contrib/ed/sub.c 5.2
SCCS-vsn: contrib/ed/t.c 5.2
SCCS-vsn: contrib/ed/u.c 5.2
SCCS-vsn: contrib/ed/w.c 5.2
SCCS-vsn: contrib/ed/z.c 5.2

34 files changed:
usr/src/contrib/ed/a.c
usr/src/contrib/ed/add_line.c
usr/src/contrib/ed/address.c
usr/src/contrib/ed/bang.c
usr/src/contrib/ed/c.c
usr/src/contrib/ed/d.c
usr/src/contrib/ed/e.c
usr/src/contrib/ed/ed.h
usr/src/contrib/ed/edhup.c
usr/src/contrib/ed/equal.c
usr/src/contrib/ed/f.c
usr/src/contrib/ed/filename.c
usr/src/contrib/ed/g.c
usr/src/contrib/ed/get_line.c
usr/src/contrib/ed/get_pattern.c
usr/src/contrib/ed/i.c
usr/src/contrib/ed/input_lines.c
usr/src/contrib/ed/j.c
usr/src/contrib/ed/k.c
usr/src/contrib/ed/l.c
usr/src/contrib/ed/line_number.c
usr/src/contrib/ed/m.c
usr/src/contrib/ed/main.c
usr/src/contrib/ed/p.c
usr/src/contrib/ed/q.c
usr/src/contrib/ed/r.c
usr/src/contrib/ed/re.c
usr/src/contrib/ed/rol.c
usr/src/contrib/ed/search.c
usr/src/contrib/ed/sub.c
usr/src/contrib/ed/t.c
usr/src/contrib/ed/u.c
usr/src/contrib/ed/w.c
usr/src/contrib/ed/z.c

index d02e95d..d1f3e3a 100644 (file)
@@ -9,31 +9,36 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)a.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)a.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This sets things up for the central input routine to place the text
  * at the proper location for an append.
  */
 
 /*
  * This sets things up for the central input routine to place the text
  * at the proper location for an append.
  */
-
 void
 a(inputt, errnum)
 void
 a(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  if (rol(inputt, errnum))
-    return;
+       if (rol(inputt, errnum))
+               return;
 
 
-  if (g_flag == 0)
-    u_clr_stk();
-  if (sigint_flag)
-    SIGINT_ACTION;
-  add_flag = 1;
-  input_lines(inputt, errnum);
-  add_flag = 0;
-} /* end-a */
+       if (g_flag == 0)
+               u_clr_stk();
+       if (sigint_flag)
+               SIGINT_ACTION;
+       add_flag = 1;
+       input_lines(inputt, errnum);
+       add_flag = 0;
+}
index 11f0557..2bfa742 100644 (file)
@@ -9,71 +9,35 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)add_line.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)add_line.c 5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
 
 /*
- * This is where the lines actually are put into the buffer. Notice
- * all the #ifdef's for the various methods of buffering - POSIX said
- * no "no attempt is made to imply a specific implementation". So,
- * you get your choice: standard I/O, core memory, or a database.
+ * This is where the lines actually are put into the buffer.
  */
  */
-
-#ifdef STDIO
-long
-add_line(p, len)
-#endif
-#ifdef DBI
 recno_t
 add_line(p, len)
 recno_t
 add_line(p, len)
-#endif
-#ifdef MEMORY
-char
-*add_line(p, len)
-#endif
-
-char *p;
-long len;
-
+       char *p;
+       long len;
 {
 {
-#ifdef STDIO
-  long l_key;
-  extern int file_loc;
-
-  if (file_seek)  /* x-ref to get_line for what this does */
-    {
-      file_seek = 0;
-      fseek(fhtmp, 0L, 2); /* set to end-to-file */
-    }
-  l_key = ftell(fhtmp);
-  file_loc = l_key + fwrite(p, sizeof(char), len, fhtmp); /* keeps user time down 20%approx */
-  return(l_key);
-#endif
-
-#ifdef DBI
-  DBT db_key, db_data;
-  static recno_t l_key=0;
-
-  l_key++;
-  (db_key.data) = &l_key;
-  (db_key.size) = sizeof(recno_t);
-  (db_data.data) = p;
-  (db_data.size) = len;
-  (dbhtmp->put)(dbhtmp, &db_key, &db_data, (u_int)(R_NOOVERWRITE));
-  return(l_key);
-#endif
-
-#ifdef MEMORY
-  char *tmp;
-  tmp = (char *)calloc(len+1, sizeof(char));
-  if (tmp)
-    {
-      bcopy(p, tmp, len);
-      tmp[len] = '\0';
-    }
-  return(tmp);
-#endif
-
-} /* end-add_line */
+       DBT db_key, db_data;
+       static recno_t l_key;
+
+       l_key++;
+       (db_key.data) = &l_key;
+       (db_key.size) = sizeof(recno_t);
+       (db_data.data) = p;
+       (db_data.size) = len;
+       (dbhtmp->put)(dbhtmp, &db_key, &db_data, (u_int)(R_NOOVERWRITE));
+       return(l_key);
+}
index c451593..fbc859a 100644 (file)
@@ -9,10 +9,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)address.c  5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)address.c  5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Make sure that address one comes before address two in the buffer
 
 /*
  * Make sure that address one comes before address two in the buffer
@@ -20,241 +29,204 @@ static char sccsid[] = "@(#)address.c     5.1 (Berkeley) %G%";
 
 int
 address_check(one, two)
 
 int
 address_check(one, two)
-
-LINE *one, *two;
-
+       LINE *one, *two;
 {
 {
-  LINE *l_cl;
+       LINE   *l_cl;
 
 
-  l_cl = one;
-
-  while (l_cl != NULL)
-       {
-         if (l_cl == two)
-           return(0);
-         l_cl = l_cl->below;
-       } /* end-while */
-  return(-1);
-}/* end-address_check */
+       for (l_cl = one; l_cl != NULL; l_cl = l_cl->below)
+               if (l_cl == two)
+                       return (0);
+       return (-1);
+}
 
 /*
  * convert a number given by the user into variable
  */
 
 /*
  * convert a number given by the user into variable
  */
-
 int
 dig_num_conv(inputt, errnum)
 int
 dig_num_conv(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
- int l_line=0;
-
- l_line = ss - '0';
- while ((ss=getc(inputt)) != EOF)
-    {
-      if ((ss < '0') || (ss > '9'))
-        break;
-      l_line = (l_line * 10) + (ss - '0');
-    }
-  *errnum = 0;
-  ungetc(ss, inputt);
-  return(l_line);
+       int l_line = 0;
+
+       l_line = ss - '0';
+       while ((ss = getc(inputt)) != EOF) {
+               if ((ss < '0') || (ss > '9'))
+                       break;
+               l_line = (l_line * 10) + (ss - '0');
+       }
+       *errnum = 0;
+       ungetc(ss, inputt);
+       return (l_line);
 }
 
 /*
  * Convert a numeric address into a LINE address (more useful for ed)
  */
 }
 
 /*
  * Convert a numeric address into a LINE address (more useful for ed)
  */
-
-LINE
-*num_to_address(num, errnum)
-
-int num, *errnum;
-
+LINE *
+num_to_address(num, errnum)
+       int num, *errnum;
 {
 {
-  int l_line=1;
-  LINE *temp1;
-
-  temp1 = top;
-
-  while (temp1->below != NULL)
-    {
-      /* find the matching line number in the buffer */
-      if (l_line >= num)
-        break;
-      l_line++;
-      temp1 = temp1->below;
-    }
-
-  if (l_line < num)
-    {
-      /* the number was wacko */
-      *errnum = -1;
-      strcpy(help_msg, "bad line number");
-      return(NULL);
-    }
-  else if (num == 0) /* special case */
-    return(NULL);
-  else
-    return(temp1);
-
-} /* end-num_to_adddress */
+       int l_line = 1;
+       LINE *temp1;
+
+       for (temp1 = top; temp1->below != NULL; temp1 = temp1->below) {
+               /* find the matching line number in the buffer */
+               if (l_line >= num)
+                       break;
+               l_line++;
+       }
+
+       if (l_line < num) {
+               /* the number was wacko */
+               *errnum = -1;
+               strcpy(help_msg, "bad line number");
+               return (NULL);
+       } else
+               if (num == 0)   /* special case */
+                       return (NULL);
+               else
+                       return (temp1);
+}
 
 
 /*
 
 
 /*
- * Figure out what the addresses are spec'd by the user.
- * Note for backward compatability the most recent addresses in
- * a chain are used by the commands (i.e. 3,5,17,22d deletes lines 17 to
- * 22 inclusive. The two leading addresses 3 and 5 are dropped as cmd_loop
- * rolls through here the extra times). Hence, the code may look
- * a little wierder than it should.
- * The variable l_order is used to control for legally constructed addresses
- * as described in ed(1). So, "$-21" and "/RE/++++" are leagal but /RE/-$ is
- * not.
+ * Figure out what the addresses are spec'd by the user.  Note for backward
+ * compatability the most recent addresses in a chain are used by the commands
+ * (i.e. 3,5,17,22d deletes lines 17 to 22 inclusive. The two leading addresses
+ * 3 and 5 are dropped as cmd_loop rolls through here the extra times).  Hence,
+ * the code may look a little wierder than it should.  The variable l_order is
+ * used to control for legally constructed addresses as described in ed(1).  So,
+ * "$-21" and "/RE/++++" are leagal but /RE/-$ is not.
  */
  */
-
-LINE
-*address_conv(tempp, inputt, errnum)
-
-LINE *tempp;
-FILE *inputt;
-int *errnum;
-
+LINE *
+address_conv(tempp, inputt, errnum)
+       LINE *tempp;
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_last, l_cnt, l_num, l_order=0;
-  LINE *l_dot;
-  int l_pass_flag=0;
-
-  l_dot = NULL;
-  address_flag = 0;
-
-  l_last = ss;
-  if (tempp == NULL)
-    l_dot = current;
-  else
-    l_dot = tempp;
-
-  while ((ss=getc(inputt)) != EOF)
-  {
-  switch (ss)
-     {
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-      case '8':
-      case '9':
-                if (l_order == (l_order | 4))
-                  {
-                    *errnum = -1;
-                    strcpy(help_msg, "malformed address");
-                    return(NULL);
-                  }
-                l_order |= 1;
-                l_num = dig_num_conv(inputt, errnum);
-                /* " " (<space>), historically, gets counted as a "+"
-                 * if it's between two 'addable' address forms. Goofy,
-                 * but it makes it compatible for those strange old
-                 * scripts (or users?)
-                 */
-                if ((l_last == '+') || ((l_last == ' ') && l_pass_flag))
-                  {
-                    if (l_last == ' ')
-                      l_num++;
-                    for (l_cnt=0; l_cnt<l_num-1 ;l_cnt++)
-                       {
-                         if (l_dot == NULL)
-                           {
-                             *errnum = -1;
-                             return(NULL);
-                           }
-                         l_dot = l_dot->below;
-                       }
-                  }
-                else if ((l_last == '-') || (l_last == '^'))
-                  {
-                    for (l_cnt=l_num-1; l_cnt>0; l_cnt--)
-                       {
-                         if (l_dot == NULL)
-                           {
-                             *errnum = -1;
-                             return(NULL);
-                           }
-                         l_dot = l_dot->above;
-                       }
-                  }
-                else
-                  l_dot = num_to_address(l_num, errnum);
-                if (*errnum < 0)
-                  return(NULL);
-                l_pass_flag = 1;
-                break;
-      case '\'':
-      case '$':
-      case '?':
-      case '/':
-      case '.': if (l_order != 0)
-                  {
-                    *errnum = -1;
-                    strcpy(help_msg, "malformed address");
-                    return(NULL);
-                  }
-                l_order = 4;
-                switch (ss)
-                {
-                  case '\'': l_dot = get_mark(errnum);
-                             break;
-                  case '$': l_dot = bottom; /* set to bottom */
-                            break;
-                  case '?': l_dot = search_r(inputt, errnum);
-                            break;
-                  case '/': l_dot = search(inputt, errnum);
-                            break;
-                  case '.': l_dot = current;
-                            break;
-                }
-                break;
-      case '-':
-      case '^':
-      case '+': l_order = 2;
-                if (ss == '+')
-                  {
-                    l_dot = l_dot->below;
-                    if (l_dot == NULL)
-                      {
-                        strcpy(help_msg, "at end of buffer");
-                        *errnum = -1;
-                        return(NULL);
-                      }
-                  }
-                else
-                  {
-                    l_dot = l_dot->above;
-                    if (l_dot == NULL)
-                      {
-                        strcpy(help_msg, "at top of buffer");
-                        *errnum = -1;
-                        return(NULL);
-                      }
-                  }
-                break;
-      case ' ': break; /* ignore here, but see comment above */
-      default: ungetc(ss, inputt);
-               return(l_dot);
-               break;
-     } /* End-switch */
-
-     if (*errnum < 0)
-       break; /* from the while-loop */
-     l_last = ss;
-   } /* end-while */
-
-  if (ss == EOF)
-    return(l_dot);
-  *errnum = -1;
-  return(NULL);
-} /* End-address_conv */
+       LINE *l_dot;
+       int l_last, l_cnt, l_num, l_order, l_pass_flag;
+
+       l_dot = NULL;
+       l_order = 0;
+       l_pass_flag = 0;
+       address_flag = 0;
+
+       l_last = ss;
+       if (tempp == NULL)
+               l_dot = current;
+       else
+               l_dot = tempp;
+
+       while ((ss = getc(inputt)) != EOF) {
+               switch (ss) {
+               case '0': case '1': case '2': case '3': case '4':
+               case '5': case '6': case '7': case '8': case '9':
+                       if (l_order == (l_order | 4)) {
+                               *errnum = -1;
+                               strcpy(help_msg, "malformed address");
+                               return (NULL);
+                       }
+                       l_order |= 1;
+                       l_num = dig_num_conv(inputt, errnum);
+                       /*
+                        * " " (<space>), historically, gets counted as a "+"
+                        * if it's between two 'addable' address forms. Goofy,
+                        * but it makes it compatible for those strange old
+                        * scripts (or users?)
+                        */
+                       if ((l_last == '+') ||
+                           ((l_last == ' ') && l_pass_flag)) {
+                               if (l_last == ' ')
+                                       l_num++;
+                               for (l_cnt = 0; l_cnt < l_num - 1; l_cnt++) {
+                                       if (l_dot == NULL) {
+                                               *errnum = -1;
+                                               return (NULL);
+                                       }
+                                       l_dot = l_dot->below;
+                               }
+                       } else
+                               if ((l_last == '-') || (l_last == '^')) {
+                                       for (l_cnt = l_num - 1;
+                                           l_cnt > 0; l_cnt--) {
+                                               if (l_dot == NULL) {
+                                                       *errnum = -1;
+                                                       return (NULL);
+                                               }
+                                               l_dot = l_dot->above;
+                                       }
+                               } else
+                                       l_dot = num_to_address(l_num, errnum);
+                       if (*errnum < 0)
+                               return (NULL);
+                       l_pass_flag = 1;
+                       break;
+               case '\'':
+               case '$':
+               case '?':
+               case '/':
+               case '.':
+                       if (l_order != 0) {
+                               *errnum = -1;
+                               strcpy(help_msg, "malformed address");
+                               return (NULL);
+                       }
+                       l_order = 4;
+                       switch (ss) {
+                       case '\'':
+                               l_dot = get_mark(errnum);
+                               break;
+                       case '$':
+                               l_dot = bottom; /* set to bottom */
+                               break;
+                       case '?':
+                               l_dot = search_r(inputt, errnum);
+                               break;
+                       case '/':
+                               l_dot = search(inputt, errnum);
+                               break;
+                       case '.':
+                               l_dot = current;
+                               break;
+                       }
+                       break;
+               case '-':
+               case '^':
+               case '+':
+                       l_order = 2;
+                       if (ss == '+') {
+                               l_dot = l_dot->below;
+                               if (l_dot == NULL) {
+                                       strcpy(help_msg, "at end of buffer");
+                                       *errnum = -1;
+                                       return (NULL);
+                               }
+                       } else {
+                               l_dot = l_dot->above;
+                               if (l_dot == NULL) {
+                                       strcpy(help_msg, "at top of buffer");
+                                       *errnum = -1;
+                                       return (NULL);
+                               }
+                       }
+                       break;
+               case ' ':
+                       break;  /* ignore here, but see comment above */
+               default:
+                       ungetc(ss, inputt);
+                       return (l_dot);
+                       break;
+               }
+
+               if (*errnum < 0)
+                       break;  /* from the while-loop */
+               l_last = ss;
+       }
+
+       if (ss == EOF)
+               return (l_dot);
+       *errnum = -1;
+       return (NULL);
+}
index 683bccb..05439e5 100644 (file)
@@ -9,10 +9,20 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)bang.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)bang.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Execute a command in sh (and always sh). For those wondering the
 
 /*
  * Execute a command in sh (and always sh). For those wondering the
@@ -21,61 +31,53 @@ static char sccsid[] = "@(#)bang.c  5.1 (Berkeley) %G%";
 
 void
 bang(inputt, errnum)
 
 void
 bang(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  static char l_shellcmd[FILENAME_LEN]; /* static for "!!" */
-  int l_cnt=0, l_esc=0;
-  static int l_cnt_last_pos; /* for "!!", offset in _static_ l_shellcmd */
+       static int l_cnt_last_pos;              /* "!!", l_shellcmd offset */
+       static char l_shellcmd[FILENAME_LEN];   /* "!!" */
+       int l_cnt = 0, l_esc = 0;
 
 
-  while (1)
-       {
-         if (sigint_flag)
-           SIGINT_ACTION;
-         ss = getchar();
-         if ((ss == '\\') && (l_esc == 0))
-           {
-             ss = getchar();
-             l_esc = 1;
-           }
-         else
-           l_esc = 0;
-         if ((ss == '\n') || (ss == EOF))
-           {
-             if (l_cnt==0)
-               {
-                 strcpy(help_msg, "no shell command given");
-                 *errnum = -1;
-                 ungetc('\n', inputt);
-                 return;
-               }
-             l_shellcmd[l_cnt] = '\0';
-             break;
-           }
-         else if ((ss == '!') && (l_esc == 0))
-           l_cnt = l_cnt_last_pos;
-         else if ((ss == '%') && (l_esc == 0))
-           {
-             l_shellcmd[l_cnt] = '\0';
-             strcat(l_shellcmd, filename_current);
-             l_cnt = l_cnt + strlen(filename_current);
-           }
-         else
-           l_shellcmd[l_cnt++] = ss;
-         if (l_cnt >= FILENAME_LEN)
-           {
-             strcpy(help_msg, "shell command too long");
-             *errnum = -1;
-             ungetc('\n', inputt);
-             return;
-           }
-       } /* end-while(1) */
+       for (;;) {
+               if (sigint_flag)
+                       SIGINT_ACTION;
+               ss = getchar();
+               if ((ss == '\\') && (l_esc == 0)) {
+                       ss = getchar();
+                       l_esc = 1;
+               } else
+                       l_esc = 0;
+               if ((ss == '\n') || (ss == EOF)) {
+                       if (l_cnt == 0) {
+                               strcpy(help_msg, "no shell command given");
+                               *errnum = -1;
+                               ungetc('\n', inputt);
+                               return;
+                       }
+                       l_shellcmd[l_cnt] = '\0';
+                       break;
+               } else
+                       if ((ss == '!') && (l_esc == 0))
+                               l_cnt = l_cnt_last_pos;
+                       else
+                               if ((ss == '%') && (l_esc == 0)) {
+                                       l_shellcmd[l_cnt] = '\0';
+                                       strcat(l_shellcmd, filename_current);
+                                       l_cnt =
+                                           l_cnt + strlen(filename_current);
+                               } else
+                                       l_shellcmd[l_cnt++] = ss;
+               if (l_cnt >= FILENAME_LEN) {
+                       strcpy(help_msg, "shell command too long");
+                       *errnum = -1;
+                       ungetc('\n', inputt);
+                       return;
+               }
+       }
 
 
-  system(l_shellcmd);
-  if (explain_flag != 0)  /* for the -s option */
-    printf("!\n");
-  l_cnt_last_pos = l_cnt;
-  *errnum = 0;
-} /* end-bang */
+       system(l_shellcmd);
+       if (explain_flag != 0)  /* for the -s option */
+               printf("!\n");
+       l_cnt_last_pos = l_cnt;
+       *errnum = 0;
+}
index 97cfcfc..74e1eb6 100644 (file)
@@ -9,10 +9,18 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)c.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)c.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This deletes the range of lines specified and then sets up things
 
 /*
  * This deletes the range of lines specified and then sets up things
@@ -21,36 +29,33 @@ static char sccsid[] = "@(#)c.c     5.1 (Berkeley) %G%";
 
 void
 c(inputt, errnum)
 
 void
 c(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-
-  if (start_default && End_default)
-    start = End = current;
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
-
-  /* first delete the lines */
-  d(inputt, errnum);
-  if (*errnum < 0)
-      return;
-  *errnum = 0;
-
-  if ((current != NULL) && (current != bottom))
-    current = current->above;
-  if (sigint_flag)
-    SIGINT_ACTION;
-  add_flag = 1;
-  start_default = End_default = 1;
-  /* now get the "change" lines */
-  input_lines(inputt, errnum);
-  add_flag = 0;
-} /* end-c */
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
+
+       /* first delete the lines */
+       d(inputt, errnum);
+       if (*errnum < 0)
+               return;
+       *errnum = 0;
+
+       if ((current != NULL) && (current != bottom))
+               current = current->above;
+       if (sigint_flag)
+               SIGINT_ACTION;
+       add_flag = 1;
+       start_default = End_default = 1;
+       /* now get the "change" lines */
+       input_lines(inputt, errnum);
+       add_flag = 0;
+}
index 47fd162..8ab0a61 100644 (file)
@@ -9,10 +9,22 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)d.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)d.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
+
+static void d_add __P((LINE *, LINE *));
 
 /*
  * This removes lines in the buffer from user access. The specified
 
 /*
  * This removes lines in the buffer from user access. The specified
@@ -21,164 +33,135 @@ static char sccsid[] = "@(#)d.c   5.1 (Berkeley) %G%";
  * in a stack for deletion later when no undo can be performed on these lines.
  * The lines in the buffer are freed then as well.
  */
  * in a stack for deletion later when no undo can be performed on these lines.
  * The lines in the buffer are freed then as well.
  */
-
 void
 d(inputt, errnum)
 void
 d(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  LINE *l_temp1, *l_temp2;
-
-  if (start_default && End_default)
-    start = End = current;
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
-
-  if (rol(inputt, errnum))
-    return;
-
-  if ((u_set == 0) && (g_flag == 0))
-    u_clr_stk();  /* for undo */
-
-  if ((start == NULL) && (End == NULL)) /* nothing to do... */
-    {
-      *errnum = 1;
-      return;
-    }
-
-  if (sigint_flag)
-    SIGINT_ACTION;
-
-  d_add(start, End); /* for buffer clearing later(!) */
-
-  /* now change preserve the pointers in case of undo and then adjust
-   * them.
-   */
-  if (start == top)
-    {
-      top = End->below;
-      if (top != NULL)
-        {
-          u_add_stk(&(top->above));
-          (top->above) = NULL;
-        }
-    }
-  else
-    {
-      l_temp1 = start->above;
-      u_add_stk(&(l_temp1->below));
-      (l_temp1->below) = End->below;
-    }
-
-  if (End == bottom)
-    {
-      bottom = start->above;
-      current = bottom;
-    }
-  else
-    {
-      l_temp2 = End->below;
-      u_add_stk(&(l_temp2->above));
-      (l_temp2->above) = start->above;
-      current = l_temp2;
-    }
-
-  /* to keep track of the marks */
-  ku_chk(start, End, NULL);
-  change_flag = 1L;
-
-  if (sigint_flag) /* next stable spot */
-    SIGINT_ACTION;
-
-  if (start == End)
-    {
-      *errnum = 1;
-      return;
-    }
-
-  *errnum = 1;
-} /* end-d */
+       LINE *l_temp1, *l_temp2;
+
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
+
+       if (rol(inputt, errnum))
+               return;
+
+       if ((u_set == 0) && (g_flag == 0))
+               u_clr_stk();    /* for undo */
+
+       if ((start == NULL) && (End == NULL)) { /* nothing to do... */
+               *errnum = 1;
+               return;
+       }
+       if (sigint_flag)
+               SIGINT_ACTION;
+
+       d_add(start, End);      /* for buffer clearing later(!) */
+
+       /*
+        * Now change preserve the pointers in case of undo and then adjust
+        * them.
+        */
+       if (start == top) {
+               top = End->below;
+               if (top != NULL) {
+                       u_add_stk(&(top->above));
+                       (top->above) = NULL;
+               }
+       } else {
+               l_temp1 = start->above;
+               u_add_stk(&(l_temp1->below));
+               (l_temp1->below) = End->below;
+       }
+
+       if (End == bottom) {
+               bottom = start->above;
+               current = bottom;
+       } else {
+               l_temp2 = End->below;
+               u_add_stk(&(l_temp2->above));
+               (l_temp2->above) = start->above;
+               current = l_temp2;
+       }
+
+       /* To keep track of the marks. */
+       ku_chk(start, End, NULL);
+       change_flag = 1L;
+
+       if (sigint_flag)        /* next stable spot */
+               SIGINT_ACTION;
+
+       if (start == End) {
+               *errnum = 1;
+               return;
+       }
+       *errnum = 1;
+}
 
 
 /*
  * This keeps a stack of the start and end lines deleted for clean-up
  * later (in d_do()). A stack is used because of the global commands.
  */
 
 
 /*
  * This keeps a stack of the start and end lines deleted for clean-up
  * later (in d_do()). A stack is used because of the global commands.
  */
-
-void
+static void
 d_add(top_d, bottom_d)
 d_add(top_d, bottom_d)
-
-LINE *top_d, *bottom_d;
-
+       LINE *top_d, *bottom_d;
 {
 {
-  struct d_layer *l_temp;
+       struct d_layer *l_temp;
 
 
-  l_temp = (struct d_layer *)malloc(sizeof(struct d_layer));
-  (l_temp->begin) = top_d;
-  (l_temp->end) = bottom_d;
-  (l_temp->next) = d_stk;
-  d_stk = l_temp;
-
-} /* end-d_add */
+       l_temp = malloc(sizeof(struct d_layer));
+       (l_temp->begin) = top_d;
+       (l_temp->end) = bottom_d;
+       (l_temp->next) = d_stk;
+       d_stk = l_temp;
 
 
+}
 
 /*
  * This cleans up the LINE structures deleted and no longer accessible
  * to undo. It performs garbage clean-up on the now non-referenced
 
 /*
  * This cleans up the LINE structures deleted and no longer accessible
  * to undo. It performs garbage clean-up on the now non-referenced
- * text in the buffer. All three buffer methods here #ifdef'd
+ * text in the buffer.
  */
  */
-
 void
 d_do()
 void
 d_do()
-
 {
 {
-  struct d_layer *l_temp;
-  LINE *l_temp2, *l_temp3;
-  int l_flag;
-#ifdef DBI
-  DBT l_db_key;
-#endif
-
-  l_temp = d_stk;
-
-  do
-    {
-      l_flag = 0;
-      l_temp2 = l_temp->begin;
-      do
-        {
-          l_temp3 = l_temp2;
-#ifdef STDIO
-          /* no garbage collection done currently */
-#endif
-#ifdef DBI
-          /* we do it, but db(3) says it doesn't really do it yet */
-          l_db_key.size = sizeof(recno_t);
-          l_db_key.data = &(l_temp2->handle);
-          (dbhtmp->del)(dbhtmp, &l_db_key, (u_int)0);
-#endif
-#ifdef MEMORY
-          free(l_temp2->handle);
-#endif
-          if ((l_temp->end) == l_temp2)
-            l_flag = 1;
-          l_temp2 = l_temp3->below;
-          free(l_temp3);
-        } while (l_flag == 0);
-
-        d_stk = d_stk->next;
-        free(l_temp);
-        l_temp = d_stk;
-      } while (d_stk);
-
-  d_stk = NULL; /* just to be sure */
-} /* end-d_do */
+       struct d_layer *l_temp;
+       DBT l_db_key;
+       LINE *l_temp2, *l_temp3;
+       int l_flag;
+
+       l_temp = d_stk;
+       do {
+               l_flag = 0;
+               l_temp2 = l_temp->begin;
+               do {
+                       l_temp3 = l_temp2;
+                       /*
+                        * We do it, but db(3) says it doesn't really do it
+                        * yet.
+                        */
+                       l_db_key.size = sizeof(recno_t);
+                       l_db_key.data = &(l_temp2->handle);
+                       (dbhtmp->del) (dbhtmp, &l_db_key, (u_int) 0);
+                       if ((l_temp->end) == l_temp2)
+                               l_flag = 1;
+                       l_temp2 = l_temp3->below;
+                       free(l_temp3);
+               } while (l_flag == 0);
+
+               d_stk = d_stk->next;
+               free(l_temp);
+               l_temp = d_stk;
+       } while (d_stk);
+
+       d_stk = NULL;           /* just to be sure */
+}
index 833454d..5497e1e 100644 (file)
@@ -9,10 +9,23 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)e.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)e.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <db.h>
+#include <fcntl.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Places a new file in the buffer to be editted. The current contents
 
 /*
  * Places a new file in the buffer to be editted. The current contents
@@ -23,126 +36,99 @@ static char sccsid[] = "@(#)e.c    5.1 (Berkeley) %G%";
 
 void
 e(inputt, errnum)
 
 void
 e(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_which;  /* which is it? 'e' or 'E' */
-  char *l_temp;
-
-  l_which = ss;
-
-  l_temp = filename(inputt, errnum);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum == 1)
-    {
-      free(filename_current);
-      filename_current = l_temp;
-    }
-  else if (*errnum == -2)
-    while (((ss = getc(inputt)) != '\n') || (ss == EOF))
-         ;
-  else if (*errnum < 0)
-    return;
-  *errnum = 0;
-
-  /* note: 'E' will bypass this if stmt., which warns of no save */
-  if ((change_flag == 1L) && (l_which == 'e'))
-    {
-      change_flag = 0L;
-      strcpy(help_msg, "warning: buffer changes not saved");
-      *errnum = -1;
-      ungetc('\n', inputt);
-      return;
-    }
-
-  start = top;
-  End = bottom;
-  start_default = End_default = 0;
-  if (start == NULL && bottom == NULL)
-    ;
-  else
-    {
-      ungetc(ss, inputt);
-      d(inputt, errnum);  /* delete the whole buffer */
-    }
-  if (sigint_flag)
-    SIGINT_ACTION;
-  u_clr_stk();  /* an 'e' clears all traces of last doc'mt, even in 'g' */
-  if (*errnum  < 0)
-    return;
-  *errnum = 0;
-#ifdef STDIO
-  if (fhtmp > NULL)
-    {
-      fclose(fhtmp);
-      unlink(template);
-    }
-#endif
-#ifdef DBI
-  if (dbhtmp != NULL)
-    {
-      (dbhtmp->close)(dbhtmp);
-      unlink(template);
-    }
-#endif
-
-  name_set = 1;
-  e2(inputt, errnum);
-  
-  *errnum = 1;
-} /* end-e */
-
-
- /* This is pulled out of e.c to make the "simulated 'e'" at startup
-  * easier to handle.
-  */
+       int l_which;            /* which is it? 'e' or 'E' */
+       char *l_temp;
+
+       l_which = ss;
+
+       l_temp = filename(inputt, errnum);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum == 1) {
+               free(filename_current);
+               filename_current = l_temp;
+       } else
+               if (*errnum == -2)
+                       while (((ss = getc(inputt)) != '\n') || (ss == EOF));
+               else
+                       if (*errnum < 0)
+                               return;
+       *errnum = 0;
+
+       /* Note: 'E' will bypass this if stmt., which warns of no save. */
+       if ((change_flag == 1L) && (l_which == 'e')) {
+               change_flag = 0L;
+               strcpy(help_msg, "warning: buffer changes not saved");
+               *errnum = -1;
+               ungetc('\n', inputt);
+               return;
+       }
+       start = top;
+       End = bottom;
+       start_default = End_default = 0;
+       if (start == NULL && bottom == NULL);
+       else {
+               ungetc(ss, inputt);
+               d(inputt, errnum);      /* delete the whole buffer */
+       }
+       if (sigint_flag)
+               SIGINT_ACTION;
+
+       /* An 'e' clears all traces of last doc'mt, even in 'g'. */
+       u_clr_stk();
+       if (*errnum < 0)
+               return;
+       *errnum = 0;
+       if (dbhtmp != NULL) {
+               (dbhtmp->close) (dbhtmp);
+               unlink(template);
+       }
+
+       name_set = 1;
+       e2(inputt, errnum);
+
+       *errnum = 1;
+}
 
 
+/*
+ * This is pulled out of e.c to make the "simulated 'e'" at startup easier to
+ * handle.
+ */
 void
 e2(inputt, errnum)
 void
 e2(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-#ifdef DBI
-  RECNOINFO l_dbaccess;
-#endif
-
-  if (template == NULL)
-    {
-      template = (char *)calloc(FILENAME_LEN, sizeof(char));
-      if (template == NULL)
-        ed_exit(4);
-    }
-
-  /* create the buffer using the method favored at compile time */
-  bcopy("/tmp/_4.4bsd_ed_XXXXXX\0", template, 22);
-  mktemp(template);
-#ifdef STDIO
-  fhtmp = fopen(template, "w+");
-  file_seek = 0;
-#endif
-#ifdef DBI
-  (l_dbaccess.bval) = (u_char)'\0';
-  (l_dbaccess.cachesize) = 0;
-  (l_dbaccess.flags) = R_NOKEY;
-  (l_dbaccess.lorder) = 0;
-  (l_dbaccess.reclen) = 0;
-  dbhtmp = dbopen(template, (O_CREAT | O_RDWR), (S_IRUSR | S_IWUSR), (DBTYPE)DB_RECNO, &l_dbaccess);
-#endif
-  current = top;
-  start = top;
-  End = bottom;
-
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (name_set)
-    {
-      filename_flag = 1; /* so 'r' knows the filename is already read in */
-      r(inputt, errnum);
-    }
-  change_flag = 0;
-} /* end-e2 */
+       RECNOINFO l_dbaccess;
+
+       if (template == NULL) {
+               template = (char *) calloc(FILENAME_LEN, sizeof(char));
+               if (template == NULL)
+                       ed_exit(4);
+       }
+       /* create the buffer using the method favored at compile time */
+       bcopy("/tmp/_4.4bsd_ed_XXXXXX\0", template, 22);
+       mktemp(template);
+       (l_dbaccess.bval) = (u_char) '\0';
+       (l_dbaccess.cachesize) = 0;
+       (l_dbaccess.flags) = R_NOKEY;
+       (l_dbaccess.lorder) = 0;
+       (l_dbaccess.reclen) = 0;
+       dbhtmp = dbopen(template, O_CREAT | O_RDWR,
+           S_IRUSR | S_IWUSR, (DBTYPE) DB_RECNO, &l_dbaccess);
+       current = top;
+       start = top;
+       End = bottom;
+
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (name_set) {
+               /* So 'r' knows the filename is already read in. */
+               filename_flag = 1;
+               r(inputt, errnum);
+       }
+       change_flag = 0;
+}
index b2b6740..1b43b3b 100644 (file)
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ed.h        5.1 (Berkeley) %G%
+ *     @(#)ed.h        5.2 (Berkeley) %G%
  */
 
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <fcntl.h>
-#include <regex.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef DBI
-#include <limits.h>
-#include <db.h>
-#endif
-
-#define FILENAME_LEN 1023
-#define JMP_SET (int)0
-#define INTERUPT (int)1
-#define HANGUP (int)2
-#define SIGINT_ACTION longjmp(ctrl_position, INTERUPT); fflush(stdin)
-#define SIGHUP_ACTION longjmp(ctrl_position, HANGUP)
-#define NN_MAX_START 510
+#define        FILENAME_LEN    1023
+#define        JMP_SET         (int)0
+#define        INTERUPT        (int)1
+#define        HANGUP          (int)2
+#define        SIGINT_ACTION   longjmp(ctrl_position, INTERUPT); fflush(stdin)
+#define        SIGHUP_ACTION   longjmp(ctrl_position, HANGUP)
+#define        NN_MAX_START    510
 
 typedef struct A {
 
 typedef struct A {
-                 struct A *above, *below;
-#ifdef STDIO
-                 long handle;
-#endif
-#ifdef DBI
-                 recno_t handle;
-#endif
-#ifdef MEMORY
-                 char *handle;
-#endif
-                 size_t len;
-               } LINE;
+       struct A *above, *below;
+       recno_t handle;
+       size_t len;
+} LINE;
 
 struct MARK {
 
 struct MARK {
-              LINE *address;
-            };
-
+       LINE *address;
+};
 
 struct g_list {
 
 struct g_list {
-                 struct g_list *next;
-                 LINE *cell;
-               };
+       struct g_list *next;
+       LINE *cell;
+};
 
 struct u_layer {
 
 struct u_layer {
-                 LINE *val, **cell;
-                 struct u_layer *below;
-               };
+       LINE *val, **cell;
+       struct u_layer *below;
+};
 
 struct d_layer {
 
 struct d_layer {
-                 LINE *begin, *end;
-                 struct d_layer *next;
-               };
-
-extern void cmd_loop();
-extern void a();
-extern void c();
-extern void d();
-extern void d_add();
-extern void d_do();
-extern void e();
-extern void e2();
-extern void f();
-extern void g();
-extern void i();
-extern void j();
-extern void k();
-extern void ku_chk();
-extern void l();
-extern void m();
-extern void p();
-extern void q();
-extern void r();
-extern void s();
-extern void t();
-extern void u();
-extern void u_add_stk();
-extern void u_clr_stk();
-extern void w();
-extern void z();
-extern void equal();
-extern void bang();
-extern void set_mark();
-extern LINE *get_mark();
-extern LINE *search();
-extern LINE *search_r();
-extern long input_lines();
-#ifdef STDIO
-extern long add_line();
-#endif
-#ifdef DBI
-extern recno_t add_line();
-#endif
-#ifdef MEMORY
-extern char *add_line();
-#endif
-extern void get_line();
-extern int num_dig_conv();
-extern LINE *address_conv();
-extern struct bounds *re_search();
-extern struct re_pattern *re_compile();
-extern void undo();
-extern char *re_replace();
-extern char *get_pattern();
-extern char *filename();
-extern int rol();
-extern void ed_exit();
+       LINE *begin, *end;
+       struct d_layer *next;
+};
 
 extern int nn_max, nn_max_flag, start_default, End_default, address_flag;
 extern LINE *nn_max_start, *nn_max_end, *start, *End, *current;
 
 extern int nn_max, nn_max_flag, start_default, End_default, address_flag;
 extern LINE *nn_max_start, *nn_max_end, *start, *End, *current;
@@ -133,16 +55,8 @@ extern int filename_flag, add_flag;
 extern long change_flag;
 extern int pat_err, flag, g_flag, GV_flag, printsfx;
 
 extern long change_flag;
 extern int pat_err, flag, g_flag, GV_flag, printsfx;
 
-#ifdef STDIO
-extern FILE *fhtmp;
-extern int file_seek;
-extern char *template;
-#endif
-
-#ifdef DBI
 extern DB *dbhtmp;
 extern char *template;
 extern DB *dbhtmp;
 extern char *template;
-#endif
 
 extern struct u_layer *u_stk;
 extern LINE *u_current, *u_top, *u_bottom;
 
 extern struct u_layer *u_stk;
 extern LINE *u_current, *u_top, *u_bottom;
index ee6b7fd..df54a15 100644 (file)
@@ -9,50 +9,51 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)edhup.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)edhup.c    5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
 
 /*
- * If a SIGHUP is received then user contact is severed. Try, if
- * possible, to save the buffer. But be nice and don't save over
- * remembered filename (you can figure out why, can't you?).
- * The buffer is saved in a file named "ed.hup" in the directory that
- * ed was started-up in. If a write cannot be made to that directory (say
- * because it is read-only) then try writting "ed.hup" in the user's $HOME
- * direcory. Then exit.
+ * If a SIGHUP is received then user contact is severed. Try, if possible,
+ * to save the buffer. But be nice and don't save over remembered filename
+ * (you can figure out why, can't you?).  The buffer is saved in a file
+ * named "ed.hup" in the directory that ed was started-up in.  If a write
+ * cannot be made to that directory (say because it is read-only) then try
+ * writting "ed.hup" in the user's $HOME directory. Then exit.
  */
  */
-
+__dead void
 do_hup()
 do_hup()
-
 {
 {
-  char l_filename[FILENAME_LEN], *l_temp;
-  FILE *l_fp;
-
-  if (change_flag == 0)
-    exit(1); /* no need to save buffer contents */
-  if ((l_fp = fopen("ed.hup", "w")) == NULL)
-    {
-      /* try writting ed.hup to the $HOME directory instead */
-      l_temp = getenv("HOME");
-      if ((l_temp == NULL) || ((strlen(l_temp)+7)>FILENAME_LEN))
-        exit(1);
-      strcpy(l_filename, l_temp);
-      strcat(l_filename, "/ed.hup");
-      if ((l_fp = fopen(l_filename, "w")) == NULL)
-        exit(1); /* we tried... */
-    }
-  edwrite(l_fp, top, bottom);
-  fclose(l_fp);
-#ifdef STDIO
-  fclose(fhtmp);
-  unlink(template);
-#endif
-#ifdef DBI
-  (dbhtmp->close)(dbhtmp);
-  unlink(template);
-#endif
-  exit(1); /* hangup */
+       char l_filename[FILENAME_LEN], *l_temp;
+       FILE *l_fp;
 
 
-} /* end-do_hup */
+       if (change_flag == 0)
+               exit(1);                /* No need to save buffer contents. */
+       if ((l_fp = fopen("ed.hup", "w")) == NULL) {
+               /* Try writting ed.hup to the $HOME directory instead. */
+               l_temp = getenv("HOME");
+               if ((l_temp == NULL) || ((strlen(l_temp) + 7) > FILENAME_LEN))
+                       exit(1);
+               strcpy(l_filename, l_temp);
+               strcat(l_filename, "/ed.hup");
+               if ((l_fp = fopen(l_filename, "w")) == NULL)
+                       exit(1);                /* We tried... */
+       }
+       edwrite(l_fp, top, bottom);
+       fclose(l_fp);
+       (dbhtmp->close) (dbhtmp);
+       unlink(template);
+       exit(1);                                /* Hangup */
+}
index f1bde8a..44502ef 100644 (file)
@@ -9,32 +9,37 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)equal.c    5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)equal.c    5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Print out what the line number of the address given is; default to
  * end-of-buffer ($).
  */
 
 /*
  * Print out what the line number of the address given is; default to
  * end-of-buffer ($).
  */
 void
 equal(inputt, errnum)
 void
 equal(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  if (End_default)
-    start = bottom;
-  else
-    start = End;
-  start_default = End_default = 0;
+       if (End_default)
+               start = bottom;
+       else
+               start = End;
+       start_default = End_default = 0;
 
 
-  if (rol(inputt, errnum))
-    return;
+       if (rol(inputt, errnum))
+               return;
 
 
-  printf("%d\n", line_number(start));
-  *errnum = 1;
-} /* end-equal */
+       (void)printf("%d\n", line_number(start));
+       *errnum = 1;
+}
index 9c24bc7..0e75e95 100644 (file)
@@ -9,40 +9,47 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)f.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)f.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h" 
 #include "ed.h" 
+#include "extern.h"
 
 /*
  * Prints out or sets the remembered filename.
  */
 
 /*
  * Prints out or sets the remembered filename.
  */
-
 void
 f(inputt, errnum)
 void
 f(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  char *l_temp;
+       char *l_temp;
 
 
-  l_temp = filename(inputt, errnum);
-  if (sigint_flag)
-     SIGINT_ACTION;
-  if (*errnum == 1)
-    {
-      free(filename_current);
-      filename_current = l_temp;
-    }
-  else if (*errnum == -2)
-    while (((ss = getc(inputt)) != '\n') || (ss == EOF))
-         ;
-  else if (*errnum < 0)
-      return;
-  if (sigint_flag)
-     SIGINT_ACTION;
-  fwrite(filename_current, sizeof(char), strlen(filename_current), stdout);
-  putchar('\n');
-  *errnum = 1;
-} /* end-f */
+       l_temp = filename(inputt, errnum);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum == 1) {
+               free(filename_current);
+               filename_current = l_temp;
+       } else
+               if (*errnum == -2)
+                       while (((ss = getc(inputt)) != '\n') || (ss == EOF));
+               else
+                       if (*errnum < 0)
+                               return;
+       if (sigint_flag)
+               SIGINT_ACTION;
+       fwrite(filename_current,
+           sizeof(char), strlen(filename_current), stdout);
+       putchar('\n');
+       *errnum = 1;
+}
index c36714d..49ce215 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)filename.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)filename.c 5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h" 
 #include "ed.h" 
+#include "extern.h"
 
 /*
  * A central function for any command that has to deal with a filename
  * (to be or not to be remembered).
  */
 
 /*
  * A central function for any command that has to deal with a filename
  * (to be or not to be remembered).
  */
-
-char
-*filename(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+char *
+filename(inputt, errnum)
+       FILE *inputt;
+       int *errnum;
 {
 {
-  char *l_fname;
-  register int l_cnt=0;
-  int l_esc=0, l_bang_flag=0, l_len;
-
-  l_fname = (char *)calloc(FILENAME_LEN, sizeof(char));
-  if (l_fname == NULL)
-    {
-      *errnum = -1;
-      strcpy(help_msg, "out of memory error");
-      return(NULL);
-    }
+       register int l_cnt = 0;
+       char *l_fname;
+       int l_esc = 0, l_bang_flag = 0, l_len;
 
 
-  if ((ss = getc(inputt)) != ' ')
-    {
-      if (ss == '\n')
-        {
-          ungetc(ss, inputt);
-          *errnum = -2; /* it's not really an error, but to flag remembered filename is to be used */
-        }
-      else
-        {
-          *errnum = -1;
-          strcpy(help_msg, "space required before filename given");
-        }
-      return(NULL);
-    }
-  while (ss = getc(inputt))
-       if (ss != ' ')
-         {
-           ungetc(ss, inputt);
-           break;
-         }
-  while (1)
-       {
-         ss = getc(inputt);
-         if ((ss == '\\') && (l_esc == 0))
-           {
-             ss = getchar();
-             l_esc = 1;
-           } 
-         else
-           l_esc = 0;
-         if ((ss == '\n') || (ss == EOF))
-           {
-             l_fname[l_cnt] = '\0';
-             break;
-           }
-         else if ((ss == '!') && (l_esc == 0))
-             l_bang_flag = 1;
-         else if (ss != ' ')
-           l_fname[l_cnt++] = ss;
-         else
-           continue;
+       l_fname = calloc(FILENAME_LEN, sizeof(char));
+       if (l_fname == NULL) {
+               *errnum = -1;
+               strcpy(help_msg, "out of memory error");
+               return (NULL);
+       }
+       if ((ss = getc(inputt)) != ' ') {
+               if (ss == '\n') {
+                       ungetc(ss, inputt);
+                       /*
+                        * It's not really an error, but to flag remembered
+                        * filename is to be used.
+                        */
+                       *errnum = -2;
+               } else {
+                       *errnum = -1;
+                       strcpy(help_msg,
+                           "space required before filename given");
+               }
+               return (NULL);
+       }
+       while (ss = getc(inputt))
+               if (ss != ' ') {
+                       ungetc(ss, inputt);
+                       break;
+               }
+       for (;;) {
+               ss = getc(inputt);
+               if ((ss == '\\') && (l_esc == 0)) {
+                       ss = getchar();
+                       l_esc = 1;
+               } else
+                       l_esc = 0;
+               if ((ss == '\n') || (ss == EOF)) {
+                       l_fname[l_cnt] = '\0';
+                       break;
+               } else
+                       if ((ss == '!') && (l_esc == 0))
+                               l_bang_flag = 1;
+                       else
+                               if (ss != ' ')
+                                       l_fname[l_cnt++] = ss;
+                               else
+                                       continue;
 
 
-         if (l_cnt >= FILENAME_LEN)
-           {
-             strcpy(help_msg, "filename+path length too long");
-             *errnum = -1;
-             ungetc('\n', inputt);
-             return(NULL);
-           }
-       } /* end-while(1) */
+               if (l_cnt >= FILENAME_LEN) {
+                       strcpy(help_msg, "filename+path length too long");
+                       *errnum = -1;
+                       ungetc('\n', inputt);
+                       return (NULL);
+               }
+       }
 
 
-  if (l_bang_flag == 1) /* user wants the name from a sh command */
-    {
-      FILE *namestream, *popen();
+       if (l_bang_flag == 1) { /* user wants the name from a sh command */
+               FILE   *namestream, *popen();
 
 
-      if (l_fname[0] == '\0')
-        {
-          strcpy(help_msg, "no command given");
-          *errnum = -1;
-          return(NULL);
-        }
-      if (((namestream = popen(l_fname, "r")) == NULL) || ((fgets(l_fname, FILENAME_LEN-1, namestream)) == NULL))
-        {
-          strcpy(help_msg, "error executing command");
-          *errnum = -1;
-          if (namestream != NULL)
-            pclose(namestream);
-          return(NULL);
-        }
-      l_len = strlen(l_fname) - 1;
-      if (l_fname[l_len] == '\n')
-        l_fname[l_len] = '\0';
-      pclose(namestream);
-    }
-  else if (l_fname[0] == '\0')
-    strcpy(l_fname, filename_current);
-  else
-    *errnum = 1;
-  return(l_fname);
-} /* end-filename */
+               if (l_fname[0] == '\0') {
+                       strcpy(help_msg, "no command given");
+                       *errnum = -1;
+                       return (NULL);
+               }
+               if (((namestream = popen(l_fname, "r")) == NULL) ||
+                   ((fgets(l_fname, FILENAME_LEN - 1, namestream)) == NULL)) {
+                       strcpy(help_msg, "error executing command");
+                       *errnum = -1;
+                       if (namestream != NULL)
+                               pclose(namestream);
+                       return (NULL);
+               }
+               l_len = strlen(l_fname) - 1;
+               if (l_fname[l_len] == '\n')
+                       l_fname[l_len] = '\0';
+               pclose(namestream);
+       } else
+               if (l_fname[0] == '\0')
+                       strcpy(l_fname, filename_current);
+               else
+                       *errnum = 1;
+       return (l_fname);
+}
index c5baa13..57d4492 100644 (file)
@@ -9,75 +9,78 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)g.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)g.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
+
+static int     find_line __P((LINE *));
+static void    w_cmd_l_file __P((FILE *, FILE *, int *));
 
 /*
  * Find a line that we noted matched the RE earlier in the current
  * buffer (it may have disappeared because of the commands in the
  * command list).
  */
 
 /*
  * Find a line that we noted matched the RE earlier in the current
  * buffer (it may have disappeared because of the commands in the
  * command list).
  */
-
 int
 find_line(dot)
 int
 find_line(dot)
-
-LINE *dot;
-
+       LINE *dot;
 {
 {
-  LINE *l_cl;
-
-  l_cl = top;
-  while (1)
-       {
-         if (l_cl == dot)
-           return(1);
-        if (l_cl == bottom)
-          return(0);
-        l_cl = l_cl->below;
-       }
-} /*end-find_line */
+       LINE *l_cl;
 
 
+       l_cl = top;
+       for (;;) {
+               if (l_cl == dot)
+                       return (1);
+               if (l_cl == bottom)
+                       return (0);
+               l_cl = l_cl->below;
+       }
+}
 
 /*
  * Write the command line to a STDIO tmp file. See g() below.
  * This allows us to use cmd_loop to run the command list because
  * we "trick" cmd_loop into reading a STDIO file instead of stdin.
  */
 
 /*
  * Write the command line to a STDIO tmp file. See g() below.
  * This allows us to use cmd_loop to run the command list because
  * we "trick" cmd_loop into reading a STDIO file instead of stdin.
  */
-
 void
 w_cmd_l_file(fp, inputt, errnum)
 void
 w_cmd_l_file(fp, inputt, errnum)
-
-FILE *fp, *inputt;
-int *errnum;
-
+       FILE *fp, *inputt;
+       int *errnum;
 {
 {
-  int l_esc=0, l_cnt=0;
-
-  while (1)
-       {
-         ss = getc(inputt);
-         if (ss == '\\')
-           {
-             l_esc = 1;
-             ss = getc(inputt);
-           }
-         if (((ss == '\n') && (l_esc == 0)) || (ss == EOF))
-           {
-             /* if no command list default command list to 'p' */
-             if (l_cnt == 0)
-               fputc('p', fp);
-             break;
-           }
-         l_esc = 0;
-         fputc(ss, fp);
-         l_cnt++;
-       } /* end-while */
-  if (ss == EOF)
-    clearerr(inputt);
-} /* end-w_cmd_l_file */
+       int l_esc = 0, l_cnt = 0;
 
 
+       for (;;) {
+               ss = getc(inputt);
+               if (ss == '\\') {
+                       l_esc = 1;
+                       ss = getc(inputt);
+               }
+               if (((ss == '\n') && (l_esc == 0)) || (ss == EOF)) {
+                       /* if no command list default command list to 'p' */
+                       if (l_cnt == 0)
+                               fputc('p', fp);
+                       break;
+               }
+               l_esc = 0;
+               fputc(ss, fp);
+               l_cnt++;
+       }
+       if (ss == EOF)
+               clearerr(inputt);
+}
 
 /*
  * The global function. All global commands (g, G, v, and V) are handled
 
 /*
  * The global function. All global commands (g, G, v, and V) are handled
@@ -86,231 +89,210 @@ int *errnum;
  * Note the trick of how the command list is executed. Saves a lot of
  * code (and allows for \n's in substitutions).
  */
  * Note the trick of how the command list is executed. Saves a lot of
  * code (and allows for \n's in substitutions).
  */
-
 void
 g(inputt, errnum)
 void
 g(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  struct g_list *l_Head, *l_Foot, *l_gut, *l_old;
-  static char *l_template_g;
-  char *l_patt;
-  static int l_template_flag=0;
-  int l_re_success, l_flag_v=0, l_err;
-  FILE *l_fp, *fopen();
+       struct g_list *l_Head, *l_Foot, *l_gut, *l_old;
+       static char *l_template_g;
+       char *l_patt;
+       static int l_template_flag = 0;
+       int l_re_success, l_flag_v = 0, l_err;
+       FILE *l_fp;
 #ifdef POSIX
 #ifdef POSIX
-  LINE *l_posix_cur;
+       LINE *l_posix_cur;
 #endif
 
 #endif
 
-  if (start_default && End_default)
-    {
-      start = top;
-      End = bottom;
-    }
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
-  if (sigint_flag)
-    SIGINT_ACTION;
+       if (start_default && End_default) {
+               start = top;
+               End = bottom;
+       } else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       if (sigint_flag)
+               SIGINT_ACTION;
 
 
-  if (l_template_flag == 0)
-    {
-      l_template_flag = 1;
-      l_template_g = (char *)calloc(FILENAME_LEN, sizeof(char));
-      if (l_template_g == NULL)
-        {
-          *errnum = -1;
-          strcpy(help_msg, "out of memory error");
-          return;
-        }
-    }
-  /* set up the STDIO command list file */
-  bcopy("/tmp/_4.4bsd_ed_g_XXXXXX\0", l_template_g, 24);
-  mktemp(l_template_g);
+       if (l_template_flag == 0) {
+               l_template_flag = 1;
+               l_template_g = calloc(FILENAME_LEN, sizeof(char));
+               if (l_template_g == NULL) {
+                       *errnum = -1;
+                       strcpy(help_msg, "out of memory error");
+                       return;
+               }
+       }
+       /* set up the STDIO command list file */
+       bcopy("/tmp/_4.4bsd_ed_g_XXXXXX\0", l_template_g, 24);
+       mktemp(l_template_g);
 
 
-  l_Head = l_Foot = l_gut = l_old = NULL;
+       l_Head = l_Foot = l_gut = l_old = NULL;
 
 
-  if ((ss == 'v') || (ss == 'V'))
-    l_flag_v = 1;
+       if ((ss == 'v') || (ss == 'V'))
+               l_flag_v = 1;
 
 
-  if ((ss == 'G') || (ss == 'V'))
-    {
-      /* if it's an interactive global command we use stdin, not a file */
-      GV_flag = 1;
-      l_fp = stdin;
-    }
-  else
-    {
-      if ((l_fp = fopen(l_template_g, "w+")) == NULL)
-        {
-          perror("ed: file I/O error");
-          exit(1);
-        }   
-    }
+       if ((ss == 'G') || (ss == 'V')) {
+               /*
+                * If it's an interactive global command we use stdin, not a
+                * file.
+                */
+               GV_flag = 1;
+               l_fp = stdin;
+       } else {
+               if ((l_fp = fopen(l_template_g, "w+")) == NULL) {
+                       perror("ed: file I/O error");
+                       exit(1);
+               }
+       }
 
 
-  ss = getc(inputt);
+       ss = getc(inputt);
 
 
-  /* get the RE for the global command */
-  l_patt = get_pattern(ss, inputt, errnum, 0);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum < -1) /* instead of: if ((*errnum == -1) && (ss == '\n'))... */
-    return;
-  *errnum = 0;
-  if ((l_patt[1] == '\0') && (RE_flag == 0))
-    {
-      *errnum = -1;
-      ungetc(ss, inputt);
-      return;
-    }
-  else if (l_patt[1] || (RE_patt == NULL))
-    {
-      free(RE_patt);
-      RE_patt = l_patt;
-    }
-  RE_sol = (RE_patt[1] == '^')?1:0;
-  if ((RE_patt[1]) && (regfree(&RE_comp), l_err = regcomp(&RE_comp, &RE_patt[1], 0)))
-    {
-      regerror(l_err, &RE_comp, help_msg, 128);
-      *errnum = -1;
-       RE_flag = 0;
-      ungetc(ss, inputt);
-      return;
-    }
-  RE_flag = 1;
-  if (sigint_flag)
-    SIGINT_ACTION;
+       /* Get the RE for the global command. */
+       l_patt = get_pattern(ss, inputt, errnum, 0);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       /* Instead of: if ((*errnum == -1) && (ss == '\n'))... */
+       if (*errnum < -1)
+               return;
+       *errnum = 0;
+       if ((l_patt[1] == '\0') && (RE_flag == 0)) {
+               *errnum = -1;
+               ungetc(ss, inputt);
+               return;
+       } else
+               if (l_patt[1] || (RE_patt == NULL)) {
+                       free(RE_patt);
+                       RE_patt = l_patt;
+               }
+       RE_sol = (RE_patt[1] == '^') ? 1 : 0;
+       if ((RE_patt[1]) &&
+           (regfree(&RE_comp), l_err = regcomp(&RE_comp, &RE_patt[1], 0))) {
+               regerror(l_err, &RE_comp, help_msg, 128);
+               *errnum = -1;
+               RE_flag = 0;
+               ungetc(ss, inputt);
+               return;
+       }
+       RE_flag = 1;
+       if (sigint_flag)
+               SIGINT_ACTION;
 #ifdef POSIX
 #ifdef POSIX
-  l_posix_cur = current;
+       l_posix_cur = current;
 #endif
 #endif
-  current = start;
+       current = start;
 
 
-  while (1)
-       {
-         /* find the lines in the buffer that the global command wants
-          * to work with
-          */
-         if (sigint_flag)
-           goto point;
-         get_line(current->handle, current->len);
-         l_re_success = regexec(&RE_comp, text, (size_t)RE_SEC, RE_match, 0);
-         /* l_re_success=0 => success */
-         if ((l_re_success  != 0 && l_flag_v == 1) || (l_re_success == 0 && l_flag_v == 0))
-           {
-             if (l_Head == NULL)
-               {
-                 l_gut = (struct g_list *)malloc(sizeof(struct g_list));
-                 if (l_gut == NULL)
-                   {
-                     *errnum = -1;
-                     strcpy(help_msg, "out of memory error");
+       for (;;) {
+               /*
+                * Find the lines in the buffer that the global command wants
+                * to work with.
+                */
+               if (sigint_flag)
+                       goto point;
+               get_line(current->handle, current->len);
+               l_re_success =
+                   regexec(&RE_comp, text, (size_t) RE_SEC, RE_match, 0);
+               /* l_re_success=0 => success */
+               if ((l_re_success != 0 && l_flag_v == 1) ||
+                   (l_re_success == 0 && l_flag_v == 0)) {
+                       if (l_Head == NULL) {
+                               l_gut = malloc(sizeof(struct g_list));
+                               if (l_gut == NULL) {
+                                       *errnum = -1;
+                                       strcpy(help_msg, "out of memory error");
 #ifdef POSIX
 #ifdef POSIX
-                     current = l_posix_cur;
+                                       current = l_posix_cur;
 #endif
 #endif
-                     return;
-                   }
-                 (l_gut->next) = NULL;
-                 (l_gut->cell) = current;
-                 l_Foot = l_Head = l_gut;
-               }
-             else
-               {
-                 (l_gut->next) = (struct g_list *)malloc(sizeof(struct g_list));
-                 if ((l_gut->next) == NULL)
-                   {
-                     *errnum = -1;
-                     strcpy(help_msg, "out of memory error");
-                     goto clean;
-                   }
-                 l_gut = l_gut->next;
-                 (l_gut->cell) = current;
-                 (l_gut->next) = NULL;
-                 l_Foot = l_gut;
-               }
-           }
+                                       return;
+                               }
+                               (l_gut->next) = NULL;
+                               (l_gut->cell) = current;
+                               l_Foot = l_Head = l_gut;
+                       } else {
+                               (l_gut->next) = malloc(sizeof(struct g_list));
+                               if ((l_gut->next) == NULL) {
+                                       *errnum = -1;
+                                       strcpy(help_msg, "out of memory error");
+                                       goto clean;
+                               }
+                               l_gut = l_gut->next;
+                               (l_gut->cell) = current;
+                               (l_gut->next) = NULL;
+                               l_Foot = l_gut;
+                       }
+               }
+               if (End == current)
+                       break;
+               current = current->below;
+       }
 
 
-         if (End == current)
-           break;
-         current = current->below;
-       } /* end-while */
-   
-  if (l_Head == NULL)
-    {
-      strcpy(help_msg, "no matches found");
-      *errnum = -1;
+       if (l_Head == NULL) {
+               strcpy(help_msg, "no matches found");
+               *errnum = -1;
 #ifdef POSIX
 #ifdef POSIX
-      current = l_posix_cur;
+               current = l_posix_cur;
 #endif
 #endif
-      return;
-    }
-
-  /* if non-interactive, get the command list */
-  if (GV_flag == 0)
-    w_cmd_l_file(l_fp, inputt, errnum);
-  l_gut = l_Head;
+               return;
+       }
+       /* if non-interactive, get the command list */
+       if (GV_flag == 0)
+               w_cmd_l_file(l_fp, inputt, errnum);
+       l_gut = l_Head;
 
 
-  if (g_flag == 0)
-    u_clr_stk();
+       if (g_flag == 0)
+               u_clr_stk();
 
 
-  while (1)
-       {
-         /* execute the command list on the lines that still exist
-          * that we indicated earlier that global wants to work with.
-          */
-         if (sigint_flag)
-           goto point;
-         if (GV_flag == 0)
-           fseek(l_fp, 0L, 0);
-         if (find_line(l_gut->cell))
-           {
-             current = (l_gut->cell);
-             get_line(current->handle, current->len);
-             if (GV_flag == 1)
-               printf("%s\n", text);
-             g_flag++;
-             explain_flag--;
-             cmd_loop(l_fp, errnum);
-             explain_flag++;
-             g_flag--;
-             if ((GV_flag == 1) && (*errnum < 0))
-               {
-                 ungetc('\n', l_fp);
-                 break;
-               }
-             *errnum = 0;
-             if (l_gut == l_Foot)
-               break;
-             l_gut = l_gut->next;
-           } /* end-if */
-       } /* end-while */
+       for (;;) {
+               /*
+                * Execute the command list on the lines that still exist that
+                * we indicated earlier that global wants to work with.
+                */
+               if (sigint_flag)
+                       goto point;
+               if (GV_flag == 0)
+                       fseek(l_fp, (off_t)0, 0);
+               if (find_line(l_gut->cell)) {
+                       current = (l_gut->cell);
+                       get_line(current->handle, current->len);
+                       if (GV_flag == 1)
+                               printf("%s\n", text);
+                       g_flag++;
+                       explain_flag--;
+                       cmd_loop(l_fp, errnum);
+                       explain_flag++;
+                       g_flag--;
+                       if ((GV_flag == 1) && (*errnum < 0)) {
+                               ungetc('\n', l_fp);
+                               break;
+                       }
+                       *errnum = 0;
+                       if (l_gut == l_Foot)
+                               break;
+                       l_gut = l_gut->next;
+               }
+       }
 
 
-  point:
-  if (GV_flag == 0)
-    {
-      fclose(l_fp);
-      unlink(l_template_g);
-    }
-  GV_flag = 0;
+point:
+       if (GV_flag == 0) {
+               fclose(l_fp);
+               unlink(l_template_g);
+       }
+       GV_flag = 0;
 clean:
 clean:
-  /* clean up */
-  l_gut = l_Head;
-  while (1)
-       {
-         if (l_gut == NULL)
-           break;
-         l_old = l_gut;
-         l_gut = l_gut->next;
-         free(l_old);
-       } /* end-while */
+       /* clean up */
+       l_gut = l_Head;
+       while (1) {
+               if (l_gut == NULL)
+                       break;
+               l_old = l_gut;
+               l_gut = l_gut->next;
+               free(l_old);
+       }
 #ifdef POSIX
 #ifdef POSIX
-  current = l_posix_cur;
+       current = l_posix_cur;
 #endif
 #endif
-  return;
-} /* end-g */
+}
index af2f4f0..22cf0f7 100644 (file)
@@ -9,10 +9,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)get_line.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)get_line.c 5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Get the specified line from the buffer. Note that in the buffer
 
 /*
  * Get the specified line from the buffer. Note that in the buffer
@@ -33,49 +42,21 @@ static char sccsid[] = "@(#)get_line.c      5.1 (Berkeley) %G%";
  * I've been told the newer BSD STDIO has fixed this, but don't
  * currently have a copy.
  */
  * I've been told the newer BSD STDIO has fixed this, but don't
  * currently have a copy.
  */
-
 int file_loc=0;
 int file_loc=0;
-extern int file_loc;
 
 /* Get a particular line of length len from ed's buffer and place it in
  * 'text', the standard repository for the "current" line.
  */
 
 /* Get a particular line of length len from ed's buffer and place it in
  * 'text', the standard repository for the "current" line.
  */
-
 void
 get_line(loc, len)
 void
 get_line(loc, len)
-
-#ifdef STDIO
-long loc;
-#endif
-#ifdef DBI
-recno_t loc;
-#endif
-#ifdef MEMORY
-char *loc;
-#endif
-int len;
-
+       recno_t loc;
+       int len;
 {
 {
-#ifdef STDIO
-
-  if (file_loc != loc)
-    fseek(fhtmp, loc, 0);
-  file_seek = 1;
-  file_loc = loc + fread(text, sizeof(char), len, fhtmp);
-#endif
-
-#ifdef DBI
-  DBT db_key, db_data;
-
-  (db_key.data) = &loc;
-  (db_key.size) = sizeof(recno_t);
-  (dbhtmp->get)(dbhtmp, &db_key, &db_data, (u_int)0);
-  strcpy(text, db_data.data);
-#endif
-
-#ifdef MEMORY
-  tmp = (char *)loc;
-  bcopy(loc, text, len);
-#endif
-  text[len] = '\0';
-} /* end-get_line */
+       DBT db_key, db_data;
+
+       (db_key.data) = &loc;
+       (db_key.size) = sizeof(recno_t);
+       (dbhtmp->get) (dbhtmp, &db_key, &db_data, (u_int) 0);
+       strcpy(text, db_data.data);
+       text[len] = '\0';
+}
index 5947d5b..27ab1d0 100644 (file)
@@ -9,99 +9,97 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)get_pattern.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)get_pattern.c      5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This is for getting RE and replacement patterns for any command
  * that uses RE's and replacements.
  */
 
 /*
  * This is for getting RE and replacement patterns for any command
  * that uses RE's and replacements.
  */
-
-char
-*get_pattern(delim, inputt, errnum, flag)
-
-int delim;
-FILE *inputt;
-int *errnum, flag;
-
+char *
+get_pattern(delim, inputt, errnum, flag)
+       int delim, *errnum, flag;
+       FILE *inputt;
 {
 {
-  int l_cnt=1;
-  static int l_max=510;
-  char *l_pat, *l_pat_tmp;
+       static int l_max = 510;
+       int l_cnt = 1;
+       char *l_pat, *l_pat_tmp;
 
 
-  /* get a "reasonable amount of space for the RE */
-  l_pat = (char *)calloc(l_max+2, sizeof(char));
-  if (l_pat == NULL)
-    {
-      *errnum = -3;
-      strcpy(help_msg, "out of memory error");
-      return(NULL);
-    }
-  l_pat[0] = delim;
+       /* get a "reasonable amount of space for the RE */
+       l_pat = calloc(l_max + 2, sizeof(char));
+       if (l_pat == NULL) {
+               *errnum = -3;
+               strcpy(help_msg, "out of memory error");
+               return (NULL);
+       }
+       l_pat[0] = delim;
 
 
-  if ((delim == ' ') || (delim == '\n'))
-    {
-      if (delim == '\n')
-        ungetc(delim, inputt);
-      strcpy(help_msg, "illegal delimiter");
-      *errnum = -2;
-      return(l_pat);
-    }
-  
-  while (1)
-       {
-         ss = getc(inputt);
-         if (ss == '\\')
-           {
-             ss = getc(inputt);
-             if ((ss == delim) || ((flag == 1) && (ss == '\n')))
-                 l_pat[l_cnt] = ss;
-             else
-               {
-                 l_pat[l_cnt] = '\\';
-                 /*ungetc(ss, inputt);*/
-                 l_pat[++l_cnt] = ss;
-               }
-             goto leap;
-           }
-         else if ((ss == '\n') || (ss == EOF))
-           {
-             ungetc(ss, inputt);
-             strcpy(help_msg, "no closing delimiter found");
-             *errnum = -1;
-             l_pat[l_cnt] = '\0'; /* this is done for 's's backward compat. */
-             return(l_pat);
-           }
-         if (ss == delim)
-           break;
+       if ((delim == ' ') || (delim == '\n')) {
+               if (delim == '\n')
+                       ungetc(delim, inputt);
+               strcpy(help_msg, "illegal delimiter");
+               *errnum = -2;
+               return (l_pat);
+       }
+       for (;;) {
+               ss = getc(inputt);
+               if (ss == '\\') {
+                       ss = getc(inputt);
+                       if ((ss == delim) || ((flag == 1) && (ss == '\n')))
+                               l_pat[l_cnt] = ss;
+                       else {
+                               l_pat[l_cnt] = '\\';
+                               /* ungetc(ss, inputt); */
+                               l_pat[++l_cnt] = ss;
+                       }
+                       goto leap;
+               } else
+                       if ((ss == '\n') || (ss == EOF)) {
+                               ungetc(ss, inputt);
+                               strcpy(help_msg, "no closing delimiter found");
+                               *errnum = -1;
+                               /* This is done for s's backward compat. */
+                               l_pat[l_cnt] = '\0';
+                               return (l_pat);
+                       }
+               if (ss == delim)
+                       break;
 
 
-         l_pat[l_cnt] = ss;
+               l_pat[l_cnt] = ss;
 
 
-leap:
-         if (l_cnt > l_max)
-           {
-             /* the RE is really long; get more space for it */
-             l_max = l_max + 256;
-             l_pat_tmp = l_pat;
-             l_pat = (char *)calloc(l_max+2, sizeof(char));
-             if (l_pat == NULL)
-               {
-                 *errnum = -3;
-                 strcpy(help_msg, "out of memory error");
-                 return(NULL);
-               }
-             bcopy(l_pat_tmp, l_pat, l_cnt);
-             free(l_pat_tmp);
-           }
-         l_cnt++;
-       }
-  l_pat[l_cnt] = '\0';
-  *errnum = 0;
-  /* send back the pattern. l_pat[0] has the delimiter in it so the RE
-   * really starts at l_pat[1]. It's done this way for the special forms
-   * of 's' (substitute).
-   */
-  return(l_pat);
-} /* end-get_pattern */
+leap:          if (l_cnt > l_max) {
+                       /* The RE is really long; get more space for it. */
+                       l_max = l_max + 256;
+                       l_pat_tmp = l_pat;
+                       l_pat = calloc(l_max + 2, sizeof(char));
+                       if (l_pat == NULL) {
+                               *errnum = -3;
+                               strcpy(help_msg, "out of memory error");
+                               return (NULL);
+                       }
+                       bcopy(l_pat_tmp, l_pat, l_cnt);
+                       free(l_pat_tmp);
+               }
+               l_cnt++;
+       }
+       l_pat[l_cnt] = '\0';
+       *errnum = 0;
+       /*
+        * Send back the pattern.  l_pat[0] has the delimiter in it so the RE
+        * really starts at l_pat[1]. It's done this way for the special forms
+        * of 's' (substitute).
+        */
+       return (l_pat);
+}
index 649b58b..f81fd23 100644 (file)
@@ -9,53 +9,57 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)i.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)i.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h" 
 #include "ed.h" 
+#include "extern.h"
 
 /*
  * Set things up for the central input routine to correctly place
  * the text as per the insert command.
  */
 
 /*
  * Set things up for the central input routine to correctly place
  * the text as per the insert command.
  */
-
 void
 i(inputt, errnum)
 void
 i(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 #ifdef POSIX
 {
 #ifdef POSIX
-  LINE *l_address;
+       LINE *l_address;
 #endif
 
 #endif
 
-  if ((End_default == 1) && (current != NULL))
-    start = End = current->above;
-  else
-    {
-      if (End == NULL)
-        {
-          strcpy(help_msg, "illegal address for command i");
-          *errnum = -1;
-          return;
-        }
-      else
-        End = End->above;
-    }
-  start_default = End_default = 0;
+       if ((End_default == 1) && (current != NULL))
+               start = End = current->above;
+       else {
+               if (End == NULL) {
+                       strcpy(help_msg, "illegal address for command i");
+                       *errnum = -1;
+                       return;
+               } else
+                       End = End->above;
+       }
+       start_default = End_default = 0;
 #ifdef POSIX
 #ifdef POSIX
-  l_address = End;
+       l_address = End;
 #endif
 
 #endif
 
-  if (sigint_flag)
-    SIGINT_ACTION;
-  /* 'i' is just a variation on 'a': completely true with BSD; with POSIX we
-   * have to fake the location of "current" in a special case.
-   */
-  a(inputt, errnum);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       /*
+        * 'i' is just a variation on 'a': completely true with BSD; with
+        * POSIX we have to fake the location of "current" in a special case.
+        */
+       a(inputt, errnum);
 #ifdef POSIX
 #ifdef POSIX
-  if (l_address->above)
-    current = l_address->below;
+       if (l_address->above)
+               current = l_address->below;
 #endif
 #endif
-} /* end-i */
+}
index aeb509d..d023eb2 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)input_lines.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)input_lines.c      5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "ed.h"
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
+#include "ed.h"
+#include "extern.h"
 
 /*
  * This central function gets text from some file, which can (and most
  * oft is) stdin. This flexability allows any text inputing function
  * to use it.
  */
 
 /*
  * This central function gets text from some file, which can (and most
  * oft is) stdin. This flexability allows any text inputing function
  * to use it.
  */
-
 long
 input_lines(fp, errnum)
 long
 input_lines(fp, errnum)
-
-FILE *fp;
-int *errnum;
-
+       FILE *fp;
+       int *errnum;
 {
 {
-  long l_ttl=0;
-  register long l_nn=0;
-  register int l_ss=ss;
-  LINE *l_temp_line, *l_temp1;
-  register char *l_text=text;
-  char *l_text2;
-  int l_nn_max=nn_max;
-
-  if (End_default)
-    start = current;
-  else
-    start = End;
-  start_default = End_default = 0;
-  /* start==NULL means line 0 which is legal for this function only */
+       register long l_nn = 0;
+       register int l_ss = ss;
+       register char *l_text = text;
+       LINE *l_temp_line, *l_temp1;
+       long l_ttl = 0;
+       int l_nn_max = nn_max;
+       char *l_text2;
 
 
-  nn_max_end = l_temp_line = start;
-  if (start == NULL)
-    {
-      l_temp1 = top;
-      u_add_stk(&(top->above));
-    }
-  else
-    {
-      u_add_stk(&(start->below));
-      l_temp1 = start->below;
-    }
+       if (End_default)
+               start = current;
+       else
+               start = End;
+       start_default = End_default = 0;
 
 
-  while (1)
-  {
-    if ((l_ss=getc(fp)) == EOF)
-      break; /* if NULL or bit-8 high not text; chuck */
-    if ((!l_ss) || (l_ss > 127))
-      continue;
-    if (sigint_flag)
-      goto point;
-    l_text[l_nn++] = (char)l_ss;
-    if (l_ss == '\n')
-      {
-       l_text[l_nn-1] = '\0';
-       if ((l_nn == 2) && (l_text[0] == '.') && add_flag)
-         break;
-       nn_max_end = (LINE *)malloc(sizeof(LINE));
-       if (nn_max_end == NULL)
-         {
-           *errnum = -1;
-           strcpy(help_msg, "out of memory error");
-           return(0L);
-         }
-       (nn_max_end->len) = l_nn - 1;
-       (nn_max_end->handle) = add_line(l_text, l_nn-1);
-       (nn_max_end->above) = l_temp_line;
-       (nn_max_end->below) = NULL;
-       if (l_temp_line)
-         (l_temp_line->below) = nn_max_end;
-       else
-         top = nn_max_end;
-       l_temp_line = nn_max_end;
+       /* start == NULL means line 0 which is legal for this function only. */
+       nn_max_end = l_temp_line = start;
+       if (start == NULL) {
+               l_temp1 = top;
+               u_add_stk(&(top->above));
+       } else {
+               u_add_stk(&(start->below));
+               l_temp1 = start->below;
+       }
 
 
-       l_ttl += l_nn;
-       l_nn = 0;
-      }
-    else if (l_nn > l_nn_max)
-           {
-             l_nn_max += 512;
-             nn_max = l_nn_max;
-             l_text2 = l_text;
-             l_text = text = (char *)calloc(l_nn_max+2, sizeof(char));
-             if (text == NULL)
-               {
-                 *errnum = -1;
-                 strcpy(help_msg, "out of memory error");
-                 return(0L);
-               }
-             bcopy(l_text2, l_text, l_nn);
-             free(l_text2);
-           }
-  } /* end-while */
+       for (;;) {
+               /* If NULL or bit-8 high not text; chuck. */
+               if ((l_ss = getc(fp)) == EOF)
+                       break;
+               if ((!l_ss) || (l_ss > 127))
+                       continue;
+               if (sigint_flag)
+                       goto point;
+               l_text[l_nn++] = (char) l_ss;
+               if (l_ss == '\n') {
+                       l_text[l_nn - 1] = '\0';
+                       if ((l_nn == 2) && (l_text[0] == '.') && add_flag)
+                               break;
+                       nn_max_end = malloc(sizeof(LINE));
+                       if (nn_max_end == NULL) {
+                               *errnum = -1;
+                               strcpy(help_msg, "out of memory error");
+                               return (0L);
+                       }
+                       (nn_max_end->len) = l_nn - 1;
+                       (nn_max_end->handle) = add_line(l_text, l_nn - 1);
+                       (nn_max_end->above) = l_temp_line;
+                       (nn_max_end->below) = NULL;
+                       if (l_temp_line)
+                               (l_temp_line->below) = nn_max_end;
+                       else
+                               top = nn_max_end;
+                       l_temp_line = nn_max_end;
 
 
-point:
-  current = nn_max_end;
-  if (current == NULL)
-    current == top;
-  if (l_temp1 == NULL)
-    bottom = nn_max_end;
-  else if (nn_max_end != NULL)
-    {
-      (nn_max_end->below) = l_temp1;
-      u_add_stk(&(l_temp1->above));
-      (l_temp1->above) = nn_max_end;
-    }
+                       l_ttl += l_nn;
+                       l_nn = 0;
+               } else
+                       if (l_nn > l_nn_max) {
+                               l_nn_max += 512;
+                               nn_max = l_nn_max;
+                               l_text2 = l_text;
+                               l_text = text =
+                                   calloc(l_nn_max + 2, sizeof(char));
+                               if (text == NULL) {
+                                       *errnum = -1;
+                                       strcpy(help_msg, "out of memory error");
+                                       return (0L);
+                               }
+                               bcopy(l_text2, l_text, l_nn);
+                               free(l_text2);
+                       }
+       }
 
 
-  change_flag = 1;
-  *errnum = 1;
-  ss = l_ss;
-  return(l_ttl);
-} /* end-input_lines */
+point: current = nn_max_end;
+       if (current == NULL)
+               current = top;
+       if (l_temp1 == NULL)
+               bottom = nn_max_end;
+       else
+               if (nn_max_end != NULL) {
+                       (nn_max_end->below) = l_temp1;
+                       u_add_stk(&(l_temp1->above));
+                       (l_temp1->above) = nn_max_end;
+               }
+       change_flag = 1;
+       *errnum = 1;
+       ss = l_ss;
+       return (l_ttl);
+}
index d4333bb..4314ec3 100644 (file)
@@ -9,10 +9,20 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)j.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)j.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h" 
 #include "ed.h" 
+#include "extern.h"
 
 /*
  * Join the spec'd lines onto one line. Make the new line from the
 
 /*
  * Join the spec'd lines onto one line. Make the new line from the
@@ -21,141 +31,129 @@ static char sccsid[] = "@(#)j.c   5.1 (Berkeley) %G%";
 
 void
 j(inputt, errnum)
 
 void
 j(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  LINE *l_ptr, *l_temp_line;
-  char *l_temp1;
-  long l_ttl=0;
-
-  if (start_default && End_default)
-    {
-      start = current;
-      *errnum = 1;
-      if ((start->below) != NULL)
-        End = start->below;
-      else
-        return;
-    }
-  else if (start_default)
-    {
-      if (rol(inputt, errnum))
-        return;
-
-      if (End == NULL)
-        {
-          strcpy(help_msg, "bad address");
-          *errnum = -1;
-        }
-      else
-        {
+       LINE *l_ptr, *l_temp_line;
+       long l_ttl = 0;
+       char *l_temp1;
+
+       if (start_default && End_default) {
+               start = current;
+               *errnum = 1;
+               if ((start->below) != NULL)
+                       End = start->below;
+               else
+                       return;
+       } else
+               if (start_default) {
+                       if (rol(inputt, errnum))
+                               return;
+
+                       if (End == NULL) {
+                               strcpy(help_msg, "bad address");
+                               *errnum = -1;
+                       } else {
 #ifdef BSD
 #ifdef BSD
-          /* for BSD a 'j' with one address sets "current" to that line */
-          if (start)
-            current = start;
+                               /*
+                                * For BSD a 'j' with one address sets
+                                * "current" to that line
+                                */
+                               if (start)
+                                       current = start;
 #endif
 #endif
-          *errnum = 1;
-        }
-      return;
-    }
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      ungetc('\n', inputt);
-      return;
-    }
-  start_default = End_default = 0;
-  if (sigint_flag)
-    SIGINT_ACTION;
-
-  if (rol(inputt, errnum))
-    return;
-
-  if (g_flag == 0)
-    u_clr_stk();
-  u_set = 1; /* set for d */
-
-  /* figure out what the length of the joined lines will be */
-  for (l_ptr=start; l_ptr!=(End->below); l_ptr=(l_ptr->below) )
-     l_ttl = l_ptr->len + l_ttl;
-
-  if (l_ttl > nn_max)
-    {
-      /* the new line is bigger than any so far, so make more space */
-      free(text);
-      nn_max = l_ttl;
-      text = (char *)calloc(l_ttl+2, sizeof(char));
-      if (text == NULL)
-        {
-          *errnum = -1;
-          strcpy(help_msg, "out of memory error");
-          return;
-        }
-    }
-
-  if (sigint_flag)
-    SIGINT_ACTION;
-  l_temp1 = (char *)calloc(l_ttl+2, sizeof(char));
-  if (text == NULL)
-    {
-      *errnum = -1;
-      strcpy(help_msg, "out of memory error");
-      return;
-    }
-  l_temp1[0] = '\0';
-
-  l_ptr = start;
-  while (1)
-     {
-       /* get each line and catenate */
-       if (sigint_flag)
-         goto point;
-       get_line(l_ptr->handle, l_ptr->len);
-       strcat(l_temp1, text);
-       l_ptr = l_ptr->below;
-       if (l_ptr == End->below)
-         break;
-     }
-
-  l_temp_line = (LINE *)malloc(sizeof(LINE));
-  if (text == NULL)
-    {
-      *errnum = -1;
-      strcpy(help_msg, "out of memory error");
-      return;
-    }
-  (l_temp_line->len) = l_ttl;
-  /* add the new line to the buffer */
-  (l_temp_line->handle) = add_line(l_temp1, l_ttl);
-  if (start == top)
-    {
-      top = l_temp_line;
-      (l_temp_line->above) = NULL;
-    }
-  else
-    {
-      (l_temp_line->above) = start->above;
-      u_add_stk(&(l_temp_line->above->below));
-      (l_temp_line->above->below) = l_temp_line;
-    }
-  (l_temp_line->below) = start;
-  u_add_stk(&(start->above));
-  (start->above) = l_temp_line;
-
-  ungetc(ss, inputt);
-  /* delete the lines used to make the joined line */
-  d(inputt, errnum);
-  if (*errnum < 0)
-    return;
-  *errnum = 0;
-  current = l_temp_line;
-
-  *errnum = 1;
-
-  point:
-  u_set = 0;
-  free(l_temp1);
-} /* end-j */
+                               *errnum = 1;
+                       }
+                       return;
+               }
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               ungetc('\n', inputt);
+               return;
+       }
+       start_default = End_default = 0;
+       if (sigint_flag)
+               SIGINT_ACTION;
+
+       if (rol(inputt, errnum))
+               return;
+
+       if (g_flag == 0)
+               u_clr_stk();
+       u_set = 1;              /* set for d */
+
+       /* Figure out what the length of the joined lines will be. */
+       for (l_ptr = start; l_ptr != (End->below); l_ptr = (l_ptr->below))
+               l_ttl = l_ptr->len + l_ttl;
+
+       if (l_ttl > nn_max) {
+               /*
+                * The new line is bigger than any so far, so make more
+                * space.
+                */
+               free(text);
+               nn_max = l_ttl;
+               text = calloc(l_ttl + 2, sizeof(char));
+               if (text == NULL) {
+                       *errnum = -1;
+                       strcpy(help_msg, "out of memory error");
+                       return;
+               }
+       }
+       if (sigint_flag)
+               SIGINT_ACTION;
+       l_temp1 = calloc(l_ttl + 2, sizeof(char));
+       if (text == NULL) {
+               *errnum = -1;
+               strcpy(help_msg, "out of memory error");
+               return;
+       }
+       l_temp1[0] = '\0';
+
+       l_ptr = start;
+       for (;;) {
+               /* Get each line and catenate. */
+               if (sigint_flag)
+                       goto point;
+               get_line(l_ptr->handle, l_ptr->len);
+               strcat(l_temp1, text);
+               l_ptr = l_ptr->below;
+               if (l_ptr == End->below)
+                       break;
+       }
+
+       l_temp_line = malloc(sizeof(LINE));
+       if (text == NULL) {
+               *errnum = -1;
+               strcpy(help_msg, "out of memory error");
+               return;
+       }
+       (l_temp_line->len) = l_ttl;
+       /* Add the new line to the buffer. */
+       (l_temp_line->handle) = add_line(l_temp1, l_ttl);
+       if (start == top) {
+               top = l_temp_line;
+               (l_temp_line->above) = NULL;
+       } else {
+               (l_temp_line->above) = start->above;
+               u_add_stk(&(l_temp_line->above->below));
+               (l_temp_line->above->below) = l_temp_line;
+       }
+       (l_temp_line->below) = start;
+       u_add_stk(&(start->above));
+       (start->above) = l_temp_line;
+
+       ungetc(ss, inputt);
+       /* Delete the lines used to make the joined line. */
+       d(inputt, errnum);
+       if (*errnum < 0)
+               return;
+       *errnum = 0;
+       current = l_temp_line;
+
+       *errnum = 1;
+
+point: u_set = 0;
+       free(l_temp1);
+}
index fdd80d6..23129d2 100644 (file)
@@ -9,10 +9,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)k.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)k.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h" 
 #include "ed.h" 
+#include "extern.h"
 
 /*
  * This the mark command (k); see ed(1).
 
 /*
  * This the mark command (k); see ed(1).
@@ -20,95 +29,82 @@ static char sccsid[] = "@(#)k.c     5.1 (Berkeley) %G%";
 
 void
 set_mark(inputt, errnum)
 
 void
 set_mark(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_mark;
-
-  l_mark = getc(inputt);
-  if (End_default == 1)
-    End = current;
-  if (End == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      ungetc('\n', inputt);
-      return;
-    }
-  start_default = End_default = 0;
-
-  /* the marks have to be "a" to "z" (inclusive); that is, ye olde
-   * portable character set (ASCII) lower case alphabet
-   */
-  if ((l_mark < 97) || (l_mark > 122) || (End == NULL))
-    {
-      strcpy(help_msg, "illegal mark character");
-      *errnum = -1;
-      return;
-    }
-  l_mark = l_mark - 97;
-  (mark_matrix[l_mark].address) = End;
-
-  if (rol(inputt, errnum))
-    return;
-
-  *errnum = 1;
-} /* end-set_mark */
+       int l_mark;
+
+       l_mark = getc(inputt);
+       if (End_default == 1)
+               End = current;
+       if (End == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               ungetc('\n', inputt);
+               return;
+       }
+       start_default = End_default = 0;
+
+       /*
+        * The marks have to be "a" to "z" (inclusive); that is, ye olde
+        * portable character set (ASCII) lower case alphabet.
+        */
+       if ((l_mark < 97) || (l_mark > 122) || (End == NULL)) {
+               strcpy(help_msg, "illegal mark character");
+               *errnum = -1;
+               return;
+       }
+       l_mark = l_mark - 97;
+       (mark_matrix[l_mark].address) = End;
+
+       if (rol(inputt, errnum))
+               return;
+
+       *errnum = 1;
+}
 
 
 /*
  * This gets the address of a marked line.
  */
 
 
 /*
  * This gets the address of a marked line.
  */
-
-LINE
-*get_mark(errnum)
-
-int *errnum;
-
+LINE *
+get_mark(errnum)
+       int *errnum;
 {
 {
-  int l_mark;
-
-  l_mark = getchar();
-  /* ditto above comment */
-  if ((l_mark < 97) || (l_mark > 122))
-    {
-      strcpy(help_msg, "illegal mark character");
-      *errnum = -1;
-      return(NULL);
-    }
+       int l_mark;
 
 
-  l_mark = l_mark - 97;
-  *errnum = 0;
-  return( mark_matrix[l_mark].address );
-} /* end-get_mark */
+       l_mark = getchar();
+       /* Ditto above comment. */
+       if ((l_mark < 97) || (l_mark > 122)) {
+               strcpy(help_msg, "illegal mark character");
+               *errnum = -1;
+               return (NULL);
+       }
+       l_mark = l_mark - 97;
+       *errnum = 0;
+       return (mark_matrix[l_mark].address);
+}
 
 
 /*
  * This is for the restoration of marks during an undo.
  */
 
 
 /*
  * This is for the restoration of marks during an undo.
  */
-
 void
 ku_chk(begi, fini, val)
 void
 ku_chk(begi, fini, val)
-
-LINE *begi, *fini, *val;
-
+       LINE *begi, *fini, *val;
 {
 {
-  register int l_cnt;
-  LINE *l_midd;
-
-  l_midd = begi;
-  while (l_midd != NULL)
-       {
-         for (l_cnt=0; l_cnt<26; l_cnt++)
-            if (mark_matrix[l_cnt].address == l_midd)
-              {
-                u_add_stk(&(mark_matrix[l_cnt].address));
-                (mark_matrix[l_cnt].address) = val;
-              }
-         if (l_midd == fini)
-           break;
-         l_midd = l_midd->below;
-       } /* end-while */
-} /* end-ku_chk */
+       register int l_cnt;
+       LINE *l_midd;
+
+       l_midd = begi;
+       while (l_midd != NULL) {
+               for (l_cnt = 0; l_cnt < 26; l_cnt++)
+                       if (mark_matrix[l_cnt].address == l_midd) {
+                               u_add_stk(&(mark_matrix[l_cnt].address));
+                               (mark_matrix[l_cnt].address) = val;
+                       }
+               if (l_midd == fini)
+                       break;
+               l_midd = l_midd->below;
+       }
+}
index a6380a1..83399c8 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)l.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)l.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This is the list command. It's not wrapped in with n and p because
  * of the unambiguous printing needed.
  */
 
 /*
  * This is the list command. It's not wrapped in with n and p because
  * of the unambiguous printing needed.
  */
-
 void
 l(inputt, errnum)
 void
 l(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_cnt, l_len=1;
-
-  if (start_default && End_default)
-    start = End = current;
-  else if (start_default)
-    start = End;
+       int l_cnt, l_len = 1;
 
 
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
 
 
-  if (rol(inputt, errnum))  /* for "command-suffix pairs" */
-    return;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
 
 
-  current = start;
-  while (1)
-       {
-         /* print out the line character-by-character and split the line
-          * when line length is at line_length.
-          */
-         if (sigint_flag)
-           SIGINT_ACTION;
-         if (current == NULL)
-           break;
-         get_line(current->handle, current->len);
-         for (l_cnt=0; l_cnt<current->len; l_cnt++)
-            {
-              /* check if line needs to be broken first */
-              if ((l_len)%line_length == 0)
-                putchar('\n');
-              /* print out the next character */
-              if (text[l_cnt] == '\b') /* backspace (cntl-H) */
-                fwrite("\\b", sizeof(char), 2, stdout);
-              else if (text[l_cnt] == '\t') /* horizontal tab */
-                fwrite("\\t", sizeof(char), 2, stdout);
-              else if (text[l_cnt] == '\n') /* newline, not that there is one */
-                fwrite("\\n", sizeof(char), 2, stdout);
-              else if (text[l_cnt] == '\v') /* vertical tab */
-                fwrite("\\v", sizeof(char), 2, stdout);
-              else if (text[l_cnt] == '\f') /* form feed */
-                fwrite("\\f", sizeof(char), 2, stdout);
-              else if (text[l_cnt] == '\r') /* return */
-                fwrite("\\r", sizeof(char), 2, stdout);
-              else if ((text[l_cnt] < 32) || (text[l_cnt] > 126)) /* not printable */
-/* 127 is del */
-                {
-                  putchar('\\');
-                  putchar(text[l_cnt]/64+'0');
-                  putchar(text[l_cnt]/8+'0');
-                  putchar(text[l_cnt]%8+'0');
-                  l_len += 2;
-                }
-              else if (text[l_cnt] == '\\')
-                fwrite("\\\\", sizeof(char), 2, stdout);
-              else
-                {
-                  l_len--;
-                  putchar(text[l_cnt]);
-                }
-              l_len += 2;
-            }
-         l_len = 1;
-         putchar('\n');
-         if (current == End)
-           break;
-         current = current->below;
-       } /* end-while */
+       if (rol(inputt, errnum))        /* For "command-suffix pairs". */
+               return;
 
 
-  *errnum = 1;
-} /* end-l */
+       current = start;
+       for (;;) {
+               /*
+                * Print out the line character-by-character and split the
+                * line when line length is at line_length.
+                */
+               if (sigint_flag)
+                       SIGINT_ACTION;
+               if (current == NULL)
+                       break;
+               get_line(current->handle, current->len);
+               for (l_cnt = 0; l_cnt < current->len; l_cnt++, l_len += 2) {
+                       /* Check if line needs to be broken first. */
+                       if ((l_len) % line_length == 0)
+                               putchar('\n');
+                       else switch (text[l_cnt]) {
+                       case '\b':      /* backspace (cntl-H) */
+                               fwrite("\\b", sizeof(char), 2, stdout);
+                               break;
+                       case '\t':      /* horizontal tab */
+                               fwrite("\\t", sizeof(char), 2, stdout);
+                               break;
+                       case '\n':      /* newline (not that there is one). */
+                               fwrite("\\n", sizeof(char), 2, stdout);
+                               break;
+                       case '\v':      /* vertical tab */
+                               fwrite("\\v", sizeof(char), 2, stdout);
+                               break;
+                       case '\f':      /* form feed */
+                               fwrite("\\f", sizeof(char), 2, stdout);
+                               break;
+                       case '\r':      /* return */
+                               fwrite("\\r", sizeof(char), 2, stdout);
+                               break;
+                       default:
+                               if ((text[l_cnt] < 32) ||
+                                   (text[l_cnt] > 126)) {
+                                       putchar('\\');
+                                       putchar(text[l_cnt] / 64 + '0');
+                                       putchar(text[l_cnt] / 8 + '0');
+                                       putchar(text[l_cnt] % 8 + '0');
+                                       l_len += 2;
+                               } else if (text[l_cnt] == '\\')
+                                       fwrite("\\\\", sizeof(char), 2, stdout);
+                               else {
+                                       l_len--;
+                                       putchar(text[l_cnt]);
+                               }
+                               break;
+                       }
+               }
+               l_len = 1;
+               putchar('\n');
+               if (current == End)
+                       break;
+               current = current->below;
+       }
+       *errnum = 1;
+}
index 1a2cb77..a779ab9 100644 (file)
@@ -9,37 +9,41 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)line_number.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)line_number.c      5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Converts a LINE to a line number (int) that can be printed to
  * the device the user is at. Used by n.
  */
 
 /*
  * Converts a LINE to a line number (int) that can be printed to
  * the device the user is at. Used by n.
  */
-
 int
 line_number(line_addr)
 int
 line_number(line_addr)
-
-LINE *line_addr;
-
+       LINE *line_addr;
 {
 {
-  int l_cnt=1; /* yes! =1 */
-  LINE *l_temp1;
-
-  l_temp1 = top;
-  if ((line_addr == NULL) && (top == NULL))
-    return(0);
-
-  while (1)
-       {
-         if (sigint_flag)
-           SIGINT_ACTION;
-         if (line_addr == l_temp1)
-           break;
-         l_temp1 = l_temp1->below;
-         l_cnt++;
-       } /* end-while */
-  return(l_cnt);
-} /* end-line_number */
+       LINE *l_temp1;
+       int l_cnt = 1;          /* yes! =1 */
+
+       l_temp1 = top;
+       if ((line_addr == NULL) && (top == NULL))
+               return (0);
+
+       for (;;) {
+               if (sigint_flag)
+                       SIGINT_ACTION;
+               if (line_addr == l_temp1)
+                       break;
+               l_temp1 = l_temp1->below;
+               l_cnt++;
+       }
+       return (l_cnt);
+}
index 8c85e30..681106a 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)m.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)m.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Move the specified lines to the new location. It's quick 'cause
  * just a couple of pointers are redirected.
  */
 
 /*
  * Move the specified lines to the new location. It's quick 'cause
  * just a couple of pointers are redirected.
  */
-
 void
 m(inputt, errnum)
 void
 m(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  LINE *l_dest, *l_old_top, *l_old_bottom;
-
-  /* set l_dest here */
-  if (((ss=getc(inputt)) != '\n') && (ss != EOF))
-    {
-      while (1)
-           {
-             if (ss != ' ')
-               {
-                 ungetc(ss, inputt);
-                 break;
-               }
-             ss = getc(inputt);
-           }
-      l_dest = address_conv(NULL, inputt, errnum);
-    }
-  else
-    (ungetc(ss, inputt), *errnum = -1);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum < 0)
-    {
-      strcpy(help_msg, "bad destination address");
-      return;
-    } /* end-if */
-  *errnum = 0;
-  if (rol(inputt, errnum))
-    return;
-
-  if (start_default && End_default)
-    start = End = current;
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
-  if (sigint_flag)
-    SIGINT_ACTION;
-
-  /* do some address checking */
-  if ((l_dest) && ((l_dest == start) || (address_check(l_dest, start) == -1)) && (address_check(End, l_dest) == -1))
-    {
-      ungetc(ss, inputt);
-      *errnum = -1;
-      strcpy(help_msg, "destination address in address range");
-      return;
-    }
-
-  change_flag = 1;
-  if (g_flag == 0)
-    u_clr_stk();
-
-  /* some more address checking. These are "legal" command constructions
-   * but are kind-a useless since the buffer doesn't change */
-  if ((start == l_dest) || (End == l_dest))
-    return;
-  if ((start == top) && (End == bottom))
-    return;
-  if ((start == top) && (l_dest == NULL))
-    return;
-
-  l_old_top = top;
-  l_old_bottom = bottom;
-
-  if (start == top)
-    {
-      top = End->below;
-      u_add_stk(&(End->below->above));
-      top->above = NULL;
-    }
-  else if (End == bottom)
-    {
-      bottom = start->above;
-      u_add_stk(&(start->above->below));
-      bottom->below = NULL;
-    }
-  else
-    {
-      u_add_stk(&(start->above->below));
-      start->above->below = End->below;
-      u_add_stk(&(End->below->above));
-      End->below->above = start->above;
-    }
-
-  if (l_dest == NULL)
-    {
-      u_add_stk(&(start->above));
-      start->above = NULL;
-      u_add_stk(&(End->below));
-      End->below = l_old_top;
-      u_add_stk(&(l_old_top->above));
-      l_old_top->above = End;
-      top = start;
-    }
-  else if (l_dest == l_old_bottom)
-    {
-      u_add_stk(&(End->below));
-      End->below = NULL;
-      u_add_stk(&(start->above));
-      start->above = l_dest;
-      u_add_stk(&(l_dest->below));
-      l_dest->below = start;
-      bottom = End;
-    }
-  else
-    {
-      u_add_stk(&(start->above));
-      start->above = l_dest;
-      u_add_stk(&(End->below));
-      End->below = l_dest->below;
-      u_add_stk(&(l_dest->below->above));
-      l_dest->below->above = End;
-      u_add_stk(&(l_dest->below));
-      l_dest->below = start;
-    }
-
-  if (l_dest)
-    l_dest->below = start;
-  current = start;
-
-  *errnum = 1;
-} /* end-m */
+       LINE *l_dest, *l_old_top, *l_old_bottom;
+
+       /* Set l_dest here. */
+       if (((ss = getc(inputt)) != '\n') && (ss != EOF)) {
+               for (;;) {
+                       if (ss != ' ') {
+                               ungetc(ss, inputt);
+                               break;
+                       }
+                       ss = getc(inputt);
+               }
+               l_dest = address_conv(NULL, inputt, errnum);
+       } else
+               (ungetc(ss, inputt), *errnum = -1);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum < 0) {
+               strcpy(help_msg, "bad destination address");
+               return;
+       }
+       *errnum = 0;
+       if (rol(inputt, errnum))
+               return;
+
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
+       if (sigint_flag)
+               SIGINT_ACTION;
+
+       /* Do some address checking. */
+       if ((l_dest) && ((l_dest == start) ||
+           (address_check(l_dest, start) == -1)) &&
+           (address_check(End, l_dest) == -1)) {
+               ungetc(ss, inputt);
+               *errnum = -1;
+               strcpy(help_msg, "destination address in address range");
+               return;
+       }
+       change_flag = 1;
+       if (g_flag == 0)
+               u_clr_stk();
+
+       /*
+        * Some more address checking. These are "legal" command constructions
+        * but are kind-a useless since the buffer doesn't change.
+        */
+       if ((start == l_dest) || (End == l_dest))
+               return;
+       if ((start == top) && (End == bottom))
+               return;
+       if ((start == top) && (l_dest == NULL))
+               return;
+
+       l_old_top = top;
+       l_old_bottom = bottom;
+
+       if (start == top) {
+               top = End->below;
+               u_add_stk(&(End->below->above));
+               top->above = NULL;
+       } else
+               if (End == bottom) {
+                       bottom = start->above;
+                       u_add_stk(&(start->above->below));
+                       bottom->below = NULL;
+               } else {
+                       u_add_stk(&(start->above->below));
+                       start->above->below = End->below;
+                       u_add_stk(&(End->below->above));
+                       End->below->above = start->above;
+               }
+
+       if (l_dest == NULL) {
+               u_add_stk(&(start->above));
+               start->above = NULL;
+               u_add_stk(&(End->below));
+               End->below = l_old_top;
+               u_add_stk(&(l_old_top->above));
+               l_old_top->above = End;
+               top = start;
+       } else
+               if (l_dest == l_old_bottom) {
+                       u_add_stk(&(End->below));
+                       End->below = NULL;
+                       u_add_stk(&(start->above));
+                       start->above = l_dest;
+                       u_add_stk(&(l_dest->below));
+                       l_dest->below = start;
+                       bottom = End;
+               } else {
+                       u_add_stk(&(start->above));
+                       start->above = l_dest;
+                       u_add_stk(&(End->below));
+                       End->below = l_dest->below;
+                       u_add_stk(&(l_dest->below->above));
+                       l_dest->below->above = End;
+                       u_add_stk(&(l_dest->below));
+                       l_dest->below = start;
+               }
+
+       if (l_dest)
+               l_dest->below = start;
+       current = start;
+
+       *errnum = 1;
+}
index 4129862..e083aac 100644 (file)
@@ -9,10 +9,21 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This is where all of the "global" variables are declared. They are
 
 /*
  * This is where all of the "global" variables are declared. They are
@@ -23,14 +34,7 @@ int nn_max, nn_max_flag, start_default, End_default, address_flag;
 int zsnum, filename_flag, add_flag=0;
 int help_flag=0;
 
 int zsnum, filename_flag, add_flag=0;
 int help_flag=0;
 
-#ifdef STDIO
-FILE *fhtmp;
-int file_seek;
-#endif
-
-#ifdef DBI
 DB *dbhtmp;
 DB *dbhtmp;
-#endif
 
 LINE *nn_max_start, *nn_max_end;
 
 
 LINE *nn_max_start, *nn_max_end;
 
@@ -55,472 +59,486 @@ int ss; /* for the getc() */
 int explain_flag=1, g_flag=0, GV_flag=0, printsfx=0;
 long change_flag=0L;
 int line_length;
 int explain_flag=1, g_flag=0, GV_flag=0, printsfx=0;
 long change_flag=0L;
 int line_length;
-jmp_buf ctrl_position; /* for SIGnal handling */
+jmp_buf ctrl_position;                 /* For SIGnal handling. */
 int sigint_flag, sighup_flag, sigspecial;
 
 int sigint_flag, sighup_flag, sigspecial;
 
-/* SIGINT is never turned off. We flag it happened and then pay attention
- * to it at certain logical locations in the code
- * we don't do more here cause some of our buffer pointer's may be in
- * an inbetween state at the time of the SIGINT. So we flag it happened,
- * let the local fn handle it and do a jump back to the cmd_loop
- */
-sigint_handler()
-
-{
-  sigint_flag = 1;
-  if (sigspecial)  /* unstick when SIGINT on read(stdin) */
-    SIGINT_ACTION;
-} /* end-sigint_handler */
-
-sighup_handler()
+static void sigint_handler __P((int));
+static void sighup_handler __P((int));
 
 
+/*
+ * Starts the whole show going. Set things up as the arguments spec
+ * in the shell and set a couple of the global variables.
+ *
+ * Note naming viol'n with errnum for consistancy.
+ */
+int
+main(argc, argv)
+       int argc;
+       char *argv[];
 {
 {
-  fprintf(stderr,"\n  SIGHUP \n");
-  sighup_flag = 1;
-  undo();
-  do_hup(); /* we shouldn't return from here */
-  SIGHUP_ACTION; /* it shouldn't get here */
-} /* end-sighup_handler */
+       int l_num, l_ret, errnum = 0, l_err = 0;
+       char *l_fnametmp, l_bp[1024], *l_term;
+
+       l_term = getenv("TERM");
+       l_ret = tgetent(l_bp, l_term);
+       if (l_ret < 1)
+               line_length = 78;       /* Reasonable number for all term's. */
+       else
+               if ((line_length = tgetnum("co") - 1) < 2)
+                       line_length = 78;
+
+       start = End = NULL;
+       top = bottom = NULL;
+       current = NULL;
+       nn_max_flag = 0;
+       nn_max_start = nn_max_end = NULL;
+       l_fnametmp = calloc(FILENAME_LEN, sizeof(char));
+       if (l_fnametmp == NULL)
+               ed_exit(4);
+       text = calloc(NN_MAX_START + 2, sizeof(char));
+       if (text == NULL)
+               ed_exit(4);
+       start_default = End_default = 0;
+       zsnum = 22;             /* for the 'z' command */
+       u_stk = NULL;
+       d_stk = NULL;
+       u_current = u_top = u_bottom = NULL;
+       u_set = 0;              /* for in d after a j */
+       filename_flag = 0;
+       filename_current = NULL;
+
+       l_num = 1;
+       for (;;) {
+               /* Process the command line options */
+               if (l_num >= argc)
+                       break;
+               switch (argv[l_num][0]) {
+               case '-':
+                       switch (argv[l_num][1]) {
+                       case '\0':      /* this is why 'getopt' not used */
+                       case 's':
+                               explain_flag = 0;
+                               break;
+                       case 'p':
+                               if (++l_num < argc) {
+                                       prompt_string =
+                                           calloc(strlen(argv[l_num]),
+                                           sizeof(char));
+                                       if (prompt_string == NULL)
+                                               ed_exit(4);
+                                       strcpy(prompt_string, argv[l_num]);
+                                       prompt_str_flg = 1;
+                                       break;
+                               }
+                               l_err = 1;
+                       default:
+                               l_err++;
+                               ed_exit(l_err);
+                       }
+                       break;
+               default:
+                       if (name_set)
+                               ed_exit(3);
+                       strcpy(l_fnametmp, argv[l_num]);
+                       filename_current = l_fnametmp;
+                       name_set = 1;
+                       if (prompt_str_flg)
+                               break;
+                       /* default ed prompt */
+                       prompt_string = (char *) calloc(3, sizeof(char));
+                       strcpy(prompt_string, "*");
+                       break;
+               }
+               l_num++;
+       }
+
+       start_up_flag = 1;
+       cmd_loop(stdin, &errnum);
+       /* NOTREACHED */
+}
 
 /*
 
 /*
- * the command loop. What the command is that the user has specified
+ * The command loop. What the command is that the user has specified
  * is determined here. This is not just for commands coming from
  * the terminal but any standard i/o stream; see the global commands.
  * Some of the commands are handled within here (i.e. 'H') while most
  * are handled in their own functions (as called).
  */
  * is determined here. This is not just for commands coming from
  * the terminal but any standard i/o stream; see the global commands.
  * Some of the commands are handled within here (i.e. 'H') while most
  * are handled in their own functions (as called).
  */
-
 void
 cmd_loop(inputt, errnum)
 void
 cmd_loop(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_last, l_jmp_flag;
-  LINE *l_tempp;
-
-  l_last = 0;
-
-  if (g_flag ==0) /* big, BIG trouble if we don't check! think. */
-    {
-      /* set the jump point for the signals */
-      l_jmp_flag = setjmp(ctrl_position);
-      signal(SIGINT, sigint_handler);
-      signal(SIGHUP, sighup_handler);
-      switch (l_jmp_flag)
-            {
-              case JMP_SET: break;
-              case INTERUPT: /* some general cleanup not specific to the jmp pt */
-                             sigint_flag = 0;
-                             GV_flag = 0; /* safest place to do these flags */
-                             g_flag = 0;
-                             printf("?\n");
-                             break;
-              case HANGUP: /* shouldn't get here. */
-                           break;
-              default: fprintf(stderr, "Signal jump problem\n");
-            }
-      /* only do this once! */
-      if (start_up_flag)
-        {
-          start_up_flag = 0;
-          /* simulate the 'e' at startup */
-          e2(inputt, errnum);
-        }
-    } /* end-if */
-
-  while (1)
-       {
-
-         if (prompt_str_flg == 1)
-           printf("%s", prompt_string);
-         sigspecial = 1;  /* see the SIGINT function above */
-         ss = getc(inputt);
-         sigspecial = 0;
-         *errnum = 0;
-         l_tempp = start = End = NULL;
-         start_default = End_default = 1;
-
-         while (1)
-         {
-         switch (ss)
-               {
-                 /* this isn't nice and alphabetical mainly because of
-                  * retrictions with 'G' and 'V' (see ed(1)).
-                  */
-                 case 'd': d(inputt, errnum);
-                           break;
-                 case 'e':
-                 case 'E': e(inputt, errnum);
-                           break;
-                 case 'f': f(inputt, errnum);
-                           break;
-                 case 'a': 
-                 case 'c':
-                 case 'i':
-                 case 'g':
-                 case 'G':
-                 case 'v':
-                 case 'V': if (GV_flag == 1)
-                             {
-                               strcpy(help_msg, "command `");
-                               strncat(help_msg, &ss, 1);
-                               strcat(help_msg, "' illegal in G/V");
-                               *errnum = -1;
-                               break;
-                             }
-                           switch (ss)
-                                 {
-                                   case 'a': a(inputt, errnum);
-                                             break;
-                                   case 'c': c(inputt, errnum);
-                                             break;
-                                   case 'i': i(inputt, errnum);
-                                             break;
-                                    default: g(inputt, errnum);
-                                 } /* end-switch */
-                           break;
-                 case 'h': if (rol(inputt, errnum))
-                             break;
-                           printf("%s\n", help_msg);
-                           *errnum = 1;
-                           break;
-                 case 'H': if (rol(inputt, errnum))
-                             break;
-                           if (help_flag == 0)
-                             {
-                               help_flag = 1;
-                               printf("%?: %s\n", help_msg);
-                             }
-                           else
-                             help_flag = 0;
-                           *errnum = 1;
-                           break;
-                 case 'j': j(inputt, errnum);
-                           break;
-                 case 'k': set_mark(inputt, errnum);
-                           break;
-                 case 'l': l(inputt, errnum);
-                           break;
-                 case 'm': m(inputt, errnum);
-                           break;
+       LINE *l_tempp;
+       int l_last, l_jmp_flag;
+
+       l_last = 0;
+
+       if (g_flag == 0) {      /* big, BIG trouble if we don't check! think. */
+               /* set the jump point for the signals */
+               l_jmp_flag = setjmp(ctrl_position);
+               signal(SIGINT, sigint_handler);
+               signal(SIGHUP, sighup_handler);
+               switch (l_jmp_flag) {
+               case JMP_SET:
+                       break;
+               /* Some general cleanup not specific to the jmp pt. */
+               case INTERUPT:
+                       sigint_flag = 0;
+                       GV_flag = 0;    /* safest place to do these flags */
+                       g_flag = 0;
+                       printf("?\n");
+                       break;
+               case HANGUP:            /* shouldn't get here. */
+                       break;
+               default:
+                       (void)fprintf(stderr, "Signal jump problem\n");
+               }
+               /* Only do this once! */
+               if (start_up_flag) {
+                       start_up_flag = 0;
+                       /* simulate the 'e' at startup */
+                       e2(inputt, errnum);
+               }
+       }
+       for (;;) {
+               if (prompt_str_flg == 1)
+                       (void)printf("%s", prompt_string);
+               sigspecial = 1; /* see the SIGINT function above */
+               ss = getc(inputt);
+               sigspecial = 0;
+               *errnum = 0;
+               l_tempp = start = End = NULL;
+               start_default = End_default = 1;
+
+               /*
+                * This isn't nice and alphabetical mainly because of
+                * restrictions with 'G' and 'V' (see ed(1)).
+                */
+               for (;;) {
+                       switch (ss) {
+                       case 'd':
+                               d(inputt, errnum);
+                               break;
+                       case 'e':
+                       case 'E':
+                               e(inputt, errnum);
+                               break;
+                       case 'f':
+                               f(inputt, errnum);
+                               break;
+                       case 'a':
+                       case 'c':
+                       case 'i':
+                       case 'g':
+                       case 'G':
+                       case 'v':
+                       case 'V':
+                               if (GV_flag == 1) {
+                                       (void)sprintf(help_msg,
+                                           "command `%c' illegal in G/V", ss);
+                                       *errnum = -1;
+                                       break;
+                               }
+                               switch (ss) {
+                               case 'a':
+                                       a(inputt, errnum);
+                                       break;
+                               case 'c':
+                                       c(inputt, errnum);
+                                       break;
+                               case 'i':
+                                       i(inputt, errnum);
+                                       break;
+                               default:
+                                       g(inputt, errnum);
+                               }
+                               break;
+                       case 'h':
+                               if (rol(inputt, errnum))
+                                       break;
+                               (void)printf("%s\n", help_msg);
+                               *errnum = 1;
+                               break;
+                       case 'H':
+                               if (rol(inputt, errnum))
+                                       break;
+                               if (help_flag == 0) {
+                                       help_flag = 1;
+                                       printf("%?: %s\n", help_msg);
+                               } else
+                                       help_flag = 0;
+                               *errnum = 1;
+                               break;
+                       case 'j':
+                               j(inputt, errnum);
+                               break;
+                       case 'k':
+                               set_mark(inputt, errnum);
+                               break;
+                       case 'l':
+                               l(inputt, errnum);
+                               break;
+                       case 'm':
+                               m(inputt, errnum);
+                               break;
 #ifdef POSIX
 #ifdef POSIX
-                           /* in POSIXland 'P' toggles the prompt */
-                 case 'P': if (rol(inputt, errnum))
-                             break;
-                           prompt_str_flg = prompt_str_flg?0:1;
-                           *errnum = 1;
-                           break;
+                               /* In POSIX-land 'P' toggles the prompt. */
+                       case 'P':
+                               if (rol(inputt, errnum))
+                                       break;
+                               prompt_str_flg = prompt_str_flg ? 0 : 1;
+                               *errnum = 1;
+                               break;
 #endif
 #endif
-                 case '\n': if (GV_flag == 1)
-                              return;
-                            ungetc(ss, inputt); /* for 'p' to consume */
-                            if ((current == bottom) && (End == NULL))
-                              {
-                                strcpy(help_msg, "at end of buffer");
-                                *errnum = -1;
-                                break;
-                              }
-                            current = current->below;
+                       case '\n':
+                               if (GV_flag == 1)
+                                       return;
+                               /* For 'p' to consume. */
+                               ungetc(ss, inputt);
+                               if ((current == bottom) && (End == NULL)) {
+                                       strcpy(help_msg, "at end of buffer");
+                                       *errnum = -1;
+                                       break;
+                               }
+                               current = current->below;
 #ifdef BSD
 #ifdef BSD
-                           /* in BSD 'P'=='p' */
-                 case 'P':
+                               /* In BSD 'P'=='p'. */
+                       case 'P':
 #endif
 #endif
-                 case 'p': p(inputt, errnum, 0);
-                           break;
-                 case 'n': p(inputt, errnum, 1);
-                           break;
-                           /* an EOF means 'q' unless we're still in the middle
-                            * of a global command, in whcih case it was just
-                            * the end of the command list found
-                            */
-                 case EOF: clearerr(inputt);
-                           if (g_flag > 0)
-                             return;
-                           ss = 'q';
-                 case 'q':
-                 case 'Q': q(inputt, errnum);
-                           break;
-                 case 'r': r(inputt, errnum);
-                           break;
-                 case 's': s(inputt, errnum);
-                           break;
-                 case 't': t(inputt, errnum);
-                           break;
-                 case 'u': u(inputt, errnum);
-                           break;
-                 case 'w':
-                 case 'W': w(inputt, errnum);
-                           break;
-                 case 'z': z(inputt, errnum);
-                           break;
-                 case '!': bang (inputt, errnum);
-                           break;
-                 case '=': equal (inputt, errnum);
-                           break;
-                         /* control of address forms from here down */
-                         /* It's a head-game to understand why ";" and ","
-                          * look as they do below, but a lot of it has to
-                          * do with ";" and "," being special address pair
-                          * forms themselves and the compatibility for
-                          * address "chains".
-                          */
-                 case ';': if ((End_default == 1) && (start_default == 1))
-                             {
-                               start = current;
-                               End = bottom;
-                               start_default = End_default = 0;
-                             }
-                           else
-                             {
-                               start = current = End;
-                               start_default = 0;
-                               End_default = 1;
-                             }
-                           l_tempp = NULL;
-                           break;
-                           /* note address ".,x" where x is a cmd is legal;
-                            * not a bug - for backward compatability */
-                 case ',': if ((End_default == 1) && (start_default == 1))
-                             {
-                               start = top;
-                               End = bottom;
-                               start_default = End_default = 0;
-                             }
-                           else
-                             {
-                               start = End;
-                               start_default = 0;
-                               End_default = 1;
-                             }
-                           l_tempp = NULL;
-                           break;
-                 case '%': if (End_default == 0)
-                             {
-                               strcpy(help_msg, "'%' is an address pair");
-                               *errnum = -1;
-                               break;
-                             }
-                           start = top;
-                           End = bottom;
-                           start_default = End_default = 0;
-                           l_tempp = NULL;
-                           break;
-                 case ' ': /* within address_conv=>l_last='+', foobar, but
-                              historical and now POSIX... */
-                           break;
-                 case '0':
-                 case '1':
-                 case '2':
-                 case '3':
-                 case '4':
-                 case '5':
-                 case '6':
-                 case '7':
-                 case '8':
-                 case '9':
-                 case '-':
-                 case '^':
-                 case '+':
-                 case '\'':
-                 case '$':
-                 case '?':
-                 case '/':
-                 case '.': ungetc(ss, inputt);
-                           if ((start_default == 0) && (End_default == 0))
-                             {
-                               strcpy(help_msg, "badly formed address");
-                               *errnum = -1;
-                               break;
-                             }
-                           ss = l_last;
-                           l_tempp = address_conv(l_tempp, inputt, errnum);
-                           if (*errnum < 0)
-                             break;
-                           End = l_tempp;
-                           End_default = 0;
-                           if (start_default == 0)
-                             *errnum = address_check(start, End);
-                           break;
-                 default: *errnum = -1;
-                          strcpy(help_msg, "unknown command");
-                          break;
-               } /* end-switch(ss) */
+                       case 'p':
+                               p(inputt, errnum, 0);
+                               break;
+                       case 'n':
+                               p(inputt, errnum, 1);
+                               break;
+                       /*
+                        * An EOF means 'q' unless we're still in the middle
+                        * of a global command, in which case it was just the
+                        * end of the command list found.
+                        */
+                       case EOF:
+                               clearerr(inputt);
+                               if (g_flag > 0)
+                                       return;
+                               ss = 'q';
+                       case 'q':
+                       case 'Q':
+                               q(inputt, errnum);
+                               break;
+                       case 'r':
+                               r(inputt, errnum);
+                               break;
+                       case 's':
+                               s(inputt, errnum);
+                               break;
+                       case 't':
+                               t(inputt, errnum);
+                               break;
+                       case 'u':
+                               u(inputt, errnum);
+                               break;
+                       case 'w':
+                       case 'W':
+                               w(inputt, errnum);
+                               break;
+                       case 'z':
+                               z(inputt, errnum);
+                               break;
+                       case '!':
+                               bang(inputt, errnum);
+                               break;
+                       case '=':
+                               equal(inputt, errnum);
+                               break;
+                       /*
+                        * Control of address forms from here down.
+                        *
+                        * It's a head-game to understand why ";" and "," look
+                        * as they do below, but a lot of it has to do with ";"
+                        * and "," being special address pair forms themselves
+                        * and the compatibility for address "chains".
+                        */
+                       case ';':
+                               if (End_default == 1 && start_default == 1) {
+                                       start = current;
+                                       End = bottom;
+                                       start_default = End_default = 0;
+                               } else {
+                                       start = current = End;
+                                       start_default = 0;
+                                       End_default = 1;
+                               }
+                               l_tempp = NULL;
+                               break;
+                       /*
+                        * Note address ".,x" where x is a cmd is legal; not a
+                        * bug - for backward compatability.
+                        */
+                       case ',':
+                               if (End_default == 1 && start_default == 1) {
+                                       start = top;
+                                       End = bottom;
+                                       start_default = End_default = 0;
+                               } else {
+                                       start = End;
+                                       start_default = 0;
+                                       End_default = 1;
+                               }
+                               l_tempp = NULL;
+                               break;
+                       case '%':
+                               if (End_default == 0) {
+                                       strcpy(help_msg,
+                                           "'%' is an address pair");
+                                       *errnum = -1;
+                                       break;
+                               }
+                               start = top;
+                               End = bottom;
+                               start_default = End_default = 0;
+                               l_tempp = NULL;
+                               break;
+                       /*
+                        * Within address_conv => l_last = '+', foobar, but
+                        * historical and now POSIX...
+                        */
+                       case ' ':
+                               break;
+                       case '0':
+                       case '1':
+                       case '2':
+                       case '3':
+                       case '4':
+                       case '5':
+                       case '6':
+                       case '7':
+                       case '8':
+                       case '9':
+                       case '-':
+                       case '^':
+                       case '+':
+                       case '\'':
+                       case '$':
+                       case '?':
+                       case '/':
+                       case '.':
+                               ungetc(ss, inputt);
+                               if (start_default == 0 && End_default == 0) {
+                                       strcpy(help_msg,
+                                           "badly formed address");
+                                       *errnum = -1;
+                                       break;
+                               }
+                               ss = l_last;
+                               l_tempp = address_conv(l_tempp, inputt, errnum);
+                               if (*errnum < 0)
+                                       break;
+                               End = l_tempp;
+                               End_default = 0;
+                               if (start_default == 0)
+                                       *errnum = address_check(start, End);
+                               break;
+                       default:
+                               *errnum = -1;
+                               strcpy(help_msg, "unknown command");
+                               break;
+                       }       /* end-switch(ss) */
+
+                       /* Things came out okay with the last command. */
+                       if (*errnum > 0) {
+                               if (GV_flag == 1)
+                                       return;
+                               /* Do the suffixes if there were any. */
+                               if (printsfx > 0) {
+                                       start = End = current;
+                                       ungetc(ss, inputt);
+                                       if (printsfx == 1)
+                                               p(inputt, errnum, 0);
+                                       else
+                                               if (printsfx == 2)
+                                                       p(inputt, errnum, 1);
+                                               else if (printsfx == 4)
+                                                       l(inputt, errnum);
+                                       /* Unlikely it's needed, but... */
+                                       if (*errnum < 0)
+                                               goto errmsg;
+                               }
+                               break;
+                       }
+                       /* There was a problem with the last command. */
+                       else if (*errnum < 0) {
+errmsg:                                while (((ss = getc(inputt)) != '\n') &&
+                                   (ss != EOF));
+                                       if (help_flag == 1)
+                                               printf("%?: %s\n", help_msg);
+                                       else
+                                               printf("?\n");
+                                       if (g_flag > 0)
+                                               return;
+                                       break;
+                       }
+                       l_last = ss;
+                       ss = getc(inputt);
+               }
+       }
+}
 
 
-          if (*errnum > 0)
-            {
-              /* things came out okay with the last command */
-              if (GV_flag == 1)
-                return;
-              /* do the suffixes if there were any */
-              if (printsfx > 0)
-                {
-                  start = End = current;
-                  ungetc(ss, inputt);
-                  if (printsfx == 1)
-                    p(inputt, errnum, 0);
-                  else if (printsfx == 2)
-                    p(inputt, errnum, 1);
-                  else if (printsfx == 4)
-                    l(inputt, errnum);
-                  if (*errnum < 0)
-                    goto errmsg; /* unlikely it's needed, but... */
-                }
-              break;
-            }
-          else if (*errnum < 0)
-            {
-errmsg:
-              /* there was a problem with the last command */
-              while (((ss=getc(inputt)) != '\n') && (ss != EOF))
-                   ;
-              if (help_flag == 1)
-                printf("%?: %s\n", help_msg);
-              else
-                printf("?\n");
-              if (g_flag > 0)
-                  return;
-              break;
-            }
-          l_last = ss;
-          ss = getc(inputt);
-          } /* second while */
-          
-       } /* end-while(1) */
-} /* end-cmd_loop */
-
-
-/* exits ed and prints an appropriate message about the command line
+/*
+ * Exits ed and prints an appropriate message about the command line
  * being malformed (see below).
  */
  * being malformed (see below).
  */
-
 void
 ed_exit(err)
 void
 ed_exit(err)
-
-int err;
-
+       int err;
 {
 {
-  switch (err)
-        {
-          case 1: fprintf(stderr, "ed: illegal option\n");
-                  break;
-          case 2: fprintf(stderr, "ed: missing promptstring\n");
-                  break;
-          case 3: fprintf(stderr, "ed: too many filenames\n");
-                  break;
-          case 4: fprintf(stderr, "ed: out of memory error\n");
-                  break;
-          default: fprintf(stderr, "ed: command line error\n");
-                   break;
-        } /* end-switch */
-  fprintf(stderr, "ed: ed [ -s ] [ -p promtstring ] [ filename ]\n");
-  exit(1);
-} /* end-ed_exit */
-
+       switch (err) {
+          case 1:
+               (void)fprintf(stderr, "ed: illegal option\n");
+               break;
+          case 2:
+               (void)fprintf(stderr, "ed: missing promptstring\n");
+               break;
+          case 3:
+               (void)fprintf(stderr, "ed: too many filenames\n");
+               break;
+          case 4:
+               (void)fprintf(stderr, "ed: out of memory error\n");
+               break;
+          default:
+               (void)fprintf(stderr, "ed: command line error\n");
+               break;
+        }
+       (void)fprintf(stderr,
+           "ed: ed [ -s ] [ -p promptstring ] [ filename ]\n");
+       exit(1);
+}
 
 /*
 
 /*
- * Starts the whole show going. Set things up as the arguments spec
- * in the shell and set a couple of the global variables.
+ * SIGINT is never turned off. We flag it happened and then pay attention
+ * to it at certain logical locations in the code we don't do more here
+ * cause some of our buffer pointer's may be in an inbetween state at the
+ * time of the SIGINT. So we flag it happened, let the local fn handle it
+ * and do a jump back to the cmd_loop
  */
  */
-
-void
-main(argc, argv)
-
-int argc;
-char *argv[];
-
+static void
+sigint_handler(signo)
+       int signo;
 {
 {
-  int l_num, errnum=0, l_err=0; /* note naming viol'n with errnum for consistancy */
-  char *l_fnametmp;
-#ifdef DBI
-  RECNOINFO l_dbaccess;
-#endif
-  /* termcap isn't really need unless you move back and forth between 80 and
-   * 123 column terminals. And if your system is wacked and you have to use
-   * ed because it's the only reliable editor (sysadmin-types know what I'm
-   * talking about), you likely don't want the termcap routines.
-   * See the Makefile about compile options.
-   */
-#ifndef NOTERMCAP
-  int l_ret;
-  char l_bp[1024], *l_term;
-#endif
-
-  setuid(getuid()); /* in case some fool does suid on ed */
-
-#ifndef NOTERMCAP
-  l_term = getenv("TERM");
-  l_ret = tgetent(l_bp, l_term);
-  if (l_ret < 1)
-    line_length = 78; /* reasonable number for all term's */
-  else if ((line_length = tgetnum("co") - 1) < 2)
-#endif
-    line_length = 78;
-  
-  start = End = NULL;
-  top = bottom = NULL;
-  current = NULL;
-  nn_max_flag = 0;
-  nn_max_start = nn_max_end = NULL;
-  l_fnametmp = (char *)calloc(FILENAME_LEN, sizeof(char));
-  if (l_fnametmp == NULL)
-    ed_exit(4);
-  text = (char *)calloc(NN_MAX_START+2, sizeof(char));
-  if (text == NULL)
-    ed_exit(4);
-  start_default = End_default = 0;
-  zsnum = 22; /* for the 'z' command */
-  u_stk = NULL;
-  d_stk = NULL;
-  u_current = u_top = u_bottom = NULL;
-  u_set = 0; /* for in d after a j */
-  filename_flag = 0;
-  filename_current = NULL;
-
-  l_num = 1;
-  while (1)
-       {
-         /* process the command line options */
-         if (l_num >= argc)
-           break;
-         switch (argv[l_num][0])
-               {
-                 case '-':
-                           switch (argv[l_num][1])
-                                 {
-                                   case '\0': /* this is why 'getopt' not used */
-                                   case 's': explain_flag = 0;
-                                             break;
-                                   case 'p': if (++l_num < argc)
-                                               {
-                                                 prompt_string = (char *)calloc(strlen(argv[l_num]), sizeof(char));
-                                                 if (prompt_string == NULL)
-                                                   ed_exit(4);
-                                                 strcpy(prompt_string, argv[l_num]);
-                                                 prompt_str_flg = 1;
-                                                 break;
-                                               }
-                                             l_err = 1;
-                                   default: l_err++;
-                                            ed_exit(l_err);
-                                 } /* end-switch */
-                           break;
-                 default:  if (name_set)
-                             ed_exit(3);
-                           strcpy(l_fnametmp, argv[l_num]);
-                           filename_current = l_fnametmp;
-                           name_set = 1;
-                           if (prompt_str_flg)
-                             break;
-                           /* default ed prompt */
-                           prompt_string = (char *)calloc(3, sizeof(char));
-                           strcpy(prompt_string, "*");
-                           break;
-               } /* end-switch */
-         l_num++;
-       } /* end-while(1) */
-
-  start_up_flag = 1;
-  cmd_loop(stdin, &errnum);
-} /* end-main */
+       sigint_flag = 1;
+       if (sigspecial)  /* Unstick when SIGINT on read(stdin). */
+               SIGINT_ACTION;
+}
+
+static void
+sighup_handler(signo)
+       int signo;
+{
+       (void)fprintf(stderr,"\n  SIGHUP \n");
+       sighup_flag = 1;
+       undo();
+       do_hup();
+       /* NOTREACHED */
+
+       SIGHUP_ACTION;
+}
index 874b535..970cb62 100644 (file)
@@ -9,63 +9,67 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)p.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)p.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Both the n and p code are here because they're almost identical.
  * Print out the line. If it's n print the line number, tab, and then
  * the line.
  */
 
 /*
  * Both the n and p code are here because they're almost identical.
  * Print out the line. If it's n print the line number, tab, and then
  * the line.
  */
-
 void
 p(inputt, errnum, flag)
 void
 p(inputt, errnum, flag)
-
-FILE *inputt;
-int *errnum, flag;
-
+       FILE *inputt;
+       int *errnum, flag;
 {
 {
-  int l_ln;
-
-  if (start_default && End_default)
-    start = End = current;
-  else if (start_default)
-    start = End;
-  start_default = End_default = 0;
+       int l_ln;
 
 
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
+       start_default = End_default = 0;
 
 
-  if (rol(inputt, errnum))  /* for "command-suffix pairs" */
-    return;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       if (rol(inputt, errnum))        /* For "command-suffix pairs". */
+               return;
 
 
-  if (flag == 1)
-    l_ln = line_number(start);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  current = start;
-  while (1)
-       {
-         /* print out the lines */
-         if (sigint_flag)
-           SIGINT_ACTION;
-         if (current == NULL)
-           break;
-         get_line(current->handle, current->len);
-         if (flag == 1) /* when 'n' */
-           printf("%d\t", l_ln++);
-         fwrite(text, sizeof(char), current->len, stdout);
-         putchar('\n');
-         if (current == End)
-           break;
-         current = current->below;
-       } /* end-while */
+       if (flag == 1)
+               l_ln = line_number(start);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       current = start;
+       for (;;) {
+               /* Print out the lines. */
+               if (sigint_flag)
+                       SIGINT_ACTION;
+               if (current == NULL)
+                       break;
+               get_line(current->handle, current->len);
+               if (flag == 1)          /* When 'n'. */
+                       printf("%d\t", l_ln++);
+               fwrite(text, sizeof(char), current->len, stdout);
+               putchar('\n');
+               if (current == End)
+                       break;
+               current = current->below;
+       }
 
 
-  *errnum = 1;
-} /* end-p */
+       *errnum = 1;
+}
index 0b14234..03e6163 100644 (file)
@@ -9,69 +9,67 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)q.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)q.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * End this editting session and exit with saving the buffer. If no
  * write has occurred since the last buffer modification a warning
  * is given once ('Q' over-rides the warning).
  */
 
 /*
  * End this editting session and exit with saving the buffer. If no
  * write has occurred since the last buffer modification a warning
  * is given once ('Q' over-rides the warning).
  */
-
 void
 q(inputt, errnum)
 void
 q(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_which; /* which is it? 'q' or 'Q' */
-  register int l_ss=ss;
-
-  l_which = ss;
-
-  while (1)
-     {
-       l_ss = getc(inputt);
-       if ((l_ss != ' ') && (l_ss != '\n') && (l_ss != EOF))
-         {
-           *errnum = -1;
-           strcpy(help_msg, "illegal command option");
-           return;
-         }
-       if ((l_ss == '\n') || (l_ss == EOF))
-         break;
-     }
+       register int l_ss = ss;
+       int l_which;                    /* Which is it? 'q' or 'Q'. */
 
 
-  ungetc(l_ss, inputt);
-  /* note: 'Q' will bypass this if stmt., which warns of no save */
-  if ((change_flag == 1L) && (l_which == 'q'))
-    {
-      change_flag = 0L;
-      strcpy(help_msg, "buffer changes not saved");
-      *errnum = -1;
-      ss = l_ss;
-      return;
-    }
+       l_which = ss;
+       for (;;) {
+               l_ss = getc(inputt);
+               if ((l_ss != ' ') && (l_ss != '\n') && (l_ss != EOF)) {
+                       *errnum = -1;
+                       strcpy(help_msg, "illegal command option");
+                       return;
+               }
+               if ((l_ss == '\n') || (l_ss == EOF))
+                       break;
+       }
 
 
-  /* do cleanup; should it be even bothered?? */
-  start = top;
-  End = bottom;
-  start_default = End_default = 0;
-  d(inputt, errnum); /* we don't care about the returned errnum val anymore */
-  u_clr_stk();
-  free(text);
-  free(filename_current); 
-#ifdef STDIO
+       ungetc(l_ss, inputt);
+       /* Note: 'Q' will bypass this if stmt., which warns of no save. */
+       if ((change_flag == 1L) && (l_which == 'q')) {
+               change_flag = 0L;
+               strcpy(help_msg, "buffer changes not saved");
+               *errnum = -1;
+               ss = l_ss;
+               return;
+       }
+       /* Do cleanup; should it be even bothered?? */
+       start = top;
+       End = bottom;
+       start_default = End_default = 0;
 
 
-  fclose(fhtmp);
-  unlink(template);
-#endif
-#ifdef DBI
-  (dbhtmp->close)(dbhtmp); /* overhead as the cache is flushed */
-  unlink(template);
-#endif
-  exit(0);
-} /* end-q */
+       /* We don't care about the returned errnum val anymore. */
+       d(inputt, errnum);
+       u_clr_stk();
+       free(text);
+       free(filename_current);
+       (dbhtmp->close) (dbhtmp);       /* Overhead as the cache is flushed. */
+       unlink(template);
+       exit(0);
+}
index 39ebfee..b21e4cf 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)r.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)r.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "ed.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include <a.out.h>
 #include <a.out.h>
+#include <db.h>
 #include <errno.h>
 #include <errno.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ed.h"
+#include "extern.h"
 
 /*
  * This sets up things for the central input routine to place the
  * incoming text at the proper place in the buffer.
  */
 
 /*
  * This sets up things for the central input routine to place the
  * incoming text at the proper place in the buffer.
  */
-
 void
 r(inputt, errnum)
 void
 r(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  FILE *fopen(), *l_fp;
-  long l_num;
-  char *l_filename_read, *l_temp;
-  struct stat l_s_buf;
-  int l_srv;
-  struct exec l_magic;
-
-  if (filename_flag == 1)
-    {
-      l_filename_read = filename_current;
-      filename_flag = 0;
-    }
-  else
-    {
-      l_temp = filename(inputt, errnum);
-      if (*errnum == 1)
-        l_filename_read = l_temp;
-      else if (*errnum == -2)
-        {
-          while (((ss = getc(inputt)) != '\n') || (ss == EOF))
-               ;
-          l_filename_read = filename_current;
-        }
-      else if (*errnum < 0)
-        return;
-      *errnum = 0;
-    } /* end-else */
-
-  if (filename_current == NULL)
-    {
-      if (l_filename_read == NULL)
-        {
-          strcpy(help_msg, "no filename given");
-          *errnum = -1;
-          if (ss)
-            ungetc('\n', inputt);
-          return;
-        }
-      else
-        filename_current = l_filename_read;
-    }
+       struct exec l_magic;
+       struct stat l_s_buf;
+       FILE *l_fp;
+       long l_num;
+       char *l_filename_read, *l_temp;
+       int l_srv;
 
 
-  if (sigint_flag)
-    SIGINT_ACTION;
+       if (filename_flag == 1) {
+               l_filename_read = filename_current;
+               filename_flag = 0;
+       } else {
+               l_temp = filename(inputt, errnum);
+               if (*errnum == 1)
+                       l_filename_read = l_temp;
+               else
+                       if (*errnum == -2) {
+                               while (((ss = getc(inputt)) != '\n') ||
+                                   (ss == EOF));
+                               l_filename_read = filename_current;
+                       } else
+                               if (*errnum < 0)
+                                       return;
+               *errnum = 0;
+       }
 
 
-  /* determine if the file can be read. If not set the help message
-   * to something descritive that the user should understand.
-   */
-  if (((l_srv = stat(l_filename_read, &l_s_buf)) == -1) || (l_s_buf.st_mode & S_IFDIR))
-    {
-      if (l_srv == -1)
-        {
-          switch (errno)
-                {
-                  case ENOTDIR: strcpy(help_msg, "directory in pathname does not exist");
-                                break;
-                  case ENOENT: strcpy(help_msg, "file does not exist");
-                               break;
-                  case EACCES: strcpy(help_msg, "permission lacking to read file");
-                               break;
-                  case ENAMETOOLONG: strcpy(help_msg, "pathname or component of pathname too long");
-                                     break;
-                  case EIO: strcpy(help_msg, "I/O error during read");
-                            break;
-                  case ELOOP: strcpy(help_msg, "too many symbolic links in pathname");
-                              break;
-                  default: strcpy(help_msg, "unable to read file stat");
-                           break;
-                }
-        }
-      else
-        strcpy(help_msg, "filename is directory, not a text file");
-      printf("?%s\n", l_filename_read);
-      *errnum = 0;
-      return;
-    }
+       if (filename_current == NULL) {
+               if (l_filename_read == NULL) {
+                       strcpy(help_msg, "no filename given");
+                       *errnum = -1;
+                       if (ss)
+                               ungetc('\n', inputt);
+                       return;
+               } else
+                       filename_current = l_filename_read;
+       }
+       if (sigint_flag)
+               SIGINT_ACTION;
 
 
-  if ((l_fp = fopen(l_filename_read, "r")) == 0)
-    {
-      strcpy(help_msg, "permission lacking to read file");
-      printf("?%s\n", l_filename_read);
-      *errnum = 0;
-      return;
-    }
+       /*
+        * Determine if the file can be read.  If not set the help message to
+        * something descriptive that the user should understand.
+        */
+       if (((l_srv = stat(l_filename_read, &l_s_buf)) == -1) ||
+           (l_s_buf.st_mode & S_IFDIR)) {
+               if (l_srv == -1)
+                       strcpy(help_msg, strerror(errno));
+               else
+                       strcpy(help_msg,
+                           "filename is directory, not a text file");
+               printf("?%s\n", l_filename_read);
+               *errnum = 0;
+               return;
+       }
+       if ((l_fp = fopen(l_filename_read, "r")) == NULL) {
+               strcpy(help_msg, "permission lacking to read file");
+               printf("?%s\n", l_filename_read);
+               *errnum = 0;
+               return;
+       }
+       /*
+        * There is permission to read the file, but if it's an executable
+        * file of the object code and linked type, we really don't want to
+        * look at it (according to ed spec's).
+        */
+       if (fread(&l_magic, sizeof(struct exec), 1, l_fp) != 0) {
+               if (!(N_BADMAG(l_magic))) {
+                       strcpy(help_msg, "unable to read executable file");
+                       printf("?%s\n", l_filename_read);
+                       *errnum = 0;
+                       return;
+               }
+       }
+       fseek(l_fp, (off_t)0, 0);
+       if (g_flag == 0)
+               u_clr_stk();
+       l_num = input_lines(l_fp, errnum);
+       if (sigint_flag == 1)
+               goto point;
+       if (*errnum < 0)
+               return;
+       *errnum = 0;
 
 
-  /* there is permission to read the file, but if it's an executable
-   * file of the object code and linked type, we really don't want
-   * to look at it (according ed spec's).
-   */
-  if (fread(&l_magic, sizeof(struct exec), 1, l_fp) != 0)
-    {
-      if (!(N_BADMAG(l_magic)))
-        {
-          strcpy(help_msg, "unable to read executable file");
-          printf("?%s\n", l_filename_read);
-          *errnum = 0;
-          return;
-        }
-    }
-  fseek(l_fp, 0L, 0);
-  if (g_flag == 0)
-    u_clr_stk();
-  l_num = input_lines(l_fp, errnum);
-  if (sigint_flag == 1)
-    goto point;
-  if (*errnum < 0)
-    return;
-  *errnum = 0;
+       if (explain_flag)       /* !=0 */
+               printf("%ld\n", l_num);
+       if (l_filename_read != filename_current)
+               free(l_filename_read);
 
 
-  if (explain_flag) /* !=0 */
-    printf("%ld\n", l_num);
-  if (l_filename_read != filename_current)
-    free(l_filename_read);
-  point:
-  fclose(l_fp);
-  change_flag = 1;
-  if (sigint_flag)
-    SIGINT_ACTION;
-  *errnum = 1;
-} /* end-r */
+point: fclose(l_fp);
+       change_flag = 1;
+       if (sigint_flag)
+               SIGINT_ACTION;
+       *errnum = 1;
+}
index 650001a..183f453 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)re.c       5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)re.c       5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "ed.h"
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 
+#include "ed.h"
+#include "extern.h"
 
 /*
  * This finds the n-th occurrence of an RE in a line. If '^' was at the start
 
 /*
  * This finds the n-th occurrence of an RE in a line. If '^' was at the start
- * of the RE then look once (in case n=1). There is no standard RE
- * interface to do this. returns 0 for success.
- * NOTE: the #ifdef REG_STARTEND is if the regex package has the BSD
- * extensions to it.
+ * of the RE then look once (in case n=1). There is no standard RE interface
+ * to do this.  Returns 0 for success.  NOTE: the #ifdef REG_STARTEND is if
+ * the regex package has the BSD extensions to it.
  */
  */
-
 int
 #ifdef REG_STARTEND
 regexec_n(reprecomp, strg, num_subexp, reprematch, flags, n, len, pass)
 #else
 regexec_n(reprecomp, strg, num_subexp, reprematch, flags, n, offset, pass)
 #endif
 int
 #ifdef REG_STARTEND
 regexec_n(reprecomp, strg, num_subexp, reprematch, flags, n, len, pass)
 #else
 regexec_n(reprecomp, strg, num_subexp, reprematch, flags, n, offset, pass)
 #endif
-
-regex_t *reprecomp;
-char *strg;
-size_t num_subexp;
-regmatch_t reprematch[];
-int flags, n;
+       regex_t *reprecomp;
+       char *strg;
+       size_t num_subexp;
+       regmatch_t reprematch[];
+       int flags, n;
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-size_t len;
+       size_t len;
 #else
 #else
-size_t *offset;
+       size_t *offset;
 #endif
 #endif
-int pass; /* if pass==0 .rm_so user set, else set default */
-
+       int pass; /* if pass == 0 .rm_so user set, else set default */
 {
 {
-  int l_cnt;
+       int l_cnt;
 #ifndef REG_STARTEND
 #ifndef REG_STARTEND
-  char *l_offset=strg;
+       char *l_offset = strg;
 #endif
 
 #endif
 
-  if (n <= 0)
-    return(REG_NOMATCH);
+       if (n <= 0)
+               return (REG_NOMATCH);
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-  flags = (flags | REG_STARTEND);
-  if (pass)
-    reprematch[0].rm_so = 0;
-  reprematch[0].rm_eo = len;
+       flags = (flags | REG_STARTEND);
+       if (pass)
+               reprematch[0].rm_so = 0;
+       reprematch[0].rm_eo = len;
 #else
 #else
-  strg = &strg[offset];
+       strg = &strg[offset];
 #endif
 #endif
-  for (l_cnt=0;;)
-     {
-       if (regexec(reprecomp, strg, num_subexp, reprematch, flags) == 0)
-         l_cnt++;
-       else
-         return(REG_NOMATCH);
-       if (l_cnt>=n)
-         break;
+       for (l_cnt = 0;;) {
+               if (regexec(reprecomp,
+                   strg, num_subexp, reprematch, flags) == 0)
+                       l_cnt++;
+               else
+                       return (REG_NOMATCH);
+               if (l_cnt >= n)
+                       break;
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-       reprematch[0].rm_so = reprematch[0].rm_eo;
-       reprematch[0].rm_eo = len;
+               reprematch[0].rm_so = reprematch[0].rm_eo;
+               reprematch[0].rm_eo = len;
 #else
 #else
-       strg = &strg[reprematch[0].rm_eo];
+               strg = &strg[reprematch[0].rm_eo];
 #endif
 #endif
-       /* if a "^" started the current RE we only loop once */
-       if (RE_sol)
-         return(REG_NOMATCH);
-     }
+               /* if a "^" started the current RE we only loop once */
+               if (RE_sol)
+                       return (REG_NOMATCH);
+       }
 #ifndef REG_STARTEND
 #ifndef REG_STARTEND
-  *offset = (size_t)(strg - l_offset);
+       *offset = (size_t) (strg - l_offset);
 #endif
 #endif
-  return(0); /* success */
-} /* end-regexec_n */
-
-
+       return (0);             /* success */
+}
 
 /*
  * Replace in the line specified at the found locations with the
  * specified replacement. There is no standard RE interface to do
  * this.
  */
 
 /*
  * Replace in the line specified at the found locations with the
  * specified replacement. There is no standard RE interface to do
  * this.
  */
-
-char
+char *
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-*re_replace(line, num_subexp, repmatch, replacer)
+re_replace(line, num_subexp, repmatch, replacer)
 #else
 #else
-*re_replace(line, num_subexp, repmatch, replacer, offset)
+re_replace(line, num_subexp, repmatch, replacer, offset)
 #endif
 #endif
-
-char *line;
-size_t num_subexp;
-regmatch_t repmatch[];
-char *replacer;
+       char *line;
+       size_t num_subexp;
+       regmatch_t repmatch[];
+       char *replacer;
 #ifndef REG_STARTEND
 #ifndef REG_STARTEND
-size_t offset;
+       size_t offset;
 #endif
 #endif
-
 {
 {
-  int l_cnt, l_len_new=0, l_new_rm_eo=0;
-  regoff_t l_len_before, l_len_whole, l_slen[RE_SEC];
-  char *l_string, *l_head;
-  static char *l_prev_r=NULL;
-  static int l_prev_r_flag=0;
+       static char *l_prev_r = NULL;
+       static int l_prev_r_flag = 0;
+       regoff_t l_len_before, l_len_whole, l_slen[RE_SEC];
+       int l_cnt, l_len_new = 0, l_new_rm_eo = 0;
+       char *l_string, *l_head;
 
 
-  if (l_prev_r_flag == 0)
-    {
-      l_prev_r_flag = 1;
-      l_prev_r = NULL;
-    }
-  l_head = replacer;
-  l_len_before = (repmatch[0].rm_so); /* length of what stays the same before */
-  l_len_whole = strlen(line);
-  if (num_subexp > RE_SEC-1)
-    num_subexp = RE_SEC-1;
-  for (l_cnt=0; l_cnt<=num_subexp; l_cnt++)
-     l_slen[l_cnt] = (repmatch[l_cnt].rm_eo) - (repmatch[l_cnt].rm_so);
-     /* l_slen[0] == len of what is to be replaced */
-     /* l_slen[1-9] == len of each backref */
+       if (l_prev_r_flag == 0) {
+               l_prev_r_flag = 1;
+               l_prev_r = NULL;
+       }
+       l_head = replacer;
+       /* Length of what stays the same before. */
+       l_len_before = (repmatch[0].rm_so);
+       l_len_whole = strlen(line);
+       if (num_subexp > RE_SEC - 1)
+               num_subexp = RE_SEC - 1;
+       for (l_cnt = 0; l_cnt <= num_subexp; l_cnt++)
+               l_slen[l_cnt] =
+                   (repmatch[l_cnt].rm_eo) - (repmatch[l_cnt].rm_so);
 
 
-  if ((*replacer == '%') && (replacer[1] == 1))
-    {
-      l_string = (char *)calloc(l_len_whole-l_slen[0]+(strlen(l_prev_r))+2, sizeof(char));
-      if (l_string == NULL)
-        {
-          /* *errnum = -1;*/
-          strcpy(help_msg, "out of memory error");
-          return(NULL);
-        }
+       /*
+        * l_slen[0] == len of what is to be replaced.
+        * l_slen[1-9] == len of each backref.
+        */
+       if ((*replacer == '%') && (replacer[1] == 1)) {
+               l_string = calloc(l_len_whole - l_slen[0] +
+                   (strlen(l_prev_r)) + 2, sizeof(char));
+               if (l_string == NULL) {
+                       /* *errnum = -1; */
+                       strcpy(help_msg, "out of memory error");
+                       return (NULL);
+               }
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-      bcopy(line, l_string, (int)l_len_before);
+               bcopy(line, l_string, (int) l_len_before);
 #else
 #else
-      bcopy(line, l_string, (int)l_len_before+offset);
+               bcopy(line, l_string, (int) l_len_before + offset);
 #endif
 #ifdef REG_STARTEND
 #endif
 #ifdef REG_STARTEND
-      l_string[l_len_before] = '\0';
+               l_string[l_len_before] = '\0';
 #else
 #else
-      l_string[l_len_before+offset] = '\0';
+               l_string[l_len_before + offset] = '\0';
 #endif
 #endif
-      strcat(l_string, l_prev_r);
+               strcat(l_string, l_prev_r);
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-      strcat(l_string, &line[repmatch[0].rm_eo]);
+               strcat(l_string, &line[repmatch[0].rm_eo]);
 #else
 #else
-      strcat(l_string, &line[repmatch[0].rm_eo+offset]);
+               strcat(l_string, &line[repmatch[0].rm_eo + offset]);
 #endif
 #endif
-      return(l_string);
-    }
-
-  /* figure out length of new line first */
-  while (*replacer != '\0')
-       {
-         /* add in the length of the RE match */
-         if (*replacer == '&')
-           l_len_new = l_len_new + l_slen[0];
-         /* add in the length of a backref */
-         else if (*replacer == '\\')
-           {
-             replacer++;
-             if ((*replacer > '0') && (*replacer < ('9'+1)) && (repmatch[*replacer-'0'].rm_so > -1))
-               l_len_new = l_len_new + l_slen[*replacer-'0']; /* -1 - -1 = 0 */
-             else
-               l_len_new++;
-           }
-         else
-           l_len_new++;
-
-         replacer++;
-       }
+               return (l_string);
+       }
 
 
-  /* create the line of an appropriate length */
-  l_string = (char *)calloc(l_len_whole-l_slen[0]+l_len_new+2, sizeof(char));
-  if (l_string == NULL)
-    {
-      strcpy(help_msg, "out of memory error");
-      return(NULL);
-    }
-  if (l_prev_r != NULL)
-    free(l_prev_r);
-  l_prev_r = (char *)calloc(l_len_new+2, sizeof(char));
-  if (l_prev_r == NULL)
-    {
-      strcpy(help_msg, "out of memory error");
-      return(NULL);
-    }
+       /* Figure out length of new line first. */
+       while (*replacer != '\0') {
+               /* Add in the length of the RE match. */
+               if (*replacer == '&')
+                       l_len_new = l_len_new + l_slen[0];
+               /* Add in the length of a backref. */
+               else if (*replacer == '\\') {
+                       replacer++;
+                       if ((*replacer > '0') &&
+                           (*replacer < ('9' + 1)) &&
+                           (repmatch[*replacer - '0'].rm_so > -1))
+                               /* -1 - -1 = 0 */
+                               l_len_new = l_len_new + l_slen[*replacer - '0'];
+                       else
+                               l_len_new++;
+               } else
+                       l_len_new++;
+               replacer++;
+       }
 
 
-  /* copy over what doesn't change before the chars to be replaced */
+       /* Create the line of an appropriate length. */
+       l_string =
+           calloc(l_len_whole - l_slen[0] + l_len_new + 2, sizeof(char));
+       if (l_string == NULL) {
+               strcpy(help_msg, "out of memory error");
+               return (NULL);
+       }
+       if (l_prev_r != NULL)
+               free(l_prev_r);
+       l_prev_r = calloc(l_len_new + 2, sizeof(char));
+       if (l_prev_r == NULL) {
+               strcpy(help_msg, "out of memory error");
+               return (NULL);
+       }
+       /* Copy over what doesn't change before the chars to be replaced. */
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-  bcopy(line, l_string, (int)l_len_before);
+       bcopy(line, l_string, (int) l_len_before);
 #else
 #else
-  bcopy(line, l_string, l_len_before+offset);
+       bcopy(line, l_string, l_len_before + offset);
 #endif
 #ifdef REG_STARTEND
 #endif
 #ifdef REG_STARTEND
-  l_string[l_len_before] = '\0';
+       l_string[l_len_before] = '\0';
 #else
 #else
-  l_string[l_len_before+offset] = '\0';
+       l_string[l_len_before + offset] = '\0';
 #endif
 #endif
-  l_prev_r[0] = '\0';
+       l_prev_r[0] = '\0';
 
 
-  /* make the replacement */
-  replacer = l_head;
-  while (*replacer != '\0')
-       {
-         /* put what matched the RE into the replacement */
-         if (*replacer == '&')
-           {
-#ifdef REG_STARTEND
-            strncat(l_string, &line[repmatch[0].rm_so], (int)l_slen[0]);
-#else
-            strncat(l_string, &line[repmatch[0].rm_so+offset], (int)l_slen[0]);
-#endif
+       /* Make the replacement. */
+       replacer = l_head;
+       while (*replacer != '\0') {
+               /* Put what matched the RE into the replacement. */
+               if (*replacer == '&') {
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-            strncat(l_prev_r, &line[repmatch[0].rm_so], (int)l_slen[0]);
+                       strncat(l_string,
+                           &line[repmatch[0].rm_so], (int)l_slen[0]);
+                       strncat(l_prev_r,
+                           &line[repmatch[0].rm_so], (int) l_slen[0]);
 #else
 #else
-            strncat(l_prev_r, &line[repmatch[0].rm_so+offset], (int)l_slen[0]);
+                       strncat(l_string,
+                           &line[repmatch[0].rm_so + offset], (int) l_slen[0]);
+                       strncat(l_prev_r,
+                           &line[repmatch[0].rm_so + offset], (int) l_slen[0]);
 #endif
 #endif
-           }
-         else if (*replacer == '\\')
-           {
-             /* likely a backref to be included */
-             replacer++;
-             if ((*replacer > '0') && (*replacer < ('9'+1)) && (repmatch[*replacer-'0'].rm_so > -1))
-               {
+               } else if (*replacer == '\\') {
+                       /* Likely a backref to be included. */
+                       replacer++;
+                       if ((*replacer > '0') && (*replacer < ('9' + 1)) &&
+                           (repmatch[*replacer - '0'].rm_so > -1)) {
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-                 strncat(l_string, &line[repmatch[*replacer-'0'].rm_so], (int)l_slen[*replacer-'0']);
+                               strncat(l_string,
+                                   &line[repmatch[*replacer - '0'].rm_so],
+                                   (int) l_slen[*replacer - '0']);
+                               strncat(l_prev_r,
+                                   &line[repmatch[*replacer - '0'].rm_so],
+                                   (int) l_slen[*replacer - '0']);
 #else
 #else
-                 strncat(l_string, &line[repmatch[*replacer-'0'].rm_so+offset], (int)l_slen[*replacer-'0']);
+                               strncat(l_string,
+                                   &line[repmatch[*replacer - '0'].rm_so +
+                                   offset], (int) l_slen[*replacer - '0']);
+                               strncat(l_prev_r,
+                                   &line[repmatch[*replacer - '0'].rm_so +
+                                   offset], (int) l_slen[*replacer - '0']);
 #endif
 #endif
-#ifdef REG_STARTEND
-                 strncat(l_prev_r, &line[repmatch[*replacer-'0'].rm_so], (int)l_slen[*replacer-'0']);
-#else
-                 strncat(l_prev_r, &line[repmatch[*replacer-'0'].rm_so+offset], (int)l_slen[*replacer-'0']);
-#endif
-               }
-             /* put the replacement in */
-             else
-               {
-                 strncat(l_string, replacer, 1);
-                 strncat(l_prev_r, replacer, 1);
-               }
-           }
-         /* put the replacement in */
-         else
-           {
-             strncat(l_string, replacer, 1);
-             strncat(l_prev_r, replacer, 1);
-           }
+                       }
+                       /* Put the replacement in. */
+                       else {
+                               strncat(l_string, replacer, 1);
+                               strncat(l_prev_r, replacer, 1);
+                       }
+               }
+               /* Put the replacement in. */
+               else {
+                       strncat(l_string, replacer, 1);
+                       strncat(l_prev_r, replacer, 1);
+               }
+               replacer++;
+       }
 
 
-         replacer++;
-       }
-  
- l_new_rm_eo = strlen(l_string);
+       l_new_rm_eo = strlen(l_string);
 
 
-  /* copy over what was after the chars to be replaced to the new line */
+       /* Copy over what was after the chars to be replaced to the new line. */
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-  strcat(l_string, &line[repmatch[0].rm_eo]);
+       strcat(l_string, &line[repmatch[0].rm_eo]);
 #else
 #else
-  strcat(l_string, &line[repmatch[0].rm_eo+offset]);
+       strcat(l_string, &line[repmatch[0].rm_eo + offset]);
 #endif
 
 #endif
 
-  repmatch[0].rm_eo = l_new_rm_eo; /* update rm_eo */
+       repmatch[0].rm_eo = l_new_rm_eo;        /* Update rm_eo. */
 #ifndef REG_STARTEND
 #ifndef REG_STARTEND
-  offset += l_new_rm_eo; /* update offset */
+       offset += l_new_rm_eo;                  /* Update offset. */
 #endif
 #endif
-  return(l_string);   /* return the new line */
-} /* end-re_replace */
-
+       return (l_string);                      /* Return the new line. */
+}
index 8eb8c62..c2735ed 100644 (file)
@@ -9,10 +9,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)rol.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)rol.c      5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * After the command check the rest of the line to see nothing illegal
 
 /*
  * After the command check the rest of the line to see nothing illegal
@@ -22,39 +31,37 @@ static char sccsid[] = "@(#)rol.c   5.1 (Berkeley) %G%";
  * function after the command that called this function finishes
  * successfully.
  */
  * function after the command that called this function finishes
  * successfully.
  */
-
 int
 rol(inputt, errnum)
 int
 rol(inputt, errnum)
+       FILE *inputt;
+       int *errnum;
+{
+       ss = getc(inputt);
+       printsfx = 0;
 
 
-FILE *inputt;
-int *errnum;
+       /* Only one of the suffix is allowed. */
+       if (ss == 'p')
+               printsfx = 1;
+       else
+               if (ss == 'n')
+                       printsfx = 2;
+               else
+                       if (ss == 'l')
+                               printsfx = 4;
+                       else
+                               ungetc(ss, inputt);
 
 
-{
+       for (;;) {
+               ss = getc(inputt);
+               if ((ss != ' ') && (ss != '\n') && (ss != EOF)) {
+                       *errnum = -1;
+                       strcpy(help_msg, "illegal command option");
+                       return (1);
+               }
+               if ((ss == '\n') || (ss == EOF))
+                       break;
+       }
 
 
-  ss = getc(inputt);
-  printsfx = 0;
-  /* only one of the suffix is allowed */
-  if (ss == 'p')
-    printsfx = 1;
-  else if (ss == 'n')
-    printsfx = 2;
-  else if (ss == 'l')
-    printsfx = 4;
-  else
-    ungetc(ss, inputt);
-
-  while (1)
-     {
-       ss = getc(inputt);
-       if ((ss != ' ') && (ss != '\n') && (ss != EOF))
-         {
-           *errnum = -1;
-           strcpy(help_msg, "illegal command option");
-           return(1);
-         }
-       if ((ss == '\n') || (ss == EOF))
-         break;
-     }
-
-return(0); /* rest-of-line was okay */
-} /* end-rol */
+       /* Rest-of-line was okay. */
+       return (0);
+}
index 17e8f41..10784d3 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)search.c   5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)search.c   5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * searches forward through the buffer (wrapping if necessary) for a
  * line that contains a match to the RE.
  */
 
 
 /*
  * searches forward through the buffer (wrapping if necessary) for a
  * line that contains a match to the RE.
  */
 
-LINE
-*search(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+LINE *
+search(inputt, errnum)
+       FILE *inputt;
+       int *errnum;
 {
 {
+       LINE *l_temp;
+       int l_err;
+       char *l_patt;
 
 
-  LINE *l_temp;
-  int l_err;
-  char *l_patt;
+       l_temp = current->below;
+       /* Get the RE. */
+       l_patt = get_pattern(ss, inputt, errnum, 0);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum < -1)
+               return (NULL);
+       *errnum = 0;
+       if ((RE_flag == 0) && (l_patt[1] == '\0')) {
+               *errnum = -1;
+               ungetc(ss, inputt);
+               return (NULL);
+       } else
+               if (l_patt[1] || (RE_patt == NULL)) {
+                       free(RE_patt);
+                       RE_patt = l_patt;
+               }
+       RE_sol = (RE_patt[1] == '^') ? 1 : 0;
 
 
-  l_temp = current->below;
-  /* get the RE */
-  l_patt = get_pattern(ss, inputt, errnum, 0);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum < -1)
-    return(NULL);
-  *errnum = 0;
-  if ((RE_flag == 0) && (l_patt[1] == '\0'))
-    {
-      *errnum = -1;
-      ungetc(ss, inputt);
-      return(NULL);
-    }
-  else if (l_patt[1] || (RE_patt == NULL))
-    {
-      free(RE_patt);
-      RE_patt = l_patt;
-    }
-  RE_sol = (RE_patt[1] == '^')?1:0;
-  /* compile it up */
-  if ((l_patt[1]) && (regfree(&RE_comp), l_err = regcomp(&RE_comp, &RE_patt[1], 0)))
-    {
-      regerror(l_err, &RE_comp, help_msg, 128);
-      *errnum = -1;
-      RE_flag = 0;
-      ungetc(ss, inputt);
-      return(NULL);
-    }
-  RE_flag = 1;
-  if (sigint_flag)
-    SIGINT_ACTION;
-  /* find a line that has the RE in it */
-  while (1) /*(l_temp != current)*/
-       {
-         if (l_temp == NULL)
-           {
-             if (top != NULL)
-               l_temp = top;
-             else
-               break;
-           }
-         get_line(l_temp->handle, l_temp->len);
-         if (regexec(&RE_comp, text, (size_t)RE_SEC, RE_match, 0))
-           {
-             l_temp = l_temp->below;
-             if (l_temp == (current->below))
-                break;
-           }
-         else
-           {
-             *errnum = 0;
-             return(l_temp);
-           }
-         if (sigint_flag)
-           SIGINT_ACTION;
-       } /* end-while */
-  strcpy(help_msg, "RE not found");
-  *errnum = -1;
-  return(NULL);
-} /* end-search */
+       /* Compile it up. */
+       if ((l_patt[1]) &&
+           (regfree(&RE_comp), l_err = regcomp(&RE_comp, &RE_patt[1], 0))) {
+               regerror(l_err, &RE_comp, help_msg, 128);
+               *errnum = -1;
+               RE_flag = 0;
+               ungetc(ss, inputt);
+               return (NULL);
+       }
+       RE_flag = 1;
+       if (sigint_flag)
+               SIGINT_ACTION;
+
+       /* Find a line that has the RE in it. */
+       for (;;) {              /* (l_temp != current) */
+               if (l_temp == NULL) {
+                       if (top != NULL)
+                               l_temp = top;
+                       else
+                               break;
+               }
+               get_line(l_temp->handle, l_temp->len);
+               if (regexec(&RE_comp, text, (size_t) RE_SEC, RE_match, 0)) {
+                       l_temp = l_temp->below;
+                       if (l_temp == (current->below))
+                               break;
+               } else {
+                       *errnum = 0;
+                       return (l_temp);
+               }
+               if (sigint_flag)
+                       SIGINT_ACTION;
+       }
+       strcpy(help_msg, "RE not found");
+       *errnum = -1;
+       return (NULL);
+}
 
 /*
  * Searches backward through the buffer (wrapping if necessary) to find
  * a line that contains a match to the RE.
  */
 
 /*
  * Searches backward through the buffer (wrapping if necessary) to find
  * a line that contains a match to the RE.
  */
+LINE *
+search_r(inputt, errnum)
+       FILE *inputt;
+       int *errnum;
+{
+       LINE *l_temp;
+       int l_err;
+       char *l_patt;
 
 
-LINE
-*search_r(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
+       l_temp = current->above;
 
 
-{
+       /* Get the RE. */
+       l_patt = get_pattern(ss, inputt, errnum, 0);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum < -1)
+               return (NULL);
+       *errnum = 0;
+       if ((RE_flag == 0) && (l_patt[1] == '\0')) {
+               *errnum = -1;
+               ungetc(ss, inputt);
+               return (NULL);
+       } else
+               if (l_patt[1] || (RE_patt == NULL)) {
+                       free(RE_patt);
+                       RE_patt = l_patt;
+               }
+       RE_sol = (RE_patt[1] == '^') ? 1 : 0;
 
 
-  LINE *l_temp;
-  int l_err;
-  char *l_patt;
+       /* Compile up the RE. */
+       if ((l_patt[1]) &&
+           (regfree(&RE_comp), l_err = regcomp(&RE_comp, &RE_patt[1], 0))) {
+               regerror(l_err, &RE_comp, help_msg, 128);
+               *errnum = -1;
+               RE_flag = 0;
+               ungetc(ss, inputt);
+               return (NULL);
+       }
+       RE_flag = 1;
+       if (sigint_flag)
+               SIGINT_ACTION;
 
 
-  l_temp = current->above;
-  /* get the RE */
-  l_patt = get_pattern(ss, inputt, errnum, 0);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum < -1)
-    return(NULL);
-  *errnum = 0;
-  if ((RE_flag == 0) && (l_patt[1] == '\0'))
-    {
-      *errnum = -1;
-      ungetc(ss, inputt);
-      return(NULL);
-    }
-  else if (l_patt[1] || (RE_patt == NULL))
-    {
-      free(RE_patt);
-      RE_patt = l_patt;
-    }
-  RE_sol = (RE_patt[1] == '^')?1:0;
-  /* compile up the RE */
-  if ((l_patt[1]) && (regfree(&RE_comp), l_err = regcomp(&RE_comp, &RE_patt[1], 0)))
-    {
-      regerror(l_err, &RE_comp, help_msg, 128);
-      *errnum = -1;
-      RE_flag = 0;
-      ungetc(ss, inputt);
-      return(NULL);
-    }
-  RE_flag = 1;
-  if (sigint_flag)
-    SIGINT_ACTION;
-  /* search for a line that has the RE in it */
-  while (1) /*(l_temp != (current->above))*/
-       {
-         if (l_temp == NULL)
-           {
-             if (bottom != NULL)
-               l_temp = bottom;
-             else
-               break;
-           }
-         get_line(l_temp->handle, l_temp->len);
-         if (regexec(&RE_comp, text, (size_t)RE_SEC, RE_match, 0))
-           {
-             l_temp = l_temp->above;
-             if (l_temp == (current->above))
-               break;
-           }
-         else
-           {
-             *errnum = 0;
-             return(l_temp);
-           }
-        if (sigint_flag)
-          SIGINT_ACTION;
-       } /* end-while */
-  strcpy(help_msg, "RE not found");
-  *errnum = -1;
-  return(NULL);
-} /* end-search */
+       /* Search for a line that has the RE in it. */
+       for (;;) {              /* (l_temp != (current->above)) */
+               if (l_temp == NULL) {
+                       if (bottom != NULL)
+                               l_temp = bottom;
+                       else
+                               break;
+               }
+               get_line(l_temp->handle, l_temp->len);
+               if (regexec(&RE_comp, text, (size_t) RE_SEC, RE_match, 0)) {
+                       l_temp = l_temp->above;
+                       if (l_temp == (current->above))
+                               break;
+               } else {
+                       *errnum = 0;
+                       return (l_temp);
+               }
+               if (sigint_flag)
+                       SIGINT_ACTION;
+       }
+       strcpy(help_msg, "RE not found");
+       *errnum = -1;
+       return (NULL);
+}
index 987c545..e4368ee 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)sub.c      5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)sub.c      5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * The substitute command. It's big because of the backward compatability.
  */
 
 /*
  * The substitute command. It's big because of the backward compatability.
  */
-
 void
 s(inputt, errnum)
 void
 s(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  static int l_count2=1, l_global=0, l_print=0, l_first_pass_flag=0;
-  static char *l_match=NULL, *l_repl=NULL;
-  int l_s_flag, l_count, l_matched, l_nflag, l_cnt, yy, l_sr_flag=0, l_err, l_sl;
-  char *l_match2=NULL, *l_local=NULL, *l_local_temp=NULL;
-  LINE *l_s_ret, *l_temp_line, *l_temp_line2, *l_kval, *l_last;
+       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;
+       int l_s_flag, l_count, l_matched, l_nflag, l_cnt, yy, l_sr_flag = 0;
+       int l_err, l_sl;
+       char *l_match2 = NULL, *l_local = NULL, *l_local_temp = NULL;
 #ifndef REG_STARTEND
 #ifndef REG_STARTEND
-  size_t l_offset=0;
+       size_t l_offset = 0;
 #endif
 
 #endif
 
-  if (start_default && End_default)
-    start = End = current;
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
-
-  l_sl = ss = getc(inputt);
-   if (l_first_pass_flag == 0)
-    l_match = l_repl = NULL;
-  l_match2 = get_pattern(l_sl, inputt, errnum, 0);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum < 0)
-    {
-      if ((*errnum == -2) && (l_sl != '\n'))
-        return;
-      if ((l_match2 == NULL) || (strlen(l_match2) > 4) || (l_first_pass_flag == 0))
-        return;
-      *errnum = 0;
-      l_sr_flag = -1;
-      for (yy=0; yy<(strlen(l_match2)); yy++)
-         {
-           switch (l_match2[yy])
-                 {
-                   case '\n': ss = getc(inputt);
-                              goto bcg1;
-                              break;
-                   case 'r': l_sr_flag = 1;
-                             break;
-                   case 'p': l_print = (l_print)?0:1;
-                             break;
-                   case 'g': l_global = (l_global)?0:1;
-                             break;
-                   case 'N': l_count2 = 1;
-                             break;
-                   default: *errnum = -1;
-                            strcpy(help_msg, "illegal modifier to s");
-                            return;
-                 } /* end-switch */
-         } /* end-for */
-      ss = getc(inputt);
-      if (l_sr_flag == 1)
-        goto bcg2;
-      else
-        goto bcg1;
-    }
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
 
 
-  if (l_first_pass_flag)
-    {
-      free(l_match);
-      free(l_repl);
-    }
-  else
-      l_first_pass_flag = 1;
-  l_match = l_match2;
-  *errnum = 0;
-  l_repl = get_pattern(ss, inputt, errnum, 1);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  l_global = l_print = 0;
-  if (*errnum < 0)
-    {
-      if ((*errnum == -1) && (ss == '\n'))
-          l_print = (int)1; /* note: \n still in stream for next getc */
-      else
-        return;
-    }
-  *errnum = 0;
+       l_sl = ss = getc(inputt);
+       if (l_first_pass_flag == 0)
+               l_match = l_repl = NULL;
+       l_match2 = get_pattern(l_sl, inputt, errnum, 0);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum < 0) {
+               if ((*errnum == -2) && (l_sl != '\n'))
+                       return;
+               if ((l_match2 == NULL) ||
+                   (strlen(l_match2) > 4) || (l_first_pass_flag == 0))
+                       return;
+               *errnum = 0;
+               l_sr_flag = -1;
+               for (yy = 0; yy < (strlen(l_match2)); yy++) {
+                       switch (l_match2[yy]) {
+                       case '\n':
+                               ss = getc(inputt);
+                               goto bcg1;
+                               break;
+                       case 'r':
+                               l_sr_flag = 1;
+                               break;
+                       case 'p':
+                               l_print = (l_print) ? 0 : 1;
+                               break;
+                       case 'g':
+                               l_global = (l_global) ? 0 : 1;
+                               break;
+                       case 'N':
+                               l_count2 = 1;
+                               break;
+                       default:
+                               *errnum = -1;
+                               strcpy(help_msg, "illegal modifier to s");
+                               return;
+                       }
+               }
+               ss = getc(inputt);
+               if (l_sr_flag == 1)
+                       goto bcg2;
+               else
+                       goto bcg1;
+       }
+       if (l_first_pass_flag) {
+               free(l_match);
+               free(l_repl);
+       } else
+               l_first_pass_flag = 1;
+       l_match = l_match2;
+       *errnum = 0;
+       l_repl = get_pattern(ss, inputt, errnum, 1);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       l_global = l_print = 0;
+       if (*errnum < 0)
+               if ((*errnum == -1) && (ss == '\n'))
+                       /* Note, \n still in stream for next getc. */
+                       l_print = 1;
+               else
+                       return;
+       *errnum = 0;
 
 
-  l_count2 = 1;
+       l_count2 = 1;
 
 
-  while (((ss=getc(inputt)) != '\n') && (ss != EOF))
-       {
-         if (ss == 'g')
-           l_global = 1;
-         else if (ss == 'p')
-           l_print = (l_print | (int)1);
-         else if (ss == 'n')
-           l_print = (l_print | (int)2);
-         else if (ss == 'l')
-           l_print = (l_print | (int)4);
-         else if ((ss > ('0'-1)) && (ss < ('9'+1)))
-             l_count2 = dig_num_conv(inputt, errnum);
-         else
-           {
-             *errnum = -1;
-             strcpy(help_msg, "illegal command option");
-             return;
-           }
-       }
+       while (((ss = getc(inputt)) != '\n') && (ss != EOF))
+               if (ss == 'g')
+                       l_global = 1;
+               else
+                       switch (ss) {
+                       case 'p':
+                               l_print = (l_print | (int) 1);
+                               break;
+                       case 'n':
+                               l_print = (l_print | (int) 2);
+                               break;
+                       case 'l':
+                               l_print = (l_print | (int) 4);
+                               break;
+                       default:
+                               if ((ss > ('0' - 1)) && (ss < ('9' + 1)))
+                                       l_count2 = dig_num_conv(inputt, errnum);
+                               else {
+                                       *errnum = -1;
+                                       strcpy(help_msg,
+                                           "illegal command option");
+                                       return;
+                               }
+               }
 
 bcg1:
 
 bcg1:
-  if ((RE_flag == 0) && (l_match[1] == '\0'))
-    {
-      *errnum = -1;
-      ungetc(ss, inputt);
-      return;
-    }
-  else if ((l_sr_flag == 0) && (l_match[1] || (RE_patt == NULL)))
-    {
-      free(RE_patt);
-      RE_patt = (char *)malloc(sizeof(char)*(2+strlen(l_match)));
-      bcopy(l_match, RE_patt);
-    }
-  RE_sol = (l_match[1] == '^')?1:0;
-  if ((l_match[1]) && (regfree(&RE_comp), l_err = regcomp(&RE_comp, &l_match[1], 0)))
-    {
-      regerror(l_err, &RE_comp, help_msg, 128);
-      *errnum = -1;
-      RE_flag = 0;
-      ungetc(ss, inputt);
-      return;
-    }
-  RE_flag = 1;
-  if (sigint_flag)
-    SIGINT_ACTION;
+       if ((RE_flag == 0) && (l_match[1] == '\0')) {
+               *errnum = -1;
+               ungetc(ss, inputt);
+               return;
+       } else
+               if ((l_sr_flag == 0) && (l_match[1] || (RE_patt == NULL))) {
+                       free(RE_patt);
+                       RE_patt = malloc(sizeof(char) * (2 + strlen(l_match)));
+                       bcopy(l_match, RE_patt, strlen(l_match + 1));
+               }
+       RE_sol = (l_match[1] == '^') ? 1 : 0;
+       if ((l_match[1]) &&
+           (regfree(&RE_comp), l_err = regcomp(&RE_comp, &l_match[1], 0))) {
+               regerror(l_err, &RE_comp, help_msg, 128);
+               *errnum = -1;
+               RE_flag = 0;
+               ungetc(ss, inputt);
+               return;
+       }
+       RE_flag = 1;
+       if (sigint_flag)
+               SIGINT_ACTION;
 bcg2:
 bcg2:
-  current = start;
-  l_s_flag = 0;
-  do
-    {
-      if (sigint_flag)
-        SIGINT_ACTION;
-      RE_match[0].rm_eo = 0;
-      get_line(current->handle, current->len);
-      l_count = l_count2;
-      l_local = text;
+       current = start;
+       l_s_flag = 0;
+       do {
+               if (sigint_flag)
+                       SIGINT_ACTION;
+               RE_match[0].rm_eo = 0;
+               get_line(current->handle, current->len);
+               l_count = l_count2;
+               l_local = text;
 #ifndef REG_STARTEND
 #ifndef REG_STARTEND
-      l_offset = 0;
+               l_offset = 0;
 #endif
 #endif
-      do
-        {
-          RE_match[0].rm_so = RE_match[0].rm_eo;
+               do {
+                       RE_match[0].rm_so = RE_match[0].rm_eo;
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-          l_matched = regexec_n(&RE_comp, l_local, (size_t)RE_SEC, RE_match, 0, l_count, (size_t)current->len, 0);
+                       l_matched = regexec_n(&RE_comp, l_local,
+                           (size_t)RE_SEC, RE_match, 0, l_count,
+                           (size_t)current->len, 0);
 #else
 #else
-          l_matched = regexec_n(&RE_comp, l_local, (size_t)RE_SEC, RE_match, 0, l_count, &l_offset, 0);
+                       l_matched = regexec_n(&RE_comp, l_local,
+                           (size_t)RE_SEC, RE_match, 0, l_count,
+                           &l_offset, 0);
 #endif
 #endif
-          if (l_matched == 0)
-            {
-              if ((l_s_flag == 0) && (g_flag == 0))
-                u_clr_stk();
-              l_count = l_s_flag = 1;
-              /* the l_local passed into re_replace is not freed in re_replace
-               * because it is "text", the global line holder, for the first
-               * pass through this loop. The value returned by re_replace is
-               * a new string (with the first replacement in it). If the 'g'
-               * flag was set with substitute then this new string is passed in
-               * for the second pass and can be freed once re_replace is done
-               * with it. (...and so on for the rest of the 'g' passes.
-               * RE_match[0].rm_eo is changed in re_replace to be the
-               * new location of the next character immediately after
-               * the replacement since it is likely the position of that
-               * character has changed because of the replacement.
-               */
+                       if (l_matched == 0) {
+                               if ((l_s_flag == 0) && (g_flag == 0))
+                                       u_clr_stk();
+                               l_count = l_s_flag = 1;
+                               /*
+                                * The l_local passed into re_replace is not
+                                * freed in re_replace because it is "text",
+                                * the global line holder, for the first pass
+                                * through this loop. The value returned by
+                                * re_replace is a new string (with the first
+                                * replacement in it). If the 'g' flag was
+                                * set with substitute then this new string
+                                * is passed in for the second pass and can
+                                * be freed once re_replace is done with it.
+                                * (...and so on for the rest of the 'g'
+                                * passes. RE_match[0].rm_eo is changed in
+                                * re_replace to be the new location of the
+                                * next character immediately after the
+                                * replacement since it is likely the
+                                * position of that character has changed
+                                * because of the replacement.
+                                */
 #ifdef REG_STARTEND
 #ifdef REG_STARTEND
-              l_local = re_replace(l_local, (size_t)(RE_SEC-1), RE_match, &l_repl[1]);
+                               l_local = re_replace(l_local,
+                                   (size_t)(RE_SEC - 1), RE_match, &l_repl[1]);
 #else
 #else
-              l_local = re_replace(l_local, (size_t)(RE_SEC-1), RE_match, &l_repl[1], l_offset);
+                               l_local = re_replace(l_local,
+                                   (size_t)(RE_SEC - 1), RE_match, &l_repl[1],
+                                   l_offset);
 #endif
 #endif
-            }
-          if (l_global == 0)
-            break;
-          if (l_local[RE_match[0].rm_eo] == '\0')
-            break;
-        } while (!l_matched);
-
-      l_cnt = l_nflag = 0;
-      l_kval = current;
-      l_temp_line = current->above;
-      l_temp_line2 = current->below;
-      l_local_temp = l_local;
-      while (1)
-           {
-             /* make the new string the one for this line. Check if
-              * it needs to be split.
-              */
-             if ((l_local[l_cnt] == '\n') || (l_local[l_cnt] == '\0'))
-               {
-                 if (l_local[l_cnt] == '\0')
-                   l_nflag = 1;
-                 l_local[l_cnt] = '\0';
-                 l_s_ret = (LINE *)malloc(sizeof(LINE));
-                 if (l_s_ret == NULL)
-                   {
-                     *errnum = -1;
-                     strcpy(help_msg, "out of memory error");
-                     return;
-                   }
-                 (l_s_ret->len) = strlen(l_local);
-                 (l_s_ret->handle) = add_line(l_local, l_s_ret->len);
-                 (l_s_ret->above) = l_temp_line;
-                 (l_s_ret->below) = NULL;
-                 if (l_temp_line == NULL)
-                   top = l_s_ret;
-                 else
-                   {
-                     u_add_stk(&(l_temp_line->below));
-                     (l_temp_line->below) = l_s_ret;
-                   }
-                 l_temp_line = l_s_ret;
-                 if ((l_local[l_cnt] == '\0') && (l_nflag == 1))
-                   break;
-                 else
-                   {
-                     l_local = &(l_local[l_cnt+1]);
-                     l_cnt = 0;
-                   }
-               } /* end-if */
-             else
-               l_cnt++;
-           } /* end-while */
-      (l_s_ret->below) = l_temp_line2;
-      ku_chk(current, current, l_kval->below);
-      if (current == End)
-        End = l_s_ret;
-      current = l_s_ret;
-      l_last = current;
-      if (l_temp_line2 == NULL)
-        bottom = l_s_ret;
-      else
-        {
-          u_add_stk(&(l_temp_line2->above));
-          (l_temp_line2->above) = current;
-        }
-      if (l_local_temp != text)
-        free(l_local_temp);
-      current = current->below;
-    } while (current != (End->below));
-
-  if (l_s_flag == 0)
-    {
-      current = start;
-      strcpy(help_msg, "no matches found for substitution");
-      *errnum = -1;
-      ungetc('\n', inputt);
-      return;
-    }
+                       }
+                       if (l_global == 0)
+                               break;
+                       if (l_local[RE_match[0].rm_eo] == '\0')
+                               break;
+               } while (!l_matched);
 
 
-  change_flag = 1;
-  current = l_last;
+               l_cnt = l_nflag = 0;
+               l_kval = current;
+               l_temp_line = current->above;
+               l_temp_line2 = current->below;
+               l_local_temp = l_local;
+               for (;;) {
+                       /*
+                        * Make the new string the one for this line.  Check if
+                        * it needs to be split.
+                        */
+                       if (l_local[l_cnt] == '\n' || l_local[l_cnt] == '\0') {
+                               if (l_local[l_cnt] == '\0')
+                                       l_nflag = 1;
+                               l_local[l_cnt] = '\0';
+                               l_s_ret = malloc(sizeof(LINE));
+                               if (l_s_ret == NULL) {
+                                       *errnum = -1;
+                                       strcpy(help_msg, "out of memory error");
+                                       return;
+                               }
+                               (l_s_ret->len) = strlen(l_local);
+                               (l_s_ret->handle) = add_line(l_local, l_s_ret->len);
+                               (l_s_ret->above) = l_temp_line;
+                               (l_s_ret->below) = NULL;
+                               if (l_temp_line == NULL)
+                                       top = l_s_ret;
+                               else {
+                                       u_add_stk(&(l_temp_line->below));
+                                       (l_temp_line->below) = l_s_ret;
+                               }
+                               l_temp_line = l_s_ret;
+                               if ((l_local[l_cnt] == '\0') && (l_nflag == 1))
+                                       break;
+                               else {
+                                       l_local = &(l_local[l_cnt + 1]);
+                                       l_cnt = 0;
+                               }
+                       } else
+                               l_cnt++;
+               }
+               (l_s_ret->below) = l_temp_line2;
+               ku_chk(current, current, l_kval->below);
+               if (current == End)
+                       End = l_s_ret;
+               current = l_s_ret;
+               l_last = current;
+               if (l_temp_line2 == NULL)
+                       bottom = l_s_ret;
+               else {
+                       u_add_stk(&(l_temp_line2->above));
+                       (l_temp_line2->above) = current;
+               }
+               if (l_local_temp != text)
+                       free(l_local_temp);
+               current = current->below;
+       } while (current != (End->below));
 
 
-  if (l_print > 0)
-    {
-      start = End = current;
-      ungetc(ss, inputt);
-      if (l_print == (l_print | (int)1))
-        p(inputt, errnum, 0);
-      if (l_print == (l_print | (int)2))
-        p(inputt, errnum, 1);
-      if (l_print == (l_print | (int)4))
-        l(inputt, errnum);
-      if (*errnum < 0)
-        return;
-    }
+       if (l_s_flag == 0) {
+               current = start;
+               strcpy(help_msg, "no matches found for substitution");
+               *errnum = -1;
+               ungetc('\n', inputt);
+               return;
+       }
+       change_flag = 1;
+       current = l_last;
 
 
-  if (l_sr_flag == -1)
-    {
-      regfree(&RE_comp);
-      regcomp(&RE_comp, &RE_patt[1], 0);
-    }
-  *errnum = 1;
-} /* end-s */
+       if (l_print > 0) {
+               start = End = current;
+               ungetc(ss, inputt);
+               if (l_print == (l_print | (int) 1))
+                       p(inputt, errnum, 0);
+               if (l_print == (l_print | (int) 2))
+                       p(inputt, errnum, 1);
+               if (l_print == (l_print | (int) 4))
+                       l(inputt, errnum);
+               if (*errnum < 0)
+                       return;
+       }
+       if (l_sr_flag == -1) {
+               regfree(&RE_comp);
+               regcomp(&RE_comp, &RE_patt[1], 0);
+       }
+       *errnum = 1;
+}
index 2ef48c6..345a490 100644 (file)
@@ -9,10 +9,20 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)t.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)t.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * The transcribe function. POSIX calls it copy, but 't' for transcribe
 
 /*
  * The transcribe function. POSIX calls it copy, but 't' for transcribe
@@ -22,126 +32,107 @@ static char sccsid[] = "@(#)t.c   5.1 (Berkeley) %G%";
 
 void
 t(inputt, errnum)
 
 void
 t(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  LINE *l_ptr, *l_tb, *l_te, *l_temp1, *l_temp2, *l_dest;
-
-  l_tb = NULL;
-  l_te = NULL;
-
-  if (((ss=getc(inputt)) != '\n') && (ss != EOF))
-    {
-      while (1)
-           {
-             if (ss != ' ')
-               {
-                 ungetc(ss, inputt);
-                 break;
-               }
-             ss = getc(inputt);
-           }
-      l_dest = address_conv(NULL, inputt, errnum);
-    }
-  else
-    (ungetc(ss, inputt), *errnum = -1);
-
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum < 0)
-    {
-      strcpy(help_msg, "bad destination address");
-      return;
-    } /* end-if */ 
-  *errnum = 0;
-  if (rol(inputt, errnum))
-    return;
-
-  if (start_default && End_default)
-      start = End = current;
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
-
-  if (sigint_flag)
-    SIGINT_ACTION;
-
-  if (g_flag == 0)
-    u_clr_stk();
-
-  for (l_ptr=start; l_ptr!=(End->below); l_ptr=(l_ptr->below) )
-     {
-       get_line(l_ptr->handle, l_ptr->len);
-       l_temp1 = (LINE *)malloc(sizeof(LINE));
-       if (l_temp1 == NULL)
-         {
-           *errnum = -1;
-           strcpy(help_msg, "out of memory error");
-           return;
-         }
-       if (l_tb == NULL)
-         {
-           l_tb = l_temp1;
-           (l_temp1->above) = NULL;
-           (l_temp1->below) = NULL;
-         }
-       else
-         {
-           (l_temp1->above) = l_te;
-           (l_temp1->below) = NULL;
-           (l_te->below) = l_temp1;
-         }
-       l_te = l_temp1;
-       (l_temp1->len) = l_ptr->len;
-       /* add it into the buffer at the spec'd location */
-       (l_temp1->handle) = add_line(text, l_ptr->len);
-       if (sigint_flag)
-         break;
-     } /* end-for */
-
-  if (l_dest == NULL)
-    l_temp2 = top;
-  else
-    {
-      u_add_stk(&(l_dest->below));
-      l_temp2 = l_dest->below;
-    }
-
-  if (l_dest == NULL)
-    {
-      u_add_stk(&(top->above));
-      (top->above) = l_tb;
-      top = l_tb;
-      (l_tb->above) = NULL;
-    } /* end-if, */
-  else
-    {
-      (l_tb->above) = l_dest;
-      (l_dest->below) = l_tb;
-    } /* end-if,else */
-
-  if (l_dest == bottom)
-    {
-      bottom = l_te;
-      (l_te->below) = NULL;
-    } /* end-if, */
-  else
-    {
-      (l_te->below) = l_temp2;
-      u_add_stk(&(l_temp2->above));
-      (l_temp2->above) = l_te;
-    } /* end-if,else */
-
-  current = l_te;
-  change_flag = 1;
-  *errnum = 1;
-  return;
-} /* end-t */
+       LINE *l_ptr, *l_tb, *l_te, *l_temp1, *l_temp2, *l_dest;
+
+       l_tb = NULL;
+       l_te = NULL;
+
+       if (((ss = getc(inputt)) != '\n') && (ss != EOF)) {
+               for (;;) {
+                       if (ss != ' ') {
+                               ungetc(ss, inputt);
+                               break;
+                       }
+                       ss = getc(inputt);
+               }
+               l_dest = address_conv(NULL, inputt, errnum);
+       } else
+               (ungetc(ss, inputt), *errnum = -1);
+
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum < 0) {
+               strcpy(help_msg, "bad destination address");
+               return;
+       }
+       *errnum = 0;
+       if (rol(inputt, errnum))
+               return;
+
+       if (start_default && End_default)
+               start = End = current;
+       else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
+
+       if (sigint_flag)
+               SIGINT_ACTION;
+
+       if (g_flag == 0)
+               u_clr_stk();
+
+       for (l_ptr = start; l_ptr != (End->below); l_ptr = (l_ptr->below)) {
+               get_line(l_ptr->handle, l_ptr->len);
+               l_temp1 = (LINE *) malloc(sizeof(LINE));
+               if (l_temp1 == NULL) {
+                       *errnum = -1;
+                       strcpy(help_msg, "out of memory error");
+                       return;
+               }
+               if (l_tb == NULL) {
+                       l_tb = l_temp1;
+                       (l_temp1->above) = NULL;
+                       (l_temp1->below) = NULL;
+               } else {
+                       (l_temp1->above) = l_te;
+                       (l_temp1->below) = NULL;
+                       (l_te->below) = l_temp1;
+               }
+               l_te = l_temp1;
+               (l_temp1->len) = l_ptr->len;
+               /* add it into the buffer at the spec'd location */
+               (l_temp1->handle) = add_line(text, l_ptr->len);
+               if (sigint_flag)
+                       break;
+       }
+
+       if (l_dest == NULL)
+               l_temp2 = top;
+       else {
+               u_add_stk(&(l_dest->below));
+               l_temp2 = l_dest->below;
+       }
+
+       if (l_dest == NULL) {
+               u_add_stk(&(top->above));
+               (top->above) = l_tb;
+               top = l_tb;
+               (l_tb->above) = NULL;
+       } else {
+               (l_tb->above) = l_dest;
+               (l_dest->below) = l_tb;
+       }
+
+       if (l_dest == bottom) {
+               bottom = l_te;
+               (l_te->below) = NULL;
+       } else {
+               (l_te->below) = l_temp2;
+               u_add_stk(&(l_temp2->above));
+               (l_temp2->above) = l_te;
+       }
+
+       current = l_te;
+       change_flag = 1;
+       *errnum = 1;
+       return;
+}
index a8454a1..6171fbe 100644 (file)
@@ -9,10 +9,20 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)u.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)u.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This restores the buffer to the state it was in just before the
 
 /*
  * This restores the buffer to the state it was in just before the
@@ -21,123 +31,108 @@ static char sccsid[] = "@(#)u.c   5.1 (Berkeley) %G%";
  * just manipulates the undo stack (u_stk); x-ref u_add_stk(),
  * u_clr_stk(), d_add(), and d_do().
  */
  * just manipulates the undo stack (u_stk); x-ref u_add_stk(),
  * u_clr_stk(), d_add(), and d_do().
  */
-
 void
 u(inputt, errnum)
 void
 u(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  if (rol(inputt, errnum))
-    return;
+       if (rol(inputt, errnum))
+               return;
 
 
-  if (u_stk == NULL)
-    {
-      *errnum = 1;
-      return;
-    }
-  undo();
-  *errnum = 1;
-} /* end-u */
+       if (u_stk == NULL) {
+               *errnum = 1;
+               return;
+       }
+       undo();
+       *errnum = 1;
+}
 
 
 /* This function does the "real work" of the undo. */
 
 
 /* This function does the "real work" of the undo. */
-
 void
 undo()
 void
 undo()
-
 {
 {
-  LINE *l_current, *l_bottom, *l_top;
-  struct u_layer *l_old_u_stk, *l_temp;
-
-  /* this is done because undo can be undone */
-  l_current = u_current;
-  l_top = u_top;
-  l_bottom = u_bottom;
-
-  u_current = current;
-  u_top = top;
-  u_bottom = bottom;
-
-  l_old_u_stk = u_stk;
-  u_stk = NULL;
+       LINE *l_current, *l_bottom, *l_top;
+       struct u_layer *l_old_u_stk, *l_temp;
+
+       /* This is done because undo can be undone. */
+       l_current = u_current;
+       l_top = u_top;
+       l_bottom = u_bottom;
+
+       u_current = current;
+       u_top = top;
+       u_bottom = bottom;
+
+       l_old_u_stk = u_stk;
+       u_stk = NULL;
+
+       while (l_old_u_stk != NULL) {
+               u_add_stk(l_old_u_stk->cell);
+               (*(l_old_u_stk->cell)) = (l_old_u_stk->val);
+               l_temp = l_old_u_stk;
+               l_old_u_stk = l_old_u_stk->below;
+               free(l_temp);
+       }
+
+       current = l_current;
+       top = l_top;
+       bottom = l_bottom;
+}
 
 
-  while (l_old_u_stk != NULL)
-       {
-         u_add_stk(l_old_u_stk->cell);
-         (*(l_old_u_stk->cell)) = (l_old_u_stk->val);
-         l_temp = l_old_u_stk;
-         l_old_u_stk = l_old_u_stk->below;
-         free(l_temp);
-       } /* end-while */
-
-  current = l_current;
-  top = l_top;
-  bottom = l_bottom;
-} /* end-undo */
-
-
-/* this function should be called before u_add_stk is in each command
+/*
+ * This function should be called before u_add_stk is in each command
  * function, _except_ when the global flag is high (>0) -- otherwise,
  * we couldn't undo all of the global commands, only the last iteration
  * of the last command -- and the u command.
  * This is where we begin to dispose of ed's undo knowledge of a line.
  * The call to d_do() gets rid of the rest.
  */
  * function, _except_ when the global flag is high (>0) -- otherwise,
  * we couldn't undo all of the global commands, only the last iteration
  * of the last command -- and the u command.
  * This is where we begin to dispose of ed's undo knowledge of a line.
  * The call to d_do() gets rid of the rest.
  */
-
 void
 u_clr_stk()
 void
 u_clr_stk()
-
 {
 {
-  register struct u_layer *l_temp;
-
-  u_current = current;
-  u_top = top;
-  u_bottom = bottom;
+       register struct u_layer *l_temp;
 
 
-  if ((u_stk) && (d_stk)) /* only if there is something to delete in the buffer */
-    d_do();
+       u_current = current;
+       u_top = top;
+       u_bottom = bottom;
 
 
-  while (u_stk != NULL)
-       {
-         l_temp = u_stk;
-         u_stk = u_stk->below;
-         free(l_temp);
-       }
-  u_stk = NULL;  /* just to sure */
-} /* end-u_clr_stk */
+       /* Only if there is something to delete in the buffer. */
+       if ((u_stk) && (d_stk))
+               d_do();
 
 
+       while (u_stk != NULL) {
+               l_temp = u_stk;
+               u_stk = u_stk->below;
+               free(l_temp);
+       }
+       u_stk = NULL;           /* Just to sure. */
+}
 
 /*
  * Place the addresses of and the pointer values of the LINE structures
 
 /*
  * Place the addresses of and the pointer values of the LINE structures
- * that are being changed on the undo stack.
- * This is a quick, simple, and effective way to preserve what could be
- * be brought back on request without keeping a copy of every bleep'n
- * thing.
+ * that are being changed on the undo stack.  This is a quick, simple,
+ * and effective way to preserve what could be be brought back on request
+ * without keeping a copy of every bleep'n thing.
  */
  */
-
 void
 u_add_stk(in)
 void
 u_add_stk(in)
-
-LINE **in;
-
+       LINE **in;
 {
 {
-  register struct u_layer *l_now;
-
-  if (in == NULL)
-    return;
-  l_now = (struct u_layer *)malloc(sizeof(struct u_layer));
-  if (l_now == NULL)
-    {
-      strcpy(help_msg, "undo: out of memory error");
-      return;
-    }
-  if (u_stk == NULL)
-    (l_now->below) = NULL;
-  else
-    (l_now->below) = u_stk;
-  u_stk = l_now;
-  (u_stk->cell) = in;
-  (u_stk->val) = (*(u_stk->cell));
-} /* end-u_add_stk */
+       register struct u_layer *l_now;
+
+       if (in == NULL)
+               return;
+       l_now = malloc(sizeof(struct u_layer));
+       if (l_now == NULL) {
+               strcpy(help_msg, "undo: out of memory error");
+               return;
+       }
+       if (u_stk == NULL)
+               (l_now->below) = NULL;
+       else
+               (l_now->below) = u_stk;
+       u_stk = l_now;
+       (u_stk->cell) = in;
+       (u_stk->val) = (*(u_stk->cell));
+}
index 7e76d87..f65b86e 100644 (file)
@@ -9,10 +9,20 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)w.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)w.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * Write the contents of the buffer out to the real file (spec'd or
 
 /*
  * Write the contents of the buffer out to the real file (spec'd or
@@ -22,133 +32,116 @@ static char sccsid[] = "@(#)w.c   5.1 (Berkeley) %G%";
  * Shame on POSIX for not including 'W' and 'wq', they're not that
  * hard to implement; yaaa! BSD for keeping it! :-)
  */
  * Shame on POSIX for not including 'W' and 'wq', they're not that
  * hard to implement; yaaa! BSD for keeping it! :-)
  */
-
 void
 w(inputt, errnum)
 void
 w(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  int l_ttl=0, l_q_flag=0, l_sl;
-  FILE *fopen(), *fp;
-  char *filename_read, *temp;
-
-  if (start_default && End_default)
-    {
-      start = top;
-      End = bottom;
-    }
-  else if (start_default)
-    start = End;
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      return;
-    }
-  start_default = End_default = 0;
-
-  l_sl = ss;
-  ss = getc(inputt);
-
-  if (ss == 'q')  /* "wq" and "Wq" command */
-    l_q_flag = 1;
-  else
-    ungetc(ss, inputt);
-
-  temp = filename(inputt, errnum);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (*errnum == 1)
-    filename_read = temp;
-  else if (*errnum == -2)
-    {
-      while (((ss = getc(inputt)) != '\n') || (ss == EOF))
-           ;
-      filename_read = filename_current;
-    }
-  else if (*errnum < 0)
-    return;
-  *errnum = 0;
-
-  if (filename_current == NULL)
-    {
-      if (filename_read == NULL)
-        {
-          strcpy(help_msg, "no filename given");
-          *errnum = -1;
-          ungetc('\n', inputt);
-          return;
-        }
-      else
-        filename_current = filename_read;
-    }
-
-  if (l_sl == 'W')
-    fp = fopen(filename_read, "a");
-  else
-    fp = fopen(filename_read, "w");
-
-  if (fp == NULL) 
-    {
-      strcpy(help_msg, "cannot write to file");
-      *errnum = -1;
-      ungetc('\n', inputt);
-      return;
-    }
-
-  if (sigint_flag)
-    goto point;
-
-  /* write it out and get a report on the number of bytes written */
-  l_ttl = edwrite(fp, start, End);
-  if (explain_flag != 0)  /* for -s option */
-    printf("%d\n", l_ttl);
-  point:
-  fclose(fp);
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (filename_read != filename_current)
-    free(filename_read);
-  change_flag = 0L;
-  *errnum = 1;
-  if (l_q_flag)  /* for "wq" */
-    {
-      ungetc('\n', inputt);
-      ss = (int)'q';
-      q(inputt, errnum);
-    }
-  return;
+       FILE *fp;
+       int l_ttl = 0, l_q_flag = 0, l_sl;
+       char *filename_read, *temp;
+
+       if (start_default && End_default) {
+               start = top;
+               End = bottom;
+       } else
+               if (start_default)
+                       start = End;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               return;
+       }
+       start_default = End_default = 0;
+
+       l_sl = ss;
+       ss = getc(inputt);
+
+       if (ss == 'q')          /* "wq" and "Wq" command */
+               l_q_flag = 1;
+       else
+               ungetc(ss, inputt);
+
+       temp = filename(inputt, errnum);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (*errnum == 1)
+               filename_read = temp;
+       else
+               if (*errnum == -2) {
+                       while (((ss = getc(inputt)) != '\n') || (ss == EOF));
+                       filename_read = filename_current;
+               } else
+                       if (*errnum < 0)
+                               return;
+       *errnum = 0;
+
+       if (filename_current == NULL) {
+               if (filename_read == NULL) {
+                       strcpy(help_msg, "no filename given");
+                       *errnum = -1;
+                       ungetc('\n', inputt);
+                       return;
+               } else
+                       filename_current = filename_read;
+       }
+       if (l_sl == 'W')
+               fp = fopen(filename_read, "a");
+       else
+               fp = fopen(filename_read, "w");
+
+       if (fp == NULL) {
+               strcpy(help_msg, "cannot write to file");
+               *errnum = -1;
+               ungetc('\n', inputt);
+               return;
+       }
+       if (sigint_flag)
+               goto point;
+
+       /* Write it out and get a report on the number of bytes written. */
+       l_ttl = edwrite(fp, start, End);
+       if (explain_flag != 0)          /* For -s option. */
+               printf("%d\n", l_ttl);
+
+point: fclose(fp);
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (filename_read != filename_current)
+               free(filename_read);
+       change_flag = 0L;
+       *errnum = 1;
+       if (l_q_flag) {                 /* For "wq". */
+               ungetc('\n', inputt);
+               ss = (int) 'q';
+               q(inputt, errnum);
+       }
 }
 
 /*
  * Actually writes out the contents of the buffer to the specified
  * STDIO file pointer for the range of lines specified.
  */
 }
 
 /*
  * Actually writes out the contents of the buffer to the specified
  * STDIO file pointer for the range of lines specified.
  */
-
 int
 edwrite(fp, begi, fini)
 int
 edwrite(fp, begi, fini)
-
-FILE *fp;
-LINE *begi, *fini;
-
+       FILE *fp;
+       LINE *begi, *fini;
 {
 {
-  register int l_ttl=0;
-
-  while (1)
-       {
-         get_line(begi->handle, begi->len);
-         /* fwrite is about 20+% faster than fprintf -- no surprise */
-         fwrite(text, sizeof(char), begi->len, fp);
-         fputc('\n', fp);
-         l_ttl = l_ttl + (begi->len) + 1;
-         if (begi == fini)
-           break;
-         else
-           begi = begi->below;
-         if (sigint_flag)
-           return(l_ttl);
-       }
-  return(l_ttl);
-} /* end-write */
+       register int l_ttl = 0;
+
+       for (;;) {
+               get_line(begi->handle, begi->len);
+
+               /* Fwrite is about 20+% faster than fprintf -- no surprise. */
+               fwrite(text, sizeof(char), begi->len, fp);
+               fputc('\n', fp);
+               l_ttl = l_ttl + (begi->len) + 1;
+               if (begi == fini)
+                       break;
+               else
+                       begi = begi->below;
+               if (sigint_flag)
+                       return (l_ttl);
+       }
+       return (l_ttl);
+}
index 67cc98b..054a19f 100644 (file)
@@ -9,10 +9,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)z.c        5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)z.c        5.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/types.h>
+
+#include <db.h>
+#include <regex.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "ed.h"
 #include "ed.h"
+#include "extern.h"
 
 /*
  * This prints out the next group of lines (as spec'd by the skicky
 
 /*
  * This prints out the next group of lines (as spec'd by the skicky
@@ -20,75 +29,66 @@ static char sccsid[] = "@(#)z.c     5.1 (Berkeley) %G%";
  * through the buffer (better than l, n, or p). Shame on POSIX for
  * not including it; yaaa! BSD for keeping it! :-)
  */
  * through the buffer (better than l, n, or p). Shame on POSIX for
  * not including it; yaaa! BSD for keeping it! :-)
  */
-
 void
 z(inputt, errnum)
 void
 z(inputt, errnum)
-
-FILE *inputt;
-int *errnum;
-
+       FILE *inputt;
+       int *errnum;
 {
 {
-  register int l_cnt;
-
-  if (current == NULL)
-    {
-      *errnum = -1;
-      strcpy(help_msg, "no lines in buffer");
-      return;
-    }
-  /* set zsnum if need be here */
-  ss = getc(inputt);
-  if ((ss > 48) && (ss < 57))
-    zsnum = dig_num_conv(inputt, errnum);  /* default set in main */
-  else if ((ss != '\n') && (ss != EOF))
-    {
-      ungetc(ss, inputt);
-      if (rol(inputt, errnum))
-        return;
-    }
+       register int l_cnt;
 
 
-  if (sigint_flag)
-    SIGINT_ACTION;
-  if (End_default)
-    {
-      if ((current->below) != NULL)
-        start = current->below;
-      else
-        {
-          strcpy(help_msg, "at end of buffer");
-          *errnum = -1;
-          ungetc('\n', inputt);
-          return;
-        }
-    }
-  else
-    start = End;
-  if (start == NULL)
-    {
-      strcpy(help_msg, "bad address");
-      *errnum = -1;
-      ungetc('\n', inputt);
-      return;
-    }
-  start_default = End_default = 0;
+       if (current == NULL) {
+               *errnum = -1;
+               strcpy(help_msg, "no lines in buffer");
+               return;
+       }
+       /* Set zsnum if need be here. */
+       ss = getc(inputt);
+       if ((ss > 48) && (ss < 57))
+               /* Default set in main. */
+               zsnum = dig_num_conv(inputt, errnum);
+       else
+               if ((ss != '\n') && (ss != EOF)) {
+                       ungetc(ss, inputt);
+                       if (rol(inputt, errnum))
+                               return;
+               }
+       if (sigint_flag)
+               SIGINT_ACTION;
+       if (End_default) {
+               if ((current->below) != NULL)
+                       start = current->below;
+               else {
+                       strcpy(help_msg, "at end of buffer");
+                       *errnum = -1;
+                       ungetc('\n', inputt);
+                       return;
+               }
+       } else
+               start = End;
+       if (start == NULL) {
+               strcpy(help_msg, "bad address");
+               *errnum = -1;
+               ungetc('\n', inputt);
+               return;
+       }
+       start_default = End_default = 0;
 
 
-  current = start;
-  l_cnt = 1;  /* yes, set to = 1 */
-  while (1)
-     {
-       /* scroll-out the next 'zsnum' of lines or until bottom */
-       if (sigint_flag)
-         SIGINT_ACTION;
-       if (current == NULL)
-         break;
-       get_line(current->handle, current->len);
-       printf("%s\n", text);
-       if (current == bottom)
-         break;
-       l_cnt++;
-       if (zsnum < l_cnt)
-         break;
-       current = current->below;
-     } /* end-while */
-  *errnum = 1;
-} /* end-z */
+       current = start;
+       l_cnt = 1;              /* Yes, set to = 1. */
+       while (1) {
+               /* Scroll-out the next 'zsnum' of lines or until bottom. */
+               if (sigint_flag)
+                       SIGINT_ACTION;
+               if (current == NULL)
+                       break;
+               get_line(current->handle, current->len);
+               printf("%s\n", text);
+               if (current == bottom)
+                       break;
+               l_cnt++;
+               if (zsnum < l_cnt)
+                       break;
+               current = current->below;
+       }
+       *errnum = 1;
+}